Skip to content

Commit

Permalink
Merge pull request #3 from CikaElectronica/fiximpl
Browse files Browse the repository at this point in the history
Correct full-duplex transaction in ESP32 as per documentation.
  • Loading branch information
rojer authored Oct 26, 2020
2 parents fc4c3bb + d533ae6 commit abf4ec6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/esp32/esp32_spi_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ static void esp32_spi_get_rx_data(spi_dev_t *dev, uint8_t *data, size_t skip,
if (skip > 0) {
skip--;
} else {
data[i++] = byte;
if (data != NULL) data[i] = byte;
++i;
}
w >>= 8;
}
Expand Down Expand Up @@ -314,7 +315,7 @@ static bool mgos_spi_run_txn_fd(struct mgos_spi *c, const void *tx_data,
}
esp32_spi_get_rx_data(dev, rxdp, 0, dlen);
txdp += dlen;
rxdp += dlen;
if (rxdp != NULL) rxdp += dlen;
}

return true;
Expand Down
3 changes: 2 additions & 1 deletion src/stm32/stm32_spi_master_gspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ bool stm32_gspi_run_txn_fd(struct mgos_spi *c, const struct mgos_spi_txn *txn) {
size_t len = txn->fd.len;
const uint8_t *tx_data = (const uint8_t *) txn->fd.tx_data;
uint8_t *rx_data = (uint8_t *) txn->fd.rx_data;
bool discard_rx = (txn->fd.rx_data == NULL);
volatile uint8_t *drp = (volatile uint8_t *) &c->regs->DR;

if (c->debug) {
Expand All @@ -128,7 +129,7 @@ bool stm32_gspi_run_txn_fd(struct mgos_spi *c, const struct mgos_spi_txn *txn) {
if (c->debug) {
LOG(LL_DEBUG, ("read 0x%02x", byte));
}
*rx_data++ = byte;
if (!discard_rx) *rx_data++ = byte;
}
len--;
}
Expand Down

0 comments on commit abf4ec6

Please sign in to comment.