28#ifndef LIGHTRANGER10_H
29#define LIGHTRANGER10_H
39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
73#define LIGHTRANGER10_REG_SOFT_RESET 0x0000
74#define LIGHTRANGER10_REG_ALGO_PTP_RANGE_OFFSET_MM 0x001E
75#define LIGHTRANGER10_REG_MM_CFG_INNER_OFFSET_MM 0x0020
76#define LIGHTRANGER10_REG_MM_CFG_OUTER_OFFSET_MM 0x0022
77#define LIGHTRANGER10_REG_RANGE_CFG_VCSEL_PERIOD_A 0x0060
78#define LIGHTRANGER10_REG_RANGE_CFG_VCSEL_PERIOD_B 0x0063
79#define LIGHTRANGER10_REG_RANGE_CFG_VALID_PHASE_HIGH 0x0069
80#define LIGHTRANGER10_REG_SD_CFG_WOI_SD0 0x0078
81#define LIGHTRANGER10_REG_SD_CFG_WOI_SD1 0x0079
82#define LIGHTRANGER10_REG_SD_CFG_INIT_PHASE_SD0 0x007A
83#define LIGHTRANGER10_REG_SD_CFG_INIT_PHASE_SD1 0x007B
84#define LIGHTRANGER10_REG_SYSTEM_INT_MEAS_PERIOD 0x006C
85#define LIGHTRANGER10_REG_SYSTEM_INTERRUPT_CLEAR 0x0086
86#define LIGHTRANGER10_REG_SYSTEM_MODE_START 0x0087
87#define LIGHTRANGER10_REG_RESULT_RANGE_MM_SD0 0x0096
88#define LIGHTRANGER10_REG_RESULT_OSC_CALIBRATE_VAL 0x00DE
89#define LIGHTRANGER10_REG_MODEL_ID 0x010F
90#define LIGHTRANGER10_REG_MODEL_TYPE 0x0110
108#define LIGHTRANGER10_SOFT_RESET_SET 0x00
109#define LIGHTRANGER10_SOFT_RESET_CLEAR 0x01
115#define LIGHTRANGER10_INTERRUPT_CLEAR 0x01
121#define LIGHTRANGER10_RANGING_ENABLE 0x40
122#define LIGHTRANGER10_RANGING_DISABLE 0x00
128#define LIGHTRANGER10_DISTANCE_MODE_MEDIUM 0x00
129#define LIGHTRANGER10_DISTANCE_MODE_LONG 0x01
135#define LIGHTRANGER10_DISTANCE_MEDIUM_RANGE_PERIOD_A 0x0B
136#define LIGHTRANGER10_DISTANCE_MEDIUM_RANGE_PERIOD_B 0x09
137#define LIGHTRANGER10_DISTANCE_MEDIUM_RANGE_VAL_PH_H 0x78
138#define LIGHTRANGER10_DISTANCE_MEDIUM_SD_WOI_SD0 0x0B
139#define LIGHTRANGER10_DISTANCE_MEDIUM_SD_WOI_SD1 0x09
140#define LIGHTRANGER10_DISTANCE_MEDIUM_SD_IN_PH_SD0 0x0A
141#define LIGHTRANGER10_DISTANCE_MEDIUM_SD_IN_PH_SD1 0x0A
142#define LIGHTRANGER10_DISTANCE_LONG_RANGE_PERIOD_A 0x0F
143#define LIGHTRANGER10_DISTANCE_LONG_RANGE_PERIOD_B 0x0D
144#define LIGHTRANGER10_DISTANCE_LONG_RANGE_VAL_PH_H 0xB8
145#define LIGHTRANGER10_DISTANCE_LONG_SD_WOI_SD0 0x0F
146#define LIGHTRANGER10_DISTANCE_LONG_SD_WOI_SD1 0x0D
147#define LIGHTRANGER10_DISTANCE_LONG_SD_IN_PH_SD0 0x0E
148#define LIGHTRANGER10_DISTANCE_LONG_SD_IN_PH_SD1 0x0E
154#define LIGHTRANGER10_ALGO_PTP_RANGE_OFFSET_MM_MULT 4
155#define LIGHTRANGER10_ALGO_PTP_RANGE_OFFSET_MM_RESET 0
156#define LIGHTRANGER10_MM_CFG_INNER_OFFSET_MM_RESET 0
157#define LIGHTRANGER10_MM_CFG_OUTER_OFFSET_MM_RESET 0
158#define LIGHTRANGER10_CALIBRATE_DISTANCE_AVERAGE_NUM 20
164#define LIGHTRANGER10_DEFAULT_IM_PERIOD_MS 200
165#define LIGHTRANGER10_OSC_CALIB_IM_PERIOD_OFFSET 4
171#define LIGHTRANGER10_MODEL_ID 0xEB
172#define LIGHTRANGER10_MODEL_TYPE 0xAA
179#define LIGHTRANGER10_DEVICE_ADDRESS 0x29
197#define LIGHTRANGER10_MAP_MIKROBUS( cfg, mikrobus ) \
198 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
199 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
200 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
201 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
err_t lightranger10_generic_read(lightranger10_t *ctx, uint16_t reg, uint8_t *data_out, uint8_t len)
LightRanger 10 I2C reading function.
uint8_t lightranger10_get_int_pin(lightranger10_t *ctx)
LightRanger 10 get int pin function.
err_t lightranger10_read_word(lightranger10_t *ctx, uint16_t reg, uint16_t *data_out)
LightRanger 10 read word function.
err_t lightranger10_calibrate_distance(lightranger10_t *ctx, uint16_t target_distance_mm)
LightRanger 10 calibrate distance function.
err_t lightranger10_check_communication(lightranger10_t *ctx)
LightRanger 10 check communication function.
err_t lightranger10_set_distance_offset(lightranger10_t *ctx, int16_t offset_mm)
LightRanger 10 set distance offset function.
err_t lightranger10_init(lightranger10_t *ctx, lightranger10_cfg_t *cfg)
LightRanger 10 initialization function.
err_t lightranger10_default_cfg(lightranger10_t *ctx)
LightRanger 10 default configuration function.
err_t lightranger10_clear_interrupts(lightranger10_t *ctx)
LightRanger 10 clear interrupts function.
err_t lightranger10_set_distance_mode(lightranger10_t *ctx, uint8_t distance_mode)
LightRanger 10 set distance mode function.
void lightranger10_cfg_setup(lightranger10_cfg_t *cfg)
LightRanger 10 configuration object setup function.
void lightranger10_enable_device(lightranger10_t *ctx)
LightRanger 10 enable device function.
err_t lightranger10_start_measurement(lightranger10_t *ctx)
LightRanger 10 start measurement function.
err_t lightranger10_read_byte(lightranger10_t *ctx, uint16_t reg, uint8_t *data_out)
LightRanger 10 read byte function.
err_t lightranger10_soft_reset(lightranger10_t *ctx)
LightRanger 10 soft reset function.
void lightranger10_disable_device(lightranger10_t *ctx)
LightRanger 10 disable device function.
err_t lightranger10_stop_measurement(lightranger10_t *ctx)
LightRanger 10 stop measurement function.
err_t lightranger10_read_dword(lightranger10_t *ctx, uint16_t reg, uint16_t *data_out)
LightRanger 10 read dword function.
err_t lightranger10_write_byte(lightranger10_t *ctx, uint16_t reg, uint8_t data_in)
LightRanger 10 write byte function.
err_t lightranger10_generic_write(lightranger10_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len)
LightRanger 10 I2C writing function.
err_t lightranger10_get_distance(lightranger10_t *ctx, uint16_t *distance_mm)
LightRanger 10 get distance function.
void lightranger10_reset_device(lightranger10_t *ctx)
LightRanger 10 reset device function.
err_t lightranger10_write_dword(lightranger10_t *ctx, uint16_t reg, uint32_t data_in)
LightRanger 10 write dword function.
err_t lightranger10_set_inter_measurement_period_ms(lightranger10_t *ctx, uint32_t period_ms)
LightRanger 10 set inter measurement period ms function.
err_t lightranger10_write_word(lightranger10_t *ctx, uint16_t reg, uint16_t data_in)
LightRanger 10 write word function.
lightranger10_return_value_t
LightRanger 10 Click return value data.
Definition lightranger10.h:248
@ LIGHTRANGER10_OK
Definition lightranger10.h:249
@ LIGHTRANGER10_ERROR
Definition lightranger10.h:250
LightRanger 10 Click configuration object.
Definition lightranger10.h:231
uint32_t i2c_speed
Definition lightranger10.h:238
pin_name_t scl
Definition lightranger10.h:232
pin_name_t en
Definition lightranger10.h:235
pin_name_t int_pin
Definition lightranger10.h:236
pin_name_t sda
Definition lightranger10.h:233
uint8_t i2c_address
Definition lightranger10.h:239
LightRanger 10 Click context object.
Definition lightranger10.h:211
digital_in_t int_pin
Definition lightranger10.h:216
i2c_master_t i2c
Definition lightranger10.h:219
digital_out_t en
Definition lightranger10.h:213
uint8_t slave_address
Definition lightranger10.h:222