renesas-ra: Rename pyb_uart_ to machine_uart_.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
This commit is contained in:
parent
20028c7c80
commit
5f57ec464a
|
@ -78,8 +78,8 @@ STATIC const char *_parity_name[] = {"None", "ODD", "EVEN"};
|
|||
///
|
||||
/// uart.any() # returns True if any characters waiting
|
||||
|
||||
STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC void machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (!self->is_enabled) {
|
||||
mp_printf(print, "UART(%u)", self->uart_id);
|
||||
} else {
|
||||
|
@ -116,7 +116,7 @@ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k
|
|||
/// - `timeout_char` is the timeout in milliseconds to wait between characters.
|
||||
/// - `flow` is RTS | CTS where RTS == 256, CTS == 512
|
||||
/// - `read_buf_len` is the character length of the read buffer (0 to disable).
|
||||
STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC mp_obj_t machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_baudrate, MP_ARG_INT | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} },
|
||||
|
@ -256,7 +256,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const
|
|||
/// - `UART(6)` is on `YA`: `(TX, RX) = (Y1, Y2) = (PC6, PC7)`
|
||||
/// - `UART(3)` is on `YB`: `(TX, RX) = (Y9, Y10) = (PB10, PB11)`
|
||||
/// - `UART(2)` is on: `(TX, RX) = (X3, X4) = (PA2, PA3)`
|
||||
STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
||||
|
@ -320,53 +320,53 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
|
|||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("UART(%d) is reserved"), uart_id);
|
||||
}
|
||||
|
||||
pyb_uart_obj_t *self;
|
||||
if (MP_STATE_PORT(pyb_uart_obj_all)[uart_id] == NULL) {
|
||||
machine_uart_obj_t *self;
|
||||
if (MP_STATE_PORT(machine_uart_obj_all)[uart_id] == NULL) {
|
||||
// create new UART object
|
||||
self = m_new0(pyb_uart_obj_t, 1);
|
||||
self->base.type = &pyb_uart_type;
|
||||
self = m_new0(machine_uart_obj_t, 1);
|
||||
self->base.type = &machine_uart_type;
|
||||
self->uart_id = uart_id;
|
||||
MP_STATE_PORT(pyb_uart_obj_all)[uart_id] = self;
|
||||
MP_STATE_PORT(machine_uart_obj_all)[uart_id] = self;
|
||||
} else {
|
||||
// reference existing UART object
|
||||
self = MP_STATE_PORT(pyb_uart_obj_all)[uart_id];
|
||||
self = MP_STATE_PORT(machine_uart_obj_all)[uart_id];
|
||||
}
|
||||
|
||||
// start the peripheral
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
|
||||
pyb_uart_init_helper(self, n_args - 1, args + 1, &kw_args);
|
||||
machine_uart_init_helper(self, n_args - 1, args + 1, &kw_args);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t pyb_uart_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
return pyb_uart_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args);
|
||||
STATIC mp_obj_t machine_uart_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
return machine_uart_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_init_obj, 1, pyb_uart_init);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_uart_init_obj, 1, machine_uart_init);
|
||||
|
||||
/// \method deinit()
|
||||
/// Turn off the UART bus.
|
||||
STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_obj_t machine_uart_deinit(mp_obj_t self_in) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uart_deinit(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_deinit_obj, pyb_uart_deinit);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_deinit_obj, machine_uart_deinit);
|
||||
|
||||
/// \method any()
|
||||
/// Return `True` if any characters waiting, else `False`.
|
||||
STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_obj_t machine_uart_any(mp_obj_t self_in) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return MP_OBJ_NEW_SMALL_INT(uart_rx_any(self));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_any_obj, machine_uart_any);
|
||||
|
||||
/// \method writechar(char)
|
||||
/// Write a single character on the bus. `char` is an integer to write.
|
||||
/// Return value: `None`.
|
||||
STATIC mp_obj_t pyb_uart_writechar(mp_obj_t self_in, mp_obj_t char_in) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_obj_t machine_uart_writechar(mp_obj_t self_in, mp_obj_t char_in) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// get the character to write (might be 9 bits)
|
||||
uint16_t data = mp_obj_get_int(char_in);
|
||||
|
@ -385,13 +385,13 @@ STATIC mp_obj_t pyb_uart_writechar(mp_obj_t self_in, mp_obj_t char_in) {
|
|||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_uart_writechar_obj, pyb_uart_writechar);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_uart_writechar_obj, machine_uart_writechar);
|
||||
|
||||
/// \method readchar()
|
||||
/// Receive a single character on the bus.
|
||||
/// Return value: The character read, as an integer. Returns -1 on timeout.
|
||||
STATIC mp_obj_t pyb_uart_readchar(mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_obj_t machine_uart_readchar(mp_obj_t self_in) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (uart_rx_wait(self, self->timeout)) {
|
||||
return MP_OBJ_NEW_SMALL_INT(uart_rx_char(self));
|
||||
} else {
|
||||
|
@ -399,21 +399,21 @@ STATIC mp_obj_t pyb_uart_readchar(mp_obj_t self_in) {
|
|||
return MP_OBJ_NEW_SMALL_INT(-1);
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_readchar_obj, pyb_uart_readchar);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_readchar_obj, machine_uart_readchar);
|
||||
|
||||
// uart.sendbreak()
|
||||
STATIC mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_obj_t machine_uart_sendbreak(mp_obj_t self_in) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
ra_sci_tx_break((uint32_t)self->uart_id);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_sendbreak_obj, pyb_uart_sendbreak);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_sendbreak_obj, machine_uart_sendbreak);
|
||||
|
||||
// irq(handler, trigger, hard)
|
||||
STATIC mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC mp_obj_t machine_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_val_t args[MP_IRQ_ARG_INIT_NUM_ARGS];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_IRQ_ARG_INIT_NUM_ARGS, mp_irq_init_args, args);
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
|
||||
if (self->mp_irq_obj == NULL) {
|
||||
self->mp_irq_trigger = 0;
|
||||
|
@ -444,14 +444,14 @@ STATIC mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
|
|||
|
||||
return MP_OBJ_FROM_PTR(self->mp_irq_obj);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_irq_obj, 1, pyb_uart_irq);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_uart_irq_obj, 1, machine_uart_irq);
|
||||
|
||||
STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
|
||||
STATIC const mp_rom_map_elem_t machine_uart_locals_dict_table[] = {
|
||||
// instance methods
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_uart_init_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_uart_deinit_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_any), MP_ROM_PTR(&pyb_uart_any_obj) },
|
||||
{ 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_any), MP_ROM_PTR(&machine_uart_any_obj) },
|
||||
|
||||
/// \method read([nbytes])
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||
|
@ -461,21 +461,21 @@ STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
||||
/// \method write(buf)
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_uart_irq_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&machine_uart_irq_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_writechar), MP_ROM_PTR(&pyb_uart_writechar_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readchar), MP_ROM_PTR(&pyb_uart_readchar_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_sendbreak), MP_ROM_PTR(&pyb_uart_sendbreak_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_writechar), MP_ROM_PTR(&machine_uart_writechar_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readchar), MP_ROM_PTR(&machine_uart_readchar_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_sendbreak), MP_ROM_PTR(&machine_uart_sendbreak_obj) },
|
||||
|
||||
// class constants
|
||||
{ MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_INT(UART_HWCONTROL_RTS) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_INT(UART_HWCONTROL_CTS) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(machine_uart_locals_dict, machine_uart_locals_dict_table);
|
||||
|
||||
STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_uint_t machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
byte *buf = buf_in;
|
||||
|
||||
// check that size is a multiple of character width
|
||||
|
@ -516,8 +516,8 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
|
|||
}
|
||||
}
|
||||
|
||||
STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_uint_t machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
const byte *buf = buf_in;
|
||||
|
||||
// check that size is a multiple of character width
|
||||
|
@ -545,8 +545,8 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
|
|||
}
|
||||
}
|
||||
|
||||
STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_uint_t machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_uint_t ret;
|
||||
if (request == MP_STREAM_POLL) {
|
||||
uintptr_t flags = arg;
|
||||
|
@ -565,19 +565,19 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t a
|
|||
}
|
||||
|
||||
STATIC const mp_stream_p_t uart_stream_p = {
|
||||
.read = pyb_uart_read,
|
||||
.write = pyb_uart_write,
|
||||
.ioctl = pyb_uart_ioctl,
|
||||
.read = machine_uart_read,
|
||||
.write = machine_uart_write,
|
||||
.ioctl = machine_uart_ioctl,
|
||||
.is_text = false,
|
||||
};
|
||||
|
||||
const mp_obj_type_t pyb_uart_type = {
|
||||
const mp_obj_type_t machine_uart_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_UART,
|
||||
.print = pyb_uart_print,
|
||||
.make_new = pyb_uart_make_new,
|
||||
.print = machine_uart_print,
|
||||
.make_new = machine_uart_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &uart_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&pyb_uart_locals_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&machine_uart_locals_dict,
|
||||
};
|
||||
|
|
|
@ -73,8 +73,8 @@ STATIC pyb_thread_t pyb_thread_main;
|
|||
#ifndef MICROPY_HW_UART_REPL_RXBUF
|
||||
#define MICROPY_HW_UART_REPL_RXBUF (260)
|
||||
#endif
|
||||
STATIC pyb_uart_obj_t pyb_uart_repl_obj;
|
||||
STATIC uint8_t pyb_uart_repl_rxbuf[MICROPY_HW_UART_REPL_RXBUF];
|
||||
STATIC machine_uart_obj_t machine_uart_repl_obj;
|
||||
STATIC uint8_t machine_uart_repl_rxbuf[MICROPY_HW_UART_REPL_RXBUF];
|
||||
#endif
|
||||
|
||||
void NORETURN __fatal_error(const char *msg) {
|
||||
|
@ -241,17 +241,17 @@ void ra_main(uint32_t reset_mode) {
|
|||
|
||||
#if defined(MICROPY_HW_UART_REPL)
|
||||
// Set up a UART REPL using a statically allocated object
|
||||
pyb_uart_repl_obj.base.type = &pyb_uart_type;
|
||||
pyb_uart_repl_obj.uart_id = MICROPY_HW_UART_REPL;
|
||||
pyb_uart_repl_obj.is_static = true;
|
||||
pyb_uart_repl_obj.timeout = 0;
|
||||
pyb_uart_repl_obj.timeout_char = 2;
|
||||
uart_init(&pyb_uart_repl_obj, MICROPY_HW_UART_REPL_BAUD, UART_WORDLENGTH_8B, UART_PARITY_NONE, UART_STOPBITS_1, 0);
|
||||
uart_set_rxbuf(&pyb_uart_repl_obj, sizeof(pyb_uart_repl_rxbuf), pyb_uart_repl_rxbuf);
|
||||
uart_attach_to_repl(&pyb_uart_repl_obj, true);
|
||||
MP_STATE_PORT(pyb_uart_obj_all)[MICROPY_HW_UART_REPL] = &pyb_uart_repl_obj;
|
||||
machine_uart_repl_obj.base.type = &machine_uart_type;
|
||||
machine_uart_repl_obj.uart_id = MICROPY_HW_UART_REPL;
|
||||
machine_uart_repl_obj.is_static = true;
|
||||
machine_uart_repl_obj.timeout = 0;
|
||||
machine_uart_repl_obj.timeout_char = 2;
|
||||
uart_init(&machine_uart_repl_obj, MICROPY_HW_UART_REPL_BAUD, UART_WORDLENGTH_8B, UART_PARITY_NONE, UART_STOPBITS_1, 0);
|
||||
uart_set_rxbuf(&machine_uart_repl_obj, sizeof(machine_uart_repl_rxbuf), machine_uart_repl_rxbuf);
|
||||
uart_attach_to_repl(&machine_uart_repl_obj, true);
|
||||
MP_STATE_PORT(machine_uart_obj_all)[MICROPY_HW_UART_REPL] = &machine_uart_repl_obj;
|
||||
#if RA_EARLY_PRINT
|
||||
MP_STATE_PORT(pyb_stdio_uart) = &pyb_uart_repl_obj;
|
||||
MP_STATE_PORT(pyb_stdio_uart) = &machine_uart_repl_obj;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -293,7 +293,7 @@ soft_reset:
|
|||
// by boot.py must be set after boot.py is run.
|
||||
|
||||
#if defined(MICROPY_HW_UART_REPL)
|
||||
MP_STATE_PORT(pyb_stdio_uart) = &pyb_uart_repl_obj;
|
||||
MP_STATE_PORT(pyb_stdio_uart) = &machine_uart_repl_obj;
|
||||
#else
|
||||
MP_STATE_PORT(pyb_stdio_uart) = NULL;
|
||||
#endif
|
||||
|
|
|
@ -285,7 +285,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&machine_hard_spi_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SoftSPI), MP_ROM_PTR(&mp_machine_soft_spi_type) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&pyb_uart_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&machine_uart_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(PYB_RESET_POWER_ON) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_HARD_RESET), MP_ROM_INT(PYB_RESET_HARD) },
|
||||
|
|
|
@ -48,15 +48,15 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_uos_sync_obj, mp_uos_sync);
|
|||
|
||||
bool mp_uos_dupterm_is_builtin_stream(mp_const_obj_t stream) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(stream);
|
||||
return type == &pyb_uart_type;
|
||||
return type == &machine_uart_type;
|
||||
}
|
||||
|
||||
void mp_uos_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached) {
|
||||
if (mp_obj_get_type(stream_detached) == &pyb_uart_type) {
|
||||
if (mp_obj_get_type(stream_detached) == &machine_uart_type) {
|
||||
uart_attach_to_repl(MP_OBJ_TO_PTR(stream_detached), false);
|
||||
}
|
||||
|
||||
if (mp_obj_get_type(stream_attached) == &pyb_uart_type) {
|
||||
if (mp_obj_get_type(stream_attached) == &machine_uart_type) {
|
||||
uart_attach_to_repl(MP_OBJ_TO_PTR(stream_attached), true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,10 +220,10 @@ extern const struct _mp_obj_module_t mp_module_onewire;
|
|||
struct _pyb_timer_obj_t *pyb_timer_obj_all[MICROPY_HW_MAX_TIMER]; \
|
||||
\
|
||||
/* stdio is repeated on this UART object if it's not null */ \
|
||||
struct _pyb_uart_obj_t *pyb_stdio_uart; \
|
||||
struct _machine_uart_obj_t *pyb_stdio_uart; \
|
||||
\
|
||||
/* pointers to all UART objects (if they have been created) */ \
|
||||
struct _pyb_uart_obj_t *pyb_uart_obj_all[MICROPY_HW_MAX_UART + MICROPY_HW_MAX_LPUART]; \
|
||||
struct _machine_uart_obj_t *machine_uart_obj_all[MICROPY_HW_MAX_UART + MICROPY_HW_MAX_LPUART]; \
|
||||
\
|
||||
/* list of registered NICs */ \
|
||||
/* mp_obj_list_t mod_network_nic_list; */ \
|
||||
|
|
|
@ -64,7 +64,7 @@ static void set_kbd_interrupt(uint32_t ch, void *keyex) {
|
|||
#endif
|
||||
|
||||
static void uart_rx_cb(uint32_t ch, int d) {
|
||||
pyb_uart_obj_t *self = MP_STATE_PORT(pyb_uart_obj_all)[ch];
|
||||
machine_uart_obj_t *self = MP_STATE_PORT(machine_uart_obj_all)[ch];
|
||||
if (self == NULL) {
|
||||
// UART object has not been set, so we can't do anything, not
|
||||
// even disable the IRQ. This should never happen.
|
||||
|
@ -86,18 +86,18 @@ void uart_init0(void) {
|
|||
|
||||
// unregister all interrupt sources
|
||||
void uart_deinit_all(void) {
|
||||
for (int i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(pyb_uart_obj_all)); i++) {
|
||||
pyb_uart_obj_t *uart_obj = MP_STATE_PORT(pyb_uart_obj_all)[i];
|
||||
for (int i = 0; i < MP_ARRAY_SIZE(MP_STATE_PORT(machine_uart_obj_all)); i++) {
|
||||
machine_uart_obj_t *uart_obj = MP_STATE_PORT(machine_uart_obj_all)[i];
|
||||
if (uart_obj != NULL && !uart_obj->is_static) {
|
||||
uart_deinit(uart_obj);
|
||||
MP_STATE_PORT(pyb_uart_obj_all)[i] = NULL;
|
||||
MP_STATE_PORT(machine_uart_obj_all)[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool uart_exists(int uart_id) {
|
||||
if (uart_id > MP_ARRAY_SIZE(MP_STATE_PORT(pyb_uart_obj_all))) {
|
||||
// safeguard against pyb_uart_obj_all array being configured too small
|
||||
if (uart_id > MP_ARRAY_SIZE(MP_STATE_PORT(machine_uart_obj_all))) {
|
||||
// safeguard against machine_uart_obj_all array being configured too small
|
||||
return false;
|
||||
}
|
||||
switch (uart_id) {
|
||||
|
@ -157,7 +157,7 @@ bool uart_exists(int uart_id) {
|
|||
}
|
||||
|
||||
// assumes Init parameters have been set up correctly
|
||||
bool uart_init(pyb_uart_obj_t *uart_obj,
|
||||
bool uart_init(machine_uart_obj_t *uart_obj,
|
||||
uint32_t baudrate, uint32_t bits, uint32_t parity, uint32_t stop, uint32_t flow) {
|
||||
uart_obj->baudrate = (uint32_t)baudrate;
|
||||
uart_obj->bits = (uint8_t)bits;
|
||||
|
@ -374,7 +374,7 @@ bool uart_init(pyb_uart_obj_t *uart_obj,
|
|||
return true;
|
||||
}
|
||||
|
||||
void uart_irq_config(pyb_uart_obj_t *self, bool enable) {
|
||||
void uart_irq_config(machine_uart_obj_t *self, bool enable) {
|
||||
if (self->mp_irq_trigger) {
|
||||
if (enable) {
|
||||
ra_sci_rxirq_enable(self->uart_id);
|
||||
|
@ -384,7 +384,7 @@ void uart_irq_config(pyb_uart_obj_t *self, bool enable) {
|
|||
}
|
||||
}
|
||||
|
||||
void uart_set_rxbuf(pyb_uart_obj_t *self, size_t len, void *buf) {
|
||||
void uart_set_rxbuf(machine_uart_obj_t *self, size_t len, void *buf) {
|
||||
// len = 0 (no interrupt) is not supported. static buf is used.
|
||||
self->read_buf_len = len;
|
||||
self->read_buf = buf;
|
||||
|
@ -394,12 +394,12 @@ void uart_set_rxbuf(pyb_uart_obj_t *self, size_t len, void *buf) {
|
|||
}
|
||||
}
|
||||
|
||||
void uart_deinit(pyb_uart_obj_t *self) {
|
||||
void uart_deinit(machine_uart_obj_t *self) {
|
||||
self->is_enabled = false;
|
||||
ra_sci_deinit(self->uart_id);
|
||||
}
|
||||
|
||||
void uart_attach_to_repl(pyb_uart_obj_t *self, bool attached) {
|
||||
void uart_attach_to_repl(machine_uart_obj_t *self, bool attached) {
|
||||
self->attached_to_repl = attached;
|
||||
#if MICROPY_KBD_EXCEPTION
|
||||
if (attached) {
|
||||
|
@ -410,12 +410,12 @@ void uart_attach_to_repl(pyb_uart_obj_t *self, bool attached) {
|
|||
#endif
|
||||
}
|
||||
|
||||
mp_uint_t uart_rx_any(pyb_uart_obj_t *self) {
|
||||
mp_uint_t uart_rx_any(machine_uart_obj_t *self) {
|
||||
int ch = (int)self->uart_id;
|
||||
return ra_sci_rx_any(ch);
|
||||
}
|
||||
|
||||
mp_uint_t uart_tx_avail(pyb_uart_obj_t *self) {
|
||||
mp_uint_t uart_tx_avail(machine_uart_obj_t *self) {
|
||||
int ch = (int)self->uart_id;
|
||||
return ra_sci_tx_wait(ch);
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ mp_uint_t uart_tx_avail(pyb_uart_obj_t *self) {
|
|||
// Waits at most timeout milliseconds for at least 1 char to become ready for
|
||||
// reading (from buf or for direct reading).
|
||||
// Returns true if something available, false if not.
|
||||
bool uart_rx_wait(pyb_uart_obj_t *self, uint32_t timeout) {
|
||||
bool uart_rx_wait(machine_uart_obj_t *self, uint32_t timeout) {
|
||||
int ch = (int)self->uart_id;
|
||||
uint32_t start = HAL_GetTick();
|
||||
for (;;) {
|
||||
|
@ -438,14 +438,14 @@ bool uart_rx_wait(pyb_uart_obj_t *self, uint32_t timeout) {
|
|||
}
|
||||
|
||||
// assumes there is a character available
|
||||
int uart_rx_char(pyb_uart_obj_t *self) {
|
||||
int uart_rx_char(machine_uart_obj_t *self) {
|
||||
int ch = (int)self->uart_id;
|
||||
return ra_sci_rx_ch(ch);
|
||||
}
|
||||
|
||||
// Waits at most timeout milliseconds for TX register to become empty.
|
||||
// Returns true if can write, false if can't.
|
||||
bool uart_tx_wait(pyb_uart_obj_t *self, uint32_t timeout) {
|
||||
bool uart_tx_wait(machine_uart_obj_t *self, uint32_t timeout) {
|
||||
uint32_t start = HAL_GetTick();
|
||||
for (;;) {
|
||||
if (uart_tx_avail(self)) {
|
||||
|
@ -462,7 +462,7 @@ bool uart_tx_wait(pyb_uart_obj_t *self, uint32_t timeout) {
|
|||
// num_chars - number of characters to send (9-bit chars count for 2 bytes from src)
|
||||
// *errcode - returns 0 for success, MP_Exxx on error
|
||||
// returns the number of characters sent (valid even if there was an error)
|
||||
size_t uart_tx_data(pyb_uart_obj_t *self, const void *src_in, size_t num_chars, int *errcode) {
|
||||
size_t uart_tx_data(machine_uart_obj_t *self, const void *src_in, size_t num_chars, int *errcode) {
|
||||
int ch = (int)self->uart_id;
|
||||
uint8_t *d8 = (uint8_t *)src_in;
|
||||
uint16_t *d16 = (uint16_t *)src_in;
|
||||
|
@ -485,13 +485,13 @@ size_t uart_tx_data(pyb_uart_obj_t *self, const void *src_in, size_t num_chars,
|
|||
return (size_t)num_chars;
|
||||
}
|
||||
|
||||
void uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len) {
|
||||
void uart_tx_strn(machine_uart_obj_t *uart_obj, const char *str, uint len) {
|
||||
int errcode;
|
||||
uart_tx_data(uart_obj, str, len, &errcode);
|
||||
}
|
||||
|
||||
STATIC mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uart_irq_config(self, false);
|
||||
self->mp_irq_trigger = new_trigger;
|
||||
uart_irq_config(self, true);
|
||||
|
@ -499,7 +499,7 @@ STATIC mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) {
|
|||
}
|
||||
|
||||
STATIC mp_uint_t uart_irq_info(mp_obj_t self_in, mp_uint_t info_type) {
|
||||
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (info_type == MP_IRQ_INFO_FLAGS) {
|
||||
return self->mp_irq_flags;
|
||||
} else if (info_type == MP_IRQ_INFO_TRIGGERS) {
|
||||
|
|
|
@ -42,7 +42,7 @@ typedef enum {
|
|||
HW_UART_7 = 7,
|
||||
HW_UART_8 = 8,
|
||||
HW_UART_9 = 9,
|
||||
} pyb_uart_t;
|
||||
} machine_uart_t;
|
||||
|
||||
#define CHAR_WIDTH_8BIT (0)
|
||||
#define CHAR_WIDTH_9BIT (1)
|
||||
|
@ -63,9 +63,9 @@ typedef enum {
|
|||
// OR-ed IRQ flags which should not be touched by the user
|
||||
#define MP_UART_RESERVED_FLAGS ((uint16_t)0x0020)
|
||||
|
||||
typedef struct _pyb_uart_obj_t {
|
||||
typedef struct _machine_uart_obj_t {
|
||||
mp_obj_base_t base;
|
||||
pyb_uart_t uart_id : 8;
|
||||
machine_uart_t uart_id : 8;
|
||||
uint32_t baudrate;
|
||||
const machine_pin_obj_t *rx;
|
||||
const machine_pin_obj_t *tx;
|
||||
|
@ -87,29 +87,29 @@ typedef struct _pyb_uart_obj_t {
|
|||
uint16_t mp_irq_trigger; // user IRQ trigger mask
|
||||
uint16_t mp_irq_flags; // user IRQ active IRQ flags
|
||||
mp_irq_obj_t *mp_irq_obj; // user IRQ object
|
||||
} pyb_uart_obj_t;
|
||||
} machine_uart_obj_t;
|
||||
|
||||
extern const mp_obj_type_t pyb_uart_type;
|
||||
extern const mp_obj_type_t machine_uart_type;
|
||||
extern const mp_irq_methods_t uart_irq_methods;
|
||||
|
||||
void uart_init0(void);
|
||||
void uart_deinit_all(void);
|
||||
bool uart_exists(int uart_id);
|
||||
bool uart_init(pyb_uart_obj_t *uart_obj,
|
||||
bool uart_init(machine_uart_obj_t *uart_obj,
|
||||
uint32_t baudrate, uint32_t bits, uint32_t parity, uint32_t stop, uint32_t flow);
|
||||
void uart_irq_config(pyb_uart_obj_t *self, bool enable);
|
||||
void uart_set_rxbuf(pyb_uart_obj_t *self, size_t len, void *buf);
|
||||
void uart_deinit(pyb_uart_obj_t *uart_obj);
|
||||
void uart_irq_config(machine_uart_obj_t *self, bool enable);
|
||||
void uart_set_rxbuf(machine_uart_obj_t *self, size_t len, void *buf);
|
||||
void uart_deinit(machine_uart_obj_t *uart_obj);
|
||||
// void uart_irq_handler(mp_uint_t uart_id);
|
||||
|
||||
void uart_attach_to_repl(pyb_uart_obj_t *self, bool attached);
|
||||
uint32_t uart_get_baudrate(pyb_uart_obj_t *self);
|
||||
mp_uint_t uart_rx_any(pyb_uart_obj_t *uart_obj);
|
||||
mp_uint_t uart_tx_avail(pyb_uart_obj_t *uart_obj);
|
||||
bool uart_rx_wait(pyb_uart_obj_t *self, uint32_t timeout);
|
||||
int uart_rx_char(pyb_uart_obj_t *uart_obj);
|
||||
bool uart_tx_wait(pyb_uart_obj_t *self, uint32_t timeout);
|
||||
size_t uart_tx_data(pyb_uart_obj_t *self, const void *src_in, size_t num_chars, int *errcode);
|
||||
void uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len);
|
||||
void uart_attach_to_repl(machine_uart_obj_t *self, bool attached);
|
||||
uint32_t uart_get_baudrate(machine_uart_obj_t *self);
|
||||
mp_uint_t uart_rx_any(machine_uart_obj_t *uart_obj);
|
||||
mp_uint_t uart_tx_avail(machine_uart_obj_t *uart_obj);
|
||||
bool uart_rx_wait(machine_uart_obj_t *self, uint32_t timeout);
|
||||
int uart_rx_char(machine_uart_obj_t *uart_obj);
|
||||
bool uart_tx_wait(machine_uart_obj_t *self, uint32_t timeout);
|
||||
size_t uart_tx_data(machine_uart_obj_t *self, const void *src_in, size_t num_chars, int *errcode);
|
||||
void uart_tx_strn(machine_uart_obj_t *uart_obj, const char *str, uint len);
|
||||
|
||||
#endif // MICROPY_INCLUDED_RA_UART_H
|
||||
|
|
Loading…
Reference in New Issue