Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
hmc58xx.c File Reference

Driver for Honeywell HMC5843 and HMC5883 magnetometers. More...

#include "peripherals/hmc58xx.h"
#include "mcu_periph/sys_time.h"
#include "std.h"
+ Include dependency graph for hmc58xx.c:

Go to the source code of this file.

Macros

#define HMC58XX_DEFAULT_DO   0x6
 
#define HMC58XX_DEFAULT_MS   0x0
 
#define HMC58XX_DEFAULT_GN   0x1
 
#define HMC58XX_DEFAULT_MD   0x0
 
#define HMC58XX_STARTUP_DELAY   1.5
 HMC58XX startup delay. More...
 
#define Int16FromBuf(_buf, _idx)   ((int16_t)((_buf[_idx]<<8) | _buf[_idx+1]))
 

Functions

static void hmc58xx_set_default_config (struct Hmc58xxConfig *c)
 
void hmc58xx_init (struct Hmc58xx *hmc, struct i2c_periph *i2c_p, uint8_t addr)
 Initialize Hmc58xx struct and set default config options. More...
 
static void hmc58xx_i2c_tx_reg (struct Hmc58xx *hmc, uint8_t reg, uint8_t val)
 
static void hmc58xx_send_config (struct Hmc58xx *hmc)
 Configuration function called once before normal use. More...
 
void hmc58xx_start_configure (struct Hmc58xx *hmc)
 
void hmc58xx_read (struct Hmc58xx *hmc)
 
void hmc58xx_event (struct Hmc58xx *hmc)
 

Detailed Description

Driver for Honeywell HMC5843 and HMC5883 magnetometers.

Todo:
DRDY/IRQ handling

Definition in file hmc58xx.c.

Macro Definition Documentation

◆ HMC58XX_DEFAULT_DO

#define HMC58XX_DEFAULT_DO   0x6

Definition at line 37 of file hmc58xx.c.

◆ HMC58XX_DEFAULT_GN

#define HMC58XX_DEFAULT_GN   0x1

Definition at line 43 of file hmc58xx.c.

◆ HMC58XX_DEFAULT_MD

#define HMC58XX_DEFAULT_MD   0x0

Definition at line 46 of file hmc58xx.c.

◆ HMC58XX_DEFAULT_MS

#define HMC58XX_DEFAULT_MS   0x0

Definition at line 40 of file hmc58xx.c.

◆ HMC58XX_STARTUP_DELAY

#define HMC58XX_STARTUP_DELAY   1.5

HMC58XX startup delay.

On startup, the hmc is making a first conversion in single mode. Trying to configure the mode register before the end of this conversion seems to void the configuration. Default conversion rate is 15 Hz (66ms) and worst case is O.75Hz (1.3s). Let set the default delay to 1.5s afer boot time.

Definition at line 58 of file hmc58xx.c.

◆ Int16FromBuf

#define Int16FromBuf (   _buf,
  _idx 
)    ((int16_t)((_buf[_idx]<<8) | _buf[_idx+1]))

Definition at line 150 of file hmc58xx.c.

Function Documentation

◆ hmc58xx_event()

◆ hmc58xx_i2c_tx_reg()

static void hmc58xx_i2c_tx_reg ( struct Hmc58xx hmc,
uint8_t  reg,
uint8_t  val 
)
static

Definition at line 90 of file hmc58xx.c.

References i2c_transaction::buf, Hmc58xx::i2c_p, i2c_submit(), Hmc58xx::i2c_trans, I2CTransTx, i2c_transaction::len_r, i2c_transaction::len_w, i2c_transaction::type, and val.

Referenced by hmc58xx_send_config().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hmc58xx_init()

void hmc58xx_init ( struct Hmc58xx hmc,
struct i2c_periph i2c_p,
uint8_t  addr 
)

Initialize Hmc58xx struct and set default config options.

Parameters
hmcHmc58xx struct
i2c_pI2C periperal to use
addrI2C address of HMC58xx

Definition at line 75 of file hmc58xx.c.

References Hmc58xx::adc_overflow_cnt, Hmc58xx::config, hmc58xx_set_default_config(), HMC_CONF_UNINIT, HMC_TYPE_5883, Hmc58xx::i2c_p, Hmc58xx::i2c_trans, I2CTransDone, Hmc58xx::init_status, Hmc58xx::initialized, i2c_transaction::slave_addr, i2c_transaction::status, and Hmc58xx::type.

Referenced by imu_aspirin_i2c_init(), imu_aspirin_init(), imu_mpu_hmc_init(), imu_px4fmu_init(), and mag_hmc58xx_module_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hmc58xx_read()

void hmc58xx_read ( struct Hmc58xx hmc)

Definition at line 139 of file hmc58xx.c.

References i2c_transaction::buf, HMC58XX_REG_DATXM, Hmc58xx::i2c_p, i2c_submit(), Hmc58xx::i2c_trans, I2CTransDone, I2CTransTxRx, Hmc58xx::initialized, i2c_transaction::len_r, i2c_transaction::len_w, i2c_transaction::status, and i2c_transaction::type.

Referenced by hmc58xx_periodic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hmc58xx_send_config()

static void hmc58xx_send_config ( struct Hmc58xx hmc)
static

Configuration function called once before normal use.

Definition at line 101 of file hmc58xx.c.

References Hmc58xx::config, Hmc58xxConfig::gain, hmc58xx_i2c_tx_reg(), HMC58XX_REG_CFGA, HMC58XX_REG_CFGB, HMC58XX_REG_MODE, HMC_CONF_CRA, HMC_CONF_CRB, HMC_CONF_DONE, HMC_CONF_MODE, Hmc58xx::i2c_trans, I2CTransDone, Hmc58xx::init_status, Hmc58xx::initialized, Hmc58xxConfig::meas, Hmc58xxConfig::mode, Hmc58xxConfig::rate, and i2c_transaction::status.

Referenced by hmc58xx_event(), and hmc58xx_start_configure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hmc58xx_set_default_config()

static void hmc58xx_set_default_config ( struct Hmc58xxConfig c)
static

Definition at line 61 of file hmc58xx.c.

References Hmc58xxConfig::gain, HMC58XX_DEFAULT_DO, HMC58XX_DEFAULT_GN, HMC58XX_DEFAULT_MD, HMC58XX_DEFAULT_MS, Hmc58xxConfig::meas, Hmc58xxConfig::mode, and Hmc58xxConfig::rate.

Referenced by hmc58xx_init().

+ Here is the caller graph for this function:

◆ hmc58xx_start_configure()

void hmc58xx_start_configure ( struct Hmc58xx hmc)

Definition at line 126 of file hmc58xx.c.

References get_sys_time_float(), hmc58xx_send_config(), HMC58XX_STARTUP_DELAY, HMC_CONF_UNINIT, Hmc58xx::i2c_trans, I2CTransDone, I2CTransSuccess, Hmc58xx::init_status, and i2c_transaction::status.

Referenced by hmc58xx_periodic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: