mirror of
https://github.com/rvtr/ctr_mcu.git
synced 2025-06-18 16:45:33 -04:00

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@153 013db118-44a6-b54f-8bf7-843cb86687b1
178 lines
6.0 KiB
C
178 lines
6.0 KiB
C
#ifndef __PM__
|
|
#define __PM__
|
|
|
|
|
|
#define IIC_SLA_PMIC 0x84
|
|
#define IIC_SLA_BT_GAUGE 0x6C
|
|
|
|
#define VCOM_DEFAULT_T 92
|
|
#define VCOM_DEFAULT_B 95
|
|
|
|
//=========================================================
|
|
enum PMIC_REG_ADRS
|
|
{
|
|
PM_REG_ADRS_VER = 0x00, // verinfo など
|
|
PM_REG_ADRS_VDD_SYS, // システムが使用する電源
|
|
PM_REG_ADRS_VDD_LCD, // 液晶電源
|
|
PM_REG_ADRS_CONT, // /RESET1, LoadSwitch
|
|
PM_REG_ADRS_BL, // バックライト on/off
|
|
PM_REG_ADRS_POW_SAVE, // 省電力設定
|
|
PM_REG_ADRS_POW_DAC1,
|
|
PM_REG_ADRS_POW_DAC2
|
|
};
|
|
|
|
enum BT_GAUGE_REG_ADRS
|
|
{
|
|
BT_GAUGE_REG_VCELL = 0x02, // それぞれ16ビットのため
|
|
BT_GAUGE_REG_SOC = 0x04,
|
|
BT_GAUGE_REG_MODE = 0x06,
|
|
BT_GAUGE_REG_VERSION = 0x08,
|
|
BT_GAUGE_REG_OCV = 0x0E,
|
|
BT_GAUGE_REG_RCOMP = 0x0C,
|
|
BT_GAUGE_REG_LOCK = 0x3E,
|
|
BT_GAUGE_REG_BT_PARAM = 0x40,
|
|
BT_GAUGE_REG_COMMAND = 0xFE
|
|
};
|
|
|
|
enum BT_VENDER
|
|
{
|
|
BT_VENDER_SHIROBAKO = 0,
|
|
BT_VENDER_PANA = 3,
|
|
BT_VENDER_MAXELL = 7
|
|
};
|
|
|
|
|
|
//=========================================================
|
|
// CODEC上のPMIC互換レジスタ
|
|
#define CODEC_REG_PM 0x10
|
|
#define CODEC_REG_BL 0x11
|
|
#define CODEC_REG_BT 0x12
|
|
//#define CODEC_REG_VOL 0x13 // ...都合により、adc.hで定義
|
|
|
|
// TWLがSPIでPMICに投げたコマンド
|
|
#define REG_BIT_TWL_REQ_OFF_REQ ( 1 << 6 )
|
|
#define REG_BIT_TWL_REQ_RST_REQ ( 1 << 0 )
|
|
#define REG_BIT_TWL_REQ_BL ( 3 << 2 )
|
|
|
|
|
|
|
|
|
|
// 0x03 pw cnt3
|
|
#define PM_REG_BIT_LDSW ( 1 << 0 )
|
|
#define PM_REG_BIT_nRST1 ( 1 << 1 )
|
|
|
|
// 0x01 pw cnt1
|
|
#define PM_REG_BIT_VDD 0x0F
|
|
#define PM_REG_BIT_VDD50A ( 1 << 4 )
|
|
|
|
// 0x02 pw cnt2
|
|
#define PM_REG_BIT_VDDLCD 0x07
|
|
#define PM_REG_BIT_LCD_VCS ( 0x01 << 4 )
|
|
#define PM_REG_BIT_LCD_TCOM ( 0x01 << 3 )
|
|
|
|
// 0x04 bl cnt
|
|
#define PM_REG_BIT_BL_U 0x01
|
|
#define PM_REG_BIT_BL_L 0x02
|
|
|
|
|
|
// 0x05 pow save
|
|
#define PM_REG_BIT_VDD1P_1R15 0b00000000
|
|
#define PM_REG_BIT_VDD1P_1R05 0b00001000
|
|
#define PM_REG_BIT_VDD1P_0R90 0b00100000
|
|
#define PM_REG_BIT_VDD_AUTO 0b00000111
|
|
#define PM_REG_BIT_VDD_PWM 0b00000000
|
|
|
|
|
|
#define DELAY_PM_TW_PWUP 16
|
|
#define DELAY_PM_TSS_50B_AND_TCOM 17
|
|
#define DELAY_PM_5V_TO_TCOM 17
|
|
#define DELAY_PM_TCOM_TO_VCS 3
|
|
#define DELAY_PM_VCS_TO_BL ( 17 + 5 )
|
|
#define DELAY_PM_LCD_OFF ( 50 + 1 )
|
|
|
|
|
|
//=========================================================
|
|
extern u8 raw_adc_temperature;
|
|
|
|
|
|
//=========================================================
|
|
err PM_sys_pow_on( );
|
|
err PM_sys_pow_off( );
|
|
err PM_bt_auth( );
|
|
void PM_init( );
|
|
err PM_LCD_vcom_set( );
|
|
|
|
err PM_LCD_on( );
|
|
void PM_LCD_off( );
|
|
err PM_BL_set( u8 );
|
|
|
|
task_status_immed PM_bt_temp_update( );
|
|
task_status_immed tski_vcom_set( );
|
|
task_status_immed tski_PM_LCD_on();
|
|
task_status_immed tski_PM_LCD_off();
|
|
task_status_immed tski_PM_BL_set();
|
|
|
|
|
|
// これを呼ぶ前に、現在温度を教えておく必要があります。
|
|
#define PM_reset() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_CONT, 0x00 ) )
|
|
|
|
|
|
//=========================================================
|
|
|
|
|
|
// 元栓 //
|
|
#define PM_LDSW_on() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_CONT, PM_REG_BIT_LDSW ))
|
|
#define PM_LDSW_off() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_CONT, 0 ))
|
|
|
|
|
|
// システム電源 //
|
|
#define PM_VDD_on() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VDD_SYS, PM_REG_BIT_VDD ))
|
|
#define PM_VDD50A_on() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VDD_SYS, ( PM_REG_BIT_VDD | PM_REG_BIT_VDD50A )))
|
|
#define PM_VDD_off() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VDD_SYS, 0 ))
|
|
#define PM_off() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VDD_SYS, 0 ))
|
|
|
|
#ifdef _MODEL_CTR_
|
|
#define PM_VDD_normMode() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, PM_REG_BIT_VDD1P_1R15 | PM_REG_BIT_VDD_PWM ))
|
|
#define PM_VDD_ecoMode() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, PM_REG_BIT_VDD1P_0R90 | PM_REG_BIT_VDD_AUTO ))
|
|
|
|
#else
|
|
// 本番チップ待ち
|
|
#ifdef _PM_BUG_
|
|
#define PM_VDD_ecoMode() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, PM_REG_BIT_VDD1P_0R90 | PM_REG_BIT_VDD_AUTO ))
|
|
#define PM_VDD_normMode() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, PM_REG_BIT_VDD1P_1R10 | PM_REG_BIT_VDD_PWM ))
|
|
|
|
#else
|
|
#define PM_VDD_ecoMode() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, PM_REG_BIT_VDD1P_1R05 | PM_REG_BIT_VDD_AUTO ))
|
|
#define PM_VDD_normMode() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, PM_REG_BIT_VDD1P_1R05 | PM_REG_BIT_VDD_PWM ))
|
|
|
|
#endif
|
|
#endif
|
|
|
|
// ほか //
|
|
#ifdef _PMIC_TWL_
|
|
#define PM_reset_neg() { PM0.0 = 1; }
|
|
#define PM_reset_ast() { P0.0 = 0; PM0.0 = 0; }
|
|
#define PM_chk_LDSW() ( 1 )
|
|
#else
|
|
|
|
#define PM_reset_neg() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_CONT, ( PM_REG_BIT_LDSW | PM_REG_BIT_nRST1 )))
|
|
#define PM_reset_ast() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_CONT, ( PM_REG_BIT_LDSW )))
|
|
#define PM_chk_LDSW() ( iic_mcu_read_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_CONT ) & PM_REG_BIT_LDSW )
|
|
// ↑ 0 だと異常
|
|
#endif
|
|
|
|
|
|
// 液晶系電源 //
|
|
#define PM_VDDLCD_on() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VDD_LCD, PM_REG_BIT_VDDLCD ))
|
|
#define PM_TCOM_on() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VDD_LCD, ( PM_REG_BIT_VDDLCD | PM_REG_BIT_LCD_TCOM )))
|
|
#define PM_VCS_on() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VDD_LCD, ( PM_REG_BIT_VDDLCD | PM_REG_BIT_LCD_VCS | PM_REG_BIT_LCD_TCOM )))
|
|
#define PM_TCOM_VCS_off() PM_VDDLCD_on()
|
|
#define PM_VDDLCD_off() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VDD_LCD, 0 ) )
|
|
|
|
#define PM_set_BL( dat ) ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_BL, dat ) )
|
|
#define PM_set_adc1( dat ) ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_DAC1, dat ) )
|
|
#define PM_set_adc2( dat ) ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_DAC2, dat ) )
|
|
|
|
|
|
#endif // __PM__
|