mirror of
https://github.com/whowechina/chu_pico.git
synced 2025-02-17 18:49:18 +01:00
VL53L0x driver integrated but not fully tested
This commit is contained in:
parent
0be51af6b3
commit
78519325ce
Binary file not shown.
@ -4,7 +4,7 @@ set(LWIP_ROOT ${PICO_SDK_PATH}/lib/lwip)
|
||||
function(make_firmware board board_def)
|
||||
pico_sdk_init()
|
||||
add_executable(${board}
|
||||
main.c slider.c air.c rgb.c save.c config.c cmd.c lzfx.c usb_descriptors.c)
|
||||
main.c slider.c air.c rgb.c save.c config.c cmd.c lzfx.c vl53l0x.c usb_descriptors.c)
|
||||
target_compile_definitions(${board} PUBLIC ${board_def})
|
||||
pico_enable_stdio_usb(${board} 1)
|
||||
pico_enable_stdio_uart(${board} 0)
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gp2y0e.h"
|
||||
#include "vl53l0x.h"
|
||||
#include "i2c_hub.h"
|
||||
|
||||
static const uint8_t TOF_LIST[] = TOF_MUX_LIST;
|
||||
@ -31,12 +32,18 @@ void air_init()
|
||||
gpio_pull_up(I2C_SCL);
|
||||
|
||||
i2c_hub_init();
|
||||
vl53l0x_init(I2C_PORT, 0);
|
||||
|
||||
for (int i = 0; i < sizeof(TOF_LIST); i++) {
|
||||
i2c_select(I2C_PORT, 1 << TOF_LIST[i]);
|
||||
#if defined(TOF_VL53L0X)
|
||||
vl53l0x_init_tof(true);
|
||||
vl53l0x_start_continuous(0);
|
||||
#elif defined(TOF_GP2Y0E03)
|
||||
gp2y0e_write(I2C_PORT, 0xa8, 0); // Accumulation 0:1, 1:5, 2:30, 3:10
|
||||
gp2y0e_write(I2C_PORT, 0x3f, 0x30); // Filter 0x00:7, 0x10:5, 0x20:9, 0x30:1
|
||||
gp2y0e_write(I2C_PORT, 0x13, 5); // Pulse [3..7]:[40, 80, 160, 240, 320] us
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +102,11 @@ void air_update()
|
||||
{
|
||||
for (int i = 0; i < sizeof(TOF_LIST); i++) {
|
||||
i2c_select(I2C_PORT, 1 << TOF_LIST[i]);
|
||||
#if defined(TOF_VL53L0X)
|
||||
distances[i] = readRangeContinuousMillimeters() * 10;
|
||||
#elif defined(TOF_GP2Y0E03)
|
||||
distances[i] = gp2y0e_dist16(I2C_PORT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
#define I2C_HUB_EN 19
|
||||
|
||||
//#define TOF_GP2Y0E03
|
||||
#define TOF_VL53L0X
|
||||
#define TOF_MUX_LIST { 1, 2, 0, 4, 5 }
|
||||
|
||||
#define RGB_PIN 2
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,9 +7,153 @@
|
||||
#define VL53L0X_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int tofGetModel(int *model, int *revision);
|
||||
int vl53l0x_distance();
|
||||
int vl53l0x_init();
|
||||
#include "hardware/i2c.h"
|
||||
|
||||
// register addresses from API vl53l0x_device.h (ordered as listed there)
|
||||
enum regAddr
|
||||
{
|
||||
SYSRANGE_START = 0x00,
|
||||
|
||||
SYSTEM_THRESH_HIGH = 0x0C,
|
||||
SYSTEM_THRESH_LOW = 0x0E,
|
||||
|
||||
SYSTEM_SEQUENCE_CONFIG = 0x01,
|
||||
SYSTEM_RANGE_CONFIG = 0x09,
|
||||
SYSTEM_INTERMEASUREMENT_PERIOD = 0x04,
|
||||
|
||||
SYSTEM_INTERRUPT_CONFIG_GPIO = 0x0A,
|
||||
|
||||
GPIO_HV_MUX_ACTIVE_HIGH = 0x84,
|
||||
|
||||
SYSTEM_INTERRUPT_CLEAR = 0x0B,
|
||||
|
||||
RESULT_INTERRUPT_STATUS = 0x13,
|
||||
RESULT_RANGE_STATUS = 0x14,
|
||||
|
||||
RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN = 0xBC,
|
||||
RESULT_CORE_RANGING_TOTAL_EVENTS_RTN = 0xC0,
|
||||
RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF = 0xD0,
|
||||
RESULT_CORE_RANGING_TOTAL_EVENTS_REF = 0xD4,
|
||||
RESULT_PEAK_SIGNAL_RATE_REF = 0xB6,
|
||||
|
||||
ALGO_PART_TO_PART_RANGE_OFFSET_MM = 0x28,
|
||||
|
||||
I2C_SLAVE_DEVICE_ADDRESS = 0x8A,
|
||||
|
||||
MSRC_CONFIG_CONTROL = 0x60,
|
||||
|
||||
PRE_RANGE_CONFIG_MIN_SNR = 0x27,
|
||||
PRE_RANGE_CONFIG_VALID_PHASE_LOW = 0x56,
|
||||
PRE_RANGE_CONFIG_VALID_PHASE_HIGH = 0x57,
|
||||
PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT = 0x64,
|
||||
|
||||
FINAL_RANGE_CONFIG_MIN_SNR = 0x67,
|
||||
FINAL_RANGE_CONFIG_VALID_PHASE_LOW = 0x47,
|
||||
FINAL_RANGE_CONFIG_VALID_PHASE_HIGH = 0x48,
|
||||
FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT = 0x44,
|
||||
|
||||
PRE_RANGE_CONFIG_SIGMA_THRESH_HI = 0x61,
|
||||
PRE_RANGE_CONFIG_SIGMA_THRESH_LO = 0x62,
|
||||
|
||||
PRE_RANGE_CONFIG_VCSEL_PERIOD = 0x50,
|
||||
PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI = 0x51,
|
||||
PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO = 0x52,
|
||||
|
||||
SYSTEM_HISTOGRAM_BIN = 0x81,
|
||||
HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT = 0x33,
|
||||
HISTOGRAM_CONFIG_READOUT_CTRL = 0x55,
|
||||
|
||||
FINAL_RANGE_CONFIG_VCSEL_PERIOD = 0x70,
|
||||
FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI = 0x71,
|
||||
FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO = 0x72,
|
||||
CROSSTALK_COMPENSATION_PEAK_RATE_MCPS = 0x20,
|
||||
|
||||
MSRC_CONFIG_TIMEOUT_MACROP = 0x46,
|
||||
|
||||
SOFT_RESET_GO2_SOFT_RESET_N = 0xBF,
|
||||
IDENTIFICATION_MODEL_ID = 0xC0,
|
||||
IDENTIFICATION_REVISION_ID = 0xC2,
|
||||
|
||||
OSC_CALIBRATE_VAL = 0xF8,
|
||||
|
||||
GLOBAL_CONFIG_VCSEL_WIDTH = 0x32,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_0 = 0xB0,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_1 = 0xB1,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_2 = 0xB2,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_3 = 0xB3,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_4 = 0xB4,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_5 = 0xB5,
|
||||
|
||||
GLOBAL_CONFIG_REF_EN_START_SELECT = 0xB6,
|
||||
DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD = 0x4E,
|
||||
DYNAMIC_SPAD_REF_EN_START_OFFSET = 0x4F,
|
||||
POWER_MANAGEMENT_GO1_POWER_FORCE = 0x80,
|
||||
|
||||
VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV = 0x89,
|
||||
|
||||
ALGO_PHASECAL_LIM = 0x30,
|
||||
ALGO_PHASECAL_CONFIG_TIMEOUT = 0x30,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
VcselPeriodPreRange, VcselPeriodFinalRange
|
||||
} vcselPeriodType;
|
||||
|
||||
void vl53l0x_init(i2c_inst_t *i2c_port, uint8_t i2c_addr);
|
||||
|
||||
bool vl53l0x_init_tof(bool io_2v8);
|
||||
|
||||
void write_reg(uint8_t reg, uint8_t value);
|
||||
void write_reg16(uint8_t reg, uint16_t value);
|
||||
void write_reg32(uint8_t reg, uint32_t value);
|
||||
uint8_t read_reg(uint8_t reg);
|
||||
uint16_t read_reg16(uint8_t reg);
|
||||
uint32_t read_reg32(uint8_t reg);
|
||||
|
||||
void write_many(uint8_t reg, uint8_t const * src, uint8_t count);
|
||||
void read_many(uint8_t reg, uint8_t * dst, uint8_t count);
|
||||
|
||||
bool setSignalRateLimit(float limit_Mcps);
|
||||
float getSignalRateLimit();
|
||||
|
||||
bool setMeasurementTimingBudget(uint32_t budget_us);
|
||||
uint32_t getMeasurementTimingBudget();
|
||||
|
||||
bool setVcselPulsePeriod(vcselPeriodType type, uint8_t period_pclks);
|
||||
uint8_t getVcselPulsePeriod(vcselPeriodType type);
|
||||
|
||||
void startContinuous(uint32_t period_ms);
|
||||
void stopContinuous();
|
||||
uint16_t readRangeContinuousMillimeters();
|
||||
uint16_t readRangeSingleMillimeters();
|
||||
|
||||
// TCC: Target CentreCheck
|
||||
// MSRC: Minimum Signal Rate Check
|
||||
// DSS: Dynamic Spad Selection
|
||||
|
||||
typedef struct {
|
||||
bool tcc, msrc, dss, pre_range, final_range;
|
||||
} SequenceStepEnables;
|
||||
|
||||
typedef struct {
|
||||
uint16_t pre_range_vcsel_period_pclks, final_range_vcsel_period_pclks;
|
||||
|
||||
uint16_t msrc_dss_tcc_mclks, pre_range_mclks, final_range_mclks;
|
||||
uint32_t msrc_dss_tcc_us, pre_range_us, final_range_us;
|
||||
} SequenceStepTimeouts;
|
||||
|
||||
bool getSpadInfo(uint8_t * count, bool * type_is_aperture);
|
||||
|
||||
void getSequenceStepEnables(SequenceStepEnables * enables);
|
||||
void getSequenceStepTimeouts(SequenceStepEnables const * enables, SequenceStepTimeouts * timeouts);
|
||||
|
||||
bool performSingleRefCalibration(uint8_t vhv_init_byte);
|
||||
|
||||
static uint16_t decodeTimeout(uint16_t value);
|
||||
static uint16_t encodeTimeout(uint32_t timeout_mclks);
|
||||
static uint32_t timeoutMclksToMicroseconds(uint16_t timeout_period_mclks, uint8_t vcsel_period_pclks);
|
||||
static uint32_t timeoutMicrosecondsToMclks(uint32_t timeout_period_us, uint8_t vcsel_period_pclks);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user