Skip to content

Commit d47b882

Browse files
committed
Add pre-commit changes to UART
- Formatting & codespell fixes from pre-commit
1 parent 872e81c commit d47b882

File tree

7 files changed

+74
-97
lines changed

7 files changed

+74
-97
lines changed

ports/analog/common-hal/busio/I2C.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// Define a struct for what BUSIO.I2C should carry
1818
typedef struct {
1919
mp_obj_base_t base;
20-
mxc_i2c_regs_t* i2c_regs;
20+
mxc_i2c_regs_t *i2c_regs;
2121
bool has_lock;
2222
const mcu_pin_obj_t *scl;
2323
const mcu_pin_obj_t *sda;

ports/analog/common-hal/busio/SPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// Define a struct for what BUSIO.SPI should carry
1818
typedef struct {
1919
mp_obj_base_t base;
20-
mxc_spi_regs_t* spi_regs;
20+
mxc_spi_regs_t *spi_regs;
2121
bool has_lock;
2222
const mcu_pin_obj_t *sck;
2323
const mcu_pin_obj_t *mosi;

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

Lines changed: 46 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ typedef enum {
8989
UART_NEVER_RESET,
9090
} uart_status_t;
9191

92-
static uint32_t timeout_ms=0;
92+
static uint32_t timeout_ms = 0;
9393

9494
// Set each bit to indicate an active UART
9595
// will be checked by ISR Handler for which ones to call
@@ -99,7 +99,7 @@ static volatile int uart_err;
9999
// static uint8_t uart_never_reset_mask = 0;
100100

101101
static int isValidBaudrate(uint32_t baudrate) {
102-
switch(baudrate) {
102+
switch (baudrate) {
103103
case UART_9600:
104104
return 1;
105105
break;
@@ -133,17 +133,16 @@ static int isValidBaudrate(uint32_t baudrate) {
133133
}
134134
}
135135

136-
static mxc_uart_parity_t convertParity(busio_uart_parity_t busio_parity)
137-
{
138-
switch(busio_parity) {
139-
case BUSIO_UART_PARITY_NONE:
140-
return MXC_UART_PARITY_DISABLE;
141-
case BUSIO_UART_PARITY_EVEN:
142-
return MXC_UART_PARITY_EVEN_0;
143-
case BUSIO_UART_PARITY_ODD:
144-
return MXC_UART_PARITY_ODD_0;
145-
default:
146-
mp_raise_ValueError(MP_ERROR_TEXT("Parity must be ODD, EVEN, or NONE\n"));
136+
static mxc_uart_parity_t convertParity(busio_uart_parity_t busio_parity) {
137+
switch (busio_parity) {
138+
case BUSIO_UART_PARITY_NONE:
139+
return MXC_UART_PARITY_DISABLE;
140+
case BUSIO_UART_PARITY_EVEN:
141+
return MXC_UART_PARITY_EVEN_0;
142+
case BUSIO_UART_PARITY_ODD:
143+
return MXC_UART_PARITY_ODD_0;
144+
default:
145+
mp_raise_ValueError(MP_ERROR_TEXT("Parity must be ODD, EVEN, or NONE\n"));
147146
}
148147
}
149148

@@ -169,33 +168,31 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
169168
const mcu_pin_obj_t *rs485_dir, bool rs485_invert,
170169
uint32_t baudrate, uint8_t bits, busio_uart_parity_t parity, uint8_t stop,
171170
mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer,
172-
bool sigint_enabled)
173-
{
171+
bool sigint_enabled) {
174172
int err, temp;
175173

176174
// Check for NULL Pointers && valid UART settings
177-
assert( self );
175+
assert(self);
178176

179177
// Assign UART ID based on pins
180178
temp = pinsToUart(tx, rx);
181179
if (temp == -1) {
182180
// Error will be indicated by pinsToUart(tx, rx) function
183181
return;
184-
}
185-
else {
182+
} else {
186183
self->uart_id = temp;
187184
self->uart_regs = MXC_UART_GET_UART(temp);
188185
}
189186

190-
assert( (self->uart_id >= 0) && (self->uart_id < NUM_UARTS) );
187+
assert((self->uart_id >= 0) && (self->uart_id < NUM_UARTS));
191188

192189
// Indicate RS485 not implemented
193-
if ( (rs485_dir != NULL) || (rs485_invert) ) {
190+
if ((rs485_dir != NULL) || (rs485_invert)) {
194191
mp_raise_NotImplementedError(MP_ERROR_TEXT("RS485"));
195192
}
196193

197194
if ((rx != NULL) && (tx != NULL)) {
198-
err = MXC_UART_Init(self->uart_regs, baudrate, MXC_UART_IBRO_CLK);
195+
err = MXC_UART_Init(self->uart_regs, baudrate, MXC_UART_IBRO_CLK);
199196
if (err != E_NO_ERROR) {
200197
mp_raise_RuntimeError(MP_ERROR_TEXT("Failed to initialize UART.\n"));
201198
}
@@ -205,14 +202,11 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
205202
self->rx_pin = rx;
206203
common_hal_mcu_pin_claim(self->tx_pin);
207204
common_hal_mcu_pin_claim(self->rx_pin);
208-
}
209-
else if (tx != NULL) {
205+
} else if (tx != NULL) {
210206
mp_raise_NotImplementedError(MP_ERROR_TEXT("UART needs TX & RX"));
211-
}
212-
else if (rx != NULL) {
207+
} else if (rx != NULL) {
213208
mp_raise_NotImplementedError(MP_ERROR_TEXT("UART needs TX & RX"));
214-
}
215-
else {
209+
} else {
216210
// Should not get here, as shared-bindings API should not call this way
217211
}
218212

@@ -222,13 +216,12 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
222216
self->rts_pin = rts;
223217
common_hal_mcu_pin_claim(self->cts_pin);
224218
common_hal_mcu_pin_claim(self->rts_pin);
225-
}
226-
else if (cts || rts) {
219+
} else if (cts || rts) {
227220
mp_raise_ValueError(MP_ERROR_TEXT("Flow Ctrl needs both CTS & RTS"));
228221
}
229222

230223
// Set stop bits & data size
231-
assert( (stop == 1) || (stop == 2) );
224+
assert((stop == 1) || (stop == 2));
232225
mp_arg_validate_int(bits, 8, MP_QSTR_bits);
233226
MXC_UART_SetDataSize(self->uart_regs, bits);
234227
MXC_UART_SetStopBits(self->uart_regs, stop);
@@ -270,8 +263,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
270263
return;
271264
}
272265

273-
void common_hal_busio_uart_deinit(busio_uart_obj_t *self)
274-
{
266+
void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
275267
assert(self);
276268

277269
if (!common_hal_busio_uart_deinited(self)) {
@@ -300,22 +292,19 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self)
300292
}
301293
}
302294

303-
bool common_hal_busio_uart_deinited(busio_uart_obj_t *self)
304-
{
295+
bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) {
305296
if (uarts_active & (1 << self->uart_id)) {
306297
return false;
307-
}
308-
else {
298+
} else {
309299
return true;
310300
};
311301
}
312302

313303
// Read characters. len is in characters NOT bytes!
314304
size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
315-
uint8_t *data, size_t len, int *errcode)
316-
{
305+
uint8_t *data, size_t len, int *errcode) {
317306
int err;
318-
uint32_t start_time=0;
307+
uint32_t start_time = 0;
319308
static size_t bytes_remaining;
320309

321310
// Setup globals & status tracking
@@ -343,12 +332,12 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
343332
*errcode = err;
344333
MXC_UART_AbortAsync(self->uart_regs);
345334
NVIC_DisableIRQ(MXC_UART_GET_IRQ(self->uart_id));
346-
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("\nERR: Error starting trasaction: %d\n"), err);
335+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("\nERR: Error starting transaction: %d\n"), err);
347336
}
348337

349338
// Wait for transaction completion or timeout
350-
while ( (uart_status[self->uart_id] != UART_FREE) &&
351-
(supervisor_ticks_ms64() - start_time < (self->timeout * 1000))) {
339+
while ((uart_status[self->uart_id] != UART_FREE) &&
340+
(supervisor_ticks_ms64() - start_time < (self->timeout * 1000))) {
352341
}
353342

354343
// If the timeout gets hit, abort and error out
@@ -357,7 +346,6 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
357346
NVIC_DisableIRQ(MXC_UART_GET_IRQ(self->uart_id));
358347
mp_raise_RuntimeError(MP_ERROR_TEXT("\nERR: Uart transaction timed out.\n"));
359348
}
360-
361349
// Check for errors from the callback
362350
else if (uart_err != E_NO_ERROR) {
363351
MXC_UART_AbortAsync(self->uart_regs);
@@ -371,11 +359,10 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
371359

372360
// Write characters. len is in characters NOT bytes!
373361
// This function blocks until the timeout finishes
374-
size_t common_hal_busio_uart_write(busio_uart_obj_t *self,
375-
const uint8_t *data, size_t len, int *errcode)
376-
{
362+
size_t common_hal_busio_uart_write(busio_uart_obj_t *self,
363+
const uint8_t *data, size_t len, int *errcode) {
377364
int err;
378-
uint32_t start_time=0;
365+
uint32_t start_time = 0;
379366
static size_t bytes_remaining;
380367

381368
// Setup globals & status tracking
@@ -407,8 +394,8 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
407394
}
408395

409396
// Wait for transaction completion or timeout
410-
while ( (uart_status[self->uart_id] != UART_FREE) &&
411-
(supervisor_ticks_ms64() - start_time < (self->timeout * 1000))) {
397+
while ((uart_status[self->uart_id] != UART_FREE) &&
398+
(supervisor_ticks_ms64() - start_time < (self->timeout * 1000))) {
412399

413400
// Call the handler and abort if errors
414401
uart_err = MXC_UART_AsyncHandler(MXC_UART_GET_UART(0));
@@ -425,7 +412,6 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
425412
NVIC_DisableIRQ(MXC_UART_GET_IRQ(self->uart_id));
426413
mp_raise_ConnectionError(MP_ERROR_TEXT("\nERR: Uart transaction timed out.\n"));
427414
}
428-
429415
// Check for errors from the callback
430416
else if (uart_err != E_NO_ERROR) {
431417
MXC_UART_AbortAsync(self->uart_regs);
@@ -436,29 +422,24 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
436422
return len;
437423
}
438424

439-
uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self)
440-
{
425+
uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) {
441426
return self->baudrate;
442427
}
443428

444429
// Validate baudrate
445-
void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate)
446-
{
447-
if ( isValidBaudrate(baudrate) ) {
430+
void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) {
431+
if (isValidBaudrate(baudrate)) {
448432
self->baudrate = baudrate;
449-
}
450-
else {
433+
} else {
451434
mp_raise_ValueError(MP_ERROR_TEXT("Baudrate invalid. Must be a standard UART baudrate.\n"));
452435
}
453436
}
454437

455-
mp_float_t common_hal_busio_uart_get_timeout(busio_uart_obj_t *self)
456-
{
438+
mp_float_t common_hal_busio_uart_get_timeout(busio_uart_obj_t *self) {
457439
return self->timeout;
458440
}
459441

460-
void common_hal_busio_uart_set_timeout(busio_uart_obj_t *self, mp_float_t timeout)
461-
{
442+
void common_hal_busio_uart_set_timeout(busio_uart_obj_t *self, mp_float_t timeout) {
462443
if (timeout > 100.0) {
463444
mp_raise_ValueError(MP_ERROR_TEXT("Timeout must be < 100 seconds"));
464445
}
@@ -469,23 +450,19 @@ void common_hal_busio_uart_set_timeout(busio_uart_obj_t *self, mp_float_t timeou
469450
return;
470451
}
471452

472-
uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self)
473-
{
453+
uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
474454
return MXC_UART_GetRXFIFOAvailable(self->uart_regs);
475455
}
476456

477-
void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self)
478-
{
457+
void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) {
479458
MXC_UART_ClearRXFIFO(self->uart_regs);
480459
}
481460

482-
bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self)
483-
{
461+
bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {
484462
return !(MXC_UART_GetStatus(self->uart_regs) & (MXC_F_UART_STATUS_TX_BUSY));
485463
}
486464

487-
void common_hal_busio_uart_never_reset(busio_uart_obj_t *self)
488-
{
465+
void common_hal_busio_uart_never_reset(busio_uart_obj_t *self) {
489466
common_hal_never_reset_pin(self->tx_pin);
490467
common_hal_never_reset_pin(self->rx_pin);
491468
common_hal_never_reset_pin(self->cts_pin);

ports/analog/common-hal/busio/UART.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef struct {
2323

2424
int uart_id;
2525
int uart_map;
26-
mxc_uart_regs_t* uart_regs;
26+
mxc_uart_regs_t *uart_regs;
2727

2828
bool parity;
2929
uint8_t bits;

ports/analog/common-hal/microcontroller/Pin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void reset_all_pins(void) {
3737
}
3838

3939
void reset_pin_number(uint8_t pin_port, uint8_t pin_pad) {
40-
if ( (pin_port == INVALID_PIN) || (pin_port > NUM_GPIO_PORTS) ) {
40+
if ((pin_port == INVALID_PIN) || (pin_port > NUM_GPIO_PORTS)) {
4141
return;
4242
}
4343

ports/analog/max32_port.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@
3030
#define GPIO4_PIN_MASK 0x00000003
3131
#define GPIO4_RESET_MASK 0xFFFFFF77
3232
#define GPIO4_OUTEN_MASK(mask) \
33-
(((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \
34-
((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_OE_POS - 1)))
33+
(((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \
34+
((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_OE_POS - 1)))
3535
#define GPIO4_PULLDIS_MASK(mask) \
36-
(((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \
37-
((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_PE_POS - 1)))
36+
(((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \
37+
((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_PE_POS - 1)))
3838
#define GPIO4_DATAOUT_MASK(mask) \
39-
(((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \
40-
((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1)))
39+
(((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \
40+
((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1)))
4141
#define GPIO4_DATAOUT_GET_MASK(mask) \
42-
((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \
43-
((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_DO) >> \
44-
(MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) & \
45-
mask)
42+
((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \
43+
((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_DO) >> \
44+
(MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) & \
45+
mask)
4646
#define GPIO4_DATAIN_MASK(mask) \
47-
((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \
48-
((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \
49-
(MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1))) & \
50-
mask)
47+
((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \
48+
((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \
49+
(MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1))) & \
50+
mask)
5151
#define GPIO4_AFEN_MASK(mask) \
52-
(((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \
53-
((mask & (1 << 1)) >> (MXC_F_MCR_OUTEN_SQWOUT_EN_POS + 1)))
52+
(((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \
53+
((mask & (1 << 1)) >> (MXC_F_MCR_OUTEN_SQWOUT_EN_POS + 1)))
5454
/** END: GPIO4 Handling specific to MAX32690 */
5555

5656
#endif

ports/analog/peripherals/max32690/max32_uart.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323

2424
const mxc_gpio_cfg_t uart_maps[NUM_UARTS] = {
2525
{ MXC_GPIO2, (MXC_GPIO_PIN_11 | MXC_GPIO_PIN_12), MXC_GPIO_FUNC_ALT1,
26-
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
26+
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
2727
{ MXC_GPIO2, (MXC_GPIO_PIN_14 | MXC_GPIO_PIN_16), MXC_GPIO_FUNC_ALT1,
28-
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
28+
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
2929
{ MXC_GPIO1, (MXC_GPIO_PIN_9 | MXC_GPIO_PIN_10),
30-
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_WEAK_PULL_UP,
31-
MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
30+
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_WEAK_PULL_UP,
31+
MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
3232
{ MXC_GPIO3, (MXC_GPIO_PIN_0 | MXC_GPIO_PIN_1),
33-
MXC_GPIO_FUNC_ALT2, MXC_GPIO_PAD_WEAK_PULL_UP,
34-
MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }
33+
MXC_GPIO_FUNC_ALT2, MXC_GPIO_PAD_WEAK_PULL_UP,
34+
MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }
3535
};
3636

3737
int pinsToUart(const mcu_pin_obj_t *rx, const mcu_pin_obj_t *tx) {
3838
for (int i = 0; i < NUM_UARTS; i++) {
39-
if ( (uart_maps[i].port == (MXC_GPIO_GET_GPIO(tx->port)))
40-
&& (uart_maps[i].mask == (( tx->mask) | (rx->mask))) ) {
39+
if ((uart_maps[i].port == (MXC_GPIO_GET_GPIO(tx->port)))
40+
&& (uart_maps[i].mask == ((tx->mask) | (rx->mask)))) {
4141
return i;
4242
}
4343
}

0 commit comments

Comments
 (0)