Merge pull request #411 from adafruit/fix-spim-gfx

fix spim is limit up to 64KB each transfer
This commit is contained in:
Limor "Ladyada" Fried authored and GitHub committed 2020-01-09 21:38:58 -05:00
commit 4159172545
1 file changed
+23 -17
+23 -17
View File
@@ -193,28 +193,34 @@ void SPIClass::setClockDivider(uint32_t div)
void SPIClass::transfer(const void *tx_buf, void *rx_buf, size_t count)
{
nrfx_spim_xfer_desc_t xfer_desc =
{
.p_tx_buffer = (uint8_t*) tx_buf,
.tx_length = tx_buf ? count : 0,
.p_rx_buffer = (uint8_t*) rx_buf,
.rx_length = rx_buf ? count : 0,
};
const uint8_t* tx_buf8 = (const uint8_t*) tx_buf;
uint8_t* rx_buf8 = (uint8_t*) rx_buf;
nrfx_spim_xfer(&_spim, &xfer_desc, 0);
while (count)
{
// each transfer can only up to 64KB (16-bit) bytes
const size_t xfer_len = min(count, UINT16_MAX);
nrfx_spim_xfer_desc_t xfer_desc =
{
.p_tx_buffer = tx_buf8,
.tx_length = tx_buf8 ? xfer_len : 0,
.p_rx_buffer = rx_buf8,
.rx_length = rx_buf8 ? xfer_len : 0,
};
nrfx_spim_xfer(&_spim, &xfer_desc, 0);
count -= xfer_len;
if (tx_buf8) tx_buf8 += xfer_len;
if (rx_buf8) rx_buf8 += xfer_len;
}
}
void SPIClass::transfer(void *buf, size_t count)
{
nrfx_spim_xfer_desc_t xfer_desc =
{
.p_tx_buffer = (uint8_t*) buf,
.tx_length = count,
.p_rx_buffer = (uint8_t*) buf,
.rx_length = count,
};
nrfx_spim_xfer(&_spim, &xfer_desc, 0);
transfer(buf, buf, count);
}
byte SPIClass::transfer(uint8_t data)