lightranger3 2.0.0.0
lightranger3.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 LIGHTRANGER3_H
36#define LIGHTRANGER3_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
56// -------------------------------------------------------------- PUBLIC MACROS
66#define LIGHTRANGER3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
76#define LIGHTRANGER3_RETVAL uint8_t
77
78#define LIGHTRANGER3_OK 0x00
79#define LIGHTRANGER3_INIT_ERROR 0xFF
86#define LIGHTRANGER3_REG_ICSR 0x00
87#define LIGHTRANGER3_REG_IER 0x02
88#define LIGHTRANGER3_REG_CMD 0x04
89#define LIGHTRANGER3_REG_DEV_STATUS 0x06
90#define LIGHTRANGER3_REG_RESULT 0x08
91#define LIGHTRANGER3_REG_RESULT_CONFIG 0x0A
92#define LIGHTRANGER3_REG_CMD_CONFIG_A 0x0C
93#define LIGHTRANGER3_REG_CMD_CONFIG_B 0x0E
94#define LIGHTRANGER3_REG_HOST_TO_MCPU_MBX 0x10
95#define LIGHTRANGER3_REG_MCPU_TO_HOST_MBX 0x12
96#define LIGHTRANGER3_REG_PMU_CONFIG 0x14
97#define LIGHTRANGER3_REG_I2C_ADDR_PTR 0x18
98#define LIGHTRANGER3_REG_I2C_DATA_PTR 0x1A
99#define LIGHTRANGER3_REG_I2C_INIT_CFG 0x1C
100#define LIGHTRANGER3_REG_MCPU_PM_CTRL 0x1E
101#define LIGHTRANGER3_REG_HW_FW_CONFIG_0 0x20
102#define LIGHTRANGER3_REG_HW_FW_CONFIG_1 0x22
103#define LIGHTRANGER3_REG_HW_FW_CONFIG_2 0x24
104#define LIGHTRANGER3_REG_HW_FW_CONFIG_3 0x26
105#define LIGHTRANGER3_REG_DEVICE_ID 0x28
106#define LIGHTRANGER3_REG_PTCH_MEMORY_CFG 0x2A
113#define LIGHTRANGER3_STANDBY_MODE 0x90
114#define LIGHTRANGER3_OFF_MODE 0x91
115#define LIGHTRANGER3_ON_MODE 0x92
116#define LIGHTRANGER3_MEASUREMENT_MODE 0x81
123#define LIGHTRANGER3_ERROR 0x01
124#define DISTANCE_IS_GOOD 0x7FFF
127 // End group macro
128// --------------------------------------------------------------- PUBLIC TYPES
137typedef struct
138{
139 // Input pins
140
141 digital_in_t int_pin;
142
143 // Modules
144
145 i2c_master_t i2c;
146
147 // ctx variable
148
150
152 uint16_t distance;
153
155
159typedef struct
160{
161 // Communication gpio pins
162
163 pin_name_t scl;
164 pin_name_t sda;
165
166 // Additional gpio pins
167
168 pin_name_t int_pin;
169
170 // static variable
171
172 uint32_t i2c_speed;
173 uint8_t i2c_address;
174
176 uint16_t dev_distance;
177
179
180 // End types group
181// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
182
188#ifdef __cplusplus
189extern "C"{
190#endif
191
201
210
221void lightranger3_generic_write ( lightranger3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
222
233void lightranger3_generic_read ( lightranger3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
234
244void lightranger3_write_byte ( lightranger3_t *ctx, uint8_t reg, uint8_t w_data );
245
255void lightranger3_write_data ( lightranger3_t *ctx, uint8_t reg, uint16_t w_data );
256
265uint8_t lightranger3_read_byte ( lightranger3_t *ctx, uint8_t reg );
266
275uint16_t lightranger3_read_data ( lightranger3_t *ctx, uint8_t reg );
276
285
294
303
312
321
330
339
348
357
366
376
377#ifdef __cplusplus
378}
379#endif
380#endif // _LIGHTRANGER3_H_
381
382 // End public_function group
384
385// ------------------------------------------------------------------------- END
#define LIGHTRANGER3_RETVAL
Definition lightranger3.h:76
uint16_t lightranger3_get_distance(lightranger3_t *ctx)
Functions for reads distance.
uint16_t lightranger3_read_data(lightranger3_t *ctx, uint8_t reg)
Functions for read data from register.
void lightranger3_write_data(lightranger3_t *ctx, uint8_t reg, uint16_t w_data)
Functions for write data in register.
uint16_t lightranger3_get_confidence_value(lightranger3_t *ctx)
Functions for reads confidence value.
uint8_t lightranger3_get_interrupt(lightranger3_t *ctx)
Functions for reads interrupt pin.
uint8_t lightranger3_device_init(lightranger3_t *ctx)
Functions for initializes chip.
uint8_t lightranger3_set_on_mode(lightranger3_t *ctx)
Functions for go to ON mode.
uint8_t lightranger3_set_measurement_mode(lightranger3_t *ctx)
Functions for go to measurement mode.
void lightranger3_cfg_setup(lightranger3_cfg_t *cfg)
Config Object Initialization function.
uint8_t lightranger3_set_standby_mode(lightranger3_t *ctx)
Functions for go to standby mode.
void lightranger3_generic_write(lightranger3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t lightranger3_set_off_mode(lightranger3_t *ctx)
Functions for go to OFF mode.
uint8_t lightranger3_read_byte(lightranger3_t *ctx, uint8_t reg)
Functions for read one byte from register.
void lightranger3_generic_read(lightranger3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t lightranger3_take_single_measurement(lightranger3_t *ctx)
Functions for measurement.
void lightranger3_write_byte(lightranger3_t *ctx, uint8_t reg, uint8_t w_data)
Functions for write one byte in register.
uint16_t lightranger3_get_device_id(lightranger3_t *ctx)
Functions for reads device ID.
LIGHTRANGER3_RETVAL lightranger3_init(lightranger3_t *ctx, lightranger3_cfg_t *cfg)
Initialization function.
void lightranger3_soft_reset(lightranger3_t *ctx)
Functions for soft reset.
Click configuration structure definition.
Definition lightranger3.h:160
uint16_t dev_confidence_value
Definition lightranger3.h:175
uint32_t i2c_speed
Definition lightranger3.h:172
uint16_t dev_distance
Definition lightranger3.h:176
pin_name_t scl
Definition lightranger3.h:163
pin_name_t int_pin
Definition lightranger3.h:168
pin_name_t sda
Definition lightranger3.h:164
uint8_t i2c_address
Definition lightranger3.h:173
Click ctx object definition.
Definition lightranger3.h:138
uint16_t confidence_value
Definition lightranger3.h:151
uint16_t distance
Definition lightranger3.h:152
digital_in_t int_pin
Definition lightranger3.h:141
i2c_master_t i2c
Definition lightranger3.h:145
uint8_t slave_address
Definition lightranger3.h:149