clean board uart read & write

This commit is contained in:
hathach 2019-03-20 20:58:27 +07:00
parent da55610f43
commit 20fb416783
10 changed files with 83 additions and 43 deletions

View File

@ -34,7 +34,6 @@ MKDIR = mkdir
SED = sed
CP = cp
RM = rm
AS = $(CROSS_COMPILE)as
INC += -Isrc \
-I$(TOP)/hw \

View File

@ -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,16 +106,27 @@ 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
}

View File

@ -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;
}

View File

@ -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

View File

@ -128,15 +128,19 @@ uint32_t board_buttons(void)
//--------------------------------------------------------------------+
// UART
//--------------------------------------------------------------------+
void board_uart_putchar(uint8_t c)
{
(void) c;
//UARTSend(&c, 1);
}
uint8_t board_uart_getchar(void)
int board_uart_read(uint8_t* buf, int len)
{
// *buffer = get_key(); TODO cannot find available code for uart getchar
(void) buf;
(void) len;
return 0;
}
int board_uart_write(void const * buf, int len)
{
//UARTSend(&c, 1);
(void) buf;
(void) len;
return 0;
}

View File

@ -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;
}

View File

@ -193,15 +193,20 @@ uint32_t board_buttons(void)
//--------------------------------------------------------------------+
// UART
//--------------------------------------------------------------------+
void board_uart_putchar(uint8_t c)
{
(void) c;
// UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
}
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;
}
int board_uart_write(void const * buf, int len)
{
// UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
(void) buf;
(void) len;
return 0;
}

View File

@ -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;
}
/*------------------------------------------------------------------*/

View File

@ -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

View File

@ -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;
}