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 <jim.mussared@gmail.com>
pull/12211/head
Jim Mussared 2023-08-09 02:14:13 +10:00 zatwierdzone przez Damien George
rodzic 286b1b3ed9
commit b4236c7368
21 zmienionych plików z 84 dodań i 96 usunięć

Wyświetl plik

@ -527,7 +527,7 @@ 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;
@ -535,7 +535,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
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);
@ -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);
}
@ -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);
}

Wyświetl plik

@ -281,7 +281,7 @@ class Pin(object):
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,
@ -295,7 +295,7 @@ class Pin(object):
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)
@ -381,7 +381,9 @@ class Pins(object):
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:
@ -395,7 +397,7 @@ class Pins(object):
)
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,
@ -428,7 +430,7 @@ class Pins(object):
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):
@ -447,7 +449,7 @@ class Pins(object):
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,

Wyświetl plik

@ -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)

Wyświetl plik

@ -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) {

Wyświetl plik

@ -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)) {
@ -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
@ -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);
}
@ -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];

Wyświetl plik

@ -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);

Wyświetl plik

@ -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)

Wyświetl plik

@ -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];

Wyświetl plik

@ -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[] = {
@ -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);
@ -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
@ -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
@ -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);
@ -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;
}
@ -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) {

Wyświetl plik

@ -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;

Wyświetl plik

@ -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)
@ -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);

Wyświetl plik

