Compare commits

..

3 Commits

Author SHA1 Message Date
Erki
af9db5a1b0 Peripherals: Fix missing include
All checks were successful
CI & Unit Tests / Unit-Tests (push) Successful in 48s
CI & Unit Tests / Docs (push) Successful in 12s
2024-03-05 20:28:23 +02:00
Erki
470ad75376 Peripherals: Begin ESP HAL
All checks were successful
CI & Unit Tests / Unit-Tests (push) Successful in 54s
CI & Unit Tests / Docs (push) Successful in 14s
2024-02-16 16:51:39 +02:00
e6f5315dac Migrate CI to use Fedora (#4)
All checks were successful
CI & Unit Tests / Unit-Tests (push) Successful in 48s
CI & Unit Tests / Docs (push) Successful in 11s
Co-authored-by: Erki <erki@skullnet.me>
Reviewed-on: #4
2024-02-07 07:27:50 +00:00
4 changed files with 96 additions and 0 deletions

View File

@ -14,6 +14,8 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/)
option(SKULLC_WITH_TESTS "Enable unit testing." OFF) option(SKULLC_WITH_TESTS "Enable unit testing." OFF)
option(SKULLC_WITH_HAL "Enable the compiling and deployment of the HAL dependent sections." OFF) option(SKULLC_WITH_HAL "Enable the compiling and deployment of the HAL dependent sections." OFF)
option(SKULLC_USE_HAL_ST "Enable the ST HAl when SKULLC_WITH_HAL is enabled." OFF)
option(SKULLC_USE_HAL_ESP "Enable the ESP HAL when SKULLC_WITH_HAL is enabled." OFF)
option(SKULLC_WITH_DOCS "Enable documentation building." OFF) option(SKULLC_WITH_DOCS "Enable documentation building." OFF)
include(skullc-install) include(skullc-install)

View File

@ -0,0 +1,37 @@
//
// Created by erki on 11/02/24.
//
#pragma once
#include <array>
#include <concepts>
#include <cstdint>
namespace Peripherals::Hal
{
template<typename T>
concept Gpio = requires (T t, const T ct) {
t.set(true);
t.toggle();
{ ct.read() } -> std::same_as<bool>;
};
template<typename T>
concept SerialInterface = requires (T t, std::uint8_t* data, const std::uint32_t len) {
{ t.transmit(data, len) } -> std::same_as<bool>;
{ t.transmit(std::array<std::uint8_t, 10>{}) } -> std::same_as<bool>;
{ t.receive(data, len) } -> std::same_as<bool>;
{ t.receive(std::array<std::uint8_t, 10>{}) } -> std::same_as<bool>;
};
template<typename T, typename RegName>
concept RegisterInterface = requires (T t, RegName reg, std::uint8_t* data, const std::uint32_t len) {
t.writerRegister(reg, std::uint8_t{});
t.writeRegisterMultibyte(reg, data, len);
{ t.readRegister(reg, std::uint32_t{}) } -> std::same_as<std::uint8_t>;
t.readRegisterMultibyte(reg, data, len, std::uint32_t{});
};
}

View File

@ -0,0 +1,51 @@
//
// 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}
}
#else
# warning "ESP HAL included without SKULLC_USE_HAL_ESP being defined."
#endif /* SKULLC_USE_HAL_ESP */

View File

@ -8,6 +8,8 @@
#ifndef SKULLC_PERIPHERALS_HAL_ST_HPP_ #ifndef SKULLC_PERIPHERALS_HAL_ST_HPP_
#define SKULLC_PERIPHERALS_HAL_ST_HPP_ #define SKULLC_PERIPHERALS_HAL_ST_HPP_
#ifdef SKULLC_USE_HAL_ST
#include <main.h> #include <main.h>
#include <array> #include <array>
@ -343,4 +345,8 @@ struct ItmSerialInterface
}// namespace Hal }// namespace Hal
}// namespace Peripherals }// namespace Peripherals
#else
# warning "ESP HAL included without SKULLC_USE_HAL_ESP being defined."
#endif /* SKULLC_USE_HAL_ST */
#endif /* SKULLC_PERIPHERALS_HAL_ST_HPP_ */ #endif /* SKULLC_PERIPHERALS_HAL_ST_HPP_ */