Skip to content

Commit b4236c7

Browse files
jimmodpgeorge
authored andcommitted
stm32: Rename pin_obj_t to machine_pin_obj_t.
This is now consistent with other ports. Also renamed `pin_{board/cpu}_pins_locals_dict` to `machine_pin_{board/cpu}_pins_locals_dict`. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
1 parent 286b1b3 commit b4236c7

21 files changed

+84
-96
lines changed

ports/stm32/adc.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -527,15 +527,15 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
527527
// STM32H5 has two ADC instances where some pins are only available on ADC1 or ADC2 (but not both).
528528
// Assume we're using a channel of ADC1. Can be overridden for ADC2 later in this function.
529529
ADC_TypeDef *adc = ADC1;
530-
const pin_obj_t *const *pin_adc_table = pin_adc1;
530+
const machine_pin_obj_t *const *pin_adc_table = pin_adc1;
531531
uint32_t num_adc_pins = MP_ARRAY_SIZE(pin_adc1);
532532
#endif
533533
uint32_t channel;
534534

535535
if (mp_obj_is_int(pin_obj)) {
536536
channel = adc_get_internal_channel(mp_obj_get_int(pin_obj));
537537
} else {
538-
const pin_obj_t *pin = pin_find(pin_obj);
538+
const machine_pin_obj_t *pin = pin_find(pin_obj);
539539
if ((pin->adc_num & PIN_ADC_MASK) == 0) {
540540
// No ADC function on the given pin.
541541
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Pin(%q) doesn't have ADC capabilities"), pin->name);
@@ -557,14 +557,14 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
557557
// If this channel corresponds to a pin then configure the pin in ADC mode.
558558
#if defined(STM32H5)
559559
if (channel < num_adc_pins) {
560-
const pin_obj_t *pin = pin_adc_table[channel];
560+
const machine_pin_obj_t *pin = pin_adc_table[channel];
561561
if (pin != NULL) {
562562
mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
563563
}
564564
}
565565
#else
566566
if (channel < MP_ARRAY_SIZE(pin_adc_table)) {
567-
const pin_obj_t *pin = pin_adc_table[channel];
567+
const machine_pin_obj_t *pin = pin_adc_table[channel];
568568
if (pin != NULL) {
569569
mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
570570
}
@@ -862,7 +862,7 @@ void adc_init_all(pyb_adc_all_obj_t *adc_all, uint32_t resolution, uint32_t en_m
862862
// only initialise those channels that are selected with the en_mask
863863
if (en_mask & (1 << channel)) {
864864
// If this channel corresponds to a pin then configure the pin in ADC mode.
865-
const pin_obj_t *pin = pin_adcall_table[channel];
865+
const machine_pin_obj_t *pin = pin_adcall_table[channel];
866866
if (pin) {
867867
mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
868868
}

ports/stm32/boards/make-pins.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def print(self, out_source):
281281
print("};", file=out_source)
282282
print("", file=out_source)
283283
print(
284-
"const pin_obj_t pin_{:s}_obj = PIN({:s}, {:d}, {:s}, {:s}, {:d});".format(
284+
"const machine_pin_obj_t pin_{:s}_obj = PIN({:s}, {:d}, {:s}, {:s}, {:d});".format(
285285
self.cpu_pin_name(),
286286
self.port_letter(),
287287
self.pin,
@@ -295,7 +295,7 @@ def print(self, out_source):
295295

296296
def print_header(self, out_header):
297297
n = self.cpu_pin_name()
298-
print("extern const pin_obj_t pin_{:s}_obj;".format(n), file=out_header)
298+
print("extern const machine_pin_obj_t pin_{:s}_obj;".format(n), file=out_header)
299299
print("#define pin_{:s} (&pin_{:s}_obj)".format(n, n), file=out_header)
300300
if self.alt_fn_count > 0:
301301
print("extern const pin_af_obj_t pin_{:s}_af[];".format(n), file=out_header)
@@ -381,7 +381,9 @@ def parse_board_file(self, filename):
381381

382382
def print_named(self, label, named_pins, out_source):
383383
print(
384-
"STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label),
384+
"STATIC const mp_rom_map_elem_t machine_pin_{:s}_pins_locals_dict_table[] = {{".format(
385+
label
386+
),
385387
file=out_source,
386388
)
387389
for named_pin in named_pins:
@@ -395,7 +397,7 @@ def print_named(self, label, named_pins, out_source):
395397
)
396398
print("};", file=out_source)
397399
print(
398-
"MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);".format(
400+
"MP_DEFINE_CONST_DICT(machine_pin_{:s}_pins_locals_dict, machine_pin_{:s}_pins_locals_dict_table);".format(
399401
label, label
400402
),
401403
file=out_source,
@@ -428,7 +430,7 @@ def print_adc(self, adc_num, out_source):
428430
self.adc_table_size[adc_num] = table_size
429431
print("", file=out_source)
430432
print(
431-
"const pin_obj_t * const pin_adc{:d}[{:d}] = {{".format(adc_num, table_size),
433+
"const machine_pin_obj_t * const pin_adc{:d}[{:d}] = {{".format(adc_num, table_size),
432434
file=out_source,
433435
)
434436
for channel in range(table_size):
@@ -447,7 +449,7 @@ def print_header(self, out_header, obj_decls):
447449
pin.print_header(out_header)
448450
for adc_num, table_size in self.adc_table_size.items():
449451
print(
450-
"extern const pin_obj_t * const pin_adc{:d}[{:d}];".format(
452+
"extern const machine_pin_obj_t * const pin_adc{:d}[{:d}];".format(
451453
adc_num, table_size
452454
),
453455
file=out_header,

ports/stm32/can.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool can_init(pyb_can_obj_t *can_obj, uint32_t mode, uint32_t prescaler, uint32_
6565

6666
CAN_TypeDef *CANx = NULL;
6767
uint32_t sce_irq = 0;
68-
const pin_obj_t *pins[2];
68+
const machine_pin_obj_t *pins[2];
6969

7070
switch (can_obj->can_id) {
7171
#if defined(MICROPY_HW_CAN1_TX)

ports/stm32/dac.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_
324324
if (mp_obj_is_int(args[0])) {
325325
dac_id = mp_obj_get_int(args[0]);
326326
} else {
327-
const pin_obj_t *pin = pin_find(args[0]);
327+
const machine_pin_obj_t *pin = pin_find(args[0]);
328328
if (pin == pin_A4) {
329329
dac_id = 1;
330330
} else if (pin == pin_A5) {

ports/stm32/extint.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ STATIC const uint8_t nvic_irq_channel[EXTI_NUM_VECTORS] = {
244244
// Set override_callback_obj to true if you want to unconditionally set the
245245
// callback function.
246246
uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t callback_obj, bool override_callback_obj) {
247-
const pin_obj_t *pin = NULL;
247+
const machine_pin_obj_t *pin = NULL;
248248
uint v_line;
249249

250250
if (mp_obj_is_int(pin_obj)) {
@@ -318,7 +318,7 @@ uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t ca
318318
}
319319

320320
// This function is intended to be used by the Pin.irq() method
321-
void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj) {
321+
void extint_register_pin(const machine_pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj) {
322322
uint32_t line = pin->pin;
323323

324324
// Check if the ExtInt line is already in use by another Pin/ExtInt
@@ -327,7 +327,7 @@ void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_
327327
if (mp_obj_is_small_int(pyb_extint_callback_arg[line])) {
328328
mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("ExtInt vector %d is already in use"), line);
329329
} else {
330-
const pin_obj_t *other_pin = MP_OBJ_TO_PTR(pyb_extint_callback_arg[line]);
330+
const machine_pin_obj_t *other_pin = MP_OBJ_TO_PTR(pyb_extint_callback_arg[line]);
331331
mp_raise_msg_varg(&mp_type_OSError,
332332
MP_ERROR_TEXT("IRQ resource already taken by Pin('%q')"), other_pin->name);
333333
}
@@ -370,7 +370,7 @@ void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_
370370
}
371371
}
372372

373-
void extint_set(const pin_obj_t *pin, uint32_t mode) {
373+
void extint_set(const machine_pin_obj_t *pin, uint32_t mode) {
374374
uint32_t line = pin->pin;
375375

376376
mp_obj_t *cb = &MP_STATE_PORT(pyb_extint_callback)[line];

ports/stm32/extint.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
void extint_init0(void);
7171

7272
uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t callback_obj, bool override_callback_obj);
73-
void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj);
74-
void extint_set(const pin_obj_t *pin, uint32_t mode);
73+
void extint_register_pin(const machine_pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj);
74+
void extint_set(const machine_pin_obj_t *pin, uint32_t mode);
7575

7676
void extint_enable(uint line);
7777
void extint_disable(uint line);

ports/stm32/fdcan.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bool can_init(pyb_can_obj_t *can_obj, uint32_t mode, uint32_t prescaler, uint32_
137137
#endif
138138

139139
FDCAN_GlobalTypeDef *CANx = NULL;
140-
const pin_obj_t *pins[2];
140+
const machine_pin_obj_t *pins[2];
141141

142142
switch (can_obj->can_id) {
143143
#if defined(MICROPY_HW_CAN1_TX)

ports/stm32/lcd.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ typedef struct _pyb_lcd_obj_t {
8989

9090
// hardware control for the LCD
9191
const spi_t *spi;
92-
const pin_obj_t *pin_cs1;
93-
const pin_obj_t *pin_rst;
94-
const pin_obj_t *pin_a0;
95-
const pin_obj_t *pin_bl;
92+
const machine_pin_obj_t *pin_cs1;
93+
const machine_pin_obj_t *pin_rst;
94+
const machine_pin_obj_t *pin_a0;
95+
const machine_pin_obj_t *pin_bl;
9696

9797
// character buffer for stdout-like output
9898
char char_buffer[LCD_CHAR_BUF_W * LCD_CHAR_BUF_H];

ports/stm32/led.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
typedef struct _pyb_led_obj_t {
4848
mp_obj_base_t base;
4949
mp_uint_t led_id;
50-
const pin_obj_t *led_pin;
50+
const machine_pin_obj_t *led_pin;
5151
} pyb_led_obj_t;
5252

5353
STATIC const pyb_led_obj_t pyb_led_obj[] = {
@@ -73,7 +73,7 @@ STATIC const pyb_led_obj_t pyb_led_obj[] = {
7373
void led_init(void) {
7474
/* Turn off LEDs and initialize */
7575
for (int led = 0; led < NUM_LEDS; led++) {
76-
const pin_obj_t *led_pin = pyb_led_obj[led].led_pin;
76+
const machine_pin_obj_t *led_pin = pyb_led_obj[led].led_pin;
7777
mp_hal_gpio_clock_enable(led_pin->gpio);
7878
MICROPY_HW_LED_OFF(led_pin);
7979
mp_hal_pin_output(led_pin);
@@ -143,7 +143,7 @@ static inline bool led_pwm_is_enabled(int led) {
143143
// this function has a large stack so it should not be inlined
144144
STATIC void led_pwm_init(int led) __attribute__((noinline));
145145
STATIC void led_pwm_init(int led) {
146-
const pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
146+
const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
147147
const led_pwm_config_t *pwm_cfg = &led_pwm_config[led - 1];
148148

149149
// GPIO configuration
@@ -192,7 +192,7 @@ STATIC void led_pwm_init(int led) {
192192

193193
STATIC void led_pwm_deinit(int led) {
194194
// make the LED's pin a standard GPIO output pin
195-
const pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
195+
const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
196196
GPIO_TypeDef *g = led_pin->gpio;
197197
uint32_t pin = led_pin->pin;
198198
static const int mode = 1; // output
@@ -211,7 +211,7 @@ void led_state(pyb_led_t led, int state) {
211211
return;
212212
}
213213

214-
const pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
214+
const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
215215
if (state == 0) {
216216
// turn LED off
217217
MICROPY_HW_LED_OFF(led_pin);
@@ -241,7 +241,7 @@ void led_toggle(pyb_led_t led) {
241241
#endif
242242

243243
// toggle the output data register to toggle the LED state
244-
const pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
244+
const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
245245
led_pin->gpio->ODR ^= led_pin->pin_mask;
246246
}
247247

@@ -261,7 +261,7 @@ int led_get_intensity(pyb_led_t led) {
261261
}
262262
#endif
263263

264-
const pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
264+
const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
265265
GPIO_TypeDef *gpio = led_pin->gpio;
266266

267267
if (gpio->ODR & led_pin->pin_mask) {

ports/stm32/machine_adc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
571571
sample_time = ADC_SAMPLETIME_DEFAULT_INT;
572572
}
573573
} else {
574-
const pin_obj_t *pin = pin_find(source);
574+
const machine_pin_obj_t *pin = pin_find(source);
575575
if (pin->adc_num & PIN_ADC1) {
576576
#if defined(STM32WL)
577577
adc = ADC;

ports/stm32/mphalport.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static inline mp_uint_t mp_hal_ticks_cpu(void) {
9090
#define MP_HAL_PIN_SPEED_HIGH (GPIO_SPEED_FREQ_HIGH)
9191
#define MP_HAL_PIN_SPEED_VERY_HIGH (GPIO_SPEED_FREQ_VERY_HIGH)
9292

93-
#define mp_hal_pin_obj_t const pin_obj_t *
93+
#define mp_hal_pin_obj_t const machine_pin_obj_t *
9494
#define mp_hal_get_pin_obj(o) pin_find(o)
9595
#define mp_hal_pin_name(p) ((p)->name)
9696
#define mp_hal_pin_input(p) mp_hal_pin_config((p), MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_NONE, 0)
@@ -114,7 +114,7 @@ void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio);
114114
void mp_hal_pin_config(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint32_t alt);
115115
bool mp_hal_pin_config_alt(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint8_t fn, uint8_t unit);
116116
void mp_hal_pin_config_speed(mp_hal_pin_obj_t pin_obj, uint32_t speed);
117-
void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj);
117+
void extint_register_pin(const machine_pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj);
118118

119119
mp_obj_base_t *mp_hal_get_spi_obj(mp_obj_t spi_in);
120120

0 commit comments

Comments
 (0)