VL53L5CX: Sideload firmware from user-supplied .bin

pull/360/head
Phil Howard 2022-05-17 12:24:50 +01:00
rodzic 872adb6d52
commit aeceefea59
9 zmienionych plików z 23 dodań i 12 usunięć

Wyświetl plik

@ -84,6 +84,7 @@ typedef struct
/* Example for most standard platform : I2C address of sensor */
uint16_t address;
i2c_inst_t *i2c;
uint8_t *firmware;
} VL53L5CX_Platform;

@ -1 +1 @@
Subproject commit 834fa4e53119b987ae9357afc9dfacc6ef8261f8
Subproject commit 80de451b3c50ef998e8a4a745e9fe8ef29314650

Wyświetl plik

@ -33,11 +33,12 @@ namespace pimoroni {
// 7-bit version of the default address (0x52)
static const uint8_t DEFAULT_ADDRESS = VL53L5CX_DEFAULT_I2C_ADDRESS >> 1;
VL53L5CX(I2C *i2c, uint8_t i2c_addr=DEFAULT_ADDRESS) {
VL53L5CX(I2C *i2c, uint8_t *firmware, uint8_t i2c_addr=DEFAULT_ADDRESS) {
configuration = new VL53L5CX_Configuration{
.platform = VL53L5CX_Platform{
.address = i2c_addr,
.i2c = i2c->get_i2c()
.i2c = i2c->get_i2c(),
.firmware = firmware
},
};
motion_configuration = new VL53L5CX_Motion_Configuration{};

Wyświetl plik

@ -1,14 +1,15 @@
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "drivers/vl53l5cx/vl53l5cx.hpp"
#include "vl53l5cx.hpp"
#include "src/vl53l5cx_firmware.h"
#include "common/pimoroni_i2c.hpp"
using namespace pimoroni;
I2C i2c(4, 5);
VL53L5CX vl53l5cx(&i2c);
VL53L5CX vl53l5cx(&i2c, (uint8_t *)&vl53l5cx_firmware_bin);
int main() {
stdio_init_all();

Wyświetl plik

@ -11,7 +11,7 @@ i2c = pimoroni_i2c.PimoroniI2C(**PINS_BREAKOUT_GARDEN, baudrate=2_000_000)
print("Starting up sensor...")
t_sta = time.ticks_ms()
sensor = breakout_vl53l5cx.VL53L5CX(i2c)
sensor = breakout_vl53l5cx.VL53L5CX(i2c, firmware=open("vl53l5cx_firmware.bin").read())
t_end = time.ticks_ms()
print("Done in {}ms...".format(t_end - t_sta))

Wyświetl plik

@ -12,7 +12,7 @@ i2c = pimoroni_i2c.PimoroniI2C(**PINS_BREAKOUT_GARDEN, baudrate=2_000_000)
print("Starting up sensor...")
t_sta = time.ticks_ms()
sensor = breakout_vl53l5cx.VL53L5CX(i2c)
sensor = breakout_vl53l5cx.VL53L5CX(i2c, firmware=open("vl53l5cx_firmware.bin").read())
t_end = time.ticks_ms()
print("Done in {}ms...".format(t_end - t_sta))

Wyświetl plik

@ -24,7 +24,7 @@ i2c = pimoroni_i2c.PimoroniI2C(**PINS_BREAKOUT_GARDEN, baudrate=2_000_000)
print("Starting up sensor...")
t_sta = time.ticks_ms()
sensor = breakout_vl53l5cx.VL53L5CX(i2c)
sensor = breakout_vl53l5cx.VL53L5CX(i2c, firmware=open("vl53l5cx_firmware.bin").read())
t_end = time.ticks_ms()
print("Done in {}ms...".format(t_end - t_sta))

Wyświetl plik

@ -61,11 +61,13 @@ mp_obj_t VL53L5CX_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw
enum {
ARG_i2c,
ARG_addr
ARG_addr,
ARG_firmware,
};
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
{ MP_QSTR_addr, MP_ARG_INT, {.u_int = pimoroni::VL53L5CX::DEFAULT_ADDRESS} }
{ MP_QSTR_addr, MP_ARG_INT, {.u_int = pimoroni::VL53L5CX::DEFAULT_ADDRESS} },
{ MP_QSTR_firmware, MP_ARG_OBJ | MP_ARG_REQUIRED }
};
// Parse args.
@ -77,13 +79,19 @@ mp_obj_t VL53L5CX_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw
return mp_const_none;
}
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[ARG_firmware].u_obj, &bufinfo, MP_BUFFER_READ);
if(bufinfo.len != (size_t)(84 * 1024)) { // firmware blob is always 84K
mp_raise_ValueError("Supplied firmware should be 84k bytes!");
}
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
int addr = args[ARG_addr].u_int;
self = m_new_obj_with_finaliser(_VL53L5CX_obj_t);
self->base.type = &VL53L5CX_type;
self->i2c = i2c;
self->breakout = new pimoroni::VL53L5CX(i2c->i2c, addr);
self->breakout = new pimoroni::VL53L5CX(i2c->i2c, (uint8_t *)bufinfo.buf, addr);
if(!self->breakout->init()) {
mp_raise_msg(&mp_type_RuntimeError, "VL53L5CX: error initialising");

Wyświetl plik

@ -29,7 +29,7 @@ include(breakout_bme280/micropython)
include(breakout_bmp280/micropython)
include(breakout_icp10125/micropython)
include(breakout_scd41/micropython)
# include(breakout_vl53l5cx/micropython)
include(breakout_vl53l5cx/micropython)
include(pico_scroll/micropython)
include(pico_rgb_keypad/micropython)