Skip to content

Commit 488d1f3

Browse files
committed
0.1.0 ADG2128_RT
1 parent ee26ea0 commit 488d1f3

File tree

15 files changed

+742
-0
lines changed

15 files changed

+742
-0
lines changed

libraries/ADG2128_RT/.arduino-ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
platforms:
19+
- uno
20+
# - due
21+
# - zero
22+
# - leonardo
23+
- m4
24+
- esp32
25+
- esp8266
26+
# - mega2560
27+
- rpipico
28+
29+
libraries:
30+
- "printHelpers"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+
custom: "https://www.paypal.me/robtillaart"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Arduino-lint
2+
3+
on: [push, pull_request]
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
timeout-minutes: 5
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Arduino CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
runTest:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 20
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 5
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: json-syntax-check
16+
uses: limitusus/json-syntax-check@v2
17+
with:
18+
pattern: "\\.json$"

libraries/ADG2128_RT/ADG2128.cpp

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
//
2+
// FILE: ADG2128.cpp
3+
// AUTHOR: Rob Tillaart
4+
// DATE: 2025-02-28
5+
// VERSION: 0.1.0
6+
// PURPOSE: Arduino library for ADG2128 8x8 (cross-point) matrix switch with I2C.
7+
// URL: https://github.com/RobTillaart/ADG2128
8+
9+
10+
11+
#include "ADG2128.h"
12+
13+
#define ADG2128_LATCHED_MODE 0x00
14+
#define ADG2128_DIRECT_MODE 0x01
15+
16+
17+
ADG2128::ADG2128(uint8_t address, TwoWire *wire)
18+
{
19+
_address = address;
20+
_wire = wire;
21+
_error = 0;
22+
_mode = ADG2128_DIRECT_MODE;
23+
_reset = 255;
24+
}
25+
26+
bool ADG2128::begin()
27+
{
28+
// reset variables
29+
_error = 0;
30+
31+
if ((_address < 0x70) || (_address > 0x77))
32+
{
33+
_error = -1;
34+
return false;
35+
}
36+
if (! isConnected())
37+
{
38+
return false;
39+
}
40+
return true;
41+
}
42+
43+
bool ADG2128::isConnected()
44+
{
45+
_wire->beginTransmission(_address);
46+
return (_wire->endTransmission() == 0);
47+
}
48+
49+
uint8_t ADG2128::getAddress()
50+
{
51+
return _address;
52+
}
53+
54+
55+
/////////////////////////////////////////////
56+
//
57+
// SWITCHES
58+
//
59+
void ADG2128::on(uint8_t row, uint8_t col)
60+
{
61+
if ((row > 7 ) || (col > 11)) return;
62+
uint8_t pins = 0x80; // 0x80 == ON
63+
if (col < 6) pins |= (col << 3) + row;
64+
else pins |= ((col + 2) << 3) + row;
65+
_send(pins, _mode);
66+
}
67+
68+
void ADG2128::off(uint8_t row, uint8_t col)
69+
{
70+
if ((row > 7 ) || (col > 11)) return;
71+
uint8_t pins = 0x00; // 0x00 == OFF
72+
if (col < 6) pins |= (col << 3) + row;
73+
else pins |= ((col + 2) << 3) + row;
74+
75+
_send(pins, _mode);
76+
}
77+
78+
bool ADG2128::isOn(uint8_t row, uint8_t col)
79+
{
80+
if ((row > 7 ) || (col > 11)) return false;
81+
uint8_t value = isOn(col);
82+
return (value & (1 << row)) > 0;
83+
}
84+
85+
uint8_t ADG2128::isOnMask(uint8_t col)
86+
{
87+
if (col > 11) return false;
88+
// Table 8 datasheet
89+
uint8_t mask = 0x34; // == 0b00110100;
90+
if (col & 0x08) mask |= 0x02;
91+
if (col & 0x04) mask |= 0x01;
92+
if (col & 0x02) mask |= 0x40;
93+
if (col & 0x01) mask |= 0x08;
94+
95+
return _readback(mask);
96+
}
97+
98+
99+
/////////////////////////////////////////////
100+
//
101+
// MODE
102+
//
103+
// default direct (transparent) mode
104+
void ADG2128::setMode(bool latched)
105+
{
106+
_mode = latched ? ADG2128_LATCHED_MODE : ADG2128_DIRECT_MODE;
107+
}
108+
109+
bool ADG2128::isLatchedMode()
110+
{
111+
return _mode == ADG2128_LATCHED_MODE;
112+
}
113+
114+
bool ADG2128::isDirectMode()
115+
{
116+
return _mode == ADG2128_DIRECT_MODE;
117+
}
118+
119+
120+
/////////////////////////////////////////////
121+
//
122+
// RESET
123+
//
124+
void ADG2128::setResetPin(uint8_t resetPin)
125+
{
126+
_reset = resetPin;
127+
pinMode(_reset, OUTPUT);
128+
digitalWrite(_reset, HIGH);
129+
}
130+
131+
132+
void ADG2128::pulseResetPin()
133+
{
134+
digitalWrite(_reset, LOW);
135+
// need delay(1);
136+
digitalWrite(_reset, HIGH);
137+
}
138+
139+
140+
/////////////////////////////////////////////
141+
//
142+
// DEBUG
143+
//
144+
int ADG2128::getLastError()
145+
{
146+
int e = _error;
147+
_error = 0;
148+
return e;
149+
}
150+
151+
152+
///////////////////////////////////////////////
153+
//
154+
// PRIVATE
155+
//
156+
157+
int ADG2128::_send(uint8_t pins, uint8_t value)
158+
{
159+
_wire->beginTransmission(_address);
160+
_wire->write(pins);
161+
_wire->write(value);
162+
_error = _wire->endTransmission();
163+
return _error;
164+
}
165+
166+
167+
int ADG2128::_readback(uint8_t value)
168+
{
169+
_wire->beginTransmission(_address);
170+
_wire->write(value);
171+
_error = _wire->endTransmission();
172+
uint8_t bytes = _wire->requestFrom(_address, (uint8_t)2);
173+
if (bytes != 2)
174+
{
175+
_error = -1;
176+
return 0;
177+
}
178+
_wire->read(); // skip dummy data
179+
return _wire->read();
180+
}
181+
182+
183+
// -- END OF FILE --
184+

