commit 588955a73d5ae9b74457bf156b4695ff7d028f6f Author: cfif Date: Fri Jan 24 13:22:32 2025 +0300 Перенос на новую организацию GONEC diff --git a/Inc/GpioPin.h b/Inc/GpioPin.h new file mode 100644 index 0000000..a04da16 --- /dev/null +++ b/Inc/GpioPin.h @@ -0,0 +1,42 @@ +// +// Created by cfif on 16.09.22. +// + +#ifndef GPIOPIN_GPIOPIN_H +#define GPIOPIN_GPIOPIN_H + +#include "GpioPinInterface.h" +#include CMSIS_device_header + +#define GPIO_PIN_NOREVERSE false +#define GPIO_PIN_REVERSE true + +tGpioPin vInitGpioPinPull( + gpio_type *port, + uint32_t pinMask, + gpio_mode_type direction, + bool reverse, + crm_periph_clock_type clock, + gpio_pull_type gpio_pull +); + +#define vInitGpioPin(PORT, PIN_MASK, DIR, REVERSE, CLK) vInitGpioPinPull(PORT,PIN_MASK,DIR,REVERSE,CLK, GPIO_PULL_NONE) + +tGpioPin vInitGpioPinOpenDrain(gpio_type *port, uint32_t pinMask, gpio_mode_type direction, bool reverse, + crm_periph_clock_type clock); + +#define InitGpioPin(PORT, MASK, DIRECTION, REVERSE) \ +vInitGpioPin(PORT, MASK, DIRECTION, REVERSE, CRM_##PORT##_PERIPH_CLOCK) + +#define InitGpioPinPull(PORT, MASK, DIRECTION, REVERSE, PULL) \ +vInitGpioPinPull(PORT, MASK, DIRECTION, REVERSE, CRM_##PORT##_PERIPH_CLOCK, PULL) + +#define InitGpioPinOpenDrain(PORT, MASK, DIRECTION, REVERSE) \ +vInitGpioPinOpenDrain(PORT, MASK, DIRECTION, REVERSE, CRM_##PORT##_PERIPH_CLOCK) + + +void GpioPinSet(tGpioPin *pin, bool value); + +bool GpioPinGet(tGpioPin *pin); + +#endif //UVEOS_DEMO_ON_NIIET_MCU_GPIOPIN_H diff --git a/Src/GpioPin.c b/Src/GpioPin.c new file mode 100644 index 0000000..336acb1 --- /dev/null +++ b/Src/GpioPin.c @@ -0,0 +1,82 @@ +// +// Created by cfif on 16.09.22. +// +#include "GpioPin.h" + +tGpioPin vInitGpioPinOpenDrain(gpio_type *port, uint32_t pinMask, gpio_mode_type direction, bool reverse, + crm_periph_clock_type clock) { + + crm_periph_clock_enable(clock, TRUE); + + gpio_init_type GPIOInit; + gpio_default_para_init(&GPIOInit); + GPIOInit.gpio_mode = direction; + GPIOInit.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN; + + tGpioPin pin = { + .port = port, + .pin = pinMask, + .reverse = reverse + }; + + GPIOInit.gpio_pins = pin.pin; + + gpio_init(pin.port, &GPIOInit); + + return pin; +} + +tGpioPin vInitGpioPinPull( + gpio_type *port, + uint32_t pinMask, + gpio_mode_type direction, + bool reverse, + crm_periph_clock_type clock, + gpio_pull_type gpio_pull +) { + + crm_periph_clock_enable(clock, TRUE); + + gpio_init_type GPIOInit; + gpio_default_para_init(&GPIOInit); + GPIOInit.gpio_mode = direction; + GPIOInit.gpio_pull = gpio_pull; + + tGpioPin pin = { + .port = port, + .pin = pinMask, + .reverse = reverse + }; + + GPIOInit.gpio_pins = pin.pin; + + gpio_init(pin.port, &GPIOInit); + + return pin; +} + +void GpioPinSet(tGpioPin *pin, bool value) { + if (pin->reverse) { + value = !value; + } + + if (value) { + gpio_bits_set(pin->port, pin->pin); + } else { + gpio_bits_reset(pin->port, pin->pin); + } +} + +bool GpioPinGet(tGpioPin *pin) { + bool value; + if (gpio_input_data_bit_read(pin->port, pin->pin) == SET) { + 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..e0f12f5 --- /dev/null +++ b/modular.json @@ -0,0 +1,17 @@ +{ + "dep": [ + { + "type": "git", + "provider": "GONEC", + "repo": "GpioPinInterface" + } + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file