mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-12 01:25:59 +00:00
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#ifndef STA_RASPI_I2C_HPP
|
|
#define STA_RASPI_I2C_HPP
|
|
|
|
#include <sta/config.hpp>
|
|
#ifdef STA_PLATFORM_RASPI
|
|
|
|
#include <sta/bus/i2c/i2c.hpp>
|
|
#include <sta/bus/i2c/device.hpp>
|
|
|
|
#include <linux/i2c-dev.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
namespace sta
|
|
{
|
|
enum class I2CNode {
|
|
DEV_1,
|
|
DEV_2
|
|
};
|
|
|
|
class RaspiI2C : public I2C
|
|
{
|
|
public:
|
|
RaspiI2C(I2CNode node, Mutex * mutex=nullptr, bool persistent_open=false);
|
|
~RaspiI2C();
|
|
|
|
void transfer(uint8_t value) override;
|
|
void transfer16(uint16_t value) override;
|
|
void transfer(const uint8_t * buffer, size_t size) override;
|
|
void receive(uint8_t * buffer, size_t size) override;
|
|
|
|
void acquire() override;
|
|
void release() override;
|
|
|
|
void fill(uint8_t value, size_t count) override;
|
|
private:
|
|
char * i2cdev_;
|
|
int i2cfd_;
|
|
bool open_ = false;
|
|
const bool persistent_open_;
|
|
};
|
|
|
|
class RaspiI2CDevice : public I2CDevice
|
|
{
|
|
RaspiI2CDevice(RaspiI2C * intf, uint16_t address_10bit, Mutex* mutex=nullptr, bool master=false, bool blocking=true);
|
|
};
|
|
} // namespace sta
|
|
|
|
#endif // STA_PLATFORM_RASPI
|
|
|
|
#endif // STA_I2C_HPP
|