twl_mcu/PMIC_TWL2.c
2024-12-17 04:24:29 -05:00

133 lines
3.8 KiB
C

/******************************************************************************
対PMIC_TWL2 I2C通信
de JHL 藤田@開技
nintendo
'07 Dec
*******************************************************************************/
#include "incs.h"
extern u8 vregs[];
extern bit rsv_set_BL;
bit eeprom_bl_dirty;
u8 bl_old;
bit flg_BLChanged;
extern u8 tsk_interval_cnt_power_led;
extern u8 tsk_interval_cnt_wifi_led;
u8 TBL_BL_Bright[5] = { 0, 2, 7, 14, 21 };
//******************************************************************************
void pmic_init(){
u8 temp;
temp = iic2m_read_byte( IIC_SLV_ADDR_PMIC, 0x00 );
vregs[ REG_INT_ADRS_PMIC_INFO ] = ( ( ( temp & 0x1C ) << 2 ) | ( temp & 0x03 ) );
vregs[ REG_INT_ADRS_BATT_INFO ] = ( ( temp & 0xE0 ) >> 1 );
PM_set_VRSET(); // 電源off時間1sec
bl_old = TBL_BL_Bright[ vregs[ REG_INT_ADRS_BL ] ];
iic2m_write_data( IIC_SLV_ADDR_PMIC, 0x03, bl_old ); // バックライト輝度復帰
}
/******************************************************************************
バックライト1チック上げる
******************************************************************************/
void BL_inc(){
if( vregs[REG_INT_ADRS_BL] != 0xFF ){ // 上限は BL_write() 内で制限&書き直し
vregs[REG_INT_ADRS_BL] += 1;
}
BL_write();
}
/******************************************************************************
バックライト1チック下げる
******************************************************************************/
void BL_dec(){
if( vregs[REG_INT_ADRS_BL] != 0 ){
vregs[REG_INT_ADRS_BL] -= 1;
}
BL_write();
}
/******************************************************************************
******************************************************************************/
void BL_write(){
u8 dat;
//*/
// 最大値は BL_IND_MAX
if( vregs[REG_INT_ADRS_BL] > BL_IND_MAX ){
vregs[REG_INT_ADRS_BL] = BL_IND_MAX;
}
dat = TBL_BL_Bright[ vregs[ REG_INT_ADRS_BL ] ];
/*/
// 最大値は32。テーブル引かない
if( vregs[REG_INT_ADRS_BL] > 31 ){
vregs[REG_INT_ADRS_BL] = 31;
}
dat = vregs[REG_INT_ADRS_BL];
//*/
if( bl_old != dat ){
bl_old = dat;
iic2m_write_data( IIC_SLV_ADDR_PMIC, 0x03, dat );
eeprom_bl_dirty = 1;
flg_BLChanged = 1;
tsk_interval_cnt_power_led = 250;
tsk_interval_cnt_wifi_led = 250;
}
}
/******************************************************************************
******************************************************************************/
void PM_set_VRSET( void ){
s8 tmp = 0;
// PMICの電源ボタン押し時間セット
if( is_TWL ){ // tmp |= is_TWL? 0x06 : 0x02; はわかりづらい?
tmp |= 0x06;
}else{
tmp |= 0x02;
}
// PMICの省電力モードセット
if( vregs[ REG_INT_ADRS_BATT_INFO ] != BATT_IS ){
if( PM_SLP ){
if( ( vregs[ REG_INT_ADRS_POWER_SAVE ] & 0x01 ) != 0 ){ tmp |= 0x40; } // 3.3 1でPFM
if( ( vregs[ REG_INT_ADRS_POWER_SAVE ] & 0x02 ) != 0 ){ tmp |= 0x20; } // 1.8
if( ( vregs[ REG_INT_ADRS_POWER_SAVE ] & 0x04 ) != 0 ){ tmp |= 0x10; } // 1.2
#ifdef after_x6 // X6以降は、スリープ中に無線を止め忘れてるのに対応
if( TxPE == 1 ){ // 強制リセット
n_sys_reset_ast;
return;
}
if( RxPE == 1 ){ // Sleep中の無線停止忘れ対応
tmp &= ~0x60;
#else // X6より前のは、強制的にPWMにします
{
tmp &= ~0x60; // ガイドライン違反なDSソフト、スリープ中にWiFi切り忘れ。シャットダウン防止
#endif
}
}else{ // 通常時
// nothing to do
}
}else{ // 赤箱
// nothing to do
}
iic2m_write_data( IIC_SLV_ADDR_PMIC, 0x01, tmp );
}