RTLib
|
STM32F1xx-specific HAL implementation for GPIO pins. More...
#include <gpio.h>
Classes | |
struct | Config |
Configuration for GPIO. More... | |
Public Types | |
enum | Configuration : uint8_t { Configuration::kInputAnalog = 0x0, Configuration::kInputFloat, Configuration::kInputPullUpDown, Configuration::kOutputPushPull = 0x0, Configuration::kOutputOpenDrain, Configuration::kOutputAltFnPushPull, Configuration::kOutputAltFnOpenDrain } |
Enumeration for different GPIO configurations. More... | |
enum | Mode : uint8_t { Mode::kInput, Mode::kOutput10MHz, Mode::kOutput2MHz, Mode::kOutput50MHz } |
Enumeration for different GPIO modes. More... | |
enum | JTAGDisables : uint32_t { JTAGDisables::kNoDisable = AFIO_MAPR_SWJ_CFG_FULL_SWJ, JTAGDisables::kNoJNTRST = AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST, JTAGDisables::kDisableJTAG = AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, JTAGDisables::kDisableJTAGSW = AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF } |
Enumeration for different Serial Wire JTAG states. More... | |
enum | PriRemap : uint32_t { PriRemap::kADC2ExtTrigReg = AFIO_MAPR_ADC2_ETRGREG_REMAP, PriRemap::kADC2ExtTrigInj = AFIO_MAPR_ADC2_ETRGINJ_REMAP, PriRemap::kADC1ExtTrigReg = AFIO_MAPR_ADC1_ETRGREG_REMAP, PriRemap::kADC1ExtTrigInj = AFIO_MAPR_ADC1_ETRGINJ_REMAP, PriRemap::kTIM5Ch4 = AFIO_MAPR_TIM5CH4_IREMAP, PriRemap::kPD01 = AFIO_MAPR_PD01_REMAP, PriRemap::kTIM4 = AFIO_MAPR_TIM4_REMAP, PriRemap::kUSART2 = AFIO_MAPR_USART2_REMAP, PriRemap::kUSART1 = AFIO_MAPR_USART1_REMAP, PriRemap::kI2C1 = AFIO_MAPR_I2C1_REMAP, PriRemap::kSPI1 = AFIO_MAPR_SPI1_REMAP, PriRemap::kCAN1PA = AFIO_MAPR_CAN1_REMAP_PORTA, PriRemap::kCAN1PB = AFIO_MAPR_CAN1_REMAP_PORTB, PriRemap::kCAN1PD = AFIO_MAPR_CAN1_REMAP_PORTD, PriRemap::kTIM3NoRemap = AFIO_MAPR_TIM3_REMAP_NO_REMAP, PriRemap::kTIM3PartRemap = AFIO_MAPR_TIM3_REMAP_PARTIAL_REMAP, PriRemap::kTIM3FullRemap = AFIO_MAPR_TIM3_REMAP_FULL_REMAP, PriRemap::kTIM2NoRemap = AFIO_MAPR_TIM2_REMAP_NO_REMAP, PriRemap::kTIM2PartRemap1 = AFIO_MAPR_TIM2_REMAP_PARTIAL_REMAP1, PriRemap::kTIM2PartRemap2 = AFIO_MAPR_TIM2_REMAP_PARTIAL_REMAP2, PriRemap::kTIM2FullRemap = AFIO_MAPR_TIM2_REMAP_FULL_REMAP, PriRemap::kTIM1NoRemap = AFIO_MAPR_TIM1_REMAP_NO_REMAP, PriRemap::kTIM1PartRemap = AFIO_MAPR_TIM1_REMAP_PARTIAL_REMAP, PriRemap::kTIM1FullRemap = AFIO_MAPR_TIM1_REMAP_FULL_REMAP, PriRemap::kUSART3NoRemap = AFIO_MAPR_USART3_REMAP_NO_REMAP, PriRemap::kUSART3PartRemap = AFIO_MAPR_USART3_REMAP_PARTIAL_REMAP, PriRemap::kUSART3FullRemap = AFIO_MAPR_USART3_REMAP_FULL_REMAP, PriRemap::kPTPPPS = AFIO_MAPR_PTP_PPS_REMAP, PriRemap::kTIM2IntTrig1 = AFIO_MAPR_TIM2ITR1_IREMAP, PriRemap::kSPI3 = AFIO_MAPR_SPI3_REMAP, PriRemap::kMIIOrRMIISelect = AFIO_MAPR_MII_RMII_SEL, PriRemap::kCAN2 = AFIO_MAPR_CAN2_REMAP, PriRemap::kEthMAC = AFIO_MAPR_ETH_REMAP } |
Enumeration for the primary set of different alternate function remaps. More... | |
enum | SecRemap : uint32_t { SecRemap::kMisc = AFIO_MAPR2_MISC_REMAP, SecRemap::kTIM12 = AFIO_MAPR2_TIM12_REMAP, SecRemap::kTIM76DMA = AFIO_MAPR2_TIM76_DAC_DMA_REMAPE, SecRemap::kDisconnectNADV = AFIO_MAPR2_FSMC_NADV_DISCONNECT, SecRemap::kTIM14 = AFIO_MAPR2_TIM14_REMAP, SecRemap::kTIM13 = AFIO_MAPR2_TIM13_REMAP, SecRemap::kTIM11 = AFIO_MAPR2_TIM11_REMAP, SecRemap::kTIM10 = AFIO_MAPR2_TIM10_REMAP, SecRemap::kTIM9 = AFIO_MAPR2_TIM9_REMAP, SecRemap::kTIM1DMA = AFIO_MAPR2_TIM1_DMA_REMAP, SecRemap::kCEC = AFIO_MAPR2_CEC_REMAP, SecRemap::kTIM17 = AFIO_MAPR2_TIM17_REMAP, SecRemap::kTIM16 = AFIO_MAPR2_TIM16_REMAP, SecRemap::kTIM15 = AFIO_MAPR1_TIM16_REMAP } |
Enumeration for the secondary set of different alternate function remaps. More... | |
using | AltFnMaps = uint32_t |
Type definition for alternate function selection. More... | |
Public Member Functions | |
GPIO (const Config &config) | |
Conversion constructor. More... | |
GPIO (Pinout pin, Configuration cnf, Mode mode) | |
Constructor for internal API use. More... | |
~GPIO ()=default | |
GPIO (GPIO &&other) noexcept=default | |
Move constructor. More... | |
GPIO & | operator= (GPIO &&other) noexcept=default |
Move assignment operator. More... | |
GPIO (const GPIO &)=delete | |
Copy constructor. More... | |
GPIO & | operator= (const GPIO &)=delete |
Copy assignment operator. More... | |
bool | Read () const |
Reads the current logic state of the managed GPIO. More... | |
void | Set (bool state) const |
Sets new GPIO state. More... | |
void | Toggle () const |
Toggles GPIO state. Logic High -> Logic Low and vice versa. More... | |
void | Reset () const |
Resets the GPIO to its original configuration, i.e. when the RESET button is first pushed. More... | |
Static Public Member Functions | |
static void | SetPriAltFn (JTAGDisables swj_state, AltFnMaps maps) |
Configures the primary remap functionality of all GPIOs. More... | |
static void | SetSecAltFn (AltFnMaps maps) |
Configures the secondary remap functionality of all GPIOs. More... | |
static void | SetPriAltFn (JTAGDisables swj_state, PriRemap map) |
Configures one primary remap functionality. More... | |
static void | SetSecAltFn (SecRemap map) |
Configures one secondary remap functionality. More... | |
STM32F1xx-specific HAL implementation for GPIO pins.
This abstraction layer provides simple Read/Write operations on GPIO pins. One GPIO object will correspond and manage one GPIO pinout from the MCU.
using core::stm32f1::GPIO::AltFnMaps = uint32_t |
Type definition for alternate function selection.
|
strong |
Enumeration for different GPIO configurations.
This enum is intended to replace equivalent macros used in libopencm3.
See http://libopencm3.org/docs/latest/stm32f1/html/group__gpio__cnf.html.
Enumerator | |
---|---|
kInputAnalog |
Use this GPIO as analog input. Equivalent to libopencm3 macro |
kInputFloat |
Use this GPIO as floating input. Equivalent to libopencm3 macro |
kInputPullUpDown |
Use this GPIO as pull-up/pull-down input. Equivalent to libopencm3 macro |
kOutputPushPull |
Use this GPIO as digital push-pull output. Equivalent to libopencm3 macro |
kOutputOpenDrain |
Use this GPIO as digital open-drain output. Equivalent to libopencm3 macro |
kOutputAltFnPushPull |
Use this GPIO as alternate function push-pull output. Equivalent to libopencm3 macro |
kOutputAltFnOpenDrain |
Use this GPIO as alternate function open-drain output. Equivalent to libopencm3 macro |
|
strong |
Enumeration for different Serial Wire JTAG states.
This enum is intended to replace equivalent macros used in libopencm3.
See http://libopencm3.org/docs/latest/stm32f1/html/group__afio__swj__disable.html.
|
strong |
Enumeration for different GPIO modes.
This enum is intended to replace equivalent macros used in libopencm3.
See http://libopencm3.org/docs/latest/stm32f1/html/group__gpio__mode.html.
|
strong |
Enumeration for the primary set of different alternate function remaps.
This enum is intended to provide a type-safe container for the full list of remaps.
See the libopencm3 documentation for the full list of remaps:
Enumerator | |
---|---|
kADC2ExtTrigReg |
ADC2 External Trigger Regulator Conversion Remapping. By default, this is connected to EXTI11. Enabling this remap will connect ADC2 External Event Regular Conversion to TIM8_TRGO.
Equivalent to libopencm3 macro |
kADC2ExtTrigInj |
ADC2 External Trigger Injected Conversion Remapping. By default, this is connected to EXTI15. Enabling this remap will connect ADC2 External Event Injected Conversion to TIM8_Channel4.
Equivalent to libopencm3 macro |
kADC1ExtTrigReg |
ADC1 External Trigger Regulator Conversion Remapping. By default, this is connected to EXTI11. Enabling this remap will connect ADC1 External Event Regular Conversion to TIM8_TRGO.
Equivalent to libopencm3 macro |
kADC1ExtTrigInj |
ADC1 External Trigger Injected Conversion Remapping. By default, this is connected to EXTI15. Enabling this remap will connect ADC2 External Event Injected Conversion to TIM8_Channel4.
Equivalent to libopencm3 macro |
kTIM5Ch4 |
TIM5 Channel 4 Internal Remapping. By default, TIM5_CH4 is connected to PA3. Enabling this remap will connect the LSI internal clock to TIM5_CH4 for calibration.
Equivalent to libopencm3 macro |
kPD01 |
Port D0/D1 Remapping. By default, PD0 and PD1 are allocated for GPIO. Enabling this remap will connect PD0 and PD1 to OSC_IN and OSC_OUT respectively.
Equivalent to libopecm3 macro |
kTIM4 |
TIM4 CH1/CH2/CH3/CH4 Remapping. By default, TIM4 channels are connected to PB6-PB9. Enabling this remap will connect the channels to PD12-PD15.
Equivalent to libopencm3 macro |
kUSART2 |
USART2 CTS/RTS/TX/RX/CK Remapping. By default, USART2 pins are connected to PA0-PA4. Enabling this remap will connect the pins to PD3-PD7. Equivalent to libopencm3 macro |
kUSART1 |
USART1 TX/RX Remapping. By default, USART1 pins are connected to PA9-PA10. Enabling this remap will connect the pins to PB6-PB7. Equivalent to libopencm3 macro |
kI2C1 |
I2C1 SCL/SDA Remapping. By default, I2C1 pins are connected to PB6-PB7. Enabling this remap will connect the pins to PB8-PB9. Equivalent to libopencm3 macro |
kSPI1 |
SPI1 NSS/SCK/MISO/MOSI Remapping. By default, SPI1 pins are connected to PA4-PA7. Enabling this remap will connect the pins to PA15/PB3-5. Equivalent to libopencm3 macro |
kCAN1PA |
CAN1 RX/TX Port A Remapping. Enabling this remap will connect CAN1 pins to PA11-PA12.
Equivalent to libopencm3 macro |
kCAN1PB |
CAN1 RX/TX Port B Remapping. Enabling this remap will connect CAN1 pins to PB8-PB9.
Equivalent to libopencm3 macro |
kCAN1PD |
CAN1 RX/TX Port D Remapping. Enabling this remap will connect CAN1 pins to PD0-PD1.
Equivalent to libopencm3 macro |
kTIM3NoRemap |
TIM3 No Remapping. (Default) Enabling this will disable remaps and connect the channels to PA6-PA7/PB0-PB1. Equivalent to libopencm3 macro |
kTIM3PartRemap |
TIM3 CH1-CH2 Partial Remapping. Enabling this will connect TIM3 CH1-CH2 to PB4-PB5.
Equivalent to libopencm3 macro |
kTIM3FullRemap |
TIM3 CH1-CH4 Full Remapping. Enabling this will connect TIM3 channels to PC6-PC9.
Equivalent to libopencm3 macro |
kTIM2NoRemap |
TIM2 No Remapping. (Default) Enabling this will disable remaps and connect the channels to PA0-PA3. Equivalent to libopencm3 macro |
kTIM2PartRemap1 |
TIM2 ETR/CH1-CH2 Partial Remapping (1). Enabling this will connect TIM2 CH1-CH2 to PA15/PB3. Equivalent to libopencm3 macro |
kTIM2PartRemap2 |
TIM2 ETR/CH1-CH4 Partial Remapping (2). Enabling this will connect TIM2 CH3-CH4 to PB10-PB11. Equivalent to libopencm3 macro |
kTIM2FullRemap |
TIM2 ETR/CH1-CH4 Full Remapping. Enabling this will connect TIM2 channels to PA15/PB3/PB10-11. Equivalent to libopencm3 macro |
kTIM1NoRemap |
TIM1 No Remapping. (Default) Enabling this will disable remaps and connect the channels to PA12/PA8-PA11/PB12-PB15. Equivalent to libopencm3 macro |
kTIM1PartRemap |
TIM1 BKIN/CH1N-CH3N Partial Remapping. Enabling this will connect TIM1 BKIN/CH1N-CH3N to PA6-PA7/PB0-PB1. Equivalent to libopencm3 macro |
kTIM1FullRemap |
TIM1 ETR/CH1-CH4/BKIN/CH1N-CH3N Full Remapping. Enabling this will connect TIM1 channels to PE7/PE9/PE11/PE13-15/PE8/PE10/PE12. Equivalent to libopencm3 macro |
kUSART3NoRemap |
USART3 No Remapping. (Default) Enabling this will disable remaps and connect USART3 channels to PB10-PB14. Equivalent to libopencm3 macro |
kUSART3PartRemap |
USART3 TX/RX/CK Partial Remapping. Enabling this will connect USART3 TX/RX/CK to PC10-PC12. Equivalent to libopencm3 macro |
kUSART3FullRemap |
USART3 TX/RX/CK/CTS/RTS Full Remapping. Enabling this will connect USART3 pins to PD8-PD12. Equivalent to libopencm3 macro |
kPTPPPS |
Ethernet PTP PPS Remapping. By default, Ethernet MAC PTP_PPS will not be output. Enabling this remap will connect PTP_PPS to PB5.
Equivalent to libopencm3 macro |
kTIM2IntTrig1 |
TIM2 Internal Trigger 1 Remapping. By default, TIM2_ITR1 is connected internally to the Ethernet PTP output. Enabling this remap will connect USB OTG Start-of-Frame output to TIM2_ITR1.
Equivalent to libopencm3 macro |
kSPI3 |
SPI3 NSS/SCK/MISO/MOSI and I2S3 WS/CK/SD Remapping. By default, SPI3/I2S3 are connected to PA15/PB3-PB5. Enabling this remap will connect the pins to PA4/PC10-PC12.
Equivalent to libopencm3 macro |
kMIIOrRMIISelect |
MII/RMII Selection. By default, the Ethernet MAC is configured for connecting with a MII PHY. Enabling this remap will configure the the MAC for connecting with a RMII PHY.
Equivalent to libopencm3 macro |
kCAN2 |
CAN2 RX/TX Remapping. By default, CAN2 pins are connected to PB12-PB13. Enabling this remap will connect the pins to PB5-PB6.
Equivalent to libopencm3 macro |
kEthMAC |
Ethernet MAC DV/RXD0-RXD3 Remapping. By default, Ethernet MAC pins are connected to PA7/PC4-PC5/PB0-PB1. Enabling this remap will connect the pins to PD8-PD12.
Equivalent to libopencm3 macro |
|
strong |
Enumeration for the secondary set of different alternate function remaps.
This enum is intended to provide a type-safe container for the full list of remaps.
See http://libopencm3.org/docs/latest/stm32f1/html/group__afio__remap2.html.
|
explicit |
Conversion constructor.
config | Configuration for the GPIO. See GPIO::Config. |
core::stm32f1::GPIO::GPIO | ( | Pinout | pin, |
Configuration | cnf, | ||
Mode | mode | ||
) |
Constructor for internal API use.
This constructor is equivalent to
. However, it is suggested to use that constructor instead for code readability.
|
default |
Default trivial destructor.
|
defaultnoexcept |
Move constructor.
other | GPIO object to move from |
|
delete |
Copy constructor.
This constructor is deleted because there should only be one object managing each GPIO pin, similar to std::unique_ptr
.
Copy assignment operator.
This constructor is deleted because there should only be one object managing each GPIO pin, similar to std::unique_ptr
.
bool core::stm32f1::GPIO::Read | ( | ) | const |
Reads the current logic state of the managed GPIO.
true
if high value, otherwise false
void core::stm32f1::GPIO::Reset | ( | ) | const |
Resets the GPIO to its original configuration, i.e. when the RESET button is first pushed.
void core::stm32f1::GPIO::Set | ( | bool | state | ) | const |
|
static |
Configures the primary remap functionality of all GPIOs.
Most pins have alternate functions associated with them. This function allows the primary set of these functions to be enabled, along with the option to disable JTAG controls for GPIOs.
By default, all alternate functions are disabled.
See the gpio_primary_remap()
section of http://libopencm3.org/docs/latest/stm32f1/html/group__gpio__file.html.
swj_state | Whether to disable JTAG capability |
maps | The alternate functions to enable. Use bitwise OR on all libopencm3 constants to enable the remaps with one function call. |
|
inlinestatic |
Configures one primary remap functionality.
As opposed to SetPriAltFn(JTAGDisables,AltFnMaps), this function only enables one alternate function from the primary set.
swj_state | Whether to disable JTAG capability |
map | The alternate function to enable. See GPIO::PriRemap for a comprehensive list of primary alternate functions. |
|
static |
Configures the secondary remap functionality of all GPIOs.
Most pins have alternate functions associated with them. This function allows the primary set of these functions to be enabled, along with the option to disable JTAG controls for GPIOs.
See the libopencm3 documentation for the full list of remaps: http://libopencm3.org/docs/latest/stm32f1/html/group__afio__remap2.html
See the gpio_secondary_remap()
section of http://libopencm3.org/docs/latest/stm32f1/html/group__gpio__file.html.
maps | The alternate functions to enable. Use bitwise OR on all libopencm3 constants to enable the remaps with one function call. |
|
inlinestatic |
Configures one secondary remap functionality.
As opposed to SetSecAltFn(AltFnMaps), this function only enables one alternate function from the secondary set.
map | The alternate function to enable. See GPIO::SecRemap for a comprehensive list of secondary alternate functions. |
void core::stm32f1::GPIO::Toggle | ( | ) | const |
Toggles GPIO state. Logic High -> Logic Low and vice versa.