mirror of
https://github.com/rvtr/ctr_mcu.git
synced 2025-06-20 01:25:32 -04:00

歩数計修正(途中) 電源シーケンス修正 inita時に電源が切れないようにする(PWMを止められたらすぐに勝手にBLを消す) off時32kHzを止めるのを忘れていた git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@34 013db118-44a6-b54f-8bf7-843cb86687b1
157 lines
5.0 KiB
C
157 lines
5.0 KiB
C
#ifndef __PM__
|
||
#define __PM__
|
||
|
||
|
||
#define IIC_SLA_PMIC 0x84
|
||
#define IIC_SLA_BT_GAUGE 0x6C
|
||
|
||
|
||
//=========================================================
|
||
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
|
||
};
|
||
|
||
|
||
|
||
|
||
//=========================================================
|
||
// CODEC上のPMIC互換レジスタ
|
||
#define CODEC_REG_PM 0x10
|
||
#define CODEC_REG_BL 0x11
|
||
#define CODEC_REG_BT 0x12
|
||
|
||
// 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
|
||
|
||
|
||
|
||
|
||
#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;
|
||
extern u8 command_bl_set;
|
||
|
||
|
||
|
||
//=========================================================
|
||
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( );
|
||
|
||
|
||
|
||
// これを呼ぶ前に、現在温度を教えておく必要があります。
|
||
#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_ecoMode() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, 0x47 ))
|
||
#define PM_VDD_normMode() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, 0x00 ))
|
||
// todo コア電圧を下げる
|
||
#else
|
||
#define PM_VDD_ecoMode() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, 0x00 | 0x40 ))
|
||
#define PM_VDD_normMode() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, 0x00 | 0x03 ))
|
||
#endif
|
||
// ↑本番チップ待ち+PMICバグ
|
||
|
||
// ほか //
|
||
#ifdef _PMIC_TWL_
|
||
#define PM_reset_neg() { PM0.0 = 1; PU0.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__
|