2024-05-01 13:23:44 +02:00

64 lines
1.6 KiB
C++

#ifndef STA_CORE_I2C_I2C_HPP
#define STA_CORE_I2C_I2C_HPP
#include <sta/bus/interface.hpp>
#include <sta/mutex.hpp>
#include <cstddef>
#include <cstdint>
namespace sta
{
/**
* @brief Possible errors that can occur during transmission-
*
*/
enum I2CError
{
SUCCESS,
ACK_FAILURE,
NACK,
DATA_TOO_LONG,
TIMEOUT,
BUS_ERROR,
ARBITRATION_LOSS,
};
/**
* @brief Interface class for %I2C hardware.
*
* Represents a single %I2C bus that can be shared by multiple devices.
*
* @ingroup sta_core_i2c
*/
class I2C : public Interface
{
public:
/**
* @brief Construct a new %I2C object.
*
* @param mutex Mutex object for managing shared access. Pass nullptr for no access control.
*/
I2C(Mutex * mutex=nullptr);
/**
* @brief Specify the mode of communication via the bus.
*
* @param address The peripheral's address to communicate with.
* @param master Whether the mcu is a master or slave.
* @param blocking Whether to use blocking or non-blocking transmits / receives.
*/
void setSettings(uint16_t address, bool master, bool blocking);
protected:
/// @brief The peripheral's address to communicate with.
uint16_t address_;
/// @brief Whether the mcu is a master or slave.
bool master_;
/// @brief Whether to use blocking or non-blocking transmits / receives.
bool blocking_;
};
} // namespace sta
#endif // STA_CORE_I2C_I2C_HPP