stm32f103
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gpio.h
Go to the documentation of this file.
1 #ifndef STM32F103_CORE_GPIO_H_
2 #define STM32F103_CORE_GPIO_H_
3 
4 #include <stm32f10x_gpio.h>
5 #include <stm32f10x_rcc.h>
6 
7 #include "util.h"
8 
12 class GPIO {
13  public:
17  struct Config {
22 
28  GPIOMode_TypeDef mode;
34  GPIOSpeed_TypeDef speed = GPIO_Speed_50MHz;
42  uint32_t rcc = 0;
43  };
44 
50  explicit GPIO(const Config& config);
51 
61  void Set(bool state);
65  void Toggle();
66 
71  bool Read();
72 
81  uint16_t GetPinSource();
85  GPIO_TypeDef* GetPort();
94  uint16_t GetPin();
95 
96  protected:
104  void Init(GPIOMode_TypeDef mode, GPIOSpeed_TypeDef speed, uint32_t rcc = 0);
111  void Rcc(FunctionalState state, uint32_t rcc = 0);
112 
113  private:
114  GPIO_TypeDef* port_;
115  GPIO_InitTypeDef GPIO_InitStructure_;
116 };
117 
118 #endif // STM32F103_CORE_GPIO_H_
uint16_t GetPin()
Definition: gpio.cpp:86
bool Read()
Read the current logic state of GPIO.
Definition: gpio.cpp:55
GPIOMode_TypeDef mode
GPIO Mode.
Definition: gpio.h:28
std::pair< GPIO_TypeDef *, uint16_t > Pin
Type definition for a single pin.
Definition: util.h:16
uint16_t GetPinSource()
Definition: gpio.cpp:59
GPIO_TypeDef * GetPort()
Definition: gpio.cpp:82
GPIO(const Config &config)
Constructor for Gpio class.
Definition: gpio.cpp:5
Pin pin
GPIO Pin to enable and initialize.
Definition: gpio.h:21
void Init(GPIOMode_TypeDef mode, GPIOSpeed_TypeDef speed, uint32_t rcc=0)
Performs initialization of this GPIO.
Definition: gpio.cpp:16
GPIOSpeed_TypeDef speed
GPIO output maximum frequency.
Definition: gpio.h:34
void Toggle()
Toggles GPIO state, Logic High -> Logic Low and vice versa.
Definition: gpio.cpp:43
HAL implementation for GPIO pins.
Definition: gpio.h:12
uint32_t rcc
Reset and Clock Control (RCC).
Definition: gpio.h:42
void Rcc(FunctionalState state, uint32_t rcc=0)
Enables/Disables RCC.
Definition: gpio.cpp:25
void Set(bool state)
Sets this GPIO state based on passed in boolean.
Definition: gpio.cpp:47
Configuration for an individual GPIO pin.
Definition: gpio.h:17