Skip to content

Commit dd21cb1

Browse files
committed
0.1.0 PCA9549
1 parent b777645 commit dd21cb1

File tree

16 files changed

+709
-0
lines changed

16 files changed

+709
-0
lines changed

libraries/PCA9549/.arduino-ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
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+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name: Arduino-lint
3+
4+
on: [push, pull_request]
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
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+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
runTest:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
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+
steps:
13+
- uses: actions/checkout@v3
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+

libraries/PCA9549/CHANGELOG.md

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

libraries/PCA9549/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) 2023-2023 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.

libraries/PCA9549/PCA9549.cpp

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
//
2+
// FILE: PCA9549.cpp
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// DATE: 2023-12-12
6+
// PURPOSE: Arduino Library for PCA9549 I2C octal bus switch.
7+
// URL: https://github.com/RobTillaart/PCA9549
8+
9+
10+
#include "PCA9549.h"
11+
12+
13+
PCA9549::PCA9549(uint8_t deviceAddress, TwoWire *wire)
14+
{
15+
_address = deviceAddress;
16+
_wire = wire;
17+
_mask = 0x00;
18+
_resetPin = -1;
19+
_forced = false;
20+
_error = PCA9549_OK;
21+
}
22+
23+
24+
bool PCA9549::begin(uint8_t mask)
25+
{
26+
if (! isConnected()) return false;
27+
setChannelMask(mask);
28+
return true;
29+
}
30+
31+
32+
bool PCA9549::isConnected()
33+
{
34+
_wire->beginTransmission(_address);
35+
return ( _wire->endTransmission() == 0);
36+
}
37+
38+
39+
bool PCA9549::enableChannel(uint8_t channel)
40+
{
41+
if (channel >= 8) return false;
42+
if (!isEnabled(channel))
43+
{
44+
setChannelMask(_mask | (0x01 << channel));
45+
}
46+
return true;
47+
}
48+
49+
50+
bool PCA9549::disableChannel(uint8_t channel)
51+
{
52+
if (channel >= 8) return false;
53+
if (!isEnabled(channel))
54+
{
55+
setChannelMask(_mask & ~(0x01 << channel));
56+
}
57+
return true;
58+
}
59+
60+
61+
bool PCA9549::selectChannel(uint8_t channel)
62+
{
63+
if (channel >= 8) return false;
64+
setChannelMask(0x01 << channel);
65+
return true;
66+
}
67+
68+
69+
bool PCA9549::isEnabled(uint8_t channel)
70+
{
71+
if (channel >= 8) return false;
72+
return (_mask & (0x01 << channel));
73+
}
74+
75+
76+
bool PCA9549::disableAllChannels()
77+
{
78+
return setChannelMask(0x00);
79+
}
80+
81+
82+
bool PCA9549::setChannelMask(uint8_t mask)
83+
{
84+
if ((_mask == mask) && (not _forced)) return true;
85+
_mask = mask;
86+
_wire->beginTransmission(_address);
87+
_wire->write(_mask);
88+
_error = _wire->endTransmission();
89+
return (_error == 0);
90+
}
91+
92+
93+
uint8_t PCA9549::getChannelMask()
94+
{
95+
if (_forced) // read from device.
96+
{
97+
_wire->requestFrom(_address, (uint8_t)1);
98+
_mask = _wire->read();
99+
}
100+
return _mask;
101+
}
102+
103+
104+
void PCA9549::setResetPin(uint8_t resetPin)
105+
{
106+
_resetPin = resetPin;
107+
pinMode(_resetPin, OUTPUT);
108+
digitalWrite(_resetPin, HIGH);
109+
}
110+
111+
112+
void PCA9549::reset()
113+
{
114+
digitalWrite(_resetPin, LOW);
115+
delayMicroseconds(1); // TODO datasheet page ? - 500 ns
116+
digitalWrite(_resetPin, HIGH);
117+
}
118+
119+
120+
void PCA9549::setForced(bool forced)
121+
{
122+
_forced = forced;
123+
};
124+
125+
126+
bool PCA9549::getForced()
127+
{
128+
return _forced;
129+
};
130+
131+
132+
int PCA9549::getError()
133+
{
134+
int error = _error;
135+
_error = PCA9549_OK;
136+
return error;
137+
}
138+
139+
140+
// -- END OF FILE --
141+

libraries/PCA9549/PCA9549.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#pragma once
2+
//
3+
// FILE: PCA9549.h
4+
// AUTHOR: Rob Tillaart
5+
// VERSION: 0.1.0
6+
// DATE: 2023-12-12
7+
// PURPOSE: Arduino Library for PCA9549 I2C octal bus switch.
8+
// URL: https://github.com/RobTillaart/PCA9549
9+
10+
11+
#include "Arduino.h"
12+
#include "Wire.h"
13+
14+
15+
#define PCA9549_LIB_VERSION (F("0.1.0"))
16+
17+
#define PCA9549_OK 0x00
18+
19+
20+
class PCA9549
21+
{
22+
public:
23+
// deviceAddress = 0x70 .. 0x77
24+
PCA9549(uint8_t deviceAddress, TwoWire *wire = &Wire);
25+
26+
bool begin(uint8_t mask = 0x00); // default no channels enabled
27+
bool isConnected(); // find multiplexer on I2C bus
28+
29+
30+
// channel = 0..channelCount()-1
31+
bool enableChannel(uint8_t channel); // enable this channel non exclusive
32+
bool disableChannel(uint8_t channel);
33+
bool selectChannel(uint8_t channel); // enable only this channel
34+
bool isEnabled(uint8_t channel);
35+
bool disableAllChannels();
36+
37+
38+
// mask = 0x00 .. 0xFF - every bit is a channel.
39+
// note 1: these are set simultaneously.
40+
bool setChannelMask(uint8_t mask);
41+
uint8_t getChannelMask();
42+
43+
// reset
44+
void setResetPin(uint8_t resetPin);
45+
void reset(); // trigger reset pin
46+
47+
// set forced IO (default false)
48+
void setForced(bool forced = false);
49+
bool getForced();
50+
51+
int getError();
52+
53+
54+
protected:
55+
uint8_t _address;
56+
TwoWire* _wire;
57+
uint8_t _mask; // caching mask = status of channels
58+
uint8_t _resetPin; // default not set == -1 (255)
59+
bool _forced;
60+
int _error;
61+
};
62+
63+
64+
// -- END OF FILE --
65+

0 commit comments

Comments
 (0)