42#ifdef PREINIT_SUPPORTED
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55#include "drv_spi_master.h"
68#define COMPASS4_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
72 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
73 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
74 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
75 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
76 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
83#define COMPASS4_MASTER_I2C 0
84#define COMPASS4_MASTER_SPI 1
91#define COMPASS4_RETVAL uint8_t
93#define COMPASS4_OK 0x00
94#define COMPASS4_INIT_ERROR 0xFF
101#define COMPASS4_REG_COMPANY_ID 0x00
102#define COMPASS4_REG_DEVICE_ID 0x01
103#define COMPASS4_REG_INFO 0x03
104#define COMPASS4_REG_STATUS_1 0x10
105#define COMPASS4_REG_X_AXIS_LSB 0x11
106#define COMPASS4_REG_X_AXIS_MSB 0x12
107#define COMPASS4_REG_Y_AXIS_LSB 0x13
108#define COMPASS4_REG_Y_AXIS_MSB 0x14
109#define COMPASS4_REG_Z_AXIS_LSB 0x15
110#define COMPASS4_REG_Z_AXIS_MSB 0x16
111#define COMPASS4_REG_TMPS 0x17
112#define COMPASS4_REG_STATUS_2 0x18
113#define COMPASS4_REG_CONTROL_1 0x30
114#define COMPASS4_REG_CONTROL_2 0x31
115#define COMPASS4_REG_CONTROL_3 0x32
116#define COMPASS4_REG_TS_1 0x33
117#define COMPASS4_REG_TS_2 0x34
118#define COMPASS4_REG_TS_3 0x35
119#define COMPASS4_REG_I2C_DISABLE 0x36
120#define COMPASS4_REG_TS_4 0x37
121#define COMPASS4_REG_ASAX 0x60
122#define COMPASS4_REG_ASAY 0x61
123#define COMPASS4_REG_ASAZ 0x62
124#define COMPASS4_REG_TPH_1 0xC0
125#define COMPASS4_REG_TPH_2 0xC1
126#define COMPASS4_REG_RR 0xC2
127#define COMPASS4_REG_SYT 0xC3
128#define COMPASS4_REG_DT 0xC4
135#define COMPASS4_DEF_COMPANY_ID 0x48
136#define COMPASS4_DEF_DEVICE_ID 0x10
143#define COMPASS4_CTRL1_WM_STEP_1 0x00
144#define COMPASS4_CTRL1_WM_STEPS_2 0x01
145#define COMPASS4_CTRL1_WM_STEPS_3 0x02
146#define COMPASS4_CTRL1_WM_STEPS_4 0x03
147#define COMPASS4_CTRL1_WM_STEPS_5 0x04
148#define COMPASS4_CTRL1_WM_STEPS_6 0x05
149#define COMPASS4_CTRL1_WM_STEPS_7 0x06
150#define COMPASS4_CTRL1_WM_STEPS_8 0x07
151#define COMPASS4_CTRL1_WM_STEPS_9 0x08
152#define COMPASS4_CTRL1_WM_STEPS_10 0x09
153#define COMPASS4_CTRL1_WM_STEPS_11 0x0A
154#define COMPASS4_CTRL1_WM_STEPS_12 0x0B
155#define COMPASS4_CTRL1_WM_STEPS_13 0x0C
156#define COMPASS4_CTRL1_WM_STEPS_14 0x0D
157#define COMPASS4_CTRL1_WM_STEPS_15 0x0E
158#define COMPASS4_CTRL1_WM_STEPS_16 0x0F
159#define COMPASS4_CTRL1_WM_STEPS_17 0x10
160#define COMPASS4_CTRL1_WM_STEPS_18 0x11
161#define COMPASS4_CTRL1_WM_STEPS_19 0x12
162#define COMPASS4_CTRL1_WM_STEPS_20 0x13
163#define COMPASS4_CTRL1_WM_STEPS_21 0x14
164#define COMPASS4_CTRL1_WM_STEPS_22 0x15
165#define COMPASS4_CTRL1_WM_STEPS_23 0x16
166#define COMPASS4_CTRL1_WM_STEPS_24 0x17
167#define COMPASS4_CTRL1_WM_STEPS_25 0x18
168#define COMPASS4_CTRL1_WM_STEPS_26 0x19
169#define COMPASS4_CTRL1_WM_STEPS_27 0x1A
170#define COMPASS4_CTRL1_WM_STEPS_28 0x1B
171#define COMPASS4_CTRL1_WM_STEPS_29 0x1C
172#define COMPASS4_CTRL1_WM_STEPS_30 0x1D
173#define COMPASS4_CTRL1_WM_STEPS_31 0x1E
174#define COMPASS4_CTRL1_WM_STEPS_32 0x1F
175#define COMPASS4_CTRL1_NOISE_DISABLE 0x00
176#define COMPASS4_CTRL1_NOISE_ENABLE 0x20
183#define COMPASS4_CTRL2_MODE_POWER_DOWN 0x00
184#define COMPASS4_CTRL2_MODE_SINGLE 0x01
185#define COMPASS4_CTRL2_MODE_CONT_1 0x02
186#define COMPASS4_CTRL2_MODE_CONT_2 0x04
187#define COMPASS4_CTRL2_MODE_CONT_3 0x06
188#define COMPASS4_CTRL2_MODE_CONT_4 0x08
189#define COMPASS4_CTRL2_MODE_CONT_5 0x0A
190#define COMPASS4_CTRL2_MODE_CONT_6 0x0C
191#define COMPASS4_CTRL2_MODE_SELF_TEST 0x10
192#define COMPASS4_CTRL2_SDR_LOW_POWER 0x00
193#define COMPASS4_CTRL2_SDR_LOW_NOISE 0x40
194#define COMPASS4_CTRL2_FIFO_ENABLE 0x80
195#define COMPASS4_CTRL2_FIFO_DISABLE 0x00
202#define COMPASS4_CTRL3_SOFT_RESET 0x01
209#define COMPASS4_SLAVE_ADDRESS_GND_GND 0x0C
210#define COMPASS4_SLAVE_ADDRESS_GND_VCC 0x0D
211#define COMPASS4_SLAVE_ADDRESS_VCC_GND 0x0E
212#define COMPASS4_SLAVE_ADDRESS_VCC_VCC 0x0F
219#define COMPASS4_GET_STATUS_1 0x01
220#define COMPASS4_GET_STATUS_2 0x02
227#define COMPASS4_X_AXIS_DATA 0x11
228#define COMPASS4_Y_AXIS_DATA 0x13
229#define COMPASS4_Z_AXIS_DATA 0x15
236#define FLUX_CONSTANT 0.15
#define COMPASS4_RETVAL
Definition compass4.h:91
void compass4_generic_read(compass4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void compass4_software_reset(compass4_t *ctx)
Software reset function.
void compass4_hardware_reset(compass4_t *ctx)
Hardware reset function.
uint8_t compass4_get_interrupt(compass4_t *ctx)
Gets INT pin state (DRDY pin)
void compass4_cfg_setup(compass4_cfg_t *cfg)
Config Object Initialization function.
void compass4_set_rst_pin_state(compass4_t *ctx, uint8_t state)
Sets RST pin state.
uint8_t compass4_check_device(compass4_t *ctx)
Check device function.
uint8_t compass4_get_status(compass4_t *ctx, uint8_t status)
Get status.
uint8_t compass4_get_magnetic_flux(compass4_t *ctx, compass4_flux_t *flux)
Gets magnetic flux of X\Y\Z axis value.
void compass4_generic_write(compass4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t compass4_get_single_magnetic_flux(compass4_t *ctx, uint8_t axis, float *flux_data)
Gets single axis flux value.
uint8_t compass4_get_axis(compass4_t *ctx, compass4_axis_t *axis)
Gets X\Y\Z Axis value.
COMPASS4_RETVAL compass4_init(compass4_t *ctx, compass4_cfg_t *cfg)
Initialization function.
void compass4_configuration(compass4_t *ctx, uint8_t cfg1, uint8_t cfg2)
Configuration function.
uint8_t compass4_get_single_axis(compass4_t *ctx, uint8_t axis_reg, int16_t *axis_data)
Gets single axis value.
uint8_t compass4_select_t
Communication type.
Definition compass4.h:266
struct compass4_s compass4_t
Click ctx object definition.
void(* compass4_master_io_t)(struct compass4_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition compass4.h:271
Definition compass4.h:248
int16_t z
Definition compass4.h:251
int16_t x
Definition compass4.h:249
int16_t y
Definition compass4.h:250
Click configuration structure definition.
Definition compass4.h:306
compass4_select_t sel
Definition compass4.h:330
uint32_t i2c_speed
Definition compass4.h:323
spi_master_chip_select_polarity_t cs_polarity
Definition compass4.h:328
pin_name_t sck
Definition compass4.h:313
spi_master_mode_t spi_mode
Definition compass4.h:327
pin_name_t mosi
Definition compass4.h:312
uint32_t spi_speed
Definition compass4.h:326
pin_name_t scl
Definition compass4.h:309
pin_name_t int_pin
Definition compass4.h:319
pin_name_t miso
Definition compass4.h:311
pin_name_t sda
Definition compass4.h:310
pin_name_t rst
Definition compass4.h:318
pin_name_t cs
Definition compass4.h:314
uint8_t i2c_address
Definition compass4.h:324
Definition compass4.h:256
float y
Definition compass4.h:258
float x
Definition compass4.h:257
float z
Definition compass4.h:259
Click ctx object definition.
Definition compass4.h:277
digital_out_t cs
Definition compass4.h:279
compass4_select_t master_sel
Definition compass4.h:298
spi_master_t spi
Definition compass4.h:290
compass4_master_io_t write_f
Definition compass4.h:296
compass4_master_io_t read_f
Definition compass4.h:297
digital_in_t int_pin
Definition compass4.h:285
i2c_master_t i2c
Definition compass4.h:289
digital_out_t rst
Definition compass4.h:281
uint8_t slave_address
Definition compass4.h:294
pin_name_t chip_select
Definition compass4.h:295