60 lsm->i2c_trans.buf[0] = reg;
61 lsm->i2c_trans.buf[1] =
val;
62 lsm->i2c_trans.len_r = 0;
63 lsm->i2c_trans.len_w = 2;
71 switch (lsm->init_status.acc) {
72 case LSM_CONF_ACC_CTRL_REG4_A:
75 (lsm->config.acc.hres & LSM303DLHC_DEFAULT_HR));
76 lsm->init_status.acc++;
78 case LSM_CONF_ACC_CTRL_REG1_A:
80 (lsm->config.acc.rate & LSM303DLHC_ODR_MASK) |
81 (lsm->config.acc.lp_mode & LSM303DLHC_LPen) |
83 lsm->init_status.acc++;
85 case LSM_CONF_ACC_CTRL_REG3_A:
87 lsm->init_status.acc++;
89 case LSM_CONF_ACC_DONE:
90 lsm->initialized =
true;
98 switch (lsm->init_status.mag) {
99 case LSM_CONF_MAG_CRA_REG_M:
101 lsm->init_status.mag++;
103 case LSM_CONF_MAG_CRB_REG_M:
105 lsm->init_status.mag++;
107 case LSM_CONF_MAG_MR_REG_M:
109 lsm->init_status.mag++;
111 case LSM_CONF_MAG_DONE:
112 lsm->initialized =
true;
125 if (lsm->init_status.acc == LSM_CONF_ACC_UNINIT) {
126 lsm->init_status.acc++;
128 lsm303dlhc_send_config(lsm);
132 if (lsm->init_status.mag == LSM_CONF_MAG_UNINIT) {
133 lsm->init_status.mag++;
146 if (!(lsm->initialized) || (lsm->initialized && lsm->i2c_trans.status ==
I2CTransDone)) {
149 lsm->i2c_trans.len_r = 6;
150 lsm->i2c_trans.len_w = 1;
154 if (lsm->initialized && lsm->i2c_trans.status ==
I2CTransDone) {
157 lsm->i2c_trans.len_r = 6;
158 lsm->i2c_trans.len_w = 1;
164 #define Int16FromBuf(_buf,_idx) ((int16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
168 if (lsm->initialized) {
175 lsm->data_available =
true;
181 if (lsm->init_status.acc != LSM_CONF_ACC_UNINIT) {
184 lsm303dlhc_send_config(lsm);
187 lsm->init_status.acc--;
189 lsm303dlhc_send_config(lsm);
193 if (lsm->init_status.mag != LSM_CONF_MAG_UNINIT) {
196 lsm303dlhc_send_config(lsm);
199 lsm->init_status.mag--;
201 lsm303dlhc_send_config(lsm);
enum I2CTransactionStatus status
Transaction status.
uint8_t slave_addr
Slave address.
static bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Submit a I2C transaction.
@ I2CTransSuccess
transaction successfully finished by I2C driver
@ I2CTransFailed
transaction failed
@ I2CTransDone
transaction set to done by user level
@ I2CTransTx
transmit only transaction
@ I2CTransTxRx
transmit and receive transaction
static void lsm303dlhc_mag_set_default_config(struct Lsm303dlhcMagConfig *c)
static void lsm303dlhc_acc_set_default_config(struct Lsm303dlhcAccConfig *c)
static void lsm303dlhc_i2c_tx_reg(struct Lsm303dlhc_I2c *lsm, uint8_t reg, uint8_t val)
void lsm303dlhc_i2c_read(struct Lsm303dlhc *lsm)
void lsm303dlhc_i2c_event(struct Lsm303dlhc *lsm)
void lsm303dlhc_i2c_init(struct Lsm303dlhc_i2c *lsm, struct i2c_periph *i2c_p, uint8_t addr)
Initialize Lsm303dlhc struct and set default config options.
static void lsm303dlhc_i2c_send_config(struct Lsm303dlhc_I2c *lsm)
Configuration function called once before normal use.
void lsm303dlhc_i2c_start_configure(struct Lsm303dlhc_I2c *lsm)
#define Int16FromBuf(_buf, _idx)
union Lsm303dlhc_i2c::@336 config
struct i2c_transaction i2c_trans
struct i2c_periph * i2c_p
bool initialized
config done flag
union Lsm303dlhc_i2c::@334 init_status
#define LSM303DLHC_REG_OUT_X_H_M
#define LSM303DLHC_ACC_ADDR
#define LSM303DLHC_FS_MASK
#define LSM303DLHC_REG_OUT_X_L_A
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.