From 2a8429320d0f6a055e5dfe74948dac82a804b373 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 12 Jul 2014 12:03:10 +0200 Subject: [PATCH] OP-1403 - Support HMC5983 temperature sensor/compensation --- flight/pios/common/pios_hmc5x83.c | 1 + flight/pios/inc/pios_hmc5x83.h | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/flight/pios/common/pios_hmc5x83.c b/flight/pios/common/pios_hmc5x83.c index 922b5fde7..d1854632f 100644 --- a/flight/pios/common/pios_hmc5x83.c +++ b/flight/pios/common/pios_hmc5x83.c @@ -135,6 +135,7 @@ static int32_t PIOS_HMC5x83_Config(const struct pios_hmc5x83_cfg *cfg) CTRLB = 0; CTRLA |= (uint8_t)(cfg->M_ODR | cfg->Meas_Conf); + CTRLA |= cfg->TempCompensation ? PIOS_HMC5x83_CTRLA_TEMP : 0; CTRLB |= (uint8_t)(cfg->Gain); MODE |= (uint8_t)(cfg->Mode); diff --git a/flight/pios/inc/pios_hmc5x83.h b/flight/pios/inc/pios_hmc5x83.h index fc0d9bbab..94f53b2f9 100644 --- a/flight/pios/inc/pios_hmc5x83.h +++ b/flight/pios/inc/pios_hmc5x83.h @@ -76,6 +76,8 @@ #define PIOS_HMC5x83_GAIN_5_6 0xC0 #define PIOS_HMC5x83_GAIN_8_1 0xE0 +#define PIOS_HMC5x83_CTRLA_TEMP 0x40 + /* Modes */ #define PIOS_HMC5x83_MODE_CONTINUOUS 0x00 #define PIOS_HMC5x83_MODE_SINGLE 0x01 @@ -109,10 +111,11 @@ struct pios_hmc5x83_cfg { #ifdef PIOS_HMC5x83_HAS_GPIOS const struct pios_exti_cfg *exti_cfg; /* Pointer to the EXTI configuration */ #endif - uint8_t M_ODR; /* OUTPUT DATA RATE --> here below the relative define (See datasheet page 11 for more details) */ - uint8_t Meas_Conf; /* Measurement Configuration,: Normal, positive bias, or negative bias --> here below the relative define */ - uint8_t Gain; /* Gain Configuration, select the full scale --> here below the relative define (See datasheet page 11 for more details) */ + uint8_t M_ODR; // OUTPUT DATA RATE --> here below the relative define (See datasheet page 11 for more details) */ + uint8_t Meas_Conf; // Measurement Configuration,: Normal, positive bias, or negative bias --> here below the relative define */ + uint8_t Gain; // Gain Configuration, select the full scale --> here below the relative define (See datasheet page 11 for more details) */ uint8_t Mode; + bool TempCompensation; // enable temperature sensor on HMC5983 for temperature gain compensation const struct pios_hmc5x83_io_driver *Driver; };