altos: Use new ao_spi_speed inline to set SPI speeds using spec'd frequencies
[fw/altos] / src / drivers / ao_mma655x.c
index a48c1db20cec31606910d5446d69e30ad7c3eb36..7736a0f89c4889d49cb3a86a31667fb226d56794 100644 (file)
 #define DEBUG_LOW      1
 #define DEBUG_HIGH     2
 #if 1
-#define PRINTD(l, ...) do { if (DEBUG & (l)) { printf ("\r%5u %s: ", ao_tick_count, __func__); printf(__VA_ARGS__); flush(); } } while(0)
+#define PRINTD(l, ...) do { if (DEBUG & (l)) { printf ("\r%5lu %s: ", (unsigned long) ao_tick_count, __func__); printf(__VA_ARGS__); flush(); } } while(0)
 #else
 #define PRINTD(l,...) 
 #endif
 
+#define AO_MMA655X_SPI_SPEED   ao_spi_speed(8333333)   /* 120ns clock period */
+
 static void
 ao_mma655x_start(void) {
        ao_spi_get_bit(AO_MMA655X_CS_PORT,
                       AO_MMA655X_CS_PIN,
-                      AO_MMA655X_CS,
                       AO_MMA655X_SPI_INDEX,
-                      AO_SPI_SPEED_FAST);
+                      AO_MMA655X_SPI_SPEED);
 }
 
 static void
 ao_mma655x_stop(void) {
        ao_spi_put_bit(AO_MMA655X_CS_PORT,
                       AO_MMA655X_CS_PIN,
-                      AO_MMA655X_CS,
                       AO_MMA655X_SPI_INDEX);
 }
 
 static void
 ao_mma655x_restart(void) {
        uint8_t i;
-       ao_gpio_set(AO_MMA655X_CS_PORT, AO_MMA655X_CS_PIN, AO_MMA655X_CS, 1);
+       ao_gpio_set(AO_MMA655X_CS_PORT, AO_MMA655X_CS_PIN, 1);
 
        /* Emperical testing on STM32L151 at 32MHz for this delay amount */
        for (i = 0; i < 10; i++)
                ao_arch_nop();
-       ao_gpio_set(AO_MMA655X_CS_PORT, AO_MMA655X_CS_PIN, AO_MMA655X_CS, 0);
+       ao_gpio_set(AO_MMA655X_CS_PORT, AO_MMA655X_CS_PIN, 0);
 }
 
 static uint8_t
@@ -234,7 +234,7 @@ ao_mma655x_setup(void)
                ao_delay(AO_ST_DELAY);
        }
        if (tries == AO_ST_TRIES)
-               ao_sensor_errors = 1;
+               AO_SENSOR_ERROR(AO_DATA_MMA655X);
 
        ao_mma655x_reg_write(AO_MMA655X_DEVCFG,
                             DEVCFG_VALUE | (1 << AO_MMA655X_DEVCFG_ENDINIT));