0.1.3 MAX14661

This commit is contained in:
rob tillaart 2022-11-16 15:18:12 +01:00
parent f46f99898f
commit faf8dbf67a
7 changed files with 117 additions and 70 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -9,3 +24,4 @@ compile:
- esp32
# - esp8266
# - mega2560
- rpipico

View File

@ -0,0 +1,24 @@
# Change Log MAX14661
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.3] - 2022-11-16
- add RP2040 in build-CI
- add changelog.md
- minor edits readme.md
## [0.1.2] - 2021-12-21
- update library.json
- update license,
- minor edits
## [0.1.1] - 2021-08-30
- add shadow interface - experimental
## [0.1.0] - 2021-01-29
- initial version.

View File

@ -2,20 +2,19 @@
// FILE: MAX14661.cpp
// AUTHOR: Rob Tillaart
// DATE: 2021-01-29
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino library for MAX14661 16 channel I2C multiplexer
// URL: https://github.com/RobTillaart/MAX14661
//
// HISTORY:
// 0.1.0 2021-01-29 initial version
// 0.1.1 2021-08-30 add shadow interface - experimental
// 0.1.2 2021-12-21 update library.json, license, minor edits
// HISTORY: see changelog.md
#include "MAX14661.h"
// registers
//
// REGISTERS
//
#define MAX14661_DIR0 0x00
#define MAX14661_DIR1 0x01
#define MAX14661_DIR2 0x02
@ -72,7 +71,7 @@ bool MAX14661::isConnected()
/////////////////////////////////////////////////////////
//
// PAIR INTERFACE
// PAIR INTERFACE
//
bool MAX14661::openChannel(uint8_t channel)
{
@ -116,7 +115,7 @@ bool MAX14661::closeChannel(uint8_t channel)
}
// assumption both A and B are in same state
// assumption both A and B are in same state
bool MAX14661::isOpenChannel(uint8_t channel)
{
if (channel > 15) return false;
@ -143,6 +142,7 @@ void MAX14661::closeAllChannels()
setChannels(0);
}
void MAX14661::setChannels(uint16_t mask)
{
writeRegister(MAX14661_DIR0, mask & 0x00FF);
@ -152,7 +152,7 @@ void MAX14661::setChannels(uint16_t mask)
}
// assumption both A and B are in same state
// assumption both A and B are in same state
uint16_t MAX14661::getChannels()
{
uint16_t channels = readRegister(MAX14661_DIR1) << 8;
@ -163,7 +163,7 @@ uint16_t MAX14661::getChannels()
/////////////////////////////////////////////////////////
//
// SHADOW INTERFACE
// SHADOW INTERFACE
//
void MAX14661::shadowClear()
{
@ -178,8 +178,10 @@ void MAX14661::activateShadow()
writeRegister(MAX14661_CMD_B, 0x11);
}
////////////////////////////////////////////////////////////
void MAX14661::setShadowChannelMaskA(uint16_t mask)
{
writeRegister(MAX14661_SHDW0, mask & 0xFF);
@ -209,8 +211,10 @@ uint16_t MAX14661::getShadowChannelMaskB()
return mask;
}
////////////////////////////////////////////////////////////
bool MAX14661::openShadowChannelA(uint8_t channel)
{
if (channel > 15) return false;
@ -312,7 +316,7 @@ bool MAX14661::isOpenShadowChannelB(uint8_t channel)
/////////////////////////////////////////////////////////
//
// MUX INTERFACE
// MUX INTERFACE
//
void MAX14661::MUXA(uint8_t channel)
{
@ -348,7 +352,7 @@ uint8_t MAX14661::getMUXB()
/////////////////////////////////////////////////////////
//
// FULL CONTROL
// FULL CONTROL
//
bool MAX14661::openA(uint8_t channel)
{
@ -420,7 +424,7 @@ bool MAX14661::closeB(uint8_t channel)
/////////////////////////////////////////////////////////
//
// LOW LEVEL CONTROL
// LOW LEVEL CONTROL
//
uint8_t MAX14661::readRegister(uint8_t reg)
{
@ -455,6 +459,5 @@ int MAX14661::lastError()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -3,7 +3,7 @@
// FILE: MAX14661.h
// AUTHOR: Rob Tillaart
// DATE: 2021-01-29
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino library for MAX14661 16 channel I2C multiplexer
// URL: https://github.com/RobTillaart/MAX14661
//
@ -13,7 +13,7 @@
#include "Wire.h"
#define MAX14661_LIB_VERSION (F("0.1.2"))
#define MAX14661_LIB_VERSION (F("0.1.3"))
class MAX14661
@ -27,36 +27,35 @@ public:
bool begin();
bool isConnected();
// PAIR INTERFACE
// - keeps A and B line in sync, ideal for an I2C bus or Serial.
// - returns false if channel nr > 15
//
// PAIR INTERFACE
// - keeps A and B line in sync, ideal for an I2C bus or Serial.
// - returns false if channel nr > 15
//
// open ==> connect
// open ==> connect
bool openChannel(uint8_t channel);
// close ==> disconnect
// close ==> disconnect
bool closeChannel(uint8_t channel);
// returns true if channel is opened
// returns true if channel is opened
bool isOpenChannel(uint8_t channel);
// open A and B lines of all channels
// open A and B lines of all channels
void openAllChannels();
// closes A and B lines of all channels
// closes A and B lines of all channels
void closeAllChannels();
// set channels with a bit mask
// set channels with a bit mask
void setChannels(uint16_t mask);
// returns channel state as bit mask
// returns channel state as bit mask
uint16_t getChannels();
//
// SHADOW INTERFACE
// - experimental - not tested.
// - prepares channels to be set in one activateShadow().
// SHADOW INTERFACE
// - experimental - not tested.
// - prepares channels to be set in one activateShadow().
//
void shadowClear();
void activateShadow(); // should we have activateShadowA() and activateShadowB() ?
void activateShadow(); // should we have activateShadowA() and activateShadowB() ?
void setShadowChannelMaskA(uint16_t mask);
uint16_t getShadowChannelMaskA();
@ -72,21 +71,19 @@ public:
bool isOpenShadowChannelB(uint8_t channel);
// MUX INTERFACE
// - allows only one channel simultaneously open
// - opening a channel closes any other.
//
// MUX INTERFACE
// - allows only one channel simultaneously open
// - opening a channel closes any other.
//
void MUXA(uint8_t channel); // 0..15, else ==> off
void MUXA(uint8_t channel); // 0..15, else ==> off
uint8_t getMUXA();
void MUXB(uint8_t channel); // 0..15, else ==> off
void MUXB(uint8_t channel); // 0..15, else ==> off
uint8_t getMUXB();
//
// FULL CONTROL PER A B LINE
// - selective open and close A and B
// - returns false if channel nr > 15
// 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);
@ -94,13 +91,13 @@ public:
bool closeB(uint8_t channel);
// 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
// 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
uint8_t readRegister(uint8_t reg);
int writeRegister(uint8_t reg, uint8_t value);
@ -116,5 +113,5 @@ private:
};
// -- END OF FILE --
// -- END OF FILE --

View File

@ -26,7 +26,7 @@ Addresses go from 0x4C (76) .. 0x4F (79). See table 3 datasheet.
## Interface
The library provides 3 kinds of interfaces.
The library provides 3 kinds of interfaces (PAIR, SHADOW, MUX).
Mixing these interfaces is allowed but definitely not advised as
especially the PAIR interface assumes that A and B selections
are kept in sync.
@ -38,7 +38,7 @@ So depending on your application choose the interface you want to use.
- **MAX14661(deviceAddress, TwoWire \*wire = &Wire)** Constructor with device address,
and optional the Wire interface as parameter.
- **bool begin()** initializes the wire interface
- **bool begin()** initializes the wire interface.
- **bool begin(sda, scl)** idem, for the ESP32 where one can choose the I2C pins.
- **bool isConnected()** checks if the address is visible on the I2C bus.
@ -91,7 +91,7 @@ prepare per channel
### MUX interface
The MUX interface allows one channel to be open at a time.
The MUX interface allows one channel (0..15) to be open at a time.
- **void MUXA(uint8_t channel)** if channel < 16 only that channel will be selected. All other values will select no channel.
- **uint8_t getMUXA()** returns the selected channel. 255 means none selected.
@ -101,7 +101,7 @@ The MUX interface allows one channel to be open at a time.
### FULL CONTROL interface
full control per channel, any combination is possible.
Full control per channel, any combination is possible.
Use with care as these can interfere e.g. with the PAIR interface.
All functions return false if channel > 15.
@ -126,21 +126,28 @@ Check datasheet for these values of the registers.
## Error codes
to be elaborated
## Future
- test behaviour
- test I2C speed.
- measure performance
- optimize low level bit set/clr/get read/write 2bytes at once.
- write unit tests.
- error handling
- improve documentation
- initial values parameter for begin()?
to be elaborated (see future).
## Operation
See examples
## Future
#### must
- improve documentation
#### should
- test behaviour
- write unit tests.
- error handling
#### could
- optimize low level bit set/clr/get read/write 2 bytes at once.
- test I2C speed.
- measure performance.
- initial values parameter for begin()?
- SPI interface.

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/MAX14661.git"
},
"version": "0.1.2",
"version": "0.1.3",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=MAX14661
version=0.1.2
version=0.1.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for MAX14661 16 channel I2C multiplexer