My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

pca9632.cpp 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 "../../inc/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 Green=LED1 Blue=LED2
  54. #ifndef PCA9632_RED
  55. #define PCA9632_RED 0x00
  56. #endif
  57. #ifndef PCA9632_GRN
  58. #define PCA9632_GRN 0x02
  59. #endif
  60. #ifndef PCA9632_BLU
  61. #define PCA9632_BLU 0x04
  62. #endif
  63. // If any of the color indexes are greater than 0x04 they can't use auto increment
  64. #if !defined(PCA9632_NO_AUTO_INC) && (PCA9632_RED > 0x04 || PCA9632_GRN > 0x04 || PCA9632_BLU > 0x04)
  65. #define PCA9632_NO_AUTO_INC
  66. #endif
  67. #define LED_OFF 0x00
  68. #define LED_ON 0x01
  69. #define LED_PWM 0x02
  70. #define PCA9632_ADDRESS 0b01100000
  71. byte PCA_init = 0;
  72. static void PCA9632_WriteRegister(const byte addr, const byte regadd, const byte value) {
  73. Wire.beginTransmission(I2C_ADDRESS(addr));
  74. Wire.write(regadd);
  75. Wire.write(value);
  76. Wire.endTransmission();
  77. }
  78. static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const byte vr, const byte vg, const byte vb) {
  79. #if DISABLED(PCA9632_NO_AUTO_INC)
  80. uint8_t data[4], len = 4;
  81. data[0] = PCA9632_AUTO_IND | regadd;
  82. data[1 + (PCA9632_RED >> 1)] = vr;
  83. data[1 + (PCA9632_GRN >> 1)] = vg;
  84. data[1 + (PCA9632_BLU >> 1)] = vb;
  85. #else
  86. uint8_t data[6], len = 6;
  87. data[0] = regadd + (PCA9632_RED >> 1);
  88. data[1] = vr;
  89. data[2] = regadd + (PCA9632_GRN >> 1);
  90. data[3] = vg;
  91. data[4] = regadd + (PCA9632_BLU >> 1);
  92. data[5] = vb;
  93. #endif
  94. Wire.beginTransmission(I2C_ADDRESS(addr));
  95. Wire.write(data, len);
  96. Wire.endTransmission();
  97. }
  98. #if 0
  99. static byte PCA9632_ReadRegister(const byte addr, const byte regadd) {
  100. Wire.beginTransmission(I2C_ADDRESS(addr));
  101. Wire.write(regadd);
  102. const byte value = Wire.read();
  103. Wire.endTransmission();
  104. return value;
  105. }
  106. #endif
  107. void pca9632_set_led_color(const LEDColor &color) {
  108. Wire.begin();
  109. if (!PCA_init) {
  110. PCA_init = 1;
  111. PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_MODE1, PCA9632_MODE1_VALUE);
  112. PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_MODE2, PCA9632_MODE2_VALUE);
  113. }
  114. const byte LEDOUT = (color.r ? LED_PWM << PCA9632_RED : 0)
  115. | (color.g ? LED_PWM << PCA9632_GRN : 0)
  116. | (color.b ? LED_PWM << PCA9632_BLU : 0);
  117. PCA9632_WriteAllRegisters(PCA9632_ADDRESS,PCA9632_PWM0, color.r, color.g, color.b);
  118. PCA9632_WriteRegister(PCA9632_ADDRESS,PCA9632_LEDOUT, LEDOUT);
  119. }
  120. #if ENABLED(PCA9632_BUZZER)
  121. void pca9632_buzz(const long, const uint16_t) {
  122. uint8_t data[] = PCA9632_BUZZER_DATA;
  123. Wire.beginTransmission(I2C_ADDRESS(PCA9632_ADDRESS));
  124. Wire.write(data, sizeof(data));
  125. Wire.endTransmission();
  126. }
  127. #endif // PCA9632_BUZZER
  128. #endif // PCA9632