88#include " zephyrInternal.h"
99#include < zephyr/kernel.h>
1010
11- arduino::ZephyrSPI::ZephyrSPI (const struct device *spi) : spi_dev(spi) {}
11+ arduino::ZephyrSPI::ZephyrSPI (const struct device *spi) : spi_dev(spi) {
12+ memset (&config, 0 , sizeof (config));
13+ }
1214
1315uint8_t arduino::ZephyrSPI::transfer (uint8_t data) {
1416 int ret;
@@ -24,6 +26,10 @@ uint8_t arduino::ZephyrSPI::transfer(uint8_t data) {
2426 .count = 1 ,
2527 };
2628
29+ if (config.frequency == 0 ) {
30+ beginTransaction (DEFAULT_SPI_SETTINGS);
31+ }
32+
2733 ret = spi_transceive (spi_dev, &config, &tx_buf_set, &rx_buf_set);
2834 if (ret < 0 ) {
2935 return 0 ;
@@ -46,6 +52,10 @@ uint16_t arduino::ZephyrSPI::transfer16(uint16_t data) {
4652 .count = 1 ,
4753 };
4854
55+ if (config.frequency == 0 ) {
56+ beginTransaction (DEFAULT_SPI_SETTINGS);
57+ }
58+
4959 ret = spi_transceive (spi_dev, &config, &tx_buf_set, &rx_buf_set);
5060 if (ret < 0 ) {
5161 return 0 ;
@@ -55,7 +65,7 @@ uint16_t arduino::ZephyrSPI::transfer16(uint16_t data) {
5565}
5666
5767void arduino::ZephyrSPI::transfer (void *buf, size_t count) {
58- int ret;
68+
5969 const struct spi_buf tx_buf = {.buf = buf, .len = count};
6070 const struct spi_buf_set tx_buf_set = {
6171 .buffers = &tx_buf,
@@ -69,6 +79,10 @@ void arduino::ZephyrSPI::transfer(void *buf, size_t count) {
6979 .count = 1 ,
7080 };
7181
82+ if (config.frequency == 0 ) {
83+ beginTransaction (DEFAULT_SPI_SETTINGS);
84+ }
85+
7286 spi_transceive (spi_dev, &config, &tx_buf_set, &rx_buf_set);
7387 memcpy (buf, rx, count);
7488}
0 commit comments