mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-09-29 05:17:33 +00:00
Move interfaces to subdir
This commit is contained in:
35
include/sta/intf/gpio_pin.hpp
Normal file
35
include/sta/intf/gpio_pin.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @brief GPIO pin interface definitions.
|
||||
*/
|
||||
#ifndef STA_GPIO_PIN_HPP
|
||||
#define STA_GPIO_PIN_HPP
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief GPIO pin state.
|
||||
*/
|
||||
enum class GpioPinState
|
||||
{
|
||||
LOW,
|
||||
HIGH
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for GPIO pins.
|
||||
*/
|
||||
class GpioPin
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Set pin output state.
|
||||
*
|
||||
* @param state Output state
|
||||
*/
|
||||
virtual void setState(GpioPinState state) = 0;
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_GPIO_PIN_HPP
|
30
include/sta/intf/mutex.hpp
Normal file
30
include/sta/intf/mutex.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @brief Mutex interface definition.
|
||||
*/
|
||||
#ifndef STA_MUTEX_HPP
|
||||
#define STA_MUTEX_HPP
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Interface for mutex objects.
|
||||
*/
|
||||
class Mutex
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Block until mutex has been acquired.
|
||||
*/
|
||||
virtual void acquire() = 0;
|
||||
/**
|
||||
* @brief Release mutex.
|
||||
*/
|
||||
virtual void release() = 0;
|
||||
|
||||
static Mutex * ALWAYS_FREE; /**< Fake mutex that can always be acquired */
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_MUTEX_HPP
|
40
include/sta/intf/signal.hpp
Normal file
40
include/sta/intf/signal.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @brief Signal interface definition.
|
||||
*/
|
||||
#ifndef STA_SIGNAL_HPP
|
||||
#define STA_SIGNAL_HPP
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Interface for signal objects.
|
||||
*/
|
||||
class Signal
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Enter signaled state.
|
||||
*/
|
||||
virtual void notify() = 0;
|
||||
/**
|
||||
* @brief Check signal state w/o changing it.
|
||||
*
|
||||
* @return True if in signaled state
|
||||
*/
|
||||
virtual bool peek() = 0;
|
||||
/**
|
||||
* @brief Check signal state.
|
||||
*
|
||||
* @return True if in signaled state
|
||||
*/
|
||||
virtual bool test() = 0;
|
||||
/**
|
||||
* @brief Wait until signaled state is entered.
|
||||
*/
|
||||
virtual void wait() = 0;
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_SIGNAL_HPP
|
109
include/sta/intf/spi_device.hpp
Normal file
109
include/sta/intf/spi_device.hpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* @brief SPI interface definitions.
|
||||
*/
|
||||
#ifndef STA_SPI_DEVICE_HPP
|
||||
#define STA_SPI_DEVICE_HPP
|
||||
|
||||
#include <sta/intf/spi_interface.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Interface for SPI devices.
|
||||
*/
|
||||
class SpiDevice
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param intf SPI hardware interface
|
||||
*/
|
||||
SpiDevice(SpiInterface * intf);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Start transmission with device.
|
||||
*
|
||||
* Must be called before any I/O operations.
|
||||
*/
|
||||
void beginTransmission();
|
||||
/**
|
||||
* @brief End transmission with device.
|
||||
*
|
||||
* Must be called after last I/O operation.
|
||||
*/
|
||||
void endTransmission();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send single byte of data.
|
||||
*
|
||||
* @param value 8-bit value
|
||||
*/
|
||||
void transfer(uint8_t value);
|
||||
/**
|
||||
* @brief Send two bytes of data.
|
||||
*
|
||||
* @param value 16-bit value
|
||||
*/
|
||||
void transfer16(uint16_t data);
|
||||
/**
|
||||
* @brief Send data from buffer.
|
||||
*
|
||||
* @param buffer Source buffer
|
||||
* @param size Number of bytes to transfer
|
||||
*/
|
||||
void transfer(const uint8_t * buffer, size_t size);
|
||||
/**
|
||||
* @brief Send and receive data simultaneously.
|
||||
*
|
||||
* @param txBuffer Send buffer
|
||||
* @param rxBuffer Receive buffer
|
||||
* @param size Number of bytes to transfer
|
||||
*/
|
||||
void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size);
|
||||
/**
|
||||
* @brief Read incoming data to buffer.
|
||||
*
|
||||
* @param buffer Destination buffer
|
||||
* @param size Number of bytes to read
|
||||
*/
|
||||
void receive(uint8_t * buffer, size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send byte value repeatedly.
|
||||
*
|
||||
* @param value 8-bit value to repeat
|
||||
* @param count Number of repetitions
|
||||
*/
|
||||
void fill(uint8_t value, size_t count);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get SPI interface settings.
|
||||
*
|
||||
* @return SPI settings
|
||||
*/
|
||||
const SpiSettings & settings() const;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Activate device via CS pin.
|
||||
*/
|
||||
virtual void select() = 0;
|
||||
/**
|
||||
* @brief Deactivate device via CS pin.
|
||||
*/
|
||||
virtual void deselect() = 0;
|
||||
|
||||
private:
|
||||
SpiInterface * intf_; /**< SPI hardware interface */
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_SPI_DEVICE_HPP
|
101
include/sta/intf/spi_interface.hpp
Normal file
101
include/sta/intf/spi_interface.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* @brief SPI interface definitions.
|
||||
*/
|
||||
#ifndef STA_SPI_INTERFACE_HPP
|
||||
#define STA_SPI_INTERFACE_HPP
|
||||
|
||||
#include <sta/intf/mutex.hpp>
|
||||
#include <sta/spi_settings.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Interface for SPI hardware.
|
||||
*/
|
||||
class SpiInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param settings SPI interface settings
|
||||
* @param mutex Mutex object for managing shared access. Pass nullptr for no access control
|
||||
*/
|
||||
SpiInterface(Mutex * mutex = nullptr);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send single byte of data.
|
||||
*
|
||||
* @param value 8-bit value
|
||||
*/
|
||||
virtual void transfer(uint8_t value) = 0;
|
||||
/**
|
||||
* @brief Send two bytes of data.
|
||||
*
|
||||
* @param value 16-bit value
|
||||
*/
|
||||
virtual void transfer16(uint16_t value) = 0;
|
||||
/**
|
||||
* @brief Send data from buffer.
|
||||
*
|
||||
* @param buffer Source buffer
|
||||
* @param size Number of bytes to transfer
|
||||
*/
|
||||
virtual void transfer(const uint8_t * buffer, size_t size) = 0;
|
||||
/**
|
||||
* @brief Send and receive data simultaneously.
|
||||
*
|
||||
* @param txBuffer Send buffer
|
||||
* @param rxBuffer Receive buffer
|
||||
* @param size Number of bytes to transfer
|
||||
*/
|
||||
virtual void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) = 0;
|
||||
/**
|
||||
* @brief Read incoming data to buffer.
|
||||
*
|
||||
* @param buffer Destination buffer
|
||||
* @param size Number of bytes to read
|
||||
*/
|
||||
virtual void receive(uint8_t * buffer, size_t size) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send byte value repeatedly.
|
||||
*
|
||||
* @param value 8-bit value to repeat
|
||||
* @param count Number of repetitions
|
||||
*/
|
||||
virtual void fill(uint8_t value, size_t count) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get SPI interface settings.
|
||||
*
|
||||
* @return SPI settings
|
||||
*/
|
||||
virtual const SpiSettings & settings() const = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Acquire usage rights to use the interface.
|
||||
*
|
||||
* Must be called before any I/O operations are executed.
|
||||
*/
|
||||
virtual void acquire();
|
||||
/**
|
||||
* @brief Release usage rights for interface.
|
||||
*
|
||||
* Must be called after last I/O operation.
|
||||
*/
|
||||
virtual void release();
|
||||
|
||||
private:
|
||||
Mutex * mutex_; /**< Mutex object */
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_SPI_INTERFACE_HPP
|
17
include/sta/intf/time.hpp
Normal file
17
include/sta/intf/time.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @brief Signatures for time related functions.
|
||||
*/
|
||||
#ifndef STA_TIME_HPP
|
||||
#define STA_TIME_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
using TimeMsFn = uint32_t (*)();
|
||||
using TimeUsFn = uint32_t (*)();
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_TIME_HPP
|
198
include/sta/intf/uart.hpp
Normal file
198
include/sta/intf/uart.hpp
Normal file
@@ -0,0 +1,198 @@
|
||||
/**
|
||||
* @brief UART interface definition.
|
||||
*/
|
||||
#ifndef STA_UART_HPP
|
||||
#define STA_UART_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Integer representation.
|
||||
*/
|
||||
enum class IntegerBase
|
||||
{
|
||||
DEC, /**< Decimal */
|
||||
BIN, /**< Binary */
|
||||
HEX /**< Hexadecimal */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for UART.
|
||||
*/
|
||||
class UART
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Print single character.
|
||||
*
|
||||
* @param c Character to print
|
||||
*/
|
||||
void print(char c);
|
||||
/**
|
||||
* @brief Print boolean value.
|
||||
*
|
||||
* @param b Boolean value
|
||||
*/
|
||||
void print(bool b);
|
||||
/**
|
||||
* @brief Print floating point value.
|
||||
*
|
||||
* @param d Floating point value
|
||||
*/
|
||||
void print(double d);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num 8-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(uint8_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num 16-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(uint16_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num 32-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(uint32_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num Integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(size_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print c-string.
|
||||
*
|
||||
* @param str Null terminated string
|
||||
*/
|
||||
void print(const char * str);
|
||||
/**
|
||||
* @brief Print string.
|
||||
*
|
||||
* @param str String buffer
|
||||
* @parma length String length
|
||||
*/
|
||||
void print(const char * str, size_t length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Print new-line.
|
||||
*/
|
||||
void println();
|
||||
/**
|
||||
* @brief Print single character followed by a new-line.
|
||||
*
|
||||
* @param c Character to print
|
||||
*/
|
||||
void println(char c);
|
||||
/**
|
||||
* @brief Print boolean value followed by a new-line.
|
||||
*
|
||||
* @param b Boolean value
|
||||
*/
|
||||
void println(bool b);
|
||||
/**
|
||||
* @brief Print floating point value followed by a new-line.
|
||||
*
|
||||
* @param d Floating point value
|
||||
*/
|
||||
void println(double d);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num 8-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(uint8_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num 16-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(uint16_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num 32-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(uint32_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num Integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(size_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print c-string followed by a new-line.
|
||||
*
|
||||
* @param str Null terminated string
|
||||
*/
|
||||
void println(const char * str);
|
||||
/**
|
||||
* @brief Print string followed by a new-line.
|
||||
*
|
||||
* @param str String buffer
|
||||
* @parma length String length
|
||||
*/
|
||||
void println(const char * str, size_t length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write buffer to UART.
|
||||
*
|
||||
* @param buffer Source buffer
|
||||
* @param size Number of bytes in buffer
|
||||
*/
|
||||
virtual void write(const uint8_t * buffer, size_t size) = 0;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Print unsigned integer in selected base.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param base Integer base
|
||||
* @param fmt printf format string for base 10
|
||||
* @param size Size of value in bytes
|
||||
*/
|
||||
void printBase(uintmax_t value, IntegerBase base, const char * fmt, size_t size);
|
||||
/**
|
||||
* @brief Print unsigned integer in base 10.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param fmt printf format string
|
||||
*/
|
||||
void printDec(uintmax_t value, const char * fmt);
|
||||
/**
|
||||
* @brief Print unsigned integer in base 2.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param digits Number of digits to print
|
||||
*/
|
||||
void printBin(uintmax_t value, size_t digits);
|
||||
/**
|
||||
* @brief Print unsigned integer in base 16.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param digits Number of digits to print
|
||||
*/
|
||||
void printHex(uintmax_t value, size_t digits);
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_UART_HPP
|
Reference in New Issue
Block a user