Skip to content

Commit 7754b90

Browse files
committed
0.1.0 LC7822
1 parent de2a3cc commit 7754b90

20 files changed

Lines changed: 938 additions & 0 deletions

libraries/LC7822/.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@v5
10+
- uses: arduino/arduino-lint-action@v2
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@v5
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
paths:
9+
- '**.json'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 5
15+
steps:
16+
- uses: actions/checkout@v5
17+
- name: json-syntax-check
18+
uses: limitusus/json-syntax-check@v2
19+
with:
20+
pattern: "\\.json$"

libraries/LC7822/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Change Log LC7822
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-12-20
10+
- initial version
11+
12+
13+

libraries/LC7822/LC7822.cpp

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
//
2+
// FILE: LC7822.cpp
3+
// AUTHOR: Rob Tillaart
4+
// DATE: 2025-12-20
5+
// VERSION: 0.1.0
6+
// PURPOSE: Arduino library for the LC7822 8 channel analogue switch.
7+
// URL: https://github.com/RobTillaart/LC7822
8+
9+
10+
#include "LC7822.h"
11+
12+
13+
LC7822::LC7822(uint8_t dataPin, uint8_t clockPin, uint8_t cePin, uint8_t sPin, uint8_t resetPin)
14+
{
15+
_address = 11;
16+
_dataPin = dataPin;
17+
_clockPin = clockPin;
18+
_cePin = cePin;
19+
_sPin = sPin;
20+
_resetPin = resetPin;
21+
_switches = 0; // all off by default.
22+
}
23+
24+
25+
bool LC7822::begin()
26+
{
27+
pinMode(_dataPin, OUTPUT);
28+
digitalWrite(_dataPin, LOW);
29+
pinMode(_clockPin, OUTPUT);
30+
digitalWrite(_clockPin, LOW);
31+
pinMode(_cePin, OUTPUT);
32+
digitalWrite(_cePin, LOW);
33+
pinMode(_sPin, OUTPUT);
34+
digitalWrite(_sPin, LOW);
35+
36+
if (_resetPin != 255)
37+
{
38+
pinMode(_resetPin, OUTPUT);
39+
digitalWrite(_resetPin, LOW); // right polarity?
40+
}
41+
return true;
42+
}
43+
44+
45+
bool LC7822::reset()
46+
{
47+
if (_resetPin != 255)
48+
{
49+
digitalWrite(_resetPin, HIGH);
50+
delayMicroseconds(2);
51+
digitalWrite(_resetPin, LOW);
52+
// force all off. needed? test...
53+
_switches = 0;
54+
_updateDevice();
55+
return true;
56+
}
57+
return false;
58+
}
59+
60+
61+
bool LC7822::setAll(uint8_t value)
62+
{
63+
_switches = value;
64+
_updateDevice();
65+
return true;
66+
}
67+
68+
69+
uint8_t LC7822::getAll()
70+
{
71+
return _switches;
72+
}
73+
74+
75+
bool LC7822::setSwitch(uint8_t sw, bool val)
76+
{
77+
if (sw > 7) return false;
78+
if (val) // ON
79+
{
80+
_switches |= (1 << sw);
81+
}
82+
else
83+
{
84+
_switches &= ~(1 << sw);
85+
}
86+
_updateDevice();
87+
return true;
88+
}
89+
90+
91+
bool LC7822::getSwitch(uint8_t sw)
92+
{
93+
if (sw > 7) return false;
94+
return _switches & (1 << sw);
95+
}
96+
97+
98+
//////////////////////////////////////////////////
99+
//
100+
// PROTECTED
101+
//
102+
void LC7822::_updateDevice()
103+
{
104+
// select this device
105+
digitalWrite(_sPin, HIGH);
106+
107+
// send address == 4 bits
108+
for (uint8_t mask = 0x08; mask > 0x00; mask >>= 1)
109+
{
110+
digitalWrite(_dataPin, (_address & mask));
111+
if (_microDelay) delayMicroseconds(_microDelay);
112+
digitalWrite(_clockPin, HIGH);
113+
if (_microDelay) delayMicroseconds(_microDelay);
114+
digitalWrite(_clockPin, LOW);
115+
}
116+
117+
// send data == 8 bits
118+
if (_microDelay) delayMicroseconds(_microDelay);
119+
digitalWrite(_cePin, HIGH);
120+
if (_microDelay) delayMicroseconds(_microDelay);
121+
122+
for (uint8_t mask = 0x80; mask > 0x00; mask >>= 1)
123+
{
124+
digitalWrite(_dataPin, (_switches & mask));
125+
if (_microDelay) delayMicroseconds(_microDelay);
126+
digitalWrite(_clockPin, HIGH);
127+
if (_microDelay) delayMicroseconds(_microDelay);
128+
digitalWrite(_clockPin, LOW);
129+
}
130+
digitalWrite(_cePin, HIGH);
131+
132+
digitalWrite(_sPin, LOW);
133+
}
134+
135+
136+
//////////////////////////////////////////////////
137+
//
138+
// DERIVED
139+
//
140+
LC7821::LC7821(uint8_t dataPin, uint8_t clockPin, uint8_t cePin, uint8_t sPin, uint8_t resetPin)
141+
:LC7822(dataPin, clockPin, cePin, sPin, resetPin)
142+
{
143+
_address = 13;
144+
}
145+
146+
147+
LC7823::LC7823(uint8_t dataPin, uint8_t clockPin, uint8_t cePin, uint8_t sPin, uint8_t resetPin)
148+
:LC7822(dataPin, clockPin, cePin, sPin, resetPin)
149+
{
150+
_address = 15;
151+
}
152+
153+
154+
// -- END OF FILE --
155+

