Skip to content

Commit

Permalink
Merge pull request #18 from KurtE/spi_updates
Browse files Browse the repository at this point in the history
SPI - Fix Transfer16 plus allow subclass to gain access to member var…
  • Loading branch information
facchinm authored Dec 19, 2024
2 parents 0d328e5 + 07c766a commit be17eab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ uint16_t arduino::ZephyrSPI::transfer16(uint16_t data) {
.count = 1,
};

ret = spi_transceive(spi_dev, &config, &tx_buf_set, &rx_buf_set);
ret = spi_transceive(spi_dev, &config16, &tx_buf_set, &rx_buf_set);
if (ret < 0) {
return 0;
}
Expand Down Expand Up @@ -85,7 +85,10 @@ void arduino::ZephyrSPI::notUsingInterrupt(int interruptNumber) {

void arduino::ZephyrSPI::beginTransaction(SPISettings settings) {
memset(&config, 0, sizeof(config));
memset(&config16, 0, sizeof(config16));
config.frequency = settings.getClockFreq() > SPI_MIN_CLOCK_FEQUENCY ? settings.getClockFreq() : SPI_MIN_CLOCK_FEQUENCY;
config16.frequency = config.frequency;

auto mode = SPI_MODE_CPOL | SPI_MODE_CPHA;
switch (settings.getDataMode()) {
case SPI_MODE0:
Expand All @@ -98,6 +101,7 @@ void arduino::ZephyrSPI::beginTransaction(SPISettings settings) {
mode = SPI_MODE_CPOL | SPI_MODE_CPHA; break;
}
config.operation = SPI_WORD_SET(8) | (settings.getBitOrder() == MSBFIRST ? SPI_TRANSFER_MSB : SPI_TRANSFER_LSB) | mode;
config16.operation = SPI_WORD_SET(16) | (settings.getBitOrder() == MSBFIRST ? SPI_TRANSFER_MSB : SPI_TRANSFER_LSB) | mode;
}

void arduino::ZephyrSPI::endTransaction(void) {
Expand All @@ -109,7 +113,10 @@ void arduino::ZephyrSPI::attachInterrupt() {}
void arduino::ZephyrSPI::detachInterrupt() {}


void arduino::ZephyrSPI::begin() {}
void arduino::ZephyrSPI::begin() {
beginTransaction(SPISettings());
endTransaction();
}

void arduino::ZephyrSPI::end() {}

Expand Down
3 changes: 2 additions & 1 deletion libraries/SPI/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ class ZephyrSPI : public HardwareSPI {
virtual void begin();
virtual void end();

private:
protected:
const struct device *spi_dev;
struct spi_config config;
struct spi_config config16;
int interrupt[INTERRUPT_COUNT];
size_t interrupt_pos = 0;
};
Expand Down

0 comments on commit be17eab

Please sign in to comment.