mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
First reworks for debugging
This commit is contained in:
parent
e7ddbbf365
commit
96d94edc52
@ -5,6 +5,8 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
|
||||
|
||||
enum class UARTMode
|
||||
{
|
||||
RX,
|
||||
|
@ -9,7 +9,7 @@ namespace sta
|
||||
class UART : public Interface
|
||||
{
|
||||
public:
|
||||
UART(const UARTSettings & settings, Mutex * mutex=nullptr);
|
||||
UART(Mutex * mutex=nullptr);
|
||||
|
||||
/**
|
||||
* @brief Get %UART interface settings.
|
||||
@ -22,4 +22,4 @@ namespace sta
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_CORE_UART_UART_HPP
|
||||
#endif // STA_CORE_UART_UART_HPP
|
||||
|
40
include/sta/debugging.hpp
Normal file
40
include/sta/debugging.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef STA_CORE_DEBUGGING_HPP
|
||||
#define STA_CORE_DEBUGGING_HPP
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_DEBUGGING_ENABLED
|
||||
|
||||
#include <sta/printable.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
extern Printable * Debug;
|
||||
} // namespace sta
|
||||
|
||||
|
||||
/**
|
||||
* @brief Debug print message.
|
||||
*
|
||||
* @param ... See @ref sta::PrintableUART::print
|
||||
*
|
||||
* @ingroup sta_core_debug
|
||||
*/
|
||||
# define STA_DEBUG_PRINT(...) sta::Debug->print(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Debug print message followed by new-line to UART.
|
||||
*
|
||||
* @param ... See @ref sta::PrintableUART::println
|
||||
*
|
||||
* @ingroup sta_core_debug
|
||||
*/
|
||||
# define STA_DEBUG_PRINTLN(...) sta::Debug->println(__VA_ARGS__)
|
||||
|
||||
#else // !STA_DEBUGGING_ENABLED
|
||||
|
||||
# define STA_DEBUG_PRINT(...) ((void)0)
|
||||
# define STA_DEBUG_PRINTLN(...) ((void)0)
|
||||
|
||||
#endif // STA_DEBUGGING_ENABLED
|
||||
|
||||
#endif // STA_CORE_DEBUGGING_HPP
|
@ -35,7 +35,8 @@ namespace sta
|
||||
|
||||
class STM32I2CDevice : public I2CDevice
|
||||
{
|
||||
STM32I2CDevice();
|
||||
public:
|
||||
STM32I2CDevice(STM32I2C * intf, int address, bool master=true, bool blocking=true);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#if defined(STA_STM32_UART_ENABLED) || defined(DOXYGEN)
|
||||
|
||||
#include <sta/uart.hpp>
|
||||
#include <sta/bus/uart/uart.hpp>
|
||||
|
||||
|
||||
/**
|
||||
@ -41,10 +41,15 @@ namespace sta
|
||||
/**
|
||||
* @param handle STM32 HAL handle
|
||||
*/
|
||||
STM32UART(UART_HandleTypeDef * handle);
|
||||
STM32UART(UART_HandleTypeDef * handle, Mutex * mutex);
|
||||
|
||||
void write(const uint8_t * buffer, size_t size) override;
|
||||
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;
|
||||
private:
|
||||
UART_HandleTypeDef * handle_; /**< STM32 HAL handle */
|
||||
};
|
@ -25,6 +25,7 @@ namespace sta
|
||||
|
||||
class Printable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Print single character.
|
||||
*
|
||||
@ -188,4 +189,4 @@ namespace sta
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_CORE_PRINTABLE_HPP
|
||||
#endif // STA_CORE_PRINTABLE_HPP
|
||||
|
@ -1,61 +0,0 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief UART interface definition.
|
||||
*/
|
||||
#ifndef STA_CORE_UART_HPP
|
||||
#define STA_CORE_UART_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup sta_core_uart UART
|
||||
* @ingroup sta_core
|
||||
* @brief UART interface.
|
||||
*/
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Interface for %UART.
|
||||
*
|
||||
* @ingroup sta_core_uart
|
||||
*/
|
||||
class UART
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @brief Write unsigned integer to %UART.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
*/
|
||||
void write(uint32_t value);
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_CORE_UART_HPP
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
UART::UART(const UARTSettings & settings, Mutex * mutex)
|
||||
: Interface{mutex}, settings_{settings}
|
||||
UART::UART(Mutex * mutex)
|
||||
: Interface{mutex}
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
#ifdef STA_PLATFORM_STM32
|
||||
|
||||
#include <sta/stm32/uart.hpp>
|
||||
#include <sta/devices/stm32/bus/uart.hpp>
|
||||
|
||||
#include <usart.h>
|
||||
// #include <usart.h>
|
||||
|
||||
// Set platform UART alias
|
||||
using PlatformUART = sta::STM32UART;
|
||||
|
@ -119,4 +119,10 @@ namespace sta
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
STM32I2CDevice::STM32I2CDevice(STM32I2C * intf, int address, bool master, bool blocking)
|
||||
: I2CDevice(intf, address, master, blocking)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace sta
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <sta/devices/stm32/spi.hpp>
|
||||
#include <sta/devices/stm32/bus/spi.hpp>
|
||||
#ifdef STA_STM32_SPI_ENABLED
|
||||
|
||||
#include <sta/assert.hpp>
|
58
src/devices/stm32/bus/uart.cpp
Normal file
58
src/devices/stm32/bus/uart.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include <sta/devices/stm32/bus/uart.hpp>
|
||||
#ifdef STA_STM32_UART_ENABLED
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
STM32UART::STM32UART(UART_HandleTypeDef * handle, Mutex * mutex)
|
||||
: UART{mutex}, handle_{handle}
|
||||
{
|
||||
STA_ASSERT(handle != nullptr);
|
||||
}
|
||||
|
||||
void STM32UART::transfer(uint8_t value)
|
||||
{
|
||||
HAL_UART_Transmit(handle_, &value, 1, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
void STM32UART::transfer16(uint16_t value)
|
||||
{
|
||||
HAL_UART_Transmit(handle_, reinterpret_cast<uint8_t *>(&value), 2, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
void STM32UART::transfer(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(buffer != nullptr);
|
||||
|
||||
HAL_UART_Transmit(handle_, const_cast<uint8_t *>(buffer), size, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
void STM32UART::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size)
|
||||
{
|
||||
// IS THIS A THING HERE?
|
||||
}
|
||||
|
||||
void STM32UART::receive(uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(buffer != nullptr);
|
||||
|
||||
HAL_UART_Receive(handle_, buffer, size, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
void STM32UART::fill(uint8_t value, size_t count)
|
||||
{
|
||||
// Initialize a buffer of size count and fill it with the value.
|
||||
uint8_t *buffer = new uint8_t[count];
|
||||
memset(buffer, value, count);
|
||||
|
||||
// Transfer the buffer via the bus.
|
||||
transfer(buffer, count);
|
||||
|
||||
delete [] buffer;
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_STM32_UART_ENABLED
|
@ -1,25 +0,0 @@
|
||||
#include <sta/devices/stm32/uart.hpp>
|
||||
#ifdef STA_STM32_UART_ENABLED
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
STM32UART::STM32UART(UART_HandleTypeDef * handle)
|
||||
: handle_{handle}
|
||||
{
|
||||
STA_ASSERT(handle != nullptr);
|
||||
}
|
||||
|
||||
|
||||
void STM32UART::write(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(buffer != nullptr);
|
||||
|
||||
HAL_UART_Transmit(handle_, const_cast<uint8_t *>(buffer), size, HAL_MAX_DELAY);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_STM32_UART_ENABLED
|
28
src/uart.cpp
28
src/uart.cpp
@ -1,28 +0,0 @@
|
||||
#include <sta/uart.hpp>
|
||||
|
||||
#include <sta/printf.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
void UART::write(uint8_t value)
|
||||
{
|
||||
// TODO Handle endian-ness
|
||||
write(&value, 1);
|
||||
}
|
||||
|
||||
void UART::write(uint16_t value)
|
||||
{
|
||||
// TODO Handle endian-ness
|
||||
write(reinterpret_cast<uint8_t *>(&value), sizeof(value));
|
||||
}
|
||||
|
||||
void UART::write(uint32_t value)
|
||||
{
|
||||
// TODO Handle endian-ness
|
||||
write(reinterpret_cast<uint8_t *>(&value), sizeof(value));
|
||||
}
|
||||
} // namespace sta
|
Loading…
x
Reference in New Issue
Block a user