altosui: Add config and pyro tabs to graph widget
[fw/altos] / src / micropeak-v2.0 / ao_micropeak.c
index 0b9972e908b1687e8741f2187fed64211b056806..c6c1e221880c0fc38e158e15dbcb4b36bb66ed5a 100644 (file)
@@ -56,7 +56,7 @@ ao_pips(void)
 }
 
 void
-ao_delay_until(uint16_t target) {
+ao_delay_until(AO_TICK_TYPE target) {
        int16_t delay = target - ao_time();
        if (delay > 0) {
                ao_sleep_for(ao_delay_until, delay);
@@ -145,10 +145,10 @@ ao_battery_fini(void)
        stm_rcc.apb2enr &= ~(1 << STM_RCC_APB2ENR_ADCEN);
 }
 
-static uint16_t
+static AO_TICK_TYPE
 ao_battery_voltage(void)
 {
-       uint16_t        vrefint;
+       AO_TICK_TYPE    vrefint;
 
        ao_battery_init();
 
@@ -167,9 +167,7 @@ ao_battery_voltage(void)
 static void
 ao_log_erase(void)
 {
-       uint32_t        pos;
-       for (pos = 0; pos < ao_storage_log_max; pos += ao_storage_block)
-               ao_storage_erase(pos);
+       ao_storage_erase(0, ao_storage_log_max);
 }
 
 uint8_t        ao_on_battery;
@@ -214,7 +212,7 @@ ao_show_bat(void)
 uint8_t
 ao_log_present(void)
 {
-       uint16_t        n_samples;
+       AO_TICK_TYPE    n_samples;
 
        ao_eeprom_read(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
 
@@ -227,7 +225,7 @@ ao_log_list(void)
        if (ao_log_present())
                printf ("flight %d start %x end %x\n",
                        1,
-                       0, MAX_LOG_OFFSET >> 8);
+                       0, (unsigned) (MAX_LOG_OFFSET >> 8));
        printf ("done\n");
 }
 
@@ -272,9 +270,6 @@ ao_hsi_init(void)
        /* Enable prefetch */
        stm_flash.acr |= (1 << STM_FLASH_ACR_PRFTBE);
 
-       /* Enable power interface clock */
-       stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_PWREN);
-
        /* HCLK to 48MHz -> AHB prescaler = /1 */
        cfgr = stm_rcc.cfgr;
        cfgr &= ~(STM_RCC_CFGR_HPRE_MASK << STM_RCC_CFGR_HPRE);
@@ -294,7 +289,7 @@ ao_hsi_init(void)
        stm_rcc.csr |= (1 << STM_RCC_CSR_RMVF);
 }
 
-void
+int
 main(void)
 {
        int i;
@@ -314,7 +309,6 @@ main(void)
        ao_led_init();
        ao_task_init();
        ao_timer_init();
-       ao_serial_init();
        stm_moder_set(&stm_gpioa, 2, STM_MODER_OUTPUT);
        ao_dma_init();
        ao_spi_init();
@@ -325,6 +319,12 @@ main(void)
        ao_ms5607_init();
        ao_storage_init();
 
+       /* Let FLITF clock turn off in sleep mode */
+       stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_FLITFEN);
+
+       /* Le SRAM clock turn off in sleep mode */
+       stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_SRAMEN);
+
        if (ao_on_battery) {
                /* On battery power, run the flight code */
                ao_add_task(&mp_task, ao_micropeak, "micropeak");