123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569 |
- #ifndef BMM150_DEFS_H_
- #define BMM150_DEFS_H_
- #ifdef __KERNEL__
- #include <linux/types.h>
- #else
- #include <stdint.h>
- #include <stddef.h>
- #endif
- #ifdef __KERNEL__
- #if (LONG_MAX) > 0x7fffffff
- #define __have_long64 1
- #elif (LONG_MAX) == 0x7fffffff
- #define __have_long32 1
- #endif
- #endif
- #if !defined(UINT8_C)
- #define INT8_C(x) x
- #if (INT_MAX) > 0x7f
- #define UINT8_C(x) x
- #else
- #define UINT8_C(x) x##U
- #endif
- #endif
- #if !defined(UINT16_C)
- #define INT16_C(x) x
- #if (INT_MAX) > 0x7fff
- #define UINT16_C(x) x
- #else
- #define UINT16_C(x) x##U
- #endif
- #endif
- #if !defined(INT32_C) && !defined(UINT32_C)
- #if __have_long32
- #define INT32_C(x) x##L
- #define UINT32_C(x) x##UL
- #else
- #define INT32_C(x) x
- #define UINT32_C(x) x##U
- #endif
- #endif
- #if !defined(INT64_C) && !defined(UINT64_C)
- #if __have_long64
- #define INT64_C(x) x##L
- #define UINT64_C(x) x##UL
- #else
- #define INT64_C(x) x##LL
- #define UINT64_C(x) x##ULL
- #endif
- #endif
- #ifndef NULL
- #ifdef __cplusplus
- #define NULL 0
- #else
- #define NULL ((void *) 0)
- #endif
- #endif
- #define TRUE UINT8_C(1)
- #define FALSE UINT8_C(0)
- #define BMM150_USE_FLOATING_POINT
- #define BMM150_OK INT8_C(0)
- #define BMM150_E_NULL_PTR INT8_C(-1)
- #define BMM150_E_DEV_NOT_FOUND INT8_C(-2)
- #define BMM150_E_INVALID_CONFIG INT8_C(-3)
- #define BMM150_W_NORMAL_SELF_TEST_YZ_FAIL INT8_C(1)
- #define BMM150_W_NORMAL_SELF_TEST_XZ_FAIL INT8_C(2)
- #define BMM150_W_NORMAL_SELF_TEST_Z_FAIL INT8_C(3)
- #define BMM150_W_NORMAL_SELF_TEST_XY_FAIL INT8_C(4)
- #define BMM150_W_NORMAL_SELF_TEST_Y_FAIL INT8_C(5)
- #define BMM150_W_NORMAL_SELF_TEST_X_FAIL INT8_C(6)
- #define BMM150_W_NORMAL_SELF_TEST_XYZ_FAIL INT8_C(7)
- #define BMM150_W_ADV_SELF_TEST_FAIL INT8_C(8)
- #define BMM150_CHIP_ID UINT8_C(0x32)
- #define BMM150_SET_SOFT_RESET UINT8_C(0x82)
- #define BMM150_NORMAL_MODE UINT8_C(0x00)
- #define BMM150_FORCED_MODE UINT8_C(0x01)
- #define BMM150_SLEEP_MODE UINT8_C(0x03)
- #define BMM150_SUSPEND_MODE UINT8_C(0x04)
- #define BMM150_DEFAULT_I2C_ADDRESS UINT8_C(0x10)
- #define BMM150_I2C_ADDRESS_CSB_LOW_SDO_HIGH UINT8_C(0x11)
- #define BMM150_I2C_ADDRESS_CSB_HIGH_SDO_LOW UINT8_C(0x12)
- #define BMM150_I2C_ADDRESS_CSB_HIGH_SDO_HIGH UINT8_C(0x13)
- #define BMM150_POWER_CNTRL_DISABLE UINT8_C(0x00)
- #define BMM150_POWER_CNTRL_ENABLE UINT8_C(0x01)
- #define BMM150_SOFT_RESET_DELAY UINT8_C(1)
- #define BMM150_NORMAL_SELF_TEST_DELAY UINT8_C(2)
- #define BMM150_START_UP_TIME UINT8_C(3)
- #define BMM150_ADV_SELF_TEST_DELAY UINT8_C(4)
- #define BMM150_XY_CHANNEL_ENABLE UINT8_C(0x00)
- #define BMM150_XY_CHANNEL_DISABLE UINT8_C(0x03)
- #define BMM150_CHIP_ID_ADDR UINT8_C(0x40)
- #define BMM150_DATA_X_LSB UINT8_C(0x42)
- #define BMM150_DATA_READY_STATUS UINT8_C(0x48)
- #define BMM150_INTERRUPT_STATUS UINT8_C(0x4A)
- #define BMM150_POWER_CONTROL_ADDR UINT8_C(0x4B)
- #define BMM150_OP_MODE_ADDR UINT8_C(0x4C)
- #define BMM150_INT_CONFIG_ADDR UINT8_C(0x4D)
- #define BMM150_AXES_ENABLE_ADDR UINT8_C(0x4E)
- #define BMM150_LOW_THRESHOLD_ADDR UINT8_C(0x4F)
- #define BMM150_HIGH_THRESHOLD_ADDR UINT8_C(0x50)
- #define BMM150_REP_XY_ADDR UINT8_C(0x51)
- #define BMM150_REP_Z_ADDR UINT8_C(0x52)
- #define BMM150_DATA_RATE_SEL UINT16_C(1)
- #define BMM150_CONTROL_MEASURE_SEL UINT16_C(1 << 1)
- #define BMM150_XY_REP_SEL UINT16_C(1 << 2)
- #define BMM150_Z_REP_SEL UINT16_C(1 << 3)
- #define BMM150_DRDY_PIN_EN_SEL UINT16_C(1 << 4)
- #define BMM150_INT_PIN_EN_SEL UINT16_C(1 << 5)
- #define BMM150_DRDY_POLARITY_SEL UINT16_C(1 << 6)
- #define BMM150_INT_LATCH_SEL UINT16_C(1 << 7)
- #define BMM150_INT_POLARITY_SEL UINT16_C(1 << 8)
- #define BMM150_DATA_OVERRUN_INT_SEL UINT16_C(1 << 9)
- #define BMM150_OVERFLOW_INT_SEL UINT16_C(1 << 10)
- #define BMM150_HIGH_THRESHOLD_INT_SEL UINT16_C(1 << 11)
- #define BMM150_LOW_THRESHOLD_INT_SEL UINT16_C(1 << 12)
- #define BMM150_LOW_THRESHOLD_SETTING_SEL UINT16_C(1 << 13)
- #define BMM150_HIGH_THRESHOLD_SETTING_SEL UINT16_C(1 << 14)
- #define BMM150_DATA_RATE_10HZ UINT8_C(0x00)
- #define BMM150_DATA_RATE_02HZ UINT8_C(0x01)
- #define BMM150_DATA_RATE_06HZ UINT8_C(0x02)
- #define BMM150_DATA_RATE_08HZ UINT8_C(0x03)
- #define BMM150_DATA_RATE_15HZ UINT8_C(0x04)
- #define BMM150_DATA_RATE_20HZ UINT8_C(0x05)
- #define BMM150_DATA_RATE_25HZ UINT8_C(0x06)
- #define BMM150_DATA_RATE_30HZ UINT8_C(0x07)
- #define BMM150_DIG_X1 UINT8_C(0x5D)
- #define BMM150_DIG_Y1 UINT8_C(0x5E)
- #define BMM150_DIG_Z4_LSB UINT8_C(0x62)
- #define BMM150_DIG_Z4_MSB UINT8_C(0x63)
- #define BMM150_DIG_X2 UINT8_C(0x64)
- #define BMM150_DIG_Y2 UINT8_C(0x65)
- #define BMM150_DIG_Z2_LSB UINT8_C(0x68)
- #define BMM150_DIG_Z2_MSB UINT8_C(0x69)
- #define BMM150_DIG_Z1_LSB UINT8_C(0x6A)
- #define BMM150_DIG_Z1_MSB UINT8_C(0x6B)
- #define BMM150_DIG_XYZ1_LSB UINT8_C(0x6C)
- #define BMM150_DIG_XYZ1_MSB UINT8_C(0x6D)
- #define BMM150_DIG_Z3_LSB UINT8_C(0x6E)
- #define BMM150_DIG_Z3_MSB UINT8_C(0x6F)
- #define BMM150_DIG_XY2 UINT8_C(0x70)
- #define BMM150_DIG_XY1 UINT8_C(0x71)
- #define BMM150_THRESHOLD_X UINT8_C(0x06)
- #define BMM150_THRESHOLD_Y UINT8_C(0x05)
- #define BMM150_THRESHOLD_Z UINT8_C(0x03)
- #define BMM150_INT_ENABLE UINT8_C(0x01)
- #define BMM150_INT_DISABLE UINT8_C(0x00)
- #define BMM150_ACTIVE_HIGH_POLARITY UINT8_C(0x01)
- #define BMM150_ACTIVE_LOW_POLARITY UINT8_C(0x00)
- #define BMM150_LATCHED UINT8_C(0x01)
- #define BMM150_NON_LATCHED UINT8_C(0x00)
- #define BMM150_LOW_THRESHOLD_INT_X UINT16_C(0x0001)
- #define BMM150_LOW_THRESHOLD_INT_Y UINT16_C(0x0002)
- #define BMM150_LOW_THRESHOLD_INT_Z UINT16_C(0x0004)
- #define BMM150_HIGH_THRESHOLD_INT_X UINT16_C(0x0008)
- #define BMM150_HIGH_THRESHOLD_INT_Y UINT16_C(0x0010)
- #define BMM150_HIGH_THRESHOLD_INT_Z UINT16_C(0x0020)
- #define BMM150_DATA_OVERFLOW_INT UINT16_C(0x0040)
- #define BMM150_DATA_OVERRUN_INT UINT16_C(0x0080)
- #define BMM150_DATA_READY_INT UINT16_C(0x0100)
- #define BMM150_PWR_CNTRL_MSK UINT8_C(0x01)
- #define BMM150_CONTROL_MEASURE_MSK UINT8_C(0x38)
- #define BMM150_CONTROL_MEASURE_POS UINT8_C(0x03)
- #define BMM150_POWER_CONTROL_BIT_MSK UINT8_C(0x01)
- #define BMM150_POWER_CONTROL_BIT_POS UINT8_C(0x00)
- #define BMM150_OP_MODE_MSK UINT8_C(0x06)
- #define BMM150_OP_MODE_POS UINT8_C(0x01)
- #define BMM150_ODR_MSK UINT8_C(0x38)
- #define BMM150_ODR_POS UINT8_C(0x03)
- #define BMM150_DATA_X_MSK UINT8_C(0xF8)
- #define BMM150_DATA_X_POS UINT8_C(0x03)
- #define BMM150_DATA_Y_MSK UINT8_C(0xF8)
- #define BMM150_DATA_Y_POS UINT8_C(0x03)
- #define BMM150_DATA_Z_MSK UINT8_C(0xFE)
- #define BMM150_DATA_Z_POS UINT8_C(0x01)
- #define BMM150_DATA_RHALL_MSK UINT8_C(0xFC)
- #define BMM150_DATA_RHALL_POS UINT8_C(0x02)
- #define BMM150_SELF_TEST_MSK UINT8_C(0x01)
- #define BMM150_ADV_SELF_TEST_MSK UINT8_C(0xC0)
- #define BMM150_ADV_SELF_TEST_POS UINT8_C(0x06)
- #define BMM150_DRDY_EN_MSK UINT8_C(0x80)
- #define BMM150_DRDY_EN_POS UINT8_C(0x07)
- #define BMM150_INT_PIN_EN_MSK UINT8_C(0x40)
- #define BMM150_INT_PIN_EN_POS UINT8_C(0x06)
- #define BMM150_DRDY_POLARITY_MSK UINT8_C(0x04)
- #define BMM150_DRDY_POLARITY_POS UINT8_C(0x02)
- #define BMM150_INT_LATCH_MSK UINT8_C(0x02)
- #define BMM150_INT_LATCH_POS UINT8_C(0x01)
- #define BMM150_INT_POLARITY_MSK UINT8_C(0x01)
- #define BMM150_DATA_OVERRUN_INT_MSK UINT8_C(0x80)
- #define BMM150_DATA_OVERRUN_INT_POS UINT8_C(0x07)
- #define BMM150_OVERFLOW_INT_MSK UINT8_C(0x40)
- #define BMM150_OVERFLOW_INT_POS UINT8_C(0x06)
- #define BMM150_HIGH_THRESHOLD_INT_MSK UINT8_C(0x38)
- #define BMM150_HIGH_THRESHOLD_INT_POS UINT8_C(0x03)
- #define BMM150_LOW_THRESHOLD_INT_MSK UINT8_C(0x07)
- #define BMM150_DRDY_STATUS_MSK UINT8_C(0x01)
- #define BMM150_XYAXES_FLIP_OVERFLOW_ADCVAL INT16_C(-4096)
- #define BMM150_ZAXIS_HALL_OVERFLOW_ADCVAL INT16_C(-16384)
- #define BMM150_OVERFLOW_OUTPUT INT16_C(-32768)
- #define BMM150_NEGATIVE_SATURATION_Z INT16_C(-32767)
- #define BMM150_POSITIVE_SATURATION_Z UINT16_C(32767)
- #ifdef BMM150_USE_FLOATING_POINT
- #define BMM150_OVERFLOW_OUTPUT_FLOAT 0.0f
- #endif
- #define BMM150_PRESETMODE_LOWPOWER UINT8_C(0x01)
- #define BMM150_PRESETMODE_REGULAR UINT8_C(0x02)
- #define BMM150_PRESETMODE_HIGHACCURACY UINT8_C(0x03)
- #define BMM150_PRESETMODE_ENHANCED UINT8_C(0x04)
- #define BMM150_LOWPOWER_REPXY UINT8_C(1)
- #define BMM150_REGULAR_REPXY UINT8_C(4)
- #define BMM150_ENHANCED_REPXY UINT8_C(7)
- #define BMM150_HIGHACCURACY_REPXY UINT8_C(23)
- #define BMM150_LOWPOWER_REPZ UINT8_C(2)
- #define BMM150_REGULAR_REPZ UINT8_C(14)
- #define BMM150_ENHANCED_REPZ UINT8_C(26)
- #define BMM150_HIGHACCURACY_REPZ UINT8_C(82)
- #define BMM150_SELF_TEST_LEN UINT8_C(5)
- #define BMM150_SETTING_DATA_LEN UINT8_C(8)
- #define BMM150_XYZR_DATA_LEN UINT8_C(8)
- #define BMM150_NORMAL_SELF_TEST UINT8_C(0)
- #define BMM150_ADVANCED_SELF_TEST UINT8_C(1)
- #define BMM150_DISABLE_XY_AXIS UINT8_C(0x03)
- #define BMM150_SELF_TEST_REP_Z UINT8_C(0x04)
- #define BMM150_DISABLE_SELF_TEST_CURRENT UINT8_C(0x00)
- #define BMM150_ENABLE_NEGATIVE_CURRENT UINT8_C(0x02)
- #define BMM150_ENABLE_POSITIVE_CURRENT UINT8_C(0x03)
- #define BMM150_SELF_TEST_STATUS_XYZ_FAIL UINT8_C(0x00)
- #define BMM150_SELF_TEST_STATUS_SUCCESS UINT8_C(0x07)
- #define BMM150_SET_BITS(reg_data, bitname, data) \
- ((reg_data & ~(bitname##_MSK)) | \
- ((data << bitname##_POS) & bitname##_MSK))
- #define BMM150_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
- (bitname##_POS))
- #define BMM150_SET_BITS_POS_0(reg_data, bitname, data) \
- ((reg_data & ~(bitname##_MSK)) | \
- (data & bitname##_MSK))
- #define BMM150_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
- enum bmm150_intf {
-
- BMM150_SPI_INTF,
-
- BMM150_I2C_INTF
- };
- typedef int8_t (*bmm150_com_fptr_t)(uint8_t dev_id, uint8_t reg_addr, uint8_t *read_data, uint16_t len);
- typedef void (*bmm150_delay_fptr_t)(uint32_t);
- struct bmm150_trim_registers {
-
- int8_t dig_x1;
-
- int8_t dig_y1;
-
- int8_t dig_x2;
-
- int8_t dig_y2;
-
- uint16_t dig_z1;
-
- int16_t dig_z2;
-
- int16_t dig_z3;
-
- int16_t dig_z4;
-
- uint8_t dig_xy1;
-
- int8_t dig_xy2;
-
- uint16_t dig_xyz1;
- };
- struct bmm150_int_ctrl_settings {
-
- uint8_t drdy_pin_en;
-
- uint8_t int_pin_en;
-
- uint8_t drdy_polarity;
-
- uint8_t int_latch;
-
- uint8_t int_polarity;
-
- uint8_t data_overrun_en;
-
- uint8_t overflow_int_en;
-
- uint8_t high_int_en;
-
- uint8_t low_int_en;
-
- uint8_t low_threshold;
-
- uint8_t high_threshold;
- };
- struct bmm150_settings {
-
- uint8_t xyz_axes_control;
-
- uint8_t pwr_cntrl_bit;
-
- uint8_t pwr_mode;
-
- uint8_t data_rate;
-
- uint8_t xy_rep;
-
- uint8_t z_rep;
-
- uint8_t preset_mode;
-
- struct bmm150_int_ctrl_settings int_settings;
- };
- struct bmm150_raw_mag_data {
-
- int16_t raw_datax;
-
- int16_t raw_datay;
-
- int16_t raw_dataz;
-
- uint16_t raw_data_r;
- };
- #ifdef BMM150_USE_FLOATING_POINT
- struct bmm150_mag_data {
-
- float x;
-
- float y;
-
- float z;
- };
- #else
- struct bmm150_mag_data {
-
- int16_t x;
-
- int16_t y;
-
- int16_t z;
- };
- #endif
- struct bmm150_dev {
-
- uint8_t chip_id;
-
- uint8_t dev_id;
-
- enum bmm150_intf intf;
-
- bmm150_com_fptr_t read;
-
- bmm150_com_fptr_t write;
-
- bmm150_delay_fptr_t delay_ms;
-
- struct bmm150_trim_registers trim_data;
-
- struct bmm150_settings settings;
-
- uint16_t int_status;
-
- struct bmm150_mag_data data;
- };
- #endif /* BMM150_DEFS_H_ */
|