52 lines
1.3 KiB
C++
Executable File
52 lines
1.3 KiB
C++
Executable File
#ifndef STM32U5XX_HAL_GPIO_HPP
|
|
#define STM32U5XX_HAL_GPIO_HPP
|
|
|
|
#include "global_variable.h"
|
|
#include "reg_gpio.h"
|
|
#include "reg_rcc.h"
|
|
#include "stm32u5xx.h"
|
|
|
|
class Gpio {
|
|
private:
|
|
uint32_t initialized_pins = 0;
|
|
GPIO_TypeDef *port = nullptr;
|
|
|
|
public:
|
|
Gpio();
|
|
|
|
void setup(GPIO_TypeDef *gpio);
|
|
|
|
hal_status_e init(uint8_t pin, reg_gpio_mode mode = OUTPUT, uint32_t af = 0,
|
|
reg_gpio_out_type ot = PULL_PUSH, reg_gpio_pupd pull = LL_NOPUPD,
|
|
reg_gpio_speed spd = HIGH_SPEED);
|
|
|
|
void set_high(uint32_t pin);
|
|
|
|
void set_low(uint32_t pin);
|
|
|
|
void toggle(uint32_t pin);
|
|
|
|
/// to set mode for a pin, just use following code:
|
|
/// this->reg_port->moder->moder0 = mode;
|
|
};
|
|
|
|
// template wrapper for gpio
|
|
// It will increase the size of code.
|
|
template <Gpio *gpio, uint32_t pin> class GpioPin {
|
|
public:
|
|
GpioPin() = default;
|
|
|
|
void setup(reg_gpio_mode mode = OUTPUT, uint32_t af = 0, reg_gpio_out_type ot = PULL_PUSH,
|
|
reg_gpio_pupd pull = LL_NOPUPD, reg_gpio_speed spd = HIGH_SPEED) {
|
|
gpio->init(pin, mode, af, ot, pull, spd);
|
|
}
|
|
|
|
void set_high() { gpio->set_high(pin); }
|
|
|
|
void set_low() { gpio->set_low(pin); }
|
|
|
|
void toggle() { gpio->toggle(pin); }
|
|
};
|
|
|
|
#endif // STM32U5XX_HAL_GPIO_HPP
|