mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-05 18:21:54 +00:00
Added I2C support for raspi & first rework of debugging
This commit is contained in:
@@ -12,9 +12,9 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <sta/can/filter.hpp>
|
||||
#include <sta/can/headers.hpp>
|
||||
#include <sta/can/iter.hpp>
|
||||
#include <sta/bus/can/filter.hpp>
|
||||
#include <sta/bus/can/headers.hpp>
|
||||
#include <sta/bus/can/iter.hpp>
|
||||
|
||||
|
||||
namespace sta
|
@@ -5,7 +5,7 @@
|
||||
#ifndef STA_CORE_CAN_FILTER_HPP
|
||||
#define STA_CORE_CAN_FILTER_HPP
|
||||
|
||||
#include <sta/can/id.hpp>
|
||||
#include <sta/bus/can/id.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
@@ -5,7 +5,7 @@
|
||||
#ifndef STA_CORE_CAN_HEADERS_HPP
|
||||
#define STA_CORE_CAN_HEADERS_HPP
|
||||
|
||||
#include <sta/can/id.hpp>
|
||||
#include <sta/bus/can/id.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
@@ -5,8 +5,8 @@
|
||||
#ifndef STA_CORE_CAN_SUBSCRIBABLE_HPP
|
||||
#define STA_CORE_CAN_SUBSCRIBABLE_HPP
|
||||
|
||||
#include <sta/can/filter.hpp>
|
||||
#include <sta/can/headers.hpp>
|
||||
#include <sta/bus/can/filter.hpp>
|
||||
#include <sta/bus/can/headers.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
@@ -96,7 +96,7 @@ namespace sta
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#include <sta/can/subscribable.tpp>
|
||||
#include <sta/bus/can/subscribable.tpp>
|
||||
|
||||
|
||||
#endif // STA_CORE_CAN_SUBSCRIBABLE_HPP
|
||||
#endif // STA_CORE_CAN_SUBSCRIBABLE_HPP
|
@@ -1,33 +1,21 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief SPI bus peripheral device.
|
||||
*/
|
||||
#ifndef STA_CORE_SPI_DEVICE_HPP
|
||||
#define STA_CORE_SPI_DEVICE_HPP
|
||||
|
||||
#include <sta/gpio_pin.hpp>
|
||||
#include <sta/spi/spi.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#ifndef STA_CORE_BUS_SERIAL_DEVICE_HPP
|
||||
#define STA_CORE_BUS_SERIAL_DEVICE_HPP
|
||||
|
||||
#include <sta/bus/interface.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Peripheral device connected via SPI.
|
||||
*
|
||||
* @ingroup sta_core_spi
|
||||
*/
|
||||
class SPIDevice
|
||||
* @brief Abstract device for serial communication.
|
||||
*/
|
||||
class Device
|
||||
{
|
||||
public:
|
||||
/**
|
||||
/**
|
||||
* @param intf %SPI hardware interface
|
||||
* @param csPin Chip select pin
|
||||
*/
|
||||
SPIDevice(SPI * intf, GpioPin * csPin);
|
||||
|
||||
Device(Interface * intf);
|
||||
|
||||
/**
|
||||
* @brief Start transmission with device.
|
||||
@@ -35,6 +23,7 @@ namespace sta
|
||||
* Must be called before any I/O operations.
|
||||
*/
|
||||
void beginTransmission();
|
||||
|
||||
/**
|
||||
* @brief End transmission with device.
|
||||
*
|
||||
@@ -42,19 +31,20 @@ namespace sta
|
||||
*/
|
||||
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 value);
|
||||
|
||||
/**
|
||||
* @brief Send data from buffer.
|
||||
*
|
||||
@@ -62,6 +52,7 @@ namespace sta
|
||||
* @param size Number of bytes to transfer
|
||||
*/
|
||||
void transfer(const uint8_t * buffer, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Send and receive data simultaneously.
|
||||
*
|
||||
@@ -70,6 +61,7 @@ namespace sta
|
||||
* @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.
|
||||
*
|
||||
@@ -78,7 +70,6 @@ namespace sta
|
||||
*/
|
||||
void receive(uint8_t * buffer, size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send byte value repeatedly.
|
||||
*
|
||||
@@ -87,29 +78,21 @@ namespace sta
|
||||
*/
|
||||
void fill(uint8_t value, size_t count);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Activate device..
|
||||
*/
|
||||
virtual void select() = 0;
|
||||
|
||||
/**
|
||||
* @brief Get %SPI interface settings.
|
||||
*
|
||||
* @return SPI settings
|
||||
* @brief Deactivate device..
|
||||
*/
|
||||
const SPISettings & settings() const;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Activate device via CS pin.
|
||||
*/
|
||||
void select();
|
||||
/**
|
||||
* @brief Deactivate device via CS pin.
|
||||
*/
|
||||
void deselect();
|
||||
virtual void deselect() = 0;
|
||||
|
||||
private:
|
||||
SPI * intf_; /**< %SPI hardware interface */
|
||||
GpioPin * csPin_; /**< Chip select pin */
|
||||
Interface * intf_;
|
||||
bool selected_ = false;
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_CORE_SPI_DEVICE_HPP
|
||||
#endif // STA_CORE_BUS_SERIAL_DEVICE_HPP
|
37
include/sta/bus/i2c/device.hpp
Normal file
37
include/sta/bus/i2c/device.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef STA_CORE_I2C_DEVICE_HPP
|
||||
#define STA_CORE_I2C_DEVICE_HPP
|
||||
|
||||
#include <sta/bus/i2c/i2c.hpp>
|
||||
#include <sta/bus/device.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Peripheral device connected via I2c.
|
||||
*
|
||||
* @ingroup sta_core_i2c
|
||||
*/
|
||||
class I2cDevice : public Device
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param intf %I2C hardware interface
|
||||
* @param csPin The peripheral's address.
|
||||
*/
|
||||
I2cDevice(I2c * intf, int addr);
|
||||
|
||||
protected:
|
||||
void select() override;
|
||||
|
||||
void deselect() override;
|
||||
|
||||
private:
|
||||
int addr_; /**< device address */
|
||||
};
|
||||
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // STA_CORE_I2C_DEVICE_HPP
|
33
include/sta/bus/i2c/i2c.hpp
Normal file
33
include/sta/bus/i2c/i2c.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef STA_CORE_I2C_I2C_HPP
|
||||
#define STA_CORE_I2C_I2C_HPP
|
||||
|
||||
#include <sta/bus/interface.hpp>
|
||||
#include <sta/mutex.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Interface class for %I2C hardware.
|
||||
*
|
||||
* Represents a single %I2C bus that can be shared by multiple devices.
|
||||
*
|
||||
* @ingroup sta_core_i2c
|
||||
*/
|
||||
class I2c : public Interface
|
||||
{
|
||||
public:
|
||||
I2c(Mutex * mutex=nullptr);
|
||||
|
||||
/**
|
||||
* @brief Address selection for the I2C bus.
|
||||
*
|
||||
* @param address The address to select.
|
||||
*/
|
||||
virtual void selectAddress(uint16_t address) = 0;
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_CORE_I2C_I2C_HPP
|
@@ -1,35 +1,20 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief SPI bus software interface.
|
||||
*/
|
||||
#ifndef STA_CORE_SPI_SPI_HPP
|
||||
#define STA_CORE_SPI_SPI_HPP
|
||||
#ifndef STA_CORE_BUS_SERIAL_INTERFACE_HPP
|
||||
#define STA_CORE_BUS_SERIAL_INTERFACE_HPP
|
||||
|
||||
#include <sta/mutex.hpp>
|
||||
#include <sta/spi/settings.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Interface class for %SPI hardware.
|
||||
*
|
||||
* Represents a single %SPI bus that can be shared by multiple devices.
|
||||
*
|
||||
* @ingroup sta_core_spi
|
||||
*/
|
||||
class SPI
|
||||
* @brief Abstract interface for serial communication.
|
||||
*/
|
||||
class Interface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param settings %SPI bus settings
|
||||
* @param mutex Mutex object for managing shared access. Pass nullptr for no access control
|
||||
*/
|
||||
SPI(const SPISettings & settings, Mutex * mutex = nullptr);
|
||||
|
||||
Interface(Mutex * mutex);
|
||||
|
||||
/**
|
||||
* @brief Send single byte of data.
|
||||
@@ -66,7 +51,6 @@ namespace sta
|
||||
*/
|
||||
virtual void receive(uint8_t * buffer, size_t size) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send byte value repeatedly.
|
||||
*
|
||||
@@ -75,14 +59,6 @@ namespace sta
|
||||
*/
|
||||
virtual void fill(uint8_t value, size_t count) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get %SPI interface settings.
|
||||
*
|
||||
* @return %SPI settings
|
||||
*/
|
||||
const SPISettings & settings();
|
||||
|
||||
/**
|
||||
* @brief Acquire usage rights to use the interface.
|
||||
*
|
||||
@@ -96,11 +72,15 @@ namespace sta
|
||||
*/
|
||||
virtual void release();
|
||||
|
||||
/**
|
||||
* @returns true if the interface has been aquired.
|
||||
*/
|
||||
bool isAquired();
|
||||
private:
|
||||
SPISettings settings_; /**< %SPI settings */
|
||||
Mutex * mutex_; /**< Mutex object */
|
||||
Mutex * mutex_;
|
||||
bool aquired_ = false;
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_CORE_SPI_SPI_HPP
|
||||
#endif // STA_CORE_BUS_SERIAL_INTERFACE_HPP
|
51
include/sta/bus/spi/device.hpp
Normal file
51
include/sta/bus/spi/device.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief SPI bus peripheral device.
|
||||
*/
|
||||
#ifndef STA_CORE_SPI_DEVICE_HPP
|
||||
#define STA_CORE_SPI_DEVICE_HPP
|
||||
|
||||
#include <sta/bus/device.hpp>
|
||||
#include <sta/bus/spi/spi.hpp>
|
||||
#include <sta/gpio_pin.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Peripheral device connected via SPI.
|
||||
*
|
||||
* @ingroup sta_core_spi
|
||||
*/
|
||||
class SPIDevice : public Device
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param intf %SPI hardware interface
|
||||
* @param csPin Chip select pin
|
||||
*/
|
||||
SPIDevice(SPI * intf, GpioPin * csPin);
|
||||
|
||||
/**
|
||||
* @brief Get %SPI interface settings.
|
||||
*
|
||||
* @return SPI settings
|
||||
*/
|
||||
const SPISettings & settings() const;
|
||||
|
||||
protected:
|
||||
void select() override;
|
||||
|
||||
void deselect() override;
|
||||
|
||||
private:
|
||||
SPI * intf_; /**< %SPI hardware interface */
|
||||
GpioPin * csPin_; /**< Chip select pin */
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_CORE_SPI_DEVICE_HPP
|
@@ -5,17 +5,14 @@
|
||||
#ifndef STA_CORE_SPI_SETTINGS_HPP
|
||||
#define STA_CORE_SPI_SETTINGS_HPP
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup sta_core_spi SPI
|
||||
* @ingroup sta_core
|
||||
* @brief SPI interface.
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
47
include/sta/bus/spi/spi.hpp
Normal file
47
include/sta/bus/spi/spi.hpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief SPI bus software interface.
|
||||
*/
|
||||
#ifndef STA_CORE_SPI_SPI_HPP
|
||||
#define STA_CORE_SPI_SPI_HPP
|
||||
|
||||
#include <sta/bus/interface.hpp>
|
||||
#include <sta/bus/spi/settings.hpp>
|
||||
#include <sta/mutex.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Interface class for %SPI hardware.
|
||||
*
|
||||
* Represents a single %SPI bus that can be shared by multiple devices.
|
||||
*
|
||||
* @ingroup sta_core_spi
|
||||
*/
|
||||
class SPI : public Interface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param settings %SPI bus settings
|
||||
* @param mutex Mutex object for managing shared access. Pass nullptr for no access control
|
||||
*/
|
||||
SPI(const SPISettings & settings, Mutex * mutex = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Get %SPI interface settings.
|
||||
*
|
||||
* @return %SPI settings
|
||||
*/
|
||||
const SPISettings & settings();
|
||||
|
||||
private:
|
||||
SPISettings settings_; /**< %SPI settings */
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_CORE_SPI_SPI_HPP
|
24
include/sta/bus/uart/settings.hpp
Normal file
24
include/sta/bus/uart/settings.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef STA_CORE_UART_SETTINGS_HPP
|
||||
#define STA_CORE_UART_SETTINGS_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
enum class UARTMode
|
||||
{
|
||||
RX,
|
||||
TX,
|
||||
RX_TX
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief %UART settings.
|
||||
*/
|
||||
struct UARTSettings
|
||||
{
|
||||
UARTMode mode;
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_CORE_UART_SETTINGS_HPP
|
25
include/sta/bus/uart/uart.hpp
Normal file
25
include/sta/bus/uart/uart.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef STA_CORE_UART_UART_HPP
|
||||
#define STA_CORE_UART_UART_HPP
|
||||
|
||||
#include <sta/bus/interface.hpp>
|
||||
#include <sta/bus/uart/settings.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
class UART : public Interface
|
||||
{
|
||||
public:
|
||||
UART(const UARTSettings & settings, Mutex * mutex=nullptr);
|
||||
|
||||
/**
|
||||
* @brief Get %UART interface settings.
|
||||
*
|
||||
* @return %UART settings
|
||||
*/
|
||||
const UARTSettings & settings();
|
||||
private:
|
||||
UARTSettings settings_; /**< %UART settings */
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_CORE_UART_UART_HPP
|
@@ -2,7 +2,7 @@
|
||||
#define STA_CONFIG
|
||||
|
||||
// Use the raspberry pi for this project.
|
||||
#include <sta/raspi/mcu/common.hpp>
|
||||
#include <sta/devices/raspi/mcu/common.hpp>
|
||||
|
||||
// #define DEBUG
|
||||
#define STA_PRINTF_USE_STDLIB
|
||||
|
52
include/sta/devices/raspi/bus/i2c.hpp
Normal file
52
include/sta/devices/raspi/bus/i2c.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef STA_RASPI_I2C_HPP
|
||||
#define STA_RASPI_I2C_HPP
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_PLATFORM_RASPI
|
||||
|
||||
#include <sta/bus/i2c/i2c.hpp>
|
||||
#include <sta/bus/i2c/device.hpp>
|
||||
|
||||
#include <linux/i2c-dev.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
enum class I2cNode {
|
||||
DEV_1,
|
||||
DEV_2
|
||||
};
|
||||
|
||||
class RaspiI2c : public I2c
|
||||
{
|
||||
public:
|
||||
RaspiI2c(I2cNode node, Mutex * mutex=nullptr, bool persistent_open=false);
|
||||
~RaspiI2c();
|
||||
|
||||
void transfer(uint8_t value) override;
|
||||
void transfer16(uint16_t value) override;
|
||||
void transfer(const uint8_t * buffer, size_t size) override;
|
||||
void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) override;
|
||||
void receive(uint8_t * buffer, size_t size) override;
|
||||
|
||||
void fill(uint8_t value, size_t count) override;
|
||||
|
||||
void selectAddress(uint16_t address) override;
|
||||
void acquire() override;
|
||||
void release() override;
|
||||
private:
|
||||
char * i2cdev_;
|
||||
int i2cfd_;
|
||||
bool open_ = false;
|
||||
const bool persistent_open_;
|
||||
};
|
||||
|
||||
class RaspiI2cDevice : public I2cDevice
|
||||
{
|
||||
RaspiI2cDevice(I2c * intf, uint16_t address_10bit, Mutex* mutex=nullptr, bool master=false, bool blocking=true);
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_PLATFORM_RASPI
|
||||
|
||||
#endif // STA_I2C_HPP
|
@@ -4,8 +4,8 @@
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_PLATFORM_RASPI
|
||||
|
||||
#include <sta/spi/device.hpp>
|
||||
#include <sta/spi/spi.hpp>
|
||||
#include <sta/bus/spi/device.hpp>
|
||||
#include <sta/bus/spi/spi.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
0
include/sta/devices/raspi/can.hpp
Normal file
0
include/sta/devices/raspi/can.hpp
Normal file
@@ -4,7 +4,7 @@
|
||||
// Only enable module on Raspi platform w/ HAL GPIO module enabled
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_PLATFORM_RASPI
|
||||
# include <sta/raspi/hal.hpp>
|
||||
# include <sta/devices/raspi/hal.hpp>
|
||||
# define STA_RASPI_GPIO_ENABLED
|
||||
#endif // STA_PLATFORM_RASPI
|
||||
|
43
include/sta/devices/template/delay.hpp
Normal file
43
include/sta/devices/template/delay.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file delay.hpp
|
||||
* @author <your name> (<you>@<your_domain>.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-06-13
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
* How to modify this file:
|
||||
* - Ctrl + F and replace "YOUR_DEVICE" with the appropriate name.
|
||||
*/
|
||||
#ifndef STA_CORE_YOUR_DEVICE_DELAY_HPP
|
||||
#define STA_CORE_YOUR_DEVICE_DELAY_HPP
|
||||
|
||||
// Only enable module on YOUR_DEVICE platform
|
||||
#include <sta/config.hpp>
|
||||
|
||||
|
||||
#if defined(STA_PLATFORM_YOUR_DEVICE) || defined(DOXYGEN)
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Millisecond delay.
|
||||
*
|
||||
* @param ms Milliseconds
|
||||
*/
|
||||
void delayMs(uint32_t ms);
|
||||
|
||||
/**
|
||||
* @brief Microsecond delay.
|
||||
*
|
||||
* @param us Microseconds
|
||||
*/
|
||||
void delayUs(uint32_t us);
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_PLATFORM_YOUR_DEVICE
|
||||
|
||||
#endif // STA_CORE_YOUR_DEVICE_DELAY_HPP
|
@@ -1,27 +0,0 @@
|
||||
#ifndef STA_I2C_HPP
|
||||
#define STA_I2C_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <sta/mutex.hpp>
|
||||
|
||||
namespace sta {
|
||||
class I2cDevice {
|
||||
protected:
|
||||
uint16_t address;
|
||||
Mutex* mutex;
|
||||
bool master;
|
||||
bool blocking;
|
||||
public:
|
||||
I2cDevice(uint16_t address_10bit, Mutex* mutex=nullptr, bool master=false, bool blocking=true);
|
||||
|
||||
virtual bool transmit(uint8_t* data, uint16_t size) = 0;
|
||||
|
||||
virtual bool receive(uint8_t* data, uint16_t size) = 0;
|
||||
|
||||
virtual void acquire();
|
||||
|
||||
virtual void release();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // STA_I2C_HPP
|
@@ -95,6 +95,14 @@
|
||||
# define STA_UNREACHABLE() __builtin_unreachable()
|
||||
#endif // !STA_UNREACHABLE
|
||||
|
||||
/**
|
||||
* @brief A macro for marking code as not implemented. Causes a program to
|
||||
* crash with the appropriate error message if the code is executed.
|
||||
*/
|
||||
#ifndef STA_NOT_IMPLEMENTED
|
||||
# define STA_NOT_IMPLEMENTED() throw "myFunction is not implemented yet.";
|
||||
#endif // !STA_NOT_IMPLEMENTED
|
||||
|
||||
/**
|
||||
* @brief Silencing compiler warnings for intended switch case fallthrough.
|
||||
*
|
||||
|
@@ -5,8 +5,6 @@
|
||||
#ifndef STA_CORE_PRINTABLE_HPP
|
||||
#define STA_CORE_PRINTABLE_HPP
|
||||
|
||||
#include <sta/printf.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
@@ -25,165 +23,168 @@ namespace sta
|
||||
HEX /**< Hexadecimal */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Print single character.
|
||||
*
|
||||
* @param c Character to print
|
||||
*/
|
||||
void print(char c);
|
||||
class Printable
|
||||
{
|
||||
/**
|
||||
* @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 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 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 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 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 32-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(uint32_t num, IntegerBase base = IntegerBase::DEC);
|
||||
|
||||
/**
|
||||
* @brief Print c-string.
|
||||
*
|
||||
* @param str Null terminated string
|
||||
*/
|
||||
void print(const char * str);
|
||||
/**
|
||||
* @brief Print c-string.
|
||||
*
|
||||
* @param str Null terminated string
|
||||
*/
|
||||
void print(const char * str);
|
||||
|
||||
/**
|
||||
* @brief Print string.
|
||||
*
|
||||
* @param str String buffer
|
||||
* @param length String length
|
||||
*/
|
||||
void print(const char * str, size_t length);
|
||||
/**
|
||||
* @brief Print string.
|
||||
*
|
||||
* @param str String buffer
|
||||
* @param length String length
|
||||
*/
|
||||
virtual void print(const char * str, size_t length) = 0;
|
||||
|
||||
/**
|
||||
* @brief Print new-line.
|
||||
*/
|
||||
void println();
|
||||
/**
|
||||
* @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 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 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 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 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 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 32-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(uint32_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 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
|
||||
* @param length String length
|
||||
*/
|
||||
void println(const char * str, size_t length);
|
||||
/**
|
||||
* @brief Print string followed by a new-line.
|
||||
*
|
||||
* @param str String buffer
|
||||
* @param length String length
|
||||
*/
|
||||
void println(const char * str, size_t length);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
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 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);
|
||||
/**
|
||||
* @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
|
||||
|
||||
|
||||
|
@@ -5,7 +5,8 @@
|
||||
#ifndef STA_CORE_PRINTABLE_UART_HPP
|
||||
#define STA_CORE_PRINTABLE_UART_HPP
|
||||
|
||||
#include <sta/uart.hpp>
|
||||
#include <sta/bus/uart/uart.hpp>
|
||||
#include <sta/printable.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -13,24 +14,12 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Integer representation.
|
||||
*
|
||||
* @ingroup sta_core
|
||||
*/
|
||||
enum class IntegerBase
|
||||
{
|
||||
DEC, /**< Decimal */
|
||||
BIN, /**< Binary */
|
||||
HEX /**< Hexadecimal */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Printable interface for UART.
|
||||
*
|
||||
* @ingroup sta_core
|
||||
*/
|
||||
class PrintableUART
|
||||
class PrintableUART : public Printable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -38,149 +27,14 @@ namespace sta
|
||||
*/
|
||||
PrintableUART(UART * intf);
|
||||
|
||||
/**
|
||||
* @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 c-string.
|
||||
*
|
||||
* @param str Null terminated string
|
||||
*/
|
||||
void print(const char * str);
|
||||
/**
|
||||
* @brief Print string.
|
||||
*
|
||||
* @param str String buffer
|
||||
* @param 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 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
|
||||
* @param length String length
|
||||
*/
|
||||
void println(const char * str, size_t length);
|
||||
|
||||
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);
|
||||
|
||||
void print(const char * str, size_t length) override;
|
||||
|
||||
private:
|
||||
UART * intf_;
|
||||
};
|
||||
|
@@ -19,10 +19,10 @@
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Interface for %UART.
|
||||
*
|
||||
* @ingroup sta_core_uart
|
||||
*/
|
||||
* @brief Interface for %UART.
|
||||
*
|
||||
* @ingroup sta_core_uart
|
||||
*/
|
||||
class UART
|
||||
{
|
||||
public:
|
||||
@@ -40,12 +40,14 @@ namespace sta
|
||||
* @param value Unsigned integer value
|
||||
*/
|
||||
void write(uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Write unsigned integer to %UART.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
*/
|
||||
void write(uint16_t value);
|
||||
|
||||
/**
|
||||
* @brief Write unsigned integer to %UART.
|
||||
*
|
||||
|
Reference in New Issue
Block a user