ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
vl53l1x.c File Reference

VL53L1X driver (see vl53l1x.h). More...

#include "vl53l1x.h"
Include dependency graph for vl53l1x.c:

Go to the source code of this file.

Macros

#define REG_SOFT_RESET   0x0000u
 
#define REG_VHV_TIMEOUT_LOOP_BOUND   0x0008u
 
#define REG_VHV_START   0x000Bu
 
#define REG_GPIO_HV_MUX_CTRL   0x0030u
 
#define REG_GPIO_TIO_HV_STATUS   0x0031u
 
#define REG_PHASECAL_TIMEOUT   0x004Bu
 
#define REG_RANGE_TIMEOUT_A_HI   0x005Eu
 
#define REG_RANGE_VCSEL_PERIOD_A   0x0060u
 
#define REG_RANGE_TIMEOUT_B_HI   0x0061u
 
#define REG_RANGE_VCSEL_PERIOD_B   0x0063u
 
#define REG_RANGE_VALID_PHASE_HIGH   0x0069u
 
#define REG_INTERMEASUREMENT   0x006Cu
 
#define REG_SD_WOI_SD0   0x0078u
 
#define REG_SD_INITIAL_PHASE_SD0   0x007Au
 
#define REG_INTERRUPT_CLEAR   0x0086u
 
#define REG_MODE_START   0x0087u
 
#define REG_RESULT_RANGE_STATUS   0x0089u
 
#define REG_RESULT_DISTANCE   0x0096u
 
#define REG_OSC_CALIBRATE_VAL   0x00DEu
 
#define REG_FIRMWARE_SYSTEM_STATUS   0x00E5u
 
#define REG_MODEL_ID   0x010Fu
 

Functions

static int32_t wr8 (vl53_t *d, uint16_t reg, uint8_t v)
 
static int32_t wr16 (vl53_t *d, uint16_t reg, uint16_t v)
 
static int32_t wr32 (vl53_t *d, uint16_t reg, uint32_t v)
 
static int32_t rd8 (vl53_t *d, uint16_t reg, uint8_t *v)
 
static int32_t rd16 (vl53_t *d, uint16_t reg, uint16_t *v)
 
static void dly (vl53_t *d, uint32_t ms)
 
static int32_t data_ready (vl53_t *d, uint8_t *rdy)
 
static uint8_t map_status (uint8_t s)
 
int32_t vl53_init (vl53_t *d, const vl53_bus_t *bus, uint16_t budget_ms)
 0 = sensor found and ranging; < 0 = absent or error (the board works without it)
 
int32_t vl53_poll (vl53_t *d, vl53_sample_t *s)
 1 = new sample in *s, 0 = none yet, < 0 = bus error
 

Variables

static const uint8_t k_default [0x87 - 0x2D+1]
 

Detailed Description

VL53L1X driver (see vl53l1x.h).

Derived from ST's VL53L1X ULD: COPYRIGHT(c) 2018 STMicroelectronics. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the BSD-3-Clause conditions are met (copyright notice, this list of conditions and the disclaimer below retained; no endorsement by STMicroelectronics). THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED.

Definition in file vl53l1x.c.

Macro Definition Documentation

◆ REG_SOFT_RESET

#define REG_SOFT_RESET   0x0000u

Definition at line 15 of file vl53l1x.c.

◆ REG_VHV_TIMEOUT_LOOP_BOUND

#define REG_VHV_TIMEOUT_LOOP_BOUND   0x0008u

Definition at line 16 of file vl53l1x.c.

◆ REG_VHV_START

#define REG_VHV_START   0x000Bu

Definition at line 17 of file vl53l1x.c.

◆ REG_GPIO_HV_MUX_CTRL

#define REG_GPIO_HV_MUX_CTRL   0x0030u

Definition at line 18 of file vl53l1x.c.

◆ REG_GPIO_TIO_HV_STATUS

#define REG_GPIO_TIO_HV_STATUS   0x0031u

Definition at line 19 of file vl53l1x.c.

