Skip to content

Commit 2ec7fdb

Browse files
iabdalkadersoburi
authored andcommitted
misc: Format repo using clang-format.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent 0d9f4cf commit 2ec7fdb

4 files changed

Lines changed: 261 additions & 248 deletions

File tree

libraries/SPI/SPI.cpp

Lines changed: 92 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -8,69 +8,70 @@
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+
}
1213

1314
uint8_t arduino::ZephyrSPI::transfer(uint8_t data) {
14-
int ret;
15-
uint8_t rx;
16-
const struct spi_buf tx_buf = {.buf = &data, .len = sizeof(data)};
17-
const struct spi_buf_set tx_buf_set = {
18-
.buffers = &tx_buf,
19-
.count = 1,
20-
};
21-
const struct spi_buf rx_buf = {.buf = &rx, .len = sizeof(rx)};
22-
const struct spi_buf_set rx_buf_set = {
23-
.buffers = &rx_buf,
24-
.count = 1,
25-
};
26-
27-
ret = spi_transceive(spi_dev, &config, &tx_buf_set, &rx_buf_set);
28-
if (ret < 0) {
29-
return 0;
30-
}
31-
32-
return rx;
15+
int ret;
16+
uint8_t rx;
17+
const struct spi_buf tx_buf = {.buf = &data, .len = sizeof(data)};
18+
const struct spi_buf_set tx_buf_set = {
19+
.buffers = &tx_buf,
20+
.count = 1,
21+
};
22+
const struct spi_buf rx_buf = {.buf = &rx, .len = sizeof(rx)};
23+
const struct spi_buf_set rx_buf_set = {
24+
.buffers = &rx_buf,
25+
.count = 1,
26+
};
27+
28+
ret = spi_transceive(spi_dev, &config, &tx_buf_set, &rx_buf_set);
29+
if (ret < 0) {
30+
return 0;
31+
}
32+
33+
return rx;
3334
}
3435

3536
uint16_t arduino::ZephyrSPI::transfer16(uint16_t data) {
36-
int ret;
37-
uint16_t rx;
38-
const struct spi_buf tx_buf = {.buf = &data, .len = sizeof(data)};
39-
const struct spi_buf_set tx_buf_set = {
40-
.buffers = &tx_buf,
41-
.count = 1,
42-
};
43-
const struct spi_buf rx_buf = {.buf = &rx, .len = sizeof(rx)};
44-
const struct spi_buf_set rx_buf_set = {
45-
.buffers = &rx_buf,
46-
.count = 1,
47-
};
48-
49-
ret = spi_transceive(spi_dev, &config16, &tx_buf_set, &rx_buf_set);
50-
if (ret < 0) {
51-
return 0;
52-
}
53-
54-
return rx;
37+
int ret;
38+
uint16_t rx;
39+
const struct spi_buf tx_buf = {.buf = &data, .len = sizeof(data)};
40+
const struct spi_buf_set tx_buf_set = {
41+
.buffers = &tx_buf,
42+
.count = 1,
43+
};
44+
const struct spi_buf rx_buf = {.buf = &rx, .len = sizeof(rx)};
45+
const struct spi_buf_set rx_buf_set = {
46+
.buffers = &rx_buf,
47+
.count = 1,
48+
};
49+
50+
ret = spi_transceive(spi_dev, &config16, &tx_buf_set, &rx_buf_set);
51+
if (ret < 0) {
52+
return 0;
53+
}
54+
55+
return rx;
5556
}
5657

5758
void arduino::ZephyrSPI::transfer(void *buf, size_t count) {
58-
int ret;
59-
const struct spi_buf tx_buf = {.buf = buf, .len = count};
60-
const struct spi_buf_set tx_buf_set = {
61-
.buffers = &tx_buf,
62-
.count = 1,
63-
};
64-
65-
uint8_t rx[count];
66-
const struct spi_buf rx_buf = {.buf = &rx, .len = count};
67-
const struct spi_buf_set rx_buf_set = {
68-
.buffers = &rx_buf,
69-
.count = 1,
70-
};
71-
72-
spi_transceive(spi_dev, &config, &tx_buf_set, &rx_buf_set);
73-
memcpy(buf, rx, count);
59+
int ret;
60+
const struct spi_buf tx_buf = {.buf = buf, .len = count};
61+
const struct spi_buf_set tx_buf_set = {
62+
.buffers = &tx_buf,
63+
.count = 1,
64+
};
65+
66+
uint8_t rx[count];
67+
const struct spi_buf rx_buf = {.buf = &rx, .len = count};
68+
const struct spi_buf_set rx_buf_set = {
69+
.buffers = &rx_buf,
70+
.count = 1,
71+
};
72+
73+
spi_transceive(spi_dev, &config, &tx_buf_set, &rx_buf_set);
74+
memcpy(buf, rx, count);
7475
}
7576

