Skip to content

Commit

Permalink
stm32: Rename pin_obj_t to machine_pin_obj_t.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jimmo authored and dpgeorge committed Nov 3, 2023
1 parent 286b1b3 commit b4236c7
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 96 deletions.
10 changes: 5 additions & 5 deletions ports/stm32/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,15 +527,15 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
// STM32H5 has two ADC instances where some pins are only available on ADC1 or ADC2 (but not both).
// Assume we're using a channel of ADC1. Can be overridden for ADC2 later in this function.
ADC_TypeDef *adc = ADC1;
const pin_obj_t *const *pin_adc_table = pin_adc1;
const machine_pin_obj_t *const *pin_adc_table = pin_adc1;
uint32_t num_adc_pins = MP_ARRAY_SIZE(pin_adc1);
#endif
uint32_t channel;

if (mp_obj_is_int(pin_obj)) {
channel = adc_get_internal_channel(mp_obj_get_int(pin_obj));
} else {
const pin_obj_t *pin = pin_find(pin_obj);
const machine_pin_obj_t *pin = pin_find(pin_obj);
if ((pin->adc_num & PIN_ADC_MASK) == 0) {
// No ADC function on the given pin.
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Pin(%q) doesn't have ADC capabilities"), pin->name);
Expand All @@ -557,14 +557,14 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
// If this channel corresponds to a pin then configure the pin in ADC mode.
#if defined(STM32H5)
if (channel < num_adc_pins) {
const pin_obj_t *pin = pin_adc_table[channel];
const machine_pin_obj_t *pin = pin_adc_table[channel];
if (pin != NULL) {
mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
}
}
#else
if (channel < MP_ARRAY_SIZE(pin_adc_table)) {
const pin_obj_t *pin = pin_adc_table[channel];
const machine_pin_obj_t *pin = pin_adc_table[channel];
if (pin != NULL) {
mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
}
Expand Down Expand Up @@ -862,7 +862,7 @@ void adc_init_all(pyb_adc_all_obj_t *adc_all, uint32_t resolution, uint32_t en_m
// only initialise those channels that are selected with the en_mask
if (en_mask & (1 << channel)) {
// If this channel corresponds to a pin then configure the pin in ADC mode.
const pin_obj_t *pin = pin_adcall_table[channel];
const machine_pin_obj_t *pin = pin_adcall_table[channel];
if (pin) {
mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
}
Expand Down
14 changes: 8 additions & 6 deletions ports/stm32/boards/make-pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def print(self, out_source):
print("};", file=out_source)
print("", file=out_source)
print(
"const pin_obj_t pin_{:s}_obj = PIN({:s}, {:d}, {:s}, {:s}, {:d});".format(
"const machine_pin_obj_t pin_{:s}_obj = PIN({:s}, {:d}, {:s}, {:s}, {:d});".format(
self.cpu_pin_name(),
self.port_letter(),
self.pin,
Expand All @@ -295,7 +295,7 @@ def print(self, out_source):

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

def print_named(self, label, named_pins, out_source):
print(
"STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label),
"STATIC const mp_rom_map_elem_t machine_pin_{:s}_pins_locals_dict_table[] = {{".format(
label
),
file=out_source,
)
for named_pin in named_pins:
Expand All @@ -395,7 +397,7 @@ def print_named(self, label, named_pins, out_source):
)
print("};", file=out_source)
print(
"MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);".format(
"MP_DEFINE_CONST_DICT(machine_pin_{:s}_pins_locals_dict, machine_pin_{:s}_pins_locals_dict_table);".format(
label, label
),
file=out_source,
Expand Down Expand Up @@ -428,7 +430,7 @@ def print_adc(self, adc_num, out_source):
self.adc_table_size[adc_num] = table_size
print("", file=out_source)
print(
"const pin_obj_t * const pin_adc{:d}[{:d}] = {{".format(adc_num, table_size),
"const machine_pin_obj_t * const pin_adc{:d}[{:d}] = {{".format(adc_num, table_size),
file=out_source,
)
for channel in range(table_size):
Expand All @@ -447,7 +449,7 @@ def print_header(self, out_header, obj_decls):
pin.print_header(out_header)
for adc_num, table_size in self.adc_table_size.items():
print(
"extern const pin_obj_t * const pin_adc{:d}[{:d}];".format(
"extern const machine_pin_obj_t * const pin_adc{:d}[{:d}];".format(
adc_num, table_size
),
file=out_header,
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool can_init(pyb_can_obj_t *can_obj, uint32_t mode, uint32_t prescaler, uint32_

CAN_TypeDef *CANx = NULL;
uint32_t sce_irq = 0;
const pin_obj_t *pins[2];
const machine_pin_obj_t *pins[2];

switch (can_obj->can_id) {
#if defined(MICROPY_HW_CAN1_TX)
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/dac.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_
if (mp_obj_is_int(args[0])) {
dac_id = mp_obj_get_int(args[0]);
} else {
const pin_obj_t *pin = pin_find(args[0]);
const machine_pin_obj_t *pin = pin_find(args[0]);
if (pin == pin_A4) {
dac_id = 1;
} else if (pin == pin_A5) {
Expand Down
8 changes: 4 additions & 4 deletions ports/stm32/extint.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ STATIC const uint8_t nvic_irq_channel[EXTI_NUM_VECTORS] = {
// Set override_callback_obj to true if you want to unconditionally set the
// callback function.
uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t callback_obj, bool override_callback_obj) {
const pin_obj_t *pin = NULL;
const machine_pin_obj_t *pin = NULL;
uint v_line;

if (mp_obj_is_int(pin_obj)) {
Expand Down Expand Up @@ -318,7 +318,7 @@ uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t ca
}

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

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

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

mp_obj_t *cb = &MP_STATE_PORT(pyb_extint_callback)[line];
Expand Down
4 changes: 2 additions & 2 deletions ports/stm32/extint.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
void extint_init0(void);

uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t callback_obj, bool override_callback_obj);
void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj);
void extint_set(const pin_obj_t *pin, uint32_t mode);
void extint_register_pin(const machine_pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj);
void extint_set(const machine_pin_obj_t *pin, uint32_t mode);

void extint_enable(uint line);
void extint_disable(uint line);
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/fdcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool can_init(pyb_can_obj_t *can_obj, uint32_t mode, uint32_t prescaler, uint32_
#endif

FDCAN_GlobalTypeDef *CANx = NULL;
const pin_obj_t *pins[2];
const machine_pin_obj_t *pins[2];

switch (can_obj->can_id) {
#if defined(MICROPY_HW_CAN1_TX)
Expand Down
8 changes: 4 additions & 4 deletions ports/stm32/lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ typedef struct _pyb_lcd_obj_t {

// hardware control for the LCD
const spi_t *spi;
const pin_obj_t *pin_cs1;
const pin_obj_t *pin_rst;
const pin_obj_t *pin_a0;
const pin_obj_t *pin_bl;
const machine_pin_obj_t *pin_cs1;
const machine_pin_obj_t *pin_rst;
const machine_pin_obj_t *pin_a0;
const machine_pin_obj_t *pin_bl;

// character buffer for stdout-like output
char char_buffer[LCD_CHAR_BUF_W * LCD_CHAR_BUF_H];
Expand Down
14 changes: 7 additions & 7 deletions ports/stm32/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
typedef struct _pyb_led_obj_t {
mp_obj_base_t base;
mp_uint_t led_id;
const pin_obj_t *led_pin;
const machine_pin_obj_t *led_pin;
} pyb_led_obj_t;

STATIC const pyb_led_obj_t pyb_led_obj[] = {
Expand All @@ -73,7 +73,7 @@ STATIC const pyb_led_obj_t pyb_led_obj[] = {
void led_init(void) {
/* Turn off LEDs and initialize */
for (int led = 0; led < NUM_LEDS; led++) {
const pin_obj_t *led_pin = pyb_led_obj[led].led_pin;
const machine_pin_obj_t *led_pin = pyb_led_obj[led].led_pin;
mp_hal_gpio_clock_enable(led_pin->gpio);
MICROPY_HW_LED_OFF(led_pin);
mp_hal_pin_output(led_pin);
Expand Down Expand Up @@ -143,7 +143,7 @@ static inline bool led_pwm_is_enabled(int led) {
// this function has a large stack so it should not be inlined
STATIC void led_pwm_init(int led) __attribute__((noinline));
STATIC void led_pwm_init(int led) {
const pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
const led_pwm_config_t *pwm_cfg = &led_pwm_config[led - 1];

// GPIO configuration
Expand Down Expand Up @@ -192,7 +192,7 @@ STATIC void led_pwm_init(int led) {

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

const pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin;
if (state == 0) {
// turn LED off
MICROPY_HW_LED_OFF(led_pin);
Expand Down Expand Up @@ -241,7 +241,7 @@ void led_toggle(pyb_led_t led) {
#endif

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

Expand All @@ -261,7 +261,7 @@ int led_get_intensity(pyb_led_t led) {
}
#endif

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

if (gpio->ODR & led_pin->pin_mask) {
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/machine_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
sample_time = ADC_SAMPLETIME_DEFAULT_INT;
}
} else {
const pin_obj_t *pin = pin_find(source);
const machine_pin_obj_t *pin = pin_find(source);
if (pin->adc_num & PIN_ADC1) {
#if defined(STM32WL)
adc = ADC;
Expand Down
4 changes: 2 additions & 2 deletions ports/stm32/mphalport.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static inline mp_uint_t mp_hal_ticks_cpu(void) {
#define MP_HAL_PIN_SPEED_HIGH (GPIO_SPEED_FREQ_HIGH)
#define MP_HAL_PIN_SPEED_VERY_HIGH (GPIO_SPEED_FREQ_VERY_HIGH)

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

mp_obj_base_t *mp_hal_get_spi_obj(mp_obj_t spi_in);

Expand Down
Loading

0 comments on commit b4236c7

Please sign in to comment.