Skip to content

Commit

Permalink
house clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Nov 2, 2023
1 parent 03bfda3 commit 9d5e6a2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/arduino/Adafruit_USBH_Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void tuh_max3421_spi_cs_api(uint8_t rhport, bool active) {
return;
}
Adafruit_USBH_Host *host = Adafruit_USBH_Host::_instance;
SPIClass *spi = host->_spi;

if (active) {
// MAX3421e max clock is 26MHz
Expand All @@ -213,10 +214,10 @@ void tuh_max3421_spi_cs_api(uint8_t rhport, bool active) {
uint32_t const max_clock = 26000000ul;
#endif

host->_spi->beginTransaction(SPISettings(max_clock, MSBFIRST, SPI_MODE0));
spi->beginTransaction(SPISettings(max_clock, MSBFIRST, SPI_MODE0));
digitalWrite(Adafruit_USBH_Host::_instance->_cs, LOW);
} else {
host->_spi->endTransaction();
spi->endTransaction();
digitalWrite(Adafruit_USBH_Host::_instance->_cs, HIGH);
}
}
Expand All @@ -229,6 +230,7 @@ bool tuh_max3421_spi_xfer_api(uint8_t rhport, uint8_t const *tx_buf,
return false;
}
Adafruit_USBH_Host *host = Adafruit_USBH_Host::_instance;
SPIClass *spi = host->_spi;

#ifdef ARDUINO_ARCH_SAMD
// SAMD cannot use transfer(tx_buf, rx_buf, len) API since it default to use
Expand All @@ -240,16 +242,16 @@ bool tuh_max3421_spi_xfer_api(uint8_t rhport, uint8_t const *tx_buf,
if (tx_buf) {
data = tx_buf[count];
}
data = host->_spi->transfer(data);
data = spi->transfer(data);

if (rx_buf) {
rx_buf[count] = data;
}
}
#elif defined(ARDUINO_ARCH_ESP32)
host->_spi->transferBytes(tx_buf, rx_buf, xfer_bytes);
spi->transferBytes(tx_buf, rx_buf, xfer_bytes);
#else
host->_spi->transfer(tx_buf, rx_buf, xfer_bytes);
spi->transfer(tx_buf, rx_buf, xfer_bytes);
#endif

return true;
Expand Down

0 comments on commit 9d5e6a2

Please sign in to comment.