7677
void arduino::ZephyrSPI::usingInterrupt(int interruptNumber) {
@@ -84,41 +85,52 @@ void arduino::ZephyrSPI::notUsingInterrupt(int interruptNumber) {
8485
#endif
8586

8687
void arduino::ZephyrSPI::beginTransaction(SPISettings settings) {
87-
memset(&config, 0, sizeof(config));
88-
memset(&config16, 0, sizeof(config16));
89-
config.frequency = settings.getClockFreq() > SPI_MIN_CLOCK_FEQUENCY ? settings.getClockFreq() : SPI_MIN_CLOCK_FEQUENCY;
90-
config16.frequency = config.frequency;
91-
92-
auto mode = SPI_MODE_CPOL | SPI_MODE_CPHA;
93-
switch (settings.getDataMode()) {
94-
case SPI_MODE0:
95-
mode = 0; break;
96-
case SPI_MODE1:
97-
mode = SPI_MODE_CPHA; break;
98-
case SPI_MODE2:
99-
mode = SPI_MODE_CPOL; break;
100-
case SPI_MODE3:
101-
mode = SPI_MODE_CPOL | SPI_MODE_CPHA; break;
102-
}
103-
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;
88+
memset(&config, 0, sizeof(config));
89+
memset(&config16, 0, sizeof(config16));
90+
config.frequency = settings.getClockFreq() > SPI_MIN_CLOCK_FEQUENCY ? settings.getClockFreq() :
91+
SPI_MIN_CLOCK_FEQUENCY;
92+
config16.frequency = config.frequency;
93+
94+
auto mode = SPI_MODE_CPOL | SPI_MODE_CPHA;
95+
switch (settings.getDataMode()) {
96+
case SPI_MODE0:
97+
mode = 0;
98+
break;
99+
case SPI_MODE1:
100+
mode = SPI_MODE_CPHA;
101+
break;
102+
case SPI_MODE2:
103+
mode = SPI_MODE_CPOL;
104+
break;
105+
case SPI_MODE3:
106+
mode = SPI_MODE_CPOL | SPI_MODE_CPHA;
107+
break;
108+
}
109+
config.operation = SPI_WORD_SET(8) |
110+
(settings.getBitOrder() == MSBFIRST ? SPI_TRANSFER_MSB : SPI_TRANSFER_LSB) |
111+
mode;
112+
config16.operation =
113+
SPI_WORD_SET(16) |
114+
(settings.getBitOrder() == MSBFIRST ? SPI_TRANSFER_MSB : SPI_TRANSFER_LSB) | mode;
105115
}
106116

107117
void arduino::ZephyrSPI::endTransaction(void) {
108-
spi_release(spi_dev, &config);
118+
spi_release(spi_dev, &config);
109119
}
110120

111-
void arduino::ZephyrSPI::attachInterrupt() {}
112-
113-
void arduino::ZephyrSPI::detachInterrupt() {}
121+
void arduino::ZephyrSPI::attachInterrupt() {
122+
}
114123

124+
void arduino::ZephyrSPI::detachInterrupt() {
125+
}
115126

116127
void arduino::ZephyrSPI::begin() {
117-
beginTransaction(SPISettings());
118-
endTransaction();
128+
beginTransaction(SPISettings());
129+
endTransaction();
119130
}
120131

121-
void arduino::ZephyrSPI::end() {}
132+
void arduino::ZephyrSPI::end() {
133+
}
122134

123135
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), spis)
124136
#if (DT_PROP_LEN(DT_PATH(zephyr_user), spis) > 1)

libraries/SPI/SPI.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,43 @@
1919
#define CPOL 3
2020
#define MSTR 4
2121
#define DORD 5
22-
#define SPE 6
22+
#define SPE 6
2323
#define SPIE 7
2424

2525
/* Count the number of GPIOs for limit of number of interrupts */
2626
#define INTERRUPT_HELPER(n, p, i) 1
27-
#define INTERRUPT_COUNT \
28-
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, \
27+
#define INTERRUPT_COUNT \
28+
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, \
2929
INTERRUPT_HELPER, (+))
3030

3131
namespace arduino {
3232
class ZephyrSPI : public HardwareSPI {
3333
public:
34-
ZephyrSPI(const struct device *spi);
34+
ZephyrSPI(const struct device *spi);
3535

36-
virtual uint8_t transfer(uint8_t data);
37-
virtual uint16_t transfer16(uint16_t data);
38-
virtual void transfer(void *buf, size_t count);
36+
virtual uint8_t transfer(uint8_t data);
37+
virtual uint16_t transfer16(uint16_t data);
38+
virtual void transfer(void *buf, size_t count);
3939

40-
// Transaction Functions
41-
virtual void usingInterrupt(int interruptNumber);
42-
virtual void notUsingInterrupt(int interruptNumber);
43-
virtual void beginTransaction(SPISettings settings);
44-
virtual void endTransaction(void);
40+
// Transaction Functions
41+
virtual void usingInterrupt(int interruptNumber);
42+
virtual void notUsingInterrupt(int interruptNumber);
43+
virtual void beginTransaction(SPISettings settings);
44+
virtual void endTransaction(void);
4545

46-
// SPI Configuration methods
47-
virtual void attachInterrupt();
48-
virtual void detachInterrupt();
46+
// SPI Configuration methods
47+
virtual void attachInterrupt();
48+
virtual void detachInterrupt();
4949

50-
virtual void begin();
51-
virtual void end();
50+
virtual void begin();
51+
virtual void end();
5252

5353
protected:
54-
const struct device *spi_dev;
55-
struct spi_config config;
56-
struct spi_config config16;
57-
int interrupt[INTERRUPT_COUNT];
58-
size_t interrupt_pos = 0;
54+
const struct device *spi_dev;
55+
struct spi_config config;
56+
struct spi_config config16;
57+
int interrupt[INTERRUPT_COUNT];
58+
size_t interrupt_pos = 0;
5959
};
6060

6161
} // namespace arduino

0 commit comments

Comments
 (0)