stm32f103
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
buzzer.h
Go to the documentation of this file.
1 #ifndef STM32F103_LIB_BUZZER_H_
2 #define STM32F103_LIB_BUZZER_H_
3 
4 #include <cstdint>
5 #include <memory>
6 #include <stm32f10x.h>
7 
8 #include "config.h"
9 #include "gpio.h"
10 #include "util.h"
11 
12 #if !defined(LIB_USE_BUZZER) || LIB_USE_BUZZER < 1
13 #error "This configuration is not specified to use this library"
14 #endif // !defined(LIB_USE_BUZZER) || LIB_USE_BUZZER < 1
15 
19 class Buzzer {
20  public:
24  struct Config {
28  uint8_t id;
29  };
30 
39  explicit Buzzer(const Config& config);
40 
46  void SetEnable(const bool flag);
47 
48  protected:
52  Pin* GetPin() { return &pin_; }
53 
57  GPIO* GetGpio() { return gpio_.get(); }
58 
59  private:
60  Pin pin_;
61  std::unique_ptr<GPIO> gpio_;
62 };
63 
64 #endif // STM32F103_LIB_BUZZER_H_
std::pair< GPIO_TypeDef *, uint16_t > Pin
Type definition for a single pin.
Definition: util.h:16
Implements abstraction layer for buzzers.
Definition: buzzer.h:19
Configuration for buzzers.
Definition: buzzer.h:24
Buzzer(const Config &config)
Constructor for buzzer.
void SetEnable(const bool flag)
Sets the state of the buzzer.
uint8_t id
ID of buzzer.
Definition: buzzer.h:28
Pin * GetPin()
Definition: buzzer.h:52
HAL implementation for GPIO pins.
Definition: gpio.h:12
GPIO * GetGpio()
Definition: buzzer.h:57