Skip to content

Commit 608251d

Browse files
committed
libraries/Wire: Fix formatting.
Fix formatting. Signed-off-by: iabdalkader <[email protected]>
1 parent e4ed02a commit 608251d

File tree

2 files changed

+123
-123
lines changed

2 files changed

+123
-123
lines changed

libraries/Wire/Wire.cpp

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -78,151 +78,151 @@ void arduino::ZephyrI2C::setClock(uint32_t freq) {
7878
uint8_t speed;
7979

8080
if (freq == 100000) {
81-
speed = I2C_SPEED_STANDARD;
81+
speed = I2C_SPEED_STANDARD;
8282
} else if (freq == 400000) {
83-
speed = I2C_SPEED_FAST;
83+
speed = I2C_SPEED_FAST;
8484
} else if (freq == 1000000) {
85-
speed = I2C_SPEED_FAST_PLUS;
85+
speed = I2C_SPEED_FAST_PLUS;
8686
} else {
87-
speed = I2C_SPEED_STANDARD;
87+
speed = I2C_SPEED_STANDARD;
8888
}
8989

9090
i2c_configure(i2c_dev, I2C_SPEED_SET(speed) | I2C_MODE_CONTROLLER);
9191
}
9292

9393
void arduino::ZephyrI2C::beginTransmission(uint8_t address) {
94-
_address = address;
95-
ring_buf_reset(&txRingBuffer.rb);
96-
ring_buf_reset(&rxRingBuffer.rb);
94+
_address = address;
95+
ring_buf_reset(&txRingBuffer.rb);
96+
ring_buf_reset(&rxRingBuffer.rb);
9797
}
9898

9999
uint8_t arduino::ZephyrI2C::endTransmission(bool stopBit) {
100-
int ret = 0;
101-
uint8_t *buf = NULL;
102-
size_t max = ring_buf_capacity_get(&txRingBuffer.rb);
103-
size_t len = ring_buf_get_claim(&txRingBuffer.rb, &buf, max);
100+
int ret = 0;
101+
uint8_t *buf = NULL;
102+
size_t max = ring_buf_capacity_get(&txRingBuffer.rb);
103+
size_t len = ring_buf_get_claim(&txRingBuffer.rb, &buf, max);
104104

105-
if (len && buf) {
106-
ret = i2c_write(i2c_dev, buf, len, _address);
107-
}
105+
if (len && buf) {
106+
ret = i2c_write(i2c_dev, buf, len, _address);
107+
}
108108

109-
// Must be called even if 0 bytes claimed.
110-
ring_buf_get_finish(&txRingBuffer.rb, len);
109+
// Must be called even if 0 bytes claimed.
110+
ring_buf_get_finish(&txRingBuffer.rb, len);
111111

112-
return ret ? 1 : 0;
112+
return ret ? 1 : 0;
113113
}
114114

115115
uint8_t arduino::ZephyrI2C::endTransmission(void) {
116-
return endTransmission(true);
116+
return endTransmission(true);
117117
}
118118

119119
size_t arduino::ZephyrI2C::requestFrom(uint8_t address, size_t len_in, bool stopBit) {
120-
int ret = 0;
121-
uint8_t *buf = NULL;
122-
size_t len = ring_buf_put_claim(&rxRingBuffer.rb, &buf, len_in);
120+
int ret = 0;
121+
uint8_t *buf = NULL;
122+
size_t len = ring_buf_put_claim(&rxRingBuffer.rb, &buf, len_in);
123123

124-
if (len && buf) {
125-
ret = i2c_read(i2c_dev, buf, len, address);
126-
}
124+
if (len && buf) {
125+
ret = i2c_read(i2c_dev, buf, len, address);
126+
}
127127

128-
// Must be called even if 0 bytes claimed.
129-
ring_buf_put_finish(&rxRingBuffer.rb, len);
128+
// Must be called even if 0 bytes claimed.
129+
ring_buf_put_finish(&rxRingBuffer.rb, len);
130130

131-
return ret ? 1 : 0;
131+
return ret ? 1 : 0;
132132
}
133133

134134
size_t arduino::ZephyrI2C::requestFrom(uint8_t address, size_t len) {
135-
return requestFrom(address, len, true);
135+
return requestFrom(address, len, true);
136136
}
137137

138138
size_t arduino::ZephyrI2C::write(uint8_t data) {
139-
return ring_buf_put(&txRingBuffer.rb, &data, 1);
139+
return ring_buf_put(&txRingBuffer.rb, &data, 1);
140140
}
141141

142142
size_t arduino::ZephyrI2C::write(const uint8_t *buffer, size_t size) {
143-
return ring_buf_put(&txRingBuffer.rb, buffer, size);
143+
return ring_buf_put(&txRingBuffer.rb, buffer, size);
144144
}
145145

146146
int arduino::ZephyrI2C::read() {
147-
uint8_t buf;
148-
if (ring_buf_get(&rxRingBuffer.rb, &buf, 1)) {
149-
return (int) buf;
150-
}
151-
return -1;
147+
uint8_t buf;
148+
if (ring_buf_get(&rxRingBuffer.rb, &buf, 1)) {
149+
return (int) buf;
150+
}
151+
return -1;
152152
}
153153

