mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.3 TCA9548
This commit is contained in:
parent
cdd4898b19
commit
d0045e9601
@ -1,11 +1,28 @@
|
||||
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:
|
||||
- uno
|
||||
- due
|
||||
- zero
|
||||
- leonardo
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
- esp8266
|
||||
- mega2560
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
||||
|
27
libraries/TCA9548/CHANGELOG.md
Normal file
27
libraries/TCA9548/CHANGELOG.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Change Log TCA9548
|
||||
|
||||
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-26
|
||||
- Add RP2040 support to build-CI.
|
||||
- Add CHANGELOG.md
|
||||
- update readme.md
|
||||
- move code to .cpp
|
||||
|
||||
|
||||
## [0.1.2] - 2021-12-28
|
||||
- update license
|
||||
- minor edits
|
||||
|
||||
## [0.1.1] - 2021-11-19
|
||||
- fix reset code (from datasheet)
|
||||
- implemented forced IO
|
||||
- update build-CI, readme.md, badges
|
||||
|
||||
## [0.1.0] - 2021-03-16
|
||||
- initial version
|
||||
|
@ -46,11 +46,13 @@ This can be used to verify a certain device is available (or not) on an enabled
|
||||
|
||||
### Channel functions
|
||||
|
||||
- **void enableChannel(uint8_t channel)** enables channel 0 .. 7. Multiple channels can be enabled in parallel.
|
||||
- **void disableChannel(uint8_t channel)** disables channel 0 .. 7. Will not disable other channels.
|
||||
- **void selectChannel(uint8_t channel)** enables a single channel 0 .. 7 uniquely.
|
||||
All other channels will be disabled, although these can be set again with enableChannel.
|
||||
- **bool isEnabled(uint8_t channel)** returns true is a channel is enabled.
|
||||
- **void enableChannel(uint8_t channel)** enables channel 0 .. 7 non-exclusive.
|
||||
Multiple channels can be enabled in parallel.
|
||||
- **void disableChannel(uint8_t channel)** disables channel 0 .. 7.
|
||||
Will not disable other channels.
|
||||
- **void selectChannel(uint8_t channel)** enables a single channel 0 .. 7 exclusive.
|
||||
All other channels will be disabled in the same call, so not before or after.
|
||||
- **bool isEnabled(uint8_t channel)** returns true if the channel is enabled.
|
||||
- **void setChannelMask(uint8_t mask)** enables 0 or more channels simultaneously with a bit mask.
|
||||
- **uint8_t getChannelMask()** reads back the bit mask of the channels enabled.
|
||||
- **void setResetPin(uint8_t resetPin)** sets the pin to reset the chip. (Not tested)
|
||||
@ -65,7 +67,9 @@ If the flag is set to false it will cache the value of the channels enabled.
|
||||
This will result in more responsive / faster calls.
|
||||
Note that writes are only optimized if the channels are already set.
|
||||
|
||||
- **void setForced(bool forced = false)** set forced write, slower but more robust. Default off.
|
||||
- **void setForced(bool forced = false)** set forced write, slower but more robust.
|
||||
- forced == false == fast mode (default).
|
||||
- forced == true == robust mode.
|
||||
- **bool getForced()** returns set flag.
|
||||
|
||||
|
||||
@ -76,12 +80,18 @@ See example
|
||||
|
||||
## Future
|
||||
|
||||
- improve error handling + documentation.
|
||||
#### must
|
||||
- improve documentation.
|
||||
- improve error handling
|
||||
|
||||
#### should
|
||||
- add examples
|
||||
- test test and test
|
||||
- improve documentation
|
||||
- write unit test
|
||||
- add **disableAll()** == setChannelMask(0)
|
||||
|
||||
#### could
|
||||
- set an "always enabled" mask (have to investigate the consequences)
|
||||
|
||||
- check PCA9548 compatibility
|
||||
|
||||
|
||||
|
@ -1,17 +1,9 @@
|
||||
//
|
||||
// FILE: TCA9548.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.3
|
||||
// DATE: 2021-03-16
|
||||
// PURPOSE: Library for TCA9548 I2C multiplexer
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2021-03-16 initial version
|
||||
// 0.1.1 2021-11-19 fix reset code (from datasheet)
|
||||
// implemented forced IO
|
||||
// update build-CI, readme.md, badges
|
||||
// 0.1.2 2021-12-28 update license, minor edits
|
||||
|
||||
|
||||
|
||||
#include "TCA9548.h"
|
||||
@ -107,7 +99,7 @@ void TCA9548::setChannelMask(uint8_t mask)
|
||||
|
||||
uint8_t TCA9548::getChannelMask()
|
||||
{
|
||||
if (_forced) // read from device.
|
||||
if (_forced) // read from device.
|
||||
{
|
||||
_wire->requestFrom(_address, 1);
|
||||
_mask = _wire->read();
|
||||
@ -120,25 +112,37 @@ void TCA9548::setResetPin(uint8_t resetPin)
|
||||
{
|
||||
_resetPin = resetPin;
|
||||
pinMode(_resetPin, OUTPUT);
|
||||
digitalWrite(_resetPin, HIGH); // page 3 HIGH is normal operation
|
||||
digitalWrite(_resetPin, HIGH); // page 3 HIGH is normal operation
|
||||
}
|
||||
|
||||
|
||||
void TCA9548::reset()
|
||||
{
|
||||
digitalWrite(_resetPin, LOW);
|
||||
delayMicroseconds(1); // datasheet page 6 & 7 - 500 ns
|
||||
delayMicroseconds(1); // datasheet page 6 & 7 - 500 ns
|
||||
digitalWrite(_resetPin, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void TCA9548::setForced(bool forced)
|
||||
{
|
||||
_forced = forced;
|
||||
};
|
||||
|
||||
|
||||
bool TCA9548::getForced()
|
||||
{
|
||||
return _forced;
|
||||
};
|
||||
|
||||
|
||||
int TCA9548::getError()
|
||||
{
|
||||
int e = _error;
|
||||
int error = _error;
|
||||
_error = 0;
|
||||
return e;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: TCA9548.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.2
|
||||
// VERSION: 0.1.3
|
||||
// DATE: 2021-03-16
|
||||
// PURPOSE: Library for TCA9548 I2C multiplexer
|
||||
//
|
||||
@ -14,44 +14,45 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define TCA9548_LIB_VERSION (F("0.1.2"))
|
||||
#define TCA9548_LIB_VERSION (F("0.1.3"))
|
||||
|
||||
|
||||
class TCA9548
|
||||
{
|
||||
public:
|
||||
// address = 0x70 .. 0x77
|
||||
// address = 0x70 .. 0x77
|
||||
TCA9548(const uint8_t deviceAddress, TwoWire *wire = &Wire);
|
||||
|
||||
#if defined (ESP8266) || defined(ESP32)
|
||||
bool begin(uint8_t sda, uint8_t scl, uint8_t mask = 0x00); // default no channels enabled
|
||||
#endif
|
||||
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
|
||||
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
|
||||
|
||||
// channel = 0.. 7
|
||||
void enableChannel(uint8_t channel);
|
||||
// channel = 0.. 7
|
||||
void enableChannel(uint8_t channel); // enable this channel non exclusive
|
||||
void disableChannel(uint8_t channel);
|
||||
void selectChannel(uint8_t channel); // enable only this channel
|
||||
void selectChannel(uint8_t channel); // enable only this channel
|
||||
bool isEnabled(uint8_t channel);
|
||||
|
||||
// mask = 0x00 .. 0xFF - every bit is a channel.
|
||||
// mask = 0x00 .. 0xFF - every bit is a channel.
|
||||
// note these are set simultaneously.
|
||||
void setChannelMask(uint8_t mask);
|
||||
uint8_t getChannelMask();
|
||||
|
||||
void setResetPin(uint8_t resetPin);
|
||||
void reset(); // trigger reset pin
|
||||
void reset(); // trigger reset pin
|
||||
|
||||
// set forced IO (default false)
|
||||
void setForced(bool forced = false) { _forced = forced; };
|
||||
bool getForced() { return _forced; };
|
||||
// set forced IO (default false)
|
||||
void setForced(bool forced = false);
|
||||
bool getForced();
|
||||
|
||||
int getError();
|
||||
|
||||
private:
|
||||
uint8_t _mask; // caching mask
|
||||
uint8_t _resetPin;
|
||||
uint8_t _mask; // caching mask = status of channels
|
||||
uint8_t _resetPin; // default not set == -1 (255)
|
||||
int _error;
|
||||
uint8_t _address;
|
||||
TwoWire* _wire;
|
||||
@ -59,5 +60,5 @@ private:
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/TCA9548"
|
||||
},
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=TCA9548
|
||||
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 TCA9548 I2C multiplexer.
|
||||
|
Loading…
Reference in New Issue
Block a user