sitara_depot/components/free_rtos/gpio/gpio.cpp

55 lines
992 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* gpio.cpp
*
* Created on: 6 мар. 2023 г.
* Author: sychev
*/
#include "free_rtos/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;
}