Skip to content

Commit ac5fb52

Browse files
[bsp/nrf52x] support putting characters to ble host and getting characters from
ble host via rtthread finsh console Signed-off-by: chenyingchun0312 <[email protected]>
1 parent 9cd3897 commit ac5fb52

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

bsp/nrf5x/libraries/drivers/drv_uart.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ static rt_err_t _uart_ctrl(struct rt_serial_device *serial, int cmd, void *arg)
165165

166166
return RT_EOK;
167167
}
168-
168+
RT_WEAK int uart_putc_hook(rt_uint8_t *ch)
169+
{
170+
return -1;
171+
}
169172
static int _uart_putc(struct rt_serial_device *serial, char c)
170173
{
171174
drv_uart_cfg_t *instance = NULL;
@@ -180,13 +183,19 @@ static int _uart_putc(struct rt_serial_device *serial, char c)
180183
nrf_uart_event_clear(instance->uart.p_reg, NRF_UART_EVENT_TXDRDY);
181184
nrf_uart_task_trigger(instance->uart.p_reg, NRF_UART_TASK_STARTTX);
182185
nrf_uart_txd_set(instance->uart.p_reg, (uint8_t)c);
186+
uart_putc_hook((rt_uint8_t *)&c);
183187
while (!nrf_uart_event_check(instance->uart.p_reg, NRF_UART_EVENT_TXDRDY))
184188
{
185189
//wait for TXD send
186190
}
187191
return rtn;
188192
}
189193

194+
RT_WEAK int uart_getc_hook(rt_uint8_t *ch)
195+
{
196+
return -1;
197+
};
198+
190199
static int _uart_getc(struct rt_serial_device *serial)
191200
{
192201
int ch = -1;
@@ -202,7 +211,22 @@ static int _uart_getc(struct rt_serial_device *serial)
202211
ch = instance->rx_byte;
203212
instance->rx_length--;
204213
}
205-
return ch;
214+
215+
if (-1 != ch)
216+
{
217+
return ch;
218+
}
219+
else
220+
{
221+
if (-1 == uart_getc_hook((rt_uint8_t *)&ch))
222+
{
223+
return -1;
224+
}
225+
else
226+
{
227+
return ch;
228+
}
229+
}
206230
}
207231

208232
static struct rt_uart_ops _uart_ops = {

0 commit comments

Comments
 (0)