---vl6180dr
This commit is contained in:
@@ -19,6 +19,10 @@ set(INCLUDE_DIR
|
||||
../loader
|
||||
../Boot/App
|
||||
../ARMCM0_STM32G0
|
||||
vl6180/Target
|
||||
vl6180/App
|
||||
Drivers/BSP/vl6180
|
||||
Drivers/BSP/custom
|
||||
#/////////////////////////////////////////////
|
||||
)
|
||||
|
||||
@@ -67,7 +71,7 @@ set(INCLUDE_DIR
|
||||
add_compile_definitions(BLACKBOX_CACHE=1)
|
||||
|
||||
#//////////////////////////USER SOURCES FILES
|
||||
file( GLOB_RECURSE SOURCES "Core/Src/*.*" "../App/*.*" "../loader/*.*")
|
||||
file( GLOB_RECURSE SOURCES "Core/Src/*.*" "../App/*.*" "../loader/*.*" "Drivers/BSP/*.c" "vl6180/*.c")
|
||||
|
||||
|
||||
#///////////////////END USER SOURCES FILES
|
||||
|
||||
556
main_prog/Drivers/BSP/custom/custom.c
Normal file
556
main_prog/Drivers/BSP/custom/custom.c
Normal file
@@ -0,0 +1,556 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : custom.c
|
||||
* @brief : Source file for the BSP Common driver
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "custom.h"
|
||||
|
||||
/** @defgroup BSP BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM CUSTOM
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL CUSTOM LOW LEVEL
|
||||
* @brief This file provides set of firmware functions to manage Leds and push-button
|
||||
* available on STM32WBxx-Nucleo Kit from STMicroelectronics.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_Private_Defines CUSTOM LOW LEVEL Private Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_FunctionPrototypes CUSTOM LOW LEVEL Private Function Prototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_Private_Variables CUSTOM LOW LEVEL Private Variables
|
||||
* @{
|
||||
*/
|
||||
typedef void (* BSP_LED_GPIO_Init) (void);
|
||||
static GPIO_TypeDef* LED_PORT[LEDn] = {LED2_GPIO_PORT};
|
||||
static const uint16_t LED_PIN[LEDn] = {LED2_PIN};
|
||||
static void LED_USER_GPIO_Init(void);
|
||||
|
||||
USART_TypeDef* COM_USART[COMn] = {COM1_UART};
|
||||
UART_HandleTypeDef hcom_uart[COMn];
|
||||
#if (USE_COM_LOG > 0)
|
||||
static COM_TypeDef COM_ActiveLogPort;
|
||||
#endif
|
||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1U)
|
||||
static uint32_t IslpUart1MspCbValid = 0;
|
||||
#endif
|
||||
__weak HAL_StatusTypeDef MX_LPUART1_UART_Init(UART_HandleTypeDef* huart);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_Private_Functions CUSTOM LOW LEVEL Private Functions
|
||||
* @{
|
||||
*/
|
||||
#if (USE_BSP_COM_FEATURE > 0)
|
||||
static void LPUART1_MspInit(UART_HandleTypeDef *huart);
|
||||
static void LPUART1_MspDeInit(UART_HandleTypeDef *huart);
|
||||
#endif
|
||||
/**
|
||||
* @brief This method returns the STM32WBxx NUCLEO BSP Driver revision
|
||||
* @retval version: 0xXYZR (8bits for each decimal, R for RC)
|
||||
*/
|
||||
int32_t BSP_GetVersion(void)
|
||||
{
|
||||
return (int32_t)__CUSTOM_BSP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures LED on GPIO and/or on MFX.
|
||||
* @param Led: LED to be configured.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED2, LED4, ...
|
||||
* @retval HAL status
|
||||
*/
|
||||
int32_t BSP_LED_Init(Led_TypeDef Led)
|
||||
{
|
||||
static const BSP_LED_GPIO_Init LedGpioInit[LEDn] = {LED_USER_GPIO_Init};
|
||||
LedGpioInit[Led]();
|
||||
return BSP_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInit LEDs.
|
||||
* @param Led: LED to be configured.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED2, LED4, ...
|
||||
* @note Led DeInit does not disable the GPIO clock nor disable the Mfx
|
||||
* @retval HAL status
|
||||
*/
|
||||
int32_t BSP_LED_DeInit(Led_TypeDef Led)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
/* Turn off LED */
|
||||
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
|
||||
/* DeInit the GPIO_LED pin */
|
||||
gpio_init_structure.Pin = LED_PIN[Led];
|
||||
HAL_GPIO_DeInit(LED_PORT[Led], gpio_init_structure.Pin);
|
||||
|
||||
return BSP_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns selected LED On.
|
||||
* @param Led: LED to be set on
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED1
|
||||
* @arg LED2
|
||||
* @arg LED3
|
||||
* @arg LED4
|
||||
* @retval HAL status
|
||||
*/
|
||||
int32_t BSP_LED_On(Led_TypeDef Led)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED_PORT [Led], LED_PIN [Led], GPIO_PIN_SET);
|
||||
|
||||
return BSP_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns selected LED Off.
|
||||
* @param Led: LED to be set off
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED1
|
||||
* @arg LED2
|
||||
* @arg LED3
|
||||
* @arg LED4
|
||||
* @retval HAL status
|
||||
*/
|
||||
int32_t BSP_LED_Off(Led_TypeDef Led)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED_PORT [Led], LED_PIN [Led], GPIO_PIN_RESET);
|
||||
|
||||
return BSP_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the selected LED.
|
||||
* @param Led: LED to be toggled
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED1
|
||||
* @arg LED2
|
||||
* @arg LED3
|
||||
* @arg LED4
|
||||
* @retval HAL status
|
||||
*/
|
||||
int32_t BSP_LED_Toggle(Led_TypeDef Led)
|
||||
{
|
||||
HAL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]);
|
||||
|
||||
return BSP_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the status of the LED.
|
||||
* @param Led: LED for which get the status
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED1
|
||||
* @arg LED2
|
||||
* @arg LED3
|
||||
* @arg LED4
|
||||
* @retval HAL status (1=high, 0=low)
|
||||
*/
|
||||
int32_t BSP_LED_GetState(Led_TypeDef Led)
|
||||
{
|
||||
return (int32_t)(HAL_GPIO_ReadPin (LED_PORT [Led], LED_PIN [Led]) == GPIO_PIN_RESET);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @retval None
|
||||
*/
|
||||
static void LED_USER_GPIO_Init(void) {
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(BUS_BSP_LED_GPIO_PORT, BUS_BSP_LED_GPIO_PIN, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : PTPIN */
|
||||
GPIO_InitStruct.Pin = BUS_BSP_LED_GPIO_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(BUS_BSP_LED_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
#if (USE_BSP_COM_FEATURE > 0)
|
||||
/**
|
||||
* @brief Configures COM port.
|
||||
* @param COM: COM port to be configured.
|
||||
* This parameter can be COM1
|
||||
* @param UART_Init: Pointer to a UART_HandleTypeDef structure that contains the
|
||||
* configuration information for the specified USART peripheral.
|
||||
* @retval BSP error code
|
||||
*/
|
||||
int32_t BSP_COM_Init(COM_TypeDef COM)
|
||||
{
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if(COM > COMn)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
hcom_uart[COM].Instance = COM_USART[COM];
|
||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 0U)
|
||||
/* Init the UART Msp */
|
||||
LPUART1_MspInit(&hcom_uart[COM]);
|
||||
#else
|
||||
if(IslpUart1MspCbValid == 0U)
|
||||
{
|
||||
if(BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE)
|
||||
{
|
||||
return BSP_ERROR_MSP_FAILURE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (MX_LPUART1_UART_Init(&hcom_uart[COM]))
|
||||
{
|
||||
ret = BSP_ERROR_PERIPH_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInit COM port.
|
||||
* @param COM COM port to be configured.
|
||||
* This parameter can be COM1
|
||||
* @retval BSP status
|
||||
*/
|
||||
int32_t BSP_COM_DeInit(COM_TypeDef COM)
|
||||
{
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if(COM > COMn)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* USART configuration */
|
||||
hcom_uart[COM].Instance = COM_USART[COM];
|
||||
|
||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 0U)
|
||||
LPUART1_MspDeInit(&hcom_uart[COM]);
|
||||
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 0U) */
|
||||
|
||||
if(HAL_UART_DeInit(&hcom_uart[COM]) != HAL_OK)
|
||||
{
|
||||
ret = BSP_ERROR_PERIPH_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures COM port.
|
||||
* @param huart USART handle
|
||||
* This parameter can be COM1
|
||||
* @param COM_Init Pointer to a UART_HandleTypeDef structure that contains the
|
||||
* configuration information for the specified USART peripheral.
|
||||
* @retval HAL error code
|
||||
*/
|
||||
|
||||
/* LPUART1 init function */
|
||||
|
||||
__weak HAL_StatusTypeDef MX_LPUART1_UART_Init(UART_HandleTypeDef* hlpuart)
|
||||
{
|
||||
HAL_StatusTypeDef ret = HAL_OK;
|
||||
|
||||
hlpuart->Instance = LPUART1;
|
||||
hlpuart->Init.BaudRate = 209700;
|
||||
hlpuart->Init.WordLength = UART_WORDLENGTH_8B;
|
||||
hlpuart->Init.StopBits = UART_STOPBITS_1;
|
||||
hlpuart->Init.Parity = UART_PARITY_NONE;
|
||||
hlpuart->Init.Mode = UART_MODE_TX_RX;
|
||||
hlpuart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
hlpuart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||
hlpuart->Init.ClockPrescaler = UART_PRESCALER_DIV1;
|
||||
hlpuart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||
hlpuart->FifoMode = UART_FIFOMODE_DISABLE;
|
||||
if (HAL_UART_Init(hlpuart) != HAL_OK)
|
||||
{
|
||||
ret = HAL_ERROR;
|
||||
}
|
||||
|
||||
if (HAL_UARTEx_SetTxFifoThreshold(hlpuart, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
|
||||
{
|
||||
ret = HAL_ERROR;
|
||||
}
|
||||
|
||||
if (HAL_UARTEx_SetRxFifoThreshold(hlpuart, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
|
||||
{
|
||||
ret = HAL_ERROR;
|
||||
}
|
||||
|
||||
if (HAL_UARTEx_DisableFifoMode(hlpuart) != HAL_OK)
|
||||
{
|
||||
ret = HAL_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1U)
|
||||
/**
|
||||
* @brief Register Default LPUART1 Bus Msp Callbacks
|
||||
* @retval BSP status
|
||||
*/
|
||||
int32_t BSP_COM_RegisterDefaultMspCallbacks(COM_TypeDef COM)
|
||||
{
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if(COM >= COMn)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
__HAL_UART_RESET_HANDLE_STATE(&hcom_uart[COM]);
|
||||
|
||||
/* Register default MspInit/MspDeInit Callback */
|
||||
if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPINIT_CB_ID, LPUART1_MspInit) != HAL_OK)
|
||||
{
|
||||
ret = BSP_ERROR_PERIPH_FAILURE;
|
||||
}
|
||||
else if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPDEINIT_CB_ID, LPUART1_MspDeInit) != HAL_OK)
|
||||
{
|
||||
ret = BSP_ERROR_PERIPH_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
IslpUart1MspCbValid = 1U;
|
||||
}
|
||||
}
|
||||
|
||||
/* BSP status */
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register LPUART1 Bus Msp Callback registering
|
||||
* @param Callbacks pointer to LPUART1 MspInit/MspDeInit callback functions
|
||||
* @retval BSP status
|
||||
*/
|
||||
int32_t BSP_COM_RegisterMspCallbacks (COM_TypeDef COM , BSP_COM_Cb_t *Callback)
|
||||
{
|
||||
int32_t ret = BSP_ERROR_NONE;
|
||||
|
||||
if(COM >= COMn)
|
||||
{
|
||||
ret = BSP_ERROR_WRONG_PARAM;
|
||||
}
|
||||
else
|
||||
{
|
||||
__HAL_UART_RESET_HANDLE_STATE(&hcom_uart[COM]);
|
||||
|
||||
/* Register MspInit/MspDeInit Callbacks */
|
||||
if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPINIT_CB_ID, Callback->pMspInitCb) != HAL_OK)
|
||||
{
|
||||
ret = BSP_ERROR_PERIPH_FAILURE;
|
||||
}
|
||||
else if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPDEINIT_CB_ID, Callback->pMspDeInitCb) != HAL_OK)
|
||||
{
|
||||
ret = BSP_ERROR_PERIPH_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
IslpUart1MspCbValid = 1U;
|
||||
}
|
||||
}
|
||||
|
||||
/* BSP status */
|
||||
return ret;
|
||||
}
|
||||
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
|
||||
|
||||
#if (USE_COM_LOG > 0)
|
||||
/**
|
||||
* @brief Select the active COM port.
|
||||
* @param COM COM port to be activated.
|
||||
* This parameter can be COM1
|
||||
* @retval BSP status
|
||||
*/
|
||||
int32_t BSP_COM_SelectLogPort(COM_TypeDef COM)
|
||||
{
|
||||
if(COM_ActiveLogPort != COM)
|
||||
{
|
||||
COM_ActiveLogPort = COM;
|
||||
}
|
||||
return BSP_ERROR_NONE;
|
||||
}
|
||||
|
||||
#if defined(__CC_ARM) /* For arm compiler 5 */
|
||||
#if !defined(__MICROLIB) /* If not Microlib */
|
||||
|
||||
struct __FILE
|
||||
{
|
||||
int dummyVar; //Just for the sake of redefining __FILE, we won't we using it anyways ;)
|
||||
};
|
||||
|
||||
FILE __stdout;
|
||||
|
||||
#endif /* If not Microlib */
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* For arm compiler 6 */
|
||||
#if !defined(__MICROLIB) /* If not Microlib */
|
||||
|
||||
FILE __stdout;
|
||||
|
||||
#endif /* If not Microlib */
|
||||
#endif /* For arm compiler 5 */
|
||||
#if defined(__ICCARM__) /* For IAR */
|
||||
size_t __write(int Handle, const unsigned char *Buf, size_t Bufsize)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0; i<Bufsize; i++)
|
||||
{
|
||||
(void)HAL_UART_Transmit(&hcom_uart[COM_ActiveLogPort], (uint8_t *)&Buf[i], 1, COM_POLL_TIMEOUT);
|
||||
}
|
||||
|
||||
return Bufsize;
|
||||
}
|
||||
#elif defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) /* For ARM Compiler 5 and 6 */
|
||||
int fputc (int ch, FILE *f)
|
||||
{
|
||||
(void)HAL_UART_Transmit(&hcom_uart[COM_ActiveLogPort], (uint8_t *)&ch, 1, COM_POLL_TIMEOUT);
|
||||
return ch;
|
||||
}
|
||||
#else /* For GCC Toolchains */
|
||||
int __io_putchar (int ch)
|
||||
{
|
||||
(void)HAL_UART_Transmit(&hcom_uart[COM_ActiveLogPort], (uint8_t *)&ch, 1, COM_POLL_TIMEOUT);
|
||||
return ch;
|
||||
}
|
||||
#endif /* For IAR */
|
||||
#endif /* USE_COM_LOG */
|
||||
/**
|
||||
* @brief Initializes LPUART1 MSP.
|
||||
* @param huart LPUART1 handle
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
static void LPUART1_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
||||
/* USER CODE BEGIN LPUART1_MspInit 0 */
|
||||
|
||||
/* USER CODE END LPUART1_MspInit 0 */
|
||||
|
||||
/** Initializes the peripherals clock
|
||||
*/
|
||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
|
||||
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
|
||||
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
|
||||
|
||||
/* Enable Peripheral clock */
|
||||
__HAL_RCC_LPUART1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**LPUART1 GPIO Configuration
|
||||
PA2 ------> LPUART1_TX
|
||||
PA3 ------> LPUART1_RX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = BUS_LPUART1_TX_GPIO_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Alternate = BUS_LPUART1_TX_GPIO_AF;
|
||||
HAL_GPIO_Init(BUS_LPUART1_TX_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = BUS_LPUART1_RX_GPIO_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Alternate = BUS_LPUART1_RX_GPIO_AF;
|
||||
HAL_GPIO_Init(BUS_LPUART1_RX_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN LPUART1_MspInit 1 */
|
||||
|
||||
/* USER CODE END LPUART1_MspInit 1 */
|
||||
}
|
||||
|
||||
static void LPUART1_MspDeInit(UART_HandleTypeDef* uartHandle)
|
||||
{
|
||||
/* USER CODE BEGIN LPUART1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END LPUART1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_LPUART1_CLK_DISABLE();
|
||||
|
||||
/**LPUART1 GPIO Configuration
|
||||
PA2 ------> LPUART1_TX
|
||||
PA3 ------> LPUART1_RX
|
||||
*/
|
||||
HAL_GPIO_DeInit(BUS_LPUART1_TX_GPIO_PORT, BUS_LPUART1_TX_GPIO_PIN);
|
||||
|
||||
HAL_GPIO_DeInit(BUS_LPUART1_RX_GPIO_PORT, BUS_LPUART1_RX_GPIO_PIN);
|
||||
|
||||
/* USER CODE BEGIN LPUART1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END LPUART1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
273
main_prog/Drivers/BSP/custom/custom.h
Normal file
273
main_prog/Drivers/BSP/custom/custom.h
Normal file
@@ -0,0 +1,273 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : custom.h
|
||||
* @brief : header file for the BSP Common driver
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __CUSTOM_H
|
||||
#define __CUSTOM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "custom_conf.h"
|
||||
#include "custom_errno.h"
|
||||
#include "main.h"
|
||||
|
||||
#if (USE_BSP_COM_FEATURE > 0)
|
||||
#if (USE_COM_LOG > 0)
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) /* For IAR and ARM Compiler 5 and 6*/
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32L4XX_NUCLEO_LOW_LEVEL_Exported_Constants LOW LEVEL Exported Constants
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief STM32WBXX NUCLEO BSP Driver version number V1.0.0
|
||||
*/
|
||||
#define __CUSTOM_BSP_VERSION_MAIN (uint32_t)(0x01) /*!< [31:24] main version */
|
||||
#define __CUSTOM_BSP_VERSION_SUB1 (uint32_t)(0x00) /*!< [23:16] sub1 version */
|
||||
#define __CUSTOM_BSP_VERSION_SUB2 (uint32_t)(0x00) /*!< [15:8] sub2 version */
|
||||
#define __CUSTOM_BSP_VERSION_RC (uint32_t)(0x00) /*!< [7:0] release candidate */
|
||||
#define __CUSTOM_BSP_VERSION ((__CUSTOM_BSP_VERSION_MAIN << 24)\
|
||||
|(__CUSTOM_BSP_VERSION_SUB1 << 16)\
|
||||
|(__CUSTOM_BSP_VERSION_SUB2 << 8 )\
|
||||
|(__CUSTOM_BSP_VERSION_RC))
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_Exported_Types CUSTOM LOW LEVEL Exported Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Define for CUSTOM board
|
||||
*/
|
||||
#if !defined (USE_CUSTOM)
|
||||
#define USE_CUSTOM
|
||||
#endif
|
||||
#ifndef USE_BSP_COM_FEATURE
|
||||
#define USE_BSP_COM_FEATURE 0U
|
||||
#endif
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_LED CUSTOM LOW LEVEL LED
|
||||
* @{
|
||||
*/
|
||||
/** Define number of LED **/
|
||||
#define LEDn 1U
|
||||
/** Definition for BSP USER LED 2 **/
|
||||
#define LED2_PIN GPIO_PIN_0
|
||||
#define LED2_GPIO_PORT GPIOB
|
||||
#define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
|
||||
#define BUS_GPIO_INSTANCE GPIO
|
||||
#define BUS_BSP_LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define BUS_BSP_LED_GPIO_PORT GPIOB
|
||||
#define BUS_BSP_LED_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#define BUS_BSP_LED_GPIO_PIN GPIO_PIN_0
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_COM CUSTOM LOW LEVEL COM
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Definition for COM portx, connected to LPUART1
|
||||
*/
|
||||
|
||||
#define BUS_LPUART1_INSTANCE LPUART1
|
||||
#define BUS_LPUART1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define BUS_LPUART1_TX_GPIO_AF GPIO_AF8_LPUART1
|
||||
#define BUS_LPUART1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define BUS_LPUART1_TX_GPIO_PIN GPIO_PIN_2
|
||||
#define BUS_LPUART1_TX_GPIO_PORT GPIOA
|
||||
#define BUS_LPUART1_RX_GPIO_AF GPIO_AF8_LPUART1
|
||||
#define BUS_LPUART1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define BUS_LPUART1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define BUS_LPUART1_RX_GPIO_PIN GPIO_PIN_3
|
||||
#define BUS_LPUART1_RX_GPIO_PORT GPIOA
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_Exported_Types LOW LEVEL Exported Types
|
||||
* @{
|
||||
*/
|
||||
#ifndef USE_BSP_COM
|
||||
#define USE_BSP_COM 0U
|
||||
#endif
|
||||
|
||||
#ifndef USE_COM_LOG
|
||||
#define USE_COM_LOG 1U
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LED2 = 0,
|
||||
LED_GREEN = LED2,
|
||||
}Led_TypeDef;
|
||||
|
||||
#if (USE_BSP_COM_FEATURE > 0)
|
||||
typedef enum
|
||||
{
|
||||
COM1 = 0U,
|
||||
COMn
|
||||
}COM_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COM_WORDLENGTH_8B = UART_WORDLENGTH_8B,
|
||||
COM_WORDLENGTH_9B = UART_WORDLENGTH_9B,
|
||||
}COM_WordLengthTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COM_STOPBITS_1 = UART_STOPBITS_1,
|
||||
COM_STOPBITS_2 = UART_STOPBITS_2,
|
||||
}COM_StopBitsTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COM_PARITY_NONE = UART_PARITY_NONE,
|
||||
COM_PARITY_EVEN = UART_PARITY_EVEN,
|
||||
COM_PARITY_ODD = UART_PARITY_ODD,
|
||||
}COM_ParityTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COM_HWCONTROL_NONE = UART_HWCONTROL_NONE,
|
||||
COM_HWCONTROL_RTS = UART_HWCONTROL_RTS,
|
||||
COM_HWCONTROL_CTS = UART_HWCONTROL_CTS,
|
||||
COM_HWCONTROL_RTS_CTS = UART_HWCONTROL_RTS_CTS,
|
||||
}COM_HwFlowCtlTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t BaudRate;
|
||||
COM_WordLengthTypeDef WordLength;
|
||||
COM_StopBitsTypeDef StopBits;
|
||||
COM_ParityTypeDef Parity;
|
||||
COM_HwFlowCtlTypeDef HwFlowCtl;
|
||||
}COM_InitTypeDef;
|
||||
#endif
|
||||
|
||||
#define MX_UART_InitTypeDef COM_InitTypeDef
|
||||
#define MX_UART_StopBitsTypeDef COM_StopBitsTypeDef
|
||||
#define MX_UART_ParityTypeDef COM_ParityTypeDef
|
||||
#define MX_UART_HwFlowCtlTypeDef COM_HwFlowCtlTypeDef
|
||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1U)
|
||||
typedef struct
|
||||
{
|
||||
void (* pMspInitCb)(UART_HandleTypeDef *);
|
||||
void (* pMspDeInitCb)(UART_HandleTypeDef *);
|
||||
} BSP_COM_Cb_t;
|
||||
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 1U) */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#define COMn 1U
|
||||
#define COM1_UART LPUART1
|
||||
|
||||
#define COM_POLL_TIMEOUT 1000
|
||||
extern UART_HandleTypeDef hcom_uart[COMn];
|
||||
#define hlpuart1 hcom_uart[COM1]
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_Exported_Variables LOW LEVEL Exported Constants
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_Exported_Functions CUSTOM LOW LEVEL Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
int32_t BSP_GetVersion(void);
|
||||
int32_t BSP_LED_Init(Led_TypeDef Led);
|
||||
int32_t BSP_LED_DeInit(Led_TypeDef Led);
|
||||
int32_t BSP_LED_On(Led_TypeDef Led);
|
||||
int32_t BSP_LED_Off(Led_TypeDef Led);
|
||||
int32_t BSP_LED_Toggle(Led_TypeDef Led);
|
||||
int32_t BSP_LED_GetState(Led_TypeDef Led);
|
||||
#if (USE_BSP_COM_FEATURE > 0)
|
||||
int32_t BSP_COM_Init(COM_TypeDef COM);
|
||||
int32_t BSP_COM_DeInit(COM_TypeDef COM);
|
||||
#endif
|
||||
|
||||
#if (USE_COM_LOG > 0)
|
||||
int32_t BSP_COM_SelectLogPort(COM_TypeDef COM);
|
||||
#endif
|
||||
|
||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1U)
|
||||
int32_t BSP_COM_RegisterDefaultMspCallbacks(COM_TypeDef COM);
|
||||
int32_t BSP_COM_RegisterMspCallbacks(COM_TypeDef COM , BSP_COM_Cb_t *Callback);
|
||||
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUSTOM__H */
|
||||
|
||||
58
main_prog/Drivers/BSP/custom/custom_errno.h
Normal file
58
main_prog/Drivers/BSP/custom/custom_errno.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : custom_errno.h
|
||||
* @brief : Error Code
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef CUSTOM_ERRNO_H
|
||||
#define CUSTOM_ERRNO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* BSP Common Error codes */
|
||||
#define BSP_ERROR_NONE 0
|
||||
#define BSP_ERROR_NO_INIT -1
|
||||
#define BSP_ERROR_WRONG_PARAM -2
|
||||
#define BSP_ERROR_BUSY -3
|
||||
#define BSP_ERROR_PERIPH_FAILURE -4
|
||||
#define BSP_ERROR_COMPONENT_FAILURE -5
|
||||
#define BSP_ERROR_UNKNOWN_FAILURE -6
|
||||
#define BSP_ERROR_UNKNOWN_COMPONENT -7
|
||||
#define BSP_ERROR_BUS_FAILURE -8
|
||||
#define BSP_ERROR_CLOCK_FAILURE -9
|
||||
#define BSP_ERROR_MSP_FAILURE -10
|
||||
#define BSP_ERROR_FEATURE_NOT_SUPPORTED -11
|
||||
|
||||
/* BSP BUS error codes */
|
||||
|
||||
#define BSP_ERROR_BUS_TRANSACTION_FAILURE -100
|
||||
#define BSP_ERROR_BUS_ARBITRATION_LOSS -101
|
||||
#define BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE -102
|
||||
#define BSP_ERROR_BUS_PROTOCOL_FAILURE -103
|
||||
|
||||
#define BSP_ERROR_BUS_MODE_FAULT -104
|
||||
#define BSP_ERROR_BUS_FRAME_ERROR -105
|
||||
#define BSP_ERROR_BUS_CRC_ERROR -106
|
||||
#define BSP_ERROR_BUS_DMA_FAILURE -107
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*CUSTOM_ERRNO_H */
|
||||
|
||||
1244
main_prog/Drivers/BSP/vl6180/Release_Notes.html
Normal file
1244
main_prog/Drivers/BSP/vl6180/Release_Notes.html
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<a:clrMap xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>
|
||||
@@ -0,0 +1,6 @@
|
||||
<xml xmlns:o="urn:schemas-microsoft-com:office:office">
|
||||
<o:MainFile HRef="../Release_Notes.html"/>
|
||||
<o:File HRef="themedata.thmx"/>
|
||||
<o:File HRef="colorschememapping.xml"/>
|
||||
<o:File HRef="filelist.xml"/>
|
||||
</xml>
|
||||
BIN
main_prog/Drivers/BSP/vl6180/Release_Notes_files/image001.png
Normal file
BIN
main_prog/Drivers/BSP/vl6180/Release_Notes_files/image001.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
BIN
main_prog/Drivers/BSP/vl6180/Release_Notes_files/image003.png
Normal file
BIN
main_prog/Drivers/BSP/vl6180/Release_Notes_files/image003.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
main_prog/Drivers/BSP/vl6180/Release_Notes_files/themedata.thmx
Normal file
BIN
main_prog/Drivers/BSP/vl6180/Release_Notes_files/themedata.thmx
Normal file
Binary file not shown.
2366
main_prog/Drivers/BSP/vl6180/vl6180_api.c
Normal file
2366
main_prog/Drivers/BSP/vl6180/vl6180_api.c
Normal file
File diff suppressed because it is too large
Load Diff
866
main_prog/Drivers/BSP/vl6180/vl6180_api.h
Normal file
866
main_prog/Drivers/BSP/vl6180/vl6180_api.h
Normal file
@@ -0,0 +1,866 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2019, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
#ifndef VL6180_API_H_
|
||||
#define VL6180_API_H_
|
||||
|
||||
#include "vl6180_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup api_ll API Low Level Functions
|
||||
* @brief API Low level functions
|
||||
*/
|
||||
|
||||
/** @defgroup api_hl API High Level Functions
|
||||
* @brief API High level functions
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Check and set default platform dependent configuration
|
||||
*/
|
||||
#ifndef VL6180_SINGLE_DEVICE_DRIVER
|
||||
#error "VL6180_SINGLE_DEVICE_DRIVER not defined"
|
||||
/* TODO you may remove or comment these #error but it is best you update your vl6180_platform.h file to define it*/
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef VL6180_RANGE_STATUS_ERRSTRING
|
||||
#warning "VL6180_RANGE_STATUS_ERRSTRING not defined ?"
|
||||
/* TODO you may remove or comment these #warning and keep the default below to keep compatibility
|
||||
or update your vl6180_platform.h file */
|
||||
/**
|
||||
* force VL6180_RANGE_STATUS_ERRSTRING to not supported when not part of any cfg file
|
||||
*/
|
||||
#define VL6180_RANGE_STATUS_ERRSTRING 0
|
||||
#endif
|
||||
|
||||
#ifndef VL6180_SAFE_POLLING_ENTER
|
||||
#warning "VL6180_SAFE_POLLING_ENTER not defined, likely old vl6180_cfg.h file ?"
|
||||
/* TODO you may remove or comment these #warning and keep the default below to keep compatibility
|
||||
or update your vl6180_platform.h file */
|
||||
/**
|
||||
* force VL6180_SAFE_POLLING_ENTER to off when not in cfg file
|
||||
*/
|
||||
#define VL6180_SAFE_POLLING_ENTER 0 /* off by default as in api 2.0 */
|
||||
#endif
|
||||
|
||||
#ifndef VL6180_LOG_ENABLE
|
||||
/**
|
||||
* Force VL6180_LOG_ENABLE to none as default
|
||||
*/
|
||||
#define VL6180_LOG_ENABLE 0
|
||||
#endif
|
||||
|
||||
#if VL6180_RANGE_STATUS_ERRSTRING
|
||||
/**@def VL6180_HAVE_RANGE_STATUS_ERRSTRING
|
||||
* @brief is defined when @a #VL6180_RANGE_STATUS_ERRSTRING is enable
|
||||
*/
|
||||
#define VL6180_HAVE_RANGE_STATUS_ERRSTRING
|
||||
#endif
|
||||
|
||||
|
||||
/** @brief Get API version as "hex integer" 0xMMnnss
|
||||
*/
|
||||
#define VL6180_ApiRevInt ((VL6180_API_REV_MAJOR<<24)+(VL6180_API_REV_MINOR<<16)+VL6180_API_REV_SUB)
|
||||
|
||||
/** Get API version as string for exe "2.1.12" "
|
||||
*/
|
||||
#define VL6180_ApiRevStr VL6180_STR(VL6180_API_REV_MAJOR) "." VL6180_STR(VL6180_API_REV_MINOR) "." VL6180_STR(VL6180_API_REV_SUB)
|
||||
|
||||
#ifndef VL6180_API
|
||||
# define VL6180_API
|
||||
#endif
|
||||
|
||||
/** @defgroup api_init Init functions
|
||||
* @brief API init functions
|
||||
* @ingroup api_hl
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Wait for device booted after chip enable (hardware standby)
|
||||
* @par Function Description
|
||||
* After Chip enable Application you can also simply wait at least 1ms to ensure device is ready
|
||||
* @warning After device chip enable (gpio0) de-asserted user must wait gpio1 to get asserted (hardware standby).
|
||||
* or wait at least 400usec prior to do any low level access or api call .
|
||||
*
|
||||
* This function implements polling for standby but you must ensure 400usec from chip enable passed\n
|
||||
* @warning Calling this function if device is not fresh out of reset will result in an indefinite loop\n
|
||||
*
|
||||
* @param dev The device
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_WaitDeviceBooted(VL6180Dev_t dev);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief One time device initialization
|
||||
*
|
||||
* To be called once and only once after device is brought out of reset (Chip enable) and booted see @a VL6180_WaitDeviceBooted()
|
||||
*
|
||||
* @par Function Description
|
||||
* When not used after a fresh device "power up" or reset, it may return @a #CALIBRATION_WARNING
|
||||
* meaning wrong calibration data may have been fetched from device that can result in unpredictable and wrong ranging values\n
|
||||
*
|
||||
* @param dev The device
|
||||
* @return 0 on success, @a #CALIBRATION_WARNING if failed
|
||||
*/
|
||||
VL6180_API int VL6180_InitData(VL6180Dev_t dev);
|
||||
|
||||
/**
|
||||
* @brief Configure GPIO1 function and set polarity.
|
||||
* @par Function Description
|
||||
* To be used prior to arm single shot measure or start continuous mode.
|
||||
*
|
||||
* The function uses @a VL6180_SetupGPIOx() for setting gpio 1.
|
||||
* @warning changing polarity can generate a spurious interrupt on pins.
|
||||
* It sets an interrupt flags condition that must be cleared to avoid polling hangs. \n
|
||||
* It is safe to run VL6180_ClearAllInterrupt() just after.
|
||||
*
|
||||
* @param dev The device
|
||||
* @param IntFunction The interrupt functionality to use one of :\n
|
||||
* @a #GPIOx_SELECT_OFF \n
|
||||
* @a #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT
|
||||
* @param ActiveHigh The interrupt line polarity see ::IntrPol_e
|
||||
* use @a #INTR_POL_LOW (falling edge) or @a #INTR_POL_HIGH (rising edge)
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_SetupGPIO1(VL6180Dev_t dev, uint8_t IntFunction, int ActiveHigh);
|
||||
|
||||
/**
|
||||
* @brief Prepare device for operation
|
||||
* @par Function Description
|
||||
* Does static initialization and reprogram common default settings \n
|
||||
* Device is prepared for new measure, ready single shot ranging typical polling operation\n
|
||||
* After prepare user can : \n
|
||||
* @li Call other API function to set other settings\n
|
||||
* @li Configure the interrupt pins, etc... \n
|
||||
* @li Then start ranging operations in single shot or continuous mode
|
||||
*
|
||||
* @param dev The device
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_Prepare(VL6180Dev_t dev);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
/** @defgroup api_hl_range Ranging functions
|
||||
* @brief Ranging functions
|
||||
* @ingroup api_hl
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Start continuous ranging mode
|
||||
*
|
||||
* @details End user should ensure device is in idle state and not already running
|
||||
*/
|
||||
VL6180_API int VL6180_RangeStartContinuousMode(VL6180Dev_t dev);
|
||||
|
||||
/**
|
||||
* @brief Start single shot ranging measure
|
||||
*
|
||||
* @details End user should ensure device is in idle state and not already running
|
||||
*/
|
||||
VL6180_API int VL6180_RangeStartSingleShot(VL6180Dev_t dev);
|
||||
|
||||
/**
|
||||
* @brief Set maximum convergence time
|
||||
*
|
||||
* @par Function Description
|
||||
* Setting a low convergence time can impact maximal detectable distance.
|
||||
* Refer to VL6180 Datasheet Table 7 : Typical range convergence time.
|
||||
* A typical value for up to x3 scaling is 50 ms
|
||||
*
|
||||
* @param dev
|
||||
* @param MaxConTime_msec
|
||||
* @return 0 on success. <0 on error. >0 for calibration warning status
|
||||
*/
|
||||
VL6180_API int VL6180_RangeSetMaxConvergenceTime(VL6180Dev_t dev, uint8_t MaxConTime_msec);
|
||||
|
||||
/**
|
||||
* @brief Single shot Range measurement in polling mode.
|
||||
*
|
||||
* @par Function Description
|
||||
* Kick off a new single shot range then wait for ready to retrieve it by polling interrupt status \n
|
||||
* Ranging must be prepared by a first call to @a VL6180_Prepare() and it is safer to clear very first poll call \n
|
||||
* This function reference VL6180_PollDelay(dev) porting macro/call on each polling loop,
|
||||
* but PollDelay(dev) may never be called if measure in ready on first poll loop \n
|
||||
* Should not be use in continuous mode operation as it will stop it and cause stop/start misbehaviour \n
|
||||
* \n This function clears Range Interrupt status , but not error one. For that uses @a VL6180_ClearErrorInterrupt() \n
|
||||
* This range error is not related VL6180_RangeData_t::errorStatus that refer measure status \n
|
||||
*
|
||||
* @param dev The device
|
||||
* @param pRangeData Will be populated with the result ranging data @a VL6180_RangeData_t
|
||||
* @return 0 on success , @a #RANGE_ERROR if device reports an error case in it status (not cleared) use
|
||||
*
|
||||
* \sa ::VL6180_RangeData_t
|
||||
*/
|
||||
VL6180_API int VL6180_RangePollMeasurement(VL6180Dev_t dev, VL6180_RangeData_t *pRangeData);
|
||||
|
||||
/**
|
||||
* @brief Check for measure readiness and get it if ready
|
||||
*
|
||||
* @par Function Description
|
||||
* Using this function is an alternative to @a VL6180_RangePollMeasurement() to avoid polling operation. This is suitable for applications
|
||||
* where host CPU is triggered on a interrupt (not from VL6180) to perform ranging operation. In this scenario, we assume that the very first ranging
|
||||
* operation is triggered by a call to @a VL6180_RangeStartSingleShot(). Then, host CPU regularly calls @a VL6180_RangeGetMeasurementIfReady() to
|
||||
* get a distance measure if ready. In case the distance is not ready, host may get it at the next call.\n
|
||||
*
|
||||
* @warning
|
||||
* This function does not re-start a new measurement : this is up to the host CPU to do it.\n
|
||||
* This function clears Range Interrupt for measure ready , but not error interrupts. For that, uses @a VL6180_ClearErrorInterrupt() \n
|
||||
*
|
||||
* @param dev The device
|
||||
* @param pRangeData Will be populated with the result ranging data if available
|
||||
* @return 0 on success and <0 in case of error. Please check pRangeData.errorStatus to check is new measurement is ready or not.
|
||||
*/
|
||||
VL6180_API int VL6180_RangeGetMeasurementIfReady(VL6180Dev_t dev, VL6180_RangeData_t *pRangeData);
|
||||
|
||||
/**
|
||||
* @brief Retrieve range measurements set from device
|
||||
*
|
||||
* @par Function Description
|
||||
* The measurement is made of range_mm status and error code @a VL6180_RangeData_t \n
|
||||
* Based on configuration selected extra measures are included.
|
||||
*
|
||||
* @warning should not be used in continuous if wrap around filter is active \n
|
||||
* Does not perform any wait nor check for result availability or validity.
|
||||
*\sa VL6180_RangeGetResult for "range only" measurement
|
||||
*
|
||||
* @param dev The device
|
||||
* @param pRangeData Pointer to the data structure to fill up
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RangeGetMeasurement(VL6180Dev_t dev, VL6180_RangeData_t *pRangeData);
|
||||
|
||||
/**
|
||||
* @brief Get ranging result and only that
|
||||
*
|
||||
* @par Function Description
|
||||
* Unlike @a VL6180_RangeGetMeasurement() this function only retrieves the range in millimeter \n
|
||||
* It does any required up-scale translation\n
|
||||
* It can be called after success status polling or in interrupt mode \n
|
||||
* @warning these function is not doing wrap around filtering \n
|
||||
* This function doesn't perform any data ready check!
|
||||
*
|
||||
* @param dev The device
|
||||
* @param pRange_mm Pointer to range distance
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RangeGetResult(VL6180Dev_t dev, int32_t *pRange_mm);
|
||||
|
||||
/**
|
||||
* @brief Configure ranging interrupt reported to application
|
||||
*
|
||||
* @param dev The device
|
||||
* @param ConfigGpioInt Select ranging report\n select one (and only one) of:\n
|
||||
* @a #CONFIG_GPIO_INTERRUPT_DISABLED \n
|
||||
* @a #CONFIG_GPIO_INTERRUPT_LEVEL_LOW \n
|
||||
* @a #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH \n
|
||||
* @a #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW \n
|
||||
* @a #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RangeConfigInterrupt(VL6180Dev_t dev, uint8_t ConfigGpioInt);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clear range interrupt
|
||||
*
|
||||
* @param dev The device
|
||||
* @return 0 On success
|
||||
*/
|
||||
#define VL6180_RangeClearInterrupt(dev) VL6180_ClearInterrupt(dev, INTERRUPT_CLEAR_RANGING)
|
||||
|
||||
/**
|
||||
* @brief Return ranging error interrupt status
|
||||
*
|
||||
* @par Function Description
|
||||
* Appropriate Interrupt report must have been selected first by @a VL6180_RangeConfigInterrupt() or @a VL6180_Prepare() \n
|
||||
*
|
||||
* Can be used in polling loop to wait for a given ranging event or in interrupt to read the trigger \n
|
||||
* Events triggers are : \n
|
||||
* @a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n
|
||||
* @a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n
|
||||
* @a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n (RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD|RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD)
|
||||
* @a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY \n
|
||||
*
|
||||
* @sa IntrStatus_t
|
||||
* @param dev The device
|
||||
* @param pIntStatus Pointer to status variable to update
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RangeGetInterruptStatus(VL6180Dev_t dev, uint8_t *pIntStatus);
|
||||
|
||||
#if VL6180_RANGE_STATUS_ERRSTRING
|
||||
|
||||
extern const char *ROMABLE_DATA VL6180_RangeStatusErrString[];
|
||||
/**
|
||||
* @brief Human readable error string for range error status
|
||||
*
|
||||
* @param RangeErrCode The error code as stored on @a VL6180_RangeData_t::errorStatus
|
||||
* @return error string , NULL for invalid RangeErrCode
|
||||
* @sa ::RangeError_u
|
||||
*/
|
||||
const char *VL6180_RangeGetStatusErrString(uint8_t RangeErrCode);
|
||||
#else
|
||||
#define VL6180_RangeGetStatusErrString(...) NULL
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
/** @defgroup api_ll_init Init functions
|
||||
* @brief Init functions
|
||||
* @ingroup api_ll
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Low level ranging register static settings (you should call @a VL6180_Prepare() function instead)
|
||||
*
|
||||
* @param dev
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_StaticInit(VL6180Dev_t dev);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @defgroup api_ll_range Ranging functions
|
||||
* @brief Ranging Low Level functions
|
||||
* @ingroup api_ll
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Wait for device to be ready (before a new ranging command can be issued by application)
|
||||
* @param dev The device
|
||||
* @param MaxLoop Max Number of i2c polling loop see @a #msec_2_i2cloop
|
||||
* @return 0 on success. <0 when fail \n
|
||||
* @ref VL6180_ErrCode_t::TIME_OUT for time out \n
|
||||
* @ref VL6180_ErrCode_t::INVALID_PARAMS if MaxLop<1
|
||||
*/
|
||||
VL6180_API int VL6180_RangeWaitDeviceReady(VL6180Dev_t dev, int MaxLoop);
|
||||
|
||||
/**
|
||||
* @brief Program Inter measurement period (used only in continuous mode)
|
||||
*
|
||||
* @par Function Description
|
||||
* When trying to set too long time, it returns #INVALID_PARAMS
|
||||
*
|
||||
* @param dev The device
|
||||
* @param InterMeasTime_msec Requires inter-measurement time in msec
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RangeSetInterMeasPeriod(VL6180Dev_t dev, uint32_t InterMeasTime_msec);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set device ranging scaling factor
|
||||
*
|
||||
* @par Function Description
|
||||
* The ranging scaling factor is applied on the raw distance measured by the device to increase operating ranging at the price of the precision.
|
||||
* Changing the scaling factor when device is not in f/w standby state (free running) is not safe.
|
||||
* It can be source of spurious interrupt, wrongly scaled range etc ...
|
||||
* @warning __This function doesns't update high/low threshold and other programmed settings linked to scaling factor__.
|
||||
* To ensure proper operation, threshold and scaling changes should be done following this procedure: \n
|
||||
* @li Set Group hold : @a VL6180_SetGroupParamHold() \n
|
||||
* @li Get Threshold @a VL6180_RangeGetThresholds() \n
|
||||
* @li Change scaling : @a VL6180_UpscaleSetScaling() \n
|
||||
* @li Set Threshold : @a VL6180_RangeSetThresholds() \n
|
||||
* @li Unset Group Hold : @a VL6180_SetGroupParamHold()
|
||||
*
|
||||
* @param dev The device
|
||||
* @param scaling Scaling factor to apply (1,2 or 3)
|
||||
* @return 0 on success when up-scale support is not configured it fail for any
|
||||
* scaling than the one statically configured.
|
||||
*/
|
||||
VL6180_API int VL6180_UpscaleSetScaling(VL6180Dev_t dev, uint8_t scaling);
|
||||
|
||||
/**
|
||||
* @brief Get current ranging scaling factor
|
||||
*
|
||||
* @param dev The device
|
||||
* @return The current scaling factor
|
||||
*/
|
||||
VL6180_API int VL6180_UpscaleGetScaling(VL6180Dev_t dev);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Give filtered state (wrap-around filter) of a range measurement
|
||||
* @param pRangeData Range measurement data
|
||||
* @return 0 means measure was not filtered, when not 0 range from device got filtered by filter post processing
|
||||
*/
|
||||
#define VL6180_RangeIsFilteredMeasurement(pRangeData) ((pRangeData)->errorStatus == RangingFiltered)
|
||||
|
||||
/**
|
||||
* @brief Get the maximal distance for actual scaling
|
||||
* @par Function Description
|
||||
* Do not use prior to @a VL6180_Prepare() or at least @a VL6180_InitData()
|
||||
*
|
||||
* Any range value more than the value returned by this function is to be considered as "no target detected"
|
||||
* or "no target in detectable range"
|
||||
* @warning The maximal distance depends on the scaling
|
||||
*
|
||||
* @param dev The device
|
||||
* @return The maximal range limit for actual mode and scaling
|
||||
*/
|
||||
uint16_t VL6180_GetUpperLimit(VL6180Dev_t dev);
|
||||
|
||||
/**
|
||||
* @brief Apply low and high ranging thresholds that are considered only in continuous mode
|
||||
*
|
||||
* @par Function Description
|
||||
* This function programs low and high ranging thresholds that are considered in continuous mode :
|
||||
* interrupt will be raised only when an object is detected at a distance inside this [low:high] range.
|
||||
* The function takes care of applying current scaling factor if any.\n
|
||||
* To be safe, in continuous operation, thresholds must be changed under "group parameter hold" cover.
|
||||
* Group hold can be activated/deactivated directly in the function or externally (then set 0)
|
||||
* using /a VL6180_SetGroupParamHold() function.
|
||||
*
|
||||
* @param dev The device
|
||||
* @param low Low threshold in mm
|
||||
* @param high High threshold in mm
|
||||
* @param SafeHold Use of group parameters hold to surround threshold programming.
|
||||
* @return 0 On success
|
||||
*/
|
||||
VL6180_API int VL6180_RangeSetThresholds(VL6180Dev_t dev, uint16_t low, uint16_t high, int SafeHold);
|
||||
|
||||
/**
|
||||
* @brief Get scaled high and low threshold from device
|
||||
*
|
||||
* @par Function Description
|
||||
* Due to scaling factor, the returned value may be different from what has been programmed first (precision lost).
|
||||
* For instance VL6180_RangeSetThresholds(dev,11,22) with scale 3
|
||||
* will read back 9 ((11/3)x3) and 21 ((22/3)x3).
|
||||
|
||||
* @param dev The device
|
||||
* @param low scaled low Threshold ptr can be NULL if not needed
|
||||
* @param high scaled High Threshold ptr can be NULL if not needed
|
||||
* @return 0 on success, return value is undefined if both low and high are NULL
|
||||
* @warning return value is undefined if both low and high are NULL
|
||||
*/
|
||||
VL6180_API int VL6180_RangeGetThresholds(VL6180Dev_t dev, uint16_t *low, uint16_t *high);
|
||||
|
||||
/**
|
||||
* @brief Set ranging raw thresholds (scaling not considered so not recommended to use it)
|
||||
*
|
||||
* @param dev The device
|
||||
* @param low raw low threshold set to raw register
|
||||
* @param high raw high threshold set to raw register
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RangeSetRawThresholds(VL6180Dev_t dev, uint8_t low, uint8_t high);
|
||||
|
||||
/**
|
||||
* @brief Set Early Convergence Estimate ratio
|
||||
* @par Function Description
|
||||
* For more information on ECE check datasheet
|
||||
* @warning May return a calibration warning in some use cases
|
||||
*
|
||||
* @param dev The device
|
||||
* @param FactorM ECE factor M in M/D
|
||||
* @param FactorD ECE factor D in M/D
|
||||
* @return 0 on success. <0 on error. >0 on warning
|
||||
*/
|
||||
VL6180_API int VL6180_RangeSetEceFactor(VL6180Dev_t dev, uint16_t FactorM, uint16_t FactorD);
|
||||
|
||||
/**
|
||||
* @brief Set Early Convergence Estimate state (See #SYSRANGE_RANGE_CHECK_ENABLES register)
|
||||
* @param dev The device
|
||||
* @param enable State to be set 0=disabled, otherwise enabled
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RangeSetEceState(VL6180Dev_t dev, int enable);
|
||||
|
||||
/**
|
||||
* @brief Set activation state of the wrap around filter
|
||||
* @param dev The device
|
||||
* @param state New activation state (0=off, otherwise on)
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_FilterSetState(VL6180Dev_t dev, int state);
|
||||
|
||||
/**
|
||||
* Get activation state of the wrap around filter
|
||||
* @param dev The device
|
||||
* @return Filter enabled or not, when filter is not supported it always returns 0S
|
||||
*/
|
||||
VL6180_API int VL6180_FilterGetState(VL6180Dev_t dev);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set activation state of DMax computation
|
||||
* @param dev The device
|
||||
* @param state New activation state (0=off, otherwise on)
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_DMaxSetState(VL6180Dev_t dev, int state);
|
||||
|
||||
/**
|
||||
* Get activation state of DMax computation
|
||||
* @param dev The device
|
||||
* @return Filter enabled or not, when filter is not supported it always returns 0S
|
||||
*/
|
||||
VL6180_API int VL6180_DMaxGetState(VL6180Dev_t dev);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set ranging mode and start/stop measure (use high level functions instead : @a VL6180_RangeStartSingleShot() or @a VL6180_RangeStartContinuousMode())
|
||||
*
|
||||
* @par Function Description
|
||||
* When used outside scope of known polling single shot stopped state, \n
|
||||
* user must ensure the device state is "idle" before to issue a new command.
|
||||
*
|
||||
* @param dev The device
|
||||
* @param mode A combination of working mode (#MODE_SINGLESHOT or #MODE_CONTINUOUS) and start/stop condition (#MODE_START_STOP) \n
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RangeSetSystemMode(VL6180Dev_t dev, uint8_t mode);
|
||||
|
||||
/**
|
||||
* @brief Enable/disable range ignore feature
|
||||
*
|
||||
* @par Function Description
|
||||
* Enable range ignore feature to ensure that the device does not range on the cover glass because of cross-talk.
|
||||
* @a VL6180_RangeIgnoreConfigure() should be run first to configure feature prior to enable it.
|
||||
*
|
||||
* @param dev The Device
|
||||
* @param EnableState Feature state to set 0= off else =on
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RangeIgnoreSetEnable(VL6180Dev_t dev, int EnableState);
|
||||
|
||||
/**
|
||||
* @brief Configure Range ignore feature
|
||||
*
|
||||
* @par Function Description
|
||||
* When return signal rate is below the IgnoreThreshold and return distance is below the ValidHeight, the distance will be ignored
|
||||
* @warning It is recommended to enable range ignore feature and configure it only when device is in stop or idle state
|
||||
* @warning Once this function is called, next call to @a VL6180_InitData() function without reseting the device will result in wrong ranging operation
|
||||
* @param dev The Device
|
||||
* @param ValidHeight_mm Valid height in mm (unscaled ie not raw value before scaling)
|
||||
* @param IgnoreThreshold Ignore threshold in fixpoint 9.7 MegaCount/sec
|
||||
* @return
|
||||
*/
|
||||
VL6180_API int VL6180_RangeIgnoreConfigure(VL6180Dev_t dev, uint16_t ValidHeight_mm, uint16_t IgnoreThreshold);
|
||||
/** @} */
|
||||
|
||||
/** @defgroup api_ll_range_calibration Ranging calibration functions
|
||||
* @brief Ranging calibration functions
|
||||
* @ingroup api_ll
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Get part to part calibration offset
|
||||
*
|
||||
* @par Function Description
|
||||
* Should only be used after a successful call to @a VL6180_InitData to backup device nvm value
|
||||
*
|
||||
* @param dev The device
|
||||
* @return part to part calibration offset from device
|
||||
*/
|
||||
VL6180_API int8_t VL6180_GetOffsetCalibrationData(VL6180Dev_t dev);
|
||||
|
||||
/**
|
||||
* Set or over-write part to part calibration offset and apply it immediately
|
||||
* \sa VL6180_InitData(), VL6180_GetOffsetCalibrationData()
|
||||
* @param dev The device
|
||||
* @param offset Offset
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_SetOffsetCalibrationData(VL6180Dev_t dev, int8_t offset);
|
||||
|
||||
/**
|
||||
* @brief Set Cross talk compensation rate
|
||||
*
|
||||
* @par Function Description
|
||||
* It programs register @a #SYSRANGE_CROSSTALK_COMPENSATION_RATE
|
||||
*
|
||||
* @param dev The device
|
||||
* @param Rate Compensation rate (9.7 fix point) see datasheet for details
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_SetXTalkCompensationRate(VL6180Dev_t dev, FixPoint97_t Rate);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup api_ll_misc Misc functions
|
||||
* @brief Misc functions
|
||||
* @ingroup api_ll
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Set Group parameter Hold state
|
||||
*
|
||||
* @par Function Description
|
||||
* Group parameter holds @a #SYSTEM_GROUPED_PARAMETER_HOLD enable safe update (non atomic across multiple measure) by host
|
||||
* \n The critical register group is composed of: \n
|
||||
* #SYSTEM_INTERRUPT_CONFIG_GPIO \n
|
||||
* #SYSRANGE_THRESH_HIGH \n
|
||||
* #SYSRANGE_THRESH_LOW
|
||||
*
|
||||
*
|
||||
* @param dev The device
|
||||
* @param Hold Group parameter Hold state to be set (on/off)
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_SetGroupParamHold(VL6180Dev_t dev, int Hold);
|
||||
|
||||
/**
|
||||
* @brief Set new device i2c address
|
||||
*
|
||||
* After completion the device will answer to the new address programmed.
|
||||
*
|
||||
* @sa AN4478: Using multiple VL6180's in a single design
|
||||
* @param dev The device
|
||||
* @param NewAddr The new i2c address (8 bits)
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_SetI2CAddress(VL6180Dev_t dev, uint8_t NewAddr);
|
||||
|
||||
/**
|
||||
* @brief Fully configure gpio 0/1 pin : polarity and functionality
|
||||
*
|
||||
* @param dev The device
|
||||
* @param pin gpio pin 0 or 1
|
||||
* @param IntFunction Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
|
||||
* @param ActiveHigh Set active high polarity, or active low see @a ::IntrPol_e
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_SetupGPIOx(VL6180Dev_t dev, int pin, uint8_t IntFunction, int ActiveHigh);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set interrupt pin polarity for the given GPIO
|
||||
*
|
||||
* @param dev The device
|
||||
* @param pin Pin 0 or 1
|
||||
* @param active_high select active high or low polarity using @ref IntrPol_e
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_SetGPIOxPolarity(VL6180Dev_t dev, int pin, int active_high);
|
||||
|
||||
/**
|
||||
* Select interrupt functionality for the given GPIO
|
||||
*
|
||||
* @par Function Description
|
||||
* Functionality refer to @a SYSTEM_MODE_GPIO0
|
||||
*
|
||||
* @param dev The device
|
||||
* @param pin Pin to configure 0 or 1 (gpio0 or gpio1)Note that gpio0 is chip enable at power up !
|
||||
* @param functionality Pin functionality : either #GPIOx_SELECT_OFF or #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT (refer to #SYSTEM_MODE_GPIO1 register definition)
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_SetGPIOxFunctionality(VL6180Dev_t dev, int pin, uint8_t functionality);
|
||||
|
||||
/**
|
||||
* @brief Disable and turn to Hi-Z gpio output pin
|
||||
*
|
||||
* @param dev The device
|
||||
* @param pin The pin number to disable 0 or 1
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_DisableGPIOxOut(VL6180Dev_t dev, int pin);
|
||||
|
||||
/**
|
||||
* @def msec_2_i2cloop
|
||||
* @brief Number of I2C polling loop (an 8 bit register) to run for maximal wait time.
|
||||
*
|
||||
* @par Function Description
|
||||
* When polling via I2C the overall time is mainly the I2C transaction time because it is a slow bus
|
||||
* one 8 bit register poll on I2C bus timing is shown below: \n
|
||||
* start + addr_w(a) + 2x8bit index(a) + stop + start + addr_rd(a) + 1x8bit data_rd(a) + stop \n
|
||||
* 1 8 1 2*(8+1) 1 1 8 1 8 1 1 \n
|
||||
* so 49 serial bits
|
||||
*
|
||||
* @param time_ms Time to wait in milli second 10
|
||||
* @param i2c_khz I2C bus frequencies in KHz for instance 400
|
||||
* @return The number of loops (at least 1)
|
||||
*/
|
||||
#define msec_2_i2cloop(time_ms, i2c_khz) (((time_ms) * (i2c_khz) / 49) + 1)
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* polarity use in @a VL6180_SetupGPIOx() , @a VL6180_SetupGPIO1()
|
||||
*/
|
||||
typedef enum {
|
||||
INTR_POL_LOW = 0, /*!< set active low polarity best setup for falling edge */
|
||||
INTR_POL_HIGH = 1, /*!< set active high polarity best setup for rising edge */
|
||||
} IntrPol_e;
|
||||
|
||||
/** @defgroup api_ll_intr Interrupts management functions
|
||||
* @brief Interrupts management functions
|
||||
* @ingroup api_ll
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get all interrupts cause
|
||||
*
|
||||
* @param dev The device
|
||||
* @param status Ptr to interrupt status. You can use @a IntrStatus_t::val
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_GetInterruptStatus(VL6180Dev_t dev, uint8_t *status);
|
||||
|
||||
/**
|
||||
* @brief Clear given system interrupt condition
|
||||
*
|
||||
* @par Function Description
|
||||
* Clear given interrupt cause by writing into register #SYSTEM_INTERRUPT_CLEAR register.
|
||||
* @param dev The device
|
||||
* @param IntClear Which interrupt source to clear. Use any combinations of #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ERROR.
|
||||
* @return 0 On success
|
||||
*/
|
||||
VL6180_API int VL6180_ClearInterrupt(VL6180Dev_t dev, uint8_t IntClear);
|
||||
|
||||
/**
|
||||
* @brief Clear error interrupt
|
||||
*
|
||||
* @param dev The device
|
||||
* @return 0 On success
|
||||
*/
|
||||
#define VL6180_ClearErrorInterrupt(dev) VL6180_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR)
|
||||
|
||||
/**
|
||||
* @brief Clear All interrupt causes (range+error)
|
||||
*
|
||||
* @param dev The device
|
||||
* @return 0 On success
|
||||
*/
|
||||
#define VL6180_ClearAllInterrupt(dev) VL6180_ClearInterrupt(dev, INTERRUPT_CLEAR_ERROR|INTERRUPT_CLEAR_RANGING)
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
/** @defgroup api_reg API Register access functions
|
||||
* @brief Registers access functions called by API core functions
|
||||
* @ingroup api_ll
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Write VL6180 single byte register
|
||||
* @param dev The device
|
||||
* @param index The register index
|
||||
* @param data 8 bit register data
|
||||
* @return success
|
||||
*/
|
||||
VL6180_API int VL6180_WrByte(VL6180Dev_t dev, uint16_t index, uint8_t data);
|
||||
/**
|
||||
* Thread safe VL6180 Update (rd/modify/write) single byte register
|
||||
*
|
||||
* Final_reg = (Initial_reg & and_data) |or_data
|
||||
*
|
||||
* @param dev The device
|
||||
* @param index The register index
|
||||
* @param AndData 8 bit and data
|
||||
* @param OrData 8 bit or data
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_UpdateByte(VL6180Dev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData);
|
||||
/**
|
||||
* Write VL6180 word register
|
||||
* @param dev The device
|
||||
* @param index The register index
|
||||
* @param data 16 bit register data
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_WrWord(VL6180Dev_t dev, uint16_t index, uint16_t data);
|
||||
/**
|
||||
* Write VL6180 double word (4 byte) register
|
||||
* @param dev The device
|
||||
* @param index The register index
|
||||
* @param data 32 bit register data
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_WrDWord(VL6180Dev_t dev, uint16_t index, uint32_t data);
|
||||
|
||||
/**
|
||||
* Read VL6180 single byte register
|
||||
* @param dev The device
|
||||
* @param index The register index
|
||||
* @param data pointer to 8 bit data
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RdByte(VL6180Dev_t dev, uint16_t index, uint8_t *data);
|
||||
|
||||
/**
|
||||
* Read VL6180 word (2byte) register
|
||||
* @param dev The device
|
||||
* @param index The register index
|
||||
* @param data pointer to 16 bit data
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RdWord(VL6180Dev_t dev, uint16_t index, uint16_t *data);
|
||||
|
||||
/**
|
||||
* Read VL6180 dword (4byte) register
|
||||
* @param dev The device
|
||||
* @param index The register index
|
||||
* @param data pointer to 32 bit data
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RdDWord(VL6180Dev_t dev, uint16_t index, uint32_t *data);
|
||||
|
||||
|
||||
/**
|
||||
* Read VL6180 multiple bytes
|
||||
* @note required only if #VL6180_HAVE_MULTI_READ is set
|
||||
* @param dev The device
|
||||
* @param index The register index
|
||||
* @param data pointer to 8 bit data
|
||||
* @param nData number of data bytes to read
|
||||
* @return 0 on success
|
||||
*/
|
||||
VL6180_API int VL6180_RdMulti(VL6180Dev_t dev, uint16_t index, uint8_t *data, int nData);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* VL6180_API_H_ */
|
||||
104
main_prog/Drivers/BSP/vl6180/vl6180_cfg.h
Normal file
104
main_prog/Drivers/BSP/vl6180/vl6180_cfg.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*******************************************************************************
|
||||
Copyright <20> 2019, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* @file VL6180_cfg.h
|
||||
*
|
||||
* Proximity configuration
|
||||
*/
|
||||
|
||||
#ifndef VL6180_CFG_H_
|
||||
#define VL6180_CFG_H_
|
||||
|
||||
/** @defgroup api_config Configuration
|
||||
* @brief API static configuration
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @ingroup api_config
|
||||
* @{*/
|
||||
|
||||
|
||||
/**
|
||||
* @def VL6180_UPSCALE_SUPPORT
|
||||
* @brief Configure up-scale capabilities and default up-scale factor for ranging operations
|
||||
*
|
||||
* @li 1 : Fixed scaling by 1 (no up-scaling support)
|
||||
* @li 2 : Fixed scaling by 2
|
||||
* @li 3 : Fixed scaling by 3
|
||||
* @li -1 -2 -3 : Run time programmable through @a VL6180_UpscaleSetScaling(). Default scaling factore is -VL6180_UPSCALE_SUPPORT \n
|
||||
*/
|
||||
#define VL6180_UPSCALE_SUPPORT -3
|
||||
|
||||
|
||||
/**
|
||||
* @def VL6180_HAVE_DMAX_RANGING
|
||||
* @brief Enable DMax calculation for ranging applications.
|
||||
*
|
||||
* When set to 1, __Dmax__ is returned by API typically when @a VL6180_RangePollMeasurement() high level
|
||||
* function is called (this is returned in @a VL6180_RangeData_t structure).
|
||||
* __Dmax__ is an estimation of the maximum distance (in mm) the product can report a valid distance of a 17% target for
|
||||
* the current ambient light conditions (__Dmax__ decreases when ambient light increases). __Dmax__ should be used only
|
||||
* when the product is not able to return a valid distance (no object or object is too far from the ranging sensor).
|
||||
* Typically, this is done by checking the __errorStatus__ field of the @a VL6180_RangeData_t structure returned by
|
||||
* the @a VL6180_RangePollMeasurement() function.
|
||||
* You may refer to ::RangeError_u to get full list of supported error codes.
|
||||
* @warning Dmax is estimated for a 17% grey target. If the real target has a reflectance lower than 17%, report Dmax could be over-estimated
|
||||
*/
|
||||
#define VL6180_HAVE_DMAX_RANGING 1
|
||||
|
||||
/**
|
||||
* @def VL6180_WRAP_AROUND_FILTER_SUPPORT
|
||||
* @brief Enable wrap around filter (WAF) feature
|
||||
*
|
||||
* In specific conditions, when targeting a mirror or a very reflective metal, a __wrap around__ effect can occur internally to the
|
||||
* ranging product which results in returning a wrong distance (under-estimated). Goal of the WAF is to detect this wrap arround effect
|
||||
* and to filter it by returning a non-valid distance : __errorStatus__ set to 16 (see ::RangeError_u)
|
||||
* @warning Wrap-around filter can not be used when device is running in continuous mode
|
||||
*
|
||||
* @li 0 : Filter is not supported, no filtering code is included in API
|
||||
* @li 1 : Filter is supported and active by default
|
||||
* @li -1 : Filter is supported but is not active by default @a VL6180_FilterSetState() can turn it on and off at any time
|
||||
*/
|
||||
#define VL6180_WRAP_AROUND_FILTER_SUPPORT 1
|
||||
|
||||
/**
|
||||
* @def VL6180_EXTENDED_RANGE
|
||||
* @brief Enable extended ranging support
|
||||
*
|
||||
* Device that do not formally support extended ranging should only be used with a scaling factor of 1.
|
||||
* Correct operation with scaling factor other than 1 (>200mm ) is not granted by ST.
|
||||
*/
|
||||
#define VL6180_EXTENDED_RANGE 0
|
||||
|
||||
|
||||
#endif
|
||||
/** @} */ // end of api_config
|
||||
|
||||
/* VL6180_CFG_H_ */
|
||||
677
main_prog/Drivers/BSP/vl6180/vl6180_def.h
Normal file
677
main_prog/Drivers/BSP/vl6180/vl6180_def.h
Normal file
@@ -0,0 +1,677 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2019, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* @file VL6180_def.h
|
||||
*
|
||||
* @brief Type definitions for vl6180 api.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _VL6180_DEF
|
||||
#define _VL6180_DEF
|
||||
|
||||
/** API major version */
|
||||
#define VL6180_API_REV_MAJOR 1
|
||||
/** API minor version */
|
||||
#define VL6180_API_REV_MINOR 3
|
||||
/** API sub version */
|
||||
#define VL6180_API_REV_SUB 0
|
||||
|
||||
#define VL6180_STR_HELPER(x) #x
|
||||
#define VL6180_STR(x) VL6180_STR_HELPER(x)
|
||||
|
||||
#include "vl6180_cfg.h"
|
||||
#include "vl6180_types.h"
|
||||
|
||||
/*
|
||||
* check configuration macro raise error or warning and suggest a default value
|
||||
*/
|
||||
|
||||
#ifndef VL6180_UPSCALE_SUPPORT
|
||||
#error "VL6180_UPSCALE_SUPPORT not defined"
|
||||
/* TODO you must define value for upscale support in your vl6180_cfg.h */
|
||||
#endif
|
||||
|
||||
#ifndef VL6180_HAVE_DMAX_RANGING
|
||||
#error "VL6180_HAVE_DMAX_RANGING not defined"
|
||||
/* TODO you may remove or comment these #error and keep the default below or update your vl6180_cfg.h .h file */
|
||||
/**
|
||||
* force VL6180_HAVE_DMAX_RANGING to not supported when not part of cfg file
|
||||
*/
|
||||
#define VL6180_HAVE_DMAX_RANGING 0
|
||||
#endif
|
||||
|
||||
#ifndef VL6180_EXTENDED_RANGE
|
||||
#define VL6180_EXTENDED_RANGE 1
|
||||
#endif
|
||||
|
||||
#ifndef VL6180_WRAP_AROUND_FILTER_SUPPORT
|
||||
#error "VL6180_WRAP_AROUND_FILTER_SUPPORT not defined ?"
|
||||
/* TODO you may remove or comment these #error and keep the default below or update vl6180_cfg.h file */
|
||||
/**
|
||||
* force VL6180_WRAP_AROUND_FILTER_SUPPORT to not supported when not part of cfg file
|
||||
*/
|
||||
#define VL6180_WRAP_AROUND_FILTER_SUPPORT 0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef VL6180_HAVE_MULTI_READ
|
||||
# define VL6180_HAVE_MULTI_READ 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Force VL6180_CACHED_REG to default 0 when not defined
|
||||
*/
|
||||
#ifndef VL6180_CACHED_REG
|
||||
# define VL6180_CACHED_REG 0
|
||||
#else
|
||||
# define VL6180_FIRST_CACHED_INDEX 0x04D
|
||||
# define VL6180_LAST_CACHED_INDEX (VL6180_FIRST_CACHED_INDEX+55)
|
||||
# define VL6180_CACHED_REG_CNT (VL6180_LAST_CACHED_INDEX-VL6180_FIRST_CACHED_INDEX+1)
|
||||
#endif
|
||||
|
||||
/****************************************
|
||||
* PRIVATE define do not edit
|
||||
****************************************/
|
||||
|
||||
/** Maximal buffer size ever use in i2c */
|
||||
#define VL6180_MAX_I2C_XFER_SIZE 8 /* At present time it 6 byte max but that can change */
|
||||
|
||||
#if VL6180_UPSCALE_SUPPORT < 0
|
||||
/**
|
||||
* @def VL6180_HAVE_UPSCALE_DATA
|
||||
* @brief is defined if device data structure has data so when user configurable up-scale is active
|
||||
*/
|
||||
#define VL6180_HAVE_UPSCALE_DATA /* have data only for user configurable up-scale config */
|
||||
#endif
|
||||
|
||||
#if VL6180_WRAP_AROUND_FILTER_SUPPORT
|
||||
/**
|
||||
* @def VL6180_HAVE_WRAP_AROUND_DATA
|
||||
* @brief is defined if device data structure has filter data so when active in cfg file
|
||||
*/
|
||||
#define VL6180_HAVE_WRAP_AROUND_DATA
|
||||
#endif
|
||||
|
||||
|
||||
#if VL6180_WRAP_AROUND_FILTER_SUPPORT || VL6180_HAVE_DMAX_RANGING
|
||||
#define VL6180_HAVE_RATE_DATA
|
||||
#endif
|
||||
|
||||
/** Error and warning code returned by API
|
||||
*
|
||||
* negative value are true error mostly fatal\n
|
||||
* positive value are warning most of time it's ok to continue\n
|
||||
*/
|
||||
enum VL6180_ErrCode_t {
|
||||
API_NO_ERROR = 0,
|
||||
CALIBRATION_WARNING = 1, /*!< warning invalid calibration data may be in used \a VL6180_InitData() \a VL6180_GetOffsetCalibrationData \a VL6180_SetOffsetCalibrationData*/
|
||||
MIN_CLIPED = 2, /*!< warning parameter passed was clipped to min before to be applied */
|
||||
NOT_GUARANTEED = 3, /*!< Correct operation is not guaranteed typically using extended ranging on vl6180 */
|
||||
|
||||
API_ERROR = -1, /*!< Unqualified error */
|
||||
INVALID_PARAMS = -2, /*!< parameter passed is invalid or out of range */
|
||||
NOT_SUPPORTED = -3, /*!< function is not supported in current mode or configuration */
|
||||
RANGE_ERROR = -4, /*!< device report a ranging error interrupt status */
|
||||
TIME_OUT = -5, /*!< aborted due to time out */
|
||||
};
|
||||
|
||||
/**
|
||||
* Filtered result data structure range data is to be used
|
||||
*/
|
||||
typedef struct RangeFilterResult_tag {
|
||||
uint16_t range_mm; /*!< Filtered ranging value */
|
||||
uint16_t rawRange_mm; /*!< raw range value (scaled) */
|
||||
uint32_t filterError; /*!< current filter error code */
|
||||
} RangeFilterResult_t;
|
||||
|
||||
/**
|
||||
* "small" unsigned data type used in filter
|
||||
*
|
||||
* if data space saving is not a concern it can be change to platform native unsigned int
|
||||
*/
|
||||
typedef uint32_t FilterType1_t;
|
||||
|
||||
/**
|
||||
* @def FILTER_NBOF_SAMPLES
|
||||
* @brief sample history len used for wrap around filtering
|
||||
*/
|
||||
#define FILTER_NBOF_SAMPLES 10
|
||||
/**
|
||||
* Wrap around filter internal data
|
||||
*/
|
||||
struct FilterData_t {
|
||||
uint32_t MeasurementIndex; /*!< current measurement index */
|
||||
uint32_t MeasurementsSinceLastFlush; /*!< Number of measurements done since last time buffer has been flushed */
|
||||
uint16_t LastTrueRange[FILTER_NBOF_SAMPLES]; /*!< filtered/corrected distance history */
|
||||
uint32_t LastReturnRates[FILTER_NBOF_SAMPLES]; /*!< Return rate history */
|
||||
uint16_t StdFilteredReads; /*!< internal use */
|
||||
FilterType1_t Default_ZeroVal; /*!< internal use */
|
||||
FilterType1_t Default_VAVGVal; /*!< internal use */
|
||||
FilterType1_t NoDelay_ZeroVal; /*!< internal use */
|
||||
FilterType1_t NoDelay_VAVGVal; /*!< internal use */
|
||||
FilterType1_t Previous_VAVGDiff; /*!< internal use */
|
||||
uint32_t FilteringOnGoingConsecutiveStates; /*!< internal use */
|
||||
uint32_t filterError; /*!< current filter error code */
|
||||
};
|
||||
|
||||
#if VL6180_HAVE_DMAX_RANGING
|
||||
typedef int32_t DMaxFix_t;
|
||||
struct DMaxData_t {
|
||||
uint32_t ambTuningWindowFactor_K; /*!< internal algo tuning (*1000) */
|
||||
|
||||
DMaxFix_t retSignalAt400mm; /*!< intermediate dmax computation value caching @a #SYSRANGE_CROSSTALK_COMPENSATION_RATE and private reg 0x02A */
|
||||
/* int32_t RegB8; */ /*!< register 0xB8 cached to speed reduce i2c traffic for dmax computation */
|
||||
/* place all word data below to optimize struct packing */
|
||||
/* int32_t minSignalNeeded; */ /*!< optimized computation intermediate base on register cached value */
|
||||
int32_t snrLimit_K; /*!< cached and optimized computation intermediate from @a #SYSRANGE_MAX_AMBIENT_LEVEL_MULT */
|
||||
uint16_t ClipSnrLimit; /*!< Max value for snr limit */
|
||||
/* place all byte data below to optimize packing */
|
||||
/* uint8_t MaxConvTime; */ /*!< cached max convergence time @a #SYSRANGE_MAX_CONVERGENCE_TIME*/
|
||||
};
|
||||
#endif
|
||||
|
||||
struct RangeIgnoreData_t {
|
||||
uint16_t ValidHeight;
|
||||
uint16_t IgnoreThreshold;
|
||||
uint8_t Enabled;
|
||||
};
|
||||
/**
|
||||
* @struct VL6180DevData_t
|
||||
*
|
||||
* @brief Per VL6180 device St private data structure \n
|
||||
* End user should never access any of these field directly
|
||||
*
|
||||
* These must never access directly but only via VL6180Dev/SetData(dev, field) macro
|
||||
*/
|
||||
struct VL6180DevData_t {
|
||||
|
||||
uint32_t Part2PartAmbNVM; /*!< backed up NVM value */
|
||||
uint32_t XTalkCompRate_KCps; /*! Cached XTlak Compensation Rate */
|
||||
|
||||
uint16_t EceFactorM; /*!< Ece Factor M numerator */
|
||||
uint16_t EceFactorD; /*!< Ece Factor D denominator*/
|
||||
|
||||
struct RangeIgnoreData_t RangeIgnore;
|
||||
|
||||
#ifdef VL6180_HAVE_UPSCALE_DATA
|
||||
uint8_t UpscaleFactor; /*!< up-scaling factor*/
|
||||
#endif
|
||||
|
||||
#ifdef VL6180_HAVE_WRAP_AROUND_DATA
|
||||
uint8_t WrapAroundFilterActive; /*!< Filter on/off */
|
||||
struct FilterData_t FilterData; /*!< Filter internal data state history ... */
|
||||
#endif
|
||||
|
||||
#if VL6180_CACHED_REG
|
||||
uint8_t CacheFilled; /*!< Set if valid data got fetched use to control when to fill up register cache */
|
||||
uint8_t CachedRegs[VL6180_CACHED_REG_CNT]; /*!< Cache register storage */
|
||||
#endif
|
||||
#if VL6180_HAVE_DMAX_RANGING
|
||||
struct DMaxData_t DMaxData;
|
||||
uint8_t DMaxEnable;
|
||||
#endif
|
||||
int8_t Part2PartOffsetNVM; /*!< backed up NVM value */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @struct VL6180_RangeData_t
|
||||
* @brief Range and any optional measurement data.
|
||||
*/
|
||||
typedef struct {
|
||||
int32_t range_mm; /*!< range distance in mm. */
|
||||
int32_t signalRate_mcps; /*!< signal rate (MCPS)\n these is a 9.7 fix point value, which is effectively a measure of target reflectance.*/
|
||||
uint32_t errorStatus; /*!< Error status of the current measurement. \n see @a ::RangeError_u @a VL6180_GetRangeStatusErrString() */
|
||||
|
||||
|
||||
#ifdef VL6180_HAVE_RATE_DATA
|
||||
uint32_t rtnAmbRate; /*!< Return Ambient rate in KCount per sec related to \a RESULT_RANGE_RETURN_AMB_COUNT */
|
||||
uint32_t rtnRate; /*!< Return rate in KCount per sec related to \a RESULT_RANGE_RETURN_SIGNAL_COUNT */
|
||||
uint32_t rtnConvTime; /*!< Return Convergence time \a RESULT_RANGE_RETURN_CONV_TIME */
|
||||
uint32_t refConvTime; /*!< Reference convergence time \a RESULT_RANGE_REFERENCE_CONV_TIME */
|
||||
#endif
|
||||
|
||||
|
||||
#if VL6180_HAVE_DMAX_RANGING
|
||||
uint32_t DMax; /*!< DMax when applicable */
|
||||
#endif
|
||||
|
||||
#ifdef VL6180_HAVE_WRAP_AROUND_DATA
|
||||
RangeFilterResult_t FilteredData; /*!< Filter result main range_mm is updated */
|
||||
#endif
|
||||
} VL6180_RangeData_t;
|
||||
|
||||
|
||||
/** use where fix point 9.7 bit values are expected
|
||||
*
|
||||
* given a floating point value f it's .7 bit point is (int)(f*(1<<7))*/
|
||||
typedef uint16_t FixPoint97_t;
|
||||
|
||||
/** lux data type */
|
||||
typedef uint32_t lux_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Range status Error code
|
||||
*
|
||||
* @a VL6180_GetRangeStatusErrString() if configured ( @a #VL6180_RANGE_STATUS_ERRSTRING )
|
||||
* related to register @a #RESULT_RANGE_STATUS and additional post processing
|
||||
*/
|
||||
typedef enum {
|
||||
NoError = 0, /*!< 0 0b0000 NoError */
|
||||
VCSEL_Continuity_Test, /*!< 1 0b0001 VCSEL_Continuity_Test */
|
||||
VCSEL_Watchdog_Test, /*!< 2 0b0010 VCSEL_Watchdog_Test */
|
||||
VCSEL_Watchdog, /*!< 3 0b0011 VCSEL_Watchdog */
|
||||
PLL1_Lock, /*!< 4 0b0100 PLL1_Lock */
|
||||
PLL2_Lock, /*!< 5 0b0101 PLL2_Lock */
|
||||
Early_Convergence_Estimate,/*!< 6 0b0110 Early_Convergence_Estimate */
|
||||
Max_Convergence, /*!< 7 0b0111 Max_Convergence */
|
||||
No_Target_Ignore, /*!< 8 0b1000 No_Target_Ignore */
|
||||
Not_used_9, /*!< 9 0b1001 Not_used */
|
||||
Not_used_10, /*!< 10 0b1010 Not_used_ */
|
||||
Max_Signal_To_Noise_Ratio, /*!< 11 0b1011 Max_Signal_To_Noise_Ratio*/
|
||||
Raw_Ranging_Algo_Underflow,/*!< 12 0b1100 Raw_Ranging_Algo_Underflow*/
|
||||
Raw_Ranging_Algo_Overflow, /*!< 13 0b1101 Raw_Ranging_Algo_Overflow */
|
||||
Ranging_Algo_Underflow, /*!< 14 0b1110 Ranging_Algo_Underflow */
|
||||
Ranging_Algo_Overflow, /*!< 15 0b1111 Ranging_Algo_Overflow */
|
||||
|
||||
/* code below are addition for API/software side they are not hardware*/
|
||||
RangingFiltered = 0x10, /*!< 16 0b10000 filtered by post processing*/
|
||||
DataNotReady = 0x12, /*!< 18 0b10011 New data sample not ready */
|
||||
|
||||
} RangeError_u;
|
||||
|
||||
|
||||
/** @defgroup device_regdef Device registers & masks definitions
|
||||
* @brief Device registers and masks definitions
|
||||
*/
|
||||
|
||||
|
||||
/** @ingroup device_regdef
|
||||
* @{*/
|
||||
|
||||
/**
|
||||
* The device model ID
|
||||
*/
|
||||
#define IDENTIFICATION_MODEL_ID 0x000
|
||||
/**
|
||||
* Revision identifier of the Device for major change.
|
||||
*/
|
||||
#define IDENTIFICATION_MODULE_REV_MAJOR 0x003
|
||||
/**
|
||||
* Revision identifier of the Device for minor change.
|
||||
*/
|
||||
#define IDENTIFICATION_MODULE_REV_MINOR 0x004
|
||||
|
||||
|
||||
/**
|
||||
* @def SYSTEM_MODE_GPIO0
|
||||
* @brief Configures polarity and select which function gpio 0 serves.
|
||||
* Gpio0 is chip enable at power up ! Be aware of all h/w implication of turning it to output.
|
||||
* Same definition as #SYSTEM_MODE_GPIO1
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSTEM_MODE_GPIO0 0x010
|
||||
/**
|
||||
* @def SYSTEM_MODE_GPIO1
|
||||
* @brief Configures polarity and select what ranging functionality gpio pin serves.
|
||||
*
|
||||
* Function can be #GPIOx_SELECT_OFF #GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT.\n
|
||||
* Same definition apply to register GPIO0 that is used as chip enable at power up.
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSTEM_MODE_GPIO1 0x011
|
||||
/** gpio pad POLARITY mask in #SYSTEM_MODE_GPIO1 (and/or 0) write 1 to set active high polarity (positive edge) */
|
||||
#define GPIOx_POLARITY_SELECT_MASK 0x20
|
||||
/** gpio pad Function select shift in #SYSTEM_MODE_GPIO1 or 0 */
|
||||
#define GPIOx_FUNCTIONALITY_SELECT_SHIFT 1
|
||||
/** gpio pad Function select mask in #SYSTEM_MODE_GPIO1 or 0 */
|
||||
#define GPIOx_FUNCTIONALITY_SELECT_MASK (0xF<<GPIOx_FUNCTIONALITY_SELECT_SHIFT)
|
||||
/** select no interrupt in #SYSTEM_MODE_GPIO1 pad is put in Hi-Z*/
|
||||
#define GPIOx_SELECT_OFF 0x00
|
||||
/** select gpiox as interrupt output in #SYSTEM_MODE_GPIO1 */
|
||||
#define GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT 0x08
|
||||
/** select range as source for interrupt on in #SYSTEM_MODE_GPIO1 */
|
||||
#define GPIOx_MODE_SELECT_RANGING 0x00
|
||||
|
||||
|
||||
/**
|
||||
* @def SYSTEM_INTERRUPT_CONFIG_GPIO
|
||||
*
|
||||
* @brief Configure Ranging interrupt reporting
|
||||
*
|
||||
* Possible values for Range \n
|
||||
*
|
||||
* #CONFIG_GPIO_INTERRUPT_DISABLED\n
|
||||
* #CONFIG_GPIO_INTERRUPT_LEVEL_LOW\n
|
||||
* #CONFIG_GPIO_INTERRUPT_LEVEL_HIGH\n
|
||||
* #CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW\n
|
||||
* #CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY\n
|
||||
* Apply respective rang shift and mask \n
|
||||
* #CONFIG_GPIO_RANGE_SHIFT and full reg mask #CONFIG_GPIO_RANGE_MASK\n
|
||||
*
|
||||
* \sa GPIO use for interrupt #SYSTEM_MODE_GPIO0 or #SYSTEM_MODE_GPIO1\n
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSTEM_INTERRUPT_CONFIG_GPIO 0x014
|
||||
/** RANGE bits shift in #SYSTEM_INTERRUPT_CONFIG_GPIO */
|
||||
#define CONFIG_GPIO_RANGE_SHIFT 0
|
||||
/** RANGE bits mask in #SYSTEM_INTERRUPT_CONFIG_GPIO (unshifted)*/
|
||||
#define CONFIG_GPIO_RANGE_MASK (0x7<<CONFIG_GPIO_RANGE_SHIFT)
|
||||
/** interrupt is disabled */
|
||||
#define CONFIG_GPIO_INTERRUPT_DISABLED 0x00
|
||||
/** trigger when value < low threshold */
|
||||
#define CONFIG_GPIO_INTERRUPT_LEVEL_LOW 0x01
|
||||
/** trigger when value < low threshold */
|
||||
#define CONFIG_GPIO_INTERRUPT_LEVEL_HIGH 0x02
|
||||
/** trigger when outside range defined by high low threshold */
|
||||
#define CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW 0x03
|
||||
/** trigger when new sample are ready */
|
||||
#define CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY 0x04
|
||||
|
||||
/**
|
||||
* @def SYSTEM_INTERRUPT_CLEAR
|
||||
* @brief Writing to this register will clear interrupt source
|
||||
*
|
||||
* Use or combination of any #INTERRUPT_CLEAR_RANGING , #INTERRUPT_CLEAR_ERROR
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSTEM_INTERRUPT_CLEAR 0x015
|
||||
/** clear ranging interrupt in write to #SYSTEM_INTERRUPT_CLEAR */
|
||||
#define INTERRUPT_CLEAR_RANGING 0x01
|
||||
/** clear error interrupt in write to #SYSTEM_INTERRUPT_CLEAR */
|
||||
#define INTERRUPT_CLEAR_ERROR 0x04
|
||||
|
||||
/** After power up or reset this register will start reading 1 when device is ready */
|
||||
#define SYSTEM_FRESH_OUT_OF_RESET 0x016
|
||||
|
||||
/**
|
||||
* @def SYSTEM_GROUPED_PARAMETER_HOLD
|
||||
* @brief Writing 1/0 activate/deactivate safe host update of multiple register in critical group \n
|
||||
* rather use \a VL6180_SetGroupParamHold()
|
||||
*
|
||||
* The critical register group is made of: \n
|
||||
* #SYSTEM_INTERRUPT_CONFIG_GPIO \n
|
||||
* #SYSRANGE_THRESH_HIGH \n
|
||||
* #SYSRANGE_THRESH_LOW \n
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSTEM_GROUPED_PARAMETER_HOLD 0x017
|
||||
|
||||
|
||||
/**
|
||||
* @def SYSRANGE_START
|
||||
* @brief Start/stop and set operating range mode
|
||||
*
|
||||
* Write Combination of #MODE_START_STOP and #MODE_CONTINUOUS to select and start desired operation.
|
||||
*
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSRANGE_START 0x018
|
||||
/** mask existing bit in #SYSRANGE_START*/
|
||||
#define SYSRANGE_START_MODE_MASK 0x03
|
||||
/** bit 0 in #SYSRANGE_START write 1 toggle state in continuous mode and arm next shot in single shot mode */
|
||||
#define MODE_START_STOP 0x01
|
||||
/** bit 1 write 1 in #SYSRANGE_START set continuous operation mode */
|
||||
#define MODE_CONTINUOUS 0x02
|
||||
/** bit 1 write 0 in #SYSRANGE_START set single shot mode */
|
||||
#define MODE_SINGLESHOT 0x00
|
||||
|
||||
/**
|
||||
* @def SYSRANGE_THRESH_HIGH
|
||||
* High level range threshold (must be scaled)
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSRANGE_THRESH_HIGH 0x019
|
||||
|
||||
/**
|
||||
* @def SYSRANGE_THRESH_LOW
|
||||
* Low level range threshold (must be scaled)
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSRANGE_THRESH_LOW 0x01A
|
||||
|
||||
/**
|
||||
* @def SYSRANGE_INTERMEASUREMENT_PERIOD
|
||||
* @brief Continuous mode intermeasurement delay \a VL6180_RangeSetInterMeasPeriod()
|
||||
*
|
||||
* Time delay between measurements in Ranging continuous mode.\n
|
||||
* Range 0-254 (0 = 10ms).\n Step size = 10ms.
|
||||
*
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSRANGE_INTERMEASUREMENT_PERIOD 0x01B
|
||||
|
||||
/**
|
||||
* @brief Maximum time to run measurement in Ranging modes.
|
||||
* Range 1 - 63 ms (1 code = 1 ms);
|
||||
*
|
||||
* Measurement aborted when limit reached to aid power reduction.\
|
||||
* For example, 0x01 = 1ms, 0x0a = 10ms.\
|
||||
* Note: Effective max_convergence_time depends on readout_averaging_sample_period setting.
|
||||
*
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSRANGE_MAX_CONVERGENCE_TIME 0x01C
|
||||
/**@brief Cross talk compensation rate
|
||||
* @warning never write register directly use @a VL6180_SetXTalkCompensationRate()
|
||||
* refer to manual for calibration procedure and computation
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define SYSRANGE_CROSSTALK_COMPENSATION_RATE 0x01E
|
||||
/**
|
||||
* @brief Minimum range value in mm to qualify for crosstalk compensation
|
||||
*/
|
||||
#define SYSRANGE_CROSSTALK_VALID_HEIGHT 0x021
|
||||
#define SYSRANGE_EARLY_CONVERGENCE_ESTIMATE 0x022
|
||||
#define SYSRANGE_PART_TO_PART_RANGE_OFFSET 0x024
|
||||
/**
|
||||
* @brief range ignore valid height
|
||||
* @warning do not program directly use @a VL6180_RangeIgnoreConfigure() and @a VL6180_RangeIgnoreSetEnable()
|
||||
*/
|
||||
#define SYSRANGE_RANGE_IGNORE_VALID_HEIGHT 0x025
|
||||
/**
|
||||
* @brief range ignore threshold
|
||||
* @warning do not program directly use @a VL6180_RangeIgnoreConfigure() and @a VL6180_RangeIgnoreSetEnable()
|
||||
*/
|
||||
#define SYSRANGE_RANGE_IGNORE_THRESHOLD 0x026
|
||||
#define SYSRANGE_EMITTER_BLOCK_THRESHOLD 0x028
|
||||
#define SYSRANGE_MAX_AMBIENT_LEVEL_THRESH 0x02A
|
||||
#define SYSRANGE_MAX_AMBIENT_LEVEL_MULT 0x02C
|
||||
/** @brief various Enable check enable register
|
||||
* @a VL6180_RangeSetEceState()
|
||||
* @a VL6180_RangeIgnoreConfigure() and @a VL6180_RangeIgnoreSetEnable()
|
||||
*/
|
||||
#define SYSRANGE_RANGE_CHECK_ENABLES 0x02D
|
||||
#define RANGE_CHECK_ECE_ENABLE_MASK 0x01
|
||||
#define RANGE_CHECK_RANGE_ENABLE_MASK 0x02
|
||||
#define RANGE_CHECK_SNR_ENABLE 0x10
|
||||
|
||||
#define SYSRANGE_VHV_RECALIBRATE 0x02E
|
||||
#define SYSRANGE_VHV_REPEAT_RATE 0x031
|
||||
|
||||
|
||||
/**
|
||||
* @brief Result range status
|
||||
*
|
||||
* Hold the various range interrupt flags and error Specific error codes
|
||||
*/
|
||||
#define RESULT_RANGE_STATUS 0x04D
|
||||
/** Device ready for new command bit 0*/
|
||||
#define RANGE_DEVICE_READY_MASK 0x01
|
||||
/** mask for error status covers bits [7:4] in #RESULT_RANGE_STATUS @a ::RangeError_u */
|
||||
#define RANGE_ERROR_CODE_MASK 0xF0 /* */
|
||||
/** range error bit position in #RESULT_RANGE_STATUS */
|
||||
#define RANGE_ERROR_CODE_SHIFT 4
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* these union can be use as a generic bit field type for map #RESULT_INTERRUPT_STATUS_GPIO register
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
typedef union IntrStatus_u {
|
||||
uint8_t val; /*!< raw 8 bit register value*/
|
||||
struct {
|
||||
unsigned Range:3; /*!< Range status one of :\n \a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n \a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n \a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n \a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY */
|
||||
unsigned Error:2; /*!< Error status of: \n \a #RES_INT_ERROR_LASER_SAFETY \n \a #RES_INT_ERROR_PLL */
|
||||
} status; /*!< interrupt status as bit field */
|
||||
} IntrStatus_t;
|
||||
|
||||
/**
|
||||
* @def RESULT_INTERRUPT_STATUS_GPIO
|
||||
* @brief System interrupt status report selected interrupt for ranging
|
||||
*
|
||||
* These register can be polled even if no gpio pins is active\n
|
||||
* What reported is selected by \a #SYSTEM_INTERRUPT_CONFIG_GPIO \n
|
||||
* Range mask with \a #RES_INT_RANGE_MASK and shit by \a #RES_INT_RANGE_SHIFT
|
||||
* Result value express condition (or combination?)
|
||||
* \a #RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD \n
|
||||
* \a #RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD \n
|
||||
* \a #RES_INT_STAT_GPIO_OUT_OF_WINDOW \n
|
||||
* \a #RES_INT_STAT_GPIO_NEW_SAMPLE_READY
|
||||
*
|
||||
* @ingroup device_regdef
|
||||
*/
|
||||
#define RESULT_INTERRUPT_STATUS_GPIO 0x4F
|
||||
/** ranging interrupt 1st bit position in #RESULT_INTERRUPT_STATUS_GPIO */
|
||||
#define RES_INT_RANGE_SHIFT 0
|
||||
/** interrupt bit position in #RESULT_INTERRUPT_STATUS_GPIO */
|
||||
#define RES_INT_ERROR_SHIFT 6
|
||||
/** Ranging interrupt mask in #RESULT_INTERRUPT_STATUS_GPIO (prior to shift) \sa IntrStatus_t */
|
||||
#define RES_INT_RANGE_MASK (0x7<<RES_INT_RANGE_SHIFT)
|
||||
|
||||
/** low threshold condition in #RESULT_INTERRUPT_STATUS_GPIO */
|
||||
#define RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD 0x01
|
||||
/** high threshold condition in #RESULT_INTERRUPT_STATUS_GPIO for Range*/
|
||||
#define RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD 0x02
|
||||
/** out of window condition in #RESULT_INTERRUPT_STATUS_GPIO */
|
||||
#define RES_INT_STAT_GPIO_OUT_OF_WINDOW 0x03
|
||||
/** new sample ready in #RESULT_INTERRUPT_STATUS_GPIO */
|
||||
#define RES_INT_STAT_GPIO_NEW_SAMPLE_READY 0x04
|
||||
/** error in #RESULT_INTERRUPT_STATUS_GPIO */
|
||||
#define RES_INT_ERROR_MASK (0x3<<RES_INT_ERROR_SHIFT)
|
||||
/** laser safety error on #RES_INT_ERROR_MASK of #RESULT_INTERRUPT_STATUS_GPIO */
|
||||
#define RES_INT_ERROR_LASER_SAFETY 1
|
||||
/** pll 1 or 2 error on #RES_INT_ERROR_MASK of #RESULT_INTERRUPT_STATUS_GPIO*/
|
||||
#define RES_INT_ERROR_PLL 2
|
||||
|
||||
/**
|
||||
* Final range result value presented to the user for use. Unit is in mm.
|
||||
*/
|
||||
#define RESULT_RANGE_VAL 0x062
|
||||
|
||||
/**
|
||||
* Raw Range result value with offset applied (no cross talk compensation applied). Unit is in mm.
|
||||
*/
|
||||
#define RESULT_RANGE_RAW 0x064
|
||||
|
||||
/**
|
||||
* @brief Sensor count rate of signal returns correlated to IR emitter.
|
||||
*
|
||||
* Computed from RETURN_SIGNAL_COUNT / RETURN_CONV_TIME. Mcps 9.7 format
|
||||
*/
|
||||
#define RESULT_RANGE_SIGNAL_RATE 0x066
|
||||
|
||||
/**
|
||||
* @brief Return signal count
|
||||
*
|
||||
* Sensor count output value attributed to signal correlated to IR emitter on the Return array.
|
||||
*/
|
||||
#define RESULT_RANGE_RETURN_SIGNAL_COUNT 0x06C
|
||||
|
||||
/**
|
||||
* @brief Reference signal count
|
||||
*
|
||||
* sensor count output value attributed to signal correlated to IR emitter on the Reference array.
|
||||
*/
|
||||
#define RESULT_RANGE_REFERENCE_SIGNAL_COUNT 0x070
|
||||
|
||||
/**
|
||||
* @brief Return ambient count
|
||||
*
|
||||
* sensor count output value attributed to uncorrelated ambient signal on the Return array.
|
||||
* Must be multiplied by 6 if used to calculate the ambient to signal threshold
|
||||
*/
|
||||
#define RESULT_RANGE_RETURN_AMB_COUNT 0x074
|
||||
|
||||
/**
|
||||
* @brief Reference ambient count
|
||||
*
|
||||
* Sensor count output value attributed to uncorrelated ambient signal on the Reference array.
|
||||
*/
|
||||
#define RESULT_RANGE_REFERENCE_AMB_COUNT 0x078
|
||||
|
||||
/**
|
||||
* sensor count output value attributed to signal on the Return array.
|
||||
*/
|
||||
#define RESULT_RANGE_RETURN_CONV_TIME 0x07C
|
||||
|
||||
/**
|
||||
* sensor count output value attributed to signal on the Reference array.
|
||||
*/
|
||||
#define RESULT_RANGE_REFERENCE_CONV_TIME 0x080
|
||||
|
||||
|
||||
/**
|
||||
* @def RANGE_SCALER
|
||||
* @brief RANGE scaling register
|
||||
*
|
||||
* Never should user write directly onto that register directly \a VL6180_UpscaleSetScaling()
|
||||
*/
|
||||
#define RANGE_SCALER 0x096
|
||||
|
||||
/**
|
||||
* @def READOUT_AVERAGING_SAMPLE_PERIOD
|
||||
* @brief Readout averaging sample period register
|
||||
*
|
||||
*
|
||||
* The internal readout averaging sample period can be adjusted from 0 to 255.
|
||||
* Increasing the sampling period decreases noise but also reduces the effective
|
||||
* max convergence time and increases power consumption
|
||||
* Each unit sample period corresponds to around 64.5 μs additional processing time.
|
||||
* The recommended setting is 48 which equates to around 4.3 ms.
|
||||
*
|
||||
* see datasheet for more detail
|
||||
*/
|
||||
#define READOUT_AVERAGING_SAMPLE_PERIOD 0x10A
|
||||
|
||||
/**
|
||||
* @def I2C_SLAVE_DEVICE_ADDRESS
|
||||
* User programmable I2C address (7-bit). Device address can be re-designated after power-up.
|
||||
* @warning What programmed in the register 7-0 are bit 8-1 of i2c address on bus (bit 0 is rd/wr)
|
||||
* so what prohamd is commonly whar ergfer as adrerss /2
|
||||
* @sa VL6180_SetI2CAddress()
|
||||
*/
|
||||
#define I2C_SLAVE_DEVICE_ADDRESS 0x212
|
||||
|
||||
#endif /* _VL6180_DEF */
|
||||
139
main_prog/vl6180/App/custom_bus.h
Normal file
139
main_prog/vl6180/App/custom_bus.h
Normal file
@@ -0,0 +1,139 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : custom_bus.h
|
||||
* @brief : header file for the BSP BUS IO driver
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef CUSTOM_BUS_H
|
||||
#define CUSTOM_BUS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "custom_conf.h"
|
||||
#include "custom_errno.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CUSTOM
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_BUS CUSTOM BUS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_BUS_Exported_Constants CUSTOM BUS Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define BUS_I2C1_INSTANCE I2C1
|
||||
#define BUS_I2C1_SCL_GPIO_PORT GPIOB
|
||||
#define BUS_I2C1_SCL_GPIO_AF GPIO_AF4_I2C1
|
||||
#define BUS_I2C1_SCL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define BUS_I2C1_SCL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#define BUS_I2C1_SCL_GPIO_PIN GPIO_PIN_8
|
||||
#define BUS_I2C1_SDA_GPIO_PIN GPIO_PIN_9
|
||||
#define BUS_I2C1_SDA_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#define BUS_I2C1_SDA_GPIO_PORT GPIOB
|
||||
#define BUS_I2C1_SDA_GPIO_AF GPIO_AF4_I2C1
|
||||
#define BUS_I2C1_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
|
||||
#ifndef BUS_I2C1_POLL_TIMEOUT
|
||||
#define BUS_I2C1_POLL_TIMEOUT 0x1000U
|
||||
#endif
|
||||
/* I2C1 Frequeny in Hz */
|
||||
#ifndef BUS_I2C1_FREQUENCY
|
||||
#define BUS_I2C1_FREQUENCY 1000000U /* Frequency of I2Cn = 100 KHz*/
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_BUS_Private_Types CUSTOM BUS Private types
|
||||
* @{
|
||||
*/
|
||||
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1U)
|
||||
typedef struct
|
||||
{
|
||||
pI2C_CallbackTypeDef pMspInitCb;
|
||||
pI2C_CallbackTypeDef pMspDeInitCb;
|
||||
}BSP_I2C_Cb_t;
|
||||
#endif /* (USE_HAL_I2C_REGISTER_CALLBACKS == 1U) */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_LOW_LEVEL_Exported_Variables LOW LEVEL Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup CUSTOM_BUS_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* BUS IO driver over I2C Peripheral */
|
||||
HAL_StatusTypeDef MX_I2C1_Init(I2C_HandleTypeDef* hi2c);
|
||||
int32_t BSP_I2C1_Init(void);
|
||||
int32_t BSP_I2C1_DeInit(void);
|
||||
int32_t BSP_I2C1_IsReady(uint16_t DevAddr, uint32_t Trials);
|
||||
int32_t BSP_I2C1_WriteReg(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length);
|
||||
int32_t BSP_I2C1_ReadReg(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length);
|
||||
int32_t BSP_I2C1_WriteReg16(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length);
|
||||
int32_t BSP_I2C1_ReadReg16(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length);
|
||||
int32_t BSP_I2C1_Send(uint16_t DevAddr, uint8_t *pData, uint16_t Length);
|
||||
int32_t BSP_I2C1_Recv(uint16_t DevAddr, uint8_t *pData, uint16_t Length);
|
||||
int32_t BSP_I2C1_SendRecv(uint16_t DevAddr, uint8_t *pTxdata, uint8_t *pRxdata, uint16_t Length);
|
||||
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1U)
|
||||
int32_t BSP_I2C1_RegisterDefaultMspCallbacks (void);
|
||||
int32_t BSP_I2C1_RegisterMspCallbacks (BSP_I2C_Cb_t *Callbacks);
|
||||
#endif /* (USE_HAL_I2C_REGISTER_CALLBACKS == 1U) */
|
||||
|
||||
int32_t BSP_GetTick(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CUSTOM_BUS_H */
|
||||
|
||||
82
main_prog/vl6180/App/custom_conf.h
Normal file
82
main_prog/vl6180/App/custom_conf.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : custom_conf.h
|
||||
* @brief : Configuration file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef CUSTOM_CONF_H
|
||||
#define CUSTOM_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup CUSTOM
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_CONFIG Config
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup CUSTOM_CONFIG_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
/* COM Feature define */
|
||||
#define USE_BSP_COM_FEATURE 1U
|
||||
|
||||
/* COM define */
|
||||
#define USE_COM_LOG 1U
|
||||
|
||||
/* IRQ priorities */
|
||||
#define BSP_BUTTON_USER_IT_PRIORITY 15U
|
||||
|
||||
/* I2C1 Frequeny in Hz */
|
||||
#define BUS_I2C1_FREQUENCY 100000U /* Frequency of I2C1 = 100 KHz*/
|
||||
|
||||
/* SPI1 Baud rate in bps */
|
||||
#define BUS_SPI1_BAUDRATE 16000000U /* baud rate of SPIn = 16 Mbps */
|
||||
|
||||
/* UART1 Baud rate in bps */
|
||||
#define BUS_UART1_BAUDRATE 9600U /* baud rate of UARTn = 9600 baud */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* CUSTOM_CONF_H */
|
||||
|
||||
58
main_prog/vl6180/App/custom_errno.h
Normal file
58
main_prog/vl6180/App/custom_errno.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : custom_errno.h
|
||||
* @brief : Error Code
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef CUSTOM_ERRNO_H
|
||||
#define CUSTOM_ERRNO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* BSP Common Error codes */
|
||||
#define BSP_ERROR_NONE 0
|
||||
#define BSP_ERROR_NO_INIT -1
|
||||
#define BSP_ERROR_WRONG_PARAM -2
|
||||
#define BSP_ERROR_BUSY -3
|
||||
#define BSP_ERROR_PERIPH_FAILURE -4
|
||||
#define BSP_ERROR_COMPONENT_FAILURE -5
|
||||
#define BSP_ERROR_UNKNOWN_FAILURE -6
|
||||
#define BSP_ERROR_UNKNOWN_COMPONENT -7
|
||||
#define BSP_ERROR_BUS_FAILURE -8
|
||||
#define BSP_ERROR_CLOCK_FAILURE -9
|
||||
#define BSP_ERROR_MSP_FAILURE -10
|
||||
#define BSP_ERROR_FEATURE_NOT_SUPPORTED -11
|
||||
|
||||
/* BSP BUS error codes */
|
||||
|
||||
#define BSP_ERROR_BUS_TRANSACTION_FAILURE -100
|
||||
#define BSP_ERROR_BUS_ARBITRATION_LOSS -101
|
||||
#define BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE -102
|
||||
#define BSP_ERROR_BUS_PROTOCOL_FAILURE -103
|
||||
|
||||
#define BSP_ERROR_BUS_MODE_FAULT -104
|
||||
#define BSP_ERROR_BUS_FRAME_ERROR -105
|
||||
#define BSP_ERROR_BUS_CRC_ERROR -106
|
||||
#define BSP_ERROR_BUS_DMA_FAILURE -107
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*CUSTOM_ERRNO_H */
|
||||
|
||||
257
main_prog/vl6180/App/vl6180_app.c
Normal file
257
main_prog/vl6180/App/vl6180_app.c
Normal file
@@ -0,0 +1,257 @@
|
||||
//
|
||||
// Created by Professional on 7/31/2023.
|
||||
//
|
||||
#include "stdint-gcc.h"
|
||||
#include "vl6180_def.h"
|
||||
#include "stm32g0xx_hal.h"
|
||||
#include "vl6180_api.h"
|
||||
#include "main.h"
|
||||
#include "i2c.h"
|
||||
|
||||
#define max_scale 1
|
||||
uint8_t changeScale = 0;
|
||||
#define ALLOW_DISABLE_WAF_FROM_BLUE_BUTTON 1
|
||||
#define theVL6180Dev 0x52 // what we use as "API device
|
||||
#define def_i2c_time_out 100
|
||||
#if VL6180_HAVE_DMAX_RANGING
|
||||
#define DMaxDispTime 0 /* Set to 1000 to display Dmax during 1 sec when no target is detected */
|
||||
#else
|
||||
#define DMaxDispTime 0
|
||||
#endif
|
||||
#define OutORangeDispfTime 800
|
||||
|
||||
#define g_TickCnt uwTick
|
||||
|
||||
enum runmode_t{
|
||||
RunRangePoll=0,
|
||||
RunAlsPoll,
|
||||
InitErr,
|
||||
ScaleSwap,
|
||||
WaitForReset,
|
||||
AlrmStart,
|
||||
AlrmRun,
|
||||
FromSwitch,
|
||||
};
|
||||
|
||||
char buffer[10];
|
||||
|
||||
struct state_t {
|
||||
int OutofRAnge:1;
|
||||
int AutoScale:1;
|
||||
int FilterEn:1;
|
||||
uint8_t mode;
|
||||
int8_t ScaleSwapCnt;
|
||||
uint8_t InitScale;
|
||||
|
||||
uint8_t CurAlrm;
|
||||
uint8_t AlrmFired; /* just used to keep display at least min time */
|
||||
}State;
|
||||
|
||||
uint32_t TimeStarted; /* various display and mode delay starting time */
|
||||
VL6180_RangeData_t Range; /* Range measurmeent */
|
||||
|
||||
int alpha =(int)(0.85*(1<<16)); /* range distance running average cofs */
|
||||
uint16_t range; /* range average distance */
|
||||
|
||||
#define AutoThreshHigh 80 /*auto scale high thresh => AutoThreshHigh * max_raneg => scale ++ */
|
||||
#define AutoThreshLow 33 /*auto scale low thresh => AutoThreshHigh * max_raneg => scale ++ */
|
||||
#define ErrRangeDispTime 0 /* Set to 800 ms to display error code when no target os detected */
|
||||
#if ErrRangeDispTime == 0
|
||||
/* supress Warning[Pe186]: pointless comparison of unsigned integer with zero */
|
||||
# ifdef __ARMCC_VERSION /* ARM/KEIL */
|
||||
# pragma diag_suppress 186
|
||||
# endif /* _ARMCC_VERSION */
|
||||
# ifdef __ICCARM__ /* IAR */
|
||||
# pragma diag_suppress=Pe186
|
||||
# endif /* _ARMCC_VERSION */
|
||||
#endif
|
||||
|
||||
#define AlrmDispTime 800
|
||||
|
||||
#define AlarmKeepDispTime 250 /* alarm message retain time after it fires */
|
||||
volatile int IntrFired=0;
|
||||
|
||||
extern volatile uint32_t SensorsEnabled;
|
||||
|
||||
|
||||
|
||||
void AbortErr( const char * msg ){
|
||||
State.mode= WaitForReset;
|
||||
}
|
||||
|
||||
void DoScalingSwap(int scaling){
|
||||
|
||||
State.mode = ScaleSwap;
|
||||
TimeStarted=g_TickCnt;
|
||||
}
|
||||
uint8_t allowIT = 0;
|
||||
void vl6180_init (void)
|
||||
{
|
||||
allowIT = 0;
|
||||
HAL_GPIO_WritePin(CS_PROXIMITY_GPIO_Port, CS_PROXIMITY_Pin, GPIO_PIN_RESET);
|
||||
HAL_Delay(200);
|
||||
HAL_GPIO_WritePin(CS_PROXIMITY_GPIO_Port, CS_PROXIMITY_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(200);
|
||||
VL6180_WaitDeviceBooted(theVL6180Dev);
|
||||
VL6180_InitData(theVL6180Dev);
|
||||
allowIT = 1;
|
||||
HAL_GPIO_WritePin(CS_PROXIMITY_GPIO_Port, CS_PROXIMITY_Pin, GPIO_PIN_RESET);
|
||||
HAL_Delay(200);
|
||||
HAL_GPIO_WritePin(CS_PROXIMITY_GPIO_Port, CS_PROXIMITY_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(200);
|
||||
VL6180_WaitDeviceBooted(theVL6180Dev);
|
||||
VL6180_InitData(theVL6180Dev);
|
||||
State.InitScale=VL6180_UpscaleGetScaling(theVL6180Dev);
|
||||
State.FilterEn=VL6180_FilterGetState(theVL6180Dev);
|
||||
VL6180_Prepare(theVL6180Dev);
|
||||
VL6180_RangeSetMaxConvergenceTime(theVL6180Dev, 20);
|
||||
VL6180_RangeSetInterMeasPeriod(theVL6180Dev, 25);
|
||||
//State.InitScale=VL6180_UpscaleGetScaling(theVL6180Dev);
|
||||
/* Enable Dmax calculation only if value is displayed (to save computation power) */
|
||||
//VL6180_DMaxSetState(theVL6180Dev, DMaxDispTime>0);
|
||||
VL6180_ClearAllInterrupt(theVL6180Dev);
|
||||
VL6180_RangeStartContinuousMode(theVL6180Dev);
|
||||
}
|
||||
|
||||
|
||||
int VL6180_I2CRead(VL6180Dev_t addr, uint8_t *buff, uint8_t len){
|
||||
int status;
|
||||
status = HAL_I2C_Master_Receive(&hi2c2, addr, buff, len , def_i2c_time_out);
|
||||
if( status ){
|
||||
MX_I2C2_Init();
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_I2CWrite(VL6180Dev_t addr, uint8_t *buff, uint8_t len){
|
||||
int status;
|
||||
status = HAL_I2C_Master_Transmit(&hi2c2, addr, buff, len , def_i2c_time_out);
|
||||
if( status ){
|
||||
MX_I2C2_Init();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
void RangeState(void) {
|
||||
HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_Pin);
|
||||
int status;
|
||||
uint16_t hlimit;
|
||||
uint8_t scaling;
|
||||
VL6180_RangeGetMeasurement(theVL6180Dev, &Range );
|
||||
scaling = VL6180_UpscaleGetScaling(theVL6180Dev);
|
||||
if (Range.errorStatus) {
|
||||
AbortErr("Er r");
|
||||
return;
|
||||
}
|
||||
|
||||
hlimit = VL6180_GetUpperLimit(theVL6180Dev);
|
||||
if (Range.range_mm >= (hlimit * AutoThreshHigh) / 100 && scaling < 3 && State.AutoScale) {
|
||||
VL6180_UpscaleSetScaling(theVL6180Dev, scaling + 1);
|
||||
}
|
||||
if (Range.range_mm < (hlimit * AutoThreshLow) / 100 && scaling > 1 && State.AutoScale) {
|
||||
VL6180_UpscaleSetScaling(theVL6180Dev, scaling - 1);
|
||||
}
|
||||
|
||||
if (Range.errorStatus) {
|
||||
/* no valid ranging*/
|
||||
if (State.OutofRAnge) {
|
||||
#if VL6180_HAVE_DMAX_RANGING
|
||||
if (g_TickCnt - TimeStarted >= ErrRangeDispTime && g_TickCnt - TimeStarted < ErrRangeDispTime + DMaxDispTime ){
|
||||
sprintf(buffer, "d%3d", (int)Range.DMax);
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
if(g_TickCnt - TimeStarted < ErrRangeDispTime )
|
||||
{
|
||||
|
||||
sprintf(buffer, "rE%2d", (int) Range.errorStatus);
|
||||
}
|
||||
else{
|
||||
State.OutofRAnge=0; /* back to out of range display */
|
||||
TimeStarted=g_TickCnt;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int FilterEn;
|
||||
#if VL6180_WRAP_AROUND_FILTER_SUPPORT
|
||||
FilterEn = VL6180_FilterGetState(theVL6180Dev);
|
||||
#else
|
||||
#endif
|
||||
if( g_TickCnt - TimeStarted > OutORangeDispfTime ) {
|
||||
State.OutofRAnge = 1;
|
||||
TimeStarted = g_TickCnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
State.OutofRAnge = 0;
|
||||
TimeStarted = g_TickCnt;
|
||||
range = (range * alpha + Range.range_mm * ((1 << 16) - alpha)) >> 16;
|
||||
sprintf(buffer, "r%3d", (int) range);
|
||||
if (State.AutoScale) {
|
||||
if (scaling == 1) {
|
||||
buffer[0] = '_';
|
||||
}
|
||||
else
|
||||
if (scaling == 2)
|
||||
buffer[0] = '=';
|
||||
else
|
||||
buffer[0] = '~';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (changeScale == 1) {
|
||||
changeScale = 0;
|
||||
TimeStarted = g_TickCnt;
|
||||
|
||||
State.ScaleSwapCnt++;
|
||||
if (State.ScaleSwapCnt % (max_scale + 1) == max_scale) {
|
||||
State.AutoScale = 1;
|
||||
scaling = max_scale;
|
||||
}
|
||||
else {
|
||||
#if ALLOW_DISABLE_WAF_FROM_BLUE_BUTTON
|
||||
/* togle filtering every time we roll over all scaling(pass by autoscale) */
|
||||
if (State.AutoScale)
|
||||
State.FilterEn = !State.FilterEn;
|
||||
#endif
|
||||
State.AutoScale = 0;
|
||||
scaling = State.InitScale + (State.ScaleSwapCnt % max_scale);
|
||||
if (scaling > max_scale)
|
||||
scaling = scaling - (max_scale);
|
||||
}
|
||||
|
||||
status = VL6180_UpscaleSetScaling(theVL6180Dev, scaling);
|
||||
if (status<0) {
|
||||
AbortErr("ErUp");
|
||||
State.mode = InitErr;
|
||||
}
|
||||
else {
|
||||
/* do not check status may fail when filter support not active */
|
||||
VL6180_FilterSetState(theVL6180Dev, State.FilterEn);
|
||||
DoScalingSwap(scaling);
|
||||
}
|
||||
}
|
||||
}
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
if (GPIO_Pin == GPIO_PIN_0)
|
||||
{
|
||||
RangeState();
|
||||
if (Range.errorStatus == 0)
|
||||
{
|
||||
__NOP();
|
||||
}
|
||||
VL6180_ClearAllInterrupt(theVL6180Dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/* USER CODE END 4 */
|
||||
9
main_prog/vl6180/App/vl6180_app.h
Normal file
9
main_prog/vl6180/App/vl6180_app.h
Normal file
@@ -0,0 +1,9 @@
|
||||
//
|
||||
// Created by Professional on 7/31/2023.
|
||||
//
|
||||
|
||||
#ifndef MYPROJECT_VL6180_APP_H
|
||||
#define MYPROJECT_VL6180_APP_H
|
||||
|
||||
#endif //MYPROJECT_VL6180_APP_H
|
||||
void vl6180_init (void);
|
||||
92
main_prog/vl6180/Target/vl6180_appcfg.h
Normal file
92
main_prog/vl6180/Target/vl6180_appcfg.h
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
/*******************************************************************************
|
||||
Copyright © 2014, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* vl6180_appcfg.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VL6180_APPCFG_H_
|
||||
#define VL6180_APPCFG_H_
|
||||
|
||||
|
||||
/**
|
||||
* @def VL6180_SINGLE_DEVICE_DRIVER
|
||||
* @brief enable lightweight single vl6180 device driver
|
||||
*
|
||||
* value 1 => single device capable
|
||||
* Configure optimized APi for single device driver with static data and minimal use of ref pointer \n
|
||||
* limited to single device driver or application in non multi thread/core environment \n
|
||||
*
|
||||
* value 0 => multiple device capable user must review "device" structure and type in porting files
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define VL6180_SINGLE_DEVICE_DRIVER 1
|
||||
|
||||
|
||||
/**
|
||||
* @def VL6180_RANGE_STATUS_ERRSTRING
|
||||
* @brief when define include range status Error string and related
|
||||
*
|
||||
* The string table lookup require some space in read only area
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define VL6180_RANGE_STATUS_ERRSTRING 1
|
||||
|
||||
/**
|
||||
* @def VL6180_SAFE_POLLING_ENTER
|
||||
*
|
||||
* @brief Ensure safe polling method when set
|
||||
*
|
||||
* Polling for a condition can be hazardous and result in infinite looping if any previous interrupt status
|
||||
* condition is not cleared. \n
|
||||
* Setting these flags enforce error clearing on start of polling method to avoid it.
|
||||
* the drawback are : \n
|
||||
* @li extra use-less i2c bus usage and traffic
|
||||
* @li potentially slower measure rate.
|
||||
* If application ensure interrupt get clear on mode or interrupt configuration change
|
||||
* then keep option disabled. \n
|
||||
* To be safe set these option to 1
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define VL6180_SAFE_POLLING_ENTER 0
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable function start/end logging
|
||||
*
|
||||
* requires porting @a #LOG_FUNCTION_START @a #LOG_FUNCTION_END @a #LOG_FUNCTION_END_FMT
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define VL6180_LOG_ENABLE 0
|
||||
|
||||
|
||||
|
||||
#endif /* VL6180_APPCFG_H_ */
|
||||
241
main_prog/vl6180/Target/vl6180_i2c.c
Normal file
241
main_prog/vl6180/Target/vl6180_i2c.c
Normal file
@@ -0,0 +1,241 @@
|
||||
|
||||
/*******************************************************************************
|
||||
Copyright © 2019, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* @file vl6180_i2c.c
|
||||
*
|
||||
* Copyright (C) 2019 ST MicroElectronics
|
||||
*
|
||||
* provide variable word size byte/Word/dword VL6180 register access via i2c
|
||||
*
|
||||
*/
|
||||
#include "vl6180_i2c.h"
|
||||
|
||||
#ifndef I2C_BUFFER_CONFIG
|
||||
#error "I2C_BUFFER_CONFIG not defined"
|
||||
/* TODO you must define value for I2C_BUFFER_CONFIG in configuration or platform h */
|
||||
#endif
|
||||
|
||||
|
||||
#if I2C_BUFFER_CONFIG == 0
|
||||
/* GLOBAL config buffer */
|
||||
uint8_t i2c_global_buffer[VL6180_MAX_I2C_XFER_SIZE];
|
||||
|
||||
#define DECL_I2C_BUFFER
|
||||
#define VL6180_GetI2cBuffer(dev, n_byte) i2c_global_buffer
|
||||
|
||||
#elif I2C_BUFFER_CONFIG == 1
|
||||
/* ON STACK */
|
||||
#define DECL_I2C_BUFFER uint8_t LocBuffer[VL6180_MAX_I2C_XFER_SIZE];
|
||||
#define VL6180_GetI2cBuffer(dev, n_byte) LocBuffer
|
||||
#elif I2C_BUFFER_CONFIG == 2
|
||||
/* user define buffer type declare DECL_I2C_BUFFER as access via VL6180_GetI2cBuffer */
|
||||
#define DECL_I2C_BUFFER
|
||||
#else
|
||||
#error "invalid I2C_BUFFER_CONFIG "
|
||||
#endif
|
||||
|
||||
|
||||
int VL6180_WrByte(VL6180Dev_t dev, uint16_t index, uint8_t data){
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
VL6180_I2C_USER_VAR
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
|
||||
buffer=VL6180_GetI2cBuffer(dev,3);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
buffer[2]=data;
|
||||
|
||||
status=VL6180_I2CWrite(dev, buffer,(uint8_t)3);
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_WrWord(VL6180Dev_t dev, uint16_t index, uint16_t data){
|
||||
int status;
|
||||
DECL_I2C_BUFFER
|
||||
uint8_t *buffer;
|
||||
VL6180_I2C_USER_VAR
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
|
||||
buffer=VL6180_GetI2cBuffer(dev,4);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
buffer[2]=data>>8;
|
||||
buffer[3]=data&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, buffer,(uint8_t)4);
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_WrDWord(VL6180Dev_t dev, uint16_t index, uint32_t data){
|
||||
VL6180_I2C_USER_VAR
|
||||
DECL_I2C_BUFFER
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
buffer=VL6180_GetI2cBuffer(dev,6);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
buffer[2]=data>>24;
|
||||
buffer[3]=(data>>16)&0xFF;
|
||||
buffer[4]=(data>>8)&0xFF;;
|
||||
buffer[5]=data&0xFF;
|
||||
status=VL6180_I2CWrite(dev, buffer,(uint8_t)6);
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_UpdateByte(VL6180Dev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData){
|
||||
VL6180_I2C_USER_VAR
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
|
||||
buffer=VL6180_GetI2cBuffer(dev,3);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, (uint8_t *)buffer,(uint8_t)2);
|
||||
if( !status ){
|
||||
/* read data direct onto buffer */
|
||||
status=VL6180_I2CRead(dev, &buffer[2],1);
|
||||
if( !status ){
|
||||
buffer[2]=(buffer[2]&AndData)|OrData;
|
||||
status=VL6180_I2CWrite(dev, buffer, (uint8_t)3);
|
||||
}
|
||||
}
|
||||
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_RdByte(VL6180Dev_t dev, uint16_t index, uint8_t *data){
|
||||
VL6180_I2C_USER_VAR
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
|
||||
buffer=VL6180_GetI2cBuffer(dev,2);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, buffer, (uint8_t)2);
|
||||
if( !status ){
|
||||
status=VL6180_I2CRead(dev, buffer,1);
|
||||
if( !status ){
|
||||
*data=buffer[0];
|
||||
}
|
||||
}
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_RdWord(VL6180Dev_t dev, uint16_t index, uint16_t *data){
|
||||
VL6180_I2C_USER_VAR
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
|
||||
buffer=VL6180_GetI2cBuffer(dev,2);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, buffer, (uint8_t)2);
|
||||
if( !status){
|
||||
status=VL6180_I2CRead(dev, buffer,2);
|
||||
if( !status ){
|
||||
/* VL6180 register are Big endian if cpu is be direct read direct into *data is possible */
|
||||
*data=((uint16_t)buffer[0]<<8)|(uint16_t)buffer[1];
|
||||
}
|
||||
}
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_RdDWord(VL6180Dev_t dev, uint16_t index, uint32_t *data){
|
||||
VL6180_I2C_USER_VAR
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
buffer=VL6180_GetI2cBuffer(dev,4);
|
||||
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, (uint8_t *) buffer, (uint8_t)2);
|
||||
if( !status ){
|
||||
status=VL6180_I2CRead(dev, buffer,4);
|
||||
if( !status ){
|
||||
/* VL6180 register are Big endian if cpu is be direct read direct into data is possible */
|
||||
*data=((uint32_t)buffer[0]<<24)|((uint32_t)buffer[1]<<16)|((uint32_t)buffer[2]<<8)|((uint32_t)buffer[3]);
|
||||
}
|
||||
}
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
int VL6180_RdMulti(VL6180Dev_t dev, uint16_t index, uint8_t *data, int nData){
|
||||
VL6180_I2C_USER_VAR
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
buffer=VL6180_GetI2cBuffer(dev,2);
|
||||
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, (uint8_t *) buffer, (uint8_t)2);
|
||||
if( !status ){
|
||||
status=VL6180_I2CRead(dev, data, nData);
|
||||
}
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
return status;
|
||||
}
|
||||
166
main_prog/vl6180/Target/vl6180_i2c.h
Normal file
166
main_prog/vl6180/Target/vl6180_i2c.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* $Date: 2015-01-08 14:30:24 +0100 (Thu, 08 Jan 2015) $
|
||||
* $Revision: 2039 $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file vl6180_i2c.h
|
||||
*
|
||||
* @brief CCI interface to "raw i2c" translation layer
|
||||
*/
|
||||
|
||||
#ifndef VL6180_I2C_H_
|
||||
#define VL6180_I2C_H_
|
||||
|
||||
#include "vl6180_platform.h"
|
||||
|
||||
/**
|
||||
* @defgroup cci_i2c CCI to RAW I2C translation layer
|
||||
*
|
||||
* This optional tranlation layer is implemented in __platform/cci-i2c__ directory. If user uses this translation layer for his platform, only @a VL6180_I2CRead() and
|
||||
* @a VL6180_I2CWrite() functions need to be implemented. Also, some code adaption (via macro) is required for multi-threading and for multiple device support.
|
||||
*
|
||||
* File vl6180_i2c.c implements device register access via raw i2c access. If the targeted application and platform has no multi-thread, no multi-cpu and uses single
|
||||
* device, then nothing else is required than the 2 mandatory function : @a VL6180_I2CRead() and @a VL6180_I2CWrite().\n
|
||||
* In other cases, review and customize @a VL6180_GetI2CAccess() and @a VL6180_DoneI2CAccess() functions as well as @a #VL6180_I2C_USER_VAR macro. This should be enough
|
||||
* to conform to a wide range of platform OS and application requirements .\n
|
||||
*
|
||||
* If your configured i2c for per device buffer via @a #I2C_BUFFER_CONFIG == 2, you must implement @a VL6180_GetI2cBuffer()
|
||||
*
|
||||
* __I2C Port sample__ \n
|
||||
* A __linux kernel__ port need a "long flags" var for its spin_lock in all functions. the following code example declares a spin lock "lock" in the custom device structure. \n
|
||||
* @code
|
||||
struct MyVL6180Dev_t {
|
||||
struct VL6180DevData_t StData;
|
||||
...
|
||||
spinlock_t i2c_lock;
|
||||
};
|
||||
typedef struct MyVL6180Dev_t *VL6180Dev_t;
|
||||
|
||||
#define VL6180_I2C_USER_VAR unsigned long flags;
|
||||
#define GetI2CAccess(dev) spin_lock_irqsave(dev->i2c_lock, flags)
|
||||
#define DoneI2CAccess(dev) spin_unlock_irqrestore(dev->i2c_lock,flags)
|
||||
@endcode
|
||||
|
||||
* __POSIX pthread__ application porting could be as follows :\n
|
||||
* @code
|
||||
struct MyVL6180Dev_t {
|
||||
struct VL6180DevData_t StData;
|
||||
...
|
||||
pthread_mutex_t *lock;
|
||||
};
|
||||
typedef struct MyVL6180Dev_t *VL6180Dev_t;
|
||||
|
||||
#define VL6180_I2C_USER_VAR //no need
|
||||
#define VL6180_GetI2CAccess(dev) pthread_mutex_lock(dev->lock)
|
||||
#define VL6180_DoneI2CAcces(dev) pthread_mutex_unlock(dev->lock)
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
/**
|
||||
* @def I2C_BUFFER_CONFIG
|
||||
*
|
||||
* @brief Configure device register I2C access
|
||||
*
|
||||
* @li 0 : one GLOBAL buffer \n
|
||||
* Use one global buffer of MAX_I2C_XFER_SIZE byte in data space \n
|
||||
* This solution is not multi-device compliant nor multi-thread cpu safe \n
|
||||
* It can be the best option for small 8/16 bit MCU without stack and limited ram (STM8s, 80C51 ...)
|
||||
*
|
||||
* @li 1 : ON_STACK/local \n
|
||||
* Use local variable (on stack) buffer \n
|
||||
* This solution is multi-thread with use of i2c resource lock or mutex see @a VL6180_GetI2CAccess() \n
|
||||
*
|
||||
* @li 2 : User defined \n
|
||||
* Per device potentially dynamic allocated. Requires @a VL6180_GetI2cBuffer() to be implemented.
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define I2C_BUFFER_CONFIG 1
|
||||
|
||||
/**
|
||||
* @brief Write data buffer to VL6180 device via i2c
|
||||
* @param dev The device to write to
|
||||
* @param buff The data buffer
|
||||
* @param len The length of the transaction in byte
|
||||
* @return 0 on success
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
int VL6180_I2CWrite(VL6180Dev_t dev, uint8_t *buff, uint8_t len);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Read data buffer from VL6180 device via i2c
|
||||
* @param dev The device to read from
|
||||
* @param buff The data buffer to fill
|
||||
* @param len The length of the transaction in byte
|
||||
* @return 0 on success
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
int VL6180_I2CRead(VL6180Dev_t dev, uint8_t *buff, uint8_t len);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Declare any required variables used by i2c lock (@a VL6180_DoneI2CAccess() and @a VL6180_GetI2CAccess())
|
||||
* and buffer access : @a VL6180_GetI2cBuffer()
|
||||
*
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
#define VL6180_I2C_USER_VAR
|
||||
|
||||
/**
|
||||
* @brief Acquire lock or mutex for access to i2c data buffer and bus.\n
|
||||
* Delete the default VL6180_GetI2CAccess 'do-nothing' macro below if you decide to implement this function.
|
||||
*
|
||||
* This function is used to perform i2c bus level and multiple access locking required for multi thread/proccess system.\n
|
||||
* Multiple access (read and update) will lock once and do multiple basic i2c rd/wr to complete the overall transfer.\n
|
||||
* When no locking is needed this can be a void macro.\n
|
||||
*
|
||||
* @param dev the device
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
void VL6180_GetI2CAccess(VL6180Dev_t dev);
|
||||
|
||||
/**
|
||||
* @def VL6180_GetI2CAccess
|
||||
* @brief Default 'do-nothing' macro for @a VL6180_GetI2CAccess(). Delete if used.
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
#define VL6180_GetI2CAccess(dev) (void)0 /* TODO delete if function used */
|
||||
|
||||
/**
|
||||
* @brief Release acquired lock or mutex for i2c access.\n
|
||||
* Delete default VL6180_DoneI2CAccess 'do-nothing' macro below if implementing that function.
|
||||
*
|
||||
* This function is used to release the acquired lock.
|
||||
* @param dev The device
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
void VL6180_DoneI2CAccess(VL6180Dev_t dev);
|
||||
|
||||
/** @def VL6180_DoneI2CAcces
|
||||
* @brief Default 'do-nothing' macro for @a VL6180_DoneI2CAcces(). Delete if used.
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
#define VL6180_DoneI2CAcces(dev) (void)0 /*TODO delete if function used */
|
||||
|
||||
/**
|
||||
* @brief Provided data buffer for i2c access for at least n_byte.
|
||||
*
|
||||
* You must implement it when i2c @a #I2C_BUFFER_CONFIG is set to 2 (User defined).\n
|
||||
* This is used used in the context of #VL6180_I2C_USER_VAR
|
||||
*
|
||||
* @param dev The device
|
||||
* @param n_byte Minimal number of byte
|
||||
* @return The buffer (cannot fail return not checked)
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
uint8_t *VL6180_GetI2cBuffer(VL6180Dev_t dev, int n_byte);
|
||||
#if I2C_BUFFER_CONFIG == 2
|
||||
#error /* TODO add your macro of code here for VL6180_GetI2cBuffer */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* VL6180_I2C_H_ */
|
||||
115
main_prog/vl6180/Target/vl6180_platform.h
Normal file
115
main_prog/vl6180/Target/vl6180_platform.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2019, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* vl6180_platform.h STM32 Nucelo F401 single device using generic cci-i2c
|
||||
* trace via swo port some GnuArm eclipse toolset */
|
||||
|
||||
#ifndef VL6180_PLATFORM
|
||||
#define VL6180_PLATFORM
|
||||
|
||||
|
||||
#include "vl6180_appcfg.h"
|
||||
#include "vl6180_def.h"
|
||||
|
||||
|
||||
|
||||
#define VL6180_DEV_DATA_ATTR
|
||||
|
||||
#define ROMABLE_DATA
|
||||
/* #define ROMABLE_DATA __attribute__ ((section ("user_rom"))) */
|
||||
|
||||
|
||||
|
||||
#if VL6180_LOG_ENABLE
|
||||
/* dot not include non ansi here trace was a case :( */
|
||||
#ifdef TRACE
|
||||
#include "diag/trace.h"
|
||||
extern volatile uint32_t g_TickCnt;
|
||||
#define LOG_GET_TIME() g_TickCnt
|
||||
#else
|
||||
/* these is nto stm32 vl6180 GNuArm eclpse build*/
|
||||
#define trace_printf(...) (void)0
|
||||
#define LOG_GET_TIME() (int)0 /* add your code here expect to be an integer native (%d) type value */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define LOG_FUNCTION_START(fmt, ... ) \
|
||||
trace_printf("beg %s start @%d\t" fmt "\n", __func__, LOG_GET_TIME(), ##__VA_ARGS__)
|
||||
|
||||
#define LOG_FUNCTION_END(status)\
|
||||
trace_printf("end %s @%d %d\n", __func__, LOG_GET_TIME(), (int)status)
|
||||
|
||||
#define LOG_FUNCTION_END_FMT(status, fmt, ... )\
|
||||
trace_printf("End %s @%d %d\t"fmt"\n" , __func__, LOG_GET_TIME(), (int)status, ##__VA_ARGS__)
|
||||
|
||||
#define VL6180_ErrLog(msg, ... )\
|
||||
do{\
|
||||
trace_printf("ERR in %s line %d\n" msg, __func__, __LINE__, ##__VA_ARGS__);\
|
||||
}while(0)
|
||||
|
||||
#else /* VL6180_LOG_ENABLE no logging */
|
||||
void OnErrLog(void);
|
||||
#define LOG_FUNCTION_START(...) (void)0
|
||||
#define LOG_FUNCTION_END(...) (void)0
|
||||
#define LOG_FUNCTION_END_FMT(...) (void)0
|
||||
#define VL6180_ErrLog(... ) OnErrLog()
|
||||
#endif
|
||||
|
||||
|
||||
#if VL6180_SINGLE_DEVICE_DRIVER
|
||||
typedef uint8_t VL6180Dev_t;
|
||||
|
||||
#else /* VL6180_SINGLE_DEVICE_DRIVER */
|
||||
|
||||
struct MyVL6180Dev_t {
|
||||
struct VL6180DevData_t Data;
|
||||
#if I2C_BUFFER_CONFIG == 2
|
||||
uint8_t i2c_buffer[VL6180_MAX_I2C_XFER_SIZE];
|
||||
#define VL6180_GetI2cBuffer(dev, n) ((dev)->i2c_buffer)
|
||||
#endif
|
||||
};
|
||||
typedef struct MyVL6180Dev_t *VL6180Dev_t;
|
||||
|
||||
#define VL6180DevDataGet(dev, field) (dev->Data.field)
|
||||
#define VL6180DevDataSet(dev, field, data) (dev->Data.field)=(data)
|
||||
|
||||
#endif /* #else VL6180_SINGLE_DEVICE_DRIVER */
|
||||
|
||||
void VL6180_PollDelay(VL6180Dev_t dev);
|
||||
|
||||
void DISP_ExecLoopBody(void);
|
||||
#define VL6180_PollDelay(dev) DISP_ExecLoopBody();
|
||||
|
||||
|
||||
#endif /* VL6180_PLATFORM */
|
||||
|
||||
|
||||
|
||||
62
main_prog/vl6180/Target/vl6180_types.h
Normal file
62
main_prog/vl6180/Target/vl6180_types.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2014, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef VL6180_TYPES_H_
|
||||
#define VL6180_TYPES_H_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h> /* these is for NULL */
|
||||
|
||||
#ifndef NULL
|
||||
#error "review NULL definition or add required include "
|
||||
#endif
|
||||
|
||||
#if !defined(STDINT_H) && !defined(_GCC_STDINT_H) && !defined(__STDINT_DECLS) && !defined(_STDINT) && !defined(_STDINT_H)
|
||||
|
||||
#pragma message("Please review type definition of STDINT define for your platform and add to list above ")
|
||||
|
||||
/*
|
||||
* target platform do not provide stdint or use a different #define than above
|
||||
* to avoid seeing the message below addapt the #define list above or implement
|
||||
* all type and delete these pragma
|
||||
*/
|
||||
|
||||
typedef unsigned int uint32_t;
|
||||
typedef int int32_t;
|
||||
|
||||
typedef unsigned short uint16_t;
|
||||
typedef short int16_t;
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
|
||||
typedef signed char int8_t;
|
||||
|
||||
#endif /* _STDINT_H */
|
||||
|
||||
#endif /* VL6180_TYPES_H_ */
|
||||
Reference in New Issue
Block a user