summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorAndrzej Tokarski <[email protected]>2022-11-21 21:45:10 +0100
committerGitHub <[email protected]>2022-11-21 21:45:10 +0100
commitb41f5eadb3143d0bfaf211d9bc84c95e5d623c29 (patch)
tree313da7c8988a2b443e6ab5647fa1177e84e424a6 /hw
parent89eac75085134d570dc26dffaf3d8f204aef5359 (diff)
parent4a2e424103b0a2626a6cb464a350c68ae109cc7e (diff)
Merge branch 'master' into midihost
Diffstat (limited to 'hw')
-rw-r--r--hw/bsp/board.c13
-rw-r--r--hw/bsp/board.h14
-rw-r--r--hw/bsp/ea4357/ea4357.c4
-rw-r--r--hw/bsp/lpc18/family.c4
-rw-r--r--hw/bsp/rp2040/board.h2
-rw-r--r--hw/bsp/rp2040/family.c34
6 files changed, 39 insertions, 32 deletions
diff --git a/hw/bsp/board.c b/hw/bsp/board.c
index e208624ba..7e96735bd 100644
--- a/hw/bsp/board.c
+++ b/hw/bsp/board.c
@@ -103,8 +103,10 @@ TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
{
(void) fhdl;
- return SEGGER_RTT_Read(0, buf, count);
+ int rd = (int) SEGGER_RTT_Read(0, buf, count);
+ return (rd > 0) ? rd : -1;
}
+
#endif
#elif defined(LOGGER_SWO)
@@ -143,7 +145,14 @@ TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
{
(void) fhdl;
- return board_uart_read((uint8_t*) buf, (int) count);
+ int rd = board_uart_read((uint8_t*) buf, (int) count);
+ return (rd > 0) ? rd : -1;
}
#endif
+
+int board_getchar(void)
+{
+ char c;
+ return ( sys_read(0, &c, 1) > 0 ) ? (int) c : (-1);
+}
diff --git a/hw/bsp/board.h b/hw/bsp/board.h
index 339e2e3b5..0a10294d0 100644
--- a/hw/bsp/board.h
+++ b/hw/bsp/board.h
@@ -66,9 +66,11 @@ void board_led_write(bool state);
uint32_t board_button_read(void);
// Get characters from UART
+// Return number of read bytes
int board_uart_read(uint8_t* buf, int len);
// Send characters to UART
+// Return number of sent bytes
int board_uart_write(void const * buf, int len);
#if CFG_TUSB_OS == OPT_OS_NONE
@@ -130,16 +132,8 @@ static inline void board_delay(uint32_t ms)
}
}
-static inline int board_uart_getchar(void)
-{
- uint8_t c;
- return board_uart_read(&c, 1) ? (int) c : (-1);
-}
-
-static inline int board_uart_putchar(uint8_t c)
-{
- return board_uart_write(&c, 1);
-}
+// stdio getchar() is blocking, this is non-blocking version
+int board_getchar(void);
#ifdef __cplusplus
}
diff --git a/hw/bsp/ea4357/ea4357.c b/hw/bsp/ea4357/ea4357.c
index 2c1d08770..f88d3b89e 100644
--- a/hw/bsp/ea4357/ea4357.c
+++ b/hw/bsp/ea4357/ea4357.c
@@ -272,9 +272,7 @@ uint32_t board_button_read(void)
int board_uart_read(uint8_t* buf, int len)
{
- //return UART_ReceiveByte(BOARD_UART_DEV);
- (void) buf; (void) len;
- return 0;
+ return Chip_UART_Read(UART_DEV, buf, len);
}
int board_uart_write(void const * buf, int len)
diff --git a/hw/bsp/lpc18/family.c b/hw/bsp/lpc18/family.c
index 0fc788873..72c20e034 100644
--- a/hw/bsp/lpc18/family.c
+++ b/hw/bsp/lpc18/family.c
@@ -141,9 +141,7 @@ uint32_t board_button_read(void)
int board_uart_read(uint8_t* buf, int len)
{
- //return UART_ReceiveByte(BOARD_UART_PORT);
- (void) buf; (void) len;
- return 0;
+ return Chip_UART_Read(UART_DEV, buf, len);
}
int board_uart_write(void const * buf, int len)
diff --git a/hw/bsp/rp2040/board.h b/hw/bsp/rp2040/board.h
index 56b8fec84..f25f80e09 100644
--- a/hw/bsp/rp2040/board.h
+++ b/hw/bsp/rp2040/board.h
@@ -52,7 +52,7 @@
#endif
// VBUS enable pin and its active state
-// #define PIO_USB_VBUSEN_PIN 22
+#define PIO_USB_VBUSEN_PIN 22
#ifndef PIO_USB_VBUSEN_STATE
#define PIO_USB_VBUSEN_STATE 1
diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c
index ee5a73ff6..26008168d 100644
--- a/hw/bsp/rp2040/family.c
+++ b/hw/bsp/rp2040/family.c
@@ -121,16 +121,6 @@ static uart_inst_t *uart_inst;
void board_init(void)
{
-#ifdef LED_PIN
- bi_decl(bi_1pin_with_name(LED_PIN, "LED"));
- gpio_init(LED_PIN);
- gpio_set_dir(LED_PIN, GPIO_OUT);
-#endif
-
- // Button
-#ifndef BUTTON_BOOTSEL
-#endif
-
#if CFG_TUH_RPI_PIO_USB || CFG_TUD_RPI_PIO_USB
// Set the system clock to a multiple of 120mhz for bitbanging USB with pico-usb
set_sys_clock_khz(120000, true);
@@ -148,6 +138,16 @@ void board_init(void)
tuh_configure(BOARD_TUH_RHPORT, TUH_CFGID_RPI_PIO_USB_CONFIGURATION, &pio_cfg);
#endif
+#ifdef LED_PIN
+ bi_decl(bi_1pin_with_name(LED_PIN, "LED"));
+ gpio_init(LED_PIN);
+ gpio_set_dir(LED_PIN, GPIO_OUT);
+#endif
+
+ // Button
+#ifndef BUTTON_BOOTSEL
+#endif
+
#if defined(UART_DEV) && defined(LIB_PICO_STDIO_UART)
bi_decl(bi_2pins_with_func(UART_TX_PIN, UART_TX_PIN, GPIO_FUNC_UART));
uart_inst = uart_get_instance(UART_DEV);
@@ -192,10 +192,13 @@ 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_inst);
+ int count = 0;
+ while ( (count < len) && uart_is_readable(uart_inst) )
+ {
+ buf[count] = uart_getc(uart_inst);
+ count++;
}
- return len;
+ return count;
#else
(void) buf; (void) len;
return 0;
@@ -216,6 +219,11 @@ int board_uart_write(void const * buf, int len)
#endif
}
+int board_getchar(void)
+{
+ return getchar_timeout_us(0);
+}
+
//--------------------------------------------------------------------+
// USB Interrupt Handler
// rp2040 implementation will install approriate handler when initializing