mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-20 00:55:58 -04:00
0.1.0 PCA9552
This commit is contained in:
parent
4ea091d924
commit
1988dcd33c
28
libraries/PCA9552/.arduino-ci.yml
Normal file
28
libraries/PCA9552/.arduino-ci.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
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
|
||||||
|
|
4
libraries/PCA9552/.github/FUNDING.yml
vendored
Normal file
4
libraries/PCA9552/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: RobTillaart
|
||||||
|
|
13
libraries/PCA9552/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/PCA9552/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
name: Arduino-lint
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: arduino/arduino-lint-action@v1
|
||||||
|
with:
|
||||||
|
library-manager: update
|
||||||
|
compliance: strict
|
17
libraries/PCA9552/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/PCA9552/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
name: Arduino CI
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
runTest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: 2.6
|
||||||
|
- run: |
|
||||||
|
gem install arduino_ci
|
||||||
|
arduino_ci.rb
|
18
libraries/PCA9552/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/PCA9552/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
name: JSON check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '**.json'
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: json-syntax-check
|
||||||
|
uses: limitusus/json-syntax-check@v1
|
||||||
|
with:
|
||||||
|
pattern: "\\.json$"
|
||||||
|
|
13
libraries/PCA9552/CHANGELOG.md
Normal file
13
libraries/PCA9552/CHANGELOG.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Change Log PCA9552
|
||||||
|
|
||||||
|
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] - 2023-07-17
|
||||||
|
- initial version
|
||||||
|
- based upon PCA9553
|
||||||
|
|
||||||
|
|
21
libraries/PCA9552/LICENSE
Normal file
21
libraries/PCA9552/LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023-2023 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.
|
260
libraries/PCA9552/PCA9552.cpp
Normal file
260
libraries/PCA9552/PCA9552.cpp
Normal file
@ -0,0 +1,260 @@
|
|||||||
|
//
|
||||||
|
// FILE: PCA9552.cpp
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// DATE: 2023-07-17
|
||||||
|
// VERSION: 0.1.0
|
||||||
|
// PURPOSE: Arduino library for for I2C PCA9552 16 channel PWM
|
||||||
|
// URL: https://github.com/RobTillaart/PCA9552
|
||||||
|
|
||||||
|
|
||||||
|
#include "PCA9552.h"
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Constructor
|
||||||
|
//
|
||||||
|
PCA9552::PCA9552(const uint8_t deviceAddress, TwoWire *wire)
|
||||||
|
{
|
||||||
|
_address = deviceAddress;
|
||||||
|
_wire = wire;
|
||||||
|
_outputCount = 16;
|
||||||
|
_error = PCA9552_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined (ESP8266) || defined(ESP32)
|
||||||
|
bool PCA9552::begin(int sda, int scl)
|
||||||
|
{
|
||||||
|
_wire = &Wire;
|
||||||
|
if ((sda < 255) && (scl < 255))
|
||||||
|
{
|
||||||
|
_wire->begin(sda, scl);
|
||||||
|
} else {
|
||||||
|
_wire->begin();
|
||||||
|
}
|
||||||
|
if (! isConnected()) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
bool PCA9552::begin()
|
||||||
|
{
|
||||||
|
_wire->begin();
|
||||||
|
if (! isConnected()) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PCA9552::isConnected()
|
||||||
|
{
|
||||||
|
_wire->beginTransmission(_address);
|
||||||
|
_error = _wire->endTransmission();
|
||||||
|
return (_error == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t PCA9552::reset()
|
||||||
|
{
|
||||||
|
// not most efficient
|
||||||
|
setPrescaler(0, 0); // 44 Hz
|
||||||
|
setPrescaler(1, 0); // 44 Hz
|
||||||
|
setPWM(0, 128); // 50%
|
||||||
|
setPWM(1, 128); // 50%
|
||||||
|
for (int pin = 0; pin < _outputCount; pin++)
|
||||||
|
{
|
||||||
|
setOutputMode(pin, 0); // LOW
|
||||||
|
}
|
||||||
|
return PCA9552_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t PCA9552::getAddress()
|
||||||
|
{
|
||||||
|
return _address;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t PCA9552::outputCount()
|
||||||
|
{
|
||||||
|
return _outputCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// GPIO
|
||||||
|
//
|
||||||
|
uint16_t PCA9552::getInput()
|
||||||
|
{
|
||||||
|
uint16_t reg = readReg(PCA9552_INPUT1);
|
||||||
|
reg <<= 8;
|
||||||
|
reg += readReg(PCA9552_INPUT0);
|
||||||
|
return reg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PCA9552::pinMode(uint8_t pin, uint8_t mode)
|
||||||
|
{
|
||||||
|
if (mode != OUTPUT) setOutputMode(pin, PCA9552_MODE_HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PCA9552::digitalWrite(uint8_t pin, uint8_t val)
|
||||||
|
{
|
||||||
|
if (val == LOW) setOutputMode(pin, PCA9552_MODE_LOW);
|
||||||
|
else setOutputMode(pin, PCA9552_MODE_HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t PCA9552::digitalRead(uint8_t pin)
|
||||||
|
{
|
||||||
|
uint8_t reg = PCA9552_INPUT0;
|
||||||
|
if (pin > 7)
|
||||||
|
{
|
||||||
|
reg += 1;
|
||||||
|
pin -= 8;
|
||||||
|
}
|
||||||
|
uint8_t value = readReg(reg);
|
||||||
|
if ((value >> pin) & 0x01) return HIGH;
|
||||||
|
return LOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PRESCALERS
|
||||||
|
//
|
||||||
|
void PCA9552::setPrescaler(uint8_t gen, uint8_t psc)
|
||||||
|
{
|
||||||
|
if (gen == 0) writeReg(PCA9552_PSC0, psc);
|
||||||
|
else writeReg(PCA9552_PSC1, psc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t PCA9552::getPrescaler(uint8_t gen)
|
||||||
|
{
|
||||||
|
if (gen == 0) return readReg(PCA9552_PSC0);
|
||||||
|
else return readReg(PCA9552_PSC1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PWM
|
||||||
|
//
|
||||||
|
void PCA9552::setPWM(uint8_t gen, uint8_t pwm)
|
||||||
|
{
|
||||||
|
if (gen == 0) writeReg(PCA9552_PWM0, pwm);
|
||||||
|
else writeReg(PCA9552_PWM1, pwm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t PCA9552::getPWM(uint8_t gen)
|
||||||
|
{
|
||||||
|
if (gen == 0) return readReg(PCA9552_PWM0);
|
||||||
|
else return readReg(PCA9552_PWM1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// OUTPUT MODE - MUX SELECTION
|
||||||
|
//
|
||||||
|
uint8_t PCA9552::setOutputMode(uint8_t pin, uint8_t mode)
|
||||||
|
{
|
||||||
|
if (pin >= _outputCount)
|
||||||
|
{
|
||||||
|
_error = PCA9552_ERR_CHAN;
|
||||||
|
return _error;
|
||||||
|
}
|
||||||
|
if (mode > 3)
|
||||||
|
{
|
||||||
|
_error = PCA9552_ERR_MODE;
|
||||||
|
return _error;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t reg = PCA9552_LS0;
|
||||||
|
while (pin > 3)
|
||||||
|
{
|
||||||
|
reg += 1;
|
||||||
|
pin -= 4;
|
||||||
|
}
|
||||||
|
uint8_t ledSelect = readReg(reg);
|
||||||
|
ledSelect &= ~(0x03 << (pin * 2));
|
||||||
|
ledSelect |= (mode << (pin * 2));
|
||||||
|
|
||||||
|
return writeReg(reg, ledSelect);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t PCA9552::getOutputMode(uint8_t pin)
|
||||||
|
{
|
||||||
|
if (pin >= _outputCount)
|
||||||
|
{
|
||||||
|
_error = PCA9552_ERR_CHAN;
|
||||||
|
return _error;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t reg = PCA9552_LS0;
|
||||||
|
while (pin > 3)
|
||||||
|
{
|
||||||
|
reg += 1;
|
||||||
|
pin -= 4;
|
||||||
|
}
|
||||||
|
uint8_t ledSelect = readReg(reg);
|
||||||
|
uint8_t mode = (ledSelect >> (pin * 2)) & 0x03;
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t PCA9552::getLastError()
|
||||||
|
{
|
||||||
|
uint8_t e = _error;
|
||||||
|
_error = PCA9552_OK;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PRIVATE
|
||||||
|
//
|
||||||
|
uint8_t PCA9552::writeReg(uint8_t reg, uint8_t value)
|
||||||
|
{
|
||||||
|
_wire->beginTransmission(_address);
|
||||||
|
_wire->write(reg);
|
||||||
|
_wire->write(value);
|
||||||
|
_error = _wire->endTransmission();
|
||||||
|
|
||||||
|
if (_error == 0) _error = PCA9552_OK;
|
||||||
|
else _error = PCA9552_ERROR;
|
||||||
|
return _error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t PCA9552::readReg(uint8_t reg)
|
||||||
|
{
|
||||||
|
_wire->beginTransmission(_address);
|
||||||
|
_wire->write(reg);
|
||||||
|
_error = _wire->endTransmission();
|
||||||
|
if (_error == 0) _error = PCA9552_OK;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_error = PCA9552_ERR_I2C;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (_wire->requestFrom(_address, (uint8_t)1) != 1)
|
||||||
|
{
|
||||||
|
_error = PCA9552_ERROR;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
_error = PCA9552_OK;
|
||||||
|
return _wire->read();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
||||||
|
|
109
libraries/PCA9552/PCA9552.h
Normal file
109
libraries/PCA9552/PCA9552.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#pragma once
|
||||||
|
//
|
||||||
|
// FILE: PCA9552.h
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// DATE: 2023-07-17
|
||||||
|
// VERSION: 0.1.0
|
||||||
|
// PUPROSE: Arduino library for for I2C PCA9552 16 channel PWM
|
||||||
|
// URL: https://github.com/RobTillaart/PCA9552
|
||||||
|
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Wire.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define PCA9552_LIB_VERSION (F("0.1.0"))
|
||||||
|
|
||||||
|
|
||||||
|
// REGISTERS
|
||||||
|
#define PCA9552_INPUT0 0x00
|
||||||
|
#define PCA9552_INPUT1 0x01
|
||||||
|
#define PCA9552_PSC0 0x02
|
||||||
|
#define PCA9552_PWM0 0x03
|
||||||
|
#define PCA9552_PSC1 0x04
|
||||||
|
#define PCA9552_PWM1 0x05
|
||||||
|
#define PCA9552_LS0 0x06
|
||||||
|
#define PCA9552_LS1 0x07
|
||||||
|
#define PCA9552_LS2 0x08
|
||||||
|
#define PCA9552_LS3 0x09
|
||||||
|
|
||||||
|
|
||||||
|
// MUX OUTPUT MODES
|
||||||
|
#define PCA9552_MODE_LOW 0
|
||||||
|
#define PCA9552_MODE_HIGH 1
|
||||||
|
#define PCA9552_MODE_PWM0 2
|
||||||
|
#define PCA9552_MODE_PWM1 3
|
||||||
|
|
||||||
|
|
||||||
|
// ERROR CODES (not all used yet)
|
||||||
|
#define PCA9552_OK 0x00
|
||||||
|
#define PCA9552_ERROR 0xFF
|
||||||
|
#define PCA9552_ERR_WRITE 0xFE
|
||||||
|
#define PCA9552_ERR_CHAN 0xFD
|
||||||
|
#define PCA9552_ERR_MODE 0xFC
|
||||||
|
#define PCA9552_ERR_REG 0xFB
|
||||||
|
#define PCA9552_ERR_I2C 0xFA
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// CLASS
|
||||||
|
//
|
||||||
|
class PCA9552
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit PCA9552(const uint8_t deviceAddress, TwoWire *wire = &Wire);
|
||||||
|
|
||||||
|
#if defined (ESP8266) || defined(ESP32)
|
||||||
|
bool begin(int sda, int scl);
|
||||||
|
#endif
|
||||||
|
bool begin();
|
||||||
|
bool isConnected();
|
||||||
|
uint8_t reset();
|
||||||
|
|
||||||
|
uint8_t getAddress();
|
||||||
|
uint8_t outputCount();
|
||||||
|
|
||||||
|
// GPIO
|
||||||
|
uint16_t getInput();
|
||||||
|
void pinMode(uint8_t pin, uint8_t mode);
|
||||||
|
void digitalWrite(uint8_t pin, uint8_t value);
|
||||||
|
uint8_t digitalRead(uint8_t pin);
|
||||||
|
|
||||||
|
// PRESCALERS
|
||||||
|
void setPrescaler(uint8_t generator, uint8_t prescaler = 0);
|
||||||
|
uint8_t getPrescaler(uint8_t generator);
|
||||||
|
|
||||||
|
// PWM
|
||||||
|
void setPWM(uint8_t generator, uint8_t pwm = 128);
|
||||||
|
uint8_t getPWM(uint8_t generator);
|
||||||
|
|
||||||
|
|
||||||
|
// OUTPUT MODE - MUX SELECTION
|
||||||
|
// pin: 0..3
|
||||||
|
// mode:
|
||||||
|
// 0 = output is set LOW (LED on)
|
||||||
|
// 1 = output is set high-impedance (LED off; default)
|
||||||
|
// 2 = output blinks at PWM0 rate
|
||||||
|
// 3 = output blinks at PWM1 rate
|
||||||
|
uint8_t setOutputMode(uint8_t pin, uint8_t mode);
|
||||||
|
uint8_t getOutputMode(uint8_t pin);
|
||||||
|
|
||||||
|
// ERROR
|
||||||
|
uint8_t getLastError();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t writeReg(uint8_t reg, uint8_t value);
|
||||||
|
uint8_t readReg(uint8_t reg);
|
||||||
|
|
||||||
|
uint8_t _address;
|
||||||
|
uint8_t _outputCount;
|
||||||
|
uint8_t _error;
|
||||||
|
|
||||||
|
TwoWire* _wire;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
||||||
|
|
197
libraries/PCA9552/README.md
Normal file
197
libraries/PCA9552/README.md
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
|
||||||
|
[![Arduino CI](https://github.com/RobTillaart/PCA9552/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||||
|
[![Arduino-lint](https://github.com/RobTillaart/PCA9552/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PCA9552/actions/workflows/arduino-lint.yml)
|
||||||
|
[![JSON check](https://github.com/RobTillaart/PCA9552/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PCA9552/actions/workflows/jsoncheck.yml)
|
||||||
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PCA9552/blob/master/LICENSE)
|
||||||
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PCA9552.svg?maxAge=3600)](https://github.com/RobTillaart/PCA9552/releases)
|
||||||
|
|
||||||
|
|
||||||
|
# PCA9552
|
||||||
|
|
||||||
|
Arduino library for PCA9552 I2C 8 bit PWM LED driver, 16 channel.
|
||||||
|
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
This experimental library is to control the I2C PCA9552 PWM extender.
|
||||||
|
|
||||||
|
It is derived from the PCA9553 library and kept in sync if possible.
|
||||||
|
|
||||||
|
This device has two possible hardcoded I2C addresses 0x62 and 0x63,
|
||||||
|
see table below.
|
||||||
|
If you need to connect more PCA9552 devices to a single I2C bus you
|
||||||
|
need a I2C multiplexer like https://github.com/RobTillaart/TCA9548.
|
||||||
|
|
||||||
|
The device has two PWM "generators", 0 and 1, and one can set the
|
||||||
|
duty cycle and the frequency by means of a pre-scaler.
|
||||||
|
|
||||||
|
Every output channel 0..3 can select to which PWM generator it is
|
||||||
|
connected, or if it is set to ON or OFF.
|
||||||
|
|
||||||
|
The output channels can also be used as generic GPIO, however that
|
||||||
|
is not implemented in the first release.
|
||||||
|
|
||||||
|
|
||||||
|
#### From datasheet
|
||||||
|
|
||||||
|
Maximum output sink current is 25 mA per bit and 100 mA per package.
|
||||||
|
|
||||||
|
Power-On Reset (POR) initializes the registers to their default state,
|
||||||
|
all zeroes, causing the bits to be set HIGH (LED off).
|
||||||
|
|
||||||
|
|
||||||
|
#### Related
|
||||||
|
|
||||||
|
- https://github.com/RobTillaart/PCA9551 (8 channel)
|
||||||
|
- https://github.com/RobTillaart/PCA9552 (16 channel)
|
||||||
|
- https://github.com/RobTillaart/PCA9553 (4 channel)
|
||||||
|
|
||||||
|
Follow up series
|
||||||
|
- https://github.com/RobTillaart/PCA9634 (8 channel)
|
||||||
|
- https://github.com/RobTillaart/PCA9635 (16 channel)
|
||||||
|
- https://github.com/RobTillaart/PCA9685_RT (16 channel)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Interface
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include "PCA9552.h"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Constructor
|
||||||
|
|
||||||
|
- **PCA9552(uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor with I2C device address, Address = 0x62 or 0x63.
|
||||||
|
and optional the Wire interface as parameter.
|
||||||
|
- **bool begin()** initializes the library after startup.
|
||||||
|
Returns true if device address is available on I2C bus.
|
||||||
|
- **bool begin(int sda, int scl)**
|
||||||
|
idem, ESP32 ESP8266 only.
|
||||||
|
- **bool isConnected()** checks if address is available on I2C bus.
|
||||||
|
- **uint8_t getAddress()** returns I2C address.
|
||||||
|
- **uint8_t outputCount()** returns the number of channels = 16.
|
||||||
|
- **uint8_t reset()**
|
||||||
|
|
||||||
|
|
||||||
|
#### GPIO
|
||||||
|
|
||||||
|
- **uint16_t getInput()** read all current output levels.
|
||||||
|
- **void pinMode(uint8_t pin, uint8_t mode)** set output pin to INPUT or OUTPUT.
|
||||||
|
- **void digitalWrite(uint8_t pin, uint8_t value)** set output pin HIGH or LOW.
|
||||||
|
- **uint8_t digitalRead(uint8_t pin)** read current state of output pin.
|
||||||
|
|
||||||
|
|
||||||
|
#### Prescaler Frequency
|
||||||
|
|
||||||
|
Get and set the pre-scaler of the PWM generator.
|
||||||
|
|
||||||
|
- **void setPrescaler(uint8_t gen, uint8_t psc = 255)** set pre-scaler for generator, default 255.
|
||||||
|
- **uint8_t getPrescaler(uint8_t gen)** get the set value.
|
||||||
|
|
||||||
|
gen = 0 or 1
|
||||||
|
|
||||||
|
The main oscillator frequency can be divided by a pre-scaler.
|
||||||
|
The period of ```BLINK = (PSC + 1) / 44```
|
||||||
|
This gives the output a blink range of 0.172 Hz to 44 Hz.
|
||||||
|
|
||||||
|
Some "magic" pre-scalers. (to be confirmed).
|
||||||
|
|
||||||
|
| psc | Period | Frequency |
|
||||||
|
|:-----:|:--------:|:-----------:|
|
||||||
|
| 0 | 0.0227 | 44.00 Hz |
|
||||||
|
| 1 | 0.0455 | 22.00 Hz |
|
||||||
|
| 3 | 0.0909 | 11.00 Hz |
|
||||||
|
| 7 | 0.1818 | 5.50 Hz |
|
||||||
|
| 10 | 0.250 | 4.00 Hz |
|
||||||
|
| 21 | 0.500 | 2.00 Hz |
|
||||||
|
| 43 | 1.000 | 1.00 Hz |
|
||||||
|
| 87 | 2.000 | 0.50 Hz |
|
||||||
|
| 175 | 4.000 | 0.25 Hz |
|
||||||
|
| 219 | 5.000 | 0.20 Hz |
|
||||||
|
| 255 | 5.818 | 0.172 Hz |
|
||||||
|
|
||||||
|
|
||||||
|
#### PWM
|
||||||
|
|
||||||
|
Get and set the duty cycle of the PWM generator.
|
||||||
|
|
||||||
|
- **void setPWM(uint8_t gen, uint8_t psc = 128)** set PWM for generator,
|
||||||
|
default value = 128.
|
||||||
|
- **uint8_t getPWM(uint8_t gen)** get the set value.
|
||||||
|
|
||||||
|
gen = 0 or 1
|
||||||
|
|
||||||
|
The duty cycle of ```BLINK = (256 - PWM) / 256```
|
||||||
|
|
||||||
|
| pwm | Duty Cycle |
|
||||||
|
|:-----:|:------------:|
|
||||||
|
| 0 | 0% |
|
||||||
|
| 64 | 25% |
|
||||||
|
| 128 | 50% |
|
||||||
|
| 192 | 75% |
|
||||||
|
| 255 | 100% |
|
||||||
|
|
||||||
|
Note: one might need a Gamma brightness correction - https://github.com/RobTillaart/GAMMA
|
||||||
|
|
||||||
|
|
||||||
|
#### Output Mode
|
||||||
|
|
||||||
|
- **uint8_t setOutputMode(uint8_t pin, uint8_t mode)** set the mode for
|
||||||
|
the selected output pin to one of 4 modi operandi.
|
||||||
|
See table below.
|
||||||
|
- pin == 0..15, mode == 0..3, see table below.
|
||||||
|
- returns 0 if OK
|
||||||
|
- returns error code if parameter is out of range.
|
||||||
|
- **uint8_t getOutputMode(uint8_t led)** returns current setting.
|
||||||
|
- pin == 0..15
|
||||||
|
- returns mode, see table below.
|
||||||
|
- returns error code if parameter is out of range.
|
||||||
|
|
||||||
|
| Define | Value | Output pin |
|
||||||
|
|:--------------------|:-------:|:---------------------|
|
||||||
|
| PCA9552_MODE_LOW | 0 | is set LOW (LED on)
|
||||||
|
| PCA9552_MODE_HIGH | 1 | is set high-impedance (LED off; default)
|
||||||
|
| PCA9552_MODE_PWM0 | 2 | blinks at PWM0 rate
|
||||||
|
| PCA9552_MODE_PWM1 | 3 | blinks at PWM1 rate
|
||||||
|
|
||||||
|
|
||||||
|
#### Power On Reset
|
||||||
|
|
||||||
|
The PCA9552 will keep its settings as long as it is powered on.
|
||||||
|
This means it can start with an previous configuration when uploading
|
||||||
|
two different sketches short after each other.
|
||||||
|
|
||||||
|
To handle this the library has a **reset()** function which sets
|
||||||
|
the device in the Power On state.
|
||||||
|
|
||||||
|
|
||||||
|
#### Error codes
|
||||||
|
|
||||||
|
These are kept similar to PCA9635 et al error codes.
|
||||||
|
|
||||||
|
| Error code | Value | Description |
|
||||||
|
|:------------------------|:-------:|:-----------------------|
|
||||||
|
| PCA9552_OK | 0x00 | Everything went well
|
||||||
|
| PCA9552_ERROR | 0xFF | Generic error
|
||||||
|
| PCA9552_ERR_WRITE | 0xFE |
|
||||||
|
| PCA9552_ERR_CHAN | 0xFD | output pin out of range / channel error
|
||||||
|
| PCA9552_ERR_MODE | 0xFC | mode parameter out of range.
|
||||||
|
| PCA9552_ERR_REG | 0xFB |
|
||||||
|
| PCA9552_ERR_I2C | 0xFA |
|
||||||
|
|
||||||
|
|
||||||
|
## Future
|
||||||
|
|
||||||
|
#### Must
|
||||||
|
|
||||||
|
- improve documentation
|
||||||
|
- keep in sync with PCA9553
|
||||||
|
|
||||||
|
#### Should
|
||||||
|
|
||||||
|
#### Could
|
||||||
|
|
||||||
|
#### Wont
|
||||||
|
|
||||||
|
|
48
libraries/PCA9552/examples/PCA9552_PWM/PCA9552_PWM.ino
Normal file
48
libraries/PCA9552/examples/PCA9552_PWM/PCA9552_PWM.ino
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
//
|
||||||
|
// FILE: PCA9552_PWM.ino
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// DATE: 2023-07-18
|
||||||
|
// PURPOSE: test PCA9552 library
|
||||||
|
// URL: https://github.com/RobTillaart/PCA9552
|
||||||
|
//
|
||||||
|
// Connect LEDs from pin 0 and pin 1 with a resistor to 5V
|
||||||
|
// See datasheet
|
||||||
|
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Wire.h"
|
||||||
|
#include "PCA9552.h"
|
||||||
|
|
||||||
|
|
||||||
|
PCA9552 leds(0x62);
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.print("PCA9552_LIB_VERSION: ");
|
||||||
|
Serial.println(PCA9552_LIB_VERSION);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
if (leds.begin() == false)
|
||||||
|
{
|
||||||
|
Serial.println("Could not connect.");
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
leds.setOutputMode(0, PCA9552_MODE_PWM0);
|
||||||
|
leds.setOutputMode(1, PCA9552_MODE_PWM1);
|
||||||
|
|
||||||
|
leds.setPrescaler(0, 43); // 1 Hz
|
||||||
|
leds.setPWM(0, 128); // 50% duty cycle
|
||||||
|
leds.setPrescaler(1, 21); // 2 Hz
|
||||||
|
leds.setPWM(1, 32); // 12% duty cycle
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
53
libraries/PCA9552/examples/PCA9552_blink/PCA9552_blink.ino
Normal file
53
libraries/PCA9552/examples/PCA9552_blink/PCA9552_blink.ino
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
//
|
||||||
|
// FILE: PCA9552_blink.ino
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// DATE: 2023-07-18
|
||||||
|
// PURPOSE: test PCA9552 library
|
||||||
|
// URL: https://github.com/RobTillaart/PCA9552
|
||||||
|
//
|
||||||
|
// Connect LEDs from pin 0 and pin 1 with a resistor to 5V
|
||||||
|
// See datasheet
|
||||||
|
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Wire.h"
|
||||||
|
#include "PCA9552.h"
|
||||||
|
|
||||||
|
|
||||||
|
PCA9552 leds(0x62);
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.print("PCA9552_LIB_VERSION: ");
|
||||||
|
Serial.println(PCA9552_LIB_VERSION);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
if (leds.begin() == false)
|
||||||
|
{
|
||||||
|
Serial.println("Could not connect.");
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GPIO
|
||||||
|
// not mandatory, just to make it explicit
|
||||||
|
leds.pinMode(0, OUTPUT);
|
||||||
|
leds.pinMode(1, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
leds.digitalWrite(0, LOW);
|
||||||
|
delay(500);
|
||||||
|
leds.digitalWrite(1, LOW);
|
||||||
|
delay(500);
|
||||||
|
leds.digitalWrite(0,HIGH);
|
||||||
|
delay(500);
|
||||||
|
leds.digitalWrite(1,HIGH);
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
@ -0,0 +1,53 @@
|
|||||||
|
//
|
||||||
|
// FILE: PCA9552_digitalRead.ino
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// DATE: 2023-07-18
|
||||||
|
// PURPOSE: test PCA9552 library
|
||||||
|
// URL: https://github.com/RobTillaart/PCA9552
|
||||||
|
//
|
||||||
|
// Connect pin 0 to 4 to either +5V or to GND
|
||||||
|
// to read LOW/HIGH values
|
||||||
|
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Wire.h"
|
||||||
|
#include "PCA9552.h"
|
||||||
|
|
||||||
|
|
||||||
|
PCA9552 leds(0x62);
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.print("PCA9552_LIB_VERSION: ");
|
||||||
|
Serial.println(PCA9552_LIB_VERSION);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
if (leds.begin() == false)
|
||||||
|
{
|
||||||
|
Serial.println("Could not connect.");
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int pin = 0; pin < leds.outputCount(); pin++)
|
||||||
|
{
|
||||||
|
leds.pinMode(pin, INPUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
for (int pin = 0; pin < leds.outputCount(); pin++)
|
||||||
|
{
|
||||||
|
int x = leds.digitalRead(pin);
|
||||||
|
Serial.print(x);
|
||||||
|
Serial.print('\t');
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
53
libraries/PCA9552/examples/PCA9552_test01/PCA9552_test01.ino
Normal file
53
libraries/PCA9552/examples/PCA9552_test01/PCA9552_test01.ino
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
//
|
||||||
|
// FILE: PCA9552_test01.ino
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// DATE: 2023-07-16
|
||||||
|
// PURPOSE: test PCA9552 library
|
||||||
|
// URL: https://github.com/RobTillaart/PCA9552
|
||||||
|
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Wire.h"
|
||||||
|
#include "PCA9552.h"
|
||||||
|
|
||||||
|
|
||||||
|
PCA9552 leds(0x62);
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.print("PCA9552_LIB_VERSION: ");
|
||||||
|
Serial.println(PCA9552_LIB_VERSION);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
if (leds.begin() == false)
|
||||||
|
{
|
||||||
|
Serial.println("Could not connect.");
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// default
|
||||||
|
leds.setPrescaler(0, 255);
|
||||||
|
leds.setPWM(0, 128);
|
||||||
|
|
||||||
|
// different
|
||||||
|
leds.setPrescaler(1, 113);
|
||||||
|
leds.setPWM(1, 32);
|
||||||
|
|
||||||
|
// all output pins in a different mode
|
||||||
|
leds.setOutputMode(0, PCA9552_MODE_LOW);
|
||||||
|
leds.setOutputMode(1, PCA9552_MODE_HIGH);
|
||||||
|
leds.setOutputMode(2, PCA9552_MODE_PWM0);
|
||||||
|
leds.setOutputMode(3, PCA9552_MODE_PWM1);
|
||||||
|
|
||||||
|
Serial.println("done...");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
48
libraries/PCA9552/examples/PCA9552_test02/PCA9552_test02.ino
Normal file
48
libraries/PCA9552/examples/PCA9552_test02/PCA9552_test02.ino
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
//
|
||||||
|
// FILE: PCA9552_test02.ino
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// DATE: 2023-07-17
|
||||||
|
// PURPOSE: test PCA9552 library
|
||||||
|
// URL: https://github.com/RobTillaart/PCA9552
|
||||||
|
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Wire.h"
|
||||||
|
#include "PCA9552.h"
|
||||||
|
|
||||||
|
|
||||||
|
PCA9552 leds(0x62);
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.print("PCA9552_LIB_VERSION: ");
|
||||||
|
Serial.println(PCA9552_LIB_VERSION);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
if (leds.begin() == false)
|
||||||
|
{
|
||||||
|
Serial.println("Could not connect.");
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// random blink
|
||||||
|
leds.digitalWrite(0, random(2));
|
||||||
|
|
||||||
|
// steady blink
|
||||||
|
leds.digitalWrite(1, !leds.digitalRead(1));
|
||||||
|
|
||||||
|
// output 2 follows 3
|
||||||
|
leds.digitalWrite(2, leds.digitalRead(3));
|
||||||
|
leds.digitalWrite(3, random(2));
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
@ -0,0 +1,119 @@
|
|||||||
|
//
|
||||||
|
// FILE: PCA9552_test_registers.ino
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// PURPOSE: test PCA9552 device registers read back
|
||||||
|
// URL: https://github.com/RobTillaart/PCA9552
|
||||||
|
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Wire.h"
|
||||||
|
#include "PCA9552.h"
|
||||||
|
|
||||||
|
|
||||||
|
PCA9552 leds(0x62);
|
||||||
|
|
||||||
|
|
||||||
|
void test_GPIO()
|
||||||
|
{
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
|
for (int i = 0; i < leds.outputCount(); i++)
|
||||||
|
{
|
||||||
|
leds.digitalWrite(i, LOW);
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.print(leds.digitalRead(i));
|
||||||
|
Serial.print("\t");
|
||||||
|
leds.digitalWrite(i, HIGH);
|
||||||
|
Serial.print(leds.digitalRead(i));
|
||||||
|
Serial.print("\n");
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_prescaler()
|
||||||
|
{
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
|
for (uint8_t val = 0; val < 255; val += 5)
|
||||||
|
{
|
||||||
|
leds.setPrescaler(0, val);
|
||||||
|
leds.setPrescaler(1, val);
|
||||||
|
Serial.print(leds.getPrescaler(0));
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.println(leds.getPrescaler(1));
|
||||||
|
Serial.print("\n");
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_PWM()
|
||||||
|
{
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
|
for (uint8_t val = 0; val < 255; val += 5)
|
||||||
|
{
|
||||||
|
leds.setPWM(0, val);
|
||||||
|
leds.setPWM(1, val);
|
||||||
|
Serial.print(leds.getPWM(0));
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.println(leds.getPWM(1));
|
||||||
|
Serial.print("\n");
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_source()
|
||||||
|
{
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
|
for (uint8_t mode = 0; mode < 4; mode++)
|
||||||
|
{
|
||||||
|
leds.setOutputMode(0, mode);
|
||||||
|
leds.setOutputMode(1, mode);
|
||||||
|
leds.setOutputMode(2, mode);
|
||||||
|
leds.setOutputMode(3, mode);
|
||||||
|
|
||||||
|
Serial.print(leds.getOutputMode(0));
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.print(leds.getOutputMode(1));
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.print(leds.getOutputMode(2));
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.print(leds.getOutputMode(3));
|
||||||
|
Serial.print("\n");
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.print("PCA9552_LIB_VERSION: ");
|
||||||
|
Serial.println(PCA9552_LIB_VERSION);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
if (leds.begin() == false)
|
||||||
|
{
|
||||||
|
Serial.println("Could not connect.");
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(leds.getAddress(), HEX);
|
||||||
|
Serial.println(leds.outputCount());
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
test_GPIO();
|
||||||
|
test_prescaler();
|
||||||
|
test_PWM();
|
||||||
|
test_source();
|
||||||
|
|
||||||
|
Serial.println("\ndone...");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
43
libraries/PCA9552/keywords.txt
Normal file
43
libraries/PCA9552/keywords.txt
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# Syntax Colouring Map for PCA9552
|
||||||
|
|
||||||
|
|
||||||
|
# Data types (KEYWORD1)
|
||||||
|
PCA9552 KEYWORD1
|
||||||
|
|
||||||
|
|
||||||
|
# Methods and Functions (KEYWORD2)
|
||||||
|
begin KEYWORD2
|
||||||
|
|
||||||
|
isConnected KEYWORD2
|
||||||
|
getAddress KEYWORD2
|
||||||
|
outputCount KEYWORD2
|
||||||
|
reset KEYWORD2
|
||||||
|
|
||||||
|
getInput KEYWORD2
|
||||||
|
pinMode KEYWORD2
|
||||||
|
digitalWrite KEYWORD2
|
||||||
|
digitalRead KEYWORD2
|
||||||
|
|
||||||
|
setPrescaler KEYWORD2
|
||||||
|
getPrescaler KEYWORD2
|
||||||
|
|
||||||
|
setPWM KEYWORD2
|
||||||
|
getPWM KEYWORD2
|
||||||
|
|
||||||
|
setOutputMode KEYWORD2
|
||||||
|
getOutputMode KEYWORD2
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Constants ( LITERAL1)
|
||||||
|
#
|
||||||
|
PCA9552_LIB_VERSION LITERAL1
|
||||||
|
|
||||||
|
PCA9552_OK LITERAL1
|
||||||
|
PCA9552_ERROR LITERAL1
|
||||||
|
|
||||||
|
PCA9552_ERR_WRITE LITERAL1
|
||||||
|
PCA9552_ERR_CHAN LITERAL1
|
||||||
|
PCA9552_ERR_MODE LITERAL1
|
||||||
|
PCA9552_ERR_REG LITERAL1
|
||||||
|
PCA9552_ERR_I2C LITERAL1
|
23
libraries/PCA9552/library.json
Normal file
23
libraries/PCA9552/library.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "PCA9552",
|
||||||
|
"keywords": "I2C,PCA9552,PWM",
|
||||||
|
"description": "Arduino library for PCA9552 I2C LED driver, 16 channel",
|
||||||
|
"authors":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Rob Tillaart",
|
||||||
|
"email": "Rob.Tillaart@gmail.com",
|
||||||
|
"maintainer": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"repository":
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/RobTillaart/PCA9552.git"
|
||||||
|
},
|
||||||
|
"version": "0.1.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"frameworks": "arduino",
|
||||||
|
"platforms": "*",
|
||||||
|
"headers": "PCA9552.h"
|
||||||
|
}
|
11
libraries/PCA9552/library.properties
Normal file
11
libraries/PCA9552/library.properties
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
name=PCA9552
|
||||||
|
version=0.1.0
|
||||||
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
|
sentence=Arduino library for PCA9552 I2C LED driver 16 channel
|
||||||
|
paragraph=
|
||||||
|
category=Signal Input/Output
|
||||||
|
url=https://github.com/RobTillaart/PCA9552
|
||||||
|
architectures=*
|
||||||
|
includes=PCA9552.h
|
||||||
|
depends=
|
95
libraries/PCA9552/test/unit_test_001.cpp
Normal file
95
libraries/PCA9552/test/unit_test_001.cpp
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
//
|
||||||
|
// FILE: unit_test_001.cpp
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// DATE: 2023-07-17
|
||||||
|
// PURPOSE: unit tests for the PCA9552 I2C LED driver
|
||||||
|
// https://github.com/RobTillaart/PCA9552
|
||||||
|
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||||
|
//
|
||||||
|
|
||||||
|
// supported assertions
|
||||||
|
// ----------------------------
|
||||||
|
// assertEqual(expected, actual); // a == b
|
||||||
|
// assertNotEqual(unwanted, actual); // a != b
|
||||||
|
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
|
||||||
|
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
|
||||||
|
// assertLess(upperBound, actual); // a < b
|
||||||
|
// assertMore(lowerBound, actual); // a > b
|
||||||
|
// assertLessOrEqual(upperBound, actual); // a <= b
|
||||||
|
// assertMoreOrEqual(lowerBound, actual); // a >= b
|
||||||
|
// assertTrue(actual);
|
||||||
|
// assertFalse(actual);
|
||||||
|
// assertNull(actual);
|
||||||
|
|
||||||
|
// // special cases for floats
|
||||||
|
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
|
||||||
|
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
|
||||||
|
// assertInfinity(actual); // isinf(a)
|
||||||
|
// assertNotInfinity(actual); // !isinf(a)
|
||||||
|
// assertNAN(arg); // isnan(a)
|
||||||
|
// assertNotNAN(arg); // !isnan(a)
|
||||||
|
|
||||||
|
#include <ArduinoUnitTests.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "PCA9552.h"
|
||||||
|
|
||||||
|
|
||||||
|
unittest_setup()
|
||||||
|
{
|
||||||
|
fprintf(stderr, "PCA9552_LIB_VERSION: %s\n", (char *) PCA9552_LIB_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unittest_teardown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unittest(test_constants)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "\nregisters");
|
||||||
|
assertEqual(PCA9552_INPUT0 , 0x00);
|
||||||
|
assertEqual(PCA9552_INPUT1 , 0x01);
|
||||||
|
assertEqual(PCA9552_PSC0 , 0x02);
|
||||||
|
assertEqual(PCA9552_PWM0 , 0x03);
|
||||||
|
assertEqual(PCA9552_PSC1 , 0x04);
|
||||||
|
assertEqual(PCA9552_PWM1 , 0x05);
|
||||||
|
assertEqual(PCA9552_LS0 , 0x06);
|
||||||
|
assertEqual(PCA9552_LS1 , 0x07);
|
||||||
|
assertEqual(PCA9552_LS2 , 0x08);
|
||||||
|
assertEqual(PCA9552_LS3 , 0x09);
|
||||||
|
|
||||||
|
fprintf(stderr, "\noutput modi");
|
||||||
|
assertEqual(PCA9552_MODE_LOW , 0x00);
|
||||||
|
assertEqual(PCA9552_MODE_HIGH , 0x01);
|
||||||
|
assertEqual(PCA9552_MODE_PWM0 , 0x02);
|
||||||
|
assertEqual(PCA9552_MODE_PWM1 , 0x03);
|
||||||
|
|
||||||
|
fprintf(stderr, "\nerrorcodes");
|
||||||
|
assertEqual(PCA9552_OK , 0x00);
|
||||||
|
assertEqual(PCA9552_ERROR , 0xFF);
|
||||||
|
assertEqual(PCA9552_ERR_WRITE , 0xFE);
|
||||||
|
assertEqual(PCA9552_ERR_CHAN , 0xFD);
|
||||||
|
assertEqual(PCA9552_ERR_MODE , 0xFC);
|
||||||
|
assertEqual(PCA9552_ERR_REG , 0xFB);
|
||||||
|
assertEqual(PCA9552_ERR_I2C , 0xFA);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unittest(test_constructor)
|
||||||
|
{
|
||||||
|
PCA9552 pca(0x62);
|
||||||
|
|
||||||
|
assertEqual(16, pca.outputCount());
|
||||||
|
assertEqual(0x62, pca.getAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
// need mock up for more tests.
|
||||||
|
// low prio.
|
||||||
|
|
||||||
|
unittest_main()
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
||||||
|
|
Loading…
Reference in New Issue
Block a user