-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi2cdevice.h
More file actions
42 lines (36 loc) · 1.2 KB
/
Copy pathi2cdevice.h
File metadata and controls
42 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef LIBESP_I2CDEVICE_H
#define LIBESP_I2CDEVICE_H
#include "i2cbus.h"
namespace libesp {
class I2CDevice {
public:
ErrorType shutdown();
ErrorType transmit(const uint8_t *data, size_t len, int timeout_ms);
ErrorType receive(uint8_t *data, size_t len, int timeout_ms);
ErrorType transmitReceive(const uint8_t *tx_data, size_t tx_len, uint8_t *rx_data, size_t rx_len, int timeout_ms);
virtual ~I2CDevice();
I2CBus *getBus() {return MyBus;}
const i2c_device_config_t &getDeviceConfig() const {return DevCfg;}
const i2c_master_dev_handle_t &getDeviceHandle() const {return DevHandle;}
protected:
I2CDevice(I2CBus *bus, const i2c_master_dev_handle_t &handle, const i2c_device_config_t &devcfg);
virtual ErrorType onShutdown() = 0;
protected:
I2CBus *MyBus;
i2c_master_dev_handle_t DevHandle;
i2c_device_config_t DevCfg;
};
class I2CMaster : public I2CDevice {
public:
virtual ~I2CMaster();
static const char *LOGTAG;
static const uint32_t MILLIS_DEFAULT_WAIT = 5;
protected:
I2CMaster(I2CBus *bus, const i2c_master_dev_handle_t &handle, const i2c_device_config_t &devcfg, SemaphoreHandle_t semaphore);
virtual ErrorType onShutdown();
private:
SemaphoreHandle_t MySemaphore;
friend class I2CBus;
};
}
#endif