Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/i2s/i2s_ll_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ static void i2s_stm32_isr(void *arg)
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
struct stream *stream = &dev_data->rx;

LOG_ERR("%s: err=%d", __func__, LL_I2S_ReadReg(cfg->i2s, SR));
LOG_ERR("%s: err=%d", __func__, (int)LL_I2S_ReadReg(cfg->i2s, SR));
stream->state = I2S_STATE_ERROR;

/* OVR error must be explicitly cleared */
Expand Down
1 change: 1 addition & 0 deletions drivers/sensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ add_subdirectory_ifdef(CONFIG_TH02 th02)
add_subdirectory_ifdef(CONFIG_TMP007 tmp007)
add_subdirectory_ifdef(CONFIG_TMP112 tmp112)
add_subdirectory_ifdef(CONFIG_VL53L0X vl53l0x)
add_subdirectory_ifdef(CONFIG_VL53L1X vl53l1x)

zephyr_sources_ifdef(CONFIG_USERSPACE sensor_handlers.c)
2 changes: 2 additions & 0 deletions drivers/sensor/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,6 @@ source "drivers/sensor/tmp112/Kconfig"

source "drivers/sensor/vl53l0x/Kconfig"

source "drivers/sensor/vl53l1x/Kconfig"

endif # SENSOR
10 changes: 10 additions & 0 deletions drivers/sensor/vl53l1x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_library()

zephyr_library_sources(
vl53l1x.c
vl53l1_platform.c
)

zephyr_library_sources_ifdef(CONFIG_VL53L1X_TRIGGER vl53l1x_trigger.c)
81 changes: 81 additions & 0 deletions drivers/sensor/vl53l1x/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#
# Copyright (c) 2019 Aaron Tsui <[email protected]>
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess here you may want to add a new copyright (2019).

Anyway, I was thinking whether we ca re-use same driver structure for both VL53L0X and VL53L1X. They seem
similar.

# SPDX-License-Identifier: Apache-2.0
#

menuconfig VL53L1X
bool "VL53L1X time of flight sensor"
depends on I2C && HAS_DTS_I2C
select HAS_STLIB
help
Enable driver for VL53L1X I2C-based time of flight sensor.

if VL53L1X

choice VL53L1X_TRIGGER_MODE
prompt "Trigger mode"
default VL53L1X_TRIGGER_NONE
help
Specify the type of triggering to be used by the driver.

config VL53L1X_TRIGGER_NONE
bool "No trigger"

config VL53L1X_TRIGGER_GLOBAL_THREAD
bool "Use global thread"
depends on GPIO
select VL53L1X_TRIGGER

config VL53L1X_TRIGGER_OWN_THREAD
bool "Use own thread"
depends on GPIO
select VL53L1X_TRIGGER

endchoice # VL53L1X_TRIGGER_MODE

config VL53L1X_TRIGGER
bool

config VL53L1X_THREAD_PRIORITY
int "Thread priority"
depends on VL53L1X_TRIGGER_OWN_THREAD
default 10
help
Priority of thread used by the driver to handle interrupts.

config VL53L1X_THREAD_STACK_SIZE
int "Thread stack size"
depends on VL53L1X_TRIGGER_OWN_THREAD
default 1024
help
Stack size of thread used by the driver to handle interrupts.

config VL53L1X_XSHUT_CONTROL_ENABLE
bool "Enable XSHUT pin control"
help
Enable it if XSHUT pin is controlled by host.

config VL53L1X_XSHUT_GPIO_DEV_NAME
string "GPIO device"
default "GPIOC"
depends on VL53L1X_XSHUT_CONTROL_ENABLE
help
The device name of the GPIO device to which the VL53L1X xshut pin
is connected.

config VL53L1X_XSHUT_GPIO_PIN_NUM
int "Interrupt GPIO pin number"
default 6
depends on VL53L1X_XSHUT_CONTROL_ENABLE
help
The number of the GPIO on which the xshut signal from the VL53L1X
is connected.

