Updated debug printing for raspi + added persistent_open setting for raspi spi

This commit is contained in:
Dario
2023-05-16 14:58:09 +01:00
parent 21cb870014
commit 0bc924bba2
14 changed files with 529 additions and 93 deletions

View File

@@ -0,0 +1,49 @@
#ifndef STA_CORE_DEBUG_PRINTF_HPP
#define STA_CORE_DEBUG_PRINTF_HPP
#include <sta/config.hpp>
// Determine if module should be enabled
// Condition 1: STA_DEBUG_PRINTF is defined
// Condition 2:
// STA_DEBUG_PRINTF_FORCE is defined
// or
// DEBUG is defined but not NDEBUG
#ifdef STA_DEBUG_PRINTF
# ifdef STA_DEBUG_PRINTF_FORCE
# define STA_DEBUG_SERIAL_ENABLED
# else // !STA_DEBUG_PRINTF_FORCE
# if defined(DEBUG) && !defined(NDEBUG)
# define STA_DEBUG_PRINTF_ENABLED
# endif // DEBUG && !NDEBUG
# endif // !STA_DEBUG_PRINTF_FORCE
#endif // STA_DEBUG_PRINTF
#if defined(STA_DEBUG_PRINTF_ENABLED) || defined(DOXYGEN)
#include <sta/printable.hpp>
/**
* @brief Print debug output.
*
* @param ... See @ref sta::PrintableUART::print
*
* @ingroup sta_core_debug
*/
# define STA_DEBUG_PRINT(...) sta::print(__VA_ARGS__)
/**
* @brief Print debug output followed by new-line to UART.
*
* @param ... See @ref sta::PrintableUART::println
*
* @ingroup sta_core_debug
*/
# define STA_DEBUG_PRINTLN(...) sta::println(__VA_ARGS__)
#else // !STA_DEBUG_PRINTF_ENABLED
# define STA_DEBUG_PRINT(...) ((void)0)
# define STA_DEBUG_PRINTLN(...) ((void)0)
#endif // !STA_DEBUG_PRINTF_ENABLED
#endif // STA_CORE_DEBUG_PRINTF_HPP

206
include/sta/printable.hpp Normal file
View File

@@ -0,0 +1,206 @@
/**
* @file
* @brief Printable UART interface definition.
*/
#ifndef STA_CORE_PRINTABLE_HPP
#define STA_CORE_PRINTABLE_HPP
#include <sta/printf.hpp>
#include <cstddef>
#include <cstdint>
namespace sta
{
/**
* @brief Integer representation.
*
* @ingroup sta_core
*/
enum class IntegerBase
{
DEC, /**< Decimal */
BIN, /**< Binary */
HEX /**< Hexadecimal */
};
/**
* @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
* @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 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
* @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);
/**
* @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_CORE_PRINTABLE_HPP

View File

@@ -77,13 +77,6 @@ namespace sta
* @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.
*
@@ -142,13 +135,6 @@ namespace sta
* @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.
*

View File

@@ -15,7 +15,7 @@
namespace sta
{
class RaspiGpioPin : GpioPin
class RaspiGpioPin : public GpioPin
{
public:
enum class GpioMode {
@@ -31,18 +31,18 @@ namespace sta
void setState(GpioPinState state) override;
static RaspiGpioPin DUMMY_GPIO;
static RaspiGpioPin * DUMMY_GPIO;
private:
uint8_t pin_;
GpioMode mode_;
};
class DummyGpioPin : RaspiGpioPin {
class DummyGpioPin : public RaspiGpioPin {
DummyGpioPin();
void setState(GpioPinState state) override;
}
};
} // namespace sta
#endif // STA_RASPI_GPIO_ENABLED

View File

@@ -2,7 +2,7 @@
#define STA_CORE_RASPI_HAL_HPP
#include <wiringPi.h>
#include <wiringPiI2C.h>
#include <stdio.h>
#include <sys/ioctl.h>
#endif //STA_CORE_RASPI_HAL_HPP

View File

@@ -0,0 +1,13 @@
/**
* @file
* @brief Common configuration for Raspberry Pi MCUs
*/
#ifndef STA_CORE_RASPI_MCU_COMMON_HPP
#define STA_CORE_RASPI_MCU_COMMON_HPP
#define STA_MCU_LITTLE_ENDIAN
// Enable STM32 platform
#define STA_PLATFORM_RASPI
#endif // STA_CORE_RASPI_MCU_COMMON_HPP

View File

@@ -9,10 +9,15 @@
namespace sta
{
enum class SPINode {
DEV_0_0,
DEV_0_1
};
class RaspiSPI : public SPI
{
public:
RaspiSPI(const char * dev, const SPISettings & settings, Mutex * mutex = nullptr);
RaspiSPI(SPINode node, const SPISettings & settings, Mutex * mutex = nullptr, bool persistent_open = true);
~RaspiSPI();
void transfer(uint8_t value) override;
@@ -30,18 +35,17 @@ namespace sta
char * spidev_;
int spifd_;
bool open_;
const bool persistent_open_;
void update_setting(int setting, int value);
int get_setting(int setting, void * rslt_ptr);
void update_settings();
};
class RaspiSPIDevice : SPIDevice
class RaspiSPIDevice : public SPIDevice
{
public:
RaspiSPIDevice(RaspiSPI * intf);
void select() override;
void deselect() override;
};
} // namespace sta

View File

@@ -93,7 +93,7 @@ namespace sta
*
* @return SPI settings
*/
const SpiSettings & settings() const;
const SPISettings & settings() const;
/**