From dd4d67395d58eecf253a93c444c235704379ca58 Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 14 Jul 2025 12:13:45 +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=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?UTF-8?q?=20GPIO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/GpioPin.h | 35 ++++++++++++++++++++++++++++++++++ Src/GpioPin.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ modular.json | 17 +++++++++++++++++ 3 files changed, 104 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..566aa4f --- /dev/null +++ b/Inc/GpioPin.h @@ -0,0 +1,35 @@ +// +// Created by cfif on 16.09.22. +// + +#ifndef GPIOPIN_GPIOPIN_H +#define GPIOPIN_GPIOPIN_H + +#include "GpioPinInterface.h" +#include CMSIS_device_header +#include "gpio_drv.h" + +#define GPIO_PIN_NOREVERSE false +#define GPIO_PIN_REVERSE true + +tGpioPin vInitGpioPinPull( + PORT_Type *port, + GPIO_Type *gpio, + uint32_t pinMask, + port_data_direction_t direction, + bool reverse, + port_pull_config_t gpio_pull +); + +#define InitGpioPin(PORT, GPIO, MASK, DIRECTION, REVERSE) \ +vInitGpioPinPull(PORT, GPIO, MASK, DIRECTION, REVERSE, PORT_INTERNAL_PULL_NOT_ENABLED) + +#define InitGpioPinPull(PORT, MASK, DIRECTION, REVERSE, PULL) \ +vInitGpioPinPull(PORT, MASK, DIRECTION, REVERSE, PULL) + + +void GpioPinSet(tGpioPin *pin, bool value); + +bool GpioPinGet(tGpioPin *pin); + +#endif diff --git a/Src/GpioPin.c b/Src/GpioPin.c new file mode 100644 index 0000000..2e25d2c --- /dev/null +++ b/Src/GpioPin.c @@ -0,0 +1,52 @@ +// +// Created by cfif on 16.09.22. +// +#include "GpioPin.h" + +tGpioPin vInitGpioPinPull( + PORT_Type *port, + GPIO_Type *gpio, + uint32_t pinMask, + port_data_direction_t direction, + bool reverse, + port_pull_config_t gpio_pull +) { + GPIO_DRV_SetMuxModeSel(port, pinMask, PORT_MUX_AS_GPIO); + GPIO_DRV_SetPinDirection(gpio, pinMask, direction); + GPIO_DRV_SetPullSel(port, pinMask, gpio_pull); + + tGpioPin pin = { + .port = port, + .gpio = gpio, + .pin = pinMask, + .reverse = reverse + }; + + return pin; +} + +void GpioPinSet(tGpioPin *pin, bool value) { + if (pin->reverse) { + value = !value; + } + + if (value) { + GPIO_DRV_WritePin(pin->gpio, pin->pin, 1); + } else { + GPIO_DRV_WritePin(pin->gpio, pin->pin, 0); + } +} + +bool GpioPinGet(tGpioPin *pin) { + bool value; + if ((GPIO_DRV_ReadPins(pin->gpio) & (1 << pin->pin))) { + value = true; + } else { + value = false; + } + if (pin->reverse) { + value = !value; + } + return value; +} + diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..00d36b0 --- /dev/null +++ b/modular.json @@ -0,0 +1,17 @@ +{ + "dep": [ + { + "type": "git", + "provider": "HVAC", + "repo": "GpioPinInterface" + } + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file