2021-05-26 06:09:27 -04:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: TCA9548.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-02-12 08:15:22 -05:00
|
|
|
// VERSION: 0.1.5
|
2021-05-26 06:09:27 -04:00
|
|
|
// DATE: 2021-03-16
|
|
|
|
// PURPOSE: Library for TCA9548 I2C multiplexer
|
|
|
|
// URL: https://github.com/RobTillaart/TCA9548
|
|
|
|
|
2021-11-19 07:21:54 -05:00
|
|
|
|
2021-05-26 06:09:27 -04:00
|
|
|
#include "Arduino.h"
|
|
|
|
#include "Wire.h"
|
|
|
|
|
|
|
|
|
2023-02-12 08:15:22 -05:00
|
|
|
#define TCA9548_LIB_VERSION (F("0.1.5"))
|
|
|
|
|
|
|
|
|
|
|
|
// ERROR CODES (to be elaborated)
|
|
|
|
#define TCA9548_OK 0
|
|
|
|
#define TCA9548_ERROR_I2C -10 // not used yet
|
|
|
|
#define TCA9548_ERROR_CHANNEL -20 // not used yet
|
|
|
|
|
2021-05-26 06:09:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TCA9548
|
|
|
|
{
|
|
|
|
public:
|
2023-01-23 10:36:29 -05:00
|
|
|
// deviceAddress = 0x70 .. 0x77
|
2021-05-26 06:09:27 -04:00
|
|
|
TCA9548(const uint8_t deviceAddress, TwoWire *wire = &Wire);
|
|
|
|
|
|
|
|
#if defined (ESP8266) || defined(ESP32)
|
2023-01-23 10:36:29 -05:00
|
|
|
bool begin(uint8_t dataPin, uint8_t clockPin, uint8_t mask = 0x00); // default no channels enabled
|
2021-05-26 06:09:27 -04:00
|
|
|
#endif
|
2022-11-26 07:02:08 -05:00
|
|
|
bool begin(uint8_t mask = 0x00); // default no channels enabled
|
|
|
|
bool isConnected(); // find multiplexer on I2C bus
|
|
|
|
bool isConnected(uint8_t address); // find any address on I2C bus
|
2021-05-26 06:09:27 -04:00
|
|
|
|
2022-11-26 07:02:08 -05:00
|
|
|
// channel = 0.. 7
|
2023-01-23 10:36:29 -05:00
|
|
|
bool enableChannel(uint8_t channel); // enable this channel non exclusive
|
|
|
|
bool disableChannel(uint8_t channel);
|
|
|
|
bool selectChannel(uint8_t channel); // enable only this channel
|
2021-05-26 06:09:27 -04:00
|
|
|
bool isEnabled(uint8_t channel);
|
2023-01-23 10:36:29 -05:00
|
|
|
bool disableAllChannels();
|
2021-05-26 06:09:27 -04:00
|
|
|
|
2022-11-26 07:02:08 -05:00
|
|
|
// mask = 0x00 .. 0xFF - every bit is a channel.
|
|
|
|
// note these are set simultaneously.
|
2023-01-23 10:36:29 -05:00
|
|
|
bool setChannelMask(uint8_t mask);
|
2021-05-26 06:09:27 -04:00
|
|
|
uint8_t getChannelMask();
|
|
|
|
|
2023-01-23 10:36:29 -05:00
|
|
|
// reset
|
2021-05-26 06:09:27 -04:00
|
|
|
void setResetPin(uint8_t resetPin);
|
2022-11-26 07:02:08 -05:00
|
|
|
void reset(); // trigger reset pin
|
2021-05-26 06:09:27 -04:00
|
|
|
|
2022-11-26 07:02:08 -05:00
|
|
|
// set forced IO (default false)
|
|
|
|
void setForced(bool forced = false);
|
|
|
|
bool getForced();
|
2021-05-26 06:09:27 -04:00
|
|
|
|
|
|
|
int getError();
|
|
|
|
|
2023-01-23 10:36:29 -05:00
|
|
|
|
2021-05-26 06:09:27 -04:00
|
|
|
private:
|
|
|
|
uint8_t _address;
|
|
|
|
TwoWire* _wire;
|
2023-02-12 08:15:22 -05:00
|
|
|
uint8_t _mask; // caching mask = status of channels
|
2023-01-23 10:36:29 -05:00
|
|
|
uint8_t _resetPin; // default not set == -1 (255)
|
2021-05-26 06:09:27 -04:00
|
|
|
bool _forced;
|
2023-01-23 10:36:29 -05:00
|
|
|
int _error;
|
2021-05-26 06:09:27 -04:00
|
|
|
};
|
|
|
|
|
2021-11-19 07:21:54 -05:00
|
|
|
|
2022-11-26 07:02:08 -05:00
|
|
|
// -- END OF FILE --
|
2021-05-26 06:09:27 -04:00
|
|
|
|