trone: added support for WHOAMI register

This commit is contained in:
parallels 2015-01-27 00:41:12 +01:00 committed by Lorenz Meier
parent 215e8e2466
commit 7ca2553da2
1 changed files with 59 additions and 44 deletions

View File

@ -79,6 +79,9 @@
/* TRONE Registers addresses */ /* TRONE Registers addresses */
#define TRONE_MEASURE_REG 0x00 /* Measure range register */ #define TRONE_MEASURE_REG 0x00 /* Measure range register */
#define TRONE_WHO_AM_I_REG 0x01 /* Who am I test register */
#define TRONE_WHO_AM_I_REG_VAL 0xA1
/* Device limits */ /* Device limits */
#define TRONE_MIN_DISTANCE (0.20f) #define TRONE_MIN_DISTANCE (0.20f)
@ -308,9 +311,22 @@ out:
int int
TRONE::probe() TRONE::probe()
{ {
uint8_t who_am_i=0;
const uint8_t cmd = TRONE_WHO_AM_I_REG;
if (transfer(&cmd, 1, &who_am_i, 1) == OK && who_am_i == TRONE_WHO_AM_I_REG_VAL) {
// it is responding correctly to a WHO_AM_I
return measure(); return measure();
} }
debug("WHO_AM_I byte mismatch 0x%02x should be 0x%02x\n",
(unsigned)who_am_i,
TRONE_WHO_AM_I_REG_VAL);
// not found on any address
return -EIO;
}
void void
TRONE::set_minimum_distance(float min) TRONE::set_minimum_distance(float min)
{ {
@ -643,7 +659,6 @@ TRONE::cycle()
* Is there a collect->measure gap? * Is there a collect->measure gap?
*/ */
if (_measure_ticks > USEC2TICK(TRONE_CONVERSION_INTERVAL)) { if (_measure_ticks > USEC2TICK(TRONE_CONVERSION_INTERVAL)) {
/* schedule a fresh cycle call when we are ready to measure again */ /* schedule a fresh cycle call when we are ready to measure again */
work_queue(HPWORK, work_queue(HPWORK,
&_work, &_work,