-
-
Notifications
You must be signed in to change notification settings - Fork 40
fix: SPI: remove holes between transfer() #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,28 +13,26 @@ arduino::ZephyrSPI::ZephyrSPI(const struct device *spi) : spi_dev(spi) { | |
|
|
||
| uint8_t arduino::ZephyrSPI::transfer(uint8_t data) { | ||
| uint8_t rx = data; | ||
| if (transfer(&rx, sizeof(rx), &config) < 0) { | ||
| if (transfer(&rx, sizeof(rx), SPI_WORD_SET(8)) < 0) { | ||
| return 0; | ||
| } | ||
| return rx; | ||
| } | ||
|
|
||
| uint16_t arduino::ZephyrSPI::transfer16(uint16_t data) { | ||
| uint16_t rx = data; | ||
| if (transfer(&rx, sizeof(rx), &config16) < 0) { | ||
| if (transfer(&rx, sizeof(rx), SPI_WORD_SET(16)) < 0) { | ||
| return 0; | ||
| } | ||
| return rx; | ||
| } | ||
|
|
||
| void arduino::ZephyrSPI::transfer(void *buf, size_t count) { | ||
| int ret = transfer(buf, count, &config); | ||
| int ret = transfer(buf, count, SPI_WORD_SET(8)); | ||
| (void)ret; | ||
| } | ||
|
|
||
| int arduino::ZephyrSPI::transfer(void *buf, size_t len, const struct spi_config *config) { | ||
| int ret; | ||
|
|
||
| int arduino::ZephyrSPI::transfer(void *buf, size_t len, uint32_t flags) { | ||
| const struct spi_buf tx_buf = {.buf = buf, .len = len}; | ||
| const struct spi_buf_set tx_buf_set = { | ||
| .buffers = &tx_buf, | ||
|
|
@@ -47,7 +45,8 @@ int arduino::ZephyrSPI::transfer(void *buf, size_t len, const struct spi_config | |
| .count = 1, | ||
| }; | ||
|
|
||
| return spi_transceive(spi_dev, config, &tx_buf_set, &rx_buf_set); | ||
| config.operation = mode | flags; | ||
| return spi_transceive(spi_dev, &config, &tx_buf_set, &rx_buf_set); | ||
| } | ||
|
|
||
| void arduino::ZephyrSPI::usingInterrupt(int interruptNumber) { | ||
|
|
@@ -57,7 +56,7 @@ void arduino::ZephyrSPI::notUsingInterrupt(int interruptNumber) { | |
| } | ||
|
|
||
| void arduino::ZephyrSPI::beginTransaction(SPISettings settings) { | ||
| uint32_t mode = 0; | ||
| mode = SPI_HOLD_ON_CS; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't really fix the issue as discussed. In any case, it should Never be set unconditionally, what if causes an issue with some random SPI device? This should be added to the API and passed in settings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is not an HW CS is a GPIO. Yes it looks swapped, I've used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
just ignore this, it changes the bit order so it is unrelated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I know. The GPIO CS delay is also controllable.
If it matches mbed core, an others, then it's probably fine, I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See |
||
|
|
||
| // Set bus mode | ||
| switch (settings.getBusMode()) { | ||
|
|
@@ -93,15 +92,9 @@ void arduino::ZephyrSPI::beginTransaction(SPISettings settings) { | |
| break; | ||
| } | ||
|
|
||
| // Set SPI configuration structure for 8-bit transfers | ||
| // Set SPI configuration structure except for operation | ||
| memset(&config, 0, sizeof(struct spi_config)); | ||
| config.operation = mode | SPI_WORD_SET(8); | ||
| config.frequency = max(SPI_MIN_CLOCK_FREQUENCY, settings.getClockFreq()); | ||
|
|
||
| // Set SPI configuration structure for 16-bit transfers | ||
| memset(&config16, 0, sizeof(struct spi_config)); | ||
| config16.operation = mode | SPI_WORD_SET(16); | ||
| config16.frequency = max(SPI_MIN_CLOCK_FREQUENCY, settings.getClockFreq()); | ||
| } | ||
|
|
||
| void arduino::ZephyrSPI::endTransaction(void) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -59,12 +59,12 @@ class ZephyrSPI : public HardwareSPI { | |||
| virtual void end(); | ||||
|
|
||||
| private: | ||||
| int transfer(void *buf, size_t len, const struct spi_config *config); | ||||
| int transfer(void *buf, size_t len, uint32_t flags); | ||||
|
|
||||
| protected: | ||||
| const struct device *spi_dev; | ||||
| struct spi_config config; | ||||
| struct spi_config config16; | ||||
| uint32_t mode; | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Already stored in operation. |
||||
| int interrupt[INTERRUPT_COUNT]; | ||||
| size_t interrupt_pos = 0; | ||||
| }; | ||||
|
|
||||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.