stm32f103
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
button.h
Go to the documentation of this file.
1 #ifndef STM32F103_LIB_BUTTON_H_
2 #define STM32F103_LIB_BUTTON_H_
3 
4 #include <cstdint>
5 #include <memory>
6 #include <utility>
7 #include <stm32f10x.h>
8 
9 #include "config.h"
10 #include "gpio.h"
11 #include "util.h"
12 
13 #if !defined(LIB_USE_BUTTON) || LIB_USE_BUTTON < 1
14 #error "This configuration is not specified to use this library"
15 #endif // !defined(LIB_USE_BUTTON) || LIB_USE_BUTTON < 1
16 
20 class Button {
21  public:
25  struct Config {
29  uint8_t id;
30  };
31 
37  explicit Button(const Config& config);
41  bool Read();
42 
43  protected:
47  Pin* GetPin() { return &pin_; }
48 
52  GPIO* GetGpio() { return gpio_.get(); }
53 
54  private:
55  Pin pin_;
56  std::unique_ptr<GPIO> gpio_ = nullptr;
57 };
58 
59 #endif
std::pair< GPIO_TypeDef *, uint16_t > Pin
Type definition for a single pin.
Definition: util.h:16
Implements button-related features.
Definition: button.h:20
bool Read()
uint8_t id
ID of button.
Definition: button.h:29
GPIO * GetGpio()
Definition: button.h:52
Button(const Config &config)
Constructor for button.
Pin * GetPin()
Definition: button.h:47
HAL implementation for GPIO pins.
Definition: gpio.h:12
Configuration for button.
Definition: button.h:25