Skip to content

spresense: minor changes for i2c, spi and uart #4412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ports/cxd56/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions ports/cxd56/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <arch/chip/pin.h>
#include <cxd56_spi.h>
#include <cxd56_pinconfig.h>

#include "py/runtime.h"

Expand All @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions ports/cxd56/common-hal/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down