aboutsummaryrefslogtreecommitdiff
path: root/ports/stm32/uart.c
diff options
context:
space:
mode:
authorDamien George2018-07-08 23:25:11 +1000
committerDamien George2018-07-08 23:25:11 +1000
commite1ae9939aca230758951f5b5b45084374e497254 (patch)
tree9b5e424e366e94395cd4976dd9acc6eb906e87ae /ports/stm32/uart.c
parentaa735dc6a478f1f99f6e433b89ca047cbf536f33 (diff)
stm32: Support compiling with object representation D.
With this and previous patches the stm32 port can now be compiled using object representation D (nan boxing). Note that native code and frozen mpy files with float constants are currently not supported with this object representation.
Diffstat (limited to 'ports/stm32/uart.c')
-rw-r--r--ports/stm32/uart.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/ports/stm32/uart.c b/ports/stm32/uart.c
index 1622c505c..6afa03486 100644
--- a/ports/stm32/uart.c
+++ b/ports/stm32/uart.c
@@ -123,7 +123,7 @@ void uart_deinit(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];
if (uart_obj != NULL) {
- pyb_uart_deinit(uart_obj);
+ pyb_uart_deinit(MP_OBJ_FROM_PTR(uart_obj));
}
}
}
@@ -542,7 +542,7 @@ void uart_irq_handler(mp_uint_t uart_id) {
/* MicroPython bindings */
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 = self_in;
+ pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (!self->is_enabled) {
mp_printf(print, "UART(%u)", self->uart_id);
} else {
@@ -596,7 +596,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_baudrate, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 9600} },
{ MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} },
- { MP_QSTR_parity, MP_ARG_OBJ, {.u_obj = mp_const_none} },
+ { MP_QSTR_parity, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
{ MP_QSTR_stop, MP_ARG_INT, {.u_int = 1} },
{ MP_QSTR_flow, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = UART_HWCONTROL_NONE} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000} },
@@ -835,18 +835,18 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size
pyb_uart_init_helper(self, n_args - 1, args + 1, &kw_args);
}
- return self;
+ 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(args[0], n_args - 1, args + 1, kw_args);
+ return pyb_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);
/// \method deinit()
/// Turn off the UART bus.
STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
- pyb_uart_obj_t *self = self_in;
+ pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
self->is_enabled = false;
UART_HandleTypeDef *uart = &self->uart;
HAL_UART_DeInit(uart);
@@ -912,7 +912,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_deinit_obj, pyb_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 = self_in;
+ pyb_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);
@@ -921,7 +921,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any);
/// 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 = self_in;
+ pyb_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);
@@ -946,7 +946,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_uart_writechar_obj, pyb_uart_writechar);
/// 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 = self_in;
+ pyb_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 {
@@ -958,7 +958,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_readchar_obj, pyb_uart_readchar);
// uart.sendbreak()
STATIC mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) {
- pyb_uart_obj_t *self = self_in;
+ pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
#if defined(STM32F0) || defined(STM32F7) || defined(STM32L4) || defined(STM32H7)
self->uart.Instance->RQR = USART_RQR_SBKRQ; // write-only register
#else
@@ -996,7 +996,7 @@ STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_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 = self_in;
+ pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
byte *buf = buf_in;
// check that size is a multiple of character width
@@ -1038,7 +1038,7 @@ 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 = self_in;
+ pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
const byte *buf = buf_in;
// check that size is a multiple of character width
@@ -1064,11 +1064,11 @@ 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, mp_uint_t arg, int *errcode) {
- pyb_uart_obj_t *self = self_in;
+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);
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
- mp_uint_t flags = arg;
+ uintptr_t flags = arg;
ret = 0;
if ((flags & MP_STREAM_POLL_RD) && uart_rx_any(self)) {
ret |= MP_STREAM_POLL_RD;