◆ REG_PHASECAL_TIMEOUT

#define REG_PHASECAL_TIMEOUT   0x004Bu

Definition at line 20 of file vl53l1x.c.

◆ REG_RANGE_TIMEOUT_A_HI

#define REG_RANGE_TIMEOUT_A_HI   0x005Eu

Definition at line 21 of file vl53l1x.c.

◆ REG_RANGE_VCSEL_PERIOD_A

#define REG_RANGE_VCSEL_PERIOD_A   0x0060u

Definition at line 22 of file vl53l1x.c.

◆ REG_RANGE_TIMEOUT_B_HI

#define REG_RANGE_TIMEOUT_B_HI   0x0061u

Definition at line 23 of file vl53l1x.c.

◆ REG_RANGE_VCSEL_PERIOD_B

#define REG_RANGE_VCSEL_PERIOD_B   0x0063u

Definition at line 24 of file vl53l1x.c.

◆ REG_RANGE_VALID_PHASE_HIGH

#define REG_RANGE_VALID_PHASE_HIGH   0x0069u

Definition at line 25 of file vl53l1x.c.

◆ REG_INTERMEASUREMENT

#define REG_INTERMEASUREMENT   0x006Cu

Definition at line 26 of file vl53l1x.c.

◆ REG_SD_WOI_SD0

#define REG_SD_WOI_SD0   0x0078u

Definition at line 27 of file vl53l1x.c.

◆ REG_SD_INITIAL_PHASE_SD0

#define REG_SD_INITIAL_PHASE_SD0   0x007Au

Definition at line 28 of file vl53l1x.c.

◆ REG_INTERRUPT_CLEAR

#define REG_INTERRUPT_CLEAR   0x0086u

Definition at line 29 of file vl53l1x.c.

◆ REG_MODE_START

#define REG_MODE_START   0x0087u

Definition at line 30 of file vl53l1x.c.

◆ REG_RESULT_RANGE_STATUS

#define REG_RESULT_RANGE_STATUS   0x0089u

Definition at line 31 of file vl53l1x.c.

◆ REG_RESULT_DISTANCE

#define REG_RESULT_DISTANCE   0x0096u

Definition at line 32 of file vl53l1x.c.

◆ REG_OSC_CALIBRATE_VAL

#define REG_OSC_CALIBRATE_VAL   0x00DEu

Definition at line 33 of file vl53l1x.c.

◆ REG_FIRMWARE_SYSTEM_STATUS

#define REG_FIRMWARE_SYSTEM_STATUS   0x00E5u

Definition at line 34 of file vl53l1x.c.

◆ REG_MODEL_ID

#define REG_MODEL_ID   0x010Fu

Definition at line 35 of file vl53l1x.c.

Function Documentation

◆ wr8()

static int32_t wr8 ( vl53_t *  d,
uint16_t  reg,
uint8_t  v 
)
static

Definition at line 47 of file vl53l1x.c.

References vl53_t::bus, vl53_bus_t::handle, and vl53_bus_t::write.

Referenced by vl53_init(), and vl53_poll().

Here is the caller graph for this function:

◆ wr16()

static int32_t wr16 ( vl53_t *  d,
uint16_t  reg,
uint16_t  v 
)
static

Definition at line 48 of file vl53l1x.c.

References b, vl53_t::bus, vl53_bus_t::handle, and vl53_bus_t::write.

Referenced by vl53_init().

Here is the caller graph for this function:

◆ wr32()

static int32_t wr32 ( vl53_t *  d,
uint16_t  reg,
uint32_t  v 
)
static

Definition at line 53 of file vl53l1x.c.

References b, vl53_t::bus, vl53_bus_t::handle, and vl53_bus_t::write.

Referenced by vl53_init().

Here is the caller graph for this function:

◆ rd8()

static int32_t rd8 ( vl53_t *  d,
uint16_t  reg,
uint8_t *  v 
)
static

Definition at line 58 of file vl53l1x.c.

References vl53_t::bus, vl53_bus_t::handle, and vl53_bus_t::read.

