Skip to content

Commit

Permalink
Support RGBW on PCA9632 (MarlinFirmware#20455)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
spamik and thinkyhead committed Jan 16, 2021
1 parent f6d651e commit d317279
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions Marlin/src/feature/leds/pca9632.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@
#ifndef PCA9632_BLU
#define PCA9632_BLU 0x04
#endif
#ifndef PCA9632_WHT
#if HAS_WHITE_LED && !defined(PCA9632_WHT)
#define PCA9632_WHT 0x06
#endif

// If any of the color indexes are greater than 0x04 they can't use auto increment
#if !defined(PCA9632_NO_AUTO_INC) && (PCA9632_RED > 0x04 || PCA9632_GRN > 0x04 || PCA9632_BLU > 0x04 || defined(PCA9632_WHT))
#if !defined(PCA9632_NO_AUTO_INC) && (PCA9632_RED > 0x04 || PCA9632_GRN > 0x04 || PCA9632_BLU > 0x04 || PCA9632_WHT > 0x04)
#define PCA9632_NO_AUTO_INC
#endif

#define LED_OFF 0x00
#define LED_ON 0x01
#define LED_PWM 0x02

#define PCA9632_ADDRESS 0b01100010
#define PCA9632_ADDRESS 0b01100000

byte PCA_init = 0;

Expand All @@ -93,24 +93,23 @@ static void PCA9632_WriteRegister(const byte addr, const byte regadd, const byte
}

static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const byte vr, const byte vg, const byte vb
#if ENABLED(PCA9632_RGBW)
, const byte vw
#endif
) {
#if ENABLED(PCA9632_RGBW)
, const byte vw
#endif
) {
#if DISABLED(PCA9632_NO_AUTO_INC)
uint8_t data[4], len = 4;
uint8_t data[4];
data[0] = PCA9632_AUTO_IND | regadd;
data[1 + (PCA9632_RED >> 1)] = vr;
data[1 + (PCA9632_GRN >> 1)] = vg;
data[1 + (PCA9632_BLU >> 1)] = vb;
Wire.beginTransmission(I2C_ADDRESS(addr));
Wire.write(data, len);
Wire.write(data, sizeof(data));
Wire.endTransmission();
#else
PCA9632_WriteRegister(addr, regadd + (PCA9632_RED >> 1), vr);
PCA9632_WriteRegister(addr, regadd + (PCA9632_GRN >> 1), vg);
PCA9632_WriteRegister(addr, regadd + (PCA9632_BLU >> 1), vb);

#if ENABLED(PCA9632_RGBW)
PCA9632_WriteRegister(addr, regadd + (PCA9632_WHT >> 1), vw);
#endif
Expand Down Expand Up @@ -144,11 +143,10 @@ void PCA9632_set_led_color(const LEDColor &color) {
;

PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, color.r, color.g, color.b
#if ENABLED(PCA9632_RGBW)
, color.w
#endif

);
#if ENABLED(PCA9632_RGBW)
, color.w
#endif
);
PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_LEDOUT, LEDOUT);
}

Expand Down

0 comments on commit d317279

Please sign in to comment.