summaryrefslogtreecommitdiff
path: root/src/drivers/ao_ms5607.c
diff options
context:
space:
mode:
authorBdale Garbee <bdale@gag.com>2012-08-28 23:39:53 -0600
committerBdale Garbee <bdale@gag.com>2012-08-28 23:39:53 -0600
commit5ed88fb72c3e3ecf3333c700d838667db71cfbdc (patch)
tree3b371f563c0f7607f2fe53242673adb352b48514 /src/drivers/ao_ms5607.c
parentadbe64c5a9402b7c5075a444a12629131b663877 (diff)
parent621d0930244f25165d2ac5da596dcc87e253b965 (diff)
Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
Conflicts: debian/control
Diffstat (limited to 'src/drivers/ao_ms5607.c')
-rw-r--r--src/drivers/ao_ms5607.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c
index 17fe853b..ec0d2202 100644
--- a/src/drivers/ao_ms5607.c
+++ b/src/drivers/ao_ms5607.c
@@ -19,6 +19,8 @@
#include <ao_exti.h>
#include "ao_ms5607.h"
+#if HAS_MS5607
+
static struct ao_ms5607_prom ms5607_prom;
static uint8_t ms5607_configured;
@@ -134,11 +136,18 @@ ao_ms5607_get_sample(uint8_t cmd) {
ao_ms5607_start();
ao_spi_send(&cmd, 1, AO_MS5607_SPI_INDEX);
ao_exti_enable(AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
+#if AO_MS5607_PRIVATE_PINS
+ ao_spi_put(AO_MS5607_SPI_INDEX);
+#endif
cli();
while (!ao_ms5607_done)
ao_sleep(&ao_ms5607_done);
sei();
+#if AO_MS5607_PRIVATE_PINS
+ stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 1);
+#else
ao_ms5607_stop();
+#endif
ao_ms5607_start();
read = AO_MS5607_ADC_READ;
@@ -194,22 +203,17 @@ ao_ms5607_convert(struct ao_ms5607_sample *sample, struct ao_ms5607_value *value
value->temp = TEMP;
}
-struct ao_ms5607_sample ao_ms5607_current;
-uint8_t ao_ms5607_valid;
-
static void
ao_ms5607(void)
{
ao_ms5607_setup();
for (;;)
{
- static struct ao_ms5607_sample ao_ms5607_next;
- ao_ms5607_sample(&ao_ms5607_next);
+ ao_ms5607_sample((struct ao_ms5607_sample *) &ao_data_ring[ao_data_head].ms5607_raw);
ao_arch_critical(
- ao_ms5607_current = ao_ms5607_next;
- ao_ms5607_valid = 1;
+ AO_DATA_PRESENT(AO_DATA_MS5607);
+ AO_DATA_WAIT();
);
- ao_delay(0);
}
}
@@ -231,13 +235,13 @@ ao_ms5607_info(void)
static void
ao_ms5607_dump(void)
{
- struct ao_ms5607_sample sample;
+ struct ao_data sample;
struct ao_ms5607_value value;
- sample = ao_ms5607_current;
- ao_ms5607_convert(&sample, &value);
- printf ("Pressure: %8u %8d\n", sample.pres, value.pres);
- printf ("Temperature: %8u %8d\n", sample.temp, value.temp);
+ ao_data_get(&sample);
+ ao_ms5607_convert(&sample.ms5607_raw, &value);
+ printf ("Pressure: %8u %8d\n", sample.ms5607_raw.pres, value.pres);
+ printf ("Temperature: %8u %8d\n", sample.ms5607_raw.temp, value.temp);
printf ("Altitude: %ld\n", ao_pa_to_altitude(value.pres));
}
@@ -250,7 +254,6 @@ void
ao_ms5607_init(void)
{
ms5607_configured = 0;
- ao_ms5607_valid = 0;
ao_cmd_register(&ao_ms5607_cmds[0]);
ao_spi_init_cs(AO_MS5607_CS_GPIO, (1 << AO_MS5607_CS));
@@ -272,3 +275,5 @@ ao_ms5607_init(void)
AO_MS5607_MISO,
STM_MODER_ALTERNATE);
}
+
+#endif