Skip to content

Commit b7799f7

Browse files
committed
Updates the SPI driver to properly support dual, quad and octal modes.
1 parent 19dedff commit b7799f7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

micropy_updates/esp32/machine_hw_spi.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,12 @@ static void machine_hw_spi_device_transfer(mp_obj_base_t *self_in, size_t len, c
319319

320320
transaction.flags = SPI_TRANS_USE_TXDATA | SPI_TRANS_USE_RXDATA;
321321
transaction.length = bits_to_send;
322-
323322
if (self->dual) {
324-
transaction.flags |= SPI_TRANS_MODE_DIO;
323+
transaction.flags |= SPI_TRANS_MODE_DIO | SPI_TRANS_MULTILINE_ADDR;
325324
} else if (self->quad) {
326-
transaction.flags |= SPI_TRANS_MODE_QIO;
325+
transaction.flags |= SPI_TRANS_MODE_QIO | SPI_TRANS_MULTILINE_ADDR;
327326
} else if (self->octal) {
328-
transaction.flags |= SPI_TRANS_MODE_OCT;
327+
transaction.flags |= SPI_TRANS_MODE_OCT _ SPI_TRANS_MULTILINE_ADDR;
329328
}
330329

331330
spi_device_transmit(spi_device, &transaction);
@@ -558,7 +557,7 @@ void mp_machine_hw_spi_bus_initilize(mp_machine_hw_spi_bus_obj_t *bus)
558557
.data5_io_num = (int)mp_obj_get_int(bus->data5),
559558
.data6_io_num = (int)mp_obj_get_int(bus->data6),
560559
.data7_io_num = (int)mp_obj_get_int(bus->data7),
561-
.flags = flags,
560+
.flags = SPICOMMON_BUSFLAG_MASTER,
562561
.max_transfer_sz = SPI_LL_DMA_MAX_BIT_LEN / 8
563562
};
564563

@@ -639,12 +638,18 @@ mp_obj_t machine_hw_spi_device_make_new(const mp_obj_type_t *type, size_t n_args
639638
self->quad = quad;
640639
self->octal = octal;
641640

641+
uint8_t flags = 0;
642+
643+
if (self->firstbit == MICROPY_PY_MACHINE_SPI_LSB) flags |= SPI_DEVICE_TXBIT_LSBFIRST | SPI_DEVICE_RXBIT_LSBFIRST;
644+
645+
if (dual || quad |m| octal) flags != SPI_DEVICE_HALFDUPLEX;
646+
642647
spi_device_interface_config_t devcfg = {
643648
.clock_speed_hz = (uint32_t)spi_get_actual_clock(APB_CLK_FREQ, args[ARG_freq].u_int, 0),
644649
.mode = self->phase | (self->polarity << 1),
645650
.spics_io_num = cs,
646651
.queue_size = 2,
647-
.flags = self->firstbit == MICROPY_PY_MACHINE_SPI_LSB ? SPI_DEVICE_TXBIT_LSBFIRST | SPI_DEVICE_RXBIT_LSBFIRST : 0,
652+
.flags = ,
648653
.pre_cb = NULL
649654
};
650655

0 commit comments

Comments
 (0)