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
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 ACCEL11_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.it1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
76 cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_INT );
83#define ACCEL11_MASTER_I2C 0
84#define ACCEL11_MASTER_SPI 1
91#define ACCEL11_RETVAL uint8_t
92
93#define ACCEL11_OK 0x00
94#define ACCEL11_INIT_ERROR 0xFF
101#define ACCEL11_CHIP_ID 0x16
108#define ACCEL11_REG_CHIP_ID 0x00
109#define ACCEL11_REG_ERROR 0x02
110#define ACCEL11_REG_STATUS 0x03
111#define ACCEL11_REG_AUX_X_LSB 0x0A
112#define ACCEL11_REG_AUX_X_MSB 0x0B
113#define ACCEL11_REG_AUX_Y_LSB 0x0C
114#define ACCEL11_REG_AUX_Y_MSB 0x0D
115#define ACCEL11_REG_AUX_Z_LSB 0x0E
116#define ACCEL11_REG_AUX_Z_MSB 0x0F
117#define ACCEL11_REG_AUX_R_LSB 0x10
118#define ACCEL11_REG_AUX_R_MSB 0x11
119#define ACCEL11_REG_ACCEL_X_LSB 0x12
120#define ACCEL11_REG_ACCEL_X_MSB 0x13
121#define ACCEL11_REG_ACCEL_Y_LSB 0x14
122#define ACCEL11_REG_ACCEL_Y_MSB 0x15
123#define ACCEL11_REG_ACCEL_Z_LSB 0x16
124#define ACCEL11_REG_ACCEL_Z_MSB 0x17
125#define ACCEL11_REG_SENSOR_TIME_0 0x18
126#define ACCEL11_REG_SENSOR_TIME_1 0x19
127#define ACCEL11_REG_SENSOR_TIME_2 0x1A
128#define ACCEL11_REG_EVENT 0x1B
129#define ACCEL11_REG_STATUS_INT_0 0x1C
130#define ACCEL11_REG_STATUS_INT_1 0x1D
131#define ACCEL11_REG_STEP_COUNTER_0 0x1E
132#define ACCEL11_REG_STEP_COUNTER_1 0x1F
133#define ACCEL11_REG_STEP_COUNTER_2 0x20
134#define ACCEL11_REG_STEP_COUNTER_3 0x21
135#define ACCEL11_REG_TEMPERATURE 0x22
136#define ACCEL11_REG_FIFO_LENGTH_LSB 0x24
137#define ACCEL11_REG_FIFO_LENGTH_MSB 0x25
138#define ACCEL11_REG_FIFO_DATA 0x26
139#define ACCEL11_REG_ACTIVITY_TYPE 0x27
140#define ACCEL11_REG_INTERNAL_STATUS 0x2A
141#define ACCEL11_REG_ACCEL_CONFIG 0x40
142#define ACCEL11_REG_ACCEL_RANGE 0x41
143#define ACCEL11_REG_AUX_CONFIG 0x44
144#define ACCEL11_REG_FIFO_DOWNS 0x45
145#define ACCEL11_REG_FIFO_WTM_LSB 0x46
146#define ACCEL11_REG_FIFO_WTM_MSB 0x47
147#define ACCEL11_REG_FIFO_CONFIG_0 0x48
148#define ACCEL11_REG_FIFO_CONFIG_1 0x49
149#define ACCEL11_AUX_DEV_ID 0x4B
150#define ACCEL11_REG_AUX_IF_CONFIG 0x4C
151#define ACCEL11_REG_AUX_RD_ADDRESS 0x4D
152#define ACCEL11_REG_AUX_WR_ADDRESS 0x4E
153#define ACCEL11_REG_AUX_WR_DATA 0x4F
154#define ACCEL11_REG_INT1_IO_CTRL 0x53
155#define ACCEL11_REG_INT2_IO_CTRL 0x54
156#define ACCEL11_REG_INT_LATCH 0x55
157#define ACCEL11_REG_INT1_MAP 0x56
158#define ACCEL11_REG_INT2_MAP 0x57
159#define ACCEL11_REG_INT_MAP_DATA 0x58
160#define ACCEL11_REG_INT_CTRL 0x59
161#define ACCEL11_REG_FEATURES_IN 0x5E
162#define ACCEL11_REG_INTERNAL_ERROR 0x5F
163#define ACCEL11_REG_NVM_CONF 0x6A
164#define ACCEL11_REG_SPI_IF_CONF 0x6B
165#define ACCEL11_REG_ACCEL_SELF_TEST 0x6D
166#define ACCEL11_REG_NV_CONF 0x70
167#define ACCEL11_REG_OFFSET_X_AXIS 0x71
168#define ACCEL11_REG_OFFSET_Y_AXIS 0x72
169#define ACCEL11_REG_OFFSET_Z_AXIS 0x73
170#define ACCEL11_REG_POWER_CONFIG 0x7C
171#define ACCEL11_REG_POWER_CTRL 0x7D
172#define ACCEL11_REG_COMMAND 0x7E
179#define ACCEL11_ERR_AUX 0x80
180#define ACCEL11_ERR_FIFO 0x80
181#define ACCEL11_ERR_ACCEL 0x04
182#define ACCEL11_ERR_CMD 0x02
183#define ACCEL11_ERR_FATAL 0x01
190#define ACCEL11_STATUS_DRDY_ACCEL 0x80
191#define ACCEL11_STATUS_DRDY_AUX 0x20
192#define ACCEL11_STATUS_RDY_CMD 0x10
193#define ACCEL11_STATUS_AUX_MAN_OP 0x04
200#define ACCEL11_EVENT_POWER_UP 0x00
201#define ACCEL11_EVENT_SOFTWARE_RESET 0x01
208#define ACCEL11_INTS0_ERR_INT_OUT 0x80
209#define ACCEL11_INTS0_NO_MOTION_OUT 0x40
210#define ACCEL11_INTS0_WAKEUP_OUT 0x20
211#define ACCEL11_INTS0_WRIST_TILT_OUT 0x08
212#define ACCEL11_INTS0_ACTIVITY_TYPE_OUT 0x04
213#define ACCEL11_INTS0_STEP_COUNTER_OUT 0x02
220#define ACCEL11_INTS1_ACCEL_DRDY_INT 0x80
221#define ACCEL11_INTS1_AUX_DRDY_INT 0x20
222#define ACCEL11_INTS1_FWM_INT 0x02
223#define ACCEL11_INTS1_FFULL_INT 0x01
230#define ACCEL11_ATYPE_USER_NOT_MOVING 0x00
231#define ACCEL11_ATYPE_USER_WALKING 0x01
232#define ACCEL11_ATYPE_USER_RUNNING 0x02
239#define ACCEL11_INTERS_ODR_HIGH_ERR 0x80
240#define ACCEL11_INTERS_ODR_50HZ_ERR 0x40
241#define ACCEL11_INTERS_AXES_REMAP_ERR 0x20
242#define ACCEL11_INTERS_NOT_INIT 0x00
243#define ACCEL11_INTERS_INIT_OK 0x01
244#define ACCEL11_INTERS_INIT_ERROR 0x02
245#define ACCEL11_INTERS_INVALID_DRIVER 0x03
246#define ACCEL11_INTERS_SENSOR_STOPPED 0x04
253#define ACCEL11_ACFG_AVERAGING_MODE 0x00
254#define ACCEL11_ACFG_CONTINUOUS_MODE 0x80
255#define ACCEL11_ACFG_BWP_NO_AVERAGING 0x00
256#define ACCEL11_ACFG_BWP_AVERAGING_2_SAMPLES 0x10
257#define ACCEL11_ACFG_BWP_AVERAGING_4_SAMPLES 0x20
258#define ACCEL11_ACFG_BWP_AVERAGING_8_SAMPLES 0x30
259#define ACCEL11_ACFG_BWP_AVERAGING_16_SAMPLES 0x40
260#define ACCEL11_ACFG_BWP_AVERAGING_32_SAMPLES 0x50
261#define ACCEL11_ACFG_BWP_AVERAGING_64_SAMPLES 0x60
262#define ACCEL11_ACFG_BWP_AVERAGING_128_SAMPLES 0x70
269#define ACCEL11_RANGE_2g 0x00
270#define ACCEL11_RANGE_4g 0x01
271#define ACCEL11_RANGE_8g 0x02
272#define ACCEL11_RANGE_16g 0x03
279#define ACCEL11_CFG_ODR_0p78Hz 0x01
280#define ACCEL11_CFG_ODR_1p5Hz 0x02
281#define ACCEL11_CFG_ODR_3p1Hz 0x03
282#define ACCEL11_CFG_ODR_6p25Hz 0x04
283#define ACCEL11_CFG_ODR_12p5Hz 0x05
284#define ACCEL11_CFG_ODR_25Hz 0x06
285#define ACCEL11_CFG_ODR_50Hz 0x07
286#define ACCEL11_CFG_ODR_100Hz 0x08
287#define ACCEL11_CFG_ODR_200Hz 0x09
288#define ACCEL11_CFG_ODR_400Hz 0x0A
289#define ACCEL11_CFG_ODR_800Hz 0x0B
290#define ACCEL11_CFG_ODR_1k6Hz 0x0C
291#define ACCEL11_CFG_ODR_3k2Hz 0x0D
292#define ACCEL11_CFG_ODR_6k4Hz 0x0E
293#define ACCEL11_CFG_ODR_12k8Hz 0x0F
300#define ACCEL11_FCFG0_FIFO_TIME_ENABLE 0x02
301#define ACCEL11_FCFG0_FIFO_TIME_DISABLE 0x00
302#define ACCEL11_FCFG0_FIFO_STOP_ON_FULL_ENABLE 0x01
303#define ACCEL11_FCFG0_FIFO_STOP_ON_FULL_DISABLE 0x00
310#define ACCEL11_FCGF1_FIFO_ACCEL_ENABLE 0x40
311#define ACCEL11_FCGF1_FIFO_ACCEL_DISABLE 0x00
312#define ACCEL11_FCGF1_FIFO_AUX_ENABLE 0x20
313#define ACCEL11_FCGF1_FIFO_AUX_DISABLE 0x00
314#define ACCEL11_FCGF1_FIFO_HEADER_ENABLE 0x10
315#define ACCEL11_FCGF1_FIFO_HEADER_DISABLE 0x00
316#define ACCEL11_FCGF1_FIFO_TAG_INT1_ENABLE 0x08
317#define ACCEL11_FCGF1_FIFO_TAG_INT1_DISABLE 0x00
318#define ACCEL11_FCGF1_FIFO_TAG_INT2_ENABLE 0x04
319#define ACCEL11_FCGF1_FIFO_TAG_INT2_DISABLE 0x00
326#define ACCEL11_IFCFG_DATA_MODE 0x00
327#define ACCEL11_IFCFG_SETUP_MODE 0x80
328#define ACCEL11_IFCFG_BURST_LENGTH_1 0x00
329#define ACCEL11_IFCFG_BURST_LENGTH_2 0x01
330#define ACCEL11_IFCFG_BURST_LENGTH_6 0x02
331#define ACCEL11_IFCFG_BURST_LENGTH_8 0x03
338#define ACCEL11_INTIO_INPUT_ENABLE 0x10
339#define ACCEL11_INTIO_INPUT_DISABLE 0x00
340#define ACCEL11_INTIO_OUTPUT_ENABLE 0x08
341#define ACCEL11_INTIO_OUTPUT_DISABLE 0x00
342#define ACCEL11_INTIO_PUSH_PULL 0x00
343#define ACCEL11_INTIO_OPEN_DRAIN 0x04
344#define ACCEL11_INTIO_LVL_ACTIVE_LOW 0x00
345#define ACCEL11_INTIO_LVL_ACTIVE_HIGH 0x02
346#define ACCEL11_INTIO_TRIGGER_LEVEL 0x00
347#define ACCEL11_INTIO_TRIGGER_EDGE 0x01
354#define ACCEL11_INTLAT_NON_LATCHED 0x00
355#define ACCEL11_INTLAT_LATCHED 0x01
362#define ACCEL11_IMAPD_INT1_FFULL 0x01
363#define ACCEL11_IMAPD_INT1_FWM 0x03
364#define ACCEL11_IMAPD_INT1_DRDY 0x04
365#define ACCEL11_IMAPD_INT2_FFULL 0x10
366#define ACCEL11_IMAPD_INT2_FWM 0x20
367#define ACCEL11_IMAPD_INT2_DRDY 0x40
374#define ACCEL11_SPI_4_WIRE 0x00
375#define ACCEL11_SPI_3_WIRE 0x01
376#define ACCEL11_AUX_INTERFACE_OFF 0x00
377#define ACCEL11_AUX_INTERFACE_MAG 0x10
384#define ACCEL_NV_ACCEL_OFFSET_ENABLE 0x08
385#define ACCEL_NV_ACCEL_OFFSET_DISABLE 0x00
386#define ACCEL_NV_I2C_WATCHDOG_ENABLE 0x04
387#define ACCEL_NV_I2C_WATCHDOG_DISABLE 0x00
388#define ACCEL_NV_I2C_WDT_TIMEOUT_SHORT 0x00
389#define ACCEL_NV_I2C_WDT_TIMEOUT_LONG 0x02
390#define ACCEL_NV_I2C_INTERFACE_ENABLE 0x00
391#define ACCEL_NV_I2C_INTERFACE_DISABLE 0x01
398#define ACCEL11_PWRCFG_APS_ON 0x01
399#define ACCEL11_PWRCFG_APS_OFF 0x00
400#define ACCEL11_PWRCFG_FSW_ON 0x02
401#define ACCEL11_PWRCFG_FSW_OFF 0x00
408#define ACCEL11_PWRCTRL_ACCEL_ENABLE 0x04
409#define ACCEL11_PWRCTRL_ACCEL_DISABLE 0x00
416#define ACCEL11_CMD_NVM_PROG 0xA0
417#define ACCEL11_CMD_FIFO_FLUSH 0xB0
418#define ACCEL11_CMD_SW_RESET 0xB6
425#define ACCEL11_ACCEL_X_AXIS 0x12
426#define ACCEL11_ACCEL_Y_AXIS 0x14
427#define ACCEL11_ACCEL_Z_AXIS 0x16
434#define ACCEL11_SLAVE_ADDRESS_GND 0x18
435#define ACCEL11_SLAVE_ADDRESS_VCC 0x19
442#define ACCEL11_TEST_COMUNICATION_ERROR 0x01
443#define ACCEL11_TEST_COMUNICATION_OK 0x00
446 // End group macro
447// --------------------------------------------------------------- PUBLIC TYPES
456typedef uint8_t accel11_select_t;
457
461typedef void ( *accel11_master_io_t )( struct accel11_s*, uint8_t, uint8_t*, uint8_t );
462
466typedef struct accel11_s
467{
468 // Output pins
469 digital_out_t cs;
470
471 // Input pins
472
473 digital_in_t it1;
474 digital_in_t it2;
475
476 // Modules
477
478 i2c_master_t i2c;
479 spi_master_t spi;
480
481 // ctx variable
482
484 pin_name_t chip_select;
488
490
494typedef struct
495{
496 // Communication gpio pins
497
498 pin_name_t scl;
499 pin_name_t sda;
500 pin_name_t miso;
501 pin_name_t mosi;
502 pin_name_t sck;
503 pin_name_t cs;
504
505 // Additional gpio pins
506
507 pin_name_t it1;
508 pin_name_t it2;
509
510 // static variable
511
512 uint32_t i2c_speed;
513 uint8_t i2c_address;
514 uint32_t spi_speed;
515 uint8_t spi_mode;
516 spi_master_chip_select_polarity_t cs_polarity;
517
519
521
522 // End types group
523// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
529#ifdef __cplusplus
530extern "C"{
531#endif
532
542
551
560
571void accel11_generic_write ( accel11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
572
583void accel11_generic_read ( accel11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
584
594void accel11_write_byte ( accel11_t *ctx, uint8_t addr, uint8_t data_in );
595
604uint8_t accel11_read_byte ( accel11_t *ctx, uint8_t addr );
605
614
623
632int16_t accel11_get_axis_data ( accel11_t *ctx, uint8_t axis );
633
642
651
652#ifdef __cplusplus
653}
654#endif
655#endif // _ACCEL11_H_
656
657 // End public_function group
659
660// ------------------------------------------------------------------------- END
#define ACCEL11_RETVAL
Definition accel11.h:91
void accel11_cfg_setup(accel11_cfg_t *cfg)
Config Object Initialization function.
ACCEL11_RETVAL accel11_init(accel11_t *ctx, accel11_cfg_t *cfg)
Initialization function.
void accel11_default_cfg(accel11_t *ctx)
Click Default Configuration function.
uint8_t accel11_read_byte(accel11_t *ctx, uint8_t addr)
Functions for read byte from register.
void accel11_write_byte(accel11_t *ctx, uint8_t addr, uint8_t data_in)
Functions for write one byte in register.
void accel11_software_reset(accel11_t *ctx)
Software reset function.
int8_t accel11_get_temperature(accel11_t *ctx)
Function get temperature.
uint8_t accel11_test_comunication(accel11_t *ctx)
Test comunication function.
void accel11_power_on_procedure(accel11_t *ctx)
Function for power on chip.
void accel11_generic_read(accel11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
int16_t accel11_get_axis_data(accel11_t *ctx, uint8_t axis)
Accel Axis data function.
void accel11_generic_write(accel11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t accel11_select_t
Communication type.
Definition accel11.h:456
void(* accel11_master_io_t)(struct accel11_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition accel11.h:461
struct accel11_s accel11_t
Click ctx object definition.
Click configuration structure definition.
Definition accel11.h:495
pin_name_t it2
Definition accel11.h:508
uint8_t spi_mode
Definition accel11.h:515
uint32_t i2c_speed
Definition accel11.h:512
pin_name_t it1
Definition accel11.h:507
accel11_select_t sel
Definition accel11.h:518
spi_master_chip_select_polarity_t cs_polarity
Definition accel11.h:516
pin_name_t sck
Definition accel11.h:502
pin_name_t mosi
Definition accel11.h:501
uint32_t spi_speed
Definition accel11.h:514
pin_name_t scl
Definition accel11.h:498
pin_name_t miso
Definition accel11.h:500
pin_name_t sda
Definition accel11.h:499
pin_name_t cs
Definition accel11.h:503
uint8_t i2c_address
Definition accel11.h:513
Click ctx object definition.
Definition accel11.h:467
digital_out_t cs
Definition accel11.h:469
spi_master_t spi
Definition accel11.h:479
digital_in_t it2
Definition accel11.h:474
accel11_master_io_t write_f
Definition accel11.h:485
i2c_master_t i2c
Definition accel11.h:478
uint8_t slave_address
Definition accel11.h:483
accel11_select_t master_sel
Definition accel11.h:487
pin_name_t chip_select
Definition accel11.h:484
digital_in_t it1
Definition accel11.h:473
accel11_master_io_t read_f
Definition accel11.h:486