My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

pca9632.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #define PCA9632_MODE1_VALUE 0b00000001 //(ALLCALL)
  30. #define PCA9632_MODE2_VALUE 0b00010101 //(DIMMING, INVERT, CHANGE ON STOP,TOTEM)
  31. #define PCA9632_LEDOUT_VALUE 0b00101010
  32. /* Register addresses */
  33. #define PCA9632_MODE1 0x00
  34. #define PCA9632_MODE2 0x01
  35. #define PCA9632_PWM0 0x02
  36. #define PCA9632_PWM1 0x03
  37. #define PCA9632_PWM2 0x04
  38. #define PCA9632_PWM3 0x05
  39. #define PCA9632_GRPPWM 0x06
  40. #define PCA9632_GRPFREQ 0x07
  41. #define PCA9632_LEDOUT 0x08
  42. #define PCA9632_SUBADR1 0x09
  43. #define PCA9632_SUBADR2 0x0A
  44. #define PCA9632_SUBADR3 0x0B
  45. #define PCA9632_ALLCALLADDR 0x0C
  46. #define PCA9632_NO_AUTOINC 0x00
  47. #define PCA9632_AUTO_ALL 0x80
  48. #define PCA9632_AUTO_IND 0xA0
  49. #define PCA9632_AUTOGLO 0xC0
  50. #define PCA9632_AUTOGI 0xE0
  51. // Red LED0
  52. // Green LED1
  53. // Blue LED2
  54. #define PCA9632_RED 0x00
  55. #define PCA9632_GRN 0x02
  56. #define PCA9632_BLU 0x04
  57. #define LED_OFF 0x00
  58. #define LED_ON 0x01
  59. #define LED_PWM 0x02
  60. #define PCA9632_ADDRESS 0b01100000
  61. byte PCA_init = 0;
  62. static void PCA9632_WriteRegister(const byte addr, const byte regadd, const byte value) {
  63. Wire.beginTransmission(addr);
  64. Wire.write(regadd);
  65. Wire.write(value);
  66. Wire.endTransmission();
  67. }
  68. static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const byte value1, const byte value2, const byte value3) {
  69. Wire.beginTransmission(addr);
  70. Wire.write(PCA9632_AUTO_IND | regadd);
  71. Wire.write(value1);
  72. Wire.write(value2);
  73. Wire.write(value3);
  74. Wire.endTransmission();
  75. }
  76. #if 0
  77. static byte PCA9632_ReadRegister(const byte addr, const byte regadd) {
  78. Wire.beginTransmission(addr);
  79. Wire.write(regadd);
  80. const byte value = Wire.read();
  81. Wire.endTransmission();
  82. return value;
  83. }
  84. #endif
  85. void PCA9632_SetColor(const byte r, const byte g, const byte b) {
  86. if (!PCA_init) {
  87. PCA_init = 1;
  88. Wire.begin();
  89. PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_MODE1, PCA9632_MODE1_VALUE);
  90. PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_MODE2, PCA9632_MODE2_VALUE);
  91. }
  92. const byte LEDOUT = (r ? LED_PWM << PCA9632_RED : 0)
  93. | (g ? LED_PWM << PCA9632_GRN : 0)
  94. | (b ? LED_PWM << PCA9632_BLU : 0);
  95. PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, r, g, b);
  96. PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_LEDOUT, LEDOUT);
  97. }
  98. #endif // PCA9632