From 20b8bdaad360d547f3321189da852e20c78b49b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=90=AA?= Date: Mon, 27 Jul 2026 17:26:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8D=87Gamma=E8=B0=83=E5=85=89?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E7=B2=BE=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ble/ble_peripheral/app/src/bridge_pwm.c | 2 +- .../ble_peripheral/app/src/light_transition.c | 38 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/project/example/ble/ble_peripheral/app/src/bridge_pwm.c b/project/example/ble/ble_peripheral/app/src/bridge_pwm.c index 002133a..3c09ec4 100644 --- a/project/example/ble/ble_peripheral/app/src/bridge_pwm.c +++ b/project/example/ble/ble_peripheral/app/src/bridge_pwm.c @@ -21,7 +21,7 @@ */ #define BRIDGE_PWM_SCALE 1000U #define BRIDGE_PWM_PERIOD 7U -#define BRIDGE_MIX_SCALE 100U +#define BRIDGE_MIX_SCALE 1000U #define BRIDGE_FRAME_US 1000U #define BRIDGE_DEADTIME_US 50U #define BRIDGE_DUAL_ACTIVE_US 900U diff --git a/project/example/ble/ble_peripheral/app/src/light_transition.c b/project/example/ble/ble_peripheral/app/src/light_transition.c index 0181415..6c87f92 100644 --- a/project/example/ble/ble_peripheral/app/src/light_transition.c +++ b/project/example/ble/ble_peripheral/app/src/light_transition.c @@ -4,9 +4,10 @@ volatile uint8_t Light_Transition_FadeActive; -#define LIGHT_FADE_STEP 1U #define BRIGHTNESS_SMOOTH_SHIFT 4U -#define BREATH_MIN_OUTPUT 1U +#define OUTPUT_SMOOTH_SHIFT 4U +#define LIGHT_OUTPUT_SCALE 1000U +#define BREATH_MIN_OUTPUT (LIGHT_OUTPUT_SCALE / 100U) #define POWER_FADE_Q12_MAX 4096U #define POWER_FADE_ON_TICKS 140U #define POWER_FADE_OFF_TICKS 160U @@ -57,6 +58,7 @@ static uint16_t current_brightness_q12; static uint16_t power_fade_progress_q12; static uint16_t power_fade_remainder; static uint8_t power_fade_direction; +static uint8_t transition_sync_pending; static uint16_t brightness_scale_for_level(uint8_t level) { @@ -88,17 +90,22 @@ static uint16_t approach_brightness_scale(uint16_t current, uint16_t target) static uint16_t approach_target(uint16_t current, uint16_t target) { + uint16_t delta; + uint16_t step; + + if(current == target) return current; if(current < target) { - uint16_t delta = target - current; - return current + ((delta > LIGHT_FADE_STEP) ? LIGHT_FADE_STEP : delta); + delta = target - current; + step = (uint16_t)((delta + ((1U << OUTPUT_SMOOTH_SHIFT) - 1U)) >> + OUTPUT_SMOOTH_SHIFT); + return current + step; } - if(current > target) - { - uint16_t delta = current - target; - return current - ((delta > LIGHT_FADE_STEP) ? LIGHT_FADE_STEP : delta); - } - return current; + + delta = current - target; + step = (uint16_t)((delta + ((1U << OUTPUT_SMOOTH_SHIFT) - 1U)) >> + OUTPUT_SMOOTH_SHIFT); + return current - step; } static uint16_t power_fade_scale(uint16_t progress_q12) @@ -176,6 +183,7 @@ void Light_Transition_SyncBrightness(uint8_t level) level == 0U ? 0U : POWER_FADE_Q12_MAX; power_fade_remainder = 0U; power_fade_direction = 0U; + transition_sync_pending = 1U; } void Light_Transition_Task(void) @@ -205,9 +213,11 @@ void Light_Transition_Task(void) : (power_fade_progress_q12 != 0U); target_w = - (uint16_t)(((uint32_t)W_PWM * brightness_scale + 2048U) >> 12); + (uint16_t)(((uint32_t)W_PWM * brightness_scale * + (LIGHT_OUTPUT_SCALE / 100U) + 2048U) >> 12); target_c = - (uint16_t)(((uint32_t)C_PWM * brightness_scale + 2048U) >> 12); + (uint16_t)(((uint32_t)C_PWM * brightness_scale * + (LIGHT_OUTPUT_SCALE / 100U) + 2048U) >> 12); if(Mode == mode1 && powered_on && !power_transitioning) { @@ -217,7 +227,8 @@ void Light_Transition_Task(void) target_c = BREATH_MIN_OUTPUT; } - if((Mode == mode2 && powered_on) || power_transitioning) + if((Mode == mode2 && powered_on) || power_transitioning || + transition_sync_pending) { W_PWM_duty = target_w; C_PWM_duty = target_c; @@ -227,6 +238,7 @@ void Light_Transition_Task(void) W_PWM_duty = approach_target(W_PWM_duty, target_w); C_PWM_duty = approach_target(C_PWM_duty, target_c); } + transition_sync_pending = 0U; Light_Transition_FadeActive = !powered_on && (power_fade_progress_q12 != 0U ||