2024-01-07 23:23:35 +01:00

49 lines
1.3 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 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