Skip to content

Commit 5aae8df

Browse files
committed
style changes, fix i2c typo
1 parent 4ec588b commit 5aae8df

File tree

4 files changed

+51
-51
lines changed

4 files changed

+51
-51
lines changed

ports/stm32f4/common-hal/busio/I2C.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
6161

6262
//match pins to I2C objects
6363
I2C_TypeDef * I2Cx;
64-
uint8_t sda_len = sizeof(mcu_i2c_sda_list) / sizeof(*mcu_i2c_sda_list);
65-
uint8_t scl_len = sizeof(mcu_i2c_scl_list) / sizeof(*mcu_i2c_scl_list);
64+
uint8_t sda_len = MP_ARRAY_SIZE(mcu_i2c_sda_list);
65+
uint8_t scl_len = MP_ARRAY_SIZE(mcu_i2c_scl_list);
6666
bool i2c_taken = false;
6767

6868
for (uint i = 0; i < sda_len; i++) {
@@ -137,7 +137,7 @@ void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
137137
never_reset_i2c[i] = true;
138138

139139
never_reset_pin_number(self->scl->pin->port, self->scl->pin->number);
140-
never_reset_pin_number(self->sda->pin->port, self->scl->pin->number);
140+
never_reset_pin_number(self->sda->pin->port, self->sda->pin->number);
141141
break;
142142
}
143143
}
@@ -209,21 +209,21 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
209209
STATIC void i2c_clock_enable(uint8_t mask) {
210210
//Note: hard reset required due to soft reboot issue.
211211
#ifdef I2C1
212-
if (mask & 1<<0) {
212+
if (mask & (1 << 0)) {
213213
__HAL_RCC_I2C1_CLK_ENABLE();
214214
__HAL_RCC_I2C1_FORCE_RESET();
215215
__HAL_RCC_I2C1_RELEASE_RESET();
216216
}
217217
#endif
218218
#ifdef I2C2
219-
if (mask & 1<<1) {
219+
if (mask & (1 << 1)) {
220220
__HAL_RCC_I2C2_CLK_ENABLE();
221221
__HAL_RCC_I2C2_FORCE_RESET();
222222
__HAL_RCC_I2C2_RELEASE_RESET();
223223
}
224224
#endif
225225
#ifdef I2C3
226-
if (mask & 1<<2) {
226+
if (mask & (1 << 2)) {
227227
__HAL_RCC_I2C3_CLK_ENABLE();
228228
__HAL_RCC_I2C3_FORCE_RESET();
229229
__HAL_RCC_I2C3_RELEASE_RESET();
@@ -233,17 +233,17 @@ STATIC void i2c_clock_enable(uint8_t mask) {
233233

234234
STATIC void i2c_clock_disable(uint8_t mask) {
235235
#ifdef I2C1
236-
if (mask & 1<<0) {
236+
if (mask & (1 << 0)) {
237237
__HAL_RCC_I2C1_CLK_DISABLE();
238238
}
239239
#endif
240240
#ifdef I2C2
241-
if (mask & 1<<1) {
241+
if (mask & (1 << 1)) {
242242
__HAL_RCC_I2C2_CLK_DISABLE();
243243
}
244244
#endif
245245
#ifdef I2C3
246-
if (mask & 1<<2) {
246+
if (mask & (1 << 2)) {
247247
__HAL_RCC_I2C3_CLK_DISABLE();
248248
}
249249
#endif

ports/stm32f4/common-hal/busio/SPI.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
104104
//match pins to SPI objects
105105
SPI_TypeDef * SPIx;
106106

107-
uint8_t sck_len = sizeof(mcu_spi_sck_list)/sizeof(*mcu_spi_sck_list);
108-
uint8_t mosi_len = sizeof(mcu_spi_mosi_list)/sizeof(*mcu_spi_mosi_list);
109-
uint8_t miso_len = sizeof(mcu_spi_miso_list)/sizeof(*mcu_spi_miso_list);
107+
uint8_t sck_len = MP_ARRAY_SIZE(mcu_spi_sck_list);
108+
uint8_t mosi_len = MP_ARRAY_SIZE(mcu_spi_mosi_list);
109+
uint8_t miso_len = MP_ARRAY_SIZE(mcu_spi_miso_list);
110110
bool spi_taken = false;
111111

112112
//SCK is not optional. MOSI and MISO are
@@ -393,65 +393,65 @@ uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self) {
393393

394394
STATIC void spi_clock_enable(uint8_t mask) {
395395
#ifdef SPI1
396-
if (mask & 1<<0) {
396+
if (mask & (1 << 0)) {
397397
__HAL_RCC_SPI1_CLK_ENABLE();
398398
}
399399
#endif
400400
#ifdef SPI2
401-
if (mask & 1<<1) {
401+
if (mask & (1 << 1)) {
402402
__HAL_RCC_SPI2_CLK_ENABLE();
403403
}
404404
#endif
405405
#ifdef SPI3
406-
if (mask & 1<<2) {
406+
if (mask & (1 << 2)) {
407407
__HAL_RCC_SPI3_CLK_ENABLE();
408408
}
409409
#endif
410410
#ifdef SPI4
411-
if (mask & 1<<3) {
411+
if (mask & (1 << 3)) {
412412
__HAL_RCC_SPI4_CLK_ENABLE();
413413
}
414414
#endif
415415
#ifdef SPI5
416-
if (mask & 1<<4) {
416+
if (mask & (1 << 4)) {
417417
__HAL_RCC_SPI5_CLK_ENABLE();
418418
}
419419
#endif
420420
#ifdef SPI6
421-
if (mask & 1<<5) {
421+
if (mask & (1 << 5)) {
422422
__HAL_RCC_SPI6_CLK_ENABLE();
423423
}
424424
#endif
425425
}
426426

427427
STATIC void spi_clock_disable(uint8_t mask) {
428428
#ifdef SPI1
429-
if (mask & 1<<0) {
429+
if (mask & (1 << 0)) {
430430
__HAL_RCC_SPI1_CLK_DISABLE();
431431
}
432432
#endif
433433
#ifdef SPI2
434-
if (mask & 1<<1) {
434+
if (mask & (1 << 1)) {
435435
__HAL_RCC_SPI2_CLK_DISABLE();
436436
}
437437
#endif
438438
#ifdef SPI3
439-
if (mask & 1<<2) {
439+
if (mask & (1 << 2)) {
440440
__HAL_RCC_SPI3_CLK_DISABLE();
441441
}
442442
#endif
443443
#ifdef SPI4
444-
if (mask & 1<<3) {
444+
if (mask & (1 << 3)) {
445445
__HAL_RCC_SPI4_CLK_DISABLE();
446446
}
447447
#endif
448448
#ifdef SPI5
449-
if (mask & 1<<4) {
449+
if (mask & (1 << 4)) {
450450
__HAL_RCC_SPI5_CLK_DISABLE();
451451
}
452452
#endif
453453
#ifdef SPI6
454-
if (mask & 1<<5) {
454+
if (mask & (1 << 5)) {
455455
__HAL_RCC_SPI6_CLK_DISABLE();
456456
}
457457
#endif

ports/stm32f4/common-hal/busio/UART.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t* self,
7979
//match pins to UART objects
8080
USART_TypeDef * USARTx;
8181

82-
uint8_t tx_len = sizeof(mcu_uart_tx_list) / sizeof(*mcu_uart_tx_list);
83-
uint8_t rx_len = sizeof(mcu_uart_rx_list) / sizeof(*mcu_uart_rx_list);
82+
uint8_t tx_len = MP_ARRAY_SIZE(mcu_uart_tx_list);
83+
uint8_t rx_len = MP_ARRAY_SIZE(mcu_uart_rx_list);
8484
bool uart_taken = false;
8585
uint8_t uart_index = 0; //origin 0 corrected
8686

ports/stm32f4/common-hal/pulseio/PWMOut.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
106106
uint32_t frequency,
107107
bool variable_frequency) {
108108
TIM_TypeDef * TIMx;
109-
uint8_t tim_num = sizeof(mcu_tim_pin_list) / sizeof(*mcu_tim_pin_list);
109+
uint8_t tim_num = MP_ARRAY_SIZE(mcu_tim_pin_list);
110110
bool tim_chan_taken = false;
111111
bool tim_taken_f_mismatch = false;
112112
bool var_freq_mismatch = false;
@@ -324,127 +324,127 @@ bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t* self
324324

325325
STATIC void tim_clock_enable(uint16_t mask) {
326326
#ifdef TIM1
327-
if (mask & 1<<0) {
327+
if (mask & (1 << 0)) {
328328
__HAL_RCC_TIM1_CLK_ENABLE();
329329
}
330330
#endif
331331
#ifdef TIM2
332-
if (mask & 1<<1) {
332+
if (mask & (1 << 1)) {
333333
__HAL_RCC_TIM2_CLK_ENABLE();
334334
}
335335
#endif
336336
#ifdef TIM3
337-
if (mask & 1<<2) {
337+
if (mask & (1 << 2)) {
338338
__HAL_RCC_TIM3_CLK_ENABLE();
339339
}
340340
#endif
341341
#ifdef TIM4
342-
if (mask & 1<<3) {
342+
if (mask & (1 << 3)) {
343343
__HAL_RCC_TIM4_CLK_ENABLE();
344344
}
345345
#endif
346346
#ifdef TIM5
347-
if (mask & 1<<4) {
347+
if (mask & (1 << 4)) {
348348
__HAL_RCC_TIM5_CLK_ENABLE();
349349
}
350350
#endif
351351
//6 and 7 are reserved ADC timers
352352
#ifdef TIM8
353-
if (mask & 1<<7) {
353+
if (mask & (1 << 7)) {
354354
__HAL_RCC_TIM8_CLK_ENABLE();
355355
}
356356
#endif
357357
#ifdef TIM9
358-
if (mask & 1<<8) {
358+
if (mask & (1 << 8)) {
359359
__HAL_RCC_TIM9_CLK_ENABLE();
360360
}
361361
#endif
362362
#ifdef TIM10
363-
if (mask & 1<<9) {
363+
if (mask & (1 << 9)) {
364364
__HAL_RCC_TIM10_CLK_ENABLE();
365365
}
366366
#endif
367367
#ifdef TIM11
368-
if (mask & 1<<10) {
368+
if (mask & (1 << 10)) {
369369
__HAL_RCC_TIM11_CLK_ENABLE();
370370
}
371371
#endif
372372
#ifdef TIM12
373-
if (mask & 1<<11) {
373+
if (mask & (1 << 11)) {
374374
__HAL_RCC_TIM12_CLK_ENABLE();
375375
}
376376
#endif
377377
#ifdef TIM13
378-
if (mask & 1<<12) {
378+
if (mask & (1 << 12)) {
379379
__HAL_RCC_TIM13_CLK_ENABLE();
380380
}
381381
#endif
382382
#ifdef TIM14
383-
if (mask & 1<<13) {
383+
if (mask & (1 << 13)) {
384384
__HAL_RCC_TIM14_CLK_ENABLE();
385385
}
386386
#endif
387387
}
388388

389389
STATIC void tim_clock_disable(uint16_t mask) {
390390
#ifdef TIM1
391-
if (mask & 1<<0) {
391+
if (mask & (1 << 0)) {
392392
__HAL_RCC_TIM1_CLK_DISABLE();
393393
}
394394
#endif
395395
#ifdef TIM2
396-
if (mask & 1<<1) {
396+
if (mask & (1 << 1)) {
397397
__HAL_RCC_TIM2_CLK_DISABLE();
398398
}
399399
#endif
400400
#ifdef TIM3
401-
if (mask & 1<<2) {
401+
if (mask & (1 << 2)) {
402402
__HAL_RCC_TIM3_CLK_DISABLE();
403403
}
404404
#endif
405405
#ifdef TIM4
406-
if (mask & 1<<3) {
406+
if (mask & (1 << 3)) {
407407
__HAL_RCC_TIM4_CLK_DISABLE();
408408
}
409409
#endif
410410
#ifdef TIM5
411-
if (mask & 1<<4) {
411+
if (mask & (1 << 4)) {
412412
__HAL_RCC_TIM5_CLK_DISABLE();
413413
}
414414
#endif
415415
//6 and 7 are reserved ADC timers
416416
#ifdef TIM8
417-
if (mask & 1<<7) {
417+
if (mask & (1 << 7)) {
418418
__HAL_RCC_TIM8_CLK_DISABLE();
419419
}
420420
#endif
421421
#ifdef TIM9
422-
if (mask & 1<<8) {
422+
if (mask & (1 << 8)) {
423423
__HAL_RCC_TIM9_CLK_DISABLE();
424424
}
425425
#endif
426426
#ifdef TIM10
427-
if (mask & 1<<9) {
427+
if (mask & (1 << 9)) {
428428
__HAL_RCC_TIM10_CLK_DISABLE();
429429
}
430430
#endif
431431
#ifdef TIM11
432-
if (mask & 1<<10) {
432+
if (mask & (1 << 10)) {
433433
__HAL_RCC_TIM11_CLK_DISABLE();
434434
}
435435
#endif
436436
#ifdef TIM12
437-
if (mask & 1<<11) {
437+
if (mask & (1 << 11)) {
438438
__HAL_RCC_TIM12_CLK_DISABLE();
439439
}
440440
#endif
441441
#ifdef TIM13
442-
if (mask & 1<<12) {
442+
if (mask & (1 << 12)) {
443443
__HAL_RCC_TIM13_CLK_DISABLE();
444444
}
445445
#endif
446446
#ifdef TIM14
447-
if (mask & 1<<13) {
447+
if (mask & (1 << 13)) {
448448
__HAL_RCC_TIM14_CLK_DISABLE();
449449
}
450450
#endif

0 commit comments

Comments
 (0)