libraries/ADG2128_RT/ADG2128.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#pragma once
2+
//
3+
// FILE: ADG2128.h
4+
// AUTHOR: Rob Tillaart
5+
// DATE: 2025-02-28
6+
// VERSION: 0.1.0
7+
// PURPOSE: Arduino library for ADG2128 8x12 (cross-point) matrix switch with I2C.
8+
// URL: https://github.com/RobTillaart/ADG2128
9+
//
10+
11+
12+
#include "Arduino.h"
13+
#include "Wire.h"
14+
15+
16+
#define ADG2128_LIB_VERSION (F("0.1.0"))
17+
18+
#define ADG2128_DEFAULT_ADDRESS 0x70
19+
20+
// ERROR CODES
21+
// values <> 0 are errors.
22+
#define ADG2128_OK 0x00
23+
#define ADG2128_CRC_ERROR 0x01
24+
#define ADG2128_NOT_READY 0x10
25+
#define ADG2128_REQUEST_ERROR 0x11
26+
27+
28+
class ADG2128
29+
{
30+
public:
31+
ADG2128(uint8_t address = ADG2128_DEFAULT_ADDRESS, TwoWire *wire = &Wire);
32+
33+
bool begin();
34+
bool isConnected();
35+
uint8_t getAddress();
36+
37+
38+
// SWITCH
39+
void on(uint8_t row, uint8_t col);
40+
void off(uint8_t row, uint8_t col);
41+
bool isOn(uint8_t row, uint8_t col);
42+
uint8_t isOnMask(uint8_t col); // get a whole column at once as bit mask.
43+
44+
// WRAPPERS.
45+
void on(uint8_t sw) { on(sw / 12, sw % 12); };
46+
void off(uint8_t sw) { off(sw / 12, sw % 12); };
47+
uint8_t isOn(uint8_t sw) { return isOn(sw / 12, sw % 12); };
48+
49+
50+
// MODE
51+
// default direct (transparent) mode
52+
void setMode(bool latched = false);
53+
bool isLatchedMode();
54+
bool isDirectMode();
55+
56+
57+
// RESET
58+
void setResetPin(uint8_t resetPin);
59+
// reset ==> all switches off, registers ==> 0.
60+
void pulseResetPin();
61+
62+
63+
// DEBUG
64+
int getLastError();
65+
66+
67+
private:
68+
uint8_t _address = 0x2A;
69+
TwoWire* _wire;
70+
71+
int _send(uint8_t pins, uint8_t value);
72+
int _readback(uint8_t value);
73+
74+
int _error;
75+
uint8_t _mode;
76+
uint8_t _reset;
77+
};
78+
79+
80+
// -- END OF FILE --
81+
82+
83+
84+
85+

libraries/ADG2128_RT/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Change Log ADG2128
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.1.0] - 2025-02-28
10+
- initial version
11+
12+
13+

libraries/ADG2128_RT/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025-2025 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)