X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fdrivers%2Fao_adxl375.c;h=9e5666cc5d6dcb83ea11697e676ba3b544555f01;hb=c1708f3fa4ff412da8817ba0fa58d05fe7ef44f5;hp=778c214b6e49b637a0ebd0be74b65c5de1120b68;hpb=c01514fa1e0a2cea3955c71a833b4a21b3d33f24;p=fw%2Faltos diff --git a/src/drivers/ao_adxl375.c b/src/drivers/ao_adxl375.c index 778c214b..9e5666cc 100644 --- a/src/drivers/ao_adxl375.c +++ b/src/drivers/ao_adxl375.c @@ -21,11 +21,13 @@ #define DEBUG 0 #if DEBUG -#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: ", ao_tick_count, __func__); printf(__VA_ARGS__); flush(); } } while(0) #else #define PRINTD(l,...) #endif +#define AO_ADXL375_SPI_SPEED ao_spi_speed(5000000) + struct ao_adxl375_sample ao_adxl375_current; static void @@ -53,7 +55,7 @@ ao_adxl375_reg_read(uint8_t addr) ao_spi_duplex(d, d, 2, AO_ADXL375_SPI_INDEX); ao_adxl375_stop(); - PRINTD(DEBUG_LOW, "read %x = %x\n", addr, d); + PRINTD(DEBUG_LOW, "read %x = %x\n", addr, d[1]); return d[1]; } @@ -71,7 +73,7 @@ ao_adxl375_reg_write(uint8_t addr, uint8_t value) ao_adxl375_stop(); #if DEBUG & DEBUG_LOW - d[0] = addr | AO_ADXL375_READ + d[0] = addr | AO_ADXL375_READ; d[1] = 0; ao_adxl375_start(); ao_spi_duplex(d, d, 2, AO_ADXL375_SPI_INDEX); @@ -103,7 +105,7 @@ struct ao_adxl375_total { #define MIN_LSB_G 18.4 #define MAX_LSB_G 22.6 -#define SELF_TEST_MIN_G 6.0 +#define SELF_TEST_MIN_G 5.0 #define SELF_TEST_MAX_G 6.8 #define MIN_SELF_TEST ((int32_t) (MIN_LSB_G * SELF_TEST_MIN_G * AO_ADXL375_SELF_TEST_SAMPLES + 0.5)) @@ -127,7 +129,7 @@ ao_adxl375_total_value(struct ao_adxl375_total *total, int samples) #define AO_ADXL375_DATA_FORMAT_SETTINGS(self_test) ( \ AO_ADXL375_DATA_FORMAT_FIXED | \ (self_test << AO_ADXL375_DATA_FORMAT_SELF_TEST) | \ - (AO_ADXL375_DATA_FORMAT_SPI_4_WIRE << AO_ADXL375_DATA_FORMAT_SPI_4_WIRE) | \ + (AO_ADXL375_DATA_FORMAT_SPI_4_WIRE << AO_ADXL375_DATA_FORMAT_SPI) | \ (0 << AO_ADXL375_DATA_FORMAT_INT_INVERT) | \ (0 << AO_ADXL375_DATA_FORMAT_JUSTIFY)) @@ -143,7 +145,7 @@ ao_adxl375_setup(void) uint8_t devid = ao_adxl375_reg_read(AO_ADXL375_DEVID); if (devid != AO_ADXL375_DEVID_ID) - ao_sensor_errors = 1; + AO_SENSOR_ERROR(AO_DATA_ADXL375); /* Set the data rate */ ao_adxl375_reg_write(AO_ADXL375_BW_RATE, @@ -172,7 +174,6 @@ ao_adxl375_setup(void) (0 << AO_ADXL375_POWER_CTL_SLEEP) | (AO_ADXL375_POWER_CTL_WAKEUP_8 << AO_ADXL375_POWER_CTL_WAKEUP)); - (void) ao_adxl375_total_value; /* Perform self-test */ struct ao_adxl375_total self_test_off, self_test_on; @@ -204,8 +205,15 @@ ao_adxl375_setup(void) self_test_value = z_change; - if (z_change < MIN_SELF_TEST || MAX_SELF_TEST < z_change) - ao_sensor_errors = 1; + if (z_change < MIN_SELF_TEST) + AO_SENSOR_ERROR(AO_DATA_ADXL375); + + /* This check is commented out as maximum self test is unreliable + + if (z_change > MAX_SELF_TEST) + AO_SENSOR_ERROR(AO_DATA_ADXL375); + + */ /* Discard some samples to let it settle down */ ao_adxl375_total_value(&self_test_off, AO_ADXL375_SELF_TEST_SETTLE); @@ -229,13 +237,13 @@ static struct ao_task ao_adxl375_task; static void ao_adxl375_dump(void) { - printf ("ADXL375 value %d %d %d self test %d min %d max %d\n", + printf ("ADXL375 value %d %d %d self test %ld min %ld max %ld\n", ao_adxl375_current.x, ao_adxl375_current.y, ao_adxl375_current.z, - self_test_value, - MIN_SELF_TEST, - MAX_SELF_TEST); + (long) self_test_value, + (long) MIN_SELF_TEST, + (long) MAX_SELF_TEST); } const struct ao_cmds ao_adxl375_cmds[] = {