libraries/LC7822/LC7822.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#pragma once
2+
//
3+
// FILE: LC7822.h
4+
// AUTHOR: Rob Tillaart
5+
// DATE: 2025-12-20
6+
// VERSION: 0.1.0
7+
// PURPOSE: Arduino library for the LC7822 8 channel analogue switch.
8+
// URL: https://github.com/RobTillaart/LC7822
9+
10+
11+
#include "Arduino.h"
12+
13+
#define LC7822_LIB_VERSION (F("0.1.0"))
14+
15+
16+
class LC7822
17+
{
18+
public:
19+
LC7822(uint8_t dataPin, uint8_t clockPin, uint8_t cePin,
20+
uint8_t sPin, uint8_t resetPin = 255);
21+
22+
bool begin();
23+
bool reset();
24+
uint8_t getAddress() { return _address; };
25+
26+
bool setAll(uint8_t value);
27+
uint8_t getAll();
28+
bool setSwitch(uint8_t sw, bool val);
29+
bool getSwitch(uint8_t sw);
30+
31+
// tune timing
32+
void setMicroDelay(uint8_t udel) { _microDelay = udel; };
33+
uint8_t getMicroDelay() { return _microDelay; };
34+
35+
36+
protected:
37+
uint8_t _address;
38+
uint8_t _dataPin;
39+
uint8_t _clockPin;
40+
uint8_t _cePin;
41+
uint8_t _sPin;
42+
uint8_t _resetPin;
43+
44+
uint8_t _switches = 0; // default all off
45+
uint8_t _microDelay = 5;
46+
47+
void _updateDevice();
48+
};
49+
50+
51+
52+
///////////////////////////////////////////
53+
//
54+
// DERIVED
55+
//
56+
class LC7821 : public LC7822
57+
{
58+
public:
59+
LC7821(uint8_t dataPin, uint8_t clockPin, uint8_t cePin,
60+
uint8_t sPin, uint8_t resetPin = 255);
61+
};
62+
63+
64+
class LC7823 : public LC7822
65+
{
66+
public:
67+
LC7823(uint8_t dataPin, uint8_t clockPin, uint8_t cePin,
68+
uint8_t sPin, uint8_t resetPin = 255);
69+
};
70+
71+
72+
73+
// -- END OF FILE --
74+
75+
76+
77+
78+

libraries/LC7822/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-2026 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)