Skip to content

Commit a32359b

Browse files
authored
Merge pull request #4386 from kamtom480/spi_and_i2c
spresense: minor i2c and spi fixes
2 parents 3b948b2 + 18668f6 commit a32359b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

ports/cxd56/common-hal/busio/I2C.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t address, cons
103103
msg.flags = (stop ? 0 : I2C_M_NOSTOP);
104104
msg.buffer = (uint8_t *) data;
105105
msg.length = len;
106-
return I2C_TRANSFER(self->i2c_dev, &msg, 1);
106+
return -I2C_TRANSFER(self->i2c_dev, &msg, 1);
107107
}
108108

109109
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
114114
msg.flags = I2C_M_READ;
115115
msg.buffer = data;
116116
msg.length = len;
117-
return I2C_TRANSFER(self->i2c_dev, &msg, 1);
117+
return -I2C_TRANSFER(self->i2c_dev, &msg, 1);
118118
}
119119

120120
void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {

ports/cxd56/common-hal/busio/SPI.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
3535
const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso) {
3636
int port = -1;
3737

38-
if (clock->number == PIN_SPI4_SCK && mosi->number == PIN_SPI4_MOSI && miso->number == PIN_SPI4_MISO) {
38+
if (clock->number == PIN_SPI4_SCK &&
39+
(mosi == NULL || mosi->number == PIN_SPI4_MOSI) &&
40+
(miso == NULL || miso->number == PIN_SPI4_MISO)) {
3941
port = 4;
40-
} else if (clock->number == PIN_EMMC_CLK && mosi->number == PIN_EMMC_DATA0 && miso->number == PIN_EMMC_DATA1) {
42+
} else if (clock->number == PIN_EMMC_CLK &&
43+
(mosi == NULL || mosi->number == PIN_EMMC_DATA0) &&
44+
(miso == NULL || miso->number == PIN_EMMC_DATA1)) {
4145
port = 5;
4246
}
4347

0 commit comments

Comments
 (0)