Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
lidar_vl53l5cx.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 Fabien-B <name.surname@gmail.com>
3 *
4 * This file is part of paparazzi
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
27#include "mcu_periph/i2c.h"
28#include "ch.h"
31#include "modules/core/abi.h"
33#include "ch.h"
34#include "hal.h"
35#include "mcu_periph/ram_arch.h"
36
37#ifndef LIDAR_VL53L5CX_I2C_ADDR
38#define LIDAR_VL53L5CX_I2C_ADDR 0x29
39#endif
40
41#define SUBTYPE_DISTANCE 0
42
45
47static void thd_lidar_vl53l5cx(void *arg);
48
49
51 "VL53L5CX_NO_ERROR",
52 "VL53L5CX_NOT_DETECTED",
53 "VL53L5CX_ULD_LOADING_FAILED",
54 "VL53L5CX_SET_RESOLUTION_FAILED",
55 "VL53L5CX_RUNTIME_ERROR",
56};
57
58
60{
61 vl53l5cx_dev.platform.i2cdev = &LIDAR_VL53L5CX_I2C_DEV;
62 vl53l5cx_dev.platform.address = LIDAR_VL53L5CX_I2C_ADDR;
63 vl53l5cx_dev.platform.user_data = NULL;
64 vl53l5cx_dev.platform.error_code = VL53L5CX_NO_ERROR;
65
66 // Create thread
69}
70
72{
73
74 if (vl53l5cx_dev.platform.user_data != NULL) {
75 thread_t* thread_handle = (thread_t*) vl53l5cx_dev.platform.user_data;
76 // check thread status
77 if (thread_handle->state == CH_STATE_FINAL) {
78 vl53l5cx_dev.platform.error_code = (enum VL53L5CX_ERRORS) chThdWait(thread_handle);
79 vl53l5cx_dev.platform.user_data = NULL;
80 }
81 } else {
82
83 // thread exited, send error code periodically
84 size_t len = strlen(VL53L5CX_ERROR_MSGS[vl53l5cx_dev.platform.error_code]);
85 // send exitcode to telemetry
87 VL53L5CX_ERROR_MSGS[vl53l5cx_dev.platform.error_code]));
88 ;
89 }
90
91
92 if (vl53l5cx_dev.platform.data_available) {
95 8, 8, sizeof(vl53l5cx_dev.platform.distances_mm[0]), SUBTYPE_DISTANCE,
96 (uint8_t *)vl53l5cx_dev.platform.distances_mm);
97
98 vl53l5cx_dev.platform.data_available = false;
99 }
100
101
102}
103
104
105
106static void thd_lidar_vl53l5cx(void *arg)
107{
108 chRegSetThreadName("vl53l5cx");
110
112
113
115
117 if (!isAlive || status) {
119 }
120
122 if (status) {
124 }
125
127 if (status) {
129 }
130
132
133 while (true) {
135 if (isReady) {
137 if (status == 0) {
138 memcpy(dev->platform.distances_mm, vl53l5cx_results.distance_mm, 64 * sizeof(vl53l5cx_results.distance_mm[0]));
139 dev->platform.data_available = true;
140 }
141 }
142
144 }
145
146
147}
148
Main include for ABI (AirBorneInterface).
#define LIDAR_DATA_VL53L5CX_ID
static uint8_t status
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
#define LIDAR_VL53L5CX_I2C_ADDR
static void thd_lidar_vl53l5cx(void *arg)
#define SUBTYPE_DISTANCE
void lidar_vl53l5cx_init(void)
char * VL53L5CX_ERROR_MSGS[]
void lidar_vl53l5cx_periodic(void)
static THD_WORKING_AREA(wa_thd_lidar_vl53l5cx, 1024)
uint16_t foo
Definition main_demo5.c:58
Specific RAM section for DMA usage on F7.
#define IN_DMA_SECTION(var)
Definition ram_arch.h:87
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
uint8_t vl53l5cx_is_alive(VL53L5CX_Configuration *p_dev, uint8_t *p_is_alive)
uint8_t vl53l5cx_get_ranging_data(VL53L5CX_Configuration *p_dev, VL53L5CX_ResultsData *p_results)
This function gets the ranging data, using the selected output and the resolution.
uint8_t vl53l5cx_init(VL53L5CX_Configuration *p_dev)
Mandatory function used to initialize the sensor.
uint8_t vl53l5cx_start_ranging(VL53L5CX_Configuration *p_dev)
This function starts a ranging session.
uint8_t vl53l5cx_check_data_ready(VL53L5CX_Configuration *p_dev, uint8_t *p_isReady)
This function checks if a new data is ready by polling I2C.
uint8_t vl53l5cx_set_resolution(VL53L5CX_Configuration *p_dev, uint8_t resolution)
This function sets a new resolution (4x4 or 8x8).
#define VL53L5CX_RESOLUTION_4X4
Macro VL53L5CX_RESOLUTION_4X4 or VL53L5CX_RESOLUTION_8X8 allows setting sensor in 4x4 mode or 8x8 mod...
Structure VL53L5CX_Configuration contains the sensor configuration.
Structure VL53L5CX_ResultsData contains the ranging results of VL53L5CX.
VL53L5CX_ERRORS
@ VL53L5CX_SET_RESOLUTION_FAILED
@ VL53L5CX_NOT_DETECTED
@ VL53L5CX_NO_ERROR
@ VL53L5CX_ULD_LOADING_FAILED