Skip to content

Commit

Permalink
0.1.0 ADG2128_RT
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Feb 28, 2025
1 parent ee26ea0 commit 488d1f3
Show file tree
Hide file tree
Showing 15 changed files with 742 additions and 0 deletions.
30 changes: 30 additions & 0 deletions libraries/ADG2128_RT/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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

libraries:
- "printHelpers"
4 changes: 4 additions & 0 deletions libraries/ADG2128_RT/.github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: RobTillaart
custom: "https://www.paypal.me/robtillaart"
13 changes: 13 additions & 0 deletions libraries/ADG2128_RT/.github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions libraries/ADG2128_RT/.github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions libraries/ADG2128_RT/.github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
@@ -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$"
184 changes: 184 additions & 0 deletions libraries/ADG2128_RT/ADG2128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
//
// FILE: ADG2128.cpp
// AUTHOR: Rob Tillaart
// DATE: 2025-02-28
// VERSION: 0.1.0
// PURPOSE: Arduino library for ADG2128 8x8 (cross-point) matrix switch with I2C.
// URL: https://github.com/RobTillaart/ADG2128



#include "ADG2128.h"

#define ADG2128_LATCHED_MODE 0x00
#define ADG2128_DIRECT_MODE 0x01


ADG2128::ADG2128(uint8_t address, TwoWire *wire)
{
_address = address;
_wire = wire;
_error = 0;
_mode = ADG2128_DIRECT_MODE;
_reset = 255;
}

bool ADG2128::begin()
{
// reset variables
_error = 0;

if ((_address < 0x70) || (_address > 0x77))
{
_error = -1;
return false;
}
if (! isConnected())
{
return false;
}
return true;
}

bool ADG2128::isConnected()
{
_wire->beginTransmission(_address);
return (_wire->endTransmission() == 0);
}

uint8_t ADG2128::getAddress()
{
return _address;
}


/////////////////////////////////////////////
//
// SWITCHES
//
void ADG2128::on(uint8_t row, uint8_t col)
{
if ((row > 7 ) || (col > 11)) return;
uint8_t pins = 0x80; // 0x80 == ON
if (col < 6) pins |= (col << 3) + row;
else pins |= ((col + 2) << 3) + row;
_send(pins, _mode);
}

void ADG2128::off(uint8_t row, uint8_t col)
{
if ((row > 7 ) || (col > 11)) return;
uint8_t pins = 0x00; // 0x00 == OFF
if (col < 6) pins |= (col << 3) + row;
else pins |= ((col + 2) << 3) + row;

_send(pins, _mode);
}

bool ADG2128::isOn(uint8_t row, uint8_t col)
{
if ((row > 7 ) || (col > 11)) return false;
uint8_t value = isOn(col);
return (value & (1 << row)) > 0;
}

uint8_t ADG2128::isOnMask(uint8_t col)
{
if (col > 11) return false;
// Table 8 datasheet
uint8_t mask = 0x34; // == 0b00110100;
if (col & 0x08) mask |= 0x02;
if (col & 0x04) mask |= 0x01;
if (col & 0x02) mask |= 0x40;
if (col & 0x01) mask |= 0x08;

return _readback(mask);
}


/////////////////////////////////////////////
//
// MODE
//
// default direct (transparent) mode
void ADG2128::setMode(bool latched)
{
_mode = latched ? ADG2128_LATCHED_MODE : ADG2128_DIRECT_MODE;
}

bool ADG2128::isLatchedMode()
{
return _mode == ADG2128_LATCHED_MODE;
}

bool ADG2128::isDirectMode()
{
return _mode == ADG2128_DIRECT_MODE;
}


/////////////////////////////////////////////
//
// RESET
//
void ADG2128::setResetPin(uint8_t resetPin)
{
_reset = resetPin;
pinMode(_reset, OUTPUT);
digitalWrite(_reset, HIGH);
}


void ADG2128::pulseResetPin()
{
digitalWrite(_reset, LOW);
// need delay(1);
digitalWrite(_reset, HIGH);
}


/////////////////////////////////////////////
//
// DEBUG
//
int ADG2128::getLastError()
{
int e = _error;
_error = 0;
return e;
}


///////////////////////////////////////////////
//
// PRIVATE
//

int ADG2128::_send(uint8_t pins, uint8_t value)
{
_wire->beginTransmission(_address);
_wire->write(pins);
_wire->write(value);
_error = _wire->endTransmission();
return _error;
}


int ADG2128::_readback(uint8_t value)
{
_wire->beginTransmission(_address);
_wire->write(value);
_error = _wire->endTransmission();
uint8_t bytes = _wire->requestFrom(_address, (uint8_t)2);
if (bytes != 2)
{
_error = -1;
return 0;
}
_wire->read(); // skip dummy data
return _wire->read();
}


// -- END OF FILE --

85 changes: 85 additions & 0 deletions libraries/ADG2128_RT/ADG2128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#pragma once
//
// FILE: ADG2128.h
// AUTHOR: Rob Tillaart
// DATE: 2025-02-28
// VERSION: 0.1.0
// PURPOSE: Arduino library for ADG2128 8x12 (cross-point) matrix switch with I2C.
// URL: https://github.com/RobTillaart/ADG2128
//


#include "Arduino.h"
#include "Wire.h"


#define ADG2128_LIB_VERSION (F("0.1.0"))

#define ADG2128_DEFAULT_ADDRESS 0x70

// ERROR CODES
// values <> 0 are errors.
#define ADG2128_OK 0x00
#define ADG2128_CRC_ERROR 0x01
#define ADG2128_NOT_READY 0x10
#define ADG2128_REQUEST_ERROR 0x11


class ADG2128
{
public:
ADG2128(uint8_t address = ADG2128_DEFAULT_ADDRESS, TwoWire *wire = &Wire);

bool begin();
bool isConnected();
uint8_t getAddress();


// SWITCH
void on(uint8_t row, uint8_t col);
void off(uint8_t row, uint8_t col);
bool isOn(uint8_t row, uint8_t col);
uint8_t isOnMask(uint8_t col); // get a whole column at once as bit mask.

// WRAPPERS.
void on(uint8_t sw) { on(sw / 12, sw % 12); };
void off(uint8_t sw) { off(sw / 12, sw % 12); };
uint8_t isOn(uint8_t sw) { return isOn(sw / 12, sw % 12); };


// MODE
// default direct (transparent) mode
void setMode(bool latched = false);
bool isLatchedMode();
bool isDirectMode();


// RESET
void setResetPin(uint8_t resetPin);
// reset ==> all switches off, registers ==> 0.
void pulseResetPin();


// DEBUG
int getLastError();


private:
uint8_t _address = 0x2A;
TwoWire* _wire;

int _send(uint8_t pins, uint8_t value);
int _readback(uint8_t value);

int _error;
uint8_t _mode;
uint8_t _reset;
};


// -- END OF FILE --





13 changes: 13 additions & 0 deletions libraries/ADG2128_RT/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Change Log ADG2128

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] - 2025-02-28
- initial version



21 changes: 21 additions & 0 deletions libraries/ADG2128_RT/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025-2025 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.
Loading

0 comments on commit 488d1f3

Please sign in to comment.