0.2.5 PCA9634

This commit is contained in:
rob tillaart 2023-01-19 19:09:52 +01:00
parent 2c03a831e7
commit 353b00ec0e
11 changed files with 128 additions and 68 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

View File

@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -6,12 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.5] - 2023-01-19
- fix #22 update readme.md
- update GitHub actions
- update license
- minor edits (comments)
## [0.2.4] - 2022-11-19
- add RP2040 in build-CI
- add changelog.md
## [0.2.3] - 2022-09-11
- update documentation
- fix begin() for ESP32 ambiguity - See PCA9635 #17

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2022-2022 Rob Tillaart
Copyright (c) 2022-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

View File

@ -1,8 +1,8 @@
//
// FILE: PCA9634.cpp
// AUTHOR: Rob Tillaart
// DATE: 03-01-2022
// VERSION: 0.2.4
// DATE: 2022-01-03
// VERSION: 0.2.5
// PURPOSE: Arduino library for PCA9634 I2C LED driver
// URL: https://github.com/RobTillaart/PCA9634
@ -108,6 +108,37 @@ uint8_t PCA9634::writeN(uint8_t channel, uint8_t* arr, uint8_t count)
}
uint8_t PCA9634::writeN_noStop(uint8_t channel, uint8_t* arr, uint8_t count)
{
if (channel + count > _channelCount)
{
_error = PCA9634_ERR_WRITE;
return PCA9634_ERROR;
}
uint8_t base = PCA9634_PWM(channel);
_wire->beginTransmission(_address);
_wire->write(base);
for(uint8_t i = 0; i < count; i++)
{
_wire->write(arr[i]);
}
// OK so far
return PCA9634_OK;
}
uint8_t PCA9634::writeStop()
{
_error = _wire->endTransmission();
if (_error != 0)
{
_error = PCA9634_ERR_I2C;
return PCA9634_ERROR;
}
return PCA9634_OK;
}
uint8_t PCA9634::writeMode(uint8_t reg, uint8_t value)
{
if ((reg == PCA9634_MODE1) || (reg == PCA9634_MODE2))
@ -120,7 +151,7 @@ uint8_t PCA9634::writeMode(uint8_t reg, uint8_t value)
}
// Note 0xFF can also mean an error.... check error flag..
// Note 0xFF can also mean an error.... ==> check error flag.
uint8_t PCA9634::readMode(uint8_t reg)
{
if ((reg == PCA9634_MODE1) || (reg == PCA9634_MODE2))
@ -149,7 +180,7 @@ uint8_t PCA9634::setLedDriverMode(uint8_t channel, uint8_t mode)
uint8_t reg = PCA9634_LEDOUT_BASE + (channel >> 2);
// some bit magic
uint8_t shift = (channel & 0x03) * 2; // 0,2,4,6 places
uint8_t shift = (channel & 0x03) * 2; // 0, 2, 4, 6 places
uint8_t setmask = mode << shift;
uint8_t clrmask = ~(0x03 << shift);
uint8_t value = (readReg(reg) & clrmask) | setmask;
@ -168,7 +199,7 @@ uint8_t PCA9634::getLedDriverMode(uint8_t channel)
}
uint8_t reg = PCA9634_LEDOUT_BASE + (channel >> 2);
uint8_t shift = (channel & 0x03) * 2; // 0,2,4,6 places
uint8_t shift = (channel & 0x03) * 2; // 0, 2, 4, 6 places
uint8_t value = (readReg(reg) >> shift ) & 0x03;
return value;
}

View File

@ -2,8 +2,8 @@
//
// FILE: PCA9634.h
// AUTHOR: Rob Tillaart
// DATE: 03-01-2022
// VERSION: 0.2.4
// DATE: 2022-01-03
// VERSION: 0.2.5
// PURPOSE: Arduino library for PCA9634 I2C LED driver, 8 channel
// URL: https://github.com/RobTillaart/PCA9634
@ -12,7 +12,7 @@
#include "Wire.h"
#define PCA9634_LIB_VERSION (F("0.2.4"))
#define PCA9634_LIB_VERSION (F("0.2.5"))
#define PCA9634_MODE1 0x00
#define PCA9634_MODE2 0x01
@ -59,10 +59,18 @@
#define PCA9634_MODE2_TOTEMPOLE 0x04 // 0 = open drain 1 = totem-pole
#define PCA9634_MODE2_NONE 0x00
// (since 0.2.0)
// Registers in which the ALLCALL and sub-addresses are stored
#define PCA9634_SUBADR(x) (0x0D +(x)) // x = 1..3
#define PCA9634_ALLCALLADR 0x11
// Standard ALLCALL and sub-addresses --> only work for write commands and NOT for read commands
#define PCA9634_ALLCALL 0x70 // TDS of chip says 0xE0, however,
// in this library the LSB is added during the write command
// (0xE0 --> 0b11100000, 0x70 --> 0b1110000)
#define PCA9634_SUB1 0x71 // see line above (0xE2 --> 0x71)
#define PCA9634_SUB2 0x72 // see line above (0xE4 --> 0x72)
#define PCA9634_SUB3 0x74 // see line above (0xE8 --> 0x74)
class PCA9634
{
@ -93,6 +101,12 @@ public:
// generic worker, write N consecutive PWM registers
uint8_t writeN(uint8_t channel, uint8_t* arr, uint8_t count);
// generic worker, write N consecutive PWM registers without Stop command
uint8_t writeN_noStop(uint8_t channel, uint8_t* arr, uint8_t count);
// write stop command to end transmission
uint8_t writeStop();
// reg = 1, 2 check datasheet for values
uint8_t writeMode(uint8_t reg, uint8_t value);
uint8_t readMode(uint8_t reg);
@ -113,6 +127,7 @@ public:
int lastError();
/////////////////////////////////////////////////////
//
// SUB CALL - ALL CALL (since 0.2.0)

View File

@ -55,6 +55,7 @@ Configure LED behaviour.
| PCA9634_LEDPWM | 0x02 | set LED in PWM mode, 0..255 |
| PCA9634_LEDGRPPWM | 0x03 | add LED to the GRPPWM* |
\* all LEDs in the group GRPPWM can be set to the same PWM value in one set.
This is ideal to trigger e.g. multiple LEDs (servo's) at same time.
@ -103,13 +104,14 @@ useful to add or remove a single flag (bit masking).
| PCA9634_MODE1_SUB3 | 0x02 | 0 = disable 1 = enable |
| PCA9634_MODE1_ALLCALL | 0x01 | 0 = disable 1 = enable |
| PCA9634_MODE1_NONE | 0x00 | |
| | | |
| ---- | | |
| PCA9634_MODE2_BLINK | 0x20 | 0 = dim 1 = blink |
| PCA9634_MODE2_INVERT | 0x10 | 0 = normal 1 = inverted |
| PCA9634_MODE2_STOP | 0x08 | 0 = on STOP 1 = on ACK |
| PCA9634_MODE2_TOTEMPOLE | 0x04 | 0 = open drain 1 = totem-pole |
| PCA9634_MODE2_NONE | 0x00 | |
These constants makes it easier to set modes without using a non descriptive
bit mask. The constants can be merged by OR-ing them together, see snippet:
@ -164,6 +166,7 @@ It needs more testing and if there are issues, please report.
AllCall is automatically activated for each device on startup.
#### Description
**SUB CALL** allows one to make groups of PCA9634 devices and control them on group level.
@ -228,16 +231,21 @@ See examples
## Future
#### must
#### Must
- improve documentation
#### should
#### Should
- unit tests
- SUB CALL if possible?
- ALL CALL if possible?
- add examples
#### could
#### Could
- move code from .h to .cpp
- sync with PCA9635 developments
- merge with PCA9635 and a PCA963X base class if possible

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/PCA9634.git"
},
"version": "0.2.4",
"version": "0.2.5",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=PCA9634
version=0.2.4
version=0.2.5
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for PCA9634 I2C LED driver 8 channel

View File

@ -94,4 +94,5 @@ unittest(test_LedDriverMode)
unittest_main()
// --------
// -- END OF FILE --