mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-09 22:49:53 +08:00
@@ -248,6 +248,15 @@
|
||||
<field name="vel_sp" type="struct FloatVect3 *" unit="m/s"/>
|
||||
</message>
|
||||
|
||||
<message name="LIDAR_DATA" id="37">
|
||||
<field name="stamp" type="uint32_t" unit="us"/>
|
||||
<field name="numRows" type="uint32_t">number of rows of the matrix</field>
|
||||
<field name="numCols" type="uint32_t">number of columns of the matrix</field>
|
||||
<field name="size" type="uint16_t">size of a matrix element</field>
|
||||
<field name="subtype" type="uint8_t">subtype of data, driver dependent (e.g. distance, reflectance, ...)</field>
|
||||
<field name="data" type="uint8_t*">pointer to the data of the matrix</field>
|
||||
</message>
|
||||
|
||||
</msg_class>
|
||||
|
||||
</protocol>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
<module name="lidar_vl53l5cx" dir="lidar" task="sensors">
|
||||
<doc>
|
||||
<description>
|
||||
VL53L5CX multizone range sensor.
|
||||
Sends LIDAR_DATA Abi messages.
|
||||
</description>
|
||||
<configure name="LIDAR_VL53L5CX_I2C_DEV" value="i2c2" description="I2C device to use for the VL53L5CX sensor"/>
|
||||
<define name="LIDAR_VL53L5CX_I2C_ADDR" value="0x52" description="I2C address"/>
|
||||
</doc>
|
||||
<dep>
|
||||
<depends>i2c</depends>
|
||||
</dep>
|
||||
<header>
|
||||
<file name="lidar_vl53l5cx.h"/>
|
||||
</header>
|
||||
<init fun="lidar_vl53l5cx_init()"/>
|
||||
<periodic fun="lidar_vl53l5cx_periodic()" freq="5.0"/>
|
||||
<makefile>
|
||||
<configure name="LIDAR_VL53L5CX_I2C_DEV" default="i2c2" case="lower|upper"/>
|
||||
<define name="LIDAR_VL53L5CX_I2C_DEV" value="$(LIDAR_VL53L5CX_I2C_DEV_LOWER)"/>
|
||||
<define name="USE_$(LIDAR_VL53L5CX_I2C_DEV_UPPER)"/>
|
||||
|
||||
<file_arch name="lidar_vl53l5cx.c"/>
|
||||
<file name="vl53l5cx_api.c" dir="peripherals"/>
|
||||
<file_arch name="vl53l5cx_platform.c"/>
|
||||
<test arch="chibios"/>
|
||||
</makefile>
|
||||
</module>
|
||||
@@ -123,6 +123,8 @@ static void handle_i2c_thd(struct i2c_periph *p)
|
||||
// wait for a transaction to be pushed in the queue
|
||||
chSemWait(&i->sem);
|
||||
|
||||
i2cAcquireBus((I2CDriver *)p->reg_addr);
|
||||
|
||||
if (p->trans_insert_idx == p->trans_extract_idx) {
|
||||
p->status = I2CIdle;
|
||||
// no transaction pending
|
||||
@@ -231,6 +233,8 @@ static void handle_i2c_thd(struct i2c_periph *p)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
i2cReleaseBus((I2CDriver *)p->reg_addr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Fabien-B <name.surname@gmail.com>
|
||||
*
|
||||
* This file is part of paparazzi
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file "modules/lidar/lidar_vl53l5cx.c"
|
||||
* @author Fabien-B <name.surname@gmail.com>
|
||||
* VL53L5CX multizone range sensor.
|
||||
*/
|
||||
|
||||
#include "modules/lidar/lidar_vl53l5cx.h"
|
||||
#include "mcu_periph/i2c.h"
|
||||
#include "ch.h"
|
||||
#include "lidar/vl53l5cx_platform.h"
|
||||
#include "peripherals/vl53l5cx_api.h"
|
||||
#include "modules/core/abi.h"
|
||||
#include "modules/datalink/downlink.h"
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include "mcu_periph/ram_arch.h"
|
||||
|
||||
#ifndef LIDAR_VL53L5CX_I2C_ADDR
|
||||
#define LIDAR_VL53L5CX_I2C_ADDR 0x29
|
||||
#endif
|
||||
|
||||
#define SUBTYPE_DISTANCE 0
|
||||
|
||||
static IN_DMA_SECTION(VL53L5CX_Configuration vl53l5cx_dev);
|
||||
static IN_DMA_SECTION(VL53L5CX_ResultsData vl53l5cx_results);
|
||||
|
||||
static THD_WORKING_AREA(wa_thd_lidar_vl53l5cx, 1024);
|
||||
static void thd_lidar_vl53l5cx(void *arg);
|
||||
|
||||
|
||||
char *VL53L5CX_ERROR_MSGS[] = {
|
||||
"VL53L5CX_NO_ERROR",
|
||||
"VL53L5CX_NOT_DETECTED",
|
||||
"VL53L5CX_ULD_LOADING_FAILED",
|
||||
"VL53L5CX_SET_RESOLUTION_FAILED",
|
||||
"VL53L5CX_RUNTIME_ERROR",
|
||||
};
|
||||
|
||||
|
||||
void lidar_vl53l5cx_init(void)
|
||||
{
|
||||
vl53l5cx_dev.platform.i2cdev = &LIDAR_VL53L5CX_I2C_DEV;
|
||||
vl53l5cx_dev.platform.address = LIDAR_VL53L5CX_I2C_ADDR;
|
||||
vl53l5cx_dev.platform.user_data = NULL;
|
||||
vl53l5cx_dev.platform.error_code = VL53L5CX_NO_ERROR;
|
||||
|
||||
// Create thread
|
||||
vl53l5cx_dev.platform.user_data = chThdCreateStatic(wa_thd_lidar_vl53l5cx, sizeof(wa_thd_lidar_vl53l5cx),
|
||||
NORMALPRIO, thd_lidar_vl53l5cx, (void *)&vl53l5cx_dev);
|
||||
}
|
||||
|
||||
void lidar_vl53l5cx_periodic(void)
|
||||
{
|
||||
|
||||
if (vl53l5cx_dev.platform.user_data != NULL) {
|
||||
thread_t* thread_handle = (thread_t*) vl53l5cx_dev.platform.user_data;
|
||||
// check thread status
|
||||
if (thread_handle->state == CH_STATE_FINAL) {
|
||||
vl53l5cx_dev.platform.error_code = (enum VL53L5CX_ERRORS) chThdWait(thread_handle);
|
||||
vl53l5cx_dev.platform.user_data = NULL;
|
||||
}
|
||||
} else {
|
||||
|
||||
// thread exited, send error code periodically
|
||||
size_t len = strlen(VL53L5CX_ERROR_MSGS[vl53l5cx_dev.platform.error_code]);
|
||||
// send exitcode to telemetry
|
||||
RunOnceEvery(10, DOWNLINK_SEND_INFO_MSG(DefaultChannel, DefaultDevice, len,
|
||||
VL53L5CX_ERROR_MSGS[vl53l5cx_dev.platform.error_code]));
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
if (vl53l5cx_dev.platform.data_available) {
|
||||
uint32_t now_ts = get_sys_time_usec();
|
||||
AbiSendMsgLIDAR_DATA(LIDAR_DATA_VL53L5CX_ID, now_ts,
|
||||
8, 8, sizeof(vl53l5cx_dev.platform.distances_mm[0]), SUBTYPE_DISTANCE,
|
||||
(uint8_t *)vl53l5cx_dev.platform.distances_mm);
|
||||
|
||||
vl53l5cx_dev.platform.data_available = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void thd_lidar_vl53l5cx(void *arg)
|
||||
{
|
||||
chRegSetThreadName("vl53l5cx");
|
||||
VL53L5CX_Configuration *dev = (VL53L5CX_Configuration *) arg;
|
||||
|
||||
uint8_t status, isAlive, isReady;
|
||||
|
||||
|
||||
chThdSleepMilliseconds(2000);
|
||||
|
||||
status = vl53l5cx_is_alive(dev, &isAlive);
|
||||
if (!isAlive || status) {
|
||||
chThdExit(VL53L5CX_NOT_DETECTED);
|
||||
}
|
||||
|
||||
status = vl53l5cx_init(dev);
|
||||
if (status) {
|
||||
chThdExit(VL53L5CX_ULD_LOADING_FAILED);
|
||||
}
|
||||
|
||||
status = vl53l5cx_set_resolution(dev, VL53L5CX_RESOLUTION_4X4);
|
||||
if (status) {
|
||||
chThdExit(VL53L5CX_SET_RESOLUTION_FAILED);
|
||||
}
|
||||
|
||||
status = vl53l5cx_start_ranging(dev);
|
||||
|
||||
while (true) {
|
||||
status = vl53l5cx_check_data_ready(dev, &isReady);
|
||||
if (isReady) {
|
||||
status = vl53l5cx_get_ranging_data(dev, &vl53l5cx_results);
|
||||
if (status == 0) {
|
||||
memcpy(dev->platform.distances_mm, vl53l5cx_results.distance_mm, 64 * sizeof(vl53l5cx_results.distance_mm[0]));
|
||||
dev->platform.data_available = true;
|
||||
}
|
||||
}
|
||||
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Fabien-B <name.surname@gmail.com>
|
||||
*
|
||||
* This file is part of paparazzi
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file "modules/lidar/lidar_vl53l5cx.h"
|
||||
* @author Fabien-B <name.surname@gmail.com>
|
||||
* VL53L5CX multizone range sensor.
|
||||
*/
|
||||
|
||||
#ifndef LIDAR_VL53L5CX_H
|
||||
#define LIDAR_VL53L5CX_H
|
||||
|
||||
#include "stdint.h"
|
||||
#include "peripherals/vl53l5cx_api.h"
|
||||
|
||||
extern void lidar_vl53l5cx_init(void);
|
||||
extern void lidar_vl53l5cx_periodic(void);
|
||||
|
||||
#endif // LIDAR_VL53L5CX_H
|
||||
@@ -0,0 +1,118 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2024 Fabien-B <name.surname@gmail.com>
|
||||
*
|
||||
* This file is part of paparazzi
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include "lidar/vl53l5cx_platform.h"
|
||||
#include "hal.h"
|
||||
|
||||
#define VL53L5_I2C_TIMEOUT chTimeMS2I(100)
|
||||
|
||||
|
||||
uint8_t RdByte(
|
||||
VL53L5CX_Platform *dev,
|
||||
uint16_t index,
|
||||
uint8_t *p_data)
|
||||
{
|
||||
return RdMulti(dev, index, p_data, 1);
|
||||
}
|
||||
|
||||
uint8_t WrByte(
|
||||
VL53L5CX_Platform *dev,
|
||||
uint16_t index,
|
||||
uint8_t data)
|
||||
{
|
||||
return WrMulti(dev, index, &data, 1);
|
||||
}
|
||||
|
||||
uint8_t WrMulti(
|
||||
VL53L5CX_Platform *dev,
|
||||
uint16_t index,
|
||||
uint8_t *pdata,
|
||||
uint32_t count)
|
||||
{
|
||||
I2CDriver * i2cd = (I2CDriver *)dev->i2cdev->reg_addr;
|
||||
|
||||
i2cAcquireBus(i2cd);
|
||||
|
||||
msg_t ret;
|
||||
|
||||
for(size_t offset = 0; offset<count; offset += VL53L5CX_I2C_BUF_SIZE) {
|
||||
uint16_t reg_addr = index + offset;
|
||||
dev->buf[0] = (reg_addr & 0xFF00) >> 8; // MSB first
|
||||
dev->buf[1] = (reg_addr & 0x00FF);
|
||||
size_t size = Min(count-offset, VL53L5CX_I2C_BUF_SIZE);
|
||||
memcpy((uint8_t *) dev->buf + 2, (pdata + offset), size);
|
||||
cacheBufferFlush(dev->buf, size+2);
|
||||
ret = i2cMasterTransmitTimeout(i2cd, dev->address, dev->buf, size+2, NULL, 0, VL53L5_I2C_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
i2cReleaseBus(i2cd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t RdMulti(
|
||||
VL53L5CX_Platform *dev,
|
||||
uint16_t index,
|
||||
uint8_t *pdata,
|
||||
uint32_t count)
|
||||
{
|
||||
I2CDriver * i2cd = (I2CDriver *)dev->i2cdev->reg_addr;
|
||||
|
||||
i2cAcquireBus(i2cd);
|
||||
|
||||
msg_t ret = 0;
|
||||
for(size_t offset = 0; offset<count; offset += VL53L5CX_I2C_BUF_SIZE) {
|
||||
uint16_t reg_addr = index + offset;
|
||||
dev->buf[0] = (reg_addr & 0xFF00) >> 8; // MSB first
|
||||
dev->buf[1] = (reg_addr & 0x00FF);
|
||||
size_t size = Min(count-offset, VL53L5CX_I2C_BUF_SIZE);
|
||||
|
||||
cacheBufferFlush(dev->buf, 2);
|
||||
ret = i2cMasterTransmitTimeout(i2cd, dev->address, dev->buf, 2, dev->buf, size, VL53L5_I2C_TIMEOUT);
|
||||
cacheBufferInvalidate(dev->buf, count);
|
||||
memcpy(pdata+offset, dev->buf, count);
|
||||
}
|
||||
|
||||
i2cReleaseBus(i2cd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SwapBuffer(
|
||||
uint8_t *buffer,
|
||||
uint16_t size)
|
||||
{
|
||||
uint32_t i, tmp;
|
||||
|
||||
/* Example of possible implementation using <string.h> */
|
||||
for(i = 0; i < size; i = i + 4)
|
||||
{
|
||||
tmp = (
|
||||
buffer[i]<<24)
|
||||
|(buffer[i+1]<<16)
|
||||
|(buffer[i+2]<<8)
|
||||
|(buffer[i+3]);
|
||||
|
||||
memcpy(&(buffer[i]), &tmp, 4);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t WaitMs(
|
||||
VL53L5CX_Platform *p_platform,
|
||||
uint32_t TimeMs)
|
||||
{
|
||||
(void)p_platform;
|
||||
chThdSleepMilliseconds(TimeMs);
|
||||
return 0;
|
||||
}
|
||||
@@ -88,8 +88,8 @@
|
||||
#define AUX_B2 7U
|
||||
#define AUX_B3 8U
|
||||
#define AUX_B4 9U
|
||||
#define I2C2_SCL_EXTERNAL 10U
|
||||
#define I2C2_SDA_EXTERNAL 11U
|
||||
#define I2C2_SCL 10U
|
||||
#define I2C2_SDA 11U
|
||||
#define SPI2_EXTERNAL_CS 12U
|
||||
#define PB13 13U
|
||||
#define SPI2_EXTERNAL_MISO 14U
|
||||
@@ -275,8 +275,8 @@
|
||||
#define LINE_AUX_B2 PAL_LINE(GPIOB, 7U)
|
||||
#define LINE_AUX_B3 PAL_LINE(GPIOB, 8U)
|
||||
#define LINE_AUX_B4 PAL_LINE(GPIOB, 9U)
|
||||
#define LINE_I2C2_SCL_EXTERNAL PAL_LINE(GPIOB, 10U)
|
||||
#define LINE_I2C2_SDA_EXTERNAL PAL_LINE(GPIOB, 11U)
|
||||
#define LINE_I2C2_SCL PAL_LINE(GPIOB, 10U)
|
||||
#define LINE_I2C2_SDA PAL_LINE(GPIOB, 11U)
|
||||
#define LINE_SPI2_EXTERNAL_CS PAL_LINE(GPIOB, 12U)
|
||||
#define LINE_SPI2_EXTERNAL_MISO PAL_LINE(GPIOB, 14U)
|
||||
#define LINE_SPI2_EXTERNAL_MOSI PAL_LINE(GPIOB, 15U)
|
||||
@@ -450,8 +450,8 @@
|
||||
PIN_MODE_ALTERNATE(AUX_B2) | \
|
||||
PIN_MODE_ALTERNATE(AUX_B3) | \
|
||||
PIN_MODE_ALTERNATE(AUX_B4) | \
|
||||
PIN_MODE_ALTERNATE(I2C2_SCL_EXTERNAL) | \
|
||||
PIN_MODE_ALTERNATE(I2C2_SDA_EXTERNAL) | \
|
||||
PIN_MODE_ALTERNATE(I2C2_SCL) | \
|
||||
PIN_MODE_ALTERNATE(I2C2_SDA) | \
|
||||
PIN_MODE_OUTPUT(SPI2_EXTERNAL_CS) | \
|
||||
PIN_MODE_INPUT(PB13) | \
|
||||
PIN_MODE_ALTERNATE(SPI2_EXTERNAL_MISO) | \
|
||||
@@ -467,8 +467,8 @@
|
||||
PIN_OTYPE_PUSHPULL(AUX_B2) | \
|
||||
PIN_OTYPE_PUSHPULL(AUX_B3) | \
|
||||
PIN_OTYPE_PUSHPULL(AUX_B4) | \
|
||||
PIN_OTYPE_OPENDRAIN(I2C2_SCL_EXTERNAL) | \
|
||||
PIN_OTYPE_OPENDRAIN(I2C2_SDA_EXTERNAL) | \
|
||||
PIN_OTYPE_OPENDRAIN(I2C2_SCL) | \
|
||||
PIN_OTYPE_OPENDRAIN(I2C2_SDA) | \
|
||||
PIN_OTYPE_PUSHPULL(SPI2_EXTERNAL_CS) | \
|
||||
PIN_OTYPE_PUSHPULL(PB13) | \
|
||||
PIN_OTYPE_PUSHPULL(SPI2_EXTERNAL_MISO) | \
|
||||
@@ -484,8 +484,8 @@
|
||||
PIN_OSPEED_SPEED_HIGH(AUX_B2) | \
|
||||
PIN_OSPEED_SPEED_HIGH(AUX_B3) | \
|
||||
PIN_OSPEED_SPEED_HIGH(AUX_B4) | \
|
||||
PIN_OSPEED_SPEED_HIGH(I2C2_SCL_EXTERNAL) | \
|
||||
PIN_OSPEED_SPEED_HIGH(I2C2_SDA_EXTERNAL) | \
|
||||
PIN_OSPEED_SPEED_HIGH(I2C2_SCL) | \
|
||||
PIN_OSPEED_SPEED_HIGH(I2C2_SDA) | \
|
||||
PIN_OSPEED_SPEED_HIGH(SPI2_EXTERNAL_CS) | \
|
||||
PIN_OSPEED_SPEED_VERYLOW(PB13) | \
|
||||
PIN_OSPEED_SPEED_HIGH(SPI2_EXTERNAL_MISO) | \
|
||||
@@ -501,8 +501,8 @@
|
||||
PIN_PUPDR_FLOATING(AUX_B2) | \
|
||||
PIN_PUPDR_FLOATING(AUX_B3) | \
|
||||
PIN_PUPDR_FLOATING(AUX_B4) | \
|
||||
PIN_PUPDR_PULLUP(I2C2_SCL_EXTERNAL) | \
|
||||
PIN_PUPDR_PULLUP(I2C2_SDA_EXTERNAL) | \
|
||||
PIN_PUPDR_PULLUP(I2C2_SCL) | \
|
||||
PIN_PUPDR_PULLUP(I2C2_SDA) | \
|
||||
PIN_PUPDR_FLOATING(SPI2_EXTERNAL_CS) | \
|
||||
PIN_PUPDR_PULLDOWN(PB13) | \
|
||||
PIN_PUPDR_FLOATING(SPI2_EXTERNAL_MISO) | \
|
||||
@@ -518,8 +518,8 @@
|
||||
PIN_ODR_LEVEL_LOW(AUX_B2) | \
|
||||
PIN_ODR_LEVEL_LOW(AUX_B3) | \
|
||||
PIN_ODR_LEVEL_LOW(AUX_B4) | \
|
||||
PIN_ODR_LEVEL_HIGH(I2C2_SCL_EXTERNAL) | \
|
||||
PIN_ODR_LEVEL_HIGH(I2C2_SDA_EXTERNAL) | \
|
||||
PIN_ODR_LEVEL_HIGH(I2C2_SCL) | \
|
||||
PIN_ODR_LEVEL_HIGH(I2C2_SDA) | \
|
||||
PIN_ODR_LEVEL_HIGH(SPI2_EXTERNAL_CS) | \
|
||||
PIN_ODR_LEVEL_LOW(PB13) | \
|
||||
PIN_ODR_LEVEL_HIGH(SPI2_EXTERNAL_MISO) | \
|
||||
@@ -536,8 +536,8 @@
|
||||
|
||||
#define VAL_GPIOB_AFRH (PIN_AFIO_AF(AUX_B3, 2) | \
|
||||
PIN_AFIO_AF(AUX_B4, 2) | \
|
||||
PIN_AFIO_AF(I2C2_SCL_EXTERNAL, 4) | \
|
||||
PIN_AFIO_AF(I2C2_SDA_EXTERNAL, 4) | \
|
||||
PIN_AFIO_AF(I2C2_SCL, 4) | \
|
||||
PIN_AFIO_AF(I2C2_SDA, 4) | \
|
||||
PIN_AFIO_AF(SPI2_EXTERNAL_CS, 0) | \
|
||||
PIN_AFIO_AF(PB13, 0) | \
|
||||
PIN_AFIO_AF(SPI2_EXTERNAL_MISO, 5) | \
|
||||
@@ -1506,10 +1506,10 @@
|
||||
#define AF_LINE_AUX_B3 2U
|
||||
#define AF_AUX_B4 2U
|
||||
#define AF_LINE_AUX_B4 2U
|
||||
#define AF_I2C2_SCL_EXTERNAL 4U
|
||||
#define AF_LINE_I2C2_SCL_EXTERNAL 4U
|
||||
#define AF_I2C2_SDA_EXTERNAL 4U
|
||||
#define AF_LINE_I2C2_SDA_EXTERNAL 4U
|
||||
#define AF_I2C2_SCL 4U
|
||||
#define AF_LINE_I2C2_SCL 4U
|
||||
#define AF_I2C2_SDA 4U
|
||||
#define AF_LINE_I2C2_SDA 4U
|
||||
#define AF_SPI2_EXTERNAL_MISO 5U
|
||||
#define AF_LINE_SPI2_EXTERNAL_MISO 5U
|
||||
#define AF_SPI2_EXTERNAL_MOSI 5U
|
||||
|
||||
@@ -109,8 +109,8 @@ PB06 AUX_B1 PWM AF:TIM4_CH1
|
||||
PB07 AUX_B2 PWM AF:TIM4_CH2
|
||||
PB08 AUX_B3 PWM AF:TIM4_CH3
|
||||
PB09 AUX_B4 PWM AF:TIM4_CH4
|
||||
PB10 I2C2_SCL_EXTERNAL I2C AF:I2C2_SCL
|
||||
PB11 I2C2_SDA_EXTERNAL I2C AF:I2C2_SDA
|
||||
PB10 I2C2_SCL I2C AF:I2C2_SCL # External
|
||||
PB11 I2C2_SDA I2C AF:I2C2_SDA # External
|
||||
PB12 SPI2_EXTERNAL_CS OUTPUT PUSHPULL SPEED_HIGH FLOATING LEVEL_HIGH
|
||||
PB14 SPI2_EXTERNAL_MISO SPI AF:SPI2_MISO
|
||||
PB15 SPI2_EXTERNAL_MOSI SPI AF:SPI2_MOSI
|
||||
|
||||
@@ -636,4 +636,13 @@
|
||||
#define VEL_SP_FCR_ID 1 // Approach Moving Target
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* IDs of LIDAR_DATA senders
|
||||
*/
|
||||
#ifndef LIDAR_DATA_VL53L5CX_ID
|
||||
#define LIDAR_DATA_VL53L5CX_ID 1
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* ABI_SENDER_IDS_H */
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Fabien-B <name.surname@gmail.com>
|
||||
*
|
||||
* This file is part of paparazzi
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#define _PLATFORM_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "mcu_periph/i2c.h"
|
||||
|
||||
#define VL53L5CX_I2C_BUF_SIZE 512
|
||||
|
||||
|
||||
enum VL53L5CX_ERRORS {
|
||||
VL53L5CX_NO_ERROR = 0,
|
||||
VL53L5CX_NOT_DETECTED = 1,
|
||||
VL53L5CX_ULD_LOADING_FAILED = 2,
|
||||
VL53L5CX_SET_RESOLUTION_FAILED = 3,
|
||||
VL53L5CX_RUNTIME_FAILURE = 4,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Structure VL53L5CX_Platform needs to be filled by the customer,
|
||||
* depending on his platform. At least, it contains the VL53L5CX I2C address.
|
||||
* Some additional fields can be added, as descriptors, or platform
|
||||
* dependencies. Anything added into this structure is visible into the platform
|
||||
* layer.
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* To be filled with customer's platform. At least an I2C address/descriptor
|
||||
* needs to be added */
|
||||
/* Example for most standard platform : I2C address of sensor */
|
||||
uint16_t address;
|
||||
//I2CDriver* i2cp;
|
||||
struct i2c_periph *i2cdev;
|
||||
bool data_available;
|
||||
int16_t distances_mm[64];
|
||||
|
||||
enum VL53L5CX_ERRORS error_code;
|
||||
uint8_t buf[VL53L5CX_I2C_BUF_SIZE+2];
|
||||
void* user_data;
|
||||
|
||||
} VL53L5CX_Platform;
|
||||
|
||||
/*
|
||||
* @brief The macro below is used to define the number of target per zone sent
|
||||
* through I2C. This value can be changed by user, in order to tune I2C
|
||||
* transaction, and also the total memory size (a lower number of target per
|
||||
* zone means a lower RAM). The value must be between 1 and 4.
|
||||
*/
|
||||
|
||||
#define VL53L5CX_NB_TARGET_PER_ZONE 1U
|
||||
|
||||
/*
|
||||
* @brief The macro below can be used to avoid data conversion into the driver.
|
||||
* By default there is a conversion between firmware and user data. Using this macro
|
||||
* allows to use the firmware format instead of user format. The firmware format allows
|
||||
* an increased precision.
|
||||
*/
|
||||
|
||||
// #define VL53L5CX_USE_RAW_FORMAT
|
||||
|
||||
/*
|
||||
* @brief All macro below are used to configure the sensor output. User can
|
||||
* define some macros if he wants to disable selected output, in order to reduce
|
||||
* I2C access.
|
||||
*/
|
||||
|
||||
// #define VL53L5CX_DISABLE_AMBIENT_PER_SPAD
|
||||
// #define VL53L5CX_DISABLE_NB_SPADS_ENABLED
|
||||
// #define VL53L5CX_DISABLE_NB_TARGET_DETECTED
|
||||
// #define VL53L5CX_DISABLE_SIGNAL_PER_SPAD
|
||||
// #define VL53L5CX_DISABLE_RANGE_SIGMA_MM
|
||||
// #define VL53L5CX_DISABLE_DISTANCE_MM
|
||||
// #define VL53L5CX_DISABLE_REFLECTANCE_PERCENT
|
||||
// #define VL53L5CX_DISABLE_TARGET_STATUS
|
||||
// #define VL53L5CX_DISABLE_MOTION_INDICATOR
|
||||
|
||||
/**
|
||||
* @param (VL53L5CX_Platform*) p_platform : Pointer of VL53L5CX platform
|
||||
* structure.
|
||||
* @param (uint16_t) Address : I2C location of value to read.
|
||||
* @param (uint8_t) *p_values : Pointer of value to read.
|
||||
* @return (uint8_t) status : 0 if OK
|
||||
*/
|
||||
|
||||
uint8_t RdByte(
|
||||
VL53L5CX_Platform *p_platform,
|
||||
uint16_t RegisterAdress,
|
||||
uint8_t *p_value);
|
||||
|
||||
/**
|
||||
* @brief Mandatory function used to write one single byte.
|
||||
* @param (VL53L5CX_Platform*) p_platform : Pointer of VL53L5CX platform
|
||||
* structure.
|
||||
* @param (uint16_t) Address : I2C location of value to read.
|
||||
* @param (uint8_t) value : Pointer of value to write.
|
||||
* @return (uint8_t) status : 0 if OK
|
||||
*/
|
||||
|
||||
uint8_t WrByte(
|
||||
VL53L5CX_Platform *p_platform,
|
||||
uint16_t RegisterAdress,
|
||||
uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Mandatory function used to read multiples bytes.
|
||||
* @param (VL53L5CX_Platform*) p_platform : Pointer of VL53L5CX platform
|
||||
* structure.
|
||||
* @param (uint16_t) Address : I2C location of values to read.
|
||||
* @param (uint8_t) *p_values : Buffer of bytes to read.
|
||||
* @param (uint32_t) size : Size of *p_values buffer.
|
||||
* @return (uint8_t) status : 0 if OK
|
||||
*/
|
||||
|
||||
uint8_t RdMulti(
|
||||
VL53L5CX_Platform *p_platform,
|
||||
uint16_t RegisterAdress,
|
||||
uint8_t *p_values,
|
||||
uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Mandatory function used to write multiples bytes.
|
||||
* @param (VL53L5CX_Platform*) p_platform : Pointer of VL53L5CX platform
|
||||
* structure.
|
||||
* @param (uint16_t) Address : I2C location of values to write.
|
||||
* @param (uint8_t) *p_values : Buffer of bytes to write.
|
||||
* @param (uint32_t) size : Size of *p_values buffer.
|
||||
* @return (uint8_t) status : 0 if OK
|
||||
*/
|
||||
|
||||
uint8_t WrMulti(
|
||||
VL53L5CX_Platform *p_platform,
|
||||
uint16_t RegisterAdress,
|
||||
uint8_t *p_values,
|
||||
uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Optional function, only used to perform an hardware reset of the
|
||||
* sensor. This function is not used in the API, but it can be used by the host.
|
||||
* This function is not mandatory to fill if user don't want to reset the
|
||||
* sensor.
|
||||
* @param (VL53L5CX_Platform*) p_platform : Pointer of VL53L5CX platform
|
||||
* structure.
|
||||
* @return (uint8_t) status : 0 if OK
|
||||
*/
|
||||
|
||||
// uint8_t Reset_Sensor(
|
||||
// VL53L5CX_Platform *p_platform);
|
||||
|
||||
/**
|
||||
* @brief Mandatory function, used to swap a buffer. The buffer size is always a
|
||||
* multiple of 4 (4, 8, 12, 16, ...).
|
||||
* @param (uint8_t*) buffer : Buffer to swap, generally uint32_t
|
||||
* @param (uint16_t) size : Buffer size to swap
|
||||
*/
|
||||
|
||||
void SwapBuffer(
|
||||
uint8_t *buffer,
|
||||
uint16_t size);
|
||||
/**
|
||||
* @brief Mandatory function, used to wait during an amount of time. It must be
|
||||
* filled as it's used into the API.
|
||||
* @param (VL53L5CX_Platform*) p_platform : Pointer of VL53L5CX platform
|
||||
* structure.
|
||||
* @param (uint32_t) TimeMs : Time to wait in ms.
|
||||
* @return (uint8_t) status : 0 if wait is finished.
|
||||
*/
|
||||
|
||||
uint8_t WaitMs(
|
||||
VL53L5CX_Platform *p_platform,
|
||||
uint32_t TimeMs);
|
||||
|
||||
#endif // _PLATFORM_H_
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user