Пример #1
0
static int yas_bma250_set_enable(int enable)
{
	int err;

	/* Check initialize */
	if (acc_data.initialize == 0)
		return YAS_ERROR_NOT_INITIALIZED;

	if (yas_bma250_ischg_enable(enable)) {
		if (enable) {
			/* Open i2c */
			err = yas_bma250_i2c_open();
			if (err != YAS_NO_ERROR)
				return err;
			/* Reset chip */
			yas_bma250_write_reg_byte(YAS_BMA250_SOFT_RESET_REG,
				YAS_BMA250_SOFT_RESET_VAL);
			yas_bma250_msleep(5);
			/* Set axes range*/
			yas_bma250_update_bits(YAS_BMA250_RANGE,
				YAS_BMA250_RANGE_2G);
			yas_bma250_set_delay(acc_data.delay);
			yas_bma250_power_up();
		} else {
			yas_bma250_power_down();
			err = yas_bma250_i2c_close();
			if (err != YAS_NO_ERROR)
				return err;
		}
	}

acc_data.enable = enable;

return YAS_NO_ERROR;
}
static int yas_bma250_init(void)
{
	struct yas_acc_filter filter;
	int err;
	int id;

	/* Check intialize */
	if (acc_data.initialize == 1)
		return YAS_ERROR_NOT_INITIALIZED;

	/* Init data */
	yas_bma250_init_data();

	/* Open i2c */
	err = yas_bma250_i2c_open();
	if (err != YAS_NO_ERROR)
		return err;

	/* Check id */
	id = yas_bma250_read_reg_byte(YAS_BMA250_CHIP_ID_REG);
	if (!((id == YAS_BMA250_CHIP_ID_250)  ||
	      (id == YAS_BMA250_CHIP_ID_250E) ||
	      (id == YAS_BMA250_CHIP_ID_254))) {
		yas_bma250_i2c_close();
		return YAS_ERROR_CHIP_ID;
	}

	/* Reset chip */
	yas_bma250_write_reg_byte(YAS_BMA250_SOFT_RESET_REG,
				  YAS_BMA250_SOFT_RESET_VAL);
	yas_bma250_msleep(3);

	/* Set axes range*/
	yas_bma250_update_bits(YAS_BMA250_RANGE, YAS_BMA250_RANGE_2G);

	acc_data.chip_id = (uint8_t)id;
	acc_data.initialize = 1;

	yas_bma250_set_delay(YAS_BMA250_DEFAULT_DELAY);
	yas_bma250_set_position(YAS_BMA250_DEFAULT_POSITION);
	filter.threshold = YAS_ACC_DEFAULT_FILTER_THRESH;
	yas_bma250_set_filter(&filter);
	yas_bma250_power_down();

	return YAS_NO_ERROR;
}