Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading