8
8
#include " zephyrInternal.h"
9
9
#include < zephyr/kernel.h>
10
10
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
+ }
12
14
13
15
uint8_t arduino::ZephyrSPI::transfer (uint8_t data) {
14
16
int ret;
@@ -24,6 +26,10 @@ uint8_t arduino::ZephyrSPI::transfer(uint8_t data) {
24
26
.count = 1 ,
25
27
};
26
28
29
+ if (config.frequency == 0 ) {
30
+ beginTransaction (DEFAULT_SPI_SETTINGS);
31
+ }
32
+
27
33
ret = spi_transceive (spi_dev, &config, &tx_buf_set, &rx_buf_set);
28
34
if (ret < 0 ) {
29
35
return 0 ;
@@ -46,6 +52,10 @@ uint16_t arduino::ZephyrSPI::transfer16(uint16_t data) {
46
52
.count = 1 ,
47
53
};
48
54
55
+ if (config.frequency == 0 ) {
56
+ beginTransaction (DEFAULT_SPI_SETTINGS);
57
+ }
58
+
49
59
ret = spi_transceive (spi_dev, &config, &tx_buf_set, &rx_buf_set);
50
60
if (ret < 0 ) {
51
61
return 0 ;
@@ -55,7 +65,7 @@ uint16_t arduino::ZephyrSPI::transfer16(uint16_t data) {
55
65
}
56
66
57
67
void arduino::ZephyrSPI::transfer (void *buf, size_t count) {
58
- int ret;
68
+
59
69
const struct spi_buf tx_buf = {.buf = buf, .len = count};
60
70
const struct spi_buf_set tx_buf_set = {
61
71
.buffers = &tx_buf,
@@ -69,6 +79,10 @@ void arduino::ZephyrSPI::transfer(void *buf, size_t count) {
69
79
.count = 1 ,
70
80
};
71
81
82
+ if (config.frequency == 0 ) {
83
+ beginTransaction (DEFAULT_SPI_SETTINGS);
84
+ }
85
+
72
86
spi_transceive (spi_dev, &config, &tx_buf_set, &rx_buf_set);
73
87
memcpy (buf, rx, count);
74
88
}
0 commit comments