-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCA9548.h
58 lines (47 loc) · 1.28 KB
/
TCA9548.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <string>
//
// FILE: TCA9548.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2021-03-16
// PURPOSE: Library for TCA9548 I2C multiplexer
//
// URL: https://github.com/RobTillaart/TCA9548
//
// Adapted for rpi PA0PHH
#define TCA9548_LIB_VERSION (F("0.1.0"))
class TCA9548
{
public:
// address = 0x70 .. 0x77
TCA9548(const char *i2c_device_filepath, const uint8_t deviceAddress = 0x70);
bool begin(uint8_t mask = 0x00); // default no channels enabled
bool isConnected(); // find multiplexer on I2C bus
// channel = 0.. 7
void enableChannel(uint8_t channel);
void disableChannel(uint8_t channel);
void selectChannel(uint8_t channel); // enable only this channel
bool isEnabled(uint8_t channel);
// mask = 0x00 .. 0xFF - every bit is a channel.
void setChannelMask(uint8_t mask);
uint8_t getChannelMask();
// set forced write
void setForced(bool forced) { _forced = forced; };
bool getForced() { return _forced; };
// TODO improve errorhandling ?
int getError();
private:
uint8_t _mask = 0x00; // caching mask
uint8_t _resetPin = -1;
int _error = 0;
uint8_t _address;
bool _forced;
int i2c_file;
std::string i2c_filepath;
int i2c_read();
int i2c_write(uint8_t data);
};
// -- END OF FILE --