From eb6bce26b54683bb29cead10132a38cb51419ecd Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 21 Feb 2013 13:46:52 +0100 Subject: [PATCH] [peripherals] hmc58xx: fix typo in comment and make explict separate defines for Y,Z data regs for HMC5843/HMC5883 --- sw/airborne/peripherals/hmc58xx.c | 2 +- sw/airborne/peripherals/hmc58xx_regs.h | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sw/airborne/peripherals/hmc58xx.c b/sw/airborne/peripherals/hmc58xx.c index 873f045739..d320b37898 100644 --- a/sw/airborne/peripherals/hmc58xx.c +++ b/sw/airborne/peripherals/hmc58xx.c @@ -145,7 +145,7 @@ void hmc58xx_event(struct Hmc58xx *hmc) hmc->data.vect.y = Int16FromBuf(hmc->i2c_trans.buf,2); hmc->data.vect.z = Int16FromBuf(hmc->i2c_trans.buf,4); } - /* HMC5843 has xzy order of axes in returned data */ + /* HMC5883 has xzy order of axes in returned data */ else { hmc->data.vect.x = Int16FromBuf(hmc->i2c_trans.buf,0); hmc->data.vect.y = Int16FromBuf(hmc->i2c_trans.buf,4); diff --git a/sw/airborne/peripherals/hmc58xx_regs.h b/sw/airborne/peripherals/hmc58xx_regs.h index a570eda15e..7eb9a1aa2f 100644 --- a/sw/airborne/peripherals/hmc58xx_regs.h +++ b/sw/airborne/peripherals/hmc58xx_regs.h @@ -36,10 +36,24 @@ #define HMC58XX_REG_MODE 0x02 #define HMC58XX_REG_DATXM 0x03 #define HMC58XX_REG_DATXL 0x04 -#define HMC58XX_REG_DATYM 0x05 -#define HMC58XX_REG_DATYL 0x06 -#define HMC58XX_REG_DATZM 0x07 -#define HMC58XX_REG_DATZL 0x08 + +/* Warning! + * The HMC5843 and HMC5883 differ here. + * - HMC5843 order: Y,Z + * - HMC5883 order: Z,Y + * So we make defines for each version explicitly. + */ +#define HMC5843_REG_DATYM 0x05 +#define HMC5843_REG_DATYL 0x06 +#define HMC5843_REG_DATZM 0x07 +#define HMC5843_REG_DATZL 0x08 + +#define HMC5883_REG_DATZM 0x05 +#define HMC5883_REG_DATZL 0x06 +#define HMC5883_REG_DATYM 0x07 +#define HMC5883_REG_DATYL 0x08 + + #define HMC58XX_REG_STATUS 0x09 #define HMC58XX_REG_IDA 0x0A #define HMC58XX_REG_IDB 0x0B