My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pca9632.cpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Driver for the Philips PCA9632 LED driver.
  24. * Written by Robert Mendon Feb 2017.
  25. */
  26. #include "MarlinConfig.h"
  27. #if ENABLED(PCA9632)
  28. #include "pca9632.h"
  29. #include "leds.h"
  30. #include <Wire.h>
  31. #define PCA9632_MODE1_VALUE 0b00000001 //(ALLCALL)
  32. #define PCA9632_MODE2_VALUE 0b00010101 //(DIMMING, INVERT, CHANGE ON STOP,TOTEM)
  33. #define PCA9632_LEDOUT_VALUE 0b00101010
  34. /* Register addresses */
  35. #define PCA9632_MODE1 0x00
  36. #define PCA9632_MODE2 0x01
  37. #define PCA9632_PWM0 0x02
  38. #define PCA9632_PWM1 0x03
  39. #define PCA9632_PWM2 0x04
  40. #define PCA9632_PWM3 0x05
  41. #define PCA9632_GRPPWM 0x06
  42. #define PCA9632_GRPFREQ 0x07
  43. #define PCA9632_LEDOUT 0x08
  44. #define PCA9632_SUBADR1 0x09
  45. #define PCA9632_SUBADR2 0x0A
  46. #define PCA9632_SUBADR3 0x0B
  47. #define PCA9632_ALLCALLADDR 0x0C
  48. #define PCA9632_NO_AUTOINC 0x00
  49. #define PCA9632_AUTO_ALL 0x80
  50. #define PCA9632_AUTO_IND 0xA0
  51. #define PCA9632_AUTOGLO 0xC0
  52. #define PCA9632_AUTOGI 0xE0
  53. // Red LED0
  54. // Green LED1
  55. // Blue LED2
  56. #define PCA9632_RED 0x00
  57. #define PCA9632_GRN 0x02
  58. #define PCA9632_BLU 0x04
  59. #define LED_OFF 0x00
  60. #define LED_ON 0x01
  61. #define LED_PWM 0x02
  62. #define PCA9632_ADDRESS 0b01100000
  63. byte PCA_init = 0;
  64. static void PCA9632_WriteRegister(const byte addr, const byte regadd, const byte value) {
  65. Wire.beginTransmission(addr);
  66. Wire.write(regadd);
  67. Wire.write(value);
  68. Wire.endTransmission();
  69. }
  70. static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const byte value1, const byte value2, const byte value3) {
  71. Wire.beginTransmission(addr);
  72. Wire.write(PCA9632_AUTO_IND | regadd);
  73. Wire.write(value1);
  74. Wire.write(value2);
  75. Wire.write(value3);
  76. Wire.endTransmission();
  77. }
  78. #if 0
  79. static byte PCA9632_ReadRegister(const byte addr, const byte regadd) {
  80. Wire.beginTransmission(addr);
  81. Wire.write(regadd);
  82. const byte value = Wire.read();
  83. Wire.endTransmission();
  84. return value;
  85. }
  86. #endif
  87. void pca9632_set_led_color(const LEDColor &color) {
  88. if (!PCA_init) {
  89. PCA_init = 1;
  90. Wire.begin();
  91. PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_MODE1, PCA9632_MODE1_VALUE);
  92. PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_MODE2, PCA9632_MODE2_VALUE);
  93. }
  94. const byte LEDOUT = (color.r ? LED_PWM << PCA9632_RED : 0)
  95. | (color.g ? LED_PWM << PCA9632_GRN : 0)
  96. | (color.b ? LED_PWM << PCA9632_BLU : 0);
  97. PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, color.r, color.g, color.b);
  98. PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_LEDOUT, LEDOUT);
  99. }
  100. #endif // PCA9632