@@ -50,10 +50,28 @@ busio_spi_obj_t status_apa102;
50
50
#endif
51
51
#endif
52
52
53
- #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK ))
53
+ #if defined(CP_RGB_STATUS_R ) || defined(CP_RGB_STATUS_G ) || defined(CP_RGB_STATUS_B )
54
+ #define CP_RGB_STATUS_LED
55
+
56
+ #include "shared-bindings/pulseio/PWMOut.h"
57
+ #include "shared-bindings/microcontroller/Pin.h"
58
+
59
+ pulseio_pwmout_obj_t rgb_status_r ;
60
+ pulseio_pwmout_obj_t rgb_status_g ;
61
+ pulseio_pwmout_obj_t rgb_status_b ;
62
+
63
+ uint8_t rgb_status_brightness = 0xFF ;
64
+
65
+ uint16_t status_rgb_color [3 ] = {
66
+ 0 /* red */ , 0 /* green */ , 0 /* blue */
67
+ };
68
+ #endif
69
+
70
+ #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )) || (defined(CP_RGB_STATUS_LED ))
54
71
static uint32_t current_status_color = 0 ;
55
72
#endif
56
73
74
+
57
75
void rgb_led_status_init () {
58
76
#ifdef MICROPY_HW_NEOPIXEL
59
77
common_hal_digitalio_digitalinout_construct (& status_neopixel , MICROPY_HW_NEOPIXEL );
@@ -93,7 +111,34 @@ void rgb_led_status_init() {
93
111
#endif
94
112
#endif
95
113
96
- #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK ))
114
+
115
+ #if defined(CP_RGB_STATUS_LED )
116
+ if (common_hal_mcu_pin_is_free (CP_RGB_STATUS_R )) {
117
+ pwmout_result_t red_result = common_hal_pulseio_pwmout_construct (& rgb_status_r , CP_RGB_STATUS_R , 0 , 50000 , false);
118
+
119
+ if (PWMOUT_OK == red_result ) {
120
+ common_hal_pulseio_pwmout_never_reset (& rgb_status_r );
121
+ }
122
+ }
123
+
124
+ if (common_hal_mcu_pin_is_free (CP_RGB_STATUS_G )) {
125
+ pwmout_result_t green_result = common_hal_pulseio_pwmout_construct (& rgb_status_g , CP_RGB_STATUS_G , 0 , 50000 , false);
126
+
127
+ if (PWMOUT_OK == green_result ) {
128
+ common_hal_pulseio_pwmout_never_reset (& rgb_status_g );
129
+ }
130
+ }
131
+
132
+ if (common_hal_mcu_pin_is_free (CP_RGB_STATUS_B )) {
133
+ pwmout_result_t blue_result = common_hal_pulseio_pwmout_construct (& rgb_status_b , CP_RGB_STATUS_B , 0 , 50000 , false);
134
+
135
+ if (PWMOUT_OK == blue_result ) {
136
+ common_hal_pulseio_pwmout_never_reset (& rgb_status_b );
137
+ }
138
+ }
139
+ #endif
140
+
141
+ #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )) || (defined(CP_RGB_STATUS_LED ))
97
142
// Force a write of the current status color.
98
143
uint32_t rgb = current_status_color ;
99
144
current_status_color = 0x1000000 ; // Not a valid color
@@ -109,10 +154,15 @@ void reset_status_led() {
109
154
reset_pin_number (MICROPY_HW_APA102_MOSI -> number );
110
155
reset_pin_number (MICROPY_HW_APA102_SCK -> number );
111
156
#endif
157
+ #if defined(CP_RGB_STATUS_LED )
158
+ reset_pin_number (CP_RGB_STATUS_R -> number );
159
+ reset_pin_number (CP_RGB_STATUS_G -> number );
160
+ reset_pin_number (CP_RGB_STATUS_B -> number );
161
+ #endif
112
162
}
113
163
114
164
void new_status_color (uint32_t rgb ) {
115
- #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK ))
165
+ #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )) || (defined( CP_RGB_STATUS_LED ))
116
166
if (current_status_color == rgb ) {
117
167
return ;
118
168
}
@@ -143,10 +193,24 @@ void new_status_color(uint32_t rgb) {
143
193
common_hal_busio_spi_write (& status_apa102 , status_apa102_color , 8 );
144
194
#endif
145
195
#endif
196
+
197
+ #if defined(CP_RGB_STATUS_LED )
198
+ uint8_t red_u8 = (rgb_adjusted >> 16 ) & 0xFF ;
199
+ uint8_t green_u8 = (rgb_adjusted >> 8 ) & 0xFF ;
200
+ uint8_t blue_u8 = rgb_adjusted & 0xFF ;
201
+
202
+ status_rgb_color [0 ] = (uint16_t ) (red_u8 << 8 ) + red_u8 ;
203
+ status_rgb_color [1 ] = (uint16_t ) (green_u8 << 8 ) + green_u8 ;
204
+ status_rgb_color [2 ] = (uint16_t ) (blue_u8 << 8 ) + blue_u8 ;
205
+
206
+ common_hal_pulseio_pwmout_set_duty_cycle (& rgb_status_r , status_rgb_color [0 ]);
207
+ common_hal_pulseio_pwmout_set_duty_cycle (& rgb_status_g , status_rgb_color [1 ]);
208
+ common_hal_pulseio_pwmout_set_duty_cycle (& rgb_status_b , status_rgb_color [2 ]);
209
+ #endif
146
210
}
147
211
148
212
void temp_status_color (uint32_t rgb ) {
149
- #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK ))
213
+ #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )) || (defined( CP_RGB_STATUS_LED ))
150
214
uint32_t rgb_adjusted = rgb ;
151
215
rgb_adjusted = color_brightness (rgb , rgb_status_brightness );
152
216
#endif
@@ -168,6 +232,19 @@ void temp_status_color(uint32_t rgb) {
168
232
common_hal_busio_spi_write (& status_apa102 , colors , 12 );
169
233
#endif
170
234
#endif
235
+ #if defined(CP_RGB_STATUS_LED )
236
+ uint8_t red_u8 = (rgb_adjusted >> 16 ) & 0xFF ;
237
+ uint8_t green_u8 = (rgb_adjusted >> 8 ) & 0xFF ;
238
+ uint8_t blue_u8 = rgb_adjusted & 0xFF ;
239
+
240
+ status_rgb_color [0 ] = (uint16_t ) (red_u8 << 8 ) + red_u8 ;
241
+ status_rgb_color [1 ] = (uint16_t ) (green_u8 << 8 ) + green_u8 ;
242
+ status_rgb_color [2 ] = (uint16_t ) (blue_u8 << 8 ) + blue_u8 ;
243
+
244
+ common_hal_pulseio_pwmout_set_duty_cycle (& rgb_status_r , status_rgb_color [0 ]);
245
+ common_hal_pulseio_pwmout_set_duty_cycle (& rgb_status_g , status_rgb_color [1 ]);
246
+ common_hal_pulseio_pwmout_set_duty_cycle (& rgb_status_b , status_rgb_color [2 ]);
247
+ #endif
171
248
}
172
249
173
250
void clear_temp_status () {
@@ -181,6 +258,11 @@ void clear_temp_status() {
181
258
common_hal_busio_spi_write (& status_apa102 , status_apa102_color , 8 );
182
259
#endif
183
260
#endif
261
+ #if defined(CP_RGB_STATUS_LED )
262
+ common_hal_pulseio_pwmout_set_duty_cycle (& rgb_status_r , status_rgb_color [0 ]);
263
+ common_hal_pulseio_pwmout_set_duty_cycle (& rgb_status_g , status_rgb_color [1 ]);
264
+ common_hal_pulseio_pwmout_set_duty_cycle (& rgb_status_b , status_rgb_color [2 ]);
265
+ #endif
184
266
}
185
267
186
268
uint32_t color_brightness (uint32_t color , uint8_t brightness ) {
@@ -210,7 +292,7 @@ void prep_rgb_status_animation(const pyexec_result_t* result,
210
292
bool found_main ,
211
293
safe_mode_t safe_mode ,
212
294
rgb_status_animation_t * status ) {
213
- #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK ))
295
+ #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )) || (defined( CP_RGB_STATUS_LED ))
214
296
new_status_color (ALL_DONE );
215
297
status -> pattern_start = ticks_ms ;
216
298
status -> safe_mode = safe_mode ;
@@ -256,7 +338,7 @@ void prep_rgb_status_animation(const pyexec_result_t* result,
256
338
}
257
339
258
340
void tick_rgb_status_animation (rgb_status_animation_t * status ) {
259
- #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK ))
341
+ #if defined(MICROPY_HW_NEOPIXEL ) || (defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )) || (defined( CP_RGB_STATUS_LED ))
260
342
uint32_t tick_diff = ticks_ms - status -> pattern_start ;
261
343
if (status -> ok ) {
262
344
// All is good. Ramp ALL_DONE up and down.
@@ -326,4 +408,4 @@ void tick_rgb_status_animation(rgb_status_animation_t* status) {
326
408
}
327
409
}
328
410
#endif
329
- }
411
+ }
0 commit comments