ctr_mcu/trunk/led_pow.c
n2232 5e6094bc54 バッテリーパラメ-タ SNAKE PANA 追加
SNAKE CCIC の 充電中通知が遷移付近でぱたぱたするので、安定するのを待つように


git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@471 013db118-44a6-b54f-8bf7-843cb86687b1
2012-09-25 00:15:20 +00:00

297 lines
6.8 KiB
C
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ========================================================
電源LED
LED_POW_B,R 6,7
TDR00 周期(0x03FF。TPS0で250kHzでカウントアップ。10bitなら250Hz位になる)
TDR0x Duty 0で消灯、TDR00(より大 =0x03FF以上)で点灯です。
$Id: asdf$
======================================================== */
/* ========================================================
enum pwr_state_{
OFF_TRIG = 0,
ON_CHECK,
ON_TRIG,
ON,
SLEEP
};
enum LED_ILUM_MODE{
LED_POW_ILM_AUTO,
LED_POW_ILM_ON,
LED_POW_ILM_SLEEP,
LED_POW_ILM_CEOFF
};
======================================================== */
#ifndef _WIN32
#pragma sfr
#endif
#include "incs.h"
#include "led.h"
#include "pm.h"
// ========================================================
// スリープ中明滅のテーブル。マジか。
const u8 LED_PTN_SLEEP[] = {
25, 38, 52, 68, 83, 98, 110, 119,
125, 128, 128, 125, 119, 110, 98, 83,
68, 52, 38, 25, 16, 10, 8, 8,
8, 8, 8, 8, 8, 8, 10, 16
};
// 赤LEDの電池残量LEDの点滅パターン
st_led_red_batt_empty led_red_batt_empty = { 0x55, 0x55, 0x55, 0x55 };
#define LED_SLEEP_FRAME_LEN 71
#define LED_SLEEP_DIM_LEN 71
#define LED_SLEEP_FRAME_NUM 32
// ========================================================
static void led_pow_normal( );
static void led_pow_sleep( );
static void led_pow_bt_empty();
static u8 led_pow_batt_low();
#define led_fade_to( now, goal ) now = fade_to( now, goal )
extern u8 fade_to( u8 now, u8 goal );
#define led_fade_to2( led, status ) led = fade_to2( status )
extern u8 fade_to2( st_LED_dim_status* status );
// ========================================================
// 電源LEDのスリープパターンのステータス類
static u8 time_to_next_frame_sleep = LED_SLEEP_FRAME_LEN;
static u8 frame_sleep;
static st_LED_dim_status LED_dim_status_sleep;
extern bit ledInitialized;
extern bit BT_IN_CHG_delayed_n;
/********************************************//**
電源LED
基本的には、
動作時、
- 電池残量 > 10% 青点灯master_brightnessの明るさ
- 5% 赤点灯 (100%点灯、HW制限で調光不可)
- それ以下 赤点灯、お知らせLED赤も同期する。ただし、アダプタが刺さったら5%~の動作に
スリープ中は
- 電池残量 > 10% 青点灯master_brightnessの明るさ
- 他 動作時と同じ
スリープには自動で切り替えないので、レジスタ操作が必要です(その方が都合がよいでしょう?)
他のパターンは生産検査のため。
***********************************************/
void tsk_led_pow( )
{
if( ! ledInitialized )
{
return;
// おしまい
}
info_led_override = false;
switch ( vreg_ctr[VREG_C_LED_POW] )
{
case ( LED_POW_ILM_AUTO ):
default:
led_pow_normal( );
break;
case ( LED_POW_ILM_SLEEP ):
led_pow_sleep( );
break;
case ( LED_POW_ILM_ON ):
led_fade_to( LED_duty_pow_blu, vreg_ctr[VREG_C_LED_BRIGHT] );
LED_pow_red = 0;
break;
case ( LED_POW_ILM_OFF ):
led_fade_to( LED_duty_pow_blu, 0 );
LED_pow_red = 0;
break;
case ( LED_POW_ILM_ONLY_RED ):
LED_duty_pow_blu = 0;
LED_pow_red = 1;
break;
case ( LED_POW_ILM_ONLY_BLUE ):
LED_duty_pow_blu = LED_BRIGHT_MAX;
LED_pow_red = 0;
break;
case ( LED_POW_ILM_FORCE_BT_EMPTY ):
led_pow_bt_empty();
break;
}
if( system_status.pwr_state == OFF || system_status.pwr_state == ON_CHECK )
{
LED_pow_red = 0;
info_led_override = false;
}
if( info_led_override )
{
LED_duty_notify_blu = 0;
LED_duty_notify_grn = 0;
LED_duty_notify_red = ( LED_pow_red == 0 )? 0 : 255;
}
}
/********************************************//**
通常動作時
電池残量で、 青→赤→赤点滅
***********************************************/
static void led_pow_normal( )
{
time_to_next_frame_sleep = LED_SLEEP_FRAME_LEN;
frame_sleep = 0;
LED_dim_status_sleep.now = (sx16)LED_duty_pow_blu * 128;
if( led_pow_batt_low() != 0 ) // 赤の点灯も←でやっています
{
return;
// おしまい
}
// 青点灯
led_fade_to( LED_duty_pow_blu, vreg_ctr[VREG_C_LED_BRIGHT] );
}
/********************************************//**
スリープ時ホタルパターン
電池残量で赤→赤点滅にする
***********************************************/
static void led_pow_sleep( )
{
if( led_pow_batt_low() != 0 ) // 赤の点灯も←でやっています
{
time_to_next_frame_sleep = LED_SLEEP_FRAME_LEN;
frame_sleep = 0;
LED_dim_status_sleep.now = (sx16)LED_duty_pow_blu * 128;
return;
// おしまい
}
LED_dim_status_sleep.to = LED_PTN_SLEEP[frame_sleep] * 128;
// グラデーションのデルタを計算
LED_dim_status_sleep.delta = (( LED_dim_status_sleep.to - LED_dim_status_sleep.now ) ) / LED_SLEEP_DIM_LEN;
led_fade_to2( LED_duty_pow_blu, &LED_dim_status_sleep );
// 次のフレームに進める?
time_to_next_frame_sleep --;
if( time_to_next_frame_sleep == 0 )
{
time_to_next_frame_sleep = LED_SLEEP_FRAME_LEN;
frame_sleep ++;
if( frame_sleep >= LED_SLEEP_FRAME_NUM -1 )
{
frame_sleep = 0;
}
}
}
/********************************************//**
電池が少ないときの共通
 返値 0 電池が少なくなかった
     1 少なかったので共通パターンにした
***********************************************/
static u8 led_pow_batt_low()
{
if( vreg_ctr[VREG_C_BT_REMAIN] > BATT_TH_LO )
{
LED_pow_red = 0;
return 0;
// おしまい
}
if(( vreg_ctr[VREG_C_BT_REMAIN] > BATT_TH_EMPTY ) || !BT_IN_CHG_delayed_n )
// 電池残量が5%10%) または、それ未満でも充電中
{
// 赤点灯
led_fade_to( LED_duty_pow_blu, 0 );
{
LED_pow_red = 1;
}
}
else // 電池が5%未満 かつ アダプタなし
{
led_pow_bt_empty();
}
return 1;
}
/********************************************//**
 電池がないパターン
  指定パターンを流す
  お知らせを上書きする
***********************************************/
static void led_pow_bt_empty()
{
static u8 delay;
static u8 red_blink_poi;
info_led_override = true;
// 赤点滅
led_fade_to( LED_duty_pow_blu, 0 );
// 赤の点滅パターンも指定できる
delay ++;
if( delay < 64 ) // フレームの保持時間稼ぎ
{
return;
}
delay = 0;
if( led_red_batt_empty.dats[ red_blink_poi / 8 ] & ( 1 << ( red_blink_poi % 8 )) )
{
LED_pow_red = 1;
}
else
{
LED_pow_red = 0;
}
red_blink_poi ++;
if( red_blink_poi >= 32 )
{
red_blink_poi = 0;
}
}