4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-30 05:10:26 +08:00

Merge pull request #3992 from chenyingchun0312/master

[bsp/nrf52x] support putting characters to ble host and getting chara…
This commit is contained in:
Bernard Xiong 2020-10-29 09:37:17 +08:00 committed by GitHub
commit a5590816e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -165,7 +165,10 @@ static rt_err_t _uart_ctrl(struct rt_serial_device *serial, int cmd, void *arg)
return RT_EOK;
}
RT_WEAK int uart_putc_hook(rt_uint8_t *ch)
{
return -1;
}
static int _uart_putc(struct rt_serial_device *serial, char c)
{
drv_uart_cfg_t *instance = NULL;
@ -180,6 +183,7 @@ static int _uart_putc(struct rt_serial_device *serial, char c)
nrf_uart_event_clear(instance->uart.p_reg, NRF_UART_EVENT_TXDRDY);
nrf_uart_task_trigger(instance->uart.p_reg, NRF_UART_TASK_STARTTX);
nrf_uart_txd_set(instance->uart.p_reg, (uint8_t)c);
uart_putc_hook((rt_uint8_t *)&c);
while (!nrf_uart_event_check(instance->uart.p_reg, NRF_UART_EVENT_TXDRDY))
{
//wait for TXD send
@ -187,6 +191,11 @@ static int _uart_putc(struct rt_serial_device *serial, char c)
return rtn;
}
RT_WEAK int uart_getc_hook(rt_uint8_t *ch)
{
return -1;
};
static int _uart_getc(struct rt_serial_device *serial)
{
int ch = -1;
@ -202,7 +211,22 @@ static int _uart_getc(struct rt_serial_device *serial)
ch = instance->rx_byte;
instance->rx_length--;
}
return ch;
if (-1 != ch)
{
return ch;
}
else
{
if (-1 == uart_getc_hook((rt_uint8_t *)&ch))
{
return -1;
}
else
{
return ch;
}
}
}
static struct rt_uart_ops _uart_ops = {