Skip to content

Commit be17eab

Browse files
authored
Merge pull request #18 from KurtE/spi_updates
SPI - Fix Transfer16 plus allow subclass to gain access to member var…
2 parents 0d328e5 + 07c766a commit be17eab

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

libraries/SPI/SPI.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ uint16_t arduino::ZephyrSPI::transfer16(uint16_t data) {
4646
.count = 1,
4747
};
4848

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

8686
void arduino::ZephyrSPI::beginTransaction(SPISettings settings) {
8787
memset(&config, 0, sizeof(config));
88+
memset(&config16, 0, sizeof(config16));
8889
config.frequency = settings.getClockFreq() > SPI_MIN_CLOCK_FEQUENCY ? settings.getClockFreq() : SPI_MIN_CLOCK_FEQUENCY;
90+
config16.frequency = config.frequency;
91+
8992
auto mode = SPI_MODE_CPOL | SPI_MODE_CPHA;
9093
switch (settings.getDataMode()) {
9194
case SPI_MODE0:
@@ -98,6 +101,7 @@ void arduino::ZephyrSPI::beginTransaction(SPISettings settings) {
98101
mode = SPI_MODE_CPOL | SPI_MODE_CPHA; break;
99102
}
100103
config.operation = SPI_WORD_SET(8) | (settings.getBitOrder() == MSBFIRST ? SPI_TRANSFER_MSB : SPI_TRANSFER_LSB) | mode;
104+
config16.operation = SPI_WORD_SET(16) | (settings.getBitOrder() == MSBFIRST ? SPI_TRANSFER_MSB : SPI_TRANSFER_LSB) | mode;
101105
}
102106

103107
void arduino::ZephyrSPI::endTransaction(void) {
@@ -109,7 +113,10 @@ void arduino::ZephyrSPI::attachInterrupt() {}
109113
void arduino::ZephyrSPI::detachInterrupt() {}
110114

111115

112-
void arduino::ZephyrSPI::begin() {}
116+
void arduino::ZephyrSPI::begin() {
117+
beginTransaction(SPISettings());
118+
endTransaction();
119+
}
113120

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

libraries/SPI/SPI.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ class ZephyrSPI : public HardwareSPI {
5050
virtual void begin();
5151
virtual void end();
5252

53-
private:
53+
protected:
5454
const struct device *spi_dev;
5555
struct spi_config config;
56+
struct spi_config config16;
5657
int interrupt[INTERRUPT_COUNT];
5758
size_t interrupt_pos = 0;
5859
};

0 commit comments

Comments
 (0)