diff options
| author | hathach <[email protected]> | 2021-01-27 16:37:31 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2021-01-27 16:37:31 +0700 |
| commit | 4fef2ddb4c500f23115781aa87afd1f83b049b9d (patch) | |
| tree | 6d987a8c1cf2b6c250ce7eb981b4be21fe3f296b | |
| parent | 1abf9eeb808d9c023352c62a486e68bdf75e1ff6 (diff) | |
rp2040 move uart id to board specific
| -rw-r--r-- | examples/device/board_test/src/main.c | 4 | ||||
| -rw-r--r-- | hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h | 5 | ||||
| -rw-r--r-- | hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h | 5 | ||||
| -rw-r--r-- | hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h | 6 | ||||
| -rw-r--r-- | hw/bsp/rp2040/boards/raspberry_pi_pico/board.h | 5 | ||||
| -rw-r--r-- | hw/bsp/rp2040/family.c | 20 |
6 files changed, 34 insertions, 11 deletions
diff --git a/examples/device/board_test/src/main.c b/examples/device/board_test/src/main.c index 71665550f..d94b24650 100644 --- a/examples/device/board_test/src/main.c +++ b/examples/device/board_test/src/main.c @@ -55,10 +55,6 @@ int main(void) { uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED; - // uart echo -// uint8_t ch; -// if ( board_uart_read(&ch, 1) ) board_uart_write(&ch, 1); - // Blink every interval ms if ( !(board_millis() - start_ms < interval_ms) ) { diff --git a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h index 44985cd6f..417db3d5d 100644 --- a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h +++ b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h @@ -35,10 +35,13 @@ #define LED_STATE_ON 1 // Button pin is BOOTSEL which is flash CS pin - #define BUTTON_BOOTSEL #define BUTTON_STATE_ACTIVE 0 +#define UART_DEV uart0 +#define UART_TX_PIN 0 +#define UART_RX_PIN 1 + #ifdef __cplusplus } #endif diff --git a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h index 3a2de12f9..b45008fcc 100644 --- a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h +++ b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h @@ -35,10 +35,13 @@ #define LED_STATE_ON 1 // Button pin is BOOTSEL which is flash CS pin - #define BUTTON_BOOTSEL #define BUTTON_STATE_ACTIVE 0 +#define UART_DEV uart0 +#define UART_TX_PIN 0 +#define UART_RX_PIN 1 + #ifdef __cplusplus } #endif diff --git a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h index 5f37105e7..d3850a19e 100644 --- a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h +++ b/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h @@ -36,10 +36,14 @@ #define LED_STATE_ON 1 // Button pin is BOOTSEL which is flash CS pin - #define BUTTON_BOOTSEL #define BUTTON_STATE_ACTIVE 0 + +#define UART_DEV uart0 +#define UART_TX_PIN 0 +#define UART_RX_PIN 1 + #ifdef __cplusplus } #endif diff --git a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h index 61532d8cb..e4a6514ad 100644 --- a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h +++ b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h @@ -35,10 +35,13 @@ #define LED_STATE_ON 1 // Button pin is BOOTSEL which is flash CS pin - #define BUTTON_BOOTSEL #define BUTTON_STATE_ACTIVE 0 +#define UART_DEV uart0 +#define UART_TX_PIN 0 +#define UART_RX_PIN 1 + #ifdef __cplusplus } #endif diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c index e616acd19..e0dc47b39 100644 --- a/hw/bsp/rp2040/family.c +++ b/hw/bsp/rp2040/family.c @@ -78,7 +78,6 @@ bool __no_inline_not_in_flash_func(get_bootsel_button)() { void board_init(void) { - setup_default_uart(); gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT); @@ -86,6 +85,12 @@ void board_init(void) #ifndef BUTTON_BOOTSEL #endif +#ifdef UART_DEV + uart_init(UART_DEV, CFG_BOARD_UART_BAUDRATE); + gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART); + gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART); +#endif + // todo probably set up device mode? #if TUSB_OPT_DEVICE_ENABLED @@ -116,18 +121,27 @@ uint32_t board_button_read(void) int board_uart_read(uint8_t* buf, int len) { +#ifdef UART_DEV for(int i=0;i<len;i++) { - buf[i] = uart_getc(uart_default); + buf[i] = uart_getc(UART_DEV); } + return len; +#else return 0; +#endif } int board_uart_write(void const * buf, int len) { +#ifdef UART_DEV + char const* bufch = (uint8_t const*) buf; for(int i=0;i<len;i++) { - uart_putc(uart_default, ((char *)buf)[i]); + uart_putc(UART_DEV, bufch[i]); } + return len; +#else return 0; +#endif } //--------------------------------------------------------------------+ |
