65 lines
1.5 KiB
C
65 lines
1.5 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 ePinLevel,
|
|
bool bPullEn,
|
|
PORT_PullStatusType ePullSel
|
|
) {
|
|
PORT_InitType tInitStruct = {0};
|
|
GPIO_InitType tGpioInitStruct = {0};
|
|
|
|
tInitStruct.bPullEn = bPullEn;
|
|
tInitStruct.ePullSel = ePullSel;
|
|
tInitStruct.u32PortPins = pinMask;
|
|
tInitStruct.uPortPinMux.u32PortPinMode = PORT_GPIO_MODE;
|
|
PORT_InitPins((PORT_InstanceType)port, &tInitStruct);
|
|
|
|
tGpioInitStruct.u32GpioPins = pinMask;
|
|
tGpioInitStruct.ePinDirection = direction;
|
|
tGpioInitStruct.ePinLevel = ePinLevel;
|
|
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;
|
|
}
|
|
|
|
void GpioPinToggle(tGpioPin *pin) {
|
|
GPIO_Toggle(pin->port, pin->pin);
|
|
} |