mirror of
https://github.com/rvtr/ctr_mcu.git
synced 2025-10-31 13:51:10 -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@6 013db118-44a6-b54f-8bf7-843cb86687b1
115 lines
3.8 KiB
C
115 lines
3.8 KiB
C
#ifndef __PM__
|
|
#define __PM__
|
|
|
|
|
|
#define IIC_SLA_PMIC 0x84
|
|
#define IIC_SLA_BT_GAUGE 0x6C
|
|
|
|
|
|
//=========================================================
|
|
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 = 0xC0,
|
|
BT_GAUGE_REG_LOCK = 0x3E,
|
|
BT_GAUGE_REG_COMMAND = 0xFE
|
|
};
|
|
|
|
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
|
|
};
|
|
|
|
// CODEC上のPMIC互換レジスタ
|
|
#define CODEC_REG_PMCOMP 0x10
|
|
|
|
|
|
|
|
//=========================================================
|
|
#define PM_REG_BIT_LDSW ( 1 << 0 )
|
|
#define PM_REG_BIT_nRST1 ( 1 << 1 )
|
|
#define PM_REG_BIT_VDD 0x0F
|
|
#define PM_REG_BIT_VDD50A ( 1 << 4 )
|
|
|
|
#define PM_REG_BIT_VDDLCD 0x07
|
|
#define PM_REG_BIT_LCD_ANALOG ( 0x03 << 3 )
|
|
|
|
|
|
#define DELAY_PM_TW_PWUP 16
|
|
#define DELAY_PM_TSS_50B 5
|
|
|
|
|
|
|
|
//=========================================================
|
|
extern u16 raw_adc_temperature;
|
|
|
|
|
|
|
|
//=========================================================
|
|
err PM_sys_pow_on();
|
|
err PM_sys_pow_off();
|
|
err PM_LCD_on();
|
|
err PM_bt_auth();
|
|
task_status_immed PM_bt_temp_update();
|
|
void PM_init();
|
|
err PM_reset();
|
|
err PM_LCD_vcom_set();
|
|
task_status_immed tski_vcom_set();
|
|
|
|
// これを呼ぶ前に、現在温度を教えておく必要があります。
|
|
#define PM_get_batt_left() ( iic_mcu_read_a_byte( IIC_SLA_BT_GAUGE, BT_GAUGE_REG_SOC ) )
|
|
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
|
|
// 元栓 //
|
|
#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 _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 )
|
|
#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_VCS_on() ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_VDD_LCD, ( PM_REG_BIT_VDDLCD | PM_REG_BIT_LCD_ANALOG )))
|
|
#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_pow_save( dat ) ( iic_mcu_write_a_byte( IIC_SLA_PMIC, PM_REG_ADRS_POW_SAVE, 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__
|