diff --git a/libraries/ADG731/.arduino-ci.yml b/libraries/ADG731/.arduino-ci.yml new file mode 100644 index 00000000..10c0e10b --- /dev/null +++ b/libraries/ADG731/.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/ADG731/.github/FUNDING.yml b/libraries/ADG731/.github/FUNDING.yml new file mode 100644 index 00000000..90d9ab4c --- /dev/null +++ b/libraries/ADG731/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: RobTillaart + diff --git a/libraries/ADG731/.github/workflows/arduino-lint.yml b/libraries/ADG731/.github/workflows/arduino-lint.yml new file mode 100644 index 00000000..8a26f14a --- /dev/null +++ b/libraries/ADG731/.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/ADG731/.github/workflows/arduino_test_runner.yml b/libraries/ADG731/.github/workflows/arduino_test_runner.yml new file mode 100644 index 00000000..a1090a68 --- /dev/null +++ b/libraries/ADG731/.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/ADG731/.github/workflows/jsoncheck.yml b/libraries/ADG731/.github/workflows/jsoncheck.yml new file mode 100644 index 00000000..37a11298 --- /dev/null +++ b/libraries/ADG731/.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/ADG731/ADG731.h b/libraries/ADG731/ADG731.h new file mode 100644 index 00000000..1c6705ff --- /dev/null +++ b/libraries/ADG731/ADG731.h @@ -0,0 +1,88 @@ +#pragma once +// +// FILE: ADG731.h +// AUTHOR: Rob Tillaart +// DATE: 2023-07-24 +// VERSION: 0.1.0 +// PURPOSE: Arduino library for ADG731 - 32 to 1 channel multiplexer +// URL: https://github.com/RobTillaart/ADG731 + + +#include "Arduino.h" + +#define ADG731_LIB_VERSION (F("0.1.0")) + +#define ADG731_ALLOFF 0x80 + + +class ADG731 +{ +public: + explicit ADG731(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. + _channel = ADG731_ALLOFF; + } + + + void setChannel(uint8_t channel) + { + _channel = channel & 0x0F; + write(_channel); + } + + + uint8_t getChannel() + { + return _channel; + } + + + uint8_t channelCount() + { + return 32; + } + + + void allOff() + { + _channel = ADG731_ALLOFF; + write(_channel); + } + + +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 _channel; +}; + + +// -- END OF FILE -- diff --git a/libraries/ADG731/CHANGELOG.md b/libraries/ADG731/CHANGELOG.md new file mode 100644 index 00000000..522aed1c --- /dev/null +++ b/libraries/ADG731/CHANGELOG.md @@ -0,0 +1,10 @@ +# Change Log ADG731 + +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/ADG731/LICENSE b/libraries/ADG731/LICENSE new file mode 100644 index 00000000..16ef1551 --- /dev/null +++ b/libraries/ADG731/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/ADG731/README.md b/libraries/ADG731/README.md new file mode 100644 index 00000000..568d2c8a --- /dev/null +++ b/libraries/ADG731/README.md @@ -0,0 +1,77 @@ + +[![Arduino CI](https://github.com/RobTillaart/ADG731/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/ADG731/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ADG731/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/ADG731/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ADG731/actions/workflows/jsoncheck.yml) +[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ADG731/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/RobTillaart/ADG731.svg?maxAge=3600)](https://github.com/RobTillaart/ADG731/releases) + + +# ADG731 + +Arduino library for ADG731 - 32 to 1 channel multiplexer. + + +## Description + +**Experimental** + +ADG731 is an Arduino class that controls a 1 x 32 multiplexer over a SPI +like interface. +Only one of the 32 channels can be connected at the same time. +The library also support to set them all off (17th state). + +This library can be used to connect 32 analog devices to one analog port. + +On power-up, all switches are in the OFF state. + +This library can be used e.g. to connect 32 analog devices to +one analog port, or to select between 32 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 "ADG731.h" +``` + +- **ADG731(uint8_t clockPin, uint8_t dataPin, uint8_t syncPin)** constructor. +- **void setChannel(uint8_t channel)** set the current channel. +Valid values for channel are 0..31. +- **uint8_t getChannel()** get last set channel == 0..31 or ADG731_ALLOFF. +- **uint8_t channelCount()** returns 32 for ADG731. + + +## Future + +#### Must + +- improve documentation +- test with hardware + +#### Should + +- add examples +- check performance + +#### Could + + +#### Wont + + diff --git a/libraries/ADG731/examples/ADG731_demo/ADG731_demo.ino b/libraries/ADG731/examples/ADG731_demo/ADG731_demo.ino new file mode 100644 index 00000000..204a23ea --- /dev/null +++ b/libraries/ADG731/examples/ADG731_demo/ADG731_demo.ino @@ -0,0 +1,52 @@ +// +// FILE: ADG731_demo.ino +// AUTHOR: Rob Tillaart +// PURPOSE: minimal sketch +// URL: https://github.com/RobTillaart/ADG731 + + +#include "ADG731.h" + + +ADG731 ADG(10, 11, 12); + +uint32_t start, stop; + +void setup() +{ + Serial.begin(115200); + Serial.print("ADG731_LIB_VERSION: "); + Serial.println(ADG731_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 < 32; ch++) + { + ADG.setChannel(ch); + + Serial.print(ch); + Serial.print("\t"); + Serial.println(ADG.getChannel()); + delay(1000); + } +} + + +// -- END OF FILE -- diff --git a/libraries/ADG731/keywords.txt b/libraries/ADG731/keywords.txt new file mode 100644 index 00000000..1ca6222f --- /dev/null +++ b/libraries/ADG731/keywords.txt @@ -0,0 +1,17 @@ +# Syntax Colouring Map For ADG731 + +# Data types (KEYWORD1) +ADG731 KEYWORD1 + + +# Methods and Functions (KEYWORD2) +setChannel KEYWORD2 +setChannel KEYWORD2 +getChannel KEYWORD2 +channelCount KEYWORD2 + + +# Constants (LITERAL1) +ADG731_LIB_VERSION LITERAL1 + +ADG731_ALLOFF LITERAL1 diff --git a/libraries/ADG731/library.json b/libraries/ADG731/library.json new file mode 100644 index 00000000..cacd4823 --- /dev/null +++ b/libraries/ADG731/library.json @@ -0,0 +1,23 @@ +{ + "name": "ADG731", + "keywords": "ADG731,32,1, multiplexer, MUX", + "description": "Arduino library for ADG731 - 32 to 1 channel multiplexer.", + "authors": + [ + { + "name": "Rob Tillaart", + "email": "Rob.Tillaart@gmail.com", + "maintainer": true + } + ], + "repository": + { + "type": "git", + "url": "https://github.com/RobTillaart/ADG731" + }, + "version": "0.1.0", + "license": "MIT", + "frameworks": "*", + "platforms": "*", + "headers": "ADG731.h" +} diff --git a/libraries/ADG731/library.properties b/libraries/ADG731/library.properties new file mode 100644 index 00000000..2bb54416 --- /dev/null +++ b/libraries/ADG731/library.properties @@ -0,0 +1,11 @@ +name=ADG731 +version=0.1.0 +author=Rob Tillaart +maintainer=Rob Tillaart +sentence=Arduino library for ADG731 - 32 to 1 channel multiplexer. +paragraph= +category=Signal Input/Output +url=https://github.com/RobTillaart/ADG731 +architectures=* +includes=ADG731.h +depends= diff --git a/libraries/ADG731/test/unit_test_001.cpp b/libraries/ADG731/test/unit_test_001.cpp new file mode 100644 index 00000000..a3f6ba90 --- /dev/null +++ b/libraries/ADG731/test/unit_test_001.cpp @@ -0,0 +1,80 @@ +// +// FILE: unit_test_001.cpp +// AUTHOR: Rob Tillaart +// DATE: 2023-07-24 +// PURPOSE: unit tests for the ADG731 library +// https://github.com/RobTillaart/ADG731 +// 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 "ADG731.h" + + +unittest_setup() +{ + fprintf(stderr, "ADG731_LIB_VERSION: %s\n", (char *) ADG731_LIB_VERSION); +} + + +unittest_teardown() +{ +} + + +unittest(test_constructor) +{ + ADG731 ADG(10, 11, 12); + + assertEqual(32, ADG.channelCount()); + assertEqual(ADG731_ALLOFF, ADG.getChannel()); +} + + +unittest(test_constants) +{ + assertEqual(0x80, ADG731_ALLOFF ); +} + + +unittest(test_allOff) +{ + ADG731 ADG(10, 11, 12); + + ADG.setChannel(13); + ADG.allOff(); + assertEqual(ADG731_ALLOFF, ADG.getChannel()); +} + + +unittest(test_channel) +{ + ADG731 ADG(10, 11, 12); + + for (int ch = 0; ch < 16; ch++) + { + ADG.setChannel(ch); + assertEqual(ch, ADG.getChannel()); + } +} + + +unittest_main() + + +// -- END OF FILE -- +