Skip to content

Commit 6979e96

Browse files
committed
Make formatting changes requested by pre-commit hook
1 parent 7f66a37 commit 6979e96

File tree

5 files changed

+48
-47
lines changed

5 files changed

+48
-47
lines changed

locale/circuitpython.pot

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ msgstr ""
10191019

10201020
#: ports/atmel-samd/common-hal/canio/Listener.c
10211021
#: ports/espressif/common-hal/canio/Listener.c
1022+
#: ports/mimxrt10xx/common-hal/canio/Listener.c
10221023
#: ports/stm/common-hal/canio/Listener.c
10231024
msgid "Filters too complex"
10241025
msgstr ""
@@ -2140,6 +2141,10 @@ msgstr ""
21402141
msgid "Unable to read color palette data"
21412142
msgstr ""
21422143

2144+
#: ports/mimxrt10xx/common-hal/canio/CAN.c
2145+
msgid "Unable to send CAN Message: all Tx message buffers are busy"
2146+
msgstr ""
2147+
21432148
#: ports/espressif/common-hal/mdns/Server.c
21442149
#: ports/raspberrypi/common-hal/mdns/Server.c
21452150
msgid "Unable to start mDNS query"

ports/mimxrt10xx/common-hal/canio/CAN.c

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
// Be verbose
2323
#define MIMXRT_CANIO_CAN_DEBUG(...) (void)0
24-
//#define MIMXRT_CANIO_CAN_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
24+
// #define MIMXRT_CANIO_CAN_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
2525

2626
#define MIMXRT_CANIO_CAN_CALLBACK_DEBUG(...) (void)0
27-
//#define MIMXRT_CANIO_CAN_CALLBACK_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
27+
// #define MIMXRT_CANIO_CAN_CALLBACK_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
2828

2929

