diff --git a/libraries/I2C_SCANNER/.arduino-ci.yml b/libraries/I2C_SCANNER/.arduino-ci.yml new file mode 100644 index 00000000..3115dcd5 --- /dev/null +++ b/libraries/I2C_SCANNER/.arduino-ci.yml @@ -0,0 +1,11 @@ +compile: + # Choosing to run compilation tests on 2 different Arduino platforms + platforms: + - uno + # - due + # - zero + # - leonardo + - m4 + - esp32 + - esp8266 + # - mega2560 \ No newline at end of file diff --git a/libraries/I2C_SCANNER/.github/FUNDING.yml b/libraries/I2C_SCANNER/.github/FUNDING.yml new file mode 100644 index 00000000..90d9ab4c --- /dev/null +++ b/libraries/I2C_SCANNER/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: RobTillaart + diff --git a/libraries/I2C_SCANNER/.github/workflows/arduino-lint.yml b/libraries/I2C_SCANNER/.github/workflows/arduino-lint.yml new file mode 100644 index 00000000..b2ca058c --- /dev/null +++ b/libraries/I2C_SCANNER/.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@v2 + - uses: arduino/arduino-lint-action@v1 + with: + library-manager: update + compliance: strict diff --git a/libraries/I2C_SCANNER/.github/workflows/arduino_test_runner.yml b/libraries/I2C_SCANNER/.github/workflows/arduino_test_runner.yml new file mode 100644 index 00000000..096b975b --- /dev/null +++ b/libraries/I2C_SCANNER/.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@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - run: | + gem install arduino_ci + arduino_ci.rb diff --git a/libraries/I2C_SCANNER/.github/workflows/jsoncheck.yml b/libraries/I2C_SCANNER/.github/workflows/jsoncheck.yml new file mode 100644 index 00000000..04603d08 --- /dev/null +++ b/libraries/I2C_SCANNER/.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@v2 + - name: json-syntax-check + uses: limitusus/json-syntax-check@v1 + with: + pattern: "\\.json$" + diff --git a/libraries/I2C_SCANNER/I2C_SCANNER.cpp b/libraries/I2C_SCANNER/I2C_SCANNER.cpp new file mode 100644 index 00000000..7c012bad --- /dev/null +++ b/libraries/I2C_SCANNER/I2C_SCANNER.cpp @@ -0,0 +1,56 @@ +// +// FILE: I2C_SCANNER.cpp +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// DATE: 2022-08-29 +// PURPOSE: I2C scanner class +// + +#include "I2C_SCANNER.h" + + + +I2C_SCANNER::I2C_SCANNER(TwoWire *wire) +{ + _wire = wire; +} + + +#if defined (ESP8266) || defined(ESP32) +bool I2C_SCANNER::begin(int dataPin, int clockPin) +{ + _wire = &Wire; + if ((dataPin < 255) && (clockPin < 255)) + { + _wire->begin(dataPin, clockPin); + } else { + _wire->begin(); + } + return true; +} +#endif + + +bool I2C_SCANNER::begin() +{ + _wire->begin(); + return true; +} + + +bool I2C_SCANNER::ping(uint8_t address) +{ + _wire->beginTransmission(address); + return ( _wire->endTransmission() == 0); +} + + +bool I2C_SCANNER::setClock(uint32_t clockFrequency) +{ + _wire->setClock(clockFrequency); + return true; +} + + +// -- END OF FILE -- + diff --git a/libraries/I2C_SCANNER/I2C_SCANNER.h b/libraries/I2C_SCANNER/I2C_SCANNER.h new file mode 100644 index 00000000..55698a69 --- /dev/null +++ b/libraries/I2C_SCANNER/I2C_SCANNER.h @@ -0,0 +1,54 @@ +#pragma once +// +// FILE: I2C_SCANNER.h +// AUTHOR: Rob Tillaart +// VERSION: 0.1.0 +// DATE: 2022-08-29 +// PURPOSE: I2C scanner class +// + +#include "Arduino.h" +#include "Wire.h" + +#define I2C_SCANNER_LIB_VERSION (F("0.1.0")) + + +class I2C_SCANNER +{ + public: + + I2C_SCANNER(TwoWire *wire = &Wire); + +#if defined (ESP8266) || defined(ESP32) + bool begin(int sda, int scl); +#endif + bool begin(); + + bool ping(uint8_t address); + + bool setClock(uint32_t clockFrequency = 100000UL); + + + + private: + uint8_t _devices[16]; // cache ? + TwoWire* _wire; + +}; + + +/* + * ideas + * +- set Wire +- detect Wirecount + +- set output stream + +- set speed, re +- + +*/ + +// -- END OF FILE -- + diff --git a/libraries/I2C_SCANNER/LICENSE b/libraries/I2C_SCANNER/LICENSE new file mode 100644 index 00000000..cb502675 --- /dev/null +++ b/libraries/I2C_SCANNER/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022-2022 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/I2C_SCANNER/README.md b/libraries/I2C_SCANNER/README.md new file mode 100644 index 00000000..1c86a757 --- /dev/null +++ b/libraries/I2C_SCANNER/README.md @@ -0,0 +1,45 @@ + +[![Arduino CI](https://github.com/RobTillaart/I2C_SCANNER/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/I2C_SCANNER/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/I2C_SCANNER/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/I2C_SCANNER/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/I2C_SCANNER/actions/workflows/jsoncheck.yml) +[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/I2C_SCANNER/blob/master/LICENSE) +[![GitHub release](https://img.shields.io/github/release/RobTillaart/I2C_SCANNER.svg?maxAge=3600)](https://github.com/RobTillaart/I2C_SCANNER/releases) + + +# I2C_SCANNER + +Arduino class to implement an I2C scanner. + + +## Description + +I2C_SCANNER is a class to build an I2C scanner, either minimal or more complex. + +Goal is to rebuild my multispeed_I2C_scanner with this class. + + +## Interface + +TODO + + +## Operation + +See examples. + + +## Future + + +#### Must + +- implement functionality +- build examples. + + +#### Should + +- unit tests +- documentation +- Add all stuff needed. + diff --git a/libraries/I2C_SCANNER/examples/I2C_scanner_minimal/I2C_scanner_minimal.ino b/libraries/I2C_SCANNER/examples/I2C_scanner_minimal/I2C_scanner_minimal.ino new file mode 100644 index 00000000..411c5e28 --- /dev/null +++ b/libraries/I2C_SCANNER/examples/I2C_scanner_minimal/I2C_scanner_minimal.ino @@ -0,0 +1,35 @@ +// FILE: I2C_scanner_minimal.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo minimal I2C scanner +// URL: https://github.com/RobTillaart/I2C_SCANNER + + +#include "I2C_SCANNER.h" + +I2C_SCANNER scanner; + +void setup() +{ + Serial.begin(115200); + while (!Serial); + Serial.println(); + Serial.println(__FILE__); + Serial.print("I2C_SCANNER_LIB_VERSION: "); + Serial.println(I2C_SCANNER_LIB_VERSION); + + scanner.begin(); + + for (int addr = 0; addr < 128; addr++) + { + Serial.print(addr); + Serial.print("\t"); + Serial.println(scanner.ping(addr)); + } +} + +void loop() +{ +} + +// -- END OF FILE -- + diff --git a/libraries/I2C_SCANNER/examples/I2C_scanner_simple/I2C_scanner_simple.ino b/libraries/I2C_SCANNER/examples/I2C_scanner_simple/I2C_scanner_simple.ino new file mode 100644 index 00000000..f0958f8c --- /dev/null +++ b/libraries/I2C_SCANNER/examples/I2C_scanner_simple/I2C_scanner_simple.ino @@ -0,0 +1,45 @@ +// FILE: I2C_scanner_simple.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo simple scanner +// URL: https://github.com/RobTillaart/I2C_SCANNER + + +#include "I2C_SCANNER.h" + +I2C_SCANNER scanner; + +void setup() +{ + Serial.begin(115200); + while (!Serial); + Serial.println(); + Serial.println(__FILE__); + Serial.print("I2C_SCANNER_LIB_VERSION: "); + Serial.println(I2C_SCANNER_LIB_VERSION); + + scanner.begin(); + + for (int addr = 0; addr < 128; addr++) + { + if (addr % 8 == 0) Serial.println(); + if (scanner.ping(addr)) + { + Serial.print(addr); + } + else + { + Serial.print("-"); + } + Serial.print("\t"); + } + Serial.println(); + Serial.println(); +} + +void loop() +{ + + +} + +// -- END OF FILE -- diff --git a/libraries/I2C_SCANNER/keywords.txt b/libraries/I2C_SCANNER/keywords.txt new file mode 100644 index 00000000..e9d2a095 --- /dev/null +++ b/libraries/I2C_SCANNER/keywords.txt @@ -0,0 +1,14 @@ +# Syntax Colouring Map For I2C_SCANNER + +# Data types (KEYWORD1) +I2C_SCANNER KEYWORD1 + +# Methods and Functions (KEYWORD2) +begin KEYWORD2 +ping KEYWORD2 +setClock KEYWORD2 + + +# Constants (LITERAL1) +I2C_SCANNER_LIB_VERSION LITERAL1 + diff --git a/libraries/I2C_SCANNER/library.json b/libraries/I2C_SCANNER/library.json new file mode 100644 index 00000000..f11bb198 --- /dev/null +++ b/libraries/I2C_SCANNER/library.json @@ -0,0 +1,23 @@ +{ + "name": "I2C_SCANNER", + "keywords": "I2C,scanner", + "description": "Arduino class to implement an I2C scanner.", + "authors": + [ + { + "name": "Rob Tillaart", + "email": "Rob.Tillaart@gmail.com", + "maintainer": true + } + ], + "repository": + { + "type": "git", + "url": "https://github.com/RobTillaart/I2C_SCANNER.git" + }, + "version": "0.1.0", + "license": "MIT", + "frameworks": "arduino", + "platforms": "*", + "headers": "I2C_SCANNER.h" +} diff --git a/libraries/I2C_SCANNER/library.properties b/libraries/I2C_SCANNER/library.properties new file mode 100644 index 00000000..adc06727 --- /dev/null +++ b/libraries/I2C_SCANNER/library.properties @@ -0,0 +1,11 @@ +name=I2C_SCANNER +version=0.1.0 +author=Rob Tillaart +maintainer=Rob Tillaart +sentence=Arduino class to implement an I2C scanner. +paragraph=. +category=Other +url=https://github.com/RobTillaart/I2C_SCANNER +architectures=* +includes=I2C_SCANNER.h +depends= diff --git a/libraries/I2C_SCANNER/test/unit_test_001.cpp b/libraries/I2C_SCANNER/test/unit_test_001.cpp new file mode 100644 index 00000000..0097dc7a --- /dev/null +++ b/libraries/I2C_SCANNER/test/unit_test_001.cpp @@ -0,0 +1,53 @@ +// +// FILE: unit_test_001.cpp +// AUTHOR: Rob Tillaart +// DATE: 2022-08-29 +// PURPOSE: unit tests for the I2C_SCANNER class +// https://github.com/RobTillaart/I2C_SCANNER +// 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 "I2C_SCANNER.h" + +#define A0 0 + + +unittest_setup() +{ + fprintf(stderr, "I2C_SCANNER_LIB_VERSION: %s\n", (char *) I2C_SCANNER_LIB_VERSION); +} + +unittest_teardown() +{ +} + + +unittest(test_constructor) +{ + I2C_SCANNER scanner; + scanner.begin(); + + assertEqual(1, 1); // keep build-CI happy +} + + +unittest_main() + + +// -- END OF FILE --