This commit is contained in:
cfif 2024-12-04 13:10:48 +03:00
commit cbe58c80a7
3 changed files with 194 additions and 0 deletions

25
Inc/GpioPin.h Normal file
View File

@ -0,0 +1,25 @@
//
// Created by cfif on 25.10.22.
//
#ifndef GPIOPIN_GPIOPIN_H
#define GPIOPIN_GPIOPIN_H
#include "GpioPinInterface.h"
#include "n32g45x.h"
#define GPIO_PIN_NOREVERSE false
#define GPIO_PIN_REVERSE true
void GpioPin_InitRccConfigOnly(GPIO_Module *port, uint32_t pinMask, GPIO_ModeType mode, GPIO_SpeedType speed, uint32_t clock);
#define GpioPin_InitConfigOnly(PORT, MASK, MODE, SPEED) \
GpioPin_InitRccConfigOnly(PORT, MASK, MODE, SPEED, RCC_APB2_PERIPH_##PORT)
tGpioPin GpioPin_InitRcc(GPIO_Module *port, uint32_t pinMask, GPIO_ModeType mode, GPIO_SpeedType speed, bool reverse, uint32_t clock);
#define GpioPin_Init(PORT, MASK, MODE, SPEED, REVERSE) \
GpioPin_InitRcc(PORT, MASK, MODE, SPEED, REVERSE, RCC_APB2_PERIPH_##PORT)
//tGpioPin InitGpioPin(GPIO_Module *port, uint32_t pinMask, GPIO_ModeType mode, GPIO_SpeedType speed, bool reverse);
//void InitGpioPinConfigOnly(GPIO_Module *port, uint32_t pinMask, GPIO_ModeType mode, GPIO_SpeedType speed);
#endif //UVEOS_DEMO_ON_NIIET_MCU_GPIOPIN_H

147
Src/GpioPin.c Normal file
View File

@ -0,0 +1,147 @@
//
// Created by cfif on 25.10.22.
//
#include "GpioPin.h"
#include "SystemDelayInterface.h"
/*
typedef struct {
GPIO_Module *port;
uint32_t apb;
} tGpioApbPair;
#define GPIO_APB_TABLE_LINE(NAME) {.port=NAME, .apb=RCC_APB2_PERIPH_##NAME}
tGpioApbPair GPIO_APB_TABLE[] = {
GPIO_APB_TABLE_LINE(GPIOA),
GPIO_APB_TABLE_LINE(GPIOB),
GPIO_APB_TABLE_LINE(GPIOC),
GPIO_APB_TABLE_LINE(GPIOD),
GPIO_APB_TABLE_LINE(GPIOE),
GPIO_APB_TABLE_LINE(GPIOF),
GPIO_APB_TABLE_LINE(GPIOG),
};
tGpioApbPair *GPIO_APB_TABLE_END = GPIO_APB_TABLE + sizeof(GPIO_APB_TABLE);
void RCC_EnableAPB2PeriphClkForGpioPort(GPIO_Module *port, FunctionalState Cmd) {
for (tGpioApbPair *pair = GPIO_APB_TABLE; pair < GPIO_APB_TABLE_END; ++pair) {
if (pair->port == port) {
RCC_EnableAPB2PeriphClk(pair->apb, Cmd);
return;
}
}
}
void InitGpioPinConfigOnly(GPIO_Module *port, uint32_t pinMask, GPIO_ModeType mode, GPIO_SpeedType speed) {
GPIO_InitType GPIO_InitStructure;
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
assert_param(pinMask <= GPIO_PIN_ALL);
RCC_EnableAPB2PeriphClkForGpioPort(port, ENABLE);
GPIO_InitStructure.Pin = pinMask;
GPIO_InitStructure.GPIO_Mode = mode;
GPIO_InitStructure.GPIO_Speed = speed;
GPIO_InitPeripheral(port, &GPIO_InitStructure);
}
tGpioPin InitGpioPin(GPIO_Module *port, uint32_t pinMask, GPIO_ModeType mode, GPIO_SpeedType speed, bool reverse) {
InitGpioPinConfigOnly(port, pinMask, mode, speed);
tGpioPin pin = {
.port = port,
.pin = pinMask,
.reverse = reverse
};
return pin;
}
*/
void GpioPin_InitRccConfigOnly(GPIO_Module *port, uint32_t pinMask, GPIO_ModeType mode, GPIO_SpeedType speed,
uint32_t clock) {
GPIO_InitType GPIO_InitStructure;
RCC_EnableAPB2PeriphClk(clock, ENABLE);
GPIO_InitStructure.Pin = pinMask;
GPIO_InitStructure.GPIO_Mode = mode;
GPIO_InitStructure.GPIO_Speed = speed;
GPIO_InitPeripheral(port, &GPIO_InitStructure);
}
tGpioPin GpioPin_InitRcc(
GPIO_Module *port,
uint32_t pinMask,
GPIO_ModeType mode,
GPIO_SpeedType speed, bool reverse,
uint32_t clock
) {
GpioPin_InitRccConfigOnly(port, pinMask, mode, speed, clock);
tGpioPin pin = {
.port = port,
.pin = pinMask,
.reverse = reverse
};
return pin;
}
/**
* @brief Set selected pin SET or RESET.
* @param pin is tGpioPin inited with InitGpioPin
*/
void GpioPinSet(tGpioPin *pin, bool value) {
if (pin->reverse) {
value = !value;
}
if (value) {
GPIO_SetBits(pin->port, pin->pin);
} else {
GPIO_ResetBits(pin->port, pin->pin);
}
}
bool Debounse(bool thisStat, tGpioPin *pin) {
bool current = GPIO_ReadInputDataBit(pin->port, pin->pin);
if(thisStat != current) {
SystemDelayMs(10);
current = GPIO_ReadInputDataBit(pin->port, pin->pin);
}
return current;
}
/**
* @brief Get selected input pin is SET or RESET.
* @param pin is tGpioPin inited with InitGpioPin
*/
bool GpioPinGet(tGpioPin *pin) {
bool value = Bit_SET;
if (Debounse(value, pin) == Bit_SET) {
value = true;
} else { //if value == Bit_RESET;
value = false;
}
if (pin->reverse) {
value = !value;
}
return value;
}

22
modular.json Normal file
View File

@ -0,0 +1,22 @@
{
"dep": [
{
"type": "git",
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
"repo": "PeripheralDriver_NATION_N32G45X"
},
{
"type": "git",
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
"repo": "GpioPinInterface"
}
],
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}