sitara_depot/components/free_rtos/gpio/gpio.cpp

55 lines
978 B
C++
Raw Normal View History

/*
* gpio.cpp
*
* Created on: 6 <EFBFBD><EFBFBD><EFBFBD>. 2023 <EFBFBD>.
* 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;
}