42 #include "sensor_defs.h"
46 #define HMC5883L_ADDR (0x1E)
48 #define RG_HMC5883L_CONFIG_A (0x00)
49 #define RG_HMC5883L_CONFIG_B (0x01)
50 #define RG_HMC5883L_MODE (0x02)
51 #define RG_HMC5883L_DATA_X (0x03)
52 #define RG_HMC5883L_DATA_Y (0x05)
53 #define RG_HMC5883L_DATA_Z (0x07)
54 #define RG_HMC5883L_STATUS (0x09)
55 #define RG_HMC5883L_IDENT_A (0x0A)
56 #define RG_HMC5883L_IDENT_B (0x0B)
57 #define RG_HMC5883L_IDENT_C (0x0C)
59 #define HMC5883L_GAIN (1090)
77 static inline void hmc5883l_trigger(
void *pctx,
bool one_shot)
79 uint8_t buf[2] = {RG_HMC5883L_MODE, 0x01};
83 static inline uint8_t hmc5883l_get_val(
void *pctx, uint8_t *pdata)
85 const uint8_t nbbytes = 6;
86 uint8_t reg = {RG_HMC5883L_DATA_X};
92 p->type = SENSOR_DATA_MAGNETIC;
93 p->sensor = SENSOR_HMC5883L;
94 p->x = (float)((buf[0] << 8) | buf[1]) / HMC5883L_GAIN;
95 p->y = (float)((buf[2] << 8) | buf[3]) / HMC5883L_GAIN;
96 p->z = (float)((buf[4] << 8) | buf[5]) / HMC5883L_GAIN;
101 static inline uint8_t hmc5883l_get_raw(
void *pctx, uint8_t *pdata)
107 static inline void hmc5883l_sleep(
void *pctx)
124 uint8_t rv =
sizeof(hmc5883l_ctx_t);
125 hmc5883l_ctx_t *pcfg;
130 pcfg = (hmc5883l_ctx_t *)pdata;
131 pcfg->g.id = SENSOR_HMC5883L;
132 pcfg->g.f_trigger = hmc5883l_trigger;
133 pcfg->g.f_get_val = raw ? hmc5883l_get_raw : hmc5883l_get_val;
134 pcfg->g.f_sleep = hmc5883l_sleep;
static uint8_t sensor_create_hmc5883l(void *pdata, bool raw, uint8_t addr)
uint8_t i2c_master_writeread(uint8_t devaddr, uint8_t *writebuf, uint8_t bytestowrite, uint8_t *readbuf, uint8_t bytestoread)