---vl6180dr
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include "main.h"
|
||||
#include "i2c.h"
|
||||
|
||||
#define max_scale 1
|
||||
#define max_scale 3
|
||||
uint8_t changeScale = 0;
|
||||
#define ALLOW_DISABLE_WAF_FROM_BLUE_BUTTON 1
|
||||
#define theVL6180Dev 0x52 // what we use as "API device
|
||||
@@ -94,13 +94,6 @@ void vl6180_init (void)
|
||||
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);
|
||||
@@ -111,6 +104,7 @@ void vl6180_init (void)
|
||||
//VL6180_DMaxSetState(theVL6180Dev, DMaxDispTime>0);
|
||||
VL6180_ClearAllInterrupt(theVL6180Dev);
|
||||
VL6180_RangeStartContinuousMode(theVL6180Dev);
|
||||
allowIT = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +129,6 @@ int VL6180_I2CWrite(VL6180Dev_t addr, uint8_t *buff, uint8_t len){
|
||||
|
||||
|
||||
void RangeState(void) {
|
||||
HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_Pin);
|
||||
int status;
|
||||
uint16_t hlimit;
|
||||
uint8_t scaling;
|
||||
@@ -159,7 +152,6 @@ void RangeState(void) {
|
||||
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
|
||||
|
||||
@@ -167,7 +159,6 @@ void RangeState(void) {
|
||||
if(g_TickCnt - TimeStarted < ErrRangeDispTime )
|
||||
{
|
||||
|
||||
sprintf(buffer, "rE%2d", (int) Range.errorStatus);
|
||||
}
|
||||
else{
|
||||
State.OutofRAnge=0; /* back to out of range display */
|
||||
@@ -190,7 +181,6 @@ void RangeState(void) {
|
||||
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] = '_';
|
||||
@@ -237,9 +227,10 @@ void RangeState(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
uint32_t resetPressedMs = 0;
|
||||
void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
if (GPIO_Pin == GPIO_PIN_0)
|
||||
if (GPIO_Pin == GPIO_PIN_0 && allowIT == 1)
|
||||
{
|
||||
RangeState();
|
||||
if (Range.errorStatus == 0)
|
||||
@@ -248,10 +239,24 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
}
|
||||
VL6180_ClearAllInterrupt(theVL6180Dev);
|
||||
}
|
||||
else
|
||||
else if (GPIO_Pin == GPIO_PIN_1)
|
||||
{
|
||||
|
||||
uint32_t res = uwTick - resetPressedMs;
|
||||
if (res > 2000 && resetPressedMs > 0 )
|
||||
HAL_NVIC_SystemReset();
|
||||
resetPressedMs = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
|
||||
if (GPIO_Pin == GPIO_PIN_1)
|
||||
{
|
||||
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == GPIO_PIN_RESET)
|
||||
{
|
||||
resetPressedMs = uwTick;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* USER CODE END 4 */
|
||||
Reference in New Issue
Block a user