3030
static CAN_Type *const flexcan_bases[] = CAN_BASE_PTRS; // e.g.: { (CAN_Type *)0u, CAN1, CAN2, CAN3 }
@@ -67,11 +67,10 @@ static uint8_t mimxrt10xx_flexcan_get_free_tx_mbid(canio_can_obj_t *self) {
6767
bool found_free_tx_mb = false;
6868
int8_t tx_array_id = 0;
6969
mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION();
70-
for ( ; tx_array_id < MIMXRT10XX_FLEXCAN_TX_MB_NUM ; ++tx_array_id)
70+
for ( ; tx_array_id < MIMXRT10XX_FLEXCAN_TX_MB_NUM; ++tx_array_id)
7171
{
7272
uint64_t tx_array_id_bit = (1UL << tx_array_id);
73-
if (!(self->data->tx_state & tx_array_id_bit))
74-
{
73+
if (!(self->data->tx_state & tx_array_id_bit)) {
7574
// Found a free tx array id. Mark it as used.
7675
MIMXRT_CANIO_CAN_DEBUG("canio: Found free Tx MB: %d\n", tx_array_id);
7776
self->data->tx_state |= tx_array_id_bit;
@@ -88,27 +87,23 @@ static uint8_t mimxrt10xx_flexcan_get_free_tx_mbid(canio_can_obj_t *self) {
8887
return MIMXRT10XX_FLEXCAN_TX_ARRID_TO_MBID(tx_array_id);
8988
}
9089

91-
static void mimxrt10xx_flexcan_set_tx_mb_free_by_mbid(canio_can_obj_t *self, uint8_t mb_idx)
92-
{
90+
static void mimxrt10xx_flexcan_set_tx_mb_free_by_mbid(canio_can_obj_t *self, uint8_t mb_idx) {
9391
// We simply set the Nth bit zero. This means that that message buffer is free to use.
9492
uint64_t tx_array_id_bit = (1UL << MIMXRT10XX_FLEXCAN_TX_MBID_TO_ARRID(mb_idx));
9593
self->data->tx_state &= ~(tx_array_id_bit);
9694
}
9795

98-
static void mimxrt10xx_flexcan_set_tx_mb_busy_by_mbid(canio_can_obj_t *self, uint8_t mb_idx)
99-
{
96+
static void mimxrt10xx_flexcan_set_tx_mb_busy_by_mbid(canio_can_obj_t *self, uint8_t mb_idx) {
10097
// We simply set the Nth bit 1. This means that that message buffer is busy and cannot be used.
10198
uint64_t tx_array_id_bit = (1UL << MIMXRT10XX_FLEXCAN_TX_MBID_TO_ARRID(mb_idx));
10299
self->data->tx_state |= tx_array_id_bit;
103100
}
104101

105-
static void mimxrt10xx_flexcan_abort_tx_frames(canio_can_obj_t *self)
106-
{
107-
for (uint8_t tx_array_id = 0 ; tx_array_id < MIMXRT10XX_FLEXCAN_TX_MB_NUM ; ++tx_array_id)
102+
static void mimxrt10xx_flexcan_abort_tx_frames(canio_can_obj_t *self) {
103+
for (uint8_t tx_array_id = 0; tx_array_id < MIMXRT10XX_FLEXCAN_TX_MB_NUM; ++tx_array_id)
108104
{
109105
uint64_t tx_array_id_bit = (1UL << tx_array_id);
110-
if (self->data->tx_state & tx_array_id_bit)
111-
{
106+
if (self->data->tx_state & tx_array_id_bit) {
112107
// Found a used/busy tx message buffer. Abort it.
113108
FLEXCAN_TransferAbortSend(self->data->base, &self->data->handle, MIMXRT10XX_FLEXCAN_TX_ARRID_TO_MBID(tx_array_id));
114109

@@ -119,8 +114,7 @@ static void mimxrt10xx_flexcan_abort_tx_frames(canio_can_obj_t *self)
119114

120115
static void mimxrt10xx_flexcan_handle_error(canio_can_obj_t *self) {
121116
canio_bus_state_t state = common_hal_canio_can_state_get(self);
122-
if (state == BUS_STATE_OFF)
123-
{
117+
if (state == BUS_STATE_OFF) {
124118
// Abort any pending tx and rx in case of bus-off.
125119
mimxrt10xx_flexcan_abort_tx_frames(self);
126120
FLEXCAN_TransferAbortReceiveFifo(self->data->base, &self->data->handle);
@@ -129,11 +123,11 @@ static void mimxrt10xx_flexcan_handle_error(canio_can_obj_t *self) {
129123

130124
static FLEXCAN_CALLBACK(mimxrt10xx_flexcan_callback)
131125
{
132-
(void) base; // unused variable
133-
(void) handle; // unused variable
126+
(void)base; // unused variable
127+
(void)handle; // unused variable
134128
// The result field can either be a message buffer index or a status flags value.
135129

136-
canio_can_obj_t *self = (canio_can_obj_t*) userData;
130+
canio_can_obj_t *self = (canio_can_obj_t *)userData;
137131

138132
switch (status) {
139133

@@ -206,7 +200,7 @@ static FLEXCAN_CALLBACK(mimxrt10xx_flexcan_callback)
206200
// Process FlexCAN module error and status event.
207201
case kStatus_FLEXCAN_ErrorStatus:
208202
// This is *very* verbose when the bus is disconnected!
209-
//MIMXRT_CANIO_CAN_CALLBACK_DEBUG("canio: callback got status = UnHandled or ErrorStatus");
203+
// MIMXRT_CANIO_CAN_CALLBACK_DEBUG("canio: callback got status = UnHandled or ErrorStatus");
210204

211205
// We could do some fancy statistics update, but canio does not have.
212206
mimxrt10xx_flexcan_handle_error(self);
@@ -243,32 +237,31 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, const mcu_pin_obj_t *
243237
FLEXCAN_GetDefaultConfig(&config);
244238

245239
// Change default flexcan module configuration based on canio constructor parameters.
246-
config.clkSrc = CLOCK_GetMux(kCLOCK_CanMux);
247-
config.baudRate = baudrate;
248-
config.enableLoopBack = loopback;
240+
config.clkSrc = CLOCK_GetMux(kCLOCK_CanMux);
241+
config.baudRate = baudrate;
242+
config.enableLoopBack = loopback;
249243
config.enableListenOnlyMode = silent;
250-
config.maxMbNum = 64;
251-
config.enableIndividMask = true; // required to enable matching using a 'Listener'
244+
config.maxMbNum = 64;
245+
config.enableIndividMask = true; // required to enable matching using a 'Listener'
252246
// config.disableSelfReception = true; // TODO: do we want to disable this?
253247

254248
#if (defined(MIMXRT10XX_FLEXCAN_USE_IMPROVED_TIMING_CONFIG) && MIMXRT10XX_FLEXCAN_USE_IMPROVED_TIMING_CONFIG)
255-
// If improved timing configuration is enabled then tell the SDK to calculate it.
256-
flexcan_timing_config_t timing_config;
257-
memset(&timing_config, 0, sizeof(flexcan_timing_config_t));
258-
if (FLEXCAN_CalculateImprovedTimingValues(self->data->base, config.baudRate, MIMXRT10XX_FLEXCAN_CLK_FREQ, &timing_config))
259-
{
260-
// SDK could calculate the improved timing configuration. Yay!
261-
// Let's update our flexcan module config to use it.
262-
memcpy(&(config.timingConfig), &timing_config, sizeof(flexcan_timing_config_t));
263-
}
249+
// If improved timing configuration is enabled then tell the SDK to calculate it.
250+
flexcan_timing_config_t timing_config;
251+
memset(&timing_config, 0, sizeof(flexcan_timing_config_t));
252+
if (FLEXCAN_CalculateImprovedTimingValues(self->data->base, config.baudRate, MIMXRT10XX_FLEXCAN_CLK_FREQ, &timing_config)) {
253+
// SDK could calculate the improved timing configuration. Yay!
254+
// Let's update our flexcan module config to use it.
255+
memcpy(&(config.timingConfig), &timing_config, sizeof(flexcan_timing_config_t));
256+
}
264257
#endif
265258

266259
// Initialize the flexcan module with user-defined settings.
267260
FLEXCAN_Init(self->data->base, &config, MIMXRT10XX_FLEXCAN_CLK_FREQ);
268261

269262
// Create FlexCAN handle structure and set call back function.
270263
// As callback data we set 'self'. In callback we can cast it back to 'canio_can_obj_t'.
271-
FLEXCAN_TransferCreateHandle(self->data->base, &self->data->handle, mimxrt10xx_flexcan_callback, (void*)self);
264+
FLEXCAN_TransferCreateHandle(self->data->base, &self->data->handle, mimxrt10xx_flexcan_callback, (void *)self);
272265

273266
// Set rx mask to don't care on all bits.
274267
flexcan_rx_fifo_config_t fifo_config;
@@ -323,7 +316,9 @@ void common_hal_canio_can_restart(canio_can_obj_t *self) {
323316
// But I will leave this code here just in case.
324317

325318
canio_bus_state_t state = common_hal_canio_can_state_get(self);
326-
if (state != BUS_STATE_OFF) return;
319+
if (state != BUS_STATE_OFF) {
320+
return;
321+
}
327322

328323
self->data->base->CTRL1 &= ~CAN_CTRL1_BOFFREC_MASK;
329324

@@ -357,8 +352,7 @@ void common_hal_canio_can_send(canio_can_obj_t *self, mp_obj_t message_in) {
357352
maybe_auto_restart(self);
358353

359354
canio_bus_state_t state = common_hal_canio_can_state_get(self);
360-
if (state == BUS_STATE_OFF)
361-
{
355+
if (state == BUS_STATE_OFF) {
362356
// Bus is off. Transmit failed.
363357
mp_raise_OSError(MP_ENODEV);
364358
}

ports/mimxrt10xx/common-hal/canio/CAN.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
typedef struct canio_can_obj {
1616
mp_obj_base_t base;
17-
mimxrt10xx_flexcan_data_t* data;
17+
mimxrt10xx_flexcan_data_t *data;
1818
int baudrate;
1919
const mcu_pin_obj_t *rx_pin;
2020
const mcu_pin_obj_t *tx_pin;

ports/mimxrt10xx/common-hal/canio/Listener.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ void common_hal_canio_listener_construct(canio_listener_obj_t *self, canio_can_o
5555
fifo_config.idFilterNum = 1;
5656
self->can->data->rx_fifo_filter[0] = 0x0;
5757
FLEXCAN_SetRxIndividualMask(self->can->data->base, 0, 0x0);
58-
}
59-
else {
58+
} else {
6059
// Required to touch any CAN registers
6160
FLEXCAN_EnterFreezeMode(self->can->data->base);
6261

@@ -94,7 +93,9 @@ void common_hal_canio_listener_check_for_deinit(canio_listener_obj_t *self) {
9493
}
9594

9695
int common_hal_canio_listener_in_waiting(canio_listener_obj_t *self) {
97-
if(FLEXCAN_GetMbStatusFlags(self->can->data->base, kFLEXCAN_RxFifoFrameAvlFlag)) return 1;
96+
if (FLEXCAN_GetMbStatusFlags(self->can->data->base, kFLEXCAN_RxFifoFrameAvlFlag)) {
97+
return 1;
98+
}
9899
return 0;
99100
}
100101

@@ -114,7 +115,7 @@ mp_obj_t common_hal_canio_listener_receive(canio_listener_obj_t *self) {
114115
}
115116

116117
flexcan_frame_t rx_frame;
117-
if(FLEXCAN_ReadRxFifo(self->can->data->base, &rx_frame) != kStatus_Success) {
118+
if (FLEXCAN_ReadRxFifo(self->can->data->base, &rx_frame) != kStatus_Success) {
118119
mp_raise_OSError(MP_EIO);
119120
}
120121

ports/mimxrt10xx/tools/gen_peripherals_data.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
"RX_DATA": "RX_DATA0",
2424
}
2525

26-
INSTANCE_RENAME = {
27-
"FLEXCAN" : "CAN"
28-
}
26+
INSTANCE_RENAME = {"FLEXCAN": "CAN"}
2927

3028
INSTANCE_RE = re.compile("([a-zA-Z0-9]+?)([0-9]+)$")
31-
def rename_instance(instance:str)-> str:
29+
30+
31+
def rename_instance(instance: str) -> str:
3232
instance_match = INSTANCE_RE.match(instance)
3333
if instance_match is None:
3434
return instance
@@ -39,6 +39,7 @@ def rename_instance(instance:str)-> str:
3939
instance_id = str(instance_res[1])
4040
return INSTANCE_RENAME.get(instance_name, instance_name) + instance_id
4141

42+
4243
SKIP_LPSR = True
4344

4445
svd_folder = pathlib.Path(sys.argv[1])

0 commit comments

Comments
 (0)