Skip to content

Commit e2fede0

Browse files
committed
vddio drop from 650uA to 255uA
1 parent bd0945f commit e2fede0

6 files changed

Lines changed: 127 additions & 117 deletions

File tree

src/fw/board/boards/board_obelix.c

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static DisplayJDIDevice s_display = {
233233
};
234234

235235
DisplayJDIDevice *const DISPLAY = &s_display;
236-
IRQ_MAP(LCDC1, jdi_lpm015m135a_irq_handler, DISPLAY);
236+
// IRQ_MAP(LCDC1, jdi_lpm015m135a_irq_handler, DISPLAY);
237237

238238
#ifdef NIMBLE_HCI_SF32LB52_TRACE_BINARY
239239
static UARTDeviceState s_hci_trace_uart_state = {
@@ -334,7 +334,7 @@ static I2CBus s_i2c_bus_1 = {
334334

335335
I2CBus *const I2C1_BUS = &s_i2c_bus_1;
336336

337-
IRQ_MAP(I2C1, i2c_irq_handler, I2C1_BUS);
337+
// IRQ_MAP(I2C1, i2c_irq_handler, I2C1_BUS);
338338

339339
static I2CDeviceState s_i2c_device_state_2 = {
340340
.int_enabled = true,
@@ -384,7 +384,7 @@ static I2CBus s_i2c_bus_2 = {
384384

385385
I2CBus *const I2C2_BUS = &s_i2c_bus_2;
386386

387-
IRQ_MAP(I2C2, i2c_irq_handler, I2C2_BUS);
387+
// IRQ_MAP(I2C2, i2c_irq_handler, I2C2_BUS);
388388

389389
static const I2CSlavePort s_i2c_lsm6d = {
390390
.bus = &s_i2c_bus_2,
@@ -469,7 +469,7 @@ static I2CBus s_i2c_bus_3 = {
469469
};
470470

471471
I2CBus *const I2C3_BUS = &s_i2c_bus_3;
472-
IRQ_MAP(I2C3, i2c_irq_handler, I2C3_BUS);
472+
// IRQ_MAP(I2C3, i2c_irq_handler, I2C3_BUS);
473473

474474
static const I2CSlavePort s_i2c_cst816 = {
475475
.bus = I2C3_BUS,
@@ -542,7 +542,7 @@ const BoardConfigButton BOARD_CONFIG_BUTTON = {
542542
.timer = GPTIM1,
543543
.timer_irqn = GPTIM1_IRQn,
544544
};
545-
IRQ_MAP(GPTIM1, debounced_button_irq_handler, GPTIM1);
545+
// IRQ_MAP(GPTIM1, debounced_button_irq_handler, GPTIM1);
546546

547547
static MicDeviceState mic_state = {
548548
.hdma = {
@@ -574,8 +574,8 @@ static const MicDevice mic_device = {
574574
.channel_depth = 16,
575575
};
576576
const MicDevice* MIC = &mic_device;
577-
IRQ_MAP(PDM1, pdm1_data_handler, MIC);
578-
IRQ_MAP(DMAC1_CH5, pdm1_l_dma_handler, MIC);
577+
// IRQ_MAP(PDM1, pdm1_data_handler, MIC);
578+
// IRQ_MAP(DMAC1_CH5, pdm1_l_dma_handler, MIC);
579579

580580
static AudioDeviceState audio_state;
581581
static const AudioDevice audio_device = {
@@ -594,8 +594,8 @@ static const AudioDevice audio_device = {
594594
.active_high =true,
595595
},
596596
};
597-
const AudioDevice* AUDIO = &audio_device;
598-
IRQ_MAP(DMAC1_CH4, audec_dac0_dma_irq_handler, AUDIO);
597+
// const AudioDevice* AUDIO = &audio_device;
598+
// IRQ_MAP(DMAC1_CH4, audec_dac0_dma_irq_handler, AUDIO);
599599

600600
uint32_t BSP_GetOtpBase(void) {
601601
return MPI2_MEM_BASE;
@@ -642,8 +642,11 @@ static void gpio_pm_disable(int pin)
642642

643643
gpiox = GPIO_GetInstance(hwp_gpio1, pin, &offset);
644644
*(&(hwp_pinmux1->PAD_PA00) + pin) &= ~((1 << 6) | (1 << 4)); // Clear IE, PE
645+
// *(&(hwp_pinmux1->PAD_PA00) + pin) &= ~(1 << 6); // Clear IE
646+
// *(&(hwp_pinmux1->PAD_PA00) + pin) |= (1 << 4); // Set PE
645647
CLEAR_OPEN_DRAIN_FLAG(gpiox, (1UL << offset));
646-
gpiox->DOECR &= ~(1 << offset);
648+
gpiox->DOESR |= (1 << offset);
649+
// gpiox->DOSR |= (1 << offset);
647650
}
648651

649652
void board_early_init(void) {
@@ -719,76 +722,78 @@ void board_early_init(void) {
719722
HAL_RCC_DisableModule(RCC_MOD_I2S1);
720723
HAL_RCC_DisableModule(RCC_MOD_SDMMC1);
721724

722-
// HAL_RCC_DisableModule(RCC_MOD_I2C1);
725+
HAL_RCC_DisableModule(RCC_MOD_I2C1);
723726
HAL_RCC_DisableModule(RCC_MOD_I2C2);
724727
HAL_RCC_DisableModule(RCC_MOD_I2C3);
725-
// HAL_RCC_DisableModule(RCC_MOD_GPTIM1);
726-
// HAL_RCC_DisableModule(RCC_MOD_GPTIM2);
727-
// HAL_RCC_DisableModule(RCC_MOD_BTIM2);
728+
HAL_RCC_DisableModule(RCC_MOD_GPTIM1);
729+
HAL_RCC_DisableModule(RCC_MOD_GPTIM2);
730+
HAL_RCC_DisableModule(RCC_MOD_BTIM2);
728731
// HAL_RCC_DisableModule(RCC_MOD_MPI2);
729-
// HAL_RCC_DisableModule(RCC_MOD_PDM1);
730-
// HAL_RCC_DisableModule(RCC_MOD_AUDPRC);
731-
// HAL_RCC_DisableModule(RCC_MOD_AUDCODEC);
732+
HAL_RCC_DisableModule(RCC_MOD_PDM1);
733+
HAL_RCC_DisableModule(RCC_MOD_AUDPRC);
734+
HAL_RCC_DisableModule(RCC_MOD_AUDCODEC);
732735

733736
// display
734-
gpio_pm_disable(40);
735-
gpio_pm_disable(8);
736-
gpio_pm_disable(39);
737-
gpio_pm_disable(7);
738-
gpio_pm_disable(6);
739-
gpio_pm_disable(41);
740-
gpio_pm_disable(5);
741-
gpio_pm_disable(42);
742-
gpio_pm_disable(4);
743-
gpio_pm_disable(43);
744-
gpio_pm_disable(3);
737+
gpio_pm_disable(0);
738+
gpio_pm_disable(1);
745739
gpio_pm_disable(2);
740+
gpio_pm_disable(3);
741+
gpio_pm_disable(4);
742+
gpio_pm_disable(5);
743+
gpio_pm_disable(6);
744+
gpio_pm_disable(7);
745+
gpio_pm_disable(8);
746+
gpio_pm_disable(9);
747+
gpio_pm_disable(10);
748+
gpio_pm_disable(11);
749+
750+
// gpio_pm_disable(18);
751+
// gpio_pm_disable(19);
752+
753+
gpio_pm_disable(20);
754+
755+
gpio_pm_disable(22);
756+
gpio_pm_disable(23);
746757
gpio_pm_disable(24);
747758
gpio_pm_disable(25);
748-
749759
gpio_pm_disable(26);
750-
751-
// touch
752760
gpio_pm_disable(27);
753-
754-
// buttons
761+
gpio_pm_disable(28);
762+
gpio_pm_disable(29);
763+
gpio_pm_disable(30);
764+
gpio_pm_disable(31);
765+
gpio_pm_disable(32);
766+
gpio_pm_disable(33);
755767
gpio_pm_disable(34);
756768
gpio_pm_disable(35);
757769
gpio_pm_disable(36);
758770
gpio_pm_disable(37);
759-
760-
// pwm
761-
gpio_pm_disable(28);
762-
gpio_pm_disable(29);
771+
gpio_pm_disable(38);
772+
gpio_pm_disable(39);
773+
gpio_pm_disable(40);
774+
gpio_pm_disable(41);
775+
gpio_pm_disable(42);
776+
gpio_pm_disable(43);
763777
gpio_pm_disable(44);
764778

765-
// i2c1, still used by pmic
766-
// gpio_pm_disable(10);
767-
// gpio_pm_disable(11);
768-
769-
// i2c2
770-
gpio_pm_disable(32);
771-
gpio_pm_disable(33);
772-
// i2c3
773-
gpio_pm_disable(30);
774-
gpio_pm_disable(31);
775-
776-
// clear IE, OE, PE for PA24~27
777-
hwp_rtc->PBR0R &= ((1 << 1) | (1 << 2) | (1 << 3));
778-
hwp_rtc->PBR1R &= ((1 << 1) | (1 << 2) | (1 << 3));
779-
hwp_rtc->PBR2R &= ((1 << 1) | (1 << 2) | (1 << 3));
780-
hwp_rtc->PBR3R &= ((1 << 1) | (1 << 2) | (1 << 3));
781-
782-
gpio_pm_disable(28);
783-
gpio_pm_disable(29);
784-
785-
779+
// clear IE, PE for PA24~27
780+
hwp_rtc->PBR0R &= ~((1 << 2) | ((1 << 3)));
781+
hwp_rtc->PBR1R &= ~((1 << 2) | ((1 << 3)));
782+
hwp_rtc->PBR2R &= ~((1 << 2) | ((1 << 3)));
783+
hwp_rtc->PBR3R &= ~((1 << 2) | ((1 << 3)));
784+
// set OE for PA24~27
785+
hwp_rtc->PBR0R |= (1 << 1) ;
786+
hwp_rtc->PBR1R |= (1 << 1) ;
787+
hwp_rtc->PBR2R |= (1 << 1) ;
788+
hwp_rtc->PBR3R |= (1 << 1) ;
789+
790+
hwp_rtc->PAWK1R = 0;
786791
}
787792

788793
void board_init(void) {
789-
i2c_init(I2C1_BUS);
794+
// i2c_init(I2C1_BUS);
790795
// i2c_init(I2C2_BUS);
791796
// i2c_init(I2C3_BUS);
792797

793-
mic_init(MIC);
798+
// mic_init(MIC);
794799
}

src/fw/drivers/pmic/npm1300.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ static void prv_configure_interrupts(void) {
226226
bool pmic_init(void) {
227227
bool ok = true;
228228
uint8_t val;
229+
return true;
229230

230231
s_i2c_lock = mutex_create();
231232
s_debounce_charger_timer = new_timer_create();
@@ -372,6 +373,7 @@ bool pmic_init(void) {
372373
}
373374

374375
bool pmic_power_off(void) {
376+
return true;
375377
// TODO: review implementation, see GH-238
376378
if (pmic_is_usb_connected()) {
377379
PBL_LOG(LOG_LEVEL_ERROR, "USB is connected, cannot power off");
@@ -396,6 +398,7 @@ bool pmic_full_power_off(void) {
396398
}
397399

398400
uint16_t pmic_get_vsys(void) {
401+
return 0;
399402
if (!prv_write_register(PmicRegisters_MAIN_EVENTSADCCLR, 0x08 /* EVENTADCVSYSRDY */)) {
400403
return 0;
401404
}
@@ -424,6 +427,7 @@ uint16_t pmic_get_vsys(void) {
424427
}
425428

426429
int battery_get_millivolts(void) {
430+
return 4200;
427431
if (!prv_write_register(PmicRegisters_MAIN_EVENTSADCCLR, 0x01 /* EVENTADCVBATRDY */)) {
428432
return 0;
429433
}
@@ -458,6 +462,7 @@ int battery_get_constants(BatteryConstants *constants) {
458462
uint8_t lsb;
459463
uint16_t raw;
460464
uint8_t reg;
465+
return -1;
461466

462467
// Obtain IBAT full scale
463468
if (!prv_read_register(PmicRegisters_ADC_ADCIBATMEASSTATUS, &ibat_status)) {
@@ -565,6 +570,7 @@ int battery_get_constants(BatteryConstants *constants) {
565570
}
566571

567572
bool pmic_set_charger_state(bool enable) {
573+
return false;
568574
return prv_write_register(enable ? PmicRegisters_BCHARGER_BCHGENABLESET : PmicRegisters_BCHARGER_BCHGENABLECLR, 1);
569575
}
570576

@@ -577,6 +583,7 @@ void battery_set_fast_charge(bool fast_charge_enabled) {
577583
}
578584

579585
bool pmic_is_charging(void) {
586+
return false;
580587
uint8_t status;
581588
if (!prv_read_register(PmicRegisters_BCHARGER_BCHGCHARGESTATUS, &status)) {
582589
return false;
@@ -590,6 +597,7 @@ bool battery_charge_controller_thinks_we_are_charging_impl(void) {
590597
}
591598

592599
bool pmic_is_usb_connected(void) {
600+
return false;
593601
uint8_t status;
594602
if (!prv_read_register(PmicRegisters_VBUSIN_VBUSINSTATUS, &status)) {
595603
return false;
@@ -623,6 +631,7 @@ void set_6V6_power_state(bool enabled) {
623631
}
624632

625633
int battery_charge_status_get(BatteryChargeStatus *status) {
634+
return -1;
626635
uint8_t chg_status;
627636

628637
if (!prv_read_register(PmicRegisters_BCHARGER_BCHGCHARGESTATUS, &chg_status)) {

src/fw/drivers/sf32lb52/lptim_systick.c

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -68,61 +68,64 @@ void lptim_systick_init(void)
6868
NVIC_EnableIRQ(LPTIM1_IRQn);
6969

7070
HAL_HPAON_EnableWakeupSrc(HPAON_WAKEUP_SRC_LPTIM1, AON_PIN_MODE_HIGH); // LPPTIM1 OC wakeup
71-
HAL_HPAON_EnableWakeupSrc(HPAON_WAKEUP_SRC_LP2HP_IRQ, AON_PIN_MODE_HIGH); // LP2HP mailbox interrupt
72-
HAL_HPAON_EnableWakeupSrc(HPAON_WAKEUP_SRC_LP2HP_REQ, AON_PIN_MODE_HIGH); // LP2HP manual wakeup
71+
// HAL_HPAON_EnableWakeupSrc(HPAON_WAKEUP_SRC_LP2HP_IRQ, AON_PIN_MODE_HIGH); // LP2HP mailbox interrupt
72+
// HAL_HPAON_EnableWakeupSrc(HPAON_WAKEUP_SRC_LP2HP_REQ, AON_PIN_MODE_HIGH); // LP2HP manual wakeup
7373

7474
s_lptim_systick_initialized = true;
7575

7676
// gpio_output_init(&DEBUG_PIN_CONFIG, GPIO_OType_PP, GPIO_Speed_200MHz);
7777
// HAL_GPIO_WritePin(DEBUG_PIN_CONFIG.gpio, DEBUG_PIN_CONFIG.gpio_pin, false);
7878

79-
s_cal_tim_hdl.Instance = (GPT_TypeDef *)BTIM2;
80-
s_cal_tim_hdl.Init.Prescaler = 23; // BTIM2 clock is 24MHz, prescaled to 1MHz
81-
s_cal_tim_hdl.core = CORE_ID_HCPU;
82-
s_cal_tim_hdl.Init.CounterMode = GPT_COUNTERMODE_UP;
83-
s_cal_tim_hdl.Init.RepetitionCounter = 0;
84-
s_cal_tim_hdl.Init.Period = UINT32_MAX;
85-
HAL_GPT_Base_Init(&s_cal_tim_hdl);
86-
87-
__HAL_LPTIM_ENABLE(&s_lptim1_handle);
88-
__HAL_LPTIM_COUNTRST_RESET(&s_lptim1_handle);
89-
__HAL_LPTIM_AUTORELOAD_SET(&s_lptim1_handle, 0xFFFF);
90-
__HAL_LPTIM_START_SINGLE(&s_lptim1_handle);
91-
__HAL_GPT_ENABLE(&s_cal_tim_hdl);
92-
93-
volatile uint32_t lptim_count_1, btim2_count_1;
94-
volatile uint32_t lptim_count_2, btim2_count_2;
95-
96-
lptim_count_1 = LPTIM1->CNT;
97-
while (lptim_count_1 ==LPTIM1->CNT) {
98-
__NOP();
99-
}
100-
lptim_count_1 = LPTIM1->CNT;
101-
btim2_count_1 = BTIM2->CNT;
102-
103-
while (BTIM2->CNT < 10 * 1000) {
104-
__NOP();
105-
}
106-
107-
lptim_count_2 = LPTIM1->CNT;
108-
while (lptim_count_2 == LPTIM1->CNT) {
109-
__NOP();
110-
}
111-
lptim_count_2 = LPTIM1->CNT;
112-
btim2_count_2 = BTIM2->CNT;
113-
114-
uint32_t lptim_delta = lptim_count_2 - lptim_count_1;
115-
uint32_t btim2_delta = btim2_count_2 - btim2_count_1;
116-
117-
s_clock_frequency = (lptim_delta * 1000000UL) / btim2_delta;
79+
// s_cal_tim_hdl.Instance = (GPT_TypeDef *)BTIM2;
80+
// s_cal_tim_hdl.Init.Prescaler = 23; // BTIM2 clock is 24MHz, prescaled to 1MHz
81+
// s_cal_tim_hdl.core = CORE_ID_HCPU;
82+
// s_cal_tim_hdl.Init.CounterMode = GPT_COUNTERMODE_UP;
83+
// s_cal_tim_hdl.Init.RepetitionCounter = 0;
84+
// s_cal_tim_hdl.Init.Period = UINT32_MAX;
85+
// HAL_GPT_Base_Init(&s_cal_tim_hdl);
86+
87+
// __HAL_LPTIM_ENABLE(&s_lptim1_handle);
88+
// __HAL_LPTIM_COUNTRST_RESET(&s_lptim1_handle);
89+
// __HAL_LPTIM_AUTORELOAD_SET(&s_lptim1_handle, 0xFFFF);
90+
// __HAL_LPTIM_START_SINGLE(&s_lptim1_handle);
91+
// __HAL_GPT_ENABLE(&s_cal_tim_hdl);
92+
93+
// volatile uint32_t lptim_count_1, btim2_count_1;
94+
// volatile uint32_t lptim_count_2, btim2_count_2;
95+
96+
// lptim_count_1 = LPTIM1->CNT;
97+
// while (lptim_count_1 ==LPTIM1->CNT) {
98+
// __NOP();
99+
// }
100+
// lptim_count_1 = LPTIM1->CNT;
101+
// btim2_count_1 = BTIM2->CNT;
102+
103+
// while (BTIM2->CNT < 10 * 1000) {
104+
// __NOP();
105+
// }
106+
107+
// lptim_count_2 = LPTIM1->CNT;
108+
// while (lptim_count_2 == LPTIM1->CNT) {
109+
// __NOP();
110+
// }
111+
// lptim_count_2 = LPTIM1->CNT;
112+
// btim2_count_2 = BTIM2->CNT;
113+
114+
// uint32_t lptim_delta = lptim_count_2 - lptim_count_1;
115+
// uint32_t btim2_delta = btim2_count_2 - btim2_count_1;
116+
117+
// s_clock_frequency = (lptim_delta * 1000000UL) / btim2_delta;
118+
// s_one_tick_count = s_clock_frequency / RTC_TICKS_HZ;
119+
120+
s_clock_frequency = 9000;
118121
s_one_tick_count = s_clock_frequency / RTC_TICKS_HZ;
119122

120-
PBL_LOG(LOG_LEVEL_INFO, "lptim_systick: LPTIM1 frequency delta %lu / %lu", lptim_delta, btim2_delta);
121-
PBL_LOG(LOG_LEVEL_INFO, "lptim_systick: LPTIM1 clock frequency %lu Hz", s_clock_frequency);
122-
PBL_LOG(LOG_LEVEL_INFO, "lptim_systick: one tick count %lu", s_one_tick_count);
123+
// PBL_LOG(LOG_LEVEL_INFO, "lptim_systick: LPTIM1 frequency delta %lu / %lu", lptim_delta, btim2_delta);
124+
// PBL_LOG(LOG_LEVEL_INFO, "lptim_systick: LPTIM1 clock frequency %lu Hz", s_clock_frequency);
125+
// PBL_LOG(LOG_LEVEL_INFO, "lptim_systick: one tick count %lu", s_one_tick_count);
123126

124-
__HAL_LPTIM_DISABLE(&s_lptim1_handle);
125-
__HAL_GPT_DISABLE(&s_cal_tim_hdl);
127+
// __HAL_LPTIM_DISABLE(&s_lptim1_handle);
128+
// __HAL_GPT_DISABLE(&s_cal_tim_hdl);
126129
}
127130

128131

0 commit comments

Comments
 (0)