2021-01-08 10:11:53 +01:00

77 lines
1.7 KiB
C++

#ifndef __PLATFORM_STM32G0XX_GPIO_H__
#define __PLATFORM_STM32G0XX_GPIO_H__
#include <cstdint>
#include "stm32g071xx.h"
namespace perinet::platform::stm32g0xx {
class Gpio
{
public:
enum class Port
{
PORT_A,
PORT_B,
PORT_C,
PORT_D,
PORT_F
};
enum class Speed
{
FREQ_LOW = 0, // Low speed
FREQ_MEDIUM, // Medium speed
FREQ_HIGH, // High speed
FREQ_VERY_HIGH // Very high speed
};
enum class Mode
{
MODE_INPUT = 0x00, // Input Floating Mode
MODE_OUTPUT_PP = 0x01, // Output Push Pull Mode
MODE_AF_PP = 0x02, // Alternate Function Push Pull Mode
MODE_ANALOG = 0x03, // Analog Mode
MODE_OUTPUT_OD = 0x11, // Output Open Drain Mode
MODE_AF_OD = 0x12, // Alternate Function Open Drain Mode
};
enum class Pullup
{
NOPULL = 0, // No Pull-up or Pull-down activation
PULLUP, // Pull-up activation
PULLDOWN // Pull-down activation
};
enum class AlternateFunction
{
ALTERNATE_FUNCTION_0 = 0,
ALTERNATE_FUNCTION_1,
ALTERNATE_FUNCTION_2,
ALTERNATE_FUNCTION_3,
ALTERNATE_FUNCTION_4,
ALTERNATE_FUNCTION_5,
ALTERNATE_FUNCTION_6,
ALTERNATE_FUNCTION_7,
ALTERNATE_FUNCTION_8,
ALTERNATE_FUNCTION_9,
ALTERNATE_FUNCTION_10,
};
Gpio(Port, uint32_t, Mode=Mode::MODE_INPUT, Pullup=Pullup::NOPULL, AlternateFunction=AlternateFunction::ALTERNATE_FUNCTION_0);
uint32_t get();
void set();
void clear();
void toggle();
private:
GPIO_TypeDef *port;
uint32_t pin;
};
}
#endif