altos/micropeak: Run MS5607 at max resolution for micropeak
[fw/altos] / src / drivers / ao_ms5607.c
index fdd2c31e5992e4c96e1120d313bb13ba186978b7..bd57400e94690524170ae6ddaa203f3103eff0b2 100644 (file)
@@ -141,10 +141,10 @@ ao_ms5607_get_sample(uint8_t cmd) {
 #if AO_MS5607_PRIVATE_PINS
        ao_spi_put(AO_MS5607_SPI_INDEX);
 #endif
-       cli();
+       ao_arch_block_interrupts();
        while (!ao_ms5607_done)
                ao_sleep((void *) &ao_ms5607_done);
-       sei();
+       ao_arch_release_interrupts();
 #if AO_MS5607_PRIVATE_PINS
        stm_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, 1);
 #else
@@ -160,23 +160,39 @@ ao_ms5607_get_sample(uint8_t cmd) {
        return ((uint32_t) reply[0] << 16) | ((uint32_t) reply[1] << 8) | (uint32_t) reply[2];
 }
 
+#ifndef AO_MS5607_BARO_OVERSAMPLE
+#define AO_MS5607_BARO_OVERSAMPLE      2048
+#endif
+
+#ifndef AO_MS5607_TEMP_OVERSAMPLE
+#define AO_MS5607_TEMP_OVERSAMPLE      AO_MS5607_BARO_OVERSAMPLE
+#endif
+
+#define token_paster(x,y)      x ## y
+#define token_evaluator(x,y)   token_paster(x,y)
+
+#define AO_CONVERT_D1  token_evaluator(AO_MS5607_CONVERT_D1_, AO_MS5607_BARO_OVERSAMPLE)
+#define AO_CONVERT_D2  token_evaluator(AO_MS5607_CONVERT_D2_, AO_MS5607_TEMP_OVERSAMPLE)
+
 void
 ao_ms5607_sample(struct ao_ms5607_sample *sample)
 {
-       sample->pres = ao_ms5607_get_sample(AO_MS5607_CONVERT_D1_2048);
-       sample->temp = ao_ms5607_get_sample(AO_MS5607_CONVERT_D2_2048);
+       sample->pres = ao_ms5607_get_sample(AO_CONVERT_D1);
+       sample->temp = ao_ms5607_get_sample(AO_CONVERT_D2);
 }
 
 #include "ao_ms5607_convert.c"
 
 #if HAS_TASK
+struct ao_ms5607_sample        ao_ms5607_current;
+
 static void
 ao_ms5607(void)
 {
        ao_ms5607_setup();
        for (;;)
        {
-               ao_ms5607_sample((struct ao_ms5607_sample *) &ao_data_ring[ao_data_head].ms5607_raw);
+               ao_ms5607_sample(&ao_ms5607_current);
                ao_arch_critical(
                        AO_DATA_PRESENT(AO_DATA_MS5607);
                        AO_DATA_WAIT();
@@ -202,14 +218,11 @@ ao_ms5607_info(void)
 static void
 ao_ms5607_dump(void)
 {
-       struct ao_ms5607_sample sample;
        struct ao_ms5607_value value;
 
-       ao_ms5607_setup();
-       ao_ms5607_sample(&sample);
-       ao_ms5607_convert(&sample, &value);
-       printf ("Pressure:    %8u %8d\n", sample.pres, value.pres);
-       printf ("Temperature: %8u %8d\n", sample.temp, value.temp);
+       ao_ms5607_convert(&ao_ms5607_current, &value);
+       printf ("Pressure:    %8u %8d\n", ao_ms5607_current.pres, value.pres);
+       printf ("Temperature: %8u %8d\n", ao_ms5607_current.temp, value.temp);
        printf ("Altitude: %ld\n", ao_pa_to_altitude(value.pres));
 }