예제 #1
0
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);
	    }
}
/*
 * Initialization function
 */
static int stmvl6180_init_client(struct stmvl6180_data *data)
{
	uint8_t id = 0, module_major = 0, module_minor = 0;
	uint8_t model_major = 0, model_minor = 0;
	uint8_t i = 0, val;

	vl6180_dbgmsg("Enter\n");

	/* Read Model ID */
	VL6180x_RdByte(vl6180x_dev, VL6180_MODEL_ID_REG, &id);
	vl6180_errmsg("read MODLE_ID: 0x%x\n", id);
	if (id == 0xb4) {
		vl6180_errmsg("STM VL6180 Found\n");
	} else if (id == 0) {
		vl6180_errmsg("Not found STM VL6180\n");
	}

	/* Read Model Version */
	VL6180x_RdByte(vl6180x_dev, VL6180_MODEL_REV_MAJOR_REG, &model_major);
	model_major &= 0x07;
	VL6180x_RdByte(vl6180x_dev, VL6180_MODEL_REV_MINOR_REG, &model_minor);
	model_minor &= 0x07;
	vl6180_errmsg("STM VL6180 Model Version : %d.%d\n", model_major, model_minor);

	/* Read Module Version */
	VL6180x_RdByte(vl6180x_dev, VL6180_MODULE_REV_MAJOR_REG, &module_major);
	VL6180x_RdByte(vl6180x_dev, VL6180_MODULE_REV_MINOR_REG, &module_minor);
	vl6180_errmsg("STM VL6180 Module Version : %d.%d\n", module_major, module_minor);

	/* Read Identification */
	printk("STM VL6180 Serial Numbe: ");
	for (i = 0; i <= (VL6180_FIRMWARE_REVISION_ID_REG - VL6180_REVISION_ID_REG); i++) {
		VL6180x_RdByte(vl6180x_dev, (VL6180_REVISION_ID_REG + i), &val);
		printk("0x%x-", val);
	}
	printk("\n");


	/* intialization */
	if (data->reset) {
		/* no need
		vl6180_dbgmsg("WaitDeviceBoot");
		VL6180x_WaitDeviceBooted(vl6180x_dev);
		*/

		/* only called if device being reset, otherwise data being overwrite */
		vl6180_dbgmsg("Init data!");
		VL6180x_InitData(vl6180x_dev); /* only called if device being reset */
		data->reset = 0;
	}
	/* set user calibration data - need to be called after VL6180x_InitData */
#ifdef CALIBRATION_FILE
	stmvl6180_read_calibration_file();
#endif

	vl6180_dbgmsg("End\n");

	return 0;
}
/**
 * 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;
}
예제 #4
0
/**
 * @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
}