예제 #1
0
static int bma250_set_bandwidth(struct i2c_client *client, unsigned char BW)
{
	int comres = 0;
	unsigned char data;
	int i = 0;

	if (client == NULL) {
		comres = -1;
	} else {

		for (i = 0; i < ARRAY_SIZE(bma250_valid_bw); i++) {
			if (bma250_valid_bw[i] == BW)
				break;
		}

		if (ARRAY_SIZE(bma250_valid_bw) > i) {
			comres = bma250_smbus_read_byte(client,
					BMA250_BANDWIDTH__REG, &data);
			data = BMA250_SET_BITSLICE(data, BMA250_BANDWIDTH, BW);
			comres += bma250_smbus_write_byte(client,
					BMA250_BANDWIDTH__REG, &data);
		} else {
			comres = -EINVAL;
		}
	}

	return comres;
}
예제 #2
0
static int bma250_set_range(struct i2c_client *client, unsigned char Range)
{
	int comres = 0;
	unsigned char data1;
	int i;

	if (client == NULL) {
		comres = -1;
	} else{
		for (i = 0; i < ARRAY_SIZE(bma250_valid_range); i++) {
			if (bma250_valid_range[i] == Range)
				break;
		}

		if (ARRAY_SIZE(bma250_valid_range) > i) {
			comres = bma250_smbus_read_byte(client,
					BMA250_RANGE_SEL_REG, &data1);

			data1  = BMA250_SET_BITSLICE(data1,
					BMA250_RANGE_SEL, Range);

			comres += bma250_smbus_write_byte(client,
					BMA250_RANGE_SEL_REG, &data1);
		} else {
			comres = -EINVAL;
		}
	}

	return comres;
}
예제 #3
0
static int bma250_set_bandwidth(struct i2c_client *client, unsigned char BW)
{
	int comres = 0;
	unsigned char data = '\0';
	int Bandwidth = 0;

	if (client == NULL) {
		comres = -1;
	} else {
		if (BW < 8) {
			switch (BW) {
			case 0:
				Bandwidth = BMA250_BW_7_81HZ;
				break;
			case 1:
				Bandwidth = BMA250_BW_15_63HZ;
				break;
			case 2:
				Bandwidth = BMA250_BW_31_25HZ;
				break;
			case 3:
				Bandwidth = BMA250_BW_62_50HZ;
				break;
			case 4:
				Bandwidth = BMA250_BW_125HZ;
				break;
			case 5:
				Bandwidth = BMA250_BW_250HZ;
				break;
			case 6:
				Bandwidth = BMA250_BW_500HZ;
				break;
			case 7:
				Bandwidth = BMA250_BW_1000HZ;
				break;
			default:
				break;
			}
			comres = bma250_smbus_read_byte(client,
							BMA250_BANDWIDTH__REG,
							&data);
			data =
			    BMA250_SET_BITSLICE(data, BMA250_BANDWIDTH,
						Bandwidth);
			comres +=
			    bma250_smbus_write_byte(client,
						    BMA250_BANDWIDTH__REG,
						    &data);
		} else {
			comres = -1;
		}
	}

	return comres;
}
예제 #4
0
static int bma250_get_interruptstatus1(struct i2c_client *client, unsigned char
	*intstatus)
{
    int comres = 0;
    unsigned char data = 0;

    comres = bma250_smbus_read_byte(client, BMA250_STATUS1_REG, &data);
    *intstatus = data;

    return comres;
}
예제 #5
0
static int bma250_get_offset_filt_z(struct i2c_client *client, unsigned char
						*offsetfilt)
{
	int comres = 0;
	unsigned char data;

	comres = bma250_smbus_read_byte(client, BMA250_OFFSET_FILT_Z_REG,
						&data);
	*offsetfilt = data;

	return comres;
}
예제 #6
0
static int bma250_set_ee_w(struct i2c_client *client, unsigned char eew)
{
	int comres = 0;
	unsigned char data;

	comres = bma250_smbus_read_byte(client,
			BMA250_UNLOCK_EE_WRITE_SETTING__REG, &data);
	data = BMA250_SET_BITSLICE(data, BMA250_UNLOCK_EE_WRITE_SETTING, eew);
	comres = bma250_smbus_write_byte(client,
			BMA250_UNLOCK_EE_WRITE_SETTING__REG, &data);
	return comres;
}
예제 #7
0
static int bma250_get_cal_ready(struct i2c_client *client,
		unsigned char *calrdy)
{
	int comres = 0 ;
	unsigned char data;

	comres = bma250_smbus_read_byte(client,
			BMA250_OFFSET_CTRL_REG, &data);
	data = BMA250_GET_BITSLICE(data, BMA250_FAST_COMP_RDY_S);
	*calrdy = data;

	return comres;
}
예제 #8
0
static int bma250_get_offset_target_z(struct i2c_client *client,
		unsigned char *offsettarget)
{
	int comres = 0 ;
	unsigned char data;

	comres = bma250_smbus_read_byte(client,
			BMA250_OFFSET_PARAMS_REG, &data);
	data = BMA250_GET_BITSLICE(data, BMA250_COMP_TARGET_OFFSET_Z);
	*offsettarget = data;

	return comres;
}
예제 #9
0
static int bma250_set_selftest_stn(struct i2c_client *client, unsigned char stn)
{
	int comres = 0;
	unsigned char data;

	comres = bma250_smbus_read_byte(client,
			BMA250_NEG_SELF_TEST__REG, &data);
	data = BMA250_SET_BITSLICE(data, BMA250_NEG_SELF_TEST, stn);
	comres = bma250_smbus_write_byte(client,
			BMA250_NEG_SELF_TEST__REG, &data);

	return comres;
}
예제 #10
0
static int bma250_get_eeprom_writing_status(struct i2c_client *client,
							unsigned char *eewrite)
{
	int comres = 0;
	unsigned char data;

	comres = bma250_smbus_read_byte(client,
				BMA250_EEPROM_CTRL_REG, &data);
	data = BMA250_GET_BITSLICE(data, BMA250_EE_WRITE_SETTING_S);
	*eewrite = data;

	return comres;
}
예제 #11
0
static int bma250_set_mode(struct i2c_client *client, unsigned char Mode)
{
	int comres = 0;
	unsigned char data1 = 0;

	if (client == NULL) {
		comres = -1;
	} else {
		if (Mode < 3) {
			comres = bma250_smbus_read_byte(client,
							BMA250_EN_LOW_POWER__REG,
							&data1);
			switch (Mode) {
			case BMA250_MODE_NORMAL:
				data1 = BMA250_SET_BITSLICE(data1,
							    BMA250_EN_LOW_POWER,
							    0);
				data1 =
				    BMA250_SET_BITSLICE(data1,
							BMA250_EN_SUSPEND, 0);
				break;
			case BMA250_MODE_LOWPOWER:
				data1 = BMA250_SET_BITSLICE(data1,
							    BMA250_EN_LOW_POWER,
							    1);
				data1 =
				    BMA250_SET_BITSLICE(data1,
							BMA250_EN_SUSPEND, 0);
				break;
			case BMA250_MODE_SUSPEND:
				data1 = BMA250_SET_BITSLICE(data1,
							    BMA250_EN_LOW_POWER,
							    0);
				data1 =
				    BMA250_SET_BITSLICE(data1,
							BMA250_EN_SUSPEND, 1);
				break;
			default:
				break;
			}

			comres += bma250_smbus_write_byte(client,
							  BMA250_EN_LOW_POWER__REG,
							  &data1);
		} else {
			comres = -1;
		}
	}

	return comres;
}
예제 #12
0
static int bma250_get_mode(struct i2c_client *client, unsigned char *Mode)
{
	int comres = 0;

	if (client == NULL) {
		comres = -1;
	} else {
		comres = bma250_smbus_read_byte(client,
						BMA250_EN_LOW_POWER__REG, Mode);
		*Mode = (*Mode) >> 6;
	}

	return comres;
}
예제 #13
0
static int bma250_set_cal_trigger(struct i2c_client *client,
		unsigned char caltrigger)
{
	int comres = 0;
	unsigned char data;

	comres = bma250_smbus_read_byte(client,
			BMA250_EN_FAST_COMP__REG, &data);
	data = BMA250_SET_BITSLICE(data,
			BMA250_EN_FAST_COMP, caltrigger);
	comres = bma250_smbus_write_byte(client,
			BMA250_EN_FAST_COMP__REG, &data);

	return comres;
}
예제 #14
0
static int bma250_set_offset_target_x(struct i2c_client *client,
		unsigned char offsettarget)
{
	int comres = 0;
	unsigned char data;

	comres = bma250_smbus_read_byte(client,
			BMA250_COMP_TARGET_OFFSET_X__REG, &data);
	data = BMA250_SET_BITSLICE(data,
			BMA250_COMP_TARGET_OFFSET_X, offsettarget);
	comres = bma250_smbus_write_byte(client,
			BMA250_COMP_TARGET_OFFSET_X__REG, &data);

	return comres;
}
예제 #15
0
static int bma250_set_ee_prog_trig(struct i2c_client *client)
{
	int comres = 0;
	unsigned char data;
	unsigned char eeprog;
	eeprog = 0x01;

	comres = bma250_smbus_read_byte(client,
			BMA250_START_EE_WRITE_SETTING__REG, &data);
	data = BMA250_SET_BITSLICE(data,
				BMA250_START_EE_WRITE_SETTING, eeprog);
	comres = bma250_smbus_write_byte(client,
			BMA250_START_EE_WRITE_SETTING__REG, &data);
	return comres;
}
예제 #16
0
static int bma250_get_range(struct i2c_client *client, unsigned char *Range)
{
	int comres = 0;
	unsigned char data = '\0';

	if (client == NULL) {
		comres = -1;
	} else {
		comres = bma250_smbus_read_byte(client, BMA250_RANGE_SEL__REG,
						&data);
		data = BMA250_GET_BITSLICE(data, BMA250_RANGE_SEL);
		*Range = data;
	}

	return comres;
}
예제 #17
0
static int bma250_set_slope_threshold(struct i2c_client *client,
	unsigned char threshold)
{
    int comres = 0;
    unsigned char data = 0;


    comres = bma250_smbus_read_byte(client,
	    BMA250_SLOPE_THRES__REG, &data);
    data = BMA250_SET_BITSLICE(data, BMA250_SLOPE_THRES, threshold);
    comres = bma250_smbus_write_byte(client,
	    BMA250_SLOPE_THRES__REG, &data);


    return comres;
}
예제 #18
0
static int bma250_set_slope_duration(struct i2c_client *client, unsigned char
	duration)
{
    int comres = 0;
    unsigned char data = 0;


    comres = bma250_smbus_read_byte(client,
	    BMA250_SLOPE_DUR__REG, &data);
    data = BMA250_SET_BITSLICE(data, BMA250_SLOPE_DUR, duration);
    comres = bma250_smbus_write_byte(client,
	    BMA250_SLOPE_DUR__REG, &data);


    return comres;
}
예제 #19
0
static int bma250_set_Int_Mode(struct i2c_client *client, unsigned char Mode)
{
    int comres = 0;
    unsigned char data = 0;
    


    comres = bma250_smbus_read_byte(client,
	    BMA250_INT_MODE_SEL__REG, &data);
    data = BMA250_SET_BITSLICE(data, BMA250_INT_MODE_SEL, Mode);
    comres = bma250_smbus_write_byte(client,
	    BMA250_INT_MODE_SEL__REG, &data);


    return comres;
}
예제 #20
0
static int bma250_set_range(struct i2c_client *client, unsigned char Range)
{
	int comres = 0;
	unsigned char data1 = '\0';

	if (client == NULL) {
		comres = -1;
	} else {
		if (Range < 4) {
			comres = bma250_smbus_read_byte(client,
							BMA250_RANGE_SEL_REG,
							&data1);
			switch (Range) {
			case 0:
				data1 = BMA250_SET_BITSLICE(data1,
							    BMA250_RANGE_SEL,
							    0);
				break;
			case 1:
				data1 = BMA250_SET_BITSLICE(data1,
							    BMA250_RANGE_SEL,
							    5);
				break;
			case 2:
				data1 = BMA250_SET_BITSLICE(data1,
							    BMA250_RANGE_SEL,
							    8);
				break;
			case 3:
				data1 = BMA250_SET_BITSLICE(data1,
							    BMA250_RANGE_SEL,
							    12);
				break;
			default:
				break;
			}
			comres += bma250_smbus_write_byte(client,
							  BMA250_RANGE_SEL_REG,
							  &data1);
		} else {
			comres = -1;
		}
	}

	return comres;
}
예제 #21
0
static int bma250_get_bandwidth(struct i2c_client *client, unsigned char *BW)
{
	int comres = 0;
	unsigned char data;

	if (client == NULL) {
		comres = -1;
	} else{
		comres = bma250_smbus_read_byte(client, BMA250_BANDWIDTH__REG,
				&data);
		data = BMA250_GET_BITSLICE(data, BMA250_BANDWIDTH);
		if (data < BMA250_BW_7_81HZ)
			*BW = BMA250_BW_7_81HZ;
		else if (data > BMA250_BW_1000HZ)
			*BW = BMA250_BW_1000HZ;
		else
			*BW = data;
	}

	return comres;
}
예제 #22
0
static int bma250_get_bandwidth(struct i2c_client *client, unsigned char *BW)
{
	int comres = 0;
	unsigned char data = '\0';

	if (client == NULL) {
		comres = -1;
	} else {
		comres = bma250_smbus_read_byte(client, BMA250_BANDWIDTH__REG,
						&data);
		data = BMA250_GET_BITSLICE(data, BMA250_BANDWIDTH);
		if (data <= 8) {
			*BW = 0;
		} else {
			if (data >= 0x0F)
				*BW = 7;
			else
				*BW = data - 8;

		}
	}

	return comres;
}
예제 #23
0
static int bma250_set_int1_pad_sel(struct i2c_client *client, unsigned char
	int1sel)
{
    int comres = 0;
    unsigned char data = 0;
    unsigned char state = 0;
    state = 0x01;


    switch (int1sel) {
	case 0:
	    comres = bma250_smbus_read_byte(client,
		    BMA250_EN_INT1_PAD_LOWG__REG, &data);
	    data = BMA250_SET_BITSLICE(data, BMA250_EN_INT1_PAD_LOWG,
		    state);
	    comres = bma250_smbus_write_byte(client,
		    BMA250_EN_INT1_PAD_LOWG__REG, &data);
	    break;
	case 1:
	    comres = bma250_smbus_read_byte(client,
		    BMA250_EN_INT1_PAD_HIGHG__REG, &data);
	    data = BMA250_SET_BITSLICE(data, BMA250_EN_INT1_PAD_HIGHG,
		    state);
	    comres = bma250_smbus_write_byte(client,
		    BMA250_EN_INT1_PAD_HIGHG__REG, &data);
	    break;
	case 2:
	    comres = bma250_smbus_read_byte(client,
		    BMA250_EN_INT1_PAD_SLOPE__REG, &data);
	    data = BMA250_SET_BITSLICE(data, BMA250_EN_INT1_PAD_SLOPE,
		    state);
	    comres = bma250_smbus_write_byte(client,
		    BMA250_EN_INT1_PAD_SLOPE__REG, &data);
	    break;
	case 3:
	    comres = bma250_smbus_read_byte(client,
		    BMA250_EN_INT1_PAD_DB_TAP__REG, &data);
	    data = BMA250_SET_BITSLICE(data, BMA250_EN_INT1_PAD_DB_TAP,
		    state);
	    comres = bma250_smbus_write_byte(client,
		    BMA250_EN_INT1_PAD_DB_TAP__REG, &data);
	    break;
	case 4:
	    comres = bma250_smbus_read_byte(client,
		    BMA250_EN_INT1_PAD_SNG_TAP__REG, &data);
	    data = BMA250_SET_BITSLICE(data, BMA250_EN_INT1_PAD_SNG_TAP,
		    state);
	    comres = bma250_smbus_write_byte(client,
		    BMA250_EN_INT1_PAD_SNG_TAP__REG, &data);
	    break;
	case 5:
	    comres = bma250_smbus_read_byte(client,
		    BMA250_EN_INT1_PAD_ORIENT__REG, &data);
	    data = BMA250_SET_BITSLICE(data, BMA250_EN_INT1_PAD_ORIENT,
		    state);
	    comres = bma250_smbus_write_byte(client,
		    BMA250_EN_INT1_PAD_ORIENT__REG, &data);
	    break;
	case 6:
	    comres = bma250_smbus_read_byte(client,
		    BMA250_EN_INT1_PAD_FLAT__REG, &data);
	    data = BMA250_SET_BITSLICE(data, BMA250_EN_INT1_PAD_FLAT,
		    state);
	    comres = bma250_smbus_write_byte(client,
		    BMA250_EN_INT1_PAD_FLAT__REG, &data);
	    break;
	default:
	    break;
    }

    return comres;
}
예제 #24
0
static int bma250_set_Int_Enable(struct i2c_client *client, unsigned char
	InterruptType , unsigned char value)
{
    int comres = 0;
    unsigned char data1 = 0, data2 = 0;



    comres = bma250_smbus_read_byte(client, BMA250_INT_ENABLE1_REG, &data1);
    comres = bma250_smbus_read_byte(client, BMA250_INT_ENABLE2_REG, &data2);


    value = value & 1;
    switch (InterruptType) {
	case 0:
	    
	    data2 = BMA250_SET_BITSLICE(data2, BMA250_EN_LOWG_INT, value);
	    break;
	case 1:
	    

	    data2 = BMA250_SET_BITSLICE(data2, BMA250_EN_HIGHG_X_INT,
		    value);
	    break;
	case 2:
	    

	    data2 = BMA250_SET_BITSLICE(data2, BMA250_EN_HIGHG_Y_INT,
		    value);
	    break;
	case 3:
	    

	    data2 = BMA250_SET_BITSLICE(data2, BMA250_EN_HIGHG_Z_INT,
		    value);
	    break;
	case 4:
	    

	    data2 = BMA250_SET_BITSLICE(data2, BMA250_EN_NEW_DATA_INT,
		    value);
	    break;
	case 5:
	    

	    data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_SLOPE_X_INT,
		    value);
	    break;
	case 6:
	    

	    data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_SLOPE_Y_INT,
		    value);
	    break;
	case 7:
	    

	    data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_SLOPE_Z_INT,
		    value);
	    break;

	case 8:
	    

	    data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_SINGLE_TAP_INT,
		    value);
	    break;
	case 9:
	    

	    data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_DOUBLE_TAP_INT,
		    value);
	    break;
	case 10:
	    

	    data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_ORIENT_INT, value);
	    break;
	case 11:
	    

	    data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_FLAT_INT, value);
	    break;
	default:
	    break;
    }
    comres = bma250_smbus_write_byte(client, BMA250_INT_ENABLE1_REG,
	    &data1);
    comres = bma250_smbus_write_byte(client, BMA250_INT_ENABLE2_REG,
	    &data2);


    return comres;
}