0.1.0 ADG726

This commit is contained in:
Rob Tillaart 2023-07-25 20:52:51 +02:00
parent c4fb017af7
commit 7d5ef73432
14 changed files with 554 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/ADG726/.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: RobTillaart

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- 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
steps:
- uses: actions/checkout@v3
- 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
steps:
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

133
libraries/ADG726/ADG726.h Normal file
View File

@ -0,0 +1,133 @@
#pragma once
//
// FILE: ADG726.h
// AUTHOR: Rob Tillaart
// DATE: 2023-07-24
// VERSION: 0.1.0
// PURPOSE: Arduino library for ADG726 - 16 to 1 channel (2x) multiplexer
// URL: https://github.com/RobTillaart/ADG726
#include "Arduino.h"
#define ADG726_LIB_VERSION (F("0.1.0"))
#define ADG726_ALLOFF 0x80
class ADG726
{
public:
ADG726(uint8_t A, uint8_t B, uint8_t C, uint8_t D, uint8_t CSA, uint8_t CSB, uint8_t EN, uint8_t WR)
{
uint8_t arr[4] = { A, B, C, D };
ADG726(arr, CSA, CSB, EN, WR);
}
explicit ADG726(uint8_t address[4], uint8_t CSA, uint8_t CSB, uint8_t EN, uint8_t WR)
{
for (int i = 0; i < 4; i++)
{
_addr[i] = address[i];
pinMode(_addr[i], OUTPUT);
digitalWrite(_addr[i], LOW);
}
_CSA = CSA;
_CSB = CSB;
_EN = EN;
_WR = WR;
pinMode(_CSA, OUTPUT);
pinMode(_CSB, OUTPUT);
pinMode(_EN, OUTPUT);
pinMode(_WR, OUTPUT);
digitalWrite(_CSA, HIGH);
digitalWrite(_CSB, HIGH);
digitalWrite(_EN, HIGH);
digitalWrite(_WR, HIGH);
// default all off.
_channelA = ADG726_ALLOFF;
_channelB = ADG726_ALLOFF;
}
// set both channels
void setChannel(uint8_t channel)
{
_channelA = channel & 0x0F;
_channelB = _channelA;
write(_channelA, LOW, LOW, LOW);
}
void setChannelA(uint8_t channel)
{
_channelA = channel & 0x0F;
write(_channelA, LOW, HIGH, LOW);
}
void setChannelB(uint8_t channel)
{
_channelB = channel & 0x0F;
write(_channelB, HIGH, LOW, LOW);
}
// last set channel
uint8_t getChannelA()
{
return _channelA;
}
uint8_t getChannelB()
{
return _channelB;
}
uint8_t channelCount()
{
return 16;
}
void allOff()
{
_channelA = ADG726_ALLOFF;
_channelB = _channelA;
write(_channelA, LOW, LOW, HIGH);
}
private:
void write(uint8_t data, uint8_t csa, uint8_t csb, uint8_t en)
{
digitalWrite(_CSA, csa);
digitalWrite(_CSB, csb);
digitalWrite(_WR, LOW);
digitalWrite(_EN, en);
uint8_t mask = 0x01;
for (int i = 0; i < 4; i++)
{
digitalWrite(_addr[i], ((data & mask) > 0));
mask <<= 1;
}
digitalWrite(_EN, HIGH);
digitalWrite(_WR, HIGH);
digitalWrite(_CSB, HIGH);
digitalWrite(_CSA, HIGH);
}
uint8_t _addr[4];
uint8_t _CSA;
uint8_t _CSB;
uint8_t _EN;
uint8_t _WR;
uint8_t _channelA;
uint8_t _channelB;
};
// -- END OF FILE --

View File

@ -0,0 +1,10 @@
# Change Log ADG726
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] - 2023-07-25
- initial version

21
libraries/ADG726/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023-2023 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.

View File

