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 COMPASS2_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 COMPASS2_MASTER_I2C 0
84#define COMPASS2_MASTER_SPI 1
91#define COMPASS2_RETVAL uint8_t
93#define COMPASS2_OK 0x00
94#define COMPASS2_INIT_ERROR 0xFF
101#define COMPASS2_REG_DEVICE_ID 0x00
102#define COMPASS2_REG_INFORMATION 0x01
103#define COMPASS2_REG_STATUS_1 0x02
104#define COMPASS2_REG_AXIS_X_LOW 0x03
105#define COMPASS2_REG_AXIS_X_HIGH 0x04
106#define COMPASS2_REG_AXIS_Y_LOW 0x05
107#define COMPASS2_REG_AXIS_Y_HIGH 0x06
108#define COMPASS2_REG_AXIS_Z_LOW 0x07
109#define COMPASS2_REG_AXIS_Z_HIGH 0x08
110#define COMPASS2_REG_STATUS_2 0x09
111#define COMPASS2_REG_CNTRL1 0x0A
112#define COMPASS2_REG_CNTRL2 0x0B
113#define COMPASS2_REG_SELF_TEST 0x0C
114#define COMPASS2_REG_TEST_1 0x0D
115#define COMPASS2_REG_TEST_2 0x0E
116#define COMPASS2_REG_I2C_DISABLE 0x0F
117#define COMPASS2_REG_X_AXIS_SENS 0x10
118#define COMPASS2_REG_Y_AXIS_SENS 0x11
119#define COMPASS2_REG_Z_AXIS_SENS 0x12
121#define COMPASS2_MODE_POWER_DOWN 0x00
122#define COMPASS2_MODE_SINGL_MEASUR 0x01
123#define COMPASS2_MODE_CONT_MEAS_1 0x02
124#define COMPASS2_MODE_CONT_MEAS_2 0x06
125#define COMPASS2_MODE_EXT_TRIG 0x04
126#define COMPASS2_MODE_SELF_TEST 0x08
127#define COMPASS2_MODE_FUSE_ROM 0x0F
129#define COMPASS2_SET_RESOLUTION_14bit 0x00
130#define COMPASS2_SET_RESOLUTION_16bit 0x10
132#define COMPASS2_MODE_SPI 0x00
133#define COMPASS2_MODE_I2C 0x01
135#define COMPASS2_X_AXIS 0x00
136#define COMPASS2_Y_AXIS 0x01
137#define COMPASS2_Z_AXIS 0x02
#define COMPASS2_RETVAL
Definition compass2.h:91
void compass2_set_mode(compass2_t *ctx, uint8_t mode)
Set output resolution function.
uint8_t compass2_read_byte(compass2_t *ctx, uint8_t reg)
Read byte function.
void compass2_new_measurement(compass2_t *ctx)
New measurement function.
void compass2_reset(compass2_t *ctx)
Hardware reset function.
float compass2_get_resolution_parameter(uint8_t res)
Get resolution function.
int16_t compass2_get_axis_data(compass2_t *ctx, uint8_t axis)
Get one axis data function.
void compass2_generic_write(compass2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t compass2_get_data_overrun(compass2_t *ctx)
Get data overrun function.
void compass2_write_byte(compass2_t *ctx, uint8_t reg, uint8_t data_buf)
Write byte function.
void compass2_software_reset(compass2_t *ctx)
Software reset function.
void compass2_get_adjustment(compass2_t *ctx, uint8_t *x, uint8_t *y, uint8_t *z)
Get axis adjustment function.
uint8_t compass2_get_rdy(compass2_t *ctx)
Get ready function.
void compass2_default_cfg(compass2_t *ctx)
Click Default Configuration function.
void compass2_i2c_disable(compass2_t *ctx)
Switch from I2C to SPI mode function.
void compass2_get_all_data(compass2_t *ctx, int16_t *x, int16_t *y, int16_t *z)
Get all data function.
void compass2_generic_read(compass2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void compass2_set_out_resolution(compass2_t *ctx, uint8_t res)
Set output resolution function.
void compass2_cfg_setup(compass2_cfg_t *cfg)
Config Object Initialization function.
COMPASS2_RETVAL compass2_init(compass2_t *ctx, compass2_cfg_t *cfg)
Initialization function.
void(* compass2_master_io_t)(struct compass2_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition compass2.h:155
struct compass2_s compass2_t
Click ctx object definition.
uint8_t compass2_select_t
Communication type.
Definition compass2.h:150
Click configuration structure definition.
Definition compass2.h:192
uint32_t i2c_speed
Definition compass2.h:209
spi_master_chip_select_polarity_t cs_polarity
Definition compass2.h:214
pin_name_t sck
Definition compass2.h:199
spi_master_mode_t spi_mode
Definition compass2.h:213
pin_name_t mosi
Definition compass2.h:198
uint32_t spi_speed
Definition compass2.h:212
compass2_select_t sel
Definition compass2.h:216
pin_name_t scl
Definition compass2.h:195
pin_name_t int_pin
Definition compass2.h:205
pin_name_t miso
Definition compass2.h:197
pin_name_t sda
Definition compass2.h:196
pin_name_t rst
Definition compass2.h:204
pin_name_t cs
Definition compass2.h:200
uint8_t i2c_address
Definition compass2.h:210
Click ctx object definition.
Definition compass2.h:161
digital_out_t cs
Definition compass2.h:165
spi_master_t spi
Definition compass2.h:174
compass2_master_io_t read_f
Definition compass2.h:181
compass2_master_io_t write_f
Definition compass2.h:180
digital_in_t int_pin
Definition compass2.h:169
i2c_master_t i2c
Definition compass2.h:173
compass2_select_t master_sel
Definition compass2.h:182
uint16_t output_resolution
Definition compass2.h:184
digital_out_t rst
Definition compass2.h:164
uint8_t slave_address
Definition compass2.h:178
pin_name_t chip_select
Definition compass2.h:179