diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2018-02-26 17:40:13 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-26 17:40:13 -0800 |
| commit | 586be2eb222fda72349ed8e85d715402f947b816 (patch) | |
| tree | 91f8c149cff3df9b24e70afa4da9e12616d1006a | |
| parent | 6723c44d5a11f22393293c9255380a520cbc0659 (diff) | |
| parent | 907b4417c08cb7cfb6b1ce9a1baa7af481fa398b (diff) | |
Merge pull request #643 from dhalbert/3.0_esp8266_uart1
Add .baudrate support to ESP8266.
| -rw-r--r-- | ports/esp8266/common-hal/busio/UART.c | 18 | ||||
| -rw-r--r-- | ports/esp8266/common-hal/busio/UART.h | 1 |
2 files changed, 17 insertions, 2 deletions
diff --git a/ports/esp8266/common-hal/busio/UART.c b/ports/esp8266/common-hal/busio/UART.c index 8d6e0b7bc..9b5d86ef5 100644 --- a/ports/esp8266/common-hal/busio/UART.c +++ b/ports/esp8266/common-hal/busio/UART.c @@ -40,11 +40,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, uint32_t timeout, uint8_t receiver_buffer_size) { - if (rx != NULL || tx != &pin_GPIO2) { + if (rx != mp_const_none || tx != &pin_GPIO2) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Only tx supported on UART1 (GPIO2).")); } + // set baudrate UartDev.baut_rate = baudrate; + self->baudrate = baudrate; // set data bits switch (bits) { @@ -90,6 +92,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, } uart_setup(UART1); + self->deinited = false; } bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { @@ -100,7 +103,8 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { if (common_hal_busio_uart_deinited(self)) { return; } - PIN_FUNC_SELECT(FUNC_U1TXD_BK, 0); + // Switch GPIO2 back to a GPIO pin. + PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); self->deinited = true; } @@ -119,6 +123,16 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data, return len; } +uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) { + return self->baudrate; +} + +void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) { + UartDev.baut_rate = baudrate; + uart_setup(UART1); + self->baudrate = baudrate; +} + uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) { return 0; } diff --git a/ports/esp8266/common-hal/busio/UART.h b/ports/esp8266/common-hal/busio/UART.h index d5dd138ad..9b75b66a3 100644 --- a/ports/esp8266/common-hal/busio/UART.h +++ b/ports/esp8266/common-hal/busio/UART.h @@ -33,6 +33,7 @@ typedef struct { mp_obj_base_t base; + uint32_t baudrate; bool deinited; } busio_uart_obj_t; |