@ -97,10 +97,10 @@ void pin_init0(void) {
}
// C API used to convert a user-supplied pin name into an ordinal pin number.
const pin_obj_t *pin_find(mp_obj_t user_obj) {
const machine_pin_obj_t *pin_find(mp_obj_t user_obj) {
const mp_print_t *print = &mp_plat_print;
const pin_obj_t *pin_obj;
const machine_pin_obj_t *pin_obj;
// If a pin was provided, then use it
if (mp_obj_is_type(user_obj, &pin_type)) {
@ -149,7 +149,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
}
// See if the pin name matches a board pin
pin_obj = pin_find_named_pin(&pin_board_pins_locals_dict, user_obj);
pin_obj = pin_find_named_pin(&machine_pin_board_pins_locals_dict, user_obj);
if (pin_obj) {
if (pin_class_debug) {
mp_printf(print, "Pin.board maps ");
@ -162,7 +162,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
}
// See if the pin name matches a cpu pin
pin_obj = pin_find_named_pin(&pin_cpu_pins_locals_dict, user_obj);
pin_obj = pin_find_named_pin(&machine_pin_cpu_pins_locals_dict, user_obj);
if (pin_obj) {
if (pin_class_debug) {
mp_printf(print, "Pin.cpu maps ");
@ -180,7 +180,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
/// \method __str__()
/// Return a string describing the pin object.
STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
// pin name
mp_printf(print, "Pin(Pin.cpu.%q, mode=Pin.", self->name);
@ -238,7 +238,7 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
}
}
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
STATIC mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *pin, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
/// \classmethod \constructor(id, ...)
/// Create a new Pin object associated with the id. If additional arguments are given,
@ -247,7 +247,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
// Run an argument through the mapper and return the result.
const pin_obj_t *pin = pin_find(args[0]);
const machine_pin_obj_t *pin = pin_find(args[0]);
if (n_args > 1 || n_kw > 0) {
// pin mode given, so configure this GPIO
@ -265,7 +265,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
// fast method for getting/setting pin value
STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (n_args == 0) {
// get pin
return MP_OBJ_NEW_SMALL_INT(mp_hal_pin_read(self));
@ -303,7 +303,7 @@ STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, MP_ROM_PTR(&pin_map_dic
/// \classmethod af_list()
/// Returns an array of alternate functions available for this pin.
STATIC mp_obj_t pin_af_list(mp_obj_t self_in) {
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t result = mp_obj_new_list(0, NULL);
const pin_af_obj_t *af = self->af;
@ -327,7 +327,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, MP_ROM_PTR(&pin_debug_fun_obj));
// init(mode, pull=None, alt=-1, *, value, alt)
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT },
{ MP_QSTR_pull, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE}},
@ -402,14 +402,14 @@ STATIC mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
STATIC mp_obj_t pin_off(mp_obj_t self_in) {
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_hal_pin_low(self);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off);
STATIC mp_obj_t pin_on(mp_obj_t self_in) {
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_hal_pin_high(self);
return mp_const_none;
}
@ -423,7 +423,7 @@ STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
{ MP_QSTR_trigger, MP_ARG_INT, {.u_int = GPIO_MODE_IT_RISING | GPIO_MODE_IT_FALLING} },
{ MP_QSTR_hard, MP_ARG_BOOL, {.u_bool = false} },
};
pin_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@ -441,7 +441,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq);
/// \method name()
/// Get the pin name.
STATIC mp_obj_t pin_name(mp_obj_t self_in) {
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_QSTR(self->name);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name);
@ -449,11 +449,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name);
/// \method names()
/// Returns the cpu and board names for this pin.
STATIC mp_obj_t pin_names(mp_obj_t self_in) {
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t result = mp_obj_new_list(0, NULL);
mp_obj_list_append(result, MP_OBJ_NEW_QSTR(self->name));
const mp_map_t *map = &pin_board_pins_locals_dict.map;
const mp_map_t *map = &machine_pin_board_pins_locals_dict.map;
mp_map_elem_t *elem = map->table;
for (mp_uint_t i = 0; i < map->used; i++, elem++) {
@ -468,7 +468,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names);
/// \method port()
/// Get the pin port.
STATIC mp_obj_t pin_port(mp_obj_t self_in) {
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(self->port);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port);
@ -476,7 +476,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port);
/// \method pin()
/// Get the pin number.
STATIC mp_obj_t pin_pin(mp_obj_t self_in) {
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(self->pin);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin);
@ -484,7 +484,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin);
/// \method gpio()
/// Returns the base address of the GPIO block associated with this pin.
STATIC mp_obj_t pin_gpio(mp_obj_t self_in) {
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT((intptr_t)self->gpio);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_gpio_obj, pin_gpio);
@ -572,7 +572,7 @@ STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);
STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
(void)errcode;
pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in);
switch (request) {
case MP_PIN_READ: {

Wyświetl plik

@ -53,7 +53,7 @@ typedef struct {
uint32_t pin_mask;
pin_gpio_t *gpio;
const pin_af_obj_t *af;
} pin_obj_t;
} machine_pin_obj_t;
extern const mp_obj_type_t pin_type;
extern const mp_obj_type_t pin_af_type;
@ -61,38 +61,22 @@ extern const mp_obj_type_t pin_af_type;
// Include all of the individual pin objects
#include "genhdr/pins.h"
typedef struct {
const char *name;
const pin_obj_t *pin;
} pin_named_pin_t;
extern const pin_named_pin_t pin_board_pins[];
extern const pin_named_pin_t pin_cpu_pins[];
// extern pin_map_obj_t pin_map_obj;
typedef struct {
mp_obj_base_t base;
qstr name;
const pin_named_pin_t *named_pins;
} pin_named_pins_obj_t;
extern const mp_obj_type_t pin_board_pins_obj_type;
extern const mp_obj_type_t pin_cpu_pins_obj_type;
extern const mp_obj_dict_t pin_cpu_pins_locals_dict;
extern const mp_obj_dict_t pin_board_pins_locals_dict;
extern const mp_obj_dict_t machine_pin_cpu_pins_locals_dict;
extern const mp_obj_dict_t machine_pin_board_pins_locals_dict;
MP_DECLARE_CONST_FUN_OBJ_KW(pin_init_obj);
void pin_init0(void);
uint32_t pin_get_mode(const pin_obj_t *pin);
uint32_t pin_get_pull(const pin_obj_t *pin);
uint32_t pin_get_af(const pin_obj_t *pin);
const pin_obj_t *pin_find(mp_obj_t user_obj);
const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit);
const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx);
const pin_af_obj_t *pin_find_af_by_name(const pin_obj_t *pin, const char *name);
uint32_t pin_get_mode(const machine_pin_obj_t *pin);
uint32_t pin_get_pull(const machine_pin_obj_t *pin);
uint32_t pin_get_af(const machine_pin_obj_t *pin);
const machine_pin_obj_t *pin_find(mp_obj_t user_obj);
const machine_pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
const pin_af_obj_t *pin_find_af(const machine_pin_obj_t *pin, uint8_t fn, uint8_t unit);
const pin_af_obj_t *pin_find_af_by_index(const machine_pin_obj_t *pin, mp_uint_t af_idx);
const pin_af_obj_t *pin_find_af_by_name(const machine_pin_obj_t *pin, const char *name);
#endif // MICROPY_INCLUDED_STM32_PIN_H

Wyświetl plik

@ -5,7 +5,7 @@
// GPIO_MODE_INPUT, GPIO_MODE_OUTPUT_PP, GPIO_MODE_OUTPUT_OD,
// GPIO_MODE_AF_PP, GPIO_MODE_AF_OD, or GPIO_MODE_ANALOG.
uint32_t pin_get_mode(const pin_obj_t *pin) {
uint32_t pin_get_mode(const machine_pin_obj_t *pin) {
GPIO_TypeDef *gpio = pin->gpio;
uint32_t mode = (gpio->MODER >> (pin->pin * 2)) & 3;
if (mode == GPIO_MODE_OUTPUT_PP || mode == GPIO_MODE_AF_PP) {
@ -19,12 +19,12 @@ uint32_t pin_get_mode(const pin_obj_t *pin) {
// Returns the pin pullup/pulldown. The value returned by this macro should
// be one of GPIO_NOPULL, GPIO_PULLUP, or GPIO_PULLDOWN.
uint32_t pin_get_pull(const pin_obj_t *pin) {
uint32_t pin_get_pull(const machine_pin_obj_t *pin) {
return (pin->gpio->PUPDR >> (pin->pin * 2)) & 3;
}
// Returns the af (alternate function) index currently set for a pin.
uint32_t pin_get_af(const pin_obj_t *pin) {
uint32_t pin_get_af(const machine_pin_obj_t *pin) {
return (pin->gpio->AFR[pin->pin >> 3] >> ((pin->pin & 7) * 4)) & 0xf;
}

Wyświetl plik

@ -133,6 +133,8 @@ enum {
PIN_ADC1 = (1 << 0),
PIN_ADC2 = (1 << 1),
PIN_ADC3 = (1 << 2),
PIN_ADC4 = (1 << 3),
PIN_ADC5 = (1 << 4),
};
typedef GPIO_TypeDef pin_gpio_t;

Wyświetl plik

@ -35,17 +35,17 @@ MP_DEFINE_CONST_OBJ_TYPE(
pin_cpu_pins_obj_type,
MP_QSTR_cpu,
MP_TYPE_FLAG_NONE,
locals_dict, &pin_cpu_pins_locals_dict
locals_dict, &machine_pin_cpu_pins_locals_dict
);
MP_DEFINE_CONST_OBJ_TYPE(
pin_board_pins_obj_type,
MP_QSTR_board,
MP_TYPE_FLAG_NONE,
locals_dict, &pin_board_pins_locals_dict
locals_dict, &machine_pin_board_pins_locals_dict
);
const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
const machine_pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) {
const mp_map_t *named_map = &named_pins->map;
mp_map_elem_t *named_elem = mp_map_lookup((mp_map_t *)named_map, name, MP_MAP_LOOKUP);
if (named_elem != NULL && named_elem->value != MP_OBJ_NULL) {
@ -54,7 +54,7 @@ const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t na
return NULL;
}
const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit) {
const pin_af_obj_t *pin_find_af(const machine_pin_obj_t *pin, uint8_t fn, uint8_t unit) {
const pin_af_obj_t *af = pin->af;
for (mp_uint_t i = 0; i < pin->num_af; i++, af++) {
if (af->fn == fn && af->unit == unit) {
@ -64,7 +64,7 @@ const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit)
return NULL;
}
const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx) {
const pin_af_obj_t *pin_find_af_by_index(const machine_pin_obj_t *pin, mp_uint_t af_idx) {
const pin_af_obj_t *af = pin->af;
for (mp_uint_t i = 0; i < pin->num_af; i++, af++) {
if (af->idx == af_idx) {
@ -75,7 +75,7 @@ const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx)
}
/* unused
const pin_af_obj_t *pin_find_af_by_name(const pin_obj_t *pin, const char *name) {
const pin_af_obj_t *pin_find_af_by_name(const machine_pin_obj_t *pin, const char *name) {
const pin_af_obj_t *af = pin->af;
for (mp_uint_t i = 0; i < pin->num_af; i++, af++) {
if (strcmp(name, qstr_str(af->name)) == 0) {

Wyświetl plik

@ -290,8 +290,8 @@ void i2c_init0(void) {
int pyb_i2c_init(I2C_HandleTypeDef *i2c) {
int i2c_unit;
const pin_obj_t *scl_pin;
const pin_obj_t *sda_pin;
const machine_pin_obj_t *scl_pin;
const machine_pin_obj_t *sda_pin;
if (0) {
#if defined(MICROPY_HW_I2C1_SCL)

Wyświetl plik

@ -48,7 +48,7 @@
typedef struct _pyb_servo_obj_t {
mp_obj_base_t base;
const pin_obj_t *pin;
const machine_pin_obj_t *pin;
uint8_t pulse_min; // units of 10us
uint8_t pulse_max; // units of 10us
uint8_t pulse_centre; // units of 10us

Wyświetl plik

@ -341,7 +341,7 @@ void spi_set_params(const spi_t *spi_obj, uint32_t prescale, int32_t baudrate,
int spi_init(const spi_t *self, bool enable_nss_pin) {
SPI_HandleTypeDef *spi = self->spi;
uint32_t irqn = 0;
const pin_obj_t *pins[4] = { NULL, NULL, NULL, NULL };
const machine_pin_obj_t *pins[4] = { NULL, NULL, NULL, NULL };
if (0) {
#if defined(MICROPY_HW_SPI1_SCK)

Wyświetl plik

@ -1199,7 +1199,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
if (!mp_obj_is_type(pin_obj, &pin_type)) {
mp_raise_ValueError(MP_ERROR_TEXT("pin argument needs to be be a Pin type"));
}
const pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
const machine_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
const pin_af_obj_t *af = pin_find_af(pin, AF_FN_TIM, self->tim_id);
if (af == NULL) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Pin(%q) doesn't have an alt for Timer(%d)"), pin->name, self->tim_id);

Wyświetl plik

@ -250,7 +250,7 @@ bool uart_init(machine_uart_obj_t *uart_obj,
uint8_t uart_fn = AF_FN_UART;
int uart_unit;
const pin_obj_t *pins[4] = {0};
const machine_pin_obj_t *pins[4] = {0};
switch (uart_obj->uart_id) {
#if defined(MICROPY_HW_UART1_TX) && defined(MICROPY_HW_UART1_RX)