Skip to content

Commit 78bcf6a

Browse files
committed
libraries: Format with clang-format
Use a formatter to standardize indentation. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent ce662c6 commit 78bcf6a

File tree

4 files changed

+209
-202
lines changed

4 files changed

+209
-202
lines changed

libraries/SPI/SPI.cpp

Lines changed: 81 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -11,115 +11,117 @@
1111
/* Serial Peripheral Control Register */
1212
uint8_t SPCR;
1313

14-
arduino::ZephyrSPI::ZephyrSPI(const struct device *spi) : spi_dev(spi) {}
14+
arduino::ZephyrSPI::ZephyrSPI(const struct device *spi) : spi_dev(spi) {
15+
}
1516

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

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

6061
void arduino::ZephyrSPI::transfer(void *buf, size_t count) {
61-
int ret;
62-
const struct spi_buf tx_buf = {.buf = buf, .len = count};
63-
const struct spi_buf_set tx_buf_set = {
64-
.buffers = &tx_buf,
65-
.count = 1,
66-
};
67-
68-
ret = spi_write(spi_dev, &config, &tx_buf_set);
69-
if (ret < 0) {
70-
return;
71-
}
72-
73-
ret = spi_read(spi_dev, &config, &tx_buf_set);
74-
if (ret < 0) {
75-
return;
76-
}
62+
int ret;
63+
const struct spi_buf tx_buf = {.buf = buf, .len = count};
64+
const struct spi_buf_set tx_buf_set = {
65+
.buffers = &tx_buf,
66+
.count = 1,
67+
};
68+
69+
ret = spi_write(spi_dev, &config, &tx_buf_set);
70+
if (ret < 0) {
71+
return;
72+
}
73+
74+
ret = spi_read(spi_dev, &config, &tx_buf_set);
75+
if (ret < 0) {
76+
return;
77+
}
7778
}
7879

7980
void arduino::ZephyrSPI::usingInterrupt(int interruptNumber) {
80-
interrupt[interrupt_pos++] = interruptNumber;
81+
interrupt[interrupt_pos++] = interruptNumber;
8182
}
8283

8384
void arduino::ZephyrSPI::notUsingInterrupt(int interruptNumber) {
84-
for (size_t i = 0; i < interrupt_pos; ++i) {
85-
if (interrupt[i] == interruptNumber) {
86-
memmove(&interrupt[i], &interrupt[i + 1], interrupt_pos - i - 1);
87-
interrupt_pos--;
88-
break;
89-
}
90-
}
85+
for (size_t i = 0; i < interrupt_pos; ++i) {
86+
if (interrupt[i] == interruptNumber) {
87+
memmove(&interrupt[i], &interrupt[i + 1], interrupt_pos - i - 1);
88+
interrupt_pos--;
89+
break;
90+
}
91+
}
9192
}
9293

9394
void arduino::ZephyrSPI::beginTransaction(SPISettings settings) {
94-
memset(&config, 0, sizeof(config));
95-
config.frequency = settings.getClockFreq();
96-
config.operation = ((settings.getBitOrder() ^ 1) << 4) |
97-
(settings.getDataMode() << 1) | ((SPCR >> MSTR) & 1) |
98-
SPI_WORD_SET(8);
95+
memset(&config, 0, sizeof(config));
96+
config.frequency = settings.getClockFreq();
97+
config.operation = ((settings.getBitOrder() ^ 1) << 4) | (settings.getDataMode() << 1) |
98+
((SPCR >> MSTR) & 1) | SPI_WORD_SET(8);
9999

100-
detachInterrupt();
100+
detachInterrupt();
101101
}
102102

103103
void arduino::ZephyrSPI::endTransaction(void) {
104-
spi_release(spi_dev, &config);
105-
attachInterrupt();
104+
spi_release(spi_dev, &config);
105+
attachInterrupt();
106106
}
107107

108108
void arduino::ZephyrSPI::attachInterrupt() {
109-
for (size_t i = 0; i < interrupt_pos; ++i) {
110-
enableInterrupt(interrupt[i]);
111-
}
109+
for (size_t i = 0; i < interrupt_pos; ++i) {
110+
enableInterrupt(interrupt[i]);
111+
}
112112
}
113113

114114
void arduino::ZephyrSPI::detachInterrupt() {
115-
for (size_t i = 0; i < interrupt_pos; ++i) {
116-
disableInterrupt(interrupt[i]);
117-
}
115+
for (size_t i = 0; i < interrupt_pos; ++i) {
116+
disableInterrupt(interrupt[i]);
117+
}
118118
}
119119

120-
void arduino::ZephyrSPI::begin() {}
120+
void arduino::ZephyrSPI::begin() {
121+
}
121122

122-
void arduino::ZephyrSPI::end() {}
123+
void arduino::ZephyrSPI::end() {
124+
}
123125

124126
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), spis)
125127
#if (DT_PROP_LEN(DT_PATH(zephyr_user), spis) > 1)

libraries/SPI/SPI.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,42 @@
1616
#define CPOL 3
1717
#define MSTR 4
1818
#define DORD 5
19-
#define SPE 6
19+
#define SPE 6
2020
#define SPIE 7
2121

2222
/* Count the number of GPIOs for limit of number of interrupts */
2323
#define INTERRUPT_HELPER(n, p, i) 1
24-
#define INTERRUPT_COUNT \
25-
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, \
24+
#define INTERRUPT_COUNT \
25+
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, \
2626
INTERRUPT_HELPER, (+))
2727

2828
namespace arduino {
2929
class ZephyrSPI : public HardwareSPI {
3030
public:
31-
ZephyrSPI(const struct device *spi);
31+
ZephyrSPI(const struct device *spi);
3232

33-
virtual uint8_t transfer(uint8_t data);
34-
virtual uint16_t transfer16(uint16_t data);
35-
virtual void transfer(void *buf, size_t count);
33+
virtual uint8_t transfer(uint8_t data);
34+
virtual uint16_t transfer16(uint16_t data);
35+
virtual void transfer(void *buf, size_t count);
3636

37-
// Transaction Functions
38-
virtual void usingInterrupt(int interruptNumber);
39-
virtual void notUsingInterrupt(int interruptNumber);
40-
virtual void beginTransaction(SPISettings settings);
41-
virtual void endTransaction(void);
37+
// Transaction Functions
38+
virtual void usingInterrupt(int interruptNumber);
39+
virtual void notUsingInterrupt(int interruptNumber);
40+
virtual void beginTransaction(SPISettings settings);
41+
virtual void endTransaction(void);
4242

43-
// SPI Configuration methods
44-
virtual void attachInterrupt();
45-
virtual void detachInterrupt();
43+
// SPI Configuration methods
44+
virtual void attachInterrupt();
45+
virtual void detachInterrupt();
4646

47-
virtual void begin();
48-
virtual void end();
47+
virtual void begin();
48+
virtual void end();
4949

5050
private:
51-
const struct device *spi_dev;
52-
struct spi_config config;
53-
int interrupt[INTERRUPT_COUNT];
54-
size_t interrupt_pos = 0;
51+
const struct device *spi_dev;
52+
struct spi_config config;
53+
int interrupt[INTERRUPT_COUNT];
54+
size_t interrupt_pos = 0;
5555
};
5656

5757
} // namespace arduino

0 commit comments

Comments
 (0)