mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-06 02:27:33 +00:00
Added I2C support for raspi & first rework of debugging
This commit is contained in:
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
|
112
include/sta/bus/spi/settings.hpp
Normal file
112
include/sta/bus/spi/settings.hpp
Normal file
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief SPI bus settings.
|
||||
*/
|
||||
#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
|
||||
{
|
||||
/**
|
||||
* @ingroup sta_core_spi
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief %SPI clock polarity.
|
||||
*/
|
||||
enum class SPIClkPolarity
|
||||
{
|
||||
LOW, /**< Low idle clock */
|
||||
HIGH /**< High idle clock */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief %SPI clock phase.
|
||||
*/
|
||||
enum class SPIClkPhase
|
||||
{
|
||||
EDGE_1, /**< Sample on first edge, shift out on second edge */
|
||||
EDGE_2 /**< Shift out on first edge, sample on second edge */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief %SPI clock mode.
|
||||
*/
|
||||
enum class SPIMode
|
||||
{
|
||||
MODE_0, /**< Low idle clock, sample on rising edge, shift out on falling edge */
|
||||
MODE_1, /**< Low idle clock, sample on falling edge, shift out on rising edge */
|
||||
MODE_2, /**< High idle clock, sample on rising edge, shift out on falling edge */
|
||||
MODE_3 /**< High idle clock, sample on falling edge, shift out on rising edge */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief %SPI data size.
|
||||
*/
|
||||
enum class SPIDataSize
|
||||
{
|
||||
SIZE_8, /**< 8-bit data size */
|
||||
SIZE_16 /**< 16-bit data size */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief %SPI bit order.
|
||||
*/
|
||||
enum class SPIBitOrder
|
||||
{
|
||||
MSB, /**< Send most significant bit first */
|
||||
LSB /**< Send least significant bit first */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief %SPI settings.
|
||||
*/
|
||||
struct SPISettings
|
||||
{
|
||||
SPIMode mode; /**< %SPI clock mode */
|
||||
SPIDataSize dataSize; /**< %SPI data size */
|
||||
SPIBitOrder bitOrder; /**< %SPI bit order */
|
||||
uint32_t clkSpeed; /**< %SPI clock speed */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get %SPI clock polarity from clock mode.
|
||||
*
|
||||
* @param mode %SPI clock mode
|
||||
* @return %SPI clock polarity
|
||||
*/
|
||||
SPIClkPolarity getSPIClkPolarity(SPIMode mode);
|
||||
/**
|
||||
* @brief Get %SPI clock phase from clock mode.
|
||||
*
|
||||
* @param mode %SPI clock mode
|
||||
* @return %SPI clock phase
|
||||
*/
|
||||
SPIClkPhase getSPIClkPhase(SPIMode mode);
|
||||
/**
|
||||
* @brief Get %SPI clock mode from clock phase and polarity.
|
||||
*
|
||||
* @param polarity %SPI clock polarity
|
||||
* @param phase %SPI clock phase
|
||||
* @return %SPI clock mode
|
||||
*/
|
||||
SPIMode getSPIMode(SPIClkPolarity polarity, SPIClkPhase phase);
|
||||
|
||||
|
||||
/** @} */
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_CORE_SPI_SETTINGS_HPP
|
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
|
Reference in New Issue
Block a user