Referenced by data_ready(), and vl53_init().

Here is the caller graph for this function:

◆ rd16()

static int32_t rd16 ( vl53_t *  d,
uint16_t  reg,
uint16_t *  v 
)
static

Definition at line 59 of file vl53l1x.c.

References b, vl53_t::bus, vl53_bus_t::handle, and vl53_bus_t::read.

Referenced by vl53_init().

Here is the caller graph for this function:

◆ dly()

static void dly ( vl53_t *  d,
uint32_t  ms 
)
static

Definition at line 66 of file vl53l1x.c.

References vl53_t::bus, vl53_bus_t::delay_ms, and ms.

Referenced by vl53_init().

Here is the caller graph for this function:

◆ data_ready()

static int32_t data_ready ( vl53_t *  d,
uint8_t *  rdy 
)
static

Definition at line 68 of file vl53l1x.c.

References vl53_t::int_pol, rd8(), and REG_GPIO_TIO_HV_STATUS.

Referenced by vl53_init(), and vl53_poll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ map_status()

static uint8_t map_status ( uint8_t  s)
static

Definition at line 76 of file vl53l1x.c.

References s.

Referenced by vl53_poll().

Here is the caller graph for this function:

◆ vl53_init()

int32_t vl53_init ( vl53_t *  d,
const vl53_bus_t *  bus,
uint16_t  budget_ms 
)

0 = sensor found and ranging; < 0 = absent or error (the board works without it)

Definition at line 86 of file vl53l1x.c.

References b, vl53_t::bus, data_ready(), dly(), vl53_bus_t::handle, vl53_t::int_pol, k_default, vl53_t::ok, rd16(), rd8(), REG_FIRMWARE_SYSTEM_STATUS, REG_GPIO_HV_MUX_CTRL, REG_INTERMEASUREMENT, REG_INTERRUPT_CLEAR, REG_MODE_START, REG_MODEL_ID, REG_OSC_CALIBRATE_VAL, REG_PHASECAL_TIMEOUT, REG_RANGE_TIMEOUT_A_HI, REG_RANGE_TIMEOUT_B_HI, REG_RANGE_VALID_PHASE_HIGH, REG_RANGE_VCSEL_PERIOD_A, REG_RANGE_VCSEL_PERIOD_B, REG_SD_INITIAL_PHASE_SD0, REG_SD_WOI_SD0, REG_VHV_START, REG_VHV_TIMEOUT_LOOP_BOUND, st(), VL53L1X_MODEL_ID, wr16(), wr32(), wr8(), and vl53_bus_t::write.

Referenced by ext_step().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vl53_poll()

int32_t vl53_poll ( vl53_t *  d,
vl53_sample_t *  s 
)

1 = new sample in *s, 0 = none yet, < 0 = bus error

Definition at line 137 of file vl53l1x.c.

References vl53_t::bus, data_ready(), vl53_bus_t::handle, map_status(), vl53_t::ok, vl53_bus_t::read, REG_INTERRUPT_CLEAR, REG_RESULT_RANGE_STATUS, s, and wr8().

Referenced by ext_step().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ k_default

const uint8_t k_default[0x87 - 0x2D+1]
static
Initial value:
= {
0x00, 0x01, 0x01, 0x01, 0x02, 0x00, 0x02, 0x08, 0x00, 0x08, 0x10, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0xff, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0b, 0x00, 0x00, 0x02, 0x0a, 0x21,
0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x38, 0xff, 0x01, 0x00, 0x08, 0x00,
0x00, 0x01, 0xdb, 0x0f, 0x01, 0xf1, 0x0d, 0x01, 0x68, 0x00, 0x80, 0x08, 0xb8, 0x00, 0x00, 0x00,
0x00, 0x0f, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0f, 0x0d, 0x0e, 0x0e, 0x00,
0x00, 0x02, 0xc7, 0xff, 0x9B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00
}

Definition at line 38 of file vl53l1x.c.

Referenced by vl53_init().