sta-core/include/sta/bus/device.hpp
2024-01-07 23:23:35 +01:00

89 lines
2.0 KiB
C++

#ifndef STA_CORE_BUS_SERIAL_DEVICE_HPP
#define STA_CORE_BUS_SERIAL_DEVICE_HPP
#include <sta/bus/interface.hpp>
namespace sta
{
/**
* @brief Abstract device for serial communication.
*/
class Device
{
public:
/**
* @param intf %SPI hardware interface
*/
Device(Interface * intf);
/**
* @brief Start transmission with device.
*
* Must be called before any I/O operations.
*/
void beginTransmission();
/**
* @brief End transmission with device.
*
* Must be called after last I/O operation.
*/
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.
*
* @param buffer Source buffer
* @param size Number of bytes to transfer
*/
void transfer(const uint8_t * buffer, size_t size);
/**
* @brief Read incoming data to buffer.
*
* @param buffer Destination buffer
* @param size Number of bytes to read
*/
void receive(uint8_t * buffer, size_t size);
/**
* @brief Send byte value repeatedly.
*
* @param value 8-bit value to repeat
* @param count Number of repetitions
*/
void fill(uint8_t value, size_t count);
protected:
/**
* @brief Activate device..
*/
virtual void select() = 0;
/**
* @brief Deactivate device..
*/
virtual void deselect() = 0;
private:
Interface * intf_;
bool selected_ = false;
};
} // namespace sta
#endif // STA_CORE_BUS_SERIAL_DEVICE_HPP