Начало
This commit is contained in:
commit
8b38899bf5
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"dep": [
|
||||
{
|
||||
"type": "git",
|
||||
"provider": "HVAC_DEV",
|
||||
"repo": "GpioPinInterface"
|
||||
}
|
||||
],
|
||||
"cmake": {
|
||||
"inc_dirs": [
|
||||
"Inc"
|
||||
],
|
||||
"srcs": [
|
||||
"Src/**.c"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue