From 6b9aea2c765d1938f6b5f04bf809b11bc1e3056a Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 29 Sep 2025 11:21:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9?= =?UTF-8?q?=D1=81=D1=8B=20=D0=B8=20=D0=B4=D1=80=D0=B0=D0=B9=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/GpioPin.h | 31 +++++++++++++++++++++++++++++ Src/GpioPin.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ modular.json | 17 ++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 Inc/GpioPin.h create mode 100644 Src/GpioPin.c create mode 100644 modular.json diff --git a/Inc/GpioPin.h b/Inc/GpioPin.h new file mode 100644 index 0000000..bbd2e1f --- /dev/null +++ b/Inc/GpioPin.h @@ -0,0 +1,31 @@ +// +// Created by cfif on 16.09.22. +// + +#ifndef HVAC_M7_GPIOPIN_H +#define HVAC_M7_GPIOPIN_H + +#include "GpioPinInterface.h" +#include CMSIS_device_header +#include "fc7xxx_driver_pcc.h" +#include "fc7xxx_driver_port.h" +#include "fc7xxx_driver_gpio.h" +#include "fc7xxx_driver_scg.h" + +#define GPIO_PIN_NOREVERSE false +#define GPIO_PIN_REVERSE true + +tGpioPin vInitGpioPinPull( + GPIO_InstanceType port, + uint32_t pinMask, + GPIO_PinDirectionType direction, + bool reverse, + GPIO_PinLevelType gpio_pull +); + + +void GpioPinSet(tGpioPin *pin, bool value); + +bool GpioPinGet(tGpioPin *pin); + +#endif //HVAC_M7_GPIOPIN_H diff --git a/Src/GpioPin.c b/Src/GpioPin.c new file mode 100644 index 0000000..a071c62 --- /dev/null +++ b/Src/GpioPin.c @@ -0,0 +1,54 @@ +// +// 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; +} + diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..f910f3c --- /dev/null +++ b/modular.json @@ -0,0 +1,17 @@ +{ + "dep": [ + { + "type": "git", + "provider": "HVAC_M7", + "repo": "GpioPinInterface" + } + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file