Skip to content
Snippets Groups Projects
Commit a2271532 authored by Damien George's avatar Damien George
Browse files

stm32: Split out UART Python bindings from uart.c to machine_uart.c.

parent 55830dd9
No related branches found
No related tags found
No related merge requests found
......@@ -243,6 +243,7 @@ SRC_C = \
help.c \
machine_i2c.c \
machine_spi.c \
machine_uart.c \
modmachine.c \
modpyb.c \
modstm.c \
......
This diff is collapsed.
......@@ -755,7 +755,7 @@ soft_reset_exit:
mod_network_deinit();
#endif
timer_deinit();
uart_deinit();
uart_deinit_all();
#if MICROPY_HW_ENABLE_CAN
can_deinit();
#endif
......
This diff is collapsed.
......@@ -38,16 +38,41 @@ typedef enum {
PYB_UART_8 = 8,
} pyb_uart_t;
typedef struct _pyb_uart_obj_t pyb_uart_obj_t;
#define CHAR_WIDTH_8BIT (0)
#define CHAR_WIDTH_9BIT (1)
typedef struct _pyb_uart_obj_t {
mp_obj_base_t base;
UART_HandleTypeDef uart; // this is 17 words big
IRQn_Type irqn;
pyb_uart_t uart_id : 8;
bool is_enabled : 1;
bool attached_to_repl; // whether the UART is attached to REPL
byte char_width; // 0 for 7,8 bit chars, 1 for 9 bit chars
uint16_t char_mask; // 0x7f for 7 bit, 0xff for 8 bit, 0x1ff for 9 bit
uint16_t timeout; // timeout waiting for first char
uint16_t timeout_char; // timeout waiting between chars
uint16_t read_buf_len; // len in chars; buf can hold len-1 chars
volatile uint16_t read_buf_head; // indexes first empty slot
uint16_t read_buf_tail; // indexes first full slot (not full if equals head)
byte *read_buf; // byte or uint16_t, depending on char size
} pyb_uart_obj_t;
extern const mp_obj_type_t pyb_uart_type;
void uart_init0(void);
void uart_deinit(void);
void uart_deinit_all(void);
bool uart_exists(int uart_id);
bool uart_init2(pyb_uart_obj_t *uart_obj);
void uart_deinit(pyb_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);
mp_uint_t uart_rx_any(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);
#endif // MICROPY_INCLUDED_STM32_UART_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment