diff --git a/libraries/ADG725/.arduino-ci.yml b/libraries/ADG725/.arduino-ci.yml new file mode 100644 index 00000000..10c0e10b --- /dev/null +++ b/libraries/ADG725/.arduino-ci.yml @@ -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 + diff --git a/libraries/ADG725/.github/FUNDING.yml b/libraries/ADG725/.github/FUNDING.yml new file mode 100644 index 00000000..90d9ab4c --- /dev/null +++ b/libraries/ADG725/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: RobTillaart + diff --git a/libraries/ADG725/.github/workflows/arduino-lint.yml b/libraries/ADG725/.github/workflows/arduino-lint.yml new file mode 100644 index 00000000..8a26f14a --- /dev/null +++ b/libraries/ADG725/.github/workflows/arduino-lint.yml @@ -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 diff --git a/libraries/ADG725/.github/workflows/arduino_test_runner.yml b/libraries/ADG725/.github/workflows/arduino_test_runner.yml new file mode 100644 index 00000000..a1090a68 --- /dev/null +++ b/libraries/ADG725/.github/workflows/arduino_test_runner.yml @@ -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 \ No newline at end of file diff --git a/libraries/ADG725/.github/workflows/jsoncheck.yml b/libraries/ADG725/.github/workflows/jsoncheck.yml new file mode 100644 index 00000000..37a11298 --- /dev/null +++ b/libraries/ADG725/.github/workflows/jsoncheck.yml @@ -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$" + diff --git a/libraries/ADG725/ADG725.h b/libraries/ADG725/ADG725.h new file mode 100644 index 00000000..680ab782 --- /dev/null +++ b/libraries/ADG725/ADG725.h @@ -0,0 +1,116 @@ +#pragma once +// +// FILE: ADG725.h +// AUTHOR: Rob Tillaart +// DATE: 2023-07-24 +// VERSION: 0.1.0 +// PURPOSE: Arduino library for ADG725 - 16 to 1 channel (2x) multiplexer +// URL: https://github.com/RobTillaart/ADG725 + + +#include "Arduino.h" + +#define ADG725_LIB_VERSION (F("0.1.0")) + +#define ADG725_ALLOFF 0x80 // ENable bit (false) +#define ADG725_A_ONLY 0x20 // retain B +#define ADG725_B_ONLY 0x40 // retain A +#define ADG725_AB_BOTH 0x00 // retain none + + +class ADG725 +{ +public: + explicit ADG725(uint8_t clockPin, uint8_t dataPin, uint8_t syncPin) + { + _clockPin = clockPin; + _dataPin = dataPin; + _syncPin = syncPin; + + pinMode(_clockPin, OUTPUT); + pinMode(_dataPin, OUTPUT); + pinMode(_syncPin, OUTPUT); + + digitalWrite(_clockPin, HIGH); + digitalWrite(_dataPin, HIGH); + digitalWrite(_syncPin, HIGH); + + // default all off. + _channelA = ADG725_ALLOFF; + _channelB = ADG725_ALLOFF; + } + + // set both channels + void setChannel(uint8_t channel) + { + _channelA = channel & 0x0F; + uint8_t data = ADG725_AB_BOTH | _channelA; + _channelB = _channelA; + write(data); + } + + void setChannelA(uint8_t channel) + { + _channelA = channel & 0x0F; + uint8_t data = ADG725_A_ONLY | _channelA; + write(data); + } + + void setChannelB(uint8_t channel) + { + _channelB = channel & 0x0F; + uint8_t data = ADG725_B_ONLY | _channelB; + write(data); + } + + // last set channel + uint8_t getChannelA() + { + return _channelA; + } + + + uint8_t getChannelB() + { + return _channelB; + } + + + uint8_t channelCount() + { + return 16; + } + + + void allOff() + { + _channelA = ADG725_ALLOFF; + _channelB = _channelA; + write(_channelA); + } + + +private: + void write(uint8_t data) + { + digitalWrite(_syncPin, LOW); + for (int i = 0; i < 8; i++) + { + // CLOCK max 30 MHz. + digitalWrite(_clockPin, HIGH); + digitalWrite(_dataPin, (data & 0x80) > 0); + data <<= 1; + digitalWrite(_clockPin, LOW); + } + digitalWrite(_syncPin, HIGH); + } + + uint8_t _clockPin; + uint8_t _dataPin; + uint8_t _syncPin; + uint8_t _channelA; + uint8_t _channelB; +}; + + +// -- END OF FILE -- diff --git a/libraries/ADG725/CHANGELOG.md b/libraries/ADG725/CHANGELOG.md new file mode 100644 index 00000000..455123c0 --- /dev/null +++ b/libraries/ADG725/CHANGELOG.md @@ -0,0 +1,10 @@ +# Change Log ADG725 + +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-24 +- initial version diff --git a/libraries/ADG725/LICENSE b/libraries/ADG725/LICENSE new file mode 100644 index 00000000..16ef1551 --- /dev/null +++ b/libraries/ADG725/LICENSE @@ -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. diff --git a/libraries/ADG725/README.md b/libraries/ADG725/README.md new file mode 100644 index 00000000..a386633c --- /dev/null +++ b/libraries/ADG725/README.md @@ -0,0 +1,81 @@ + +[![Arduino CI](https://github.com/RobTillaart/ADG725/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/ADG725/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ADG725/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/ADG725/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ADG725/actions/workflows/jsoncheck.yml) +[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ADG725/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/RobTillaart/ADG725.svg?maxAge=3600)](https://github.com/RobTillaart/ADG725/releases) + + +# ADG725 + +Arduino library for ADG725 - 16 to 1 channel (2x) multiplexer. + + +## Description + +**Experimental** + +ADG725 is an Arduino class that controls two 16 to 1 multiplexers +over a SPI like 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. + +Not tests with hardware have been done yet, so use with care. +Feedback welcome! + + +TODO insert picture. + + +#### 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/ADG731 (1x32 mux) + + +## Interface + +```cpp +#include "ADG725.h" +``` + +- **ADG725(uint8_t clockPin, uint8_t dataPin, uint8_t syncPin)** 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 ADG725_ALLOFF. +- **uint8_t getChannelB()** get last set channel B == 0..15 or ADG725_ALLOFF. +- **uint8_t channelCount()** returns 16 for ADG725. + + +## Future + +#### Must + +- improve documentation +- test with hardware + +#### Should + +- add examples +- check performance + +#### Could + + +#### Wont + + diff --git a/libraries/ADG725/examples/ADG725_demo/ADG725_demo.ino b/libraries/ADG725/examples/ADG725_demo/ADG725_demo.ino new file mode 100644 index 00000000..a269783c --- /dev/null +++ b/libraries/ADG725/examples/ADG725_demo/ADG725_demo.ino @@ -0,0 +1,52 @@ +// +// FILE: ADG725_demo.ino +// AUTHOR: Rob Tillaart +// PURPOSE: minimal sketch +// URL: https://github.com/RobTillaart/ADG725 + + +#include "ADG725.h" + + +ADG725 ADG(10, 11, 12); + +uint32_t start, stop; + +void setup() +{ + Serial.begin(115200); + Serial.print("ADG725_LIB_VERSION: "); + Serial.println(ADG725_LIB_VERSION); + delay(100); + + start = micros(); + ADG.setChannel(0); + stop = micros(); + Serial.print("Time:\t"); + Serial.println(stop - start); + 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 -- diff --git a/libraries/ADG725/keywords.txt b/libraries/ADG725/keywords.txt new file mode 100644 index 00000000..712d16b0 --- /dev/null +++ b/libraries/ADG725/keywords.txt @@ -0,0 +1,19 @@ +# Syntax Colouring Map For ADG725 + +# Data types (KEYWORD1) +ADG725 KEYWORD1 + + +# Methods and Functions (KEYWORD2) +setChannel KEYWORD2 +setChannelA KEYWORD2 +setChannelB KEYWORD2 +getChannelA KEYWORD2 +getChannelB KEYWORD2 +channelCount KEYWORD2 + + +# Constants (LITERAL1) +ADG725_LIB_VERSION LITERAL1 + +ADG725_ALLOFF LITERAL1 diff --git a/libraries/ADG725/library.json b/libraries/ADG725/library.json new file mode 100644 index 00000000..e008ea9e --- /dev/null +++ b/libraries/ADG725/library.json @@ -0,0 +1,23 @@ +{ + "name": "ADG725", + "keywords": "ADG725,16,2, multiplexer, MUX", + "description": "Arduino library for ADG725 - 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/ADG725" + }, + "version": "0.1.0", + "license": "MIT", + "frameworks": "*", + "platforms": "*", + "headers": "ADG725.h" +} diff --git a/libraries/ADG725/library.properties b/libraries/ADG725/library.properties new file mode 100644 index 00000000..4c3337b3 --- /dev/null +++ b/libraries/ADG725/library.properties @@ -0,0 +1,11 @@ +name=ADG725 +version=0.1.0 +author=Rob Tillaart +maintainer=Rob Tillaart +sentence=Arduino library for ADG725 - 16 to 1 channel (2x) multiplexer. +paragraph= +category=Signal Input/Output +url=https://github.com/RobTillaart/ADG725 +architectures=* +includes=ADG725.h +depends= diff --git a/libraries/ADG725/test/unit_test_001.cpp b/libraries/ADG725/test/unit_test_001.cpp new file mode 100644 index 00000000..8b968953 --- /dev/null +++ b/libraries/ADG725/test/unit_test_001.cpp @@ -0,0 +1,115 @@ +// +// FILE: unit_test_001.cpp +// AUTHOR: Rob Tillaart +// DATE: 2023-07-24 +// PURPOSE: unit tests for the ADG725 library +// https://github.com/RobTillaart/ADG725 +// 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 + +#include "Arduino.h" +#include "ADG725.h" + + +unittest_setup() +{ + fprintf(stderr, "ADG725_LIB_VERSION: %s\n", (char *) ADG725_LIB_VERSION); +} + + +unittest_teardown() +{ +} + + +unittest(test_constructor) +{ + ADG725 ADG(10, 11, 12); + + assertEqual(16, ADG.channelCount()); + assertEqual(ADG725_ALLOFF, ADG.getChannelA()); + assertEqual(ADG725_ALLOFF, ADG.getChannelB()); +} + + +unittest(test_constants) +{ + assertEqual(0x80, ADG725_ALLOFF ); + assertEqual(0x20, ADG725_A_ONLY ); + assertEqual(0x40, ADG725_B_ONLY ); + assertEqual(0x00, ADG725_AB_BOTH); +} + + +unittest(test_allOff) +{ + ADG725 ADG(10, 11, 12); + + ADG.setChannelA(13); + ADG.setChannelB(7); + ADG.allOff(); + assertEqual(ADG725_ALLOFF, ADG.getChannelA()); + assertEqual(ADG725_ALLOFF, ADG.getChannelB()); +} + + +unittest(test_channel) +{ + ADG725 ADG(10, 11, 12); + + for (int ch = 0; ch < 16; ch++) + { + ADG.setChannel(ch); + assertEqual(ch, ADG.getChannelA()); + assertEqual(ch, ADG.getChannelB()); + } +} + + +unittest(test_channelA) +{ + ADG725 ADG(10, 11, 12); + + ADG.setChannelB(7); + for (int ch = 0; ch < 16; ch++) + { + ADG.setChannelA(ch); + assertEqual(ch, ADG.getChannelA()); + } + assertEqual(7, ADG.getChannelB()); +} + + +unittest(test_channelB) +{ + ADG725 ADG(10, 11, 12); + + 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 -- +