55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
//
|
|
// Created by cfif on 16.09.22.
|
|
//
|
|
#include "GpioPin.h"
|
|
|
|
tGpioPin vInitGpioPinPull(
|
|
GPIO_InstanceType port,
|
|
uint32_t pinMask,
|
|
GPIO_PinDirectionType direction,
|
|
bool reverse,
|
|
GPIO_PinLevelType gpio_pull
|
|
) {
|
|
GPIO_InitType tGpioInitStruct;
|
|
|
|
tGpioInitStruct.u32GpioPins = pinMask;
|
|
tGpioInitStruct.ePinDirection = direction;
|
|
tGpioInitStruct.ePinLevel = gpio_pull;
|
|
|
|
GPIO_InitPins(port, &tGpioInitStruct);
|
|
|
|
tGpioPin pin = {
|
|
.port = port,
|
|
.pin = pinMask,
|
|
.reverse = reverse
|
|
};
|
|
|
|
return pin;
|
|
}
|
|
|
|
void GpioPinSet(tGpioPin *pin, bool value) {
|
|
if (pin->reverse) {
|
|
value = !value;
|
|
}
|
|
|
|
if (value) {
|
|
GPIO_WritePins(pin->port, pin->pin, GPIO_HIGH);
|
|
} else {
|
|
GPIO_WritePins(pin->port, pin->pin, GPIO_LOW);
|
|
}
|
|
}
|
|
|
|
bool GpioPinGet(tGpioPin *pin) {
|
|
bool value;
|
|
if (GPIO_ReadPins(pin->port, pin->pin)) {
|
|
value = true;
|
|
} else { //if value == RESET;
|
|
value = false;
|
|
}
|
|
if (pin->reverse) {
|
|
value = !value;
|
|
}
|
|
return value;
|
|
}
|
|
|