accel11  2.0.0.0
accel11.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 ACCEL11_H
36 #define ACCEL11_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 #include "drv_spi_master.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define ACCEL11_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
56  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
57  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
58  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
59  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
60  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
61  cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
62  cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_INT );
63 
69 #define ACCEL11_MASTER_I2C 0
70 #define ACCEL11_MASTER_SPI 1
71 
77 #define ACCEL11_RETVAL uint8_t
78 
79 #define ACCEL11_OK 0x00
80 #define ACCEL11_INIT_ERROR 0xFF
81 
87 #define ACCEL11_CHIP_ID 0x16
88 
94 #define ACCEL11_REG_CHIP_ID 0x00
95 #define ACCEL11_REG_ERROR 0x02
96 #define ACCEL11_REG_STATUS 0x03
97 #define ACCEL11_REG_AUX_X_LSB 0x0A
98 #define ACCEL11_REG_AUX_X_MSB 0x0B
99 #define ACCEL11_REG_AUX_Y_LSB 0x0C
100 #define ACCEL11_REG_AUX_Y_MSB 0x0D
101 #define ACCEL11_REG_AUX_Z_LSB 0x0E
102 #define ACCEL11_REG_AUX_Z_MSB 0x0F
103 #define ACCEL11_REG_AUX_R_LSB 0x10
104 #define ACCEL11_REG_AUX_R_MSB 0x11
105 #define ACCEL11_REG_ACCEL_X_LSB 0x12
106 #define ACCEL11_REG_ACCEL_X_MSB 0x13
107 #define ACCEL11_REG_ACCEL_Y_LSB 0x14
108 #define ACCEL11_REG_ACCEL_Y_MSB 0x15
109 #define ACCEL11_REG_ACCEL_Z_LSB 0x16
110 #define ACCEL11_REG_ACCEL_Z_MSB 0x17
111 #define ACCEL11_REG_SENSOR_TIME_0 0x18
112 #define ACCEL11_REG_SENSOR_TIME_1 0x19
113 #define ACCEL11_REG_SENSOR_TIME_2 0x1A
114 #define ACCEL11_REG_EVENT 0x1B
115 #define ACCEL11_REG_STATUS_INT_0 0x1C
116 #define ACCEL11_REG_STATUS_INT_1 0x1D
117 #define ACCEL11_REG_STEP_COUNTER_0 0x1E
118 #define ACCEL11_REG_STEP_COUNTER_1 0x1F
119 #define ACCEL11_REG_STEP_COUNTER_2 0x20
120 #define ACCEL11_REG_STEP_COUNTER_3 0x21
121 #define ACCEL11_REG_TEMPERATURE 0x22
122 #define ACCEL11_REG_FIFO_LENGTH_LSB 0x24
123 #define ACCEL11_REG_FIFO_LENGTH_MSB 0x25
124 #define ACCEL11_REG_FIFO_DATA 0x26
125 #define ACCEL11_REG_ACTIVITY_TYPE 0x27
126 #define ACCEL11_REG_INTERNAL_STATUS 0x2A
127 #define ACCEL11_REG_ACCEL_CONFIG 0x40
128 #define ACCEL11_REG_ACCEL_RANGE 0x41
129 #define ACCEL11_REG_AUX_CONFIG 0x44
130 #define ACCEL11_REG_FIFO_DOWNS 0x45
131 #define ACCEL11_REG_FIFO_WTM_LSB 0x46
132 #define ACCEL11_REG_FIFO_WTM_MSB 0x47
133 #define ACCEL11_REG_FIFO_CONFIG_0 0x48
134 #define ACCEL11_REG_FIFO_CONFIG_1 0x49
135 #define ACCEL11_AUX_DEV_ID 0x4B
136 #define ACCEL11_REG_AUX_IF_CONFIG 0x4C
137 #define ACCEL11_REG_AUX_RD_ADDRESS 0x4D
138 #define ACCEL11_REG_AUX_WR_ADDRESS 0x4E
139 #define ACCEL11_REG_AUX_WR_DATA 0x4F
140 #define ACCEL11_REG_INT1_IO_CTRL 0x53
141 #define ACCEL11_REG_INT2_IO_CTRL 0x54
142 #define ACCEL11_REG_INT_LATCH 0x55
143 #define ACCEL11_REG_INT1_MAP 0x56
144 #define ACCEL11_REG_INT2_MAP 0x57
145 #define ACCEL11_REG_INT_MAP_DATA 0x58
146 #define ACCEL11_REG_INT_CTRL 0x59
147 #define ACCEL11_REG_FEATURES_IN 0x5E
148 #define ACCEL11_REG_INTERNAL_ERROR 0x5F
149 #define ACCEL11_REG_NVM_CONF 0x6A
150 #define ACCEL11_REG_SPI_IF_CONF 0x6B
151 #define ACCEL11_REG_ACCEL_SELF_TEST 0x6D
152 #define ACCEL11_REG_NV_CONF 0x70
153 #define ACCEL11_REG_OFFSET_X_AXIS 0x71
154 #define ACCEL11_REG_OFFSET_Y_AXIS 0x72
155 #define ACCEL11_REG_OFFSET_Z_AXIS 0x73
156 #define ACCEL11_REG_POWER_CONFIG 0x7C
157 #define ACCEL11_REG_POWER_CTRL 0x7D
158 #define ACCEL11_REG_COMMAND 0x7E
159 
165 #define ACCEL11_ERR_AUX 0x80
166 #define ACCEL11_ERR_FIFO 0x80
167 #define ACCEL11_ERR_ACCEL 0x04
168 #define ACCEL11_ERR_CMD 0x02
169 #define ACCEL11_ERR_FATAL 0x01
170 
176 #define ACCEL11_STATUS_DRDY_ACCEL 0x80
177 #define ACCEL11_STATUS_DRDY_AUX 0x20
178 #define ACCEL11_STATUS_RDY_CMD 0x10
179 #define ACCEL11_STATUS_AUX_MAN_OP 0x04
180 
186 #define ACCEL11_EVENT_POWER_UP 0x00
187 #define ACCEL11_EVENT_SOFTWARE_RESET 0x01
188 
194 #define ACCEL11_INTS0_ERR_INT_OUT 0x80
195 #define ACCEL11_INTS0_NO_MOTION_OUT 0x40
196 #define ACCEL11_INTS0_WAKEUP_OUT 0x20
197 #define ACCEL11_INTS0_WRIST_TILT_OUT 0x08
198 #define ACCEL11_INTS0_ACTIVITY_TYPE_OUT 0x04
199 #define ACCEL11_INTS0_STEP_COUNTER_OUT 0x02
200 
206 #define ACCEL11_INTS1_ACCEL_DRDY_INT 0x80
207 #define ACCEL11_INTS1_AUX_DRDY_INT 0x20
208 #define ACCEL11_INTS1_FWM_INT 0x02
209 #define ACCEL11_INTS1_FFULL_INT 0x01
210 
216 #define ACCEL11_ATYPE_USER_NOT_MOVING 0x00
217 #define ACCEL11_ATYPE_USER_WALKING 0x01
218 #define ACCEL11_ATYPE_USER_RUNNING 0x02
219 
225 #define ACCEL11_INTERS_ODR_HIGH_ERR 0x80
226 #define ACCEL11_INTERS_ODR_50HZ_ERR 0x40
227 #define ACCEL11_INTERS_AXES_REMAP_ERR 0x20
228 #define ACCEL11_INTERS_NOT_INIT 0x00
229 #define ACCEL11_INTERS_INIT_OK 0x01
230 #define ACCEL11_INTERS_INIT_ERROR 0x02
231 #define ACCEL11_INTERS_INVALID_DRIVER 0x03
232 #define ACCEL11_INTERS_SENSOR_STOPPED 0x04
233 
239 #define ACCEL11_ACFG_AVERAGING_MODE 0x00
240 #define ACCEL11_ACFG_CONTINUOUS_MODE 0x80
241 #define ACCEL11_ACFG_BWP_NO_AVERAGING 0x00
242 #define ACCEL11_ACFG_BWP_AVERAGING_2_SAMPLES 0x10
243 #define ACCEL11_ACFG_BWP_AVERAGING_4_SAMPLES 0x20
244 #define ACCEL11_ACFG_BWP_AVERAGING_8_SAMPLES 0x30
245 #define ACCEL11_ACFG_BWP_AVERAGING_16_SAMPLES 0x40
246 #define ACCEL11_ACFG_BWP_AVERAGING_32_SAMPLES 0x50
247 #define ACCEL11_ACFG_BWP_AVERAGING_64_SAMPLES 0x60
248 #define ACCEL11_ACFG_BWP_AVERAGING_128_SAMPLES 0x70
249 
255 #define ACCEL11_RANGE_2g 0x00
256 #define ACCEL11_RANGE_4g 0x01
257 #define ACCEL11_RANGE_8g 0x02
258 #define ACCEL11_RANGE_16g 0x03
259 
265 #define ACCEL11_CFG_ODR_0p78Hz 0x01
266 #define ACCEL11_CFG_ODR_1p5Hz 0x02
267 #define ACCEL11_CFG_ODR_3p1Hz 0x03
268 #define ACCEL11_CFG_ODR_6p25Hz 0x04
269 #define ACCEL11_CFG_ODR_12p5Hz 0x05
270 #define ACCEL11_CFG_ODR_25Hz 0x06
271 #define ACCEL11_CFG_ODR_50Hz 0x07
272 #define ACCEL11_CFG_ODR_100Hz 0x08
273 #define ACCEL11_CFG_ODR_200Hz 0x09
274 #define ACCEL11_CFG_ODR_400Hz 0x0A
275 #define ACCEL11_CFG_ODR_800Hz 0x0B
276 #define ACCEL11_CFG_ODR_1k6Hz 0x0C
277 #define ACCEL11_CFG_ODR_3k2Hz 0x0D
278 #define ACCEL11_CFG_ODR_6k4Hz 0x0E
279 #define ACCEL11_CFG_ODR_12k8Hz 0x0F
280 
286 #define ACCEL11_FCFG0_FIFO_TIME_ENABLE 0x02
287 #define ACCEL11_FCFG0_FIFO_TIME_DISABLE 0x00
288 #define ACCEL11_FCFG0_FIFO_STOP_ON_FULL_ENABLE 0x01
289 #define ACCEL11_FCFG0_FIFO_STOP_ON_FULL_DISABLE 0x00
290 
296 #define ACCEL11_FCGF1_FIFO_ACCEL_ENABLE 0x40
297 #define ACCEL11_FCGF1_FIFO_ACCEL_DISABLE 0x00
298 #define ACCEL11_FCGF1_FIFO_AUX_ENABLE 0x20
299 #define ACCEL11_FCGF1_FIFO_AUX_DISABLE 0x00
300 #define ACCEL11_FCGF1_FIFO_HEADER_ENABLE 0x10
301 #define ACCEL11_FCGF1_FIFO_HEADER_DISABLE 0x00
302 #define ACCEL11_FCGF1_FIFO_TAG_INT1_ENABLE 0x08
303 #define ACCEL11_FCGF1_FIFO_TAG_INT1_DISABLE 0x00
304 #define ACCEL11_FCGF1_FIFO_TAG_INT2_ENABLE 0x04
305 #define ACCEL11_FCGF1_FIFO_TAG_INT2_DISABLE 0x00
306 
312 #define ACCEL11_IFCFG_DATA_MODE 0x00
313 #define ACCEL11_IFCFG_SETUP_MODE 0x80
314 #define ACCEL11_IFCFG_BURST_LENGTH_1 0x00
315 #define ACCEL11_IFCFG_BURST_LENGTH_2 0x01
316 #define ACCEL11_IFCFG_BURST_LENGTH_6 0x02
317 #define ACCEL11_IFCFG_BURST_LENGTH_8 0x03
318 
324 #define ACCEL11_INTIO_INPUT_ENABLE 0x10
325 #define ACCEL11_INTIO_INPUT_DISABLE 0x00
326 #define ACCEL11_INTIO_OUTPUT_ENABLE 0x08
327 #define ACCEL11_INTIO_OUTPUT_DISABLE 0x00
328 #define ACCEL11_INTIO_PUSH_PULL 0x00
329 #define ACCEL11_INTIO_OPEN_DRAIN 0x04
330 #define ACCEL11_INTIO_LVL_ACTIVE_LOW 0x00
331 #define ACCEL11_INTIO_LVL_ACTIVE_HIGH 0x02
332 #define ACCEL11_INTIO_TRIGGER_LEVEL 0x00
333 #define ACCEL11_INTIO_TRIGGER_EDGE 0x01
334 
340 #define ACCEL11_INTLAT_NON_LATCHED 0x00
341 #define ACCEL11_INTLAT_LATCHED 0x01
342 
348 #define ACCEL11_IMAPD_INT1_FFULL 0x01
349 #define ACCEL11_IMAPD_INT1_FWM 0x03
350 #define ACCEL11_IMAPD_INT1_DRDY 0x04
351 #define ACCEL11_IMAPD_INT2_FFULL 0x10
352 #define ACCEL11_IMAPD_INT2_FWM 0x20
353 #define ACCEL11_IMAPD_INT2_DRDY 0x40
354 
360 #define ACCEL11_SPI_4_WIRE 0x00
361 #define ACCEL11_SPI_3_WIRE 0x01
362 #define ACCEL11_AUX_INTERFACE_OFF 0x00
363 #define ACCEL11_AUX_INTERFACE_MAG 0x10
364 
370 #define ACCEL_NV_ACCEL_OFFSET_ENABLE 0x08
371 #define ACCEL_NV_ACCEL_OFFSET_DISABLE 0x00
372 #define ACCEL_NV_I2C_WATCHDOG_ENABLE 0x04
373 #define ACCEL_NV_I2C_WATCHDOG_DISABLE 0x00
374 #define ACCEL_NV_I2C_WDT_TIMEOUT_SHORT 0x00
375 #define ACCEL_NV_I2C_WDT_TIMEOUT_LONG 0x02
376 #define ACCEL_NV_I2C_INTERFACE_ENABLE 0x00
377 #define ACCEL_NV_I2C_INTERFACE_DISABLE 0x01
378 
384 #define ACCEL11_PWRCFG_APS_ON 0x01
385 #define ACCEL11_PWRCFG_APS_OFF 0x00
386 #define ACCEL11_PWRCFG_FSW_ON 0x02
387 #define ACCEL11_PWRCFG_FSW_OFF 0x00
388 
394 #define ACCEL11_PWRCTRL_ACCEL_ENABLE 0x04
395 #define ACCEL11_PWRCTRL_ACCEL_DISABLE 0x00
396 
402 #define ACCEL11_CMD_NVM_PROG 0xA0
403 #define ACCEL11_CMD_FIFO_FLUSH 0xB0
404 #define ACCEL11_CMD_SW_RESET 0xB6
405 
411 #define ACCEL11_ACCEL_X_AXIS 0x12
412 #define ACCEL11_ACCEL_Y_AXIS 0x14
413 #define ACCEL11_ACCEL_Z_AXIS 0x16
414 
420 #define ACCEL11_SLAVE_ADDRESS_GND 0x18
421 #define ACCEL11_SLAVE_ADDRESS_VCC 0x19
422 
428 #define ACCEL11_TEST_COMUNICATION_ERROR 0x01
429 #define ACCEL11_TEST_COMUNICATION_OK 0x00
430  // End group macro
433 // --------------------------------------------------------------- PUBLIC TYPES
442 typedef uint8_t accel11_select_t;
443 
447 typedef void ( *accel11_master_io_t )( struct accel11_s*, uint8_t, uint8_t*, uint8_t );
448 
452 typedef struct accel11_s
453 {
454  // Output pins
455  digital_out_t cs;
456 
457  // Input pins
458 
459  digital_in_t it1;
460  digital_in_t it2;
461 
462  // Modules
463 
464  i2c_master_t i2c;
465  spi_master_t spi;
466 
467  // ctx variable
468 
469  uint8_t slave_address;
470  pin_name_t chip_select;
474 
476 
480 typedef struct
481 {
482  // Communication gpio pins
483 
484  pin_name_t scl;
485  pin_name_t sda;
486  pin_name_t miso;
487  pin_name_t mosi;
488  pin_name_t sck;
489  pin_name_t cs;
490 
491  // Additional gpio pins
492 
493  pin_name_t it1;
494  pin_name_t it2;
495 
496  // static variable
497 
498  uint32_t i2c_speed;
499  uint8_t i2c_address;
500  uint32_t spi_speed;
501  uint8_t spi_mode;
502  spi_master_chip_select_polarity_t cs_polarity;
503 
505 
506 } accel11_cfg_t;
507  // End types group
509 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
515 #ifdef __cplusplus
516 extern "C"{
517 #endif
518 
528 
537 
546 
557 void accel11_generic_write ( accel11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
558 
569 void accel11_generic_read ( accel11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
570 
580 void accel11_write_byte ( accel11_t *ctx, uint8_t addr, uint8_t data_in );
581 
590 uint8_t accel11_read_byte ( accel11_t *ctx, uint8_t addr );
591 
600 
609 
618 int16_t accel11_get_axis_data ( accel11_t *ctx, uint8_t axis );
619 
628 
637 
638 #ifdef __cplusplus
639 }
640 #endif
641 #endif // _ACCEL11_H_
642  // End public_function group
645 
646 // ------------------------------------------------------------------------- END
accel11_cfg_t::mosi
pin_name_t mosi
Definition: accel11.h:487
accel11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: accel11.h:498
accel11_init
ACCEL11_RETVAL accel11_init(accel11_t *ctx, accel11_cfg_t *cfg)
Initialization function.
accel11_s::master_sel
accel11_select_t master_sel
Definition: accel11.h:473
accel11_cfg_t::spi_mode
uint8_t spi_mode
Definition: accel11.h:501
accel11_cfg_t::it2
pin_name_t it2
Definition: accel11.h:494
accel11_cfg_t::it1
pin_name_t it1
Definition: accel11.h:493
accel11_cfg_t::sck
pin_name_t sck
Definition: accel11.h:488
accel11_s::slave_address
uint8_t slave_address
Definition: accel11.h:469
accel11_cfg_t::i2c_address
uint8_t i2c_address
Definition: accel11.h:499
accel11_software_reset
void accel11_software_reset(accel11_t *ctx)
Software reset function.
accel11_default_cfg
void accel11_default_cfg(accel11_t *ctx)
Click Default Configuration function.
accel11_cfg_t::sda
pin_name_t sda
Definition: accel11.h:485
accel11_s::read_f
accel11_master_io_t read_f
Definition: accel11.h:472
accel11_s::write_f
accel11_master_io_t write_f
Definition: accel11.h:471
accel11_cfg_t
Click configuration structure definition.
Definition: accel11.h:481
ACCEL11_RETVAL
#define ACCEL11_RETVAL
Definition: accel11.h:77
accel11_get_temperature
int8_t accel11_get_temperature(accel11_t *ctx)
Function get temperature.
accel11_generic_read
void accel11_generic_read(accel11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
accel11_s
Click ctx object definition.
Definition: accel11.h:453
accel11_read_byte
uint8_t accel11_read_byte(accel11_t *ctx, uint8_t addr)
Functions for read byte from register.
accel11_s::chip_select
pin_name_t chip_select
Definition: accel11.h:470
accel11_s::spi
spi_master_t spi
Definition: accel11.h:465
accel11_s::i2c
i2c_master_t i2c
Definition: accel11.h:464
accel11_select_t
uint8_t accel11_select_t
Communication type.
Definition: accel11.h:442
accel11_s::it2
digital_in_t it2
Definition: accel11.h:460
accel11_cfg_t::miso
pin_name_t miso
Definition: accel11.h:486
accel11_get_axis_data
int16_t accel11_get_axis_data(accel11_t *ctx, uint8_t axis)
Accel Axis data function.
accel11_write_byte
void accel11_write_byte(accel11_t *ctx, uint8_t addr, uint8_t data_in)
Functions for write one byte in register.
accel11_s::it1
digital_in_t it1
Definition: accel11.h:459
accel11_cfg_t::cs
pin_name_t cs
Definition: accel11.h:489
accel11_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: accel11.h:502
accel11_cfg_setup
void accel11_cfg_setup(accel11_cfg_t *cfg)
Config Object Initialization function.
accel11_s::cs
digital_out_t cs
Definition: accel11.h:455
accel11_t
struct accel11_s accel11_t
Click ctx object definition.
accel11_master_io_t
void(* accel11_master_io_t)(struct accel11_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: accel11.h:447
accel11_cfg_t::spi_speed
uint32_t spi_speed
Definition: accel11.h:500
accel11_test_comunication
uint8_t accel11_test_comunication(accel11_t *ctx)
Test comunication function.
accel11_cfg_t::sel
accel11_select_t sel
Definition: accel11.h:504
accel11_power_on_procedure
void accel11_power_on_procedure(accel11_t *ctx)
Function for power on chip.
accel11_cfg_t::scl
pin_name_t scl
Definition: accel11.h:484
accel11_generic_write
void accel11_generic_write(accel11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.