Skip to content

Commit 9ce1ca5

Browse files
committed
libraries/Wire: Fix formatting.
Fix formatting. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent e4ed02a commit 9ce1ca5

File tree

2 files changed

+160
-160
lines changed

2 files changed

+160
-160
lines changed

libraries/Wire/Wire.cpp

Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -10,219 +10,219 @@
1010

1111
// Helper function to get ZephyrI2C instance from config pointer.
1212
static arduino::ZephyrI2C* getInstance(struct i2c_target_config *config) {
13-
return reinterpret_cast<arduino::ZephyrI2C*>(
14-
reinterpret_cast<char*>(config) - offsetof(arduino::ZephyrI2C, i2c_cfg)
15-
);
13+
return reinterpret_cast<arduino::ZephyrI2C*>(
14+
reinterpret_cast<char*>(config) - offsetof(arduino::ZephyrI2C, i2c_cfg)
15+
);
1616
}
1717

1818
static int i2c_target_stop_cb(struct i2c_target_config *config) {
19-
arduino::ZephyrI2C *instance = getInstance(config);
20-
return instance->stopCallback(config);
19+
arduino::ZephyrI2C *instance = getInstance(config);
20+
return instance->stopCallback(config);
2121
}
2222

2323
static int i2c_target_write_requested_cb(struct i2c_target_config *config) {
24-
arduino::ZephyrI2C *instance = getInstance(config);
25-
return instance->writeRequestedCallback(config);
24+
arduino::ZephyrI2C *instance = getInstance(config);
25+
return instance->writeRequestedCallback(config);
2626
}
2727

2828
static int i2c_target_write_received_cb(struct i2c_target_config *config, uint8_t val) {
29-
arduino::ZephyrI2C *instance = getInstance(config);
30-
return instance->writeReceivedCallback(config, val);
29+
arduino::ZephyrI2C *instance = getInstance(config);
30+
return instance->writeReceivedCallback(config, val);
3131
}
3232

3333
static int i2c_target_read_requested_cb(struct i2c_target_config *config, uint8_t *val) {
34-
arduino::ZephyrI2C *instance = getInstance(config);
35-
return instance->readRequestedCallback(config, val);
34+
arduino::ZephyrI2C *instance = getInstance(config);
35+
return instance->readRequestedCallback(config, val);
3636
}
3737

3838
static int i2c_target_read_processed_cb(struct i2c_target_config *config, uint8_t *val) {
39-
arduino::ZephyrI2C *instance = getInstance(config);
40-
return instance->readProcessedCallback(config, val);
39+
arduino::ZephyrI2C *instance = getInstance(config);
40+
return instance->readProcessedCallback(config, val);
4141
}
4242

4343
// I2C target callback structure.
4444
static struct i2c_target_callbacks target_callbacks = {
45-
.write_requested = i2c_target_write_requested_cb,
46-
.read_requested = i2c_target_read_requested_cb,
47-
.write_received = i2c_target_write_received_cb,
48-
.read_processed = i2c_target_read_processed_cb,
49-
.stop = i2c_target_stop_cb,
45+
.write_requested = i2c_target_write_requested_cb,
46+
.read_requested = i2c_target_read_requested_cb,
47+
.write_received = i2c_target_write_received_cb,
48+
.read_processed = i2c_target_read_processed_cb,
49+
.stop = i2c_target_stop_cb,
5050
};
5151

5252
arduino::ZephyrI2C::ZephyrI2C(const struct device *i2c) : i2c_dev(i2c), i2c_cfg({0}) {
53-
ring_buf_init(&txRingBuffer.rb, sizeof(txRingBuffer.buffer), txRingBuffer.buffer);
54-
ring_buf_init(&rxRingBuffer.rb, sizeof(rxRingBuffer.buffer), rxRingBuffer.buffer);
53+
ring_buf_init(&txRingBuffer.rb, sizeof(txRingBuffer.buffer), txRingBuffer.buffer);
54+
ring_buf_init(&rxRingBuffer.rb, sizeof(rxRingBuffer.buffer), rxRingBuffer.buffer);
5555
}
5656

5757
void arduino::ZephyrI2C::begin() {
5858

5959
}
6060

6161
void arduino::ZephyrI2C::begin(uint8_t slaveAddr) {
62-
i2c_cfg.address = slaveAddr;
63-
i2c_cfg.callbacks = &target_callbacks;
62+
i2c_cfg.address = slaveAddr;
63+
i2c_cfg.callbacks = &target_callbacks;
6464

65-
// Register I2C target
66-
i2c_target_register(i2c_dev, &i2c_cfg);
65+
// Register I2C target
66+
i2c_target_register(i2c_dev, &i2c_cfg);
6767
}
6868

6969
void arduino::ZephyrI2C::end() {
70-
// Unregister I2C target
71-
if (i2c_cfg.address) {
72-
i2c_target_unregister(i2c_dev, &i2c_cfg);
73-
memset(&i2c_cfg, 0, sizeof(i2c_cfg));
74-
}
70+
// Unregister I2C target
71+
if (i2c_cfg.address) {
72+
i2c_target_unregister(i2c_dev, &i2c_cfg);
73+
memset(&i2c_cfg, 0, sizeof(i2c_cfg));
74+
}
7575
}
7676

7777
void arduino::ZephyrI2C::setClock(uint32_t freq) {
78-
uint8_t speed;
78+
uint8_t speed;
7979

80-
if (freq == 100000) {
81-
speed = I2C_SPEED_STANDARD;
82-
} else if (freq == 400000) {
83-
speed = I2C_SPEED_FAST;
84-
} else if (freq == 1000000) {
85-
speed = I2C_SPEED_FAST_PLUS;
86-
} else {
87-
speed = I2C_SPEED_STANDARD;
88-
}
80+
if (freq == 100000) {
81+
speed = I2C_SPEED_STANDARD;
82+
} else if (freq == 400000) {
83+
speed = I2C_SPEED_FAST;
84+
} else if (freq == 1000000) {
85+
speed = I2C_SPEED_FAST_PLUS;
86+
} else {
87+
speed = I2C_SPEED_STANDARD;
88+
}
8989

90-
i2c_configure(i2c_dev, I2C_SPEED_SET(speed) | I2C_MODE_CONTROLLER);
90+
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);
223-
}
224-
}
225-
return 0;
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+
}
224+
}
225+
return 0;
226226
}
227227

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

0 commit comments

Comments
 (0)