@ -0,0 +1,84 @@
[![Arduino CI](https://github.com/RobTillaart/ADG726/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/ADG726/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ADG726/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/ADG726/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ADG726/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ADG726/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ADG726.svg?maxAge=3600)](https://github.com/RobTillaart/ADG726/releases)
# ADG726
Arduino library for ADG726 - 16 to 1 channel (2x) multiplexer.
## Description
**Experimental**
ADG726 is an Arduino class that controls two 16 to 1 multiplexers
over a **parallel** interface.
Only one of the 16 channels can be connected at the same time.
The channels can be set per multiplexer or together in one call.
The library also support to set them all off (17th state).
On power-up, all switches are in the OFF state.
This library can be used e.g. to connect 16 analog devices to
one analog port, or to select between 16 DHT22 sensors.
No tests with hardware have been done yet, so use with care.
Feedback welcome!
#### Related
- https://github.com/RobTillaart/HC4051 (1x8 mux)
- https://github.com/RobTillaart/HC4052 (2x8 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/ADG731 (1x32 mux)
- https://github.com/RobTillaart/ADG732 (1x32 mux)
## Interface
```cpp
#include "ADG726.h"
```
- **ADG726(uint8_t A, uint8_t B, uint8_t C, uint8_t D, uint8_t CSA, uint8_t CSB, uint8_t EN, uint8_t WR)** constructor.
- **ADG726(uint8_t address[4], uint8_t CSA, uint8_t CSB, uint8_t EN, uint8_t WR)** constructor.
- **void setChannel(uint8_t channel)** set the current channel for both A and B.
Valid values for channel are 0..15.
- **void setChannelA(uint8_t channel)** set the current channel for A only.
Valid values for channel are 0..15.
- **void setChannelB(uint8_t channel)** set the current channel for B only.
Valid values for channel are 0..15.
- **uint8_t getChannelA()** get last set channel A == 0..15 or ADG726_ALLOFF.
- **uint8_t getChannelB()** get last set channel B == 0..15 or ADG726_ALLOFF.
- **uint8_t channelCount()** returns 16 for ADG726.
- **void allOff()** sets all channels to OFF, none selected.
## Future
#### Must
- improve documentation
- insert schematic
- test with hardware
- keep in sync with ADG725 (interface)
#### Should
- add examples
- check performance
#### Could
#### Wont

View File

@ -0,0 +1,55 @@
//
// FILE: ADG726_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: minimal sketch
// URL: https://github.com/RobTillaart/ADG725
#include "ADG726.h"
ADG726 ADG(4, 5, 6, 7, 8, 9, 10, 11);
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
Serial.print("ADG726_LIB_VERSION: ");
Serial.println(ADG726_LIB_VERSION);
delay(100);
start = micros();
for (int ch = 0; ch < 16; ch++)
{
ADG.setChannel(ch);
}
stop = micros();
Serial.print("Time:\t");
Serial.println((stop - start) / 16.0);
delay(100);
start = micros();
ADG.setChannel(1);
stop = micros();
Serial.print("Time:\t");
Serial.println(stop - start);
delay(100);
}
void loop()
{
for (int ch = 0; ch < 16; ch++)
{
ADG.setChannel(ch);
Serial.print(ch);
Serial.print("\t");
Serial.println(ADG.getChannelA());
delay(1000);
}
}
// -- END OF FILE --

View File

@ -0,0 +1,20 @@
# Syntax Colouring Map For ADG726
# Data types (KEYWORD1)
ADG726 KEYWORD1
# Methods and Functions (KEYWORD2)
setChannel KEYWORD2
setChannelA KEYWORD2
setChannelB KEYWORD2
getChannelA KEYWORD2
getChannelB KEYWORD2
channelCount KEYWORD2
allOff KEYWORD2
# Constants (LITERAL1)
ADG726_LIB_VERSION LITERAL1
ADG726_ALLOFF LITERAL1

View File

@ -0,0 +1,23 @@
{
"name": "ADG726",
"keywords": "ADG726,16,2, multiplexer, MUX",
"description": "Arduino library for ADG726 - 16 to 1 channel (2x) multiplexer.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/ADG726"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
"headers": "ADG726.h"
}

View File

@ -0,0 +1,11 @@
name=ADG726
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for ADG726 - 16 to 1 channel (2x) multiplexer.
paragraph=
category=Signal Input/Output
url=https://github.com/RobTillaart/ADG726
architectures=*
includes=ADG726.h
depends=

View File

@ -0,0 +1,117 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2023-07-25
// PURPOSE: unit tests for the ADG726 library
// https://github.com/RobTillaart/ADG726
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual)
// assertNotEqual(expected, actual)
// assertLess(expected, actual)
// assertMore(expected, actual)
// assertLessOrEqual(expected, actual)
// assertMoreOrEqual(expected, actual)
// assertTrue(actual)
// assertFalse(actual)
// assertNull(actual)
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "ADG726.h"
unittest_setup()
{
fprintf(stderr, "ADG726_LIB_VERSION: %s\n", (char *) ADG726_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_constructor)
{
uint8_t arr[4] = {4, 5, 6, 7};
ADG726 ADG(arr, 10, 11, 12, 13);
assertEqual(16, ADG.channelCount());
assertEqual(ADG726_ALLOFF, ADG.getChannelA());
assertEqual(ADG726_ALLOFF, ADG.getChannelB());
}
unittest(test_constants)
{
assertEqual(0x80, ADG726_ALLOFF );
}
unittest(test_allOff)
{
uint8_t arr[4] = {4, 5, 6, 7};
ADG726 ADG(arr, 10, 11, 12, 13);
ADG.setChannelA(13);
ADG.setChannelB(7);
ADG.allOff();
assertEqual(ADG726_ALLOFF, ADG.getChannelA());
assertEqual(ADG726_ALLOFF, ADG.getChannelB());
}
unittest(test_channel)
{
uint8_t arr[4] = {4, 5, 6, 7};
ADG726 ADG(arr, 10, 11, 12, 13);
for (int ch = 0; ch < 16; ch++)
{
ADG.setChannel(ch);
assertEqual(ch, ADG.getChannelA());
assertEqual(ch, ADG.getChannelB());
}
}
unittest(test_channelA)
{
uint8_t arr[4] = {4, 5, 6, 7};
ADG726 ADG(arr, 10, 11, 12, 13);
ADG.setChannelB(7);
for (int ch = 0; ch < 16; ch++)
{
ADG.setChannelA(ch);
assertEqual(ch, ADG.getChannelA());
}
assertEqual(7, ADG.getChannelB());
}
unittest(test_channelB)
{
uint8_t arr[4] = {4, 5, 6, 7};
ADG726 ADG(arr, 10, 11, 12, 13);
ADG.setChannelA(13);
for (int ch = 0; ch < 16; ch++)
{
ADG.setChannelB(ch);
assertEqual(ch, ADG.getChannelB());
}
assertEqual(13, ADG.getChannelA());
}
unittest_main()
// -- END OF FILE --