| 55 | // ============================================================================ |
| 56 | |
| 57 | inline void pinMode(int pin, PinMode mode) FL_NOEXCEPT { |
| 58 | #if defined(HAL_GPIO_MODULE_ENABLED) && defined(FL_STM32_HAS_HAL) |
| 59 | // Use native helper functions instead of Arduino-specific digitalPinToPinName() |
| 60 | GPIO_TypeDef* port = fl::stm32::getGPIOPort(pin); |
| 61 | u32 pin_mask = fl::stm32::getGPIOPin(pin); |
| 62 | |
| 63 | if (port == nullptr || pin_mask == 0) { |
| 64 | FL_WARN("STM32: Invalid pin " << pin); |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | // Enable GPIO clock (based on port) |
| 69 | #ifdef GPIOA |
| 70 | if (port == GPIOA) __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 71 | #endif |
| 72 | #ifdef GPIOB |
| 73 | if (port == GPIOB) __HAL_RCC_GPIOB_CLK_ENABLE(); |
| 74 | #endif |
| 75 | #ifdef GPIOC |
| 76 | if (port == GPIOC) __HAL_RCC_GPIOC_CLK_ENABLE(); |
| 77 | #endif |
| 78 | #ifdef GPIOD |
| 79 | if (port == GPIOD) __HAL_RCC_GPIOD_CLK_ENABLE(); |
| 80 | #endif |
| 81 | #ifdef GPIOE |
| 82 | if (port == GPIOE) __HAL_RCC_GPIOE_CLK_ENABLE(); |
| 83 | #endif |
| 84 | #ifdef GPIOF |
| 85 | if (port == GPIOF) __HAL_RCC_GPIOF_CLK_ENABLE(); |
| 86 | #endif |
| 87 | #ifdef GPIOG |
| 88 | if (port == GPIOG) __HAL_RCC_GPIOG_CLK_ENABLE(); |
| 89 | #endif |
| 90 | #ifdef GPIOH |
| 91 | if (port == GPIOH) __HAL_RCC_GPIOH_CLK_ENABLE(); |
| 92 | #endif |
| 93 | #ifdef GPIOI |
| 94 | if (port == GPIOI) __HAL_RCC_GPIOI_CLK_ENABLE(); |
| 95 | #endif |
| 96 | #ifdef GPIOJ |
| 97 | if (port == GPIOJ) __HAL_RCC_GPIOJ_CLK_ENABLE(); |
| 98 | #endif |
| 99 | #ifdef GPIOK |
| 100 | if (port == GPIOK) __HAL_RCC_GPIOK_CLK_ENABLE(); |
| 101 | #endif |
| 102 | |
| 103 | // Configure GPIO based on mode |
| 104 | GPIO_InitTypeDef GPIO_InitStruct = {}; |
| 105 | GPIO_InitStruct.Pin = pin_mask; |
| 106 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
| 107 | |
| 108 | // Map fl::PinMode to STM32 HAL modes |
| 109 | // PinMode::Input=0, Output=1, InputPullup=2, InputPulldown=3 |
| 110 | switch (mode) { |
| 111 | case PinMode::Input: |
| 112 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
| 113 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 114 | break; |