skullc-peripherals/Peripherals/Inc/peripherals_hal_esp.hpp
Erki 4d897ad5c6
Some checks failed
CI & Unit Tests / Unit-Tests (push) Failing after 10s
CI & Unit Tests / Docs (push) Successful in 14s
WIP2
2025-02-02 16:37:52 +02:00

52 lines
979 B
C++

//
// Created by erki on 11/02/24.
//
#pragma once
#ifdef SKULLC_USE_HAL_ESP
#include <peripherals_hal_concepts.hpp>
#include <driver/gpio.h>
namespace Peripherals::Hal::Esp
{
struct Gpio
{
gpio_num_t gpio;
const bool inverted = false;
Gpio() = delete;
explicit Gpio(gpio_num_t gpio, const bool inverted)
: gpio(gpio), inverted(inverted)
{}
void set(const bool& state)
{
gpio_set_level(gpio, inverted ? !state : state);
}
void toggle() { gpio_set_level(gpio, !gpio_get_level(gpio)); }
bool read() const
{
return inverted ? !bool(gpio_get_level(gpio)) : bool(gpio_get_level(gpio));
}
};
static_assert(Peripherals::Hal::Gpio<Gpio>);
#define CREATE_GPIO(name) \
Peripherals::Hal::Esp::Gpio { name, false }
#define CREATE_INV_GPIO(name) \
Peripherals::Hal::Esp::Gpio { name, true }
}// namespace Peripherals::Hal::Esp
#else
#warning "ESP HAL included without SKULLC_USE_HAL_ESP being defined."
#endif /* SKULLC_USE_HAL_ESP */