43 lines
1.2 KiB
C++

#ifndef STA_CORE_STM32_I2C_HPP
#define STA_CORE_STM32_I2C_HPP
#include <sta/config.hpp>
#ifdef STA_PLATFORM_STM32
# include <sta/devices/stm32/hal.hpp>
# ifdef HAL_I2C_MODULE_ENABLED
# define STA_STM32_I2C_ENABLED
# endif // HAL_SPI_MODULE_ENABLED
#endif // STA_PLATFORM_STM32
#ifdef STA_STM32_I2C_ENABLED
#include <sta/bus/i2c/i2c.hpp>
#include <sta/bus/i2c/device.hpp>
namespace sta
{
class STM32I2C : public I2C
{
public:
STM32I2C(I2C_HandleTypeDef * handle, Mutex * mutex=nullptr);
bool transfer(uint8_t value, uint32_t timeout = STA_MAX_TIMEOUT) override;
bool transfer16(uint16_t value, uint32_t timeout = STA_MAX_TIMEOUT) override;
bool transfer(const uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) override;
bool receive(uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) override;
bool fill(uint8_t value, size_t count, uint32_t timeout = STA_MAX_TIMEOUT) override;
private:
I2C_HandleTypeDef * handle_;
};
class STM32I2CDevice : public I2CDevice
{
public:
STM32I2CDevice(STM32I2C * intf, int address, bool master=true, bool blocking=true);
};
}
#endif // STA_STM32_I2C_ENABLED
#endif // STA_CORE_STM32_I2C_HPP