154154
int arduino::ZephyrI2C::available() {
155-
return ring_buf_size_get(&rxRingBuffer.rb);
155+
return ring_buf_size_get(&rxRingBuffer.rb);
156156
}
157157

158158
int arduino::ZephyrI2C::peek() {
159-
uint8_t buf;
160-
if (ring_buf_peek(&rxRingBuffer.rb, &buf, 1)) {
161-
return (int) buf;
162-
}
163-
return -1;
159+
uint8_t buf;
160+
if (ring_buf_peek(&rxRingBuffer.rb, &buf, 1)) {
161+
return (int) buf;
162+
}
163+
return -1;
164164
}
165165

166166
void arduino::ZephyrI2C::flush() {
167167

168168
}
169169

170170
void arduino::ZephyrI2C::onReceive(voidFuncPtrParamInt cb) {
171-
onReceiveCb = cb;
171+
onReceiveCb = cb;
172172
}
173173

174174
void arduino::ZephyrI2C::onRequest(voidFuncPtr cb) {
175-
onRequestCb = cb;
175+
onRequestCb = cb;
176176
}
177177

178178
int arduino::ZephyrI2C::writeRequestedCallback(struct i2c_target_config *config) {
179-
// Reset the buffer on write requests.
180-
ring_buf_reset(&rxRingBuffer.rb);
181-
return 0;
179+
// Reset the buffer on write requests.
180+
ring_buf_reset(&rxRingBuffer.rb);
181+
return 0;
182182
}
183183

184184
int arduino::ZephyrI2C::writeReceivedCallback(struct i2c_target_config *config, uint8_t val) {
185-
size_t len = ring_buf_size_get(&rxRingBuffer.rb);
186-
size_t max = ring_buf_capacity_get(&rxRingBuffer.rb);
185+
size_t len = ring_buf_size_get(&rxRingBuffer.rb);
186+
size_t max = ring_buf_capacity_get(&rxRingBuffer.rb);
187187

188-
// If the buffer is about to overflow, invoke the callback
189-
// with the current length.
190-
if (onReceiveCb && ((len + 1) > max)) {
191-
onReceiveCb(len);
192-
}
188+
// If the buffer is about to overflow, invoke the callback
189+
// with the current length.
190+
if (onReceiveCb && ((len + 1) > max)) {
191+
onReceiveCb(len);
192+
}
193193

194-
return ring_buf_put(&rxRingBuffer.rb, &val, 1) ? 0 : -1;
194+
return ring_buf_put(&rxRingBuffer.rb, &val, 1) ? 0 : -1;
195195
}
196196

197197
int arduino::ZephyrI2C::readRequestedCallback(struct i2c_target_config *config, uint8_t *val) {
198-
// Reset the buffer on read requests.
199-
ring_buf_reset(&txRingBuffer.rb);
198+
// Reset the buffer on read requests.
199+
ring_buf_reset(&txRingBuffer.rb);
200200

201-
if (onRequestCb) {
202-
onRequestCb();
203-
}
201+
if (onRequestCb) {
202+
onRequestCb();
203+
}
204204

205-
return readProcessedCallback(config, val);
205+
return readProcessedCallback(config, val);
206206
}
207207

208208
int arduino::ZephyrI2C::readProcessedCallback(struct i2c_target_config *config, uint8_t *val) {
209-
*val = 0xFF;
210-
ring_buf_get(&txRingBuffer.rb, val, 1);
211-
// Returning a negative value here is not handled gracefully and
212-
// causes the target/board to stop responding (at least with ST).
213-
return 0;
209+
*val = 0xFF;
210+
ring_buf_get(&txRingBuffer.rb, val, 1);
211+
// Returning a negative value here is not handled gracefully and
212+
// causes the target/board to stop responding (at least with ST).
213+
return 0;
214214
}
215215

216216
int arduino::ZephyrI2C::stopCallback(struct i2c_target_config *config) {
217-
// If the RX buffer is not empty invoke the callback with the
218-
// remaining data length.
219-
if (onReceiveCb) {
220-
size_t len = ring_buf_size_get(&rxRingBuffer.rb);
221-
if (len) {
222-
onReceiveCb(len);
217+
// If the RX buffer is not empty invoke the callback with the
218+
// remaining data length.
219+
if (onReceiveCb) {
220+
size_t len = ring_buf_size_get(&rxRingBuffer.rb);
221+
if (len) {
222+
onReceiveCb(len);
223+
}
223224
}
224-
}
225-
return 0;
225+
return 0;
226226
}
227227

228228
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), i2cs)

