From 76d0870fba5a86813242c37ee653c1fc7e008c65 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Thu, 11 Mar 2021 18:04:01 +0100 Subject: [PATCH 1/2] spresense: return error as positive value for i2c --- ports/cxd56/common-hal/busio/I2C.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/cxd56/common-hal/busio/I2C.c b/ports/cxd56/common-hal/busio/I2C.c index 127b6e75cd..5579bedeb1 100644 --- a/ports/cxd56/common-hal/busio/I2C.c +++ b/ports/cxd56/common-hal/busio/I2C.c @@ -103,7 +103,7 @@ uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t address, cons msg.flags = (stop ? 0 : I2C_M_NOSTOP); msg.buffer = (uint8_t *) data; msg.length = len; - return I2C_TRANSFER(self->i2c_dev, &msg, 1); + return -I2C_TRANSFER(self->i2c_dev, &msg, 1); } uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t address, uint8_t *data, size_t len) { @@ -114,7 +114,7 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t address, uint8 msg.flags = I2C_M_READ; msg.buffer = data; msg.length = len; - return I2C_TRANSFER(self->i2c_dev, &msg, 1); + return -I2C_TRANSFER(self->i2c_dev, &msg, 1); } void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { From 18668f6e2848a5a36d37df42354ecd1ee53786ba Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Thu, 11 Mar 2021 18:06:49 +0100 Subject: [PATCH 2/2] spresense: fix spi to work with only one data pin --- ports/cxd56/common-hal/busio/SPI.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ports/cxd56/common-hal/busio/SPI.c b/ports/cxd56/common-hal/busio/SPI.c index 2d365d4826..56ab0758d4 100644 --- a/ports/cxd56/common-hal/busio/SPI.c +++ b/ports/cxd56/common-hal/busio/SPI.c @@ -35,9 +35,13 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t * const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso) { int port = -1; - if (clock->number == PIN_SPI4_SCK && mosi->number == PIN_SPI4_MOSI && miso->number == PIN_SPI4_MISO) { + if (clock->number == PIN_SPI4_SCK && + (mosi == NULL || mosi->number == PIN_SPI4_MOSI) && + (miso == NULL || miso->number == PIN_SPI4_MISO)) { port = 4; - } else if (clock->number == PIN_EMMC_CLK && mosi->number == PIN_EMMC_DATA0 && miso->number == PIN_EMMC_DATA1) { + } else if (clock->number == PIN_EMMC_CLK && + (mosi == NULL || mosi->number == PIN_EMMC_DATA0) && + (miso == NULL || miso->number == PIN_EMMC_DATA1)) { port = 5; }