GY-63_MS5611/libraries/MAX14661/MAX14661.h

125 lines
3.0 KiB
C
Raw Normal View History

2021-06-03 03:31:17 -04:00
#pragma once
//
// FILE: MAX14661.h
// AUTHOR: Rob Tillaart
// DATE: 2021-01-29
2021-08-30 14:24:50 -04:00
// VERSION: 0.1.1
2021-06-03 03:31:17 -04:00
// PURPOSE: Arduino library for MAX14661 16 channel I2C multiplexer
// URL: https://github.com/RobTillaart/MAX14661
//
#include "Arduino.h"
#include "Wire.h"
2021-08-30 14:24:50 -04:00
#define MAX14661_LIB_VERSION (F("0.1.1"))
2021-06-03 03:31:17 -04:00
class MAX14661
{
public:
explicit MAX14661(const uint8_t deviceAddress, TwoWire *wire = &Wire);
#if defined (ESP8266) || defined(ESP32)
bool begin(uint8_t sda, uint8_t scl);
#endif
bool begin();
bool isConnected();
//
2021-08-30 14:24:50 -04:00
// PAIR INTERFACE
// - keeps A and B line in sync, ideal for an I2C bus or Serial.
2021-06-03 03:31:17 -04:00
// - returns false if channel nr > 15
//
// open ==> connect
bool openChannel(uint8_t channel);
// close ==> disconnect
bool closeChannel(uint8_t channel);
2021-08-30 14:24:50 -04:00
// returns true if channel is opened
2021-06-03 03:31:17 -04:00
bool isOpenChannel(uint8_t channel);
// open A and B lines of all channels
void openAllChannels();
// closes A and B lines of all channels
void closeAllChannels();
// set channels with a bit mask
void setChannels(uint16_t mask);
// returns channel state as bit mask
uint16_t getChannels();
//
// SHADOW INTERFACE
2021-08-30 14:24:50 -04:00
// - experimental - not tested.
// - prepares channels to be set in one activateShadow().
2021-06-03 03:31:17 -04:00
//
2021-08-30 14:24:50 -04:00
void shadowClear();
void activateShadow(); // should we have activateShadowA() and activateShadowB() ?
void setShadowChannelMaskA(uint16_t mask);
uint16_t getShadowChannelMaskA();
void setShadowChannelMaskB(uint16_t mask);
uint16_t getShadowChannelMaskB();
bool openShadowChannelA(uint8_t channel);
bool closeShadowChannelA(uint8_t channel);
bool isOpenShadowChannelA(uint8_t channel);
bool openShadowChannelB(uint8_t channel);
bool closeShadowChannelB(uint8_t channel);
bool isOpenShadowChannelB(uint8_t channel);
2021-06-03 03:31:17 -04:00
//
// MUX INTERFACE
2021-08-30 14:24:50 -04:00
// - allows only one channel simultaneously open
// - opening a channel closes any other.
2021-06-03 03:31:17 -04:00
//
void MUXA(uint8_t channel); // 0..15, else ==> off
uint8_t getMUXA();
void MUXB(uint8_t channel); // 0..15, else ==> off
uint8_t getMUXB();
2021-08-30 14:24:50 -04:00
2021-06-03 03:31:17 -04:00
//
// FULL CONTROL PER A B LINE
// - selective open and close A and B
// - returns false if channel nr > 15
//
bool openA(uint8_t channel);
bool openB(uint8_t channel);
bool closeA(uint8_t channel);
bool closeB(uint8_t channel);
2021-08-30 14:24:50 -04:00
2021-06-03 03:31:17 -04:00
// LOW LEVEL CONTROL
2021-08-30 14:24:50 -04:00
// optional optimizations.
// uint8_t getRegister(uint8_t reg, uint8_t bit);
// uint8_t setRegister(uint8_t reg, uint8_t bit);
// uint8_t clrRegister(uint8_t reg, uint8_t bit);
// uint16_t readRegister2(uint8_t reg); // 2 bytes
// int writeRegister2(uint8_t reg, uint16_t value); // 2 bytes
2021-06-03 03:31:17 -04:00
uint8_t readRegister(uint8_t reg);
int writeRegister(uint8_t reg, uint8_t value);
int lastError();
private:
uint8_t _address;
TwoWire* _wire;
2021-08-30 14:24:50 -04:00
2021-06-03 03:31:17 -04:00
int _error;
2021-08-30 14:24:50 -04:00
2021-06-03 03:31:17 -04:00
// cache direct registers?
};
2021-08-30 14:24:50 -04:00
// -- END OF FILE --