52 lines
1.2 KiB
C++
Executable File
52 lines
1.2 KiB
C++
Executable File
//
|
|
// Created by Guangzong Chen on 6/12/23.
|
|
//
|
|
|
|
#ifndef STM32U5XX_HAL_GPIO_HPP
|
|
#define STM32U5XX_HAL_GPIO_HPP
|
|
|
|
#include "global_variable.h"
|
|
#include "reg_rcc.h"
|
|
#include "stm32u5xx.h"
|
|
#include "reg_gpio.h"
|
|
|
|
class Gpio {
|
|
private:
|
|
uint32_t initialized_pins;
|
|
GPIO_TypeDef *port;
|
|
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);
|
|
};
|
|
|
|
// following code use template, should be careful when use it
|
|
// it may introduce extra overhead
|
|
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
|