Compare commits
3 Commits
feature/mi
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af9db5a1b0 | ||
|
|
470ad75376 | ||
| e6f5315dac |
@ -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)
|
||||||
|
|||||||
37
Peripherals/Inc/peripherals_hal_concepts.hpp
Normal file
37
Peripherals/Inc/peripherals_hal_concepts.hpp
Normal 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{});
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
51
Peripherals/Inc/peripherals_hal_esp.hpp
Normal file
51
Peripherals/Inc/peripherals_hal_esp.hpp
Normal 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 */
|
||||||
@ -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_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user