config VL53L1X_PROXIMITY_THRESHOLD
int "Proximity threshold in millimeters"
default 100
help
Threshold used for proximity detection when sensor is used with SENSOR_CHAN_PROX.

endif # VL53L1X
242 changes: 242 additions & 0 deletions drivers/sensor/vl53l1x/vl53l1_platform.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
/*
* Copyright (c) 2019 Aaron Tsui <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/


#include "vl53l1_platform.h"

#include <sensor.h>
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <i2c.h>
#include <logging/log.h>

#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
LOG_MODULE_DECLARE(VL53L1X);

VL53L1_Error VL53L1_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata,
uint32_t count)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I was saying before do you think it is possible to re-use same routine for both VL53L1 and VL53L0?
Maybe using ifdef for the difference.

VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t status_int = 0;
uint8_t buf[count + 2];

buf[0] = index >> 8;
buf[1] = index & 0xFF;
memcpy(&buf[2], pdata, count);

status_int = i2c_write(Dev->i2c, buf, count + 2, Dev->I2cDevAddr);

if (status_int < 0) {
Status = VL53L1_ERROR_CONTROL_INTERFACE;
LOG_ERR("Failed to write");
}

return Status;
}

VL53L1_Error VL53L1_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata,
uint32_t count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.
What is the difference with VL53L0?
index is on 16-bit instead of 8-bit?

Copy link
Contributor Author

@overheat overheat Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the VL53L1 index is on 16-bit instead of 8-bit

I have thought about re-use same driver but looks the internal implication is different between vl53l1x and vl53l0x, as you already have seen the "index"(register address) length is not the same. Also, those API related to interrupt and threshold and so on. So there should be lots of ifdef, if we want to merge those drivers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have thought about re-use same driver but looks the internal implication is different between vl53l1x and vl53l0x, as you already have seen the "index"(register address) length is not the same. Also, those API related to interrupt and threshold and so on. So there should be lots of ifdef, if we want to merge those drivers together.

Yes, yes. In fact my initial idea was to re-use same driver, but the more I was going deep thru the review the less I found it applicable. So at the end I left it as a comment from your side.

{
VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t status_int;
u8_t buf[2];

buf[0] = index >> 8;
buf[1] = index & 0xFF;

status_int =
i2c_write_read(Dev->i2c, Dev->I2cDevAddr, buf, 2, pdata, count);
if (status_int < 0) {
LOG_ERR("Failed to read");
return -EIO;
}

return Status;
}

VL53L1_Error VL53L1_WrByte(VL53L1_DEV Dev, uint16_t index, uint8_t data)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t status_int;
u8_t buf[3];

buf[0] = index >> 8;
buf[1] = index & 0xFF;
buf[2] = data;

status_int = i2c_write(Dev->i2c, buf, 3, Dev->I2cDevAddr);

if (status_int < 0) {
Status = VL53L1_ERROR_CONTROL_INTERFACE;
LOG_ERR("i2c_reg_write_byte failed (%d)", Status);
}

return Status;
}

VL53L1_Error VL53L1_WrWord(VL53L1_DEV Dev, uint16_t index, uint16_t data)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t status_int;
uint8_t buf[4];

buf[0] = index >> 8;
buf[1] = index & 0x00FF;
buf[2] = data >> 8;
buf[3] = data & 0x00FF;

status_int = i2c_write(Dev->i2c, buf, 4, Dev->I2cDevAddr);
if (status_int < 0) {
Status = VL53L1_ERROR_CONTROL_INTERFACE;
LOG_ERR("i2c_write failed (%d)", Status);
}

return Status;
}

VL53L1_Error VL53L1_WrDWord(VL53L1_DEV Dev, uint16_t index, uint32_t data)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t status_int;
uint8_t buf[6];

buf[0] = index >> 8;
buf[1] = index & 0x00FF;
buf[2] = (data >> 24) & 0xFF;
buf[3] = (data >> 16) & 0xFF;
buf[4] = (data >> 8) & 0xFF;
buf[5] = (data >> 0) & 0xFF;

status_int = i2c_write(Dev->i2c, buf, 6, Dev->I2cDevAddr);
if (status_int < 0) {
Status = VL53L1_ERROR_CONTROL_INTERFACE;
LOG_ERR("i2c_write failed (%d)", Status);
}

return Status;
}

VL53L1_Error VL53L1_UpdateByte(VL53L1_DEV Dev, uint16_t index, uint8_t AndData,
uint8_t OrData)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t status_int;
uint8_t deviceAddress;
uint8_t data;

deviceAddress = Dev->I2cDevAddr;

status_int = VL53L1_RdByte(Dev, index, &data);
if (status_int < 0) {
Status = VL53L1_ERROR_CONTROL_INTERFACE;
LOG_ERR("VL53L1_RdByte failed (%d)", Status);
}

if (Status == VL53L1_ERROR_NONE) {
data = (data & AndData) | OrData;
status_int = VL53L1_WrByte(Dev, index, data);
if (status_int != 0) {
Status = VL53L1_ERROR_CONTROL_INTERFACE;
LOG_DBG("VL53L1_WrByte failed.(%d)", Status);
}
}

return Status;
}

VL53L1_Error VL53L1_RdByte(VL53L1_DEV Dev, uint16_t index, uint8_t *data)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t status_int;
uint8_t buf[2];

buf[0] = index >> 8;
buf[1] = index & 0xFF;

status_int = i2c_write_read(Dev->i2c, Dev->I2cDevAddr, buf, 2, buf, 1);
if (status_int < 0) {
Status = VL53L1_ERROR_CONTROL_INTERFACE;
LOG_ERR("i2c_reg_read_byte failed (%d)", Status);
}
*data = buf[0];

return Status;
}

VL53L1_Error VL53L1_RdWord(VL53L1_DEV Dev, uint16_t index, uint16_t *data)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t status_int;
uint8_t buf[2];

buf[0] = index >> 8;
buf[1] = index & 0xFF;

status_int = i2c_write_read(Dev->i2c, Dev->I2cDevAddr, buf, 2, buf, 2);
if (status_int < 0) {
LOG_ERR("i2c_write_read failed");
return -EIO;
}
*data = ((uint16_t)buf[0] << 8) + (uint16_t)buf[1];

return Status;
}

VL53L1_Error VL53L1_RdDWord(VL53L1_DEV Dev, uint16_t index, uint32_t *data)
{
VL53L1_Error Status = VL53L1_ERROR_NONE;
int32_t status_int;
u8_t buf[4];

buf[0] = index >> 8;
buf[1] = index & 0xFF;

status_int = i2c_write_read(Dev->i2c, Dev->I2cDevAddr, buf, 2, buf, 4);
if (status_int < 0) {
LOG_ERR("i2c_write_read failed");
return -EIO;
}
*data = ((uint32_t)buf[0] << 24) + ((uint32_t)buf[1] << 16) +
((uint32_t)buf[2] << 8) + (uint32_t)buf[3];

return Status;
}

VL53L1_Error VL53L1_GetTickCount(uint32_t *ptick_count_ms)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
*ptick_count_ms = k_cycle_get_32();
return status;
}

VL53L1_Error VL53L1_GetTimerFrequency(int32_t *ptimer_freq_hz)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
return status;
}

VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
k_sleep(wait_ms);
return status;
}

VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
k_busy_wait(wait_us);
return status;
}

VL53L1_Error VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms,
uint16_t index, uint8_t value, uint8_t mask,
uint32_t poll_delay_ms)
{
VL53L1_Error status = VL53L1_ERROR_NONE;
return status;
}
Loading