/** * @file * @brief SPI bus software interface. */ #ifndef STA_CORE_SPI_SPI_HPP #define STA_CORE_SPI_SPI_HPP #include #include #include #include #include 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 Send and receive data simultaneously. * * @param txBuffer Send buffer * @param rxBuffer Receive buffer * @param size Number of bytes to transfer */ virtual bool transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) = 0; /** * @brief Write data to a specific memory address of the peripheral. * * @param regAddr The memory address. * @param buffer The buffer of data to write to the address * @param size The number of bytes to write to the peripheral. */ bool writeMemory(uint8_t regAddr, const uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) override; /** * @brief Read data from a specific memory address of the peripheral. * * @param regAddr The memory address. * @param buffer The buffer of data to write the received data to. * @param size The number of bytes to receive from the peripheral. */ bool readMemory(uint8_t regAddr, uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) override; /** * @brief Get %SPI interface settings. * * @return %SPI settings */ const SPISettings & settings(); private: SPISettings settings_; /**< %SPI settings */ }; } // namespace sta #endif // STA_CORE_SPI_SPI_HPP