sitara_depot/components/free_rtos/gpio/gpio.cpp
algin ae3cac8a7d feat: First commit
Adds sitara_depot/free_rtos

Original one is on server_gorbunov/SmartForce4.0/sitara_depot
2023-05-03 14:01:32 +03:00

55 lines
978 B
C++

/*
* gpio.cpp
*
* Created on: 6 ìàð. 2023 ã.
* Author: sychev
*/
#include "gpio/gpio.hpp"
#include <drivers/gpio.h>
free_rtos::Gpio::Gpio(uint32_t num, Dir dir, uint32_t base_address) :
num_{num},
dir_{dir},
base_addr_{base_address}
{
uint32_t gpio_dir = GPIO_DIRECTION_INPUT;
if (dir_ == e_gpioDirOutput) {
gpio_dir = GPIO_DIRECTION_OUTPUT;
}
GPIO_setDirMode(base_addr_, num_, gpio_dir);
}
void free_rtos::Gpio::set() {
GPIO_pinWriteHigh(base_addr_, num_);
}
void free_rtos::Gpio::clr() {
GPIO_pinWriteLow(base_addr_, num_);
}
void free_rtos::Gpio::toggle() {
bool state = get();
if (state) {
clr();
}
else {
set();
}
}
bool free_rtos::Gpio::get() {
bool out = false;
if (dir_ == e_gpioDirInput) {
out = GPIO_pinRead(base_addr_, num_);
}
else if (dir_ == e_gpioDirOutput) {
out = GPIO_pinOutValueRead(base_addr_, num_);
}
return out;
}