示例#1
0
/**
 * @brief Set the BMA220 digital filter cut-off frequency
 *
 * @param hal      Address of an initialized sensor hardware descriptor.
 * @param band     The index of a driver-specific bandwidth table entry.
 * @return bool    true if the call succeeds, else false is returned.
 */
static bool bma220_set_bandwidth(sensor_hal_t *hal, int16_t band)
{
	uint8_t const reg = REG_ADDR(BMA220_BANDWIDTH_CONFIG);
	sensor_reg_fieldset(hal, reg, FILTER_CONFIG_FIELD,
			band_table[band].reserved_val);

	return true;
}
示例#2
0
/**
 * @brief Set a BMA220 event threshold value
 *
 * @param hal       Address of an initialized sensor hardware descriptor.
 * @param threshold Address of threshold descriptor.
 * @return bool     true if the call succeeds, else false is returned.
 */
static bool bma220_set_threshold
	(sensor_hal_t *hal, sensor_threshold_desc_t *threshold)
{
	int8_t const value = THRESHOLD_IN_G(threshold->value, hal->range);

	switch (threshold->type) {
	/* Invalid/unsupported threshold type. */
	default:
		return false;

	/* any-motion (slope) threshold */
	case SENSOR_THRESHOLD_MOTION:
	case SENSOR_THRESHOLD_TILT:
	{
		uint8_t const reg = REG_ADDR(BMA220_SLOPE_CONFIG);
		sensor_reg_fieldset(hal, reg, SLOPE_TH_FIELD, value);
	}
	break;

	/* tap/double-tap threshold */
	case SENSOR_THRESHOLD_TAP:
	{
		uint8_t const reg = REG_ADDR(BMA220_TAP_CONFIG);
		sensor_reg_fieldset(hal, reg, TT_TH_FIELD, value);
	}
	break;

	/* low-G threshold */
	case SENSOR_THRESHOLD_LOW_G:
	{
		uint8_t const reg = REG_ADDR(BMA220_HG_LG_THRESHOLD);
		sensor_reg_fieldset(hal, reg, LOW_TH_FIELD, value);
	}
	break;

	/* high-G threshold */
	case SENSOR_THRESHOLD_HIGH_G:
	{
		uint8_t const reg = REG_ADDR(BMA220_HG_LG_THRESHOLD);
		sensor_reg_fieldset(hal, reg, HIGH_TH_FIELD, value);
	}
	break;
	}

	return true;
}
示例#3
0
/**
 * @brief Set the BMA220 full scale acceleration range.
 *
 * @param hal       Address of an initialized sensor hardware descriptor.
 * @param range     The index of a driver-specific range table entry.
 * @return bool     true if the call succeeds, else false is returned.
 */
static bool bma220_set_range(sensor_hal_t *hal, int16_t range)
{
	uint8_t const reg = REG_ADDR(BMA220_RANGE_SELFTEST);
	sensor_reg_fieldset(hal, reg, RANGE_FIELD,
			range_table[range].reserved_val);

	return true;
}
示例#4
0
/**
 * @brief Set event threshold value
 *
 * @param hal       Address of an initialized sensor hardware descriptor.
 * @param threshold Address of threshold descriptor.
 * @return bool     true if the call succeeds, else false is returned.
 */
static bool bma250_set_threshold
	(sensor_hal_t *hal, sensor_threshold_desc_t *threshold)
{
	/* Threshold values will be passed in milli-g units (assumed). */
	int32_t value = scaled_to_raw(hal, threshold->value);

	switch (threshold->type) {
	default:
		return false;

	case SENSOR_THRESHOLD_MOTION:

		/*
		 * Any-Motion (slope) Threshold
		 *
		 * The slope interrupt threshold value LSB corresponds to an LSB
		 * of acceleration data for the selected g-range. The default
		 * value of 14h for the default 2mg range implies a threshold of
		 * 312.5mg.
		 */
		sensor_bus_put(hal, BMA250_SLOPE_THRESHOLD, (uint8_t)value);
		break;

	case SENSOR_THRESHOLD_TAP:

		/*
		 * Single-Tap or Double-Tap Threshold
		 *
		 * An LSB of tap threshold depends upon the selected g-range
		 * where an acceleration delta of 62.5mg in 2-g, 125mg in 4-g,
		 *etc.
		 * will apply. The default 0ah raw value corresponds to the
		 *default
		 * 2mg range.
		 */
	{
		int8_t const mask = BMA250_TAP_TH_FIELD;
		sensor_reg_fieldset(hal, BMA250_TAP_CONFIG, mask,
				(uint8_t)value);
	}
	break;

	case SENSOR_THRESHOLD_LOW_G:

		/*
		 * Low-G Threshold
		 *
		 * An LSB of low-g threshold always corresponds to an
		 * acceleration of 7.81mg; namely, the increment is independent
		 * of the g-range. Divide the requested threshold in milli-g
		 * by 7.81mg (781/100) to calculate the register value.
		 */
		value = (threshold->value * 100) / 781;
		sensor_bus_put(hal, BMA250_LOW_G_THRESHOLD, (uint8_t)value);
		break;

	case SENSOR_THRESHOLD_HIGH_G:

		/*
		 * High-G Threshold
		 *
		 * An LSB of high-g threshold depends upon the selected g-range
		 * where an acceleration delta of 62.5mg in 2-g, 125mg in 4-g,
		 * etc. will apply. The default 0ah raw value corresponds to the
		 * default 2mg range.
		 */
		sensor_bus_put(hal, BMA250_HIGH_G_THRESHOLD, (uint8_t)value);
		break;
	}

	return (STATUS_OK == hal->bus.status);
}