Tool Libs
UMIT-TIROL Institute of Automation and Control Engineering library collection
 
Loading...
Searching...
No Matches
gpio.h
Go to the documentation of this file.
1
5#ifndef STM_GPIO_H
6#define STM_GPIO_H
7
8#include "hal.h"
9
13class DIO {
14private:
16 uint32_t iPin;
17 GPIO_TypeDef *port;
19public:
20 DIO(uint32_t pin, GPIO_TypeDef *port,
21 uint32_t mode = GPIO_MODE_OUTPUT_PP,
22 uint32_t pull = GPIO_NOPULL) {
23 this->iPin = pin;
24 this->port = port;
25 GPIO_InitTypeDef GPIO_InitStruct = {};
26 GPIO_InitStruct.Pin = iPin;
27 GPIO_InitStruct.Mode = mode;
28 GPIO_InitStruct.Pull = pull;
29 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
30 HAL_GPIO_Init(port, &GPIO_InitStruct);
31 }
32
37 void set(bool high) {
38 HAL_GPIO_WritePin(port, iPin, (GPIO_PinState) high);
39 }
40
45 bool get() {
46 return HAL_GPIO_ReadPin(port, iPin);
47 }
48
52 void toggle() {
53 HAL_GPIO_TogglePin(port, iPin);
54 }
55};
56
60class AFIO {
61public:
62 AFIO(uint32_t pin, GPIO_TypeDef *port, uint32_t alternate,
63 uint32_t pull = GPIO_NOPULL,
64 uint32_t speed = GPIO_SPEED_FREQ_LOW,
65 uint32_t mode = GPIO_MODE_AF_PP) {
66 GPIO_InitTypeDef GPIO_InitStruct = {};
67 GPIO_InitStruct.Pin = pin;
68 GPIO_InitStruct.Mode = mode;
69 GPIO_InitStruct.Pull = pull;
70 GPIO_InitStruct.Speed = speed;
71 GPIO_InitStruct.Alternate = alternate;
72 HAL_GPIO_Init(port, &GPIO_InitStruct);
73 }
74};
75
76#endif //STM_GPIO_H
Wrapper class for pins in alternate configuration mode.
Definition gpio.h:60
Wrapper class for simple digital input/output pin.
Definition gpio.h:13
void set(bool high)
set digital output level
Definition gpio.h:37
void toggle()
toggle digital output level
Definition gpio.h:52
bool get()
read digital input level
Definition gpio.h:45
Copyright (c) 2020 IACE.