static int hal_gpio_init_stm32_int(int pin, GPIO_InitTypeDef *cfg, GPIO_PinState *state) { int port; uint32_t mcu_gpio_pin; /* Is this a valid pin? */ port = HAL_GPIO_PORT(pin); if (port >= HAL_GPIO_PORT_COUNT) { return -1; } mcu_gpio_pin = HAL_GPIO_PIN(pin); cfg->Pin = mcu_gpio_pin; /* Enable the GPIO clock */ hal_gpio_clk_enable(port); /* Write initial state if required */ if (NULL != state) { HAL_GPIO_WritePin(portmap[port], mcu_gpio_pin, *state); } /* Initialize pin setting proper mode */ HAL_GPIO_Init(portmap[port], cfg); return 0; }
/** * hal gpio init * * Called to initialize a gpio. * * @param pin * @param cfg * * @return int */ static int hal_gpio_init(int pin, GPIO_InitTypeDef *cfg) { int port; uint32_t mcu_pin_mask; /* Is this a valid pin? */ port = GPIO_PORT(pin); if (port >= HAL_GPIO_NUM_PORTS) { return -1; } mcu_pin_mask = GPIO_MASK(pin); cfg->GPIO_Pin = mcu_pin_mask; /* Enable the GPIO clockl */ hal_gpio_clk_enable(port); /* Initialize pin as an input, setting proper mode */ GPIO_Init(portmap[port], cfg); return 0; }