diff options
| author | hathach <[email protected]> | 2019-03-20 20:58:27 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2019-03-20 20:58:27 +0700 |
| commit | 20fb416783c4dcce71a581f6db1674a3c6a1ae12 (patch) | |
| tree | a4e36f39293a40193c88e7c18dedd73ebc0e9f50 | |
| parent | da55610f4355bb65bd9297798f9ad961807feea9 (diff) | |
clean board uart read & write
| -rw-r--r-- | examples/device/cdc_msc_hid/Makefile | 1 | ||||
| -rw-r--r-- | hw/bsp/board.h | 31 | ||||
| -rw-r--r-- | hw/bsp/ea4088qs/board_ea4088qs.c | 11 | ||||
| -rw-r--r-- | hw/bsp/ea4357/board_ea4357.c | 10 | ||||
| -rw-r--r-- | hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c | 14 | ||||
| -rw-r--r-- | hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c | 12 | ||||
| -rw-r--r-- | hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c | 15 | ||||
| -rw-r--r-- | hw/bsp/mcb1800/board_mcb1800.c | 10 | ||||
| -rw-r--r-- | hw/bsp/pca10056/board_pca10056.c | 10 | ||||
| -rw-r--r-- | hw/bsp/printf_retarget.c | 4 |
10 files changed, 79 insertions, 39 deletions
diff --git a/examples/device/cdc_msc_hid/Makefile b/examples/device/cdc_msc_hid/Makefile index 86587dd47..fffabee9d 100644 --- a/examples/device/cdc_msc_hid/Makefile +++ b/examples/device/cdc_msc_hid/Makefile @@ -34,7 +34,6 @@ MKDIR = mkdir SED = sed CP = cp RM = rm -AS = $(CROSS_COMPILE)as INC += -Isrc \ -I$(TOP)/hw \ diff --git a/hw/bsp/board.h b/hw/bsp/board.h index e39d8dead..6b432d2e5 100644 --- a/hw/bsp/board.h +++ b/hw/bsp/board.h @@ -65,6 +65,8 @@ #include "metro_m4_express/board_metro_m4_express.h" #elif defined BOARD_METRO_M0_EXPRESS #include "metro_m0_express/board_metro_m0_express.h" + +// ST STM32 #elif defined BOARD_STM32F407G_DISC1 #include "stm32f407g_disc1/board_stm32f407g_disc1.h" #else @@ -76,7 +78,7 @@ #define board_tick2ms(tck) ( ( ((uint64_t)(tck)) * 1000) / BOARD_TICKS_HZ ) -/// Initialize on-board peripherals +// Initialize on-board peripherals void board_init(void); //--------------------------------------------------------------------+ @@ -104,17 +106,28 @@ static inline void board_led_off(void) */ uint32_t board_buttons(void); -/** Get a character input from UART - * \return ASCII code of the input character or zero if none. - */ -uint8_t board_uart_getchar(void); +//--------------------------------------------------------------------+ +// UART +//--------------------------------------------------------------------+ -/** Send a character to UART - * \param[in] c the character to be sent - */ -void board_uart_putchar(uint8_t c); +// Get characters from UART +int board_uart_read(uint8_t* buf, int len); + +// Send characters to UART +int board_uart_write(void const * buf, int len); +static inline int8_t board_uart_getchar(void) +{ + uint8_t c; + return board_uart_read(&c, 1) ? c : (-1); +} + +static inline int board_uart_putchar(uint8_t c) +{ + return board_uart_write(&c, 1); +} + #ifdef __cplusplus } #endif diff --git a/hw/bsp/ea4088qs/board_ea4088qs.c b/hw/bsp/ea4088qs/board_ea4088qs.c index 385f8a74c..b0ce7281b 100644 --- a/hw/bsp/ea4088qs/board_ea4088qs.c +++ b/hw/bsp/ea4088qs/board_ea4088qs.c @@ -137,18 +137,21 @@ uint32_t board_buttons(void) return result; } - //------------- UART -------------// -uint8_t board_uart_getchar(void) +int board_uart_read(uint8_t* buf, int len) { //return UART_ReceiveByte(BOARD_UART_PORT); + (void) buf; + (void) len; return 0; } -void board_uart_putchar(uint8_t c) +int board_uart_write(void const * buf, int len) { //UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); - (void) c; + (void) buf; + (void) len; + return 0; } diff --git a/hw/bsp/ea4357/board_ea4357.c b/hw/bsp/ea4357/board_ea4357.c index c5f2d81ac..d44082551 100644 --- a/hw/bsp/ea4357/board_ea4357.c +++ b/hw/bsp/ea4357/board_ea4357.c @@ -282,16 +282,20 @@ uint32_t board_buttons(void) //--------------------------------------------------------------------+ // UART //--------------------------------------------------------------------+ -uint8_t board_uart_getchar(void) +int board_uart_read(uint8_t* buf, int len) { //return UART_ReceiveByte(BOARD_UART_PORT); + (void) buf; + (void) len; return 0; } -void board_uart_putchar(uint8_t c) +int board_uart_write(void const * buf, int len) { //UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); - (void) c; + (void) buf; + (void) len; + return 0; } #endif diff --git a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c b/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c index 56ef84758..ab05c045a 100644 --- a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c +++ b/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c @@ -128,15 +128,19 @@ uint32_t board_buttons(void) //--------------------------------------------------------------------+ // UART //--------------------------------------------------------------------+ -void board_uart_putchar(uint8_t c) +int board_uart_read(uint8_t* buf, int len) { - (void) c; - //UARTSend(&c, 1); +// *buffer = get_key(); TODO cannot find available code for uart getchar + (void) buf; + (void) len; + return 0; } -uint8_t board_uart_getchar(void) +int board_uart_write(void const * buf, int len) { -// *buffer = get_key(); TODO cannot find available code for uart getchar + //UARTSend(&c, 1); + (void) buf; + (void) len; return 0; } diff --git a/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c b/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c index cfa4f1f7e..325577cd7 100644 --- a/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c +++ b/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c @@ -153,14 +153,18 @@ uint32_t board_buttons(void) //--------------------------------------------------------------------+ // UART //--------------------------------------------------------------------+ -void board_uart_putchar(uint8_t c) +int board_uart_read(uint8_t* buf, int len) { - (void) c; -// UARTSend(&c, 1); + (void) buf; + (void) len; + return 0; } -uint8_t board_uart_getchar(void) +int board_uart_write(void const * buf, int len) { +// UARTSend(&c, 1); + (void) buf; + (void) len; return 0; } diff --git a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c index 98c3d0a5f..5ee799da5 100644 --- a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c +++ b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c @@ -193,15 +193,20 @@ uint32_t board_buttons(void) //--------------------------------------------------------------------+ // UART //--------------------------------------------------------------------+ -void board_uart_putchar(uint8_t c) +int board_uart_read(uint8_t* buf, int len) { - (void) c; -// UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); +// return UART_ReceiveByte(BOARD_UART_PORT); + (void) buf; + (void) len; + return 0; + } -uint8_t board_uart_getchar(void) +int board_uart_write(void const * buf, int len) { -// return UART_ReceiveByte(BOARD_UART_PORT); +// UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); + (void) buf; + (void) len; return 0; } diff --git a/hw/bsp/mcb1800/board_mcb1800.c b/hw/bsp/mcb1800/board_mcb1800.c index 0e119476b..9989b334f 100644 --- a/hw/bsp/mcb1800/board_mcb1800.c +++ b/hw/bsp/mcb1800/board_mcb1800.c @@ -205,16 +205,20 @@ uint32_t board_buttons(void) //------------- UART -------------// -uint8_t board_uart_getchar(void) +int board_uart_read(uint8_t* buf, int len) { //return UART_ReceiveByte(BOARD_UART_PORT); + (void) buf; + (void) len; return 0; } -void board_uart_putchar(uint8_t c) +int board_uart_write(void const * buf, int len) { - (void) c; //UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING); + (void) buf; + (void) len; + return 0; } /*------------------------------------------------------------------*/ diff --git a/hw/bsp/pca10056/board_pca10056.c b/hw/bsp/pca10056/board_pca10056.c index 0bdaddece..c48c00374 100644 --- a/hw/bsp/pca10056/board_pca10056.c +++ b/hw/bsp/pca10056/board_pca10056.c @@ -247,14 +247,18 @@ uint32_t board_buttons(void) return ret; } -uint8_t board_uart_getchar(void) +int board_uart_read(uint8_t* buf, int len) { + (void) buf; + (void) len; return 0; } -void board_uart_putchar(uint8_t c) +int board_uart_write(void const * buf, int len) { - (void) c; + (void) buf; + (void) len; + return 0; } #ifdef SOFTDEVICE_PRESENT diff --git a/hw/bsp/printf_retarget.c b/hw/bsp/printf_retarget.c index 34f68fbb0..0c1d80d17 100644 --- a/hw/bsp/printf_retarget.c +++ b/hw/bsp/printf_retarget.c @@ -168,8 +168,8 @@ size_t __read(int handle, unsigned char *buf, size_t bufSize) size_t i; for (i=0; i<bufSize; i++) { - uint8_t ch = board_uart_getchar(); - if (ch == 0) break; + int8_t ch = board_uart_getchar(); + if (ch == -1) break; buf[i] = ch; } |
