@@ -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
9393void 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
9999uint8_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
115115uint8_t arduino::ZephyrI2C::endTransmission (void ) {
116- return endTransmission (true );
116+ return endTransmission (true );
117117}
118118
119119size_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
134134size_t arduino::ZephyrI2C::requestFrom (uint8_t address, size_t len) {
135- return requestFrom (address, len, true );
135+ return requestFrom (address, len, true );
136136}
137137
138138size_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
142142size_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
146146int 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
154154int arduino::ZephyrI2C::available () {
155- return ring_buf_size_get (&rxRingBuffer.rb );
155+ return ring_buf_size_get (&rxRingBuffer.rb );
156156}
157157
158158int 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
166166void arduino::ZephyrI2C::flush () {
167167
168168}
169169
170170void arduino::ZephyrI2C::onReceive (voidFuncPtrParamInt cb) {
171- onReceiveCb = cb;
171+ onReceiveCb = cb;
172172}
173173
174174void arduino::ZephyrI2C::onRequest (voidFuncPtr cb) {
175- onRequestCb = cb;
175+ onRequestCb = cb;
176176}
177177
178178int 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
184184int 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
197197int 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
208208int 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
216216int 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)
0 commit comments