#define PRINTD(l,...)
#endif
+#define AO_ADXL375_SPI_SPEED ao_spi_speed(5000000)
+
struct ao_adxl375_sample ao_adxl375_current;
static void
int32_t z;
};
-#define AO_ADXL375_SELF_TEST_SAMPLES 16
-#define AO_ADXL375_SELF_TEST_SETTLE 6
+#define AO_ADXL375_SELF_TEST_SAMPLES 10
+#define AO_ADXL375_SELF_TEST_SETTLE 4
#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))
#define MAX_SELF_TEST ((int32_t) (MAX_LSB_G * SELF_TEST_MAX_G * AO_ADXL375_SELF_TEST_SAMPLES + 0.5))
-static const int32_t min_self_test = MIN_SELF_TEST;
-static const int32_t max_self_test = MAX_SELF_TEST;
-
static void
ao_adxl375_total_value(struct ao_adxl375_total *total, int samples)
{
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,
(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 */
-#define AO_ADXL375_SELF_TEST_SAMPLES 16
-#define AO_ADXL375_SELF_TEST_SETTLE 6
-
struct ao_adxl375_total self_test_off, self_test_on;
/* Discard some samples to let it settle down */
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);
}
-static int adxl375_count;
-
static void
ao_adxl375(void)
{
ao_adxl375_setup();
for (;;) {
ao_adxl375_value(&ao_adxl375_current);
- ++adxl375_count;
ao_arch_critical(
AO_DATA_PRESENT(AO_DATA_ADXL375);
AO_DATA_WAIT();
static void
ao_adxl375_dump(void)
{
- printf ("ADXL375 value %d %d %d count %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,
- adxl375_count,
- 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[] = {