-
-
Save shima-529/885cc90e602f932fe661896efd62e6bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stm32f3xx.h> | |
#ifndef PERIPHERAL_BASE_HPP_ | |
#define PERIPHERAL_BASE_HPP_ | |
class GpioConfig { | |
public: | |
GpioConfig() : mode(PinMode::INPUT), outputtype(PinOutputType::PP), speed(PinSpeed::LOW), | |
pull(PinPull::FLOATING), alternateFunc(0) {}; | |
enum struct PinMode { | |
INPUT = 0x00, GPIO_OUTPUT = 0x01, ALTERNATE = 0x02, ANALOG = 0x03 | |
} mode; | |
enum struct PinOutputType { | |
PP = 0, OD = 1 | |
} outputtype; | |
enum struct PinSpeed { | |
LOW = 0x00, MEDIUM = 0x01, HIGH = 0x03 | |
} speed; | |
enum struct PinPull { | |
FLOATING = 0x00, PULLUP = 0x01, PULLDOWN = 0x02 | |
} pull; | |
uint8_t alternateFunc; | |
}; | |
class Gpio { | |
using PinName = uint8_t; | |
public: | |
Gpio(); | |
Gpio(GPIO_TypeDef *gpio, PinName pin, GpioConfig pd); | |
Gpio(GPIO_TypeDef *gpio, PinName pin, GpioConfig::PinMode mode = GpioConfig::PinMode::GPIO_OUTPUT); | |
void configure(GPIO_TypeDef *gpio, PinName pin, GpioConfig pd); | |
void configure(GPIO_TypeDef *gpio, PinName pin, GpioConfig::PinMode mode = GpioConfig::PinMode::GPIO_OUTPUT); | |
void setMode(GpioConfig::PinMode mode); | |
// operator overloads | |
uint8_t operator=(bool); | |
uint8_t operator^(bool); | |
uint8_t operator^=(bool); | |
bool getValue(); | |
private: | |
static void allGpioInit(); | |
GPIO_TypeDef *Instance; | |
PinName pin; | |
GpioConfig config; | |
static uint8_t instancesNum; | |
}; | |
#endif /* PERIPHERAL_BASE_HPP_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment