Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add invert control #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/PCA9633.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ void PCA9633::setDrvState(uint8_t state) {
writeReg(REG_MODE2, newReg);
}

void PCA9633::setInvertState(uint8_t invert) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code does not compile because invert needs to be renamed to state.


uint8_t prevReg = readReg(REG_MODE2);
uint8_t newReg;

// first clear the INVRT bit
newReg = prevReg & ~(1 << BIT_INVRT);

// second set new state to specified invrt
newReg |= (state << BIT_INVRT);

writeReg(REG_MODE2, newReg);
}

void PCA9633::setAutoIncrement(uint8_t option) {

uint8_t newReg;
Expand Down
21 changes: 21 additions & 0 deletions src/PCA9633.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@
*/
#define OUTDRV_TOTEM_POLE 1

// LED driver invert mode, INVRT (page 12, table 9, MODE2 register table, also see section 7.7)

/**
* The 4 LED outputs are configured with non-inverting outputs
*/
#define INVERT_OFF 0

/**
* The 4 LED outputs are configured with inverting outputs
*/
#define INVERT_ON 1

// LED driver output state, LEDOUT (page 14, below table 13)

/**
Expand Down Expand Up @@ -404,6 +416,15 @@ class PCA9633 {
*/
void setDrvState(uint8_t state);

/**
* Set the global output invert mode. There are two types:
* - INVERT_OFF
* - INVERT_ON
*
* @param state One of the two possible states
*/
void setInvertState(uint8_t state);

/**
* Set the LED driver output state for a given channel. There are four states:
* - LDR_STATE_OFF
Expand Down