void range_finder_init() { /* MCU Configuration----------------------------------------------------------*/ /* Initialize all configured peripherals */ MX_I2C1_Init(); tca9545_init(); tca9545_set(Channel_0); /* these almost just redo what already done just above by CubeMx Init */ XNUCLEO6180XA1_GPIO_Init(); XNUCLEO6180XA1_I2C1_Init(&hi2c1); tca9545Channel_e channel; for(channel = Channel_0; channel <= Channel_3; channel++) { tca9545_set(channel); MyDev_Init(myDev); // your code init device variable MyDev_SetChipEnable(myDev); // your code assert chip enable MyDev_uSleep(1000); // your code sleep at least 1 msec VL6180x_InitData(myDev); VL6180x_Prepare(myDev); } }
/** * All in one device init * @param myDev The device * @return 0 on success may @a #CALIBRATION_WARNING <0 on errir */ int Sample_Init(VL6180xDev_t myDev){ int status, init_status; MyDev_Init(myDev); // your code MyDev_SetChipEnable(myDev); // your code MyDev_uSleep(2000); // your code sleep at least 1msec prior to do i2c to device init_status = VL6180x_InitData(myDev); if(init_status == 0 || init_status == CALIBRATION_WARNING ){ status = VL6180x_Prepare(myDev); if( !status ) status=init_status; // if prepare is successfull return potential init warning } return status; }
static int stmvl6180_start(struct stmvl6180_data *data, uint8_t scaling, init_mode_e mode) { int rc = 0; vl6180_dbgmsg("Enter\n"); /* Power up */ rc = data->pmodule_func_tbl->power_up(&data->client_object, &data->reset); if (rc) { vl6180_errmsg("%d,error rc %d\n", __LINE__, rc); return rc; } /* init */ rc = stmvl6180_init_client(data); if (rc) { vl6180_errmsg("%d, error rc %d\n", __LINE__, rc); data->pmodule_func_tbl->power_down(&data->client_object); return -EINVAL; } /* prepare */ VL6180x_Prepare(vl6180x_dev); VL6180x_UpscaleSetScaling(vl6180x_dev, scaling); /* check mode */ if (mode != NORMAL_MODE) { #if VL6180x_WRAP_AROUND_FILTER_SUPPORT /* turn off wrap around filter */ VL6180x_FilterSetState(vl6180x_dev, 0); #endif VL6180x_SetXTalkCompensationRate(vl6180x_dev, 0); VL6180x_UpdateByte(vl6180x_dev, SYSRANGE_RANGE_CHECK_ENABLES, ~RANGE_CHECK_RANGE_ENABLE_MASK, 0); } if (mode == OFFSETCALIB_MODE) VL6180x_SetOffsetCalibrationData(vl6180x_dev, 0); /* start - single shot mode */ VL6180x_RangeSetSystemMode(vl6180x_dev, MODE_START_STOP|MODE_SINGLESHOT); data->ps_is_singleshot = 1; data->enable_ps_sensor = 1; /* enable work handler */ stmvl6180_schedule_handler(data); vl6180_dbgmsg("End\n"); return rc; }
/** * @brief Simplest polling ALS * that may be your main() */ void Sample_SimpleAls(void) { #if VL6180x_ALS_SUPPORT VL6180xDev_t myDev; VL6180x_AlsData_t Als; MyDev_Init(myDev); // your code init device variable MyDev_SetChipEnable(myDev); // your code assert chip enable MyDev_uSleep(1000); // your code sleep at least 1 msec VL6180x_InitData(myDev); VL6180x_Prepare(myDev); do { VL6180x_AlsPollMeasurement(myDev, &Als); if (Als.errorStatus == 0 ) MyDev_ShowLux(myDev, Als.lux); // your code display range in mm else MyDev_ShowErr(myDev, Als.errorStatus); // your code display error code } while (!MyDev_UserSayStop(myDev)); // your code to stop looping #endif }