libraries/Wire/Wire.h

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,56 @@ typedef void (*voidFuncPtrParamInt)(int);
1616
namespace arduino {
1717

1818
struct i2c_ring {
19-
struct ring_buf rb;
20-
uint8_t buffer[256];
19+
struct ring_buf rb;
20+
uint8_t buffer[256];
2121
};
2222

2323
class ZephyrI2C : public HardwareI2C {
24-
public:
25-
ZephyrI2C(const struct device* i2c);
26-
27-
virtual void begin();
28-
virtual void end();
29-
virtual void begin(uint8_t address);
30-
virtual void setClock(uint32_t freq);
31-
32-
virtual void beginTransmission(uint8_t address);
33-
virtual uint8_t endTransmission(bool stopBit);
34-
virtual uint8_t endTransmission(void);
35-
36-
virtual size_t requestFrom(uint8_t address, size_t len, bool stopBit);
37-
virtual size_t requestFrom(uint8_t address, size_t len);
38-
39-
virtual void onReceive(void (*)(int));
40-
virtual void onRequest(void (*)(void));
41-
42-
virtual size_t write(uint8_t data);
43-
virtual size_t write(int data) { return write((uint8_t)data); };
44-
virtual size_t write(const uint8_t *buffer, size_t size);
45-
using Print::write;
46-
virtual int read();
47-
virtual int peek();
48-
virtual void flush();
49-
virtual int available();
50-
51-
// I2C target callbacks
52-
int writeRequestedCallback(struct i2c_target_config *config);
53-
int writeReceivedCallback(struct i2c_target_config *config, uint8_t val);
54-
int readRequestedCallback(struct i2c_target_config *config, uint8_t *val);
55-
int readProcessedCallback(struct i2c_target_config *config, uint8_t *val);
56-
int stopCallback(struct i2c_target_config *config);
57-
58-
struct i2c_target_config i2c_cfg;
59-
60-
private:
61-
int _address;
62-
63-
struct i2c_ring txRingBuffer;
64-
struct i2c_ring rxRingBuffer;
65-
const struct device *i2c_dev;
66-
67-
voidFuncPtr onRequestCb = NULL;
68-
voidFuncPtrParamInt onReceiveCb = NULL;
24+
public:
25+
ZephyrI2C(const struct device* i2c);
26+
27+
virtual void begin();
28+
virtual void end();
29+
virtual void begin(uint8_t address);
30+
virtual void setClock(uint32_t freq);
31+
32+
virtual void beginTransmission(uint8_t address);
33+
virtual uint8_t endTransmission(bool stopBit);
34+
virtual uint8_t endTransmission(void);
35+
36+
virtual size_t requestFrom(uint8_t address, size_t len, bool stopBit);
37+
virtual size_t requestFrom(uint8_t address, size_t len);
38+
39+
virtual void onReceive(void (*)(int));
40+
virtual void onRequest(void (*)(void));
41+
42+
virtual size_t write(uint8_t data);
43+
virtual size_t write(int data) { return write((uint8_t)data); };
44+
virtual size_t write(const uint8_t *buffer, size_t size);
45+
using Print::write;
46+
virtual int read();
47+
virtual int peek();
48+
virtual void flush();
49+
virtual int available();
50+
51+
// I2C target callbacks
52+
int writeRequestedCallback(struct i2c_target_config *config);
53+
int writeReceivedCallback(struct i2c_target_config *config, uint8_t val);
54+
int readRequestedCallback(struct i2c_target_config *config, uint8_t *val);
55+
int readProcessedCallback(struct i2c_target_config *config, uint8_t *val);
56+
int stopCallback(struct i2c_target_config *config);
57+
58+
struct i2c_target_config i2c_cfg;
59+
60+
private:
61+
int _address;
62+
63+
struct i2c_ring txRingBuffer;
64+
struct i2c_ring rxRingBuffer;
65+
const struct device *i2c_dev;
66+
67+
voidFuncPtr onRequestCb = NULL;
68+
voidFuncPtrParamInt onReceiveCb = NULL;
6969
};
7070

7171
} // namespace arduino
@@ -75,7 +75,7 @@ class ZephyrI2C : public HardwareI2C {
7575
#define DECL_EXTERN_WIRE_0(i) extern arduino::ZephyrI2C Wire;
7676
#define DECL_EXTERN_WIRE_N(i) extern arduino::ZephyrI2C Wire##i;
7777
#define DECLARE_EXTERN_WIRE_N(n, p, i) \
78-
COND_CODE_1(ARDUINO_WIRE_DEFINED_##i, (DECL_EXTERN_WIRE_0(i)), (DECL_EXTERN_WIRE_N(i)))
78+
COND_CODE_1(ARDUINO_WIRE_DEFINED_##i, (DECL_EXTERN_WIRE_0(i)), (DECL_EXTERN_WIRE_N(i)))
7979

8080
/* Declare Wire, Wire1, Wire2, ... */
8181
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), i2cs, DECLARE_EXTERN_WIRE_N)
@@ -85,7 +85,7 @@ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), i2cs, DECLARE_EXTERN_WIRE_N)
8585
#undef DECL_EXTERN_WIRE_0
8686
#undef ARDUINO_WIRE_DEFINED_0
8787
#else
88-
extern arduino::ZephyrI2C Wire;
88+
extern arduino::ZephyrI2C Wire;
8989
#endif
9090

91-
typedef arduino::ZephyrI2C TwoWire;
91+
typedef arduino::ZephyrI2C TwoWire;

0 commit comments

Comments
 (0)