aboutsummaryrefslogtreecommitdiff
path: root/ports/stm32/uart.h
diff options
context:
space:
mode:
Diffstat (limited to 'ports/stm32/uart.h')
-rw-r--r--ports/stm32/uart.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/ports/stm32/uart.h b/ports/stm32/uart.h
index fb7768db2..97781522c 100644
--- a/ports/stm32/uart.h
+++ b/ports/stm32/uart.h
@@ -43,7 +43,7 @@ typedef enum {
typedef struct _pyb_uart_obj_t {
mp_obj_base_t base;
- UART_HandleTypeDef uart; // this is 17 words big
+ USART_TypeDef *uartx;
IRQn_Type irqn;
pyb_uart_t uart_id : 8;
bool is_enabled : 1;
@@ -63,7 +63,7 @@ extern const mp_obj_type_t pyb_uart_type;
void uart_init0(void);
void uart_deinit_all(void);
bool uart_exists(int uart_id);
-bool uart_init2(pyb_uart_obj_t *uart_obj);
+bool uart_init2(pyb_uart_obj_t *uart_obj, UART_InitTypeDef *init);
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_handler(mp_uint_t uart_id);
@@ -77,4 +77,12 @@ 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);
+static inline bool uart_tx_avail(pyb_uart_obj_t *self) {
+ #if defined(STM32F4)
+ return self->uartx->SR & USART_SR_TXE;
+ #else
+ return self->uartx->ISR & USART_ISR_TXE;
+ #endif
+}
+
#endif // MICROPY_INCLUDED_STM32_UART_H