@@ -164,25 +164,8 @@ void ArduinoSPI::begin()
164
164
init_ok = false ;
165
165
}
166
166
}
167
- else
168
- {
169
- #if 0
170
- /* not using FSP for SPI anymore and no interrupts */
171
- SpiMasterIrqReq_t irq_req
172
- {
173
- .ctrl = &_spi_ctrl,
174
- .cfg = &_spi_cfg,
175
- .hw_channel = (uint8_t)_channel,
176
- };
177
- init_ok &= IRQManager::getInstance().addPeripheral(IRQ_SPI_MASTER, &irq_req);
178
167
179
- if (FSP_SUCCESS == _open(&_spi_ctrl, &_spi_cfg)) {
180
- init_ok &= true;
181
- } else {
182
- init_ok = false;
183
- }
184
- #endif
185
- }
168
+ /* not using FSP for SPI anymore and no interrupts */
186
169
187
170
_is_initialized = init_ok;
188
171
}
@@ -229,17 +212,17 @@ uint8_t ArduinoSPI::transfer(uint8_t data)
229
212
230
213
uint16_t ArduinoSPI::transfer16 (uint16_t data)
231
214
{
232
- union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } t;
233
- t.val = data;
215
+ union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } t;
216
+ t.val = data;
234
217
235
- if (_settings.getBitOrder () == LSBFIRST) {
236
- t.lsb = transfer (t.lsb );
237
- t.msb = transfer (t.msb );
238
- } else {
239
- t.msb = transfer (t.msb );
240
- t.lsb = transfer (t.lsb );
241
- }
242
- return t.val ;
218
+ if (_settings.getBitOrder () == LSBFIRST) {
219
+ t.lsb = transfer (t.lsb );
220
+ t.msb = transfer (t.msb );
221
+ } else {
222
+ t.msb = transfer (t.msb );
223
+ t.lsb = transfer (t.lsb );
224
+ }
225
+ return t.val ;
243
226
}
244
227
245
228
void ArduinoSPI::transfer (void *buf, size_t count)
@@ -263,8 +246,8 @@ void ArduinoSPI::transfer(void *buf, size_t count)
263
246
{
264
247
if (buf != NULL ) {
265
248
uint32_t *buffer32 = (uint32_t *) buf;
266
- size_t ir = 0 ;
267
- size_t it = 0 ;
249
+ size_t index_rx = 0 ;
250
+ size_t index_tx = 0 ;
268
251
size_t const n32 = count / 4U ;
269
252
uint8_t const bytes_remaining = (uint8_t ) (count & 3U );
270
253
@@ -274,28 +257,28 @@ void ArduinoSPI::transfer(void *buf, size_t count)
274
257
_spi_ctrl.p_regs ->SPCMD_b [0 ].SPB = 2 ; /* spi bit width = 32 */
275
258
_spi_ctrl.p_regs ->SPCR_b .SPE = 1 ; /* enable SPI unit */
276
259
277
- while ((it < 2U ) && (it < n32)) {
260
+ while ((index_tx < 2U ) && (index_tx < n32)) {
278
261
if (_spi_ctrl.p_regs ->SPSR_b .SPTEF ) {
279
- _spi_ctrl.p_regs ->SPDR = buffer32[it ];
280
- it ++;
262
+ _spi_ctrl.p_regs ->SPDR = buffer32[index_tx ];
263
+ index_tx ++;
281
264
}
282
265
}
283
266
284
- while (it < n32) {
267
+ while (index_tx < n32) {
285
268
if (_spi_ctrl.p_regs ->SPSR_b .SPRF ) {
286
269
uint32_t tmp = _spi_ctrl.p_regs ->SPDR ;
287
- _spi_ctrl.p_regs ->SPDR = buffer32[it ];
288
- buffer32[ir ] = tmp;
289
- ir ++;
290
- it ++;
270
+ _spi_ctrl.p_regs ->SPDR = buffer32[index_tx ];
271
+ buffer32[index_rx ] = tmp;
272
+ index_rx ++;
273
+ index_tx ++;
291
274
}
292
275
}
293
276
294
- while (ir < n32) { /* collect the last word received */
277
+ while (index_rx < n32) { /* collect the last word received */
295
278
if (_spi_ctrl.p_regs ->SPSR_b .SPRF ) {
296
279
uint32_t tmp = _spi_ctrl.p_regs ->SPDR ;
297
- buffer32[ir ] = tmp;
298
- ir ++;
280
+ buffer32[index_rx ] = tmp;
281
+ index_rx ++;
299
282
}
300
283
}
301
284
@@ -306,7 +289,7 @@ void ArduinoSPI::transfer(void *buf, size_t count)
306
289
}
307
290
308
291
/* send the remaining bytes with 8-bit transfers */
309
- uint8_t *buffer = (uint8_t *) &buffer32[ir ];
292
+ uint8_t *buffer = (uint8_t *) &buffer32[index_rx ];
310
293
311
294
for (uint8_t index = 0 ; index < bytes_remaining; index ++) {
312
295
_spi_ctrl.p_regs ->SPDR_BY = buffer[index ];
@@ -344,35 +327,35 @@ void ArduinoSPI::transfer(void *buf, void *rxbuf, size_t count)
344
327
345
328
const uint32_t * tx32 = (const uint32_t *) buf;
346
329
uint32_t * rx32 = (uint32_t *) rxbuf;
347
- size_t ir = 0 ;
348
- size_t it = 0 ;
330
+ size_t index_rx = 0 ;
331
+ size_t index_tx = 0 ;
349
332
350
- while ((it < 2U ) && (it < n32)) {
333
+ while ((index_tx < 2U ) && (index_tx < n32)) {
351
334
if (_spi_ctrl.p_regs ->SPSR_b .SPTEF ) {
352
- _spi_ctrl.p_regs ->SPDR = (buf != NULL ) ? tx32[it ] : 0xFFFFFFFF ;
353
- it ++;
335
+ _spi_ctrl.p_regs ->SPDR = (buf != NULL ) ? tx32[index_tx ] : 0xFFFFFFFF ;
336
+ index_tx ++;
354
337
}
355
338
}
356
339
357
- while (it < n32) {
340
+ while (index_tx < n32) {
358
341
if (_spi_ctrl.p_regs ->SPSR_b .SPRF ) {
359
342
uint32_t tmp = _spi_ctrl.p_regs ->SPDR ;
360
- _spi_ctrl.p_regs ->SPDR = (buf != NULL ) ? tx32[it ] : 0xFFFFFFFF ;
343
+ _spi_ctrl.p_regs ->SPDR = (buf != NULL ) ? tx32[index_tx ] : 0xFFFFFFFF ;
361
344
if (rxbuf != NULL ) {
362
- rx32[ir ] = tmp;
345
+ rx32[index_rx ] = tmp;
363
346
}
364
- ir ++;
365
- it ++;
347
+ index_rx ++;
348
+ index_tx ++;
366
349
}
367
350
}
368
351
369
- while (ir < n32) { /* collect the last word received */
352
+ while (index_rx < n32) { /* collect the last word received */
370
353
if (_spi_ctrl.p_regs ->SPSR_b .SPRF ) {
371
354
uint32_t tmp = _spi_ctrl.p_regs ->SPDR ;
372
355
if (rxbuf != NULL ) {
373
- rx32[ir ] = tmp;
356
+ rx32[index_rx ] = tmp;
374
357
}
375
- ir ++;
358
+ index_rx ++;
376
359
}
377
360
}
378
361
0 commit comments