0.1.0 ADG728

This commit is contained in:
Rob Tillaart 2024-07-03 17:21:20 +02:00
parent bb4a166b98
commit d6ac94a01c
16 changed files with 748 additions and 0 deletions

View File

@ -0,0 +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
- m4
- esp32
- esp8266
# - mega2560
- rpipico

4
libraries/ADG728/.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: RobTillaart
custom: "https://www.paypal.me/robtillaart"

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict

View File

@ -0,0 +1,17 @@
name: Arduino CI
on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -0,0 +1,18 @@
name: JSON check
on:
push:
paths:
- '**.json'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: json-syntax-check
uses: limitusus/json-syntax-check@v2
with:
pattern: "\\.json$"

143
libraries/ADG728/ADG728.cpp Normal file
View File

@ -0,0 +1,143 @@
//
// FILE: ADG728.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2024-07-03
// PURPOSE: Arduino Library for I2C ADG728 matrix switch. 1x8 Multiplexer.
// URL: https://github.com/RobTillaart/ADG728
// https://www.adafruit.com/product/5899
#include "ADG728.h"
ADG728::ADG728(uint8_t deviceAddress, TwoWire *wire)
{
_address = deviceAddress;
_wire = wire;
_mask = 0x00;
_resetPin = -1;
_forced = false;
_error = ADG728_OK;
_channels = 8;
}
bool ADG728::begin(uint8_t mask)
{
if (! isConnected()) return false;
setChannelMask(mask);
return true;
}
bool ADG728::isConnected()
{
_wire->beginTransmission(_address);
return ( _wire->endTransmission() == 0);
}
uint8_t ADG728::channelCount()
{
return _channels;
}
bool ADG728::enableChannel(uint8_t channel)
{
if (channel >= _channels) return false;
return setChannelMask(_mask | (0x01 << channel));
}
bool ADG728::disableChannel(uint8_t channel)
{
if (channel >= _channels) return false;
return setChannelMask(_mask & ~(0x01 << channel));
}
bool ADG728::selectChannel(uint8_t channel)
{
if (channel >= _channels) return false;
return setChannelMask(0x01 << channel);
}
bool ADG728::isEnabled(uint8_t channel)
{
if (channel >= _channels) return false;
return (_mask & (0x01 << channel));
}
bool ADG728::disableAllChannels()
{
return setChannelMask(0x00);
}
bool ADG728::setChannelMask(uint8_t mask)
{
if ((_mask == mask) && (not _forced)) return true;
_mask = mask;
_wire->beginTransmission(_address);
_wire->write(_mask);
_error = _wire->endTransmission();
return (_error == 0);
}
uint8_t ADG728::getChannelMask()
{
if (_forced) // read from device.
{
_wire->requestFrom(_address, (uint8_t)1);
_mask = _wire->read();
}
return _mask;
}
void ADG728::setResetPin(uint8_t resetPin)
{
_resetPin = resetPin;
pinMode(_resetPin, OUTPUT);
digitalWrite(_resetPin, HIGH); // page 3 HIGH is normal operation
}
void ADG728::reset()
{
if (_resetPin != -1)
{
digitalWrite(_resetPin, LOW);
delayMicroseconds(1);
digitalWrite(_resetPin, HIGH);
}
}
void ADG728::setForced(bool forced)
{
_forced = forced;
}
bool ADG728::getForced()
{
return _forced;
}
int ADG728::getError()
{
int error = _error;
_error = ADG728_OK;
return error;
}
// -- END OF FILE --

74
libraries/ADG728/ADG728.h Normal file
View File

@ -0,0 +1,74 @@
#pragma once
//
// FILE: ADG728.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2024-07-03
// PURPOSE: Arduino Library for I2C ADG728 matrix switch. 1x8 Multiplexer.
// URL: https://github.com/RobTillaart/ADG728
// https://www.adafruit.com/product/5899
#include "Arduino.h"
#include "Wire.h"
#define ADG728_LIB_VERSION (F("0.1.0"))
// ERROR CODES (to be elaborated)
#define ADG728_OK 0
#define ADG728_ERROR_I2C -10 // not used yet
#define ADG728_ERROR_CHANNEL -20 // not used yet
class ADG728
{
public:
// deviceAddress = 0x4C .. 0x4F
ADG728(uint8_t deviceAddress, TwoWire *wire = &Wire);
bool begin(uint8_t mask = 0x00); // default no channels enabled
bool isConnected(); // find address on I2C bus
// channel = 0..channelCount()-1
uint8_t channelCount();
bool enableChannel(uint8_t channel); // enable channel NON exclusive
bool disableChannel(uint8_t channel);
bool selectChannel(uint8_t channel); // enable channel exclusive
bool isEnabled(uint8_t channel);
bool disableAllChannels();
// mask = 0x00 .. 0xFF - every bit is a channel.
// although not for derived types.
// note 1: these are set simultaneously.
// note 2: these may include interrupt bits (in derived classes)
bool setChannelMask(uint8_t mask);
uint8_t getChannelMask();
// reset
void setResetPin(uint8_t resetPin);
void reset(); // trigger reset pin
// set forced IO (default false)
void setForced(bool forced = false);
bool getForced();
int getError();
protected:
uint8_t _address;
TwoWire* _wire;
uint8_t _mask; // caching mask = status of channels
uint8_t _resetPin; // default not set == -1 (255)
bool _forced;
int _error;
uint8_t _channels;
};
// -- END OF FILE --

