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

118 lines
3.1 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
2023-12-07 11:22:19 -05:00
// VERSION: 0.2.0
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
2023-12-07 11:22:19 -05:00
#define MAX14661_LIB_VERSION (F("0.2.0"))
2023-02-25 10:29:54 -05:00
#define MAX14661_OK 0x00
#define MAX14661_ERR_I2C 0x80 // Not implemented yet
#define MAX14661_ERR_CHANNEL 0x81 // Not implemented yet
2021-06-03 03:31:17 -04:00
class MAX14661
{
public:
explicit MAX14661(const uint8_t deviceAddress, TwoWire *wire = &Wire);
bool begin();
bool isConnected();
2023-12-07 11:22:19 -05:00
uint8_t getAddress();
2021-06-03 03:31:17 -04:00
2022-11-16 09:18:12 -05:00
// PAIR INTERFACE
// - keeps A and B line in sync, ideal for an I2C bus or Serial.
2023-02-25 10:29:54 -05:00
// - returns false if channel > 15
2021-06-03 03:31:17 -04:00
//
2022-11-16 09:18:12 -05:00
// open ==> connect
2021-06-03 03:31:17 -04:00
bool openChannel(uint8_t channel);
2022-11-16 09:18:12 -05:00
// close ==> disconnect
2021-06-03 03:31:17 -04:00
bool closeChannel(uint8_t channel);
2022-11-16 09:18:12 -05:00
// returns true if channel is opened
2021-06-03 03:31:17 -04:00
bool isOpenChannel(uint8_t channel);
2022-11-16 09:18:12 -05:00
// open A and B lines of all channels
2021-06-03 03:31:17 -04:00
void openAllChannels();
2022-11-16 09:18:12 -05:00
// closes A and B lines of all channels
2021-06-03 03:31:17 -04:00
void closeAllChannels();
2022-11-16 09:18:12 -05:00
// set channels with a bit mask
2021-06-03 03:31:17 -04:00
void setChannels(uint16_t mask);
2022-11-16 09:18:12 -05:00
// returns channel state as bit mask
2021-06-03 03:31:17 -04:00
uint16_t getChannels();
2022-11-16 09:18:12 -05:00
// SHADOW INTERFACE
// - 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();
2023-02-25 10:29:54 -05:00
// should we have activateShadowA() and activateShadowB() ?
void activateShadow();
2021-08-30 14:24:50 -04:00
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
2022-11-16 09:18:12 -05:00
// MUX INTERFACE
// - allows only one channel simultaneously open
// - opening a channel closes any other.
2021-06-03 03:31:17 -04:00
//
2022-11-16 09:18:12 -05:00
void MUXA(uint8_t channel); // 0..15, else ==> off
2021-06-03 03:31:17 -04:00
uint8_t getMUXA();
2022-11-16 09:18:12 -05:00
void MUXB(uint8_t channel); // 0..15, else ==> off
2021-06-03 03:31:17 -04:00
uint8_t getMUXB();
2021-08-30 14:24:50 -04:00
2023-02-25 10:29:54 -05:00
// FULL CONTROL PER A and B LINE
2022-11-16 09:18:12 -05:00
// - selective open and close A and B
2023-02-25 10:29:54 -05:00
// - returns false if channel > 15
2021-06-03 03:31:17 -04:00
//
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
2022-11-16 09:18:12 -05:00
// LOW LEVEL CONTROL
// 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-08-30 14:24:50 -04:00
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;
};
2022-11-16 09:18:12 -05:00
// -- END OF FILE --
2021-12-21 07:06:15 -05:00