52
52
#define BRD_ID_1_UPPER_THR_V 935 // Upper threshold in mV for 100nF and 4700R
53
53
#define BRD_ID_1_LOWER_THR_V 268 // Lower threshold in mV for 100nF and 4700R
54
54
55
- #define PWR_LED_ON_MAX_BRIGHTNESS 100 // Max LED Brightness (PC Connected)
56
- #define PWR_LED_INIT_FADE_BRIGHTNESS 80 // Initial fade LED Brightness
57
- #define PWR_LED_ON_BATT_BRIGHTNESS 40 // LED Brightness while being powered by battery
58
- #define PWR_LED_FADEOUT_MIN_BRIGHTNESS 30 // Minimum LED brightness when fading out
55
+ #define PWR_LED_ON_MAX_BRIGHTNESS 255 // Max LED Brightness (PC Connected)
56
+ #define PWR_LED_INIT_FADE_BRIGHTNESS 200 // Initial fade LED Brightness
57
+ #define PWR_LED_ON_BATT_BRIGHTNESS 100 // LED Brightness while being powered by battery
58
+ #define PWR_LED_FADEOUT_MIN_BRIGHTNESS 80 // Minimum LED brightness when fading out
59
59
#define PWR_LED_SLEEP_STATE_DEFAULT true
60
60
#define AUTOMATIC_SLEEP_DEFAULT true
61
61
@@ -120,6 +120,7 @@ static uint32_t read_file_data_txt(uint32_t sector_offset, uint8_t *data, uint32
120
120
// shutdown state
121
121
static main_shutdown_state_t main_shutdown_state = MAIN_SHUTDOWN_WAITING ;
122
122
static uint8_t shutdown_led_dc = PWR_LED_ON_MAX_BRIGHTNESS ;
123
+ static uint8_t final_fade_led_dc = 0 ;
123
124
static uint8_t power_led_max_duty_cycle = PWR_LED_ON_MAX_BRIGHTNESS ;
124
125
static uint8_t initial_fade_brightness = PWR_LED_INIT_FADE_BRIGHTNESS ;
125
126
static bool power_led_sleep_state_on = PWR_LED_SLEEP_STATE_DEFAULT ;
@@ -211,10 +212,10 @@ static void set_board_id(mb_version_t board_version) {
211
212
}
212
213
}
213
214
214
- // Apply a gamma curve to the LED. Input brightness between 0-100
215
+ // Apply a gamma curve to the LED. Input brightness between 0-255
215
216
static inline uint8_t get_led_gamma (uint8_t brightness ) {
216
217
uint8_t duty_cycle ;
217
- duty_cycle = (brightness * brightness * brightness + 5000 ) / 10000 ;
218
+ duty_cycle = (brightness * brightness * brightness + 32512 ) / ( 255 * 255 ) ;
218
219
return duty_cycle ;
219
220
}
220
221
@@ -382,11 +383,12 @@ void board_30ms_hook()
382
383
case MAIN_SHUTDOWN_REACHED :
383
384
// Hold LED in min brightness
384
385
shutdown_led_dc = PWR_LED_FADEOUT_MIN_BRIGHTNESS ;
386
+ final_fade_led_dc = get_led_gamma (PWR_LED_FADEOUT_MIN_BRIGHTNESS );
385
387
break ;
386
388
case MAIN_SHUTDOWN_REACHED_FADE :
387
389
// Fast fade to off
388
- if (shutdown_led_dc > 0 ) {
389
- shutdown_led_dc -- ;
390
+ if (final_fade_led_dc > 0 ) {
391
+ final_fade_led_dc -- ;
390
392
}
391
393
break ;
392
394
case MAIN_USER_EVENT :
@@ -450,10 +452,10 @@ void board_30ms_hook()
450
452
if (shutdown_led_dc < 10 ) {
451
453
shutdown_led_dc ++ ;
452
454
} else if (shutdown_led_dc == 10 ) {
453
- shutdown_led_dc = 100 ;
454
- } else if (shutdown_led_dc <= 90 ) {
455
+ shutdown_led_dc = PWR_LED_ON_MAX_BRIGHTNESS ;
456
+ } else if (shutdown_led_dc <= ( PWR_LED_ON_MAX_BRIGHTNESS - 10 ) ) {
455
457
shutdown_led_dc = 0 ;
456
- } else if (shutdown_led_dc > 90 ) {
458
+ } else if (shutdown_led_dc > ( PWR_LED_ON_MAX_BRIGHTNESS - 10 ) ) {
457
459
shutdown_led_dc -- ;
458
460
}
459
461
@@ -471,7 +473,7 @@ void board_30ms_hook()
471
473
}
472
474
} else {
473
475
blink_in_progress = 10 ;
474
- shutdown_led_dc = 100 ;
476
+ shutdown_led_dc = PWR_LED_ON_MAX_BRIGHTNESS ;
475
477
}
476
478
477
479
if (blink_in_progress == 0 ) {
@@ -481,8 +483,14 @@ void board_30ms_hook()
481
483
default :
482
484
break ;
483
485
}
484
- uint8_t gamma_led_dc = get_led_gamma (shutdown_led_dc );
485
- flexio_pwm_set_dutycycle (gamma_led_dc );
486
+
487
+ // Use gamma curve except in final fade
488
+ if (main_shutdown_state != MAIN_SHUTDOWN_REACHED_FADE ) {
489
+ uint8_t gamma_led_dc = get_led_gamma (shutdown_led_dc );
490
+ flexio_pwm_set_dutycycle (gamma_led_dc );
491
+ } else {
492
+ flexio_pwm_set_dutycycle (final_fade_led_dc );
493
+ }
486
494
487
495
// Remount if requested.
488
496
if (do_remount ) {
0 commit comments