Rationalize board header pin defines, and add partner board headers (#192)
* Board definition header files for the iniital set of SparkFun rp2040 boards * Add default PICO_DEFAULT_I2C*, allow no PICO_DEFAULT_LED_PIN, no PICO_DEFAULT_UART* (instead of -1) Fixup SparkFun headers * Pimoroni board headers * Add LED related board defines PICO_CONFIGs (to pico_stdlib for now) * more board config changes * add Adafruit feather, itsybitsy, qtpy board headers * add PICO_DEFAULT_WS2812_POWER_PIN define * MOSI/MISO -> TX/RX, some UART cleanup.. make vgaboard.h defines take preference over pico.h ones * local change to tinyusb to cope with no default LED or UART * fix review issues Co-authored-by: Kirk Benell <github-stuff@accvec.com> Co-authored-by: ZodiusInfuser <christopher.parrott2@gmail.com> Co-authored-by: hathach <thach@tinyusb.org>
This commit is contained in:
committed by
graham sanderson
parent
839224c2a3
commit
7ee36e3328
@ -48,6 +48,10 @@ extern "C" {
|
||||
|
||||
typedef struct i2c_inst i2c_inst_t;
|
||||
|
||||
// PICO_CONFIG: PICO_DEFAULT_I2C, Define the default I2C for a board, default=undefined, group=hardware_i2c
|
||||
// PICO_CONFIG: PICO_DEFAULT_I2C_SDA_PIN, Define the default I2C SDA, min=0, max=29, default=undefined, group=hardware_i2c
|
||||
// PICO_CONFIG: PICO_DEFAULT_I2C_SCL_PIN, Define the default I2C SCL pin, min=0, max=29, default=undefined, group=hardware_i2c
|
||||
|
||||
/** The I2C identifiers for use in I2C functions.
|
||||
*
|
||||
* e.g. i2c_init(i2c0, 48000)
|
||||
@ -61,6 +65,14 @@ extern i2c_inst_t i2c1_inst;
|
||||
#define i2c0 (&i2c0_inst) ///< Identifier for I2C HW Block 0
|
||||
#define i2c1 (&i2c1_inst) ///< Identifier for I2C HW Block 1
|
||||
|
||||
#if !defined(PICO_DEFAULT_I2C_INSTANCE) && defined(PICO_DEFAULT_I2C)
|
||||
#define PICO_DEFAULT_I2C_INSTANCE (__CONCAT(i2c,PICO_DEFAULT_I2C))
|
||||
#endif
|
||||
|
||||
#ifdef PICO_DEFAULT_I2C_INSTANCE
|
||||
#define i2c_default PICO_DEFAULT_I2C_INSTANCE
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -126,7 +138,7 @@ struct i2c_inst {
|
||||
* \ingroup hardware_i2c
|
||||
*
|
||||
* \param i2c I2C instance
|
||||
* \return Number of UART, 0 or 1.
|
||||
* \return Number of I2C, 0 or 1.
|
||||
*/
|
||||
static inline uint i2c_hw_index(i2c_inst_t *i2c) {
|
||||
invalid_params_if(I2C, i2c != i2c0 && i2c != i2c1);
|
||||
|
@ -341,7 +341,7 @@ static inline void sm_config_set_out_special(pio_sm_config *c, bool sticky, bool
|
||||
* \param status_n parameter for the mov status operation (currently a bit count)
|
||||
*/
|
||||
static inline void sm_config_set_mov_status(pio_sm_config *c, enum pio_mov_status_type status_sel, uint status_n) {
|
||||
valid_params_if(PIO, join >= STATUS_TX_LESSTHAN && join <= STATUS_RX_LESSTHAN);
|
||||
valid_params_if(PIO, status_sel >= STATUS_TX_LESSTHAN && status_sel <= STATUS_RX_LESSTHAN);
|
||||
c->execctrl = (c->execctrl
|
||||
& ~(PIO_SM0_EXECCTRL_STATUS_SEL_BITS | PIO_SM0_EXECCTRL_STATUS_N_BITS))
|
||||
| ((((uint)status_sel) << PIO_SM0_EXECCTRL_STATUS_SEL_LSB) & PIO_SM0_EXECCTRL_STATUS_SEL_BITS)
|
||||
|
@ -35,6 +35,12 @@ extern "C" {
|
||||
* Each controller can be connected to a number of GPIO pins, see the datasheet GPIO function selection table for more information.
|
||||
*/
|
||||
|
||||
// PICO_CONFIG: PICO_DEFAULT_SPI, Define the default SPI for a board, default=undefined, group=hardware_spi
|
||||
// PICO_CONFIG: PICO_DEFAULT_SPI_SCK_PIN, Define the default SPI SCK pin, min=0, max=29, default=undefined, group=hardware_spi
|
||||
// PICO_CONFIG: PICO_DEFAULT_SPI_TX_PIN, Define the default SPI TX pin, min=0, max=29, default=undefined, group=hardware_spi
|
||||
// PICO_CONFIG: PICO_DEFAULT_SPI_RX_PIN, Define the default SPI RX pin, min=0, max=29, default=undefined, group=hardware_spi
|
||||
// PICO_CONFIG: PICO_DEFAULT_SPI_CSN_PIN, Define the default SPI CSN pin, min=0, max=29, default=undefined, group=hardware_spi
|
||||
|
||||
/**
|
||||
* Opaque type representing an SPI instance.
|
||||
*/
|
||||
@ -56,6 +62,14 @@ typedef struct spi_inst spi_inst_t;
|
||||
*/
|
||||
#define spi1 ((spi_inst_t * const)spi1_hw)
|
||||
|
||||
#if !defined(PICO_DEFAULT_SPI_INSTANCE) && defined(PICO_DEFAULT_SPI)
|
||||
#define PICO_DEFAULT_SPI_INSTANCE (__CONCAT(spi,PICO_DEFAULT_SPI))
|
||||
#endif
|
||||
|
||||
#ifdef PICO_DEFAULT_SPI_INSTANCE
|
||||
#define spi_default PICO_DEFAULT_SPI_INSTANCE
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
SPI_CPHA_0 = 0,
|
||||
SPI_CPHA_1 = 1
|
||||
|
@ -29,26 +29,15 @@ extern "C" {
|
||||
#define PICO_UART_DEFAULT_CRLF 0
|
||||
#endif
|
||||
|
||||
// PICO_CONFIG: PICO_DEFAULT_UART, Define the default UART used for printf etc, default=0, group=hardware_uart
|
||||
#ifndef PICO_DEFAULT_UART
|
||||
#define PICO_DEFAULT_UART 0 ///< Default UART instance
|
||||
#endif
|
||||
// PICO_CONFIG: PICO_DEFAULT_UART, Define the default UART used for printf etc, default=undefined, group=hardware_uart
|
||||
// PICO_CONFIG: PICO_DEFAULT_UART_TX_PIN, Define the default UART TX pin, min=0, max=29, default=undefined, group=hardware_uart
|
||||
// PICO_CONFIG: PICO_DEFAULT_UART_RX_PIN, Define the default UART RX pin, min=0, max=29, default=undefined, group=hardware_uart
|
||||
|
||||
// PICO_CONFIG: PICO_DEFAULT_UART_BAUD_RATE, Define the default UART baudrate, max=921600, default=115200, group=hardware_uart
|
||||
#ifndef PICO_DEFAULT_UART_BAUD_RATE
|
||||
#define PICO_DEFAULT_UART_BAUD_RATE 115200 ///< Default baud rate
|
||||
#endif
|
||||
|
||||
// PICO_CONFIG: PICO_DEFAULT_UART_TX_PIN, Define the default UART TX pin, min=0, max=29, default=0, group=hardware_uart
|
||||
#ifndef PICO_DEFAULT_UART_TX_PIN
|
||||
#define PICO_DEFAULT_UART_TX_PIN 0 ///< Default TX pin
|
||||
#endif
|
||||
|
||||
// PICO_CONFIG: PICO_DEFAULT_UART_RX_PIN, Define the default UART RX pin, min=0, max=29, default=1, group=hardware_uart
|
||||
#ifndef PICO_DEFAULT_UART_RX_PIN
|
||||
#define PICO_DEFAULT_UART_RX_PIN 1 ///< Default RX pin
|
||||
#endif
|
||||
|
||||
/** \file hardware/uart.h
|
||||
* \defgroup hardware_uart hardware_uart
|
||||
*
|
||||
@ -93,11 +82,13 @@ typedef struct uart_inst uart_inst_t;
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifndef PICO_DEFAULT_UART_INSTANCE
|
||||
#if !defined(PICO_DEFAULT_UART_INSTANCE) && defined(PICO_DEFAULT_UART)
|
||||
#define PICO_DEFAULT_UART_INSTANCE (__CONCAT(uart,PICO_DEFAULT_UART))
|
||||
#endif
|
||||
|
||||
#ifdef PICO_DEFAULT_UART_INSTANCE
|
||||
#define uart_default PICO_DEFAULT_UART_INSTANCE
|
||||
#endif
|
||||
|
||||
/*! \brief Convert UART instance to hardware instance number
|
||||
* \ingroup hardware_uart
|
||||
@ -414,7 +405,11 @@ void uart_set_translate_crlf(uart_inst_t *uart, bool translate);
|
||||
* \ingroup hardware_uart
|
||||
*/
|
||||
static inline void uart_default_tx_wait_blocking(void) {
|
||||
#ifdef uart_default
|
||||
uart_tx_wait_blocking(uart_default);
|
||||
#else
|
||||
assert(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*! \brief Wait for up to a certain number of microseconds for the RX FIFO to be non empty
|
||||
|
@ -18,11 +18,12 @@ static uart_inst_t *uart_instance;
|
||||
#endif
|
||||
|
||||
void stdio_uart_init() {
|
||||
#ifdef uart_default
|
||||
int tx_pin = -1;
|
||||
int rx_pin = -1;
|
||||
#if defined(PICO_DEFAULT_UART_TX_PIN) && PICO_DEFAULT_UART_TX_PIN != -1
|
||||
#ifdef PICO_DEFAULT_UART_TX_PIN
|
||||
tx_pin = PICO_DEFAULT_UART_TX_PIN;
|
||||
#if defined(PICO_DEFAULT_UART_RX_PIN) && PICO_DEFAULT_UART_RX_PIN != -1
|
||||
#ifdef PICO_DEFAULT_UART_RX_PIN
|
||||
rx_pin = PICO_DEFAULT_UART_RX_PIN;
|
||||
stdio_bi_decl_if_func_used(bi_program_feature("UART stdin / stdout"));
|
||||
bi_decl_if_func_used(bi_2pins_with_func(PICO_DEFAULT_UART_RX_PIN, PICO_DEFAULT_UART_TX_PIN, GPIO_FUNC_UART));
|
||||
@ -30,22 +31,23 @@ void stdio_uart_init() {
|
||||
stdio_bi_decl_if_func_used(bi_program_feature("UART stdout"));
|
||||
bi_decl_if_func_used(bi_1pin_with_func(PICO_DEFAULT_UART_TX_PIN, GPIO_FUNC_UART));
|
||||
#endif
|
||||
#elif defined(PICO_DEFAULT_UART_RX_PIN) && PICO_DEFAULT_UART_RX_PIN != -1
|
||||
#elif defined(PICO_DEFAULT_UART_RX_PIN)
|
||||
rx_pin = PICO_DEFAULT_UART_RX_PIN;
|
||||
stdio_bi_decl_if_func_used(bi_program_feature("UART stdin"));
|
||||
bi_decl_if_func_used(bi_1pin_with_func(PICO_DEFAULT_UART_RX_PIN, GPIO_FUNC_UART));
|
||||
#endif
|
||||
#if !defined(PICO_DEFAULT_UART_BAUD_RATE) || !defined(uart_default)
|
||||
#if !defined(PICO_DEFAULT_UART_BAUD_RATE)
|
||||
panic("UART baud rate undefined");
|
||||
#else
|
||||
stdio_uart_init_full(uart_default, PICO_DEFAULT_UART_BAUD_RATE, tx_pin, rx_pin);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void stdout_uart_init() {
|
||||
#ifdef PICO_DEFAULT_UART_TX_PIN
|
||||
#if defined(uart_default) && defined(PICO_DEFAULT_UART_TX_PIN)
|
||||
bi_decl_if_func_used(bi_1pin_with_func(PICO_DEFAULT_UART_TX_PIN, GPIO_FUNC_UART));
|
||||
#if !defined(PICO_DEFAULT_UART_BAUD_RATE) || !defined(uart_default)
|
||||
#if !defined(PICO_DEFAULT_UART_BAUD_RATE)
|
||||
panic("UART baud rate undefined");
|
||||
#else
|
||||
stdio_bi_decl_if_func_used(bi_program_feature("UART stdout"));
|
||||
@ -55,9 +57,9 @@ void stdout_uart_init() {
|
||||
}
|
||||
|
||||
void stdin_uart_init() {
|
||||
#ifdef PICO_DEFAULT_UART_RX_PIN
|
||||
#if defined(uart_default) && defined(PICO_DEFAULT_UART_RX_PIN)
|
||||
bi_decl_if_func_used(bi_1pin_with_func(PICO_DEFAULT_UART_RX_PIN, GPIO_FUNC_UART));
|
||||
#if !defined(PICO_DEFAULT_UART_BAUD_RATE) || !defined(uart_default)
|
||||
#if !defined(PICO_DEFAULT_UART_BAUD_RATE)
|
||||
panic("UART baud rate undefined");
|
||||
#else
|
||||
stdio_bi_decl_if_func_used(bi_program_feature("UART stdin"));
|
||||
@ -76,14 +78,14 @@ void stdio_uart_init_full(struct uart_inst *uart, uint baud_rate, int tx_pin, in
|
||||
|
||||
static void stdio_uart_out_chars(const char *buf, int length) {
|
||||
for (int i = 0; i <length; i++) {
|
||||
uart_putc(uart_default, buf[i]);
|
||||
uart_putc(uart_instance, buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int stdio_uart_in_chars(char *buf, int length) {
|
||||
int i=0;
|
||||
while (i<length && uart_is_readable(uart_default)) {
|
||||
buf[i++] = uart_getc(uart_default);
|
||||
while (i<length && uart_is_readable(uart_instance)) {
|
||||
buf[i++] = uart_getc(uart_instance);
|
||||
}
|
||||
return i ? i : PICO_ERROR_NO_DATA;
|
||||
}
|
||||
|
Reference in New Issue
Block a user