Skip to content

Commit

Permalink
add machine_uart readchar and any method
Browse files Browse the repository at this point in the history
  • Loading branch information
xelll committed Apr 12, 2019
1 parent b9f51fe commit 210e0f7
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ mp_uint_t uart_rx_any(machine_uart_obj_t *self)
}
}

mp_obj_t uart_any(machine_uart_obj_t *self)
{
return mp_obj_new_int(uart_rx_any(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_any_obj, uart_any);

int uart_rx_irq(void *ctx)
{
machine_uart_obj_t *self = ctx;
Expand Down Expand Up @@ -237,6 +243,18 @@ int uart_rx_char(machine_uart_obj_t *self)
return -1;
}

mp_obj_t uart_readchar(machine_uart_obj_t *self)
{
int data = uart_rx_char(self);

if(data != -1)
{
return mp_obj_new_bytes(&data,1);
}
return MP_OBJ_NULL;
}
MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_rx_char_obj, uart_rx_char);

int uart_rx_data(machine_uart_obj_t *self,uint8_t* buf_in,uint32_t size)
{
uint16_t data_num = 0;
Expand Down Expand Up @@ -501,7 +519,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_deinit_obj, machine_uart_deinit);
STATIC const mp_rom_map_elem_t machine_uart_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_uart_init_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_uart_deinit_obj) },


{ MP_ROM_QSTR(MP_QSTR_readchar), MP_ROM_PTR(&machine_uart_rx_char_obj)},
{ MP_ROM_QSTR(MP_QSTR_any), MP_ROM_PTR(&machine_uart_any_obj)},
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj)},
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
Expand Down

0 comments on commit 210e0f7

Please sign in to comment.