mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-09 22:49:53 +08:00
Port HMC5843 to new i2c format, enable i2c for test_imu_b2
This commit is contained in:
@@ -360,7 +360,9 @@ test_imu_b2_2.CFLAGS += -DMAX_1168_DRDY_PORT_SOURCE=$(MAX_1168_DRDY_PORT_SOURCE)
|
||||
test_imu_b2_2.CFLAGS += -DUSE_SPI2 -DUSE_DMA1_C4_IRQ -DUSE_EXTI2_IRQ -DUSE_SPI2_IRQ
|
||||
test_imu_b2_2.srcs += $(SRC_FIRMWARE)/imu/imu_b2.c $(SRC_FIRMWARE)/imu/arch/$(ARCH)/imu_b2_arch.c
|
||||
test_imu_b2_2.srcs += $(SRC_BOOZ)/peripherals/booz_max1168.c $(SRC_BOOZ_ARCH)/peripherals/booz_max1168_arch.c
|
||||
test_imu_b2_2.srcs += $(SRC_BOOZ)/peripherals/booz_hmc5843.c # $(SRC_BOOZ_ARCH)/peripherals/booz_hmc5843.c
|
||||
test_imu_b2_2.CFLAGS += -DUSE_I2C2
|
||||
test_imu_b2_2.srcs += i2c.c $(SRC_ARCH)/i2c_hw.c
|
||||
test_imu_b2_2.srcs += $(SRC_BOOZ)/peripherals/booz_hmc5843.c
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,36 +3,49 @@
|
||||
#include "i2c.h"
|
||||
|
||||
struct Hmc5843 hmc5843;
|
||||
static struct i2c_transaction hmc5843_i2c_trans;
|
||||
|
||||
void hmc5843_init(void) {
|
||||
hmc5843.status = HMC5843_UNINITIALIZED1;
|
||||
hmc5843.i2c_done = TRUE;
|
||||
|
||||
hmc5843_i2c_trans.status = I2CTransSuccess;
|
||||
hmc5843_i2c_trans.slave_addr = HMC5843_ADDR;
|
||||
hmc5843_i2c_trans.stop_after_transmit = TRUE;
|
||||
}
|
||||
|
||||
void hmc5843_periodic(void) {
|
||||
|
||||
if (!hmc5843.i2c_done) return;
|
||||
if (hmc5843_i2c_trans.status != I2CTransSuccess) return;
|
||||
switch (hmc5843.status) {
|
||||
case HMC5843_UNINITIALIZED1:
|
||||
i2c2.buf[0] = HMC5843_REG_CFGA; // set to rate to 50Hz
|
||||
i2c2.buf[1] = 0x00 | (0x06 << 2);
|
||||
i2c2_transmit(HMC5843_ADDR, 2, &hmc5843.i2c_done);
|
||||
hmc5843_i2c_trans.buf[0] = HMC5843_REG_CFGA; // set to rate to 50Hz
|
||||
hmc5843_i2c_trans.buf[1] = 0x00 | (0x06 << 2);
|
||||
hmc5843_i2c_trans.type = I2CTransTx;
|
||||
hmc5843_i2c_trans.len_w = 2;
|
||||
i2c_submit(&i2c2, &hmc5843_i2c_trans);
|
||||
hmc5843.status = HMC5843_UNINITIALIZED2;
|
||||
break;
|
||||
case HMC5843_UNINITIALIZED2:
|
||||
i2c2.buf[0] = HMC5843_REG_CFGB; // set to gain to 1 Gauss
|
||||
i2c2.buf[1] = 0x01<<5;
|
||||
i2c2_transmit(HMC5843_ADDR, 2, &hmc5843.i2c_done);
|
||||
hmc5843_i2c_trans.buf[0] = HMC5843_REG_CFGB; // set to gain to 1 Gauss
|
||||
hmc5843_i2c_trans.buf[1] = 0x01<<5;
|
||||
hmc5843_i2c_trans.type = I2CTransTx;
|
||||
hmc5843_i2c_trans.len_w = 2;
|
||||
i2c_submit(&i2c2, &hmc5843_i2c_trans);
|
||||
hmc5843.status = HMC5843_UNINITIALIZED3;
|
||||
break;
|
||||
case HMC5843_UNINITIALIZED3:
|
||||
i2c2.buf[0] = HMC5843_REG_MODE; // set to continuous mode
|
||||
i2c2.buf[1] = 0x00;
|
||||
i2c2_transmit(HMC5843_ADDR, 2, &hmc5843.i2c_done);
|
||||
hmc5843_i2c_trans.buf[0] = HMC5843_REG_MODE; // set to continuous mode
|
||||
hmc5843_i2c_trans.buf[1] = 0x00;
|
||||
hmc5843_i2c_trans.type = I2CTransTx;
|
||||
hmc5843_i2c_trans.len_w = 2;
|
||||
i2c_submit(&i2c2, &hmc5843_i2c_trans);
|
||||
hmc5843.status = HMC5843_IDLE;
|
||||
break;
|
||||
case HMC5843_IDLE:
|
||||
i2c2_receive(HMC5843_ADDR, 6, &hmc5843.i2c_done);
|
||||
hmc5843_i2c_trans.type = I2CTransRx;
|
||||
hmc5843_i2c_trans.len_w = 6;
|
||||
i2c_submit(&i2c2, &hmc5843_i2c_trans);
|
||||
hmc5843.status = HMC5843_READING;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -69,7 +69,7 @@ extern void hmc5843_periodic(void);
|
||||
#include <string.h>
|
||||
|
||||
#define MagEvent(_m_handler) { \
|
||||
if (hmc5843.status == HMC5843_READING && hmc5843.i2c_done) { \
|
||||
if (hmc5843.status == HMC5843_READING && hmc5843_i2c_trans.status == I2CTransSuccess) { \
|
||||
memcpy(hmc5843.data.buf, (const void*)i2c2.buf, 6); \
|
||||
_m_handler(); \
|
||||
hmc5843.status = HMC5843_IDLE; \
|
||||
|
||||
Reference in New Issue
Block a user