c3dhall5 2.0.0.0
c3dhall5.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef C3DHALL5_H
36#define C3DHALL5_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55#include "drv_spi_master.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define C3DHALL5_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.css = MIKROBUS( mikrobus, MIKROBUS_RST ); \
76 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
83#define C3DHALL5_MASTER_I2C 0
84#define C3DHALL5_MASTER_SPI 1
91#define C3DHALL5_RETVAL uint8_t
92
93#define C3DHALL5_OK 0x00
94#define C3DHALL5_INIT_ERROR 0xFF
101#define C3DHALL5_I_AM 0x40;
108#define C3DHALL5_AXIS_X 0x68
109#define C3DHALL5_AXIS_Y 0x6A
110#define C3DHALL5_AXIS_Z 0x6C
117#define C3DHALL5_OFFSET_AXIS_X 0x45
118#define C3DHALL5_OFFSET_AXIS_Y 0x47
119#define C3DHALL5_OFFSET_AXIS_Z 0x49
126#define C3DHALL5_REG_OFFSET_X_LSB 0x45
127#define C3DHALL5_REG_OFFSET_X_MSB 0x46
128#define C3DHALL5_REG_OFFSET_Y_LSB 0x47
129#define C3DHALL5_REG_OFFSET_Y_MSB 0x48
130#define C3DHALL5_REG_OFFSET_Z_LSB 0x49
131#define C3DHALL5_REG_OFFSET_Z_MSB 0x4A
132#define C3DHALL5_REG_WHO_AM_I 0x4F
133#define C3DHALL5_REG_CONFIG_A 0x60
134#define C3DHALL5_REG_CONFIG_B 0x61
135#define C3DHALL5_REG_CONFIG_C 0x62
136#define C3DHALL5_REG_INT_CTRL 0x63
137#define C3DHALL5_REG_INT_SOURCE 0x64
138#define C3DHALL5_REG_INT_THS_LSB 0x65
139#define C3DHALL5_REG_INT_THS_MSB 0x66
140#define C3DHALL5_REG_STATUS 0x67
141#define C3DHALL5_REG_X_AXIS_LSB 0x68
142#define C3DHALL5_REG_X_AXIS_MSB 0x69
143#define C3DHALL5_REG_Y_AXIS_LSB 0x6A
144#define C3DHALL5_REG_Y_AXIS_MSB 0x6B
145#define C3DHALL5_REG_Z_AXIS_LSB 0x6C
146#define C3DHALL5_REG_Z_AXIS_MSB 0x6D
147#define C3DHALL5_REG_TEMP_LSB 0x6E
148#define C3DHALL5_REG_TEMP_MSB 0x6F
155#define C3DHALL5_CFG_A_COMP_TEMP_ENABLE 0x80
156#define C3DHALL5_CFG_A_COMP_TEMP_DISABLE 0x00
157#define C3DHALL5_CFG_A_REBOOT_MEM_CONTENT 0x40
158#define C3DHALL5_CFG_A_NORMAL_MODE 0x00
159#define C3DHALL5_CFG_A_SOFTRESET 0x20
160#define C3DHALL5_CFG_A_HIGH_RESOLUTION_MODE 0x00
161#define C3DHALL5_CFG_A_LOW_POWER_MODE 0x10
162#define C3DHALL5_CFG_A_ODR_10Hz 0x00
163#define C3DHALL5_CFG_A_ODR_20Hz 0x04
164#define C3DHALL5_CFG_A_ODR_50Hz 0x08
165#define C3DHALL5_CFG_A_ODR_100Hz 0x0C
166#define C3DHALL5_CFG_A_MODE_CONTINUOUS 0x00
167#define C3DHALL5_CFG_A_MODE_SINGLE 0x01
168#define C3DHALL5_CFG_A_MODE_IDLE 0x02
175#define C3DHALL5_CFG_B_OFFSET_IN_SINGLE_MODE_ENABLE 0x10
176#define C3DHALL5_CFG_B_OFFSET_IN_SINGLE_MODE_DISABLE 0x00
177#define C3DHALL5_CFG_B_INT_ON_DATA_OFF 0x08
178#define C3DHALL5_CFG_B_SET_PULSE_63_ODR 0x00
179#define C3DHALL5_CFG_B_SET_PULSE_PD_CONDITION 0x04
180#define C3DHALL5_CFG_B_OFFSET_ENABLE 0x02
181#define C3DHALL5_CFG_B_OFFSET_DISABLE 0x00
182#define C3DHALL5_CFG_B_LPF_DISABLE_ODR_2 0x00
183#define C3DHALL5_CFG_B_LPF_ENABLE_ODR_4 0x01
190#define C3DHALL5_CFG_C_INT_ON_PIN 0x40
191#define C3DHALL5_CFG_C_INT_ON_PIN_DISABLE 0x00
192#define C3DHALL5_CFG_C_I2C_DISABLE 0x20
193#define C3DHALL5_CFG_C_BLE_ENABLE 0x08
194#define C3DHALL5_CFG_C_SELF_TEST 0x02
195#define C3DHALL5_CFG_C_DRDY_ON_PIN 0x01
202#define C3DHALL5_INT_CTRL_X_AXIS_ENABLE 0x80
203#define C3DHALL5_INT_CTRL_Y_AXIS_ENABLE 0x40
204#define C3DHALL5_INT_CTRL_Z_AXIS_ENABLE 0x20
205#define C3DHALL5_INT_CTRL_IEA_0_SIGNALS_AN_INT 0x00
206#define C3DHALL5_INT_CTRL_IEA_1_SIGNALS_AN_INT 0x04
207#define C3DHALL5_INT_CTRL_IEL_INT_IS_PILSED 0x00
208#define C3DHALL5_INT_CTRL_IEL_INT_IS_LATCHED 0x02
209#define C3DHALL5_INT_CTRL_IEN_INT_ENABLE 0x01
210#define C3DHALL5_INT_CTRL_IEN_INT_DISABLE 0x00
217#define C3DHALL5_INT_SOURCE_POS_TH_X 0x80
218#define C3DHALL5_INT_SOURCE_POS_TH_Y 0x40
219#define C3DHALL5_INT_SOURCE_POS_TH_Z 0x20
220#define C3DHALL5_INT_SOURCE_NEG_TH_X 0x10
221#define C3DHALL5_INT_SOURCE_NEG_TH_Y 0x08
222#define C3DHALL5_INT_SOURCE_NEG_TH_N 0x04
229#define C3DHALL5_STATUS_XYZ_DATA_OVERRUN 0x80
230#define C3DHALL5_STATUS_Z_DATA_OVERRUN 0x40
231#define C3DHALL5_STATUS_Y_DATA_OVERRUN 0x20
232#define C3DHALL5_STATUS_X_DATA_OVERRUN 0x10
233#define C3DHALL5_STATUS_XYZ_NEW_DATA 0x08
234#define C3DHALL5_STATUS_Z_NEW_DATA 0x04
235#define C3DHALL5_STATUS_Y_NEW_DATA 0x02
236#define C3DHALL5_STATUS_X_NEW_DATA 0x01
239 // End group macro
240// --------------------------------------------------------------- PUBLIC TYPES
249typedef uint8_t c3dhall5_select_t;
250
254typedef void ( *c3dhall5_master_io_t )( struct c3dhall5_s*, uint8_t, uint8_t*, uint8_t );
255
259typedef struct c3dhall5_s
260{
261 // Output pins
262 digital_out_t css;
263
264 // Input pins
265
266 digital_in_t int_pin;
267
268 // Modules
269
270 i2c_master_t i2c;
271 spi_master_t spi;
272
273 // ctx variable
274
276 pin_name_t chip_select;
280
282
286typedef struct
287{
288 // Communication gpio pins
289
290 pin_name_t scl;
291 pin_name_t sda;
292 pin_name_t miso;
293 pin_name_t mosi;
294 pin_name_t sck;
295 pin_name_t cs;
296
297 // Additional gpio pins
298
299 pin_name_t css;
300 pin_name_t int_pin;
301
302 // static variable
303
304 uint32_t i2c_speed;
305 uint8_t i2c_address;
306
307 uint32_t spi_speed;
308 spi_master_mode_t spi_mode;
309 spi_master_chip_select_polarity_t cs_polarity;
310
312
314
315 // End types group
316// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
322#ifdef __cplusplus
323extern "C"{
324#endif
325
335
344
360
371void c3dhall5_generic_write ( c3dhall5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
372
383void c3dhall5_generic_read ( c3dhall5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
384
394
404
412
420void c3dhall5_set_offset ( c3dhall5_t *ctx, uint8_t offset_axis, int16_t offset );
421
429int16_t c3dhall5_get_axis_data ( c3dhall5_t *ctx, uint8_t axis );
430
431#ifdef __cplusplus
432}
433#endif
434#endif // _C3DHALL5_H_
435
436 // End public_function group
438
439// ------------------------------------------------------------------------- END
#define C3DHALL5_RETVAL
Definition c3dhall5.h:91
void c3dhall5_cfg_setup(c3dhall5_cfg_t *cfg)
Config Object Initialization function.
uint8_t c3dhall5_get_interrupt_state(c3dhall5_t *ctx)
Interrupt state.
float c3dhall5_get_temperature_data(c3dhall5_t *ctx)
Temperature data.
uint8_t c3dhall5_get_device_id(c3dhall5_t *ctx)
Device ID.
void c3dhall5_set_offset(c3dhall5_t *ctx, uint8_t offset_axis, int16_t offset)
Set offest.
void c3dhall5_generic_write(c3dhall5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
C3DHALL5_RETVAL c3dhall5_init(c3dhall5_t *ctx, c3dhall5_cfg_t *cfg)
Initialization function.
int16_t c3dhall5_get_axis_data(c3dhall5_t *ctx, uint8_t axis)
Axis data.
void c3dhall5_default_cfg(c3dhall5_t *ctx)
Click Default Configuration function.
void c3dhall5_generic_read(c3dhall5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t c3dhall5_select_t
Communication type.
Definition c3dhall5.h:249
struct c3dhall5_s c3dhall5_t
Click ctx object definition.
void(* c3dhall5_master_io_t)(struct c3dhall5_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition c3dhall5.h:254
Click configuration structure definition.
Definition c3dhall5.h:287
uint32_t i2c_speed
Definition c3dhall5.h:304
c3dhall5_select_t sel
Definition c3dhall5.h:311
spi_master_chip_select_polarity_t cs_polarity
Definition c3dhall5.h:309
pin_name_t sck
Definition c3dhall5.h:294
spi_master_mode_t spi_mode
Definition c3dhall5.h:308
pin_name_t mosi
Definition c3dhall5.h:293
uint32_t spi_speed
Definition c3dhall5.h:307
pin_name_t scl
Definition c3dhall5.h:290
pin_name_t int_pin
Definition c3dhall5.h:300
pin_name_t css
Definition c3dhall5.h:299
pin_name_t miso
Definition c3dhall5.h:292
pin_name_t sda
Definition c3dhall5.h:291
pin_name_t cs
Definition c3dhall5.h:295
uint8_t i2c_address
Definition c3dhall5.h:305
Click ctx object definition.
Definition c3dhall5.h:260
c3dhall5_master_io_t read_f
Definition c3dhall5.h:278
spi_master_t spi
Definition c3dhall5.h:271
c3dhall5_master_io_t write_f
Definition c3dhall5.h:277
digital_in_t int_pin
Definition c3dhall5.h:266
i2c_master_t i2c
Definition c3dhall5.h:270
digital_out_t css
Definition c3dhall5.h:262
uint8_t slave_address
Definition c3dhall5.h:275
c3dhall5_select_t master_sel
Definition c3dhall5.h:279
pin_name_t chip_select
Definition c3dhall5.h:276