stm32: Change pin_X and pyb_pin_X identifiers to be pointers to objects.

Rather than pin objects themselves.  The actual object is now pin_X_obj and
defines are provided so that pin_X is &pin_X_obj.  This makes it so that
code that uses pin objects doesn't need to know if they are literals or
objects (that need pointers taken) or something else.  They are just
entities that can be passed to the map_hal_pin_xxx functions.  This mirrors
how the core handles constant objects (eg mp_const_none which is
&mp_const_none_obj) and allows for the possibility of different
implementations of the pin layer.

For example, prior to this patch there was the following:

    extern const pin_obj_t pin_A0;
    #define pyb_pin_X1 pin_A0
    ...
    mp_hal_pin_high(&pin_A0);

and now there is:

    extern const pin_obj_t pin_A0_obj;
    #define pin_A0 (&pin_A0_obj)
    #define pyb_pin_X1 pin_A0
    ...
    mp_hal_pin_high(pin_A0);

This patch should have minimal effect on board configuration files.  The
only change that may be needed is if a board has .c files that configure
pins.
This commit is contained in:
Damien George 2018-03-28 16:13:21 +11:00
parent cf1d6df05a
commit 2dca693c24
12 changed files with 108 additions and 108 deletions

View File

@ -56,8 +56,8 @@
void accel_init(void) {
// PB5 is connected to AVDD; pull high to enable MMA accel device
mp_hal_pin_low(&MICROPY_HW_MMA_AVDD_PIN); // turn off AVDD
mp_hal_pin_output(&MICROPY_HW_MMA_AVDD_PIN);
mp_hal_pin_low(MICROPY_HW_MMA_AVDD_PIN); // turn off AVDD
mp_hal_pin_output(MICROPY_HW_MMA_AVDD_PIN);
}
STATIC void accel_start(void) {
@ -73,9 +73,9 @@ STATIC void accel_start(void) {
i2c_init(&I2CHandle1);
// turn off AVDD, wait 30ms, turn on AVDD, wait 30ms again
mp_hal_pin_low(&MICROPY_HW_MMA_AVDD_PIN); // turn off
mp_hal_pin_low(MICROPY_HW_MMA_AVDD_PIN); // turn off
mp_hal_delay_ms(30);
mp_hal_pin_high(&MICROPY_HW_MMA_AVDD_PIN); // turn on
mp_hal_pin_high(MICROPY_HW_MMA_AVDD_PIN); // turn on
mp_hal_delay_ms(30);
HAL_StatusTypeDef status;

View File

@ -207,18 +207,18 @@ class Pin(object):
print("// ", end='')
print('};')
print('')
print('const pin_obj_t pin_{:s} = PIN({:s}, {:d}, {:s}, {:s}, {:d});'.format(
print('const pin_obj_t pin_{:s}_obj = PIN({:s}, {:d}, {:s}, {:s}, {:d});'.format(
self.cpu_pin_name(), self.port_letter(), self.pin,
self.alt_fn_name(null_if_0=True),
self.adc_num_str(), self.adc_channel))
print('')
def print_header(self, hdr_file):
hdr_file.write('extern const pin_obj_t pin_{:s};\n'.
format(self.cpu_pin_name()))
n = self.cpu_pin_name()
hdr_file.write('extern const pin_obj_t pin_{:s}_obj;\n'.format(n))
hdr_file.write('#define pin_{:s} (&pin_{:s}_obj)\n'.format(n, n))
if self.alt_fn_count > 0:
hdr_file.write('extern const pin_af_obj_t pin_{:s}_af[];\n'.
format(self.cpu_pin_name()))
hdr_file.write('extern const pin_af_obj_t pin_{:s}_af[];\n'.format(n))
def qstr_list(self):
result = []
@ -287,7 +287,7 @@ class Pins(object):
for named_pin in named_pins:
pin = named_pin.pin()
if pin.is_board_pin():
print(' {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&pin_{:s}) }},'.format(named_pin.name(), pin.cpu_pin_name()))
print(' {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&pin_{:s}_obj) }},'.format(named_pin.name(), pin.cpu_pin_name()))
print('};')
print('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);'.format(label, label));
@ -311,7 +311,7 @@ class Pins(object):
pin = named_pin.pin()
if (pin.is_board_pin() and
(pin.adc_num & (1 << (adc_num - 1))) and (pin.adc_channel == channel)):
print(' &pin_{:s}, // {:d}'.format(pin.cpu_pin_name(), channel))
print(' &pin_{:s}_obj, // {:d}'.format(pin.cpu_pin_name(), channel))
adc_found = True
break
if not adc_found:

View File

@ -212,9 +212,9 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_
dac_id = mp_obj_get_int(args[0]);
} else {
const pin_obj_t *pin = pin_find(args[0]);
if (pin == &pin_A4) {
if (pin == pin_A4) {
dac_id = 1;
} else if (pin == &pin_A5) {
} else if (pin == pin_A5) {
dac_id = 2;
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin(%q) doesn't have DAC capabilities", pin->name));

View File

@ -260,29 +260,29 @@ void i2c_init(I2C_HandleTypeDef *i2c) {
#if defined(MICROPY_HW_I2C1_SCL)
} else if (i2c == &I2CHandle1) {
i2c_unit = 1;
scl_pin = &MICROPY_HW_I2C1_SCL;
sda_pin = &MICROPY_HW_I2C1_SDA;
scl_pin = MICROPY_HW_I2C1_SCL;
sda_pin = MICROPY_HW_I2C1_SDA;
__I2C1_CLK_ENABLE();
#endif
#if defined(MICROPY_HW_I2C2_SCL)
} else if (i2c == &I2CHandle2) {
i2c_unit = 2;
scl_pin = &MICROPY_HW_I2C2_SCL;
sda_pin = &MICROPY_HW_I2C2_SDA;
scl_pin = MICROPY_HW_I2C2_SCL;
sda_pin = MICROPY_HW_I2C2_SDA;
__I2C2_CLK_ENABLE();
#endif
#if defined(MICROPY_HW_I2C3_SCL)
} else if (i2c == &I2CHandle3) {
i2c_unit = 3;
scl_pin = &MICROPY_HW_I2C3_SCL;
sda_pin = &MICROPY_HW_I2C3_SDA;
scl_pin = MICROPY_HW_I2C3_SCL;
sda_pin = MICROPY_HW_I2C3_SDA;
__I2C3_CLK_ENABLE();
#endif
#if defined(MICROPY_HW_I2C4_SCL)
} else if (i2c == &I2CHandle4) {
i2c_unit = 4;
scl_pin = &MICROPY_HW_I2C4_SCL;
sda_pin = &MICROPY_HW_I2C4_SDA;
scl_pin = MICROPY_HW_I2C4_SCL;
sda_pin = MICROPY_HW_I2C4_SDA;
__I2C4_CLK_ENABLE();
#endif
} else {

View File

@ -207,16 +207,16 @@ STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_
// TODO accept an SPI object and pin objects for full customisation
if ((lcd_id[0] | 0x20) == 'x' && lcd_id[1] == '\0') {
lcd->spi = &spi_obj[0];
lcd->pin_cs1 = &pyb_pin_X3;
lcd->pin_rst = &pyb_pin_X4;
lcd->pin_a0 = &pyb_pin_X5;
lcd->pin_bl = &pyb_pin_X12;
lcd->pin_cs1 = pyb_pin_X3;
lcd->pin_rst = pyb_pin_X4;
lcd->pin_a0 = pyb_pin_X5;
lcd->pin_bl = pyb_pin_X12;
} else if ((lcd_id[0] | 0x20) == 'y' && lcd_id[1] == '\0') {
lcd->spi = &spi_obj[1];
lcd->pin_cs1 = &pyb_pin_Y3;
lcd->pin_rst = &pyb_pin_Y4;
lcd->pin_a0 = &pyb_pin_Y5;
lcd->pin_bl = &pyb_pin_Y12;
lcd->pin_cs1 = pyb_pin_Y3;
lcd->pin_rst = pyb_pin_Y4;
lcd->pin_a0 = pyb_pin_Y5;
lcd->pin_bl = pyb_pin_Y12;
} else {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LCD(%s) doesn't exist", lcd_id));
}

View File

@ -51,13 +51,13 @@ typedef struct _pyb_led_obj_t {
} pyb_led_obj_t;
STATIC const pyb_led_obj_t pyb_led_obj[] = {
{{&pyb_led_type}, 1, &MICROPY_HW_LED1},
{{&pyb_led_type}, 1, MICROPY_HW_LED1},
#if defined(MICROPY_HW_LED2)
{{&pyb_led_type}, 2, &MICROPY_HW_LED2},
{{&pyb_led_type}, 2, MICROPY_HW_LED2},
#if defined(MICROPY_HW_LED3)
{{&pyb_led_type}, 3, &MICROPY_HW_LED3},
{{&pyb_led_type}, 3, MICROPY_HW_LED3},
#if defined(MICROPY_HW_LED4)
{{&pyb_led_type}, 4, &MICROPY_HW_LED4},
{{&pyb_led_type}, 4, MICROPY_HW_LED4},
#endif
#endif
#endif

View File

@ -424,22 +424,22 @@ typedef mp_machine_soft_i2c_obj_t machine_hard_i2c_obj_t;
STATIC machine_hard_i2c_obj_t machine_hard_i2c_obj[] = {
#if defined(MICROPY_HW_I2C1_SCL)
{{&machine_hard_i2c_type}, 1, 500, &MICROPY_HW_I2C1_SCL, &MICROPY_HW_I2C1_SDA},
{{&machine_hard_i2c_type}, 1, 500, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA},
#else
{{NULL}, 0, 0, NULL, NULL},
#endif
#if defined(MICROPY_HW_I2C2_SCL)
{{&machine_hard_i2c_type}, 1, 500, &MICROPY_HW_I2C2_SCL, &MICROPY_HW_I2C2_SDA},
{{&machine_hard_i2c_type}, 1, 500, MICROPY_HW_I2C2_SCL, MICROPY_HW_I2C2_SDA},
#else
{{NULL}, 0, 0, NULL, NULL},
#endif
#if defined(MICROPY_HW_I2C3_SCL)
{{&machine_hard_i2c_type}, 1, 500, &MICROPY_HW_I2C3_SCL, &MICROPY_HW_I2C3_SDA},
{{&machine_hard_i2c_type}, 1, 500, MICROPY_HW_I2C3_SCL, MICROPY_HW_I2C3_SDA},
#else
{{NULL}, 0, 0, NULL, NULL},
#endif
#if defined(MICROPY_HW_I2C4_SCL)
{{&machine_hard_i2c_type}, 1, 500, &MICROPY_HW_I2C4_SCL, &MICROPY_HW_I2C4_SDA},
{{&machine_hard_i2c_type}, 1, 500, MICROPY_HW_I2C4_SCL, MICROPY_HW_I2C4_SDA},
#else
{{NULL}, 0, 0, NULL, NULL},
#endif

View File

@ -141,25 +141,25 @@ void sdcard_init(void) {
// which clocks up to 25MHz maximum.
#if defined(MICROPY_HW_SDMMC2_CK)
// Use SDMMC2 peripheral with pins provided by the board's config
mp_hal_pin_config_alt(&MICROPY_HW_SDMMC2_CK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(&MICROPY_HW_SDMMC2_CMD, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(&MICROPY_HW_SDMMC2_D0, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(&MICROPY_HW_SDMMC2_D1, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(&MICROPY_HW_SDMMC2_D2, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(&MICROPY_HW_SDMMC2_D3, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(MICROPY_HW_SDMMC2_CK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(MICROPY_HW_SDMMC2_CMD, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(MICROPY_HW_SDMMC2_D0, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(MICROPY_HW_SDMMC2_D1, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(MICROPY_HW_SDMMC2_D2, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
mp_hal_pin_config_alt(MICROPY_HW_SDMMC2_D3, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, AF_FN_SDMMC, 2);
#else
// Default SDIO/SDMMC1 config
mp_hal_pin_config(&MICROPY_HW_SDMMC_D0, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(&MICROPY_HW_SDMMC_D1, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(&MICROPY_HW_SDMMC_D2, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(&MICROPY_HW_SDMMC_D3, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(&MICROPY_HW_SDMMC_CK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(&MICROPY_HW_SDMMC_CMD, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(MICROPY_HW_SDMMC_D0, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(MICROPY_HW_SDMMC_D1, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(MICROPY_HW_SDMMC_D2, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(MICROPY_HW_SDMMC_D3, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(MICROPY_HW_SDMMC_CK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(MICROPY_HW_SDMMC_CMD, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
#endif
// configure the SD card detect pin
// we do this here so we can detect if the SD card is inserted before powering it on
mp_hal_pin_config(&MICROPY_HW_SDCARD_DETECT_PIN, MP_HAL_PIN_MODE_INPUT, MICROPY_HW_SDCARD_DETECT_PULL, 0);
mp_hal_pin_config(MICROPY_HW_SDCARD_DETECT_PIN, MP_HAL_PIN_MODE_INPUT, MICROPY_HW_SDCARD_DETECT_PULL, 0);
}
void HAL_SD_MspInit(SD_HandleTypeDef *hsd) {
@ -185,7 +185,7 @@ void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd) {
}
bool sdcard_is_present(void) {
return HAL_GPIO_ReadPin(MICROPY_HW_SDCARD_DETECT_PIN.gpio, MICROPY_HW_SDCARD_DETECT_PIN.pin_mask) == MICROPY_HW_SDCARD_DETECT_PRESENT;
return HAL_GPIO_ReadPin(MICROPY_HW_SDCARD_DETECT_PIN->gpio, MICROPY_HW_SDCARD_DETECT_PIN->pin_mask) == MICROPY_HW_SDCARD_DETECT_PRESENT;
}
bool sdcard_power_on(void) {

View File

@ -80,15 +80,15 @@ void servo_init(void) {
// assign servo objects to specific pins (must be some permutation of PA0-PA3)
#ifdef pyb_pin_X1
pyb_servo_obj[0].pin = &pyb_pin_X1;
pyb_servo_obj[1].pin = &pyb_pin_X2;
pyb_servo_obj[2].pin = &pyb_pin_X3;
pyb_servo_obj[3].pin = &pyb_pin_X4;
pyb_servo_obj[0].pin = pyb_pin_X1;
pyb_servo_obj[1].pin = pyb_pin_X2;
pyb_servo_obj[2].pin = pyb_pin_X3;
pyb_servo_obj[3].pin = pyb_pin_X4;
#else
pyb_servo_obj[0].pin = &pin_A0;
pyb_servo_obj[1].pin = &pin_A1;
pyb_servo_obj[2].pin = &pin_A2;
pyb_servo_obj[3].pin = &pin_A3;
pyb_servo_obj[0].pin = pin_A0;
pyb_servo_obj[1].pin = pin_A1;
pyb_servo_obj[2].pin = pin_A2;
pyb_servo_obj[3].pin = pin_A3;
#endif
}

View File

@ -248,78 +248,78 @@ void spi_init(const spi_t *self, bool enable_nss_pin) {
#if defined(MICROPY_HW_SPI1_SCK)
} else if (spi->Instance == SPI1) {
#if defined(MICROPY_HW_SPI1_NSS)
pins[0] = &MICROPY_HW_SPI1_NSS;
pins[0] = MICROPY_HW_SPI1_NSS;
#endif
pins[1] = &MICROPY_HW_SPI1_SCK;
pins[1] = MICROPY_HW_SPI1_SCK;
#if defined(MICROPY_HW_SPI1_MISO)
pins[2] = &MICROPY_HW_SPI1_MISO;
pins[2] = MICROPY_HW_SPI1_MISO;
#endif
pins[3] = &MICROPY_HW_SPI1_MOSI;
pins[3] = MICROPY_HW_SPI1_MOSI;
// enable the SPI clock
__HAL_RCC_SPI1_CLK_ENABLE();
#endif
#if defined(MICROPY_HW_SPI2_SCK)
} else if (spi->Instance == SPI2) {
#if defined(MICROPY_HW_SPI2_NSS)
pins[0] = &MICROPY_HW_SPI2_NSS;
pins[0] = MICROPY_HW_SPI2_NSS;
#endif
pins[1] = &MICROPY_HW_SPI2_SCK;
pins[1] = MICROPY_HW_SPI2_SCK;
#if defined(MICROPY_HW_SPI2_MISO)
pins[2] = &MICROPY_HW_SPI2_MISO;
pins[2] = MICROPY_HW_SPI2_MISO;
#endif
pins[3] = &MICROPY_HW_SPI2_MOSI;
pins[3] = MICROPY_HW_SPI2_MOSI;
// enable the SPI clock
__HAL_RCC_SPI2_CLK_ENABLE();
#endif
#if defined(MICROPY_HW_SPI3_SCK)
} else if (spi->Instance == SPI3) {
#if defined(MICROPY_HW_SPI3_NSS)
pins[0] = &MICROPY_HW_SPI3_NSS;
pins[0] = MICROPY_HW_SPI3_NSS;
#endif
pins[1] = &MICROPY_HW_SPI3_SCK;
pins[1] = MICROPY_HW_SPI3_SCK;
#if defined(MICROPY_HW_SPI3_MISO)
pins[2] = &MICROPY_HW_SPI3_MISO;
pins[2] = MICROPY_HW_SPI3_MISO;
#endif
pins[3] = &MICROPY_HW_SPI3_MOSI;
pins[3] = MICROPY_HW_SPI3_MOSI;
// enable the SPI clock
__HAL_RCC_SPI3_CLK_ENABLE();
#endif
#if defined(MICROPY_HW_SPI4_SCK)
} else if (spi->Instance == SPI4) {
#if defined(MICROPY_HW_SPI4_NSS)
pins[0] = &MICROPY_HW_SPI4_NSS;
pins[0] = MICROPY_HW_SPI4_NSS;
#endif
pins[1] = &MICROPY_HW_SPI4_SCK;
pins[1] = MICROPY_HW_SPI4_SCK;
#if defined(MICROPY_HW_SPI4_MISO)
pins[2] = &MICROPY_HW_SPI4_MISO;
pins[2] = MICROPY_HW_SPI4_MISO;
#endif
pins[3] = &MICROPY_HW_SPI4_MOSI;
pins[3] = MICROPY_HW_SPI4_MOSI;
// enable the SPI clock
__HAL_RCC_SPI4_CLK_ENABLE();
#endif
#if defined(MICROPY_HW_SPI5_SCK)
} else if (spi->Instance == SPI5) {
#if defined(MICROPY_HW_SPI5_NSS)
pins[0] = &MICROPY_HW_SPI5_NSS;
pins[0] = MICROPY_HW_SPI5_NSS;
#endif
pins[1] = &MICROPY_HW_SPI5_SCK;
pins[1] = MICROPY_HW_SPI5_SCK;
#if defined(MICROPY_HW_SPI5_MISO)
pins[2] = &MICROPY_HW_SPI5_MISO;
pins[2] = MICROPY_HW_SPI5_MISO;
#endif
pins[3] = &MICROPY_HW_SPI5_MOSI;
pins[3] = MICROPY_HW_SPI5_MOSI;
// enable the SPI clock
__HAL_RCC_SPI5_CLK_ENABLE();
#endif
#if defined(MICROPY_HW_SPI6_SCK)
} else if (spi->Instance == SPI6) {
#if defined(MICROPY_HW_SPI6_NSS)
pins[0] = &MICROPY_HW_SPI6_NSS;
pins[0] = MICROPY_HW_SPI6_NSS;
#endif
pins[1] = &MICROPY_HW_SPI6_SCK;
pins[1] = MICROPY_HW_SPI6_SCK;
#if defined(MICROPY_HW_SPI6_MISO)
pins[2] = &MICROPY_HW_SPI6_MISO;
pins[2] = MICROPY_HW_SPI6_MISO;
#endif
pins[3] = &MICROPY_HW_SPI6_MOSI;
pins[3] = MICROPY_HW_SPI6_MOSI;
// enable the SPI clock
__HAL_RCC_SPI6_CLK_ENABLE();
#endif

View File

@ -181,8 +181,8 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
uart_unit = 1;
UARTx = USART1;
irqn = USART1_IRQn;
pins[0] = &MICROPY_HW_UART1_TX;
pins[1] = &MICROPY_HW_UART1_RX;
pins[0] = MICROPY_HW_UART1_TX;
pins[1] = MICROPY_HW_UART1_RX;
__HAL_RCC_USART1_CLK_ENABLE();
break;
#endif
@ -192,16 +192,16 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
uart_unit = 2;
UARTx = USART2;
irqn = USART2_IRQn;
pins[0] = &MICROPY_HW_UART2_TX;
pins[1] = &MICROPY_HW_UART2_RX;
pins[0] = MICROPY_HW_UART2_TX;
pins[1] = MICROPY_HW_UART2_RX;
#if defined(MICROPY_HW_UART2_RTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
pins[2] = &MICROPY_HW_UART2_RTS;
pins[2] = MICROPY_HW_UART2_RTS;
}
#endif
#if defined(MICROPY_HW_UART2_CTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
pins[3] = &MICROPY_HW_UART2_CTS;
pins[3] = MICROPY_HW_UART2_CTS;
}
#endif
__HAL_RCC_USART2_CLK_ENABLE();
@ -213,16 +213,16 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
uart_unit = 3;
UARTx = USART3;
irqn = USART3_IRQn;
pins[0] = &MICROPY_HW_UART3_TX;
pins[1] = &MICROPY_HW_UART3_RX;
pins[0] = MICROPY_HW_UART3_TX;
pins[1] = MICROPY_HW_UART3_RX;
#if defined(MICROPY_HW_UART3_RTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
pins[2] = &MICROPY_HW_UART3_RTS;
pins[2] = MICROPY_HW_UART3_RTS;
}
#endif
#if defined(MICROPY_HW_UART3_CTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
pins[3] = &MICROPY_HW_UART3_CTS;
pins[3] = MICROPY_HW_UART3_CTS;
}
#endif
__HAL_RCC_USART3_CLK_ENABLE();
@ -234,8 +234,8 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
uart_unit = 4;
UARTx = UART4;
irqn = UART4_IRQn;
pins[0] = &MICROPY_HW_UART4_TX;
pins[1] = &MICROPY_HW_UART4_RX;
pins[0] = MICROPY_HW_UART4_TX;
pins[1] = MICROPY_HW_UART4_RX;
__HAL_RCC_UART4_CLK_ENABLE();
break;
#endif
@ -245,8 +245,8 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
uart_unit = 5;
UARTx = UART5;
irqn = UART5_IRQn;
pins[0] = &MICROPY_HW_UART5_TX;
pins[1] = &MICROPY_HW_UART5_RX;
pins[0] = MICROPY_HW_UART5_TX;
pins[1] = MICROPY_HW_UART5_RX;
__HAL_RCC_UART5_CLK_ENABLE();
break;
#endif
@ -256,16 +256,16 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
uart_unit = 6;
UARTx = USART6;
irqn = USART6_IRQn;
pins[0] = &MICROPY_HW_UART6_TX;
pins[1] = &MICROPY_HW_UART6_RX;
pins[0] = MICROPY_HW_UART6_TX;
pins[1] = MICROPY_HW_UART6_RX;
#if defined(MICROPY_HW_UART6_RTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
pins[2] = &MICROPY_HW_UART6_RTS;
pins[2] = MICROPY_HW_UART6_RTS;
}
#endif
#if defined(MICROPY_HW_UART6_CTS)
if (uart_obj->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
pins[3] = &MICROPY_HW_UART6_CTS;
pins[3] = MICROPY_HW_UART6_CTS;
}
#endif
__HAL_RCC_USART6_CLK_ENABLE();
@ -277,8 +277,8 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
uart_unit = 7;
UARTx = UART7;
irqn = UART7_IRQn;
pins[0] = &MICROPY_HW_UART7_TX;
pins[1] = &MICROPY_HW_UART7_RX;
pins[0] = MICROPY_HW_UART7_TX;
pins[1] = MICROPY_HW_UART7_RX;
__HAL_RCC_UART7_CLK_ENABLE();
break;
#endif
@ -288,8 +288,8 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
uart_unit = 8;
UARTx = UART8;
irqn = UART8_IRQn;
pins[0] = &MICROPY_HW_UART8_TX;
pins[1] = &MICROPY_HW_UART8_RX;
pins[0] = MICROPY_HW_UART8_TX;
pins[1] = MICROPY_HW_UART8_RX;
__HAL_RCC_UART8_CLK_ENABLE();
break;
#endif

View File

@ -53,11 +53,11 @@
// this function inits the switch GPIO so that it can be used
void switch_init0(void) {
mp_hal_pin_config(&MICROPY_HW_USRSW_PIN, MP_HAL_PIN_MODE_INPUT, MICROPY_HW_USRSW_PULL, 0);
mp_hal_pin_config(MICROPY_HW_USRSW_PIN, MP_HAL_PIN_MODE_INPUT, MICROPY_HW_USRSW_PULL, 0);
}
int switch_get(void) {
int val = ((MICROPY_HW_USRSW_PIN.gpio->IDR & MICROPY_HW_USRSW_PIN.pin_mask) != 0);
int val = ((MICROPY_HW_USRSW_PIN->gpio->IDR & MICROPY_HW_USRSW_PIN->pin_mask) != 0);
return val == MICROPY_HW_USRSW_PRESSED;
}
@ -118,7 +118,7 @@ mp_obj_t pyb_switch_callback(mp_obj_t self_in, mp_obj_t callback) {
// Init the EXTI each time this function is called, since the EXTI
// may have been disabled by an exception in the interrupt, or the
// user disabling the line explicitly.
extint_register((mp_obj_t)&MICROPY_HW_USRSW_PIN,
extint_register((mp_obj_t)MICROPY_HW_USRSW_PIN,
MICROPY_HW_USRSW_EXTI_MODE,
MICROPY_HW_USRSW_PULL,
callback == mp_const_none ? mp_const_none : (mp_obj_t)&switch_callback_obj,