8000 [rgb led status] Add CP_RGB_STATUS_PWM_INVERTED symbol to invert pwm … · losingrose/circuitpython@fae1039 · GitHub
[go: up one dir, main page]

Skip to content

Commit fae1039

Browse files
committed
[rgb led status] Add CP_RGB_STATUS_PWM_INVERTED symbol to invert pwm signals.
1 parent 5610e05 commit fae1039

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

supervisor/shared/rgb_led_status.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,17 @@ void new_status_color(uint32_t rgb) {
196196
uint8_t red_u8 = (rgb_adjusted >> 16) & 0xFF;
197197
uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF;
198198
uint8_t blue_u8 = rgb_adjusted & 0xFF;
199-
200-
status_rgb_color[0] = (1<<16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8);
201-
status_rgb_color[1] = (1<<16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8);
202-
status_rgb_color[2] = (1<<16) - 1 - ((uint16_t) (blue_u8 << 8) + blue_u8);
203-
199+
200+
#if defined(CP_RGB_STATUS_INVERTED_PWM)
201+
status_rgb_color[0] = (1 << 16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8);
202+
status_rgb_color[1] = (1 << 16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8);
203+
status_rgb_color[2] = (1 << 16) - 1 - ((uint16_t) (blue_u8 << 8) + blue_u8);
204+
#else
205+
status_rgb_color[0] = (uint16_t) (red_u8 << 8) + red_u8;
206+
status_rgb_color[1] = (uint16_t) (green_u8 << 8) + green_u8;
207+
status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8;
208+
#endif
209+
204210
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]);
205211
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]);
206212
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]);
@@ -235,11 +241,18 @@ void temp_status_color(uint32_t rgb) {
235241
uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF;
236242
uint8_t blue_u8 = rgb_adjusted & 0xFF;
237243

238-
uint16_t temp_status_color_rgb[3];
244+
uint16_t temp_status_color_rgb[3] = {0};
245+
246+
#if defined(CP_RGB_STATUS_INVERTED_PWM)
247+
temp_status_color_rgb[0] = (1 << 16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8);
248+
temp_status_color_rgb[1] = (1 << 16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8);
249+
temp_status_color_rgb[2] = (1 << 16) - 1 - ((uint16_t) (blue_u8 << 8) + blue_u8);
250+
#else
239251
temp_status_color_rgb[0] = (uint16_t) (red_u8 << 8) + red_u8;
240252
temp_status_color_rgb[1] = (uint16_t) (green_u8 << 8) + green_u8;
241253
temp_status_color_rgb[2] = (uint16_t) (blue_u8 << 8) + blue_u8;
242-
254+
#endif
255+
243256
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, temp_status_color_rgb[0]);
244257
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, temp_status_color_rgb[1]);
245258
common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, temp_status_color_rgb[2]);
@@ -407,4 +420,4 @@ void tick_rgb_status_animation(rgb_status_animation_t* status) {
407420
}
408421
}
409422
#endif
410-
}
423+
}

0 commit comments

Comments
 (0)
0