diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2021-03-15 17:35:06 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-15 17:35:06 -0700 |
| commit | 9cb8ce67ed01d71c2142a60dd1d2c7a042a47bb0 (patch) | |
| tree | 101350a7490cc6659f741b885fa7796b6f4325af | |
| parent | 05ed179e11599dd45a76dfb14ecf624d0ff96d68 (diff) | |
| parent | ed3f636be5aaaaebea8e44746ea88298c6d187df (diff) | |
Merge pull request #4412 from kamtom480/spi_and_i2c
spresense: minor changes for i2c, spi and uart
| -rw-r--r-- | ports/cxd56/common-hal/busio/I2C.c | 2 | ||||
| -rw-r--r-- | ports/cxd56/common-hal/busio/SPI.c | 3 | ||||
| -rw-r--r-- | ports/cxd56/common-hal/busio/UART.c | 11 |
3 files changed, 16 insertions, 0 deletions
diff --git a/ports/cxd56/common-hal/busio/I2C.c b/ports/cxd56/common-hal/busio/I2C.c index 0e6dbedc0..7b9420fa1 100644 --- a/ports/cxd56/common-hal/busio/I2C.c +++ b/ports/cxd56/common-hal/busio/I2C.c @@ -27,6 +27,7 @@ #include <arch/chip/pin.h> #include <nuttx/i2c/i2c_master.h> #include <cxd56_i2c.h> +#include <cxd56_pinconfig.h> #include "py/runtime.h" @@ -49,6 +50,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t * self->sda_pin = sda; self->frequency = frequency; self->i2c_dev = cxd56_i2cbus_initialize(0); + CXD56_PIN_CONFIGS(PINCONFS_I2C0); } void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { diff --git a/ports/cxd56/common-hal/busio/SPI.c b/ports/cxd56/common-hal/busio/SPI.c index e77c0224d..ff834f7f3 100644 --- a/ports/cxd56/common-hal/busio/SPI.c +++ b/ports/cxd56/common-hal/busio/SPI.c @@ -26,6 +26,7 @@ #include <arch/chip/pin.h> #include <cxd56_spi.h> +#include <cxd56_pinconfig.h> #include "py/runtime.h" @@ -39,10 +40,12 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t * (mosi == NULL || mosi->number == PIN_SPI4_MOSI) && (miso == NULL || miso->number == PIN_SPI4_MISO)) { port = 4; + CXD56_PIN_CONFIGS(PINCONFS_SPI4); } else if (clock->number == PIN_EMMC_CLK && (mosi == NULL || mosi->number == PIN_EMMC_DATA0) && (miso == NULL || miso->number == PIN_EMMC_DATA1)) { port = 5; + CXD56_PIN_CONFIGS(PINCONFS_EMMCA_SPI5); } if (port < 0) { diff --git a/ports/cxd56/common-hal/busio/UART.c b/ports/cxd56/common-hal/busio/UART.c index f7588c710..91fbe5244 100644 --- a/ports/cxd56/common-hal/busio/UART.c +++ b/ports/cxd56/common-hal/busio/UART.c @@ -59,6 +59,9 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, uint32_t baudrate, uint8_t bits, busio_uart_parity_t parity, uint8_t stop, mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer, bool sigint_enabled) { + int i; + int count; + char tmp; struct termios tio; if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) { @@ -96,6 +99,14 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, if (busio_uart_dev[self->number].fd < 0) { mp_raise_ValueError(translate("Could not initialize UART")); } + + // Wait to make sure the UART is ready + usleep(1000); + // Clear RX FIFO + ioctl(busio_uart_dev[self->number].fd, FIONREAD, (long unsigned int)&count); + for (i = 0; i < count; i++) { + read(busio_uart_dev[self->number].fd, &tmp, 1); + } } ioctl(busio_uart_dev[self->number].fd, TCGETS, (long unsigned int)&tio); |