View File

@ -0,0 +1,11 @@
# Change Log ADG728
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.0] - 2024-07-03
- initial version

21
libraries/ADG728/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024-2024 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

165
libraries/ADG728/README.md Normal file
View File

@ -0,0 +1,165 @@
[![Arduino CI](https://github.com/RobTillaart/ADG728/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/ADG728/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ADG728/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/ADG728/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ADG728/actions/workflows/jsoncheck.yml)
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/ADG728.svg)](https://github.com/RobTillaart/ADG728/issues)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ADG728/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ADG728.svg?maxAge=3600)](https://github.com/RobTillaart/ADG728/releases)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/ADG728.svg)](https://registry.platformio.org/libraries/robtillaart/ADG728)
# ADG728
Arduino Library for I2C ADG728 matrix switch. 1x8 Multiplexer.
## Description
**Experimental**
Library for the ADG728 1 to 8 channel multiplexer.
The library allows you to enable 0 to 8 channels uniquely or simultaneously.
In fact the ADG728 is therefore a **switch**, although often named a multiplexer.
The library caches the channels enabled, and if a channel is enabled,
it will not be enabled again (low level) to optimize performance.
This can however be overruled.
The device works with 2.3 V to 5.5 V so it should work with most MCU's.
**Warning**
The library is not tested with hardware yet.
#### I2C
I2C address of the device itself is 0x4C .. 0x4F.
#### I2C performance
The ADG728 can work up to 400 KHz according to the datasheet.
#### Related
Other multiplexers
- https://github.com/RobTillaart/HC4051 (1x8 mux)
- https://github.com/RobTillaart/HC4052 (2x4 mux)
- https://github.com/RobTillaart/HC4053 (3x2 mux)
- https://github.com/RobTillaart/HC4067 (1x16 mux)
- https://github.com/RobTillaart/ADG725 (2x16 mux)
- https://github.com/RobTillaart/ADG726 (2x16 mux)
- https://github.com/RobTillaart/ADG728 (1x8 mux)
- https://github.com/RobTillaart/ADG729 (2x4 mux)
- https://github.com/RobTillaart/ADG731 (1x32 mux)
- https://github.com/RobTillaart/ADG732 (1x32 mux)
- https://github.com/RobTillaart/TCA9548 I2C multiplexer
## Interface
```cpp
#include "ADG728.h"
```
#### Constructor
- **ADG728(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
deviceAddress = 0x4C .. 0x4F, wire = Wire or WireN.
- **bool begin(uint8_t mask = 0x00)** set mask of channels to be enabled, default all disabled.
- **bool isConnected()** returns true if address of the multiplexer is found on I2C bus.
#### Channel functions
All "channel functions" return true on success.
- **bool enableChannel(uint8_t channel)** enables channel 0 .. 7 **non-exclusive**.
Multiple channels can be enabled in parallel.
- **bool disableChannel(uint8_t channel)** disables channel 0 .. 7.
Will not disable other channels.
- **bool 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.
- **bool disableAllChannels()** fast way to disable all channels.
Multiple channels can also be enabled in one call with a mask.
- **bool 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.
#### Reset
Optional the library can reset the device.
- **void setResetPin(uint8_t resetPin)** sets the pin to reset the chip.
- **void reset()** trigger the reset pin.
#### Debug
- **int getError()** returns the last (I2C) status / error.
#### Forced IO
When forced IO is set, all writes and read, e.g. **uint8_t getChannelMask()**,
will go to the device.
If the **forced-IO** flag is set to false, it will cache the value of the channels enabled.
This will result in far more responsive and faster calls.
Note that writes are only optimized if the channels are already set.
Forced IO is also used to speed up **getChannelMask()**.
- **void setForced(bool forced = false)** set forced write, slower but more robust.
- forced == false == fast mode (default).
- forced == true == slower, robust mode.
- **bool getForced()** returns set flag.
## Error Codes
Not implemented yet, preparation for future.
| name | value | description |
|:-----------------------|:-------:|:------------------------|
| ADG728_OK | 00 | no error |
| ADG728_ERROR_I2C | -10 | detected an I2C error |
| ADG728_ERROR_CHANNEL | -20 | channel out of range |
## Future
#### Must
- improve documentation.
- test with hardware.
#### Should
- add examples.
- improve error handling.
#### Could
- extend the unit tests.
#### Wont
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,

Binary file not shown.

View File

@ -0,0 +1,54 @@
//
// FILE: ADG728_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo ADG728 I2C multiplexer
// URL: https://github.com/RobTillaart/ADG728
#include "ADG728.h"
ADG728 MP(0x4C); // 0x4C..0x4F
uint8_t channels = 0;
uint8_t selected = 0;
uint32_t lastTime = 0;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("ADG728_LIB_VERSION: ");
Serial.println(ADG728_LIB_VERSION);
Serial.println();
Wire.begin();
// initialize multiplexer
if (MP.begin() == false)
{
Serial.println("Multiplexer error");
}
channels = MP.channelCount();
selected = 0;
}
void loop()
{
if ((millis() - lastTime) >= 5000)
{
lastTime = millis();
selected++;
if (selected >= MP.channelCount()) selected = 0;
MP.selectChannel(selected);
Serial.println(selected);
}
}
// -- END OF FILE --

View File

@ -0,0 +1,41 @@
# Syntax Colouring Map For ADG728
# Data types (KEYWORD1)
ADG728 KEYWORD1
# Methods and Functions (KEYWORD2)
begin KEYWORD2
isConnected KEYWORD2
find KEYWORD2
channelCount KEYWORD2
enableChannel KEYWORD2
disableChannel KEYWORD2
selectChannel KEYWORD2
isEnabled KEYWORD2
disableAllChannels KEYWORD2
setChannelMask KEYWORD2
getChannelMask KEYWORD2
setResetPin KEYWORD2
reset KEYWORD2
setForced KEYWORD2
getForced KEYWORD2
getError KEYWORD2
# Devices with interrupt
getInterruptMask KEYWORD2
# Constants (LITERAL1)
ADG728_LIB_VERSION LITERAL1
ADG728_OK LITERAL1
ADG728_ERROR_I2C LITERAL1
ADG728_ERROR_CHANNEL LITERAL1

View File

@ -0,0 +1,23 @@
{
"name": "ADG728",
"keywords": "I2C,multiplexer",
"description": "Arduino Library for I2C ADG728 matrix switch. 1x8 Multiplexer.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/ADG728"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
"headers": "ADG728.h"
}

View File

@ -0,0 +1,11 @@
name=ADG728
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library for I2C ADG728 matrix switch. 1x8 Multiplexer.
paragraph=
category=Signal Input/Output
url=https://github.com/RobTillaart/ADG728
architectures=*
includes=ADG728.h
depends=

View File

@ -0,0 +1,125 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2021-03-16
// PURPOSE: unit tests for the ADG728 I2C matrix switch. Multiplexer.
// https://github.com/RobTillaart/ADG728
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual); // a == b
// assertNotEqual(unwanted, actual); // a != b
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
// assertLess(upperBound, actual); // a < b
// assertMore(lowerBound, actual); // a > b
// assertLessOrEqual(upperBound, actual); // a <= b
// assertMoreOrEqual(lowerBound, actual); // a >= b
// assertTrue(actual);
// assertFalse(actual);
// assertNull(actual);
// // special cases for floats
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
// assertInfinity(actual); // isinf(a)
// assertNotInfinity(actual); // !isinf(a)
// assertNAN(arg); // isnan(a)
// assertNotNAN(arg); // !isnan(a)
/*
most unit tests will test for fail
as there is no sensor connected
and there is no mockup.
It appears that Wire.write does not fail without sensor...
*/
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "ADG728.h"
unittest_setup()
{
fprintf(stderr, "ADG728_LIB_VERSION: %s\n", (char *) ADG728_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_constants)
{
assertEqual(0, ADG728_OK);
assertEqual(-10, ADG728_ERROR_I2C);
assertEqual(-20, ADG728_ERROR_CHANNEL);
}
unittest(test_constructor)
{
ADG728 adg(0x4C);
Wire.begin();
assertTrue(adg.begin());
assertTrue(adg.isConnected());
assertEqual(8, adg.channelCount());
}
unittest(test_enable)
{
ADG728 adg(0x4C);
Wire.begin();
bool b = adg.begin();
assertEqual(b, true);
uint8_t mask = 0x00;
for (int chan = 0; chan < 8; chan++)
{
adg.enableChannel(chan);
assertTrue(adg.isEnabled(chan));
}
assertEqual(0xFF, adg.getChannelMask());
adg.setChannelMask(0x00);
assertEqual(0x00, adg.getChannelMask());
}
unittest(test_select)
{
ADG728 adg(0x4C);
Wire.begin();
bool b = adg.begin();
assertEqual(b, true);
uint8_t mask = 0x00;
for (int chan = 0; chan < 8; chan++)
{
adg.selectChannel(chan);
assertTrue(adg.isEnabled(chan));
}
assertEqual(0x80, adg.getChannelMask());
adg.setChannelMask(0x00);
assertEqual(0x00, adg.getChannelMask());
}
unittest_main()
// -- END OF FILE --