static void txc_ps_handler(struct work_struct *work) { struct txc_data *txc = container_of(work, struct txc_data, ps_dwork.work); struct i2c_client *client = txc_info->client; u8 psdata=0; int ps_data = txc->ps_data; u8 sendvalue; int res; u8 data; int ret; pa12201001_read_ps(client,&psdata); printk("%s, psdata is %d\n", __func__, psdata); if (txc->mcu_enable) { if (psdata > PA12_PS_FAR_TH_HIGH) { ps_data = PS_NEAR; } else if (psdata < PA12_PS_NEAR_TH_LOW) { ps_data = PS_FAR ; } } else { if (txc->ps_data == PS_UNKONW || txc->ps_data == PS_FAR) { if(psdata > PA12_PS_FAR_TH_HIGH){ ps_data = PS_NEAR; // Set PS threshold sendvalue=PA12_PS_NEAR_TH_HIGH; res=i2c_write_reg(client,REG_PS_TH,sendvalue); //set TH threshold sendvalue=PA12_PS_NEAR_TH_LOW; res=i2c_write_reg(client,REG_PS_TL,sendvalue); //set TL threshold } else if (psdata < PA12_PS_NEAR_TH_LOW) { ps_data= PS_FAR; } } else if (txc->ps_data == PS_NEAR) { if(psdata < PA12_PS_NEAR_TH_LOW){ ps_data = PS_FAR; sendvalue=PA12_PS_FAR_TH_HIGH; res=i2c_write_reg(client,REG_PS_TH,sendvalue); //set TH threshold sendvalue=PA12_PS_FAR_TH_LOW; res=i2c_write_reg(client,REG_PS_TL,sendvalue); //set TL threshold } } if (txc->ps_data != ps_data) { txc->ps_data = ps_data; input_report_rel(txc->input_dev, REL_Z, ps_data); input_sync(txc->input_dev); if (ps_data == PS_NEAR) { printk("***********near***********\n"); } else if (ps_data == PS_FAR) { printk("****************far***************\n"); } } ret = i2c_read_reg(txc->client, REG_CFG2, &data); if (ret < 0) { pr_err("%s: txc_read error\n", __func__); } data &= 0xfc; ret = i2c_write_reg(txc->client, REG_CFG2, data); if (ret < 0) { pr_err("%s: txc_write error\n", __func__); } } mt_eint_unmask(CUST_EINT_INTI_INT_NUM); }
static int apds9190_set_enable(struct td_device *dev, uint8_t reg) { return i2c_write_reg(dev, REG_ENABLE, reg); }
static uint8_t tcs37727_trim_gain(tcs37727_t *dev, int32_t rawc) { uint8_t reg_again = 0; int val_again = dev->again; if (rawc < TCS37727_AG_THRESHOLD_LOW) { switch (val_again) { case 1: reg_again = TCS37727_CONTROL_AGAIN_4; val_again = 4; break; case 4: reg_again = TCS37727_CONTROL_AGAIN_16; val_again = 16; break; case 16: reg_again = TCS37727_CONTROL_AGAIN_60; val_again = 60; break; case 60: default: return -1; } } else if (rawc > TCS37727_AG_THRESHOLD_HIGH) { switch (val_again) { case 60: reg_again = TCS37727_CONTROL_AGAIN_16; val_again = 16; break; case 16: reg_again = TCS37727_CONTROL_AGAIN_4; val_again = 4; break; case 4: reg_again = TCS37727_CONTROL_AGAIN_1; val_again = 1; break; case 1: default: return -1; } } else { return 0; } i2c_acquire(BUS); uint8_t reg = 0; if (i2c_read_reg(BUS, ADR, TCS37727_CONTROL, ®) != 1) { i2c_release(BUS); return -2; } reg &= ~TCS37727_CONTROL_AGAIN_MASK; reg |= reg_again; if (i2c_write_reg(BUS, ADR, TCS37727_CONTROL, reg) != 1) { i2c_release(BUS); return -2; } i2c_release(BUS); dev->again = val_again; return 0; }
/******************************************************************************* * Function Name : I2C_MEMS_Off * Description : It turn off the device. * Input : None * Output : None * Return : 1 if the device has been successfully set to power-down mode, 0 otherwise. *******************************************************************************/ int8u MEMS_Off (void) { return i2c_write_reg (kLIS3L02DQ_SLAVE_ADDR, CTRL_REG1, 0x87); }
static int imx6sx_sdb_setup_pmic_voltages(void) { unsigned char value, rev_id = 0; struct i2c_adapter *adapter = NULL; struct i2c_client client; int addr = -1, bus = 0; if (!of_machine_is_compatible("fsl,imx6sx-sdb")) return 0; /* I2C2 bus (2-1 = 1 in barebox numbering) */ bus = 0; /* PFUZE100 device address is 0x08 */ addr = 0x08; adapter = i2c_get_adapter(bus); if (!adapter) return -ENODEV; client.adapter = adapter; client.addr = addr; if (i2c_read_reg(&client, PFUZE100_DEVICEID, &value, 1) < 0) goto err_out; if (i2c_read_reg(&client, PFUZE100_REVID, &rev_id, 1) < 0) goto err_out; pr_info("Found PFUZE100! deviceid 0x%x, revid 0x%x\n", value, rev_id); if (imx6sx_sdb_setup_pmic_mode(&client, value & 0xf)) goto err_out; /* set SW1AB standby volatage 0.975V */ if (i2c_read_reg(&client, PFUZE100_SW1ABSTBY, &value, 1) < 0) goto err_out; value &= ~0x3f; value |= PFUZE100_SW1ABC_SETP(9750); if (i2c_write_reg(&client, PFUZE100_SW1ABSTBY, &value, 1) < 0) goto err_out; /* set SW1AB/VDDARM step ramp up time from 16us to 4us/25mV */ if (i2c_read_reg(&client, PFUZE100_SW1ABCONF, &value, 1) < 0) goto err_out; value &= ~0xc0; value |= 0x40; if (i2c_write_reg(&client, PFUZE100_SW1ABCONF, &value, 1) < 0) goto err_out; /* set SW1C standby volatage 0.975V */ if (i2c_read_reg(&client, PFUZE100_SW1CSTBY, &value, 1) < 0) goto err_out; value &= ~0x3f; value |= PFUZE100_SW1ABC_SETP(9750); if (i2c_write_reg(&client, PFUZE100_SW1CSTBY, &value, 1) < 0) goto err_out; /* set SW1C/VDDSOC step ramp up time to from 16us to 4us/25mV */ if (i2c_read_reg(&client, PFUZE100_SW1CCONF, &value, 1) < 0) goto err_out; value &= ~0xc0; value |= 0x40; if (i2c_write_reg(&client, PFUZE100_SW1CCONF, &value, 1) < 0) goto err_out; /* Enable power of VGEN5 3V3, needed for SD3 */ if (i2c_read_reg(&client, PFUZE100_VGEN5CTL, &value, 1) < 0) goto err_out; value &= ~0x1F; value |= 0x1F; if (i2c_write_reg(&client, PFUZE100_VGEN5CTL, &value, 1) < 0) goto err_out; return 0; err_out: pr_err("Setting up PMIC failed\n"); return -EIO; }
/** * Initialize compass * Caution: This internal function does not acquire exclusive access to the I2C bus. * Acquisation and release is supposed to be handled by the calling function. */ static int compass_init(mpu9150_t *dev) { char data[3]; /* Enable Bypass Mode to speak to compass directly */ conf_bypass(dev, 1); /* Check whether compass answers correctly */ i2c_read_reg(dev->i2c_dev, dev->comp_addr, COMPASS_WHOAMI_REG, data); if (data[0] != MPU9150_COMP_WHOAMI_ANSWER) { DEBUG("[Error] Wrong answer from compass\n"); return -1; } /* Configure Power Down mode */ i2c_write_reg(dev->i2c_dev, dev->comp_addr, COMPASS_CNTL_REG, MPU9150_COMP_POWER_DOWN); hwtimer_wait(HWTIMER_TICKS(MPU9150_COMP_MODE_SLEEP_US)); /* Configure Fuse ROM access */ i2c_write_reg(dev->i2c_dev, dev->comp_addr, COMPASS_CNTL_REG, MPU9150_COMP_FUSE_ROM); hwtimer_wait(HWTIMER_TICKS(MPU9150_COMP_MODE_SLEEP_US)); /* Read sensitivity adjustment values from Fuse ROM */ i2c_read_regs(dev->i2c_dev, dev->comp_addr, COMPASS_ASAX_REG, data, 3); dev->conf.compass_x_adj = data[0]; dev->conf.compass_y_adj = data[1]; dev->conf.compass_z_adj = data[2]; /* Configure Power Down mode again */ i2c_write_reg(dev->i2c_dev, dev->comp_addr, COMPASS_CNTL_REG, MPU9150_COMP_POWER_DOWN); hwtimer_wait(HWTIMER_TICKS(MPU9150_COMP_MODE_SLEEP_US)); /* Disable Bypass Mode to configure MPU as master to the compass */ conf_bypass(dev, 0); /* Configure MPU9150 for single master mode */ i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_I2C_MST_REG, BIT_WAIT_FOR_ES); /* Set up slave line 0 */ /* Slave line 0 reads the compass data */ i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_SLAVE0_ADDR_REG, (BIT_SLAVE_RW | dev->comp_addr)); /* Slave line 0 read starts at compass data register */ i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_SLAVE0_REG_REG, COMPASS_DATA_START_REG); /* Enable slave line 0 and configure read length to 6 consecutive registers */ i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_SLAVE0_CTRL_REG, (BIT_SLAVE_EN | 0x06)); /* Set up slave line 1 */ /* Slave line 1 writes to the compass */ i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_SLAVE1_ADDR_REG, dev->comp_addr); /* Slave line 1 write starts at compass control register */ i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_SLAVE1_REG_REG, COMPASS_CNTL_REG); /* Enable slave line 1 and configure write length to 1 register */ i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_SLAVE1_CTRL_REG, (BIT_SLAVE_EN | 0x01)); /* Configure data which is written by slave line 1 to compass control */ i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_SLAVE1_DATA_OUT_REG, MPU9150_COMP_SINGLE_MEASURE); /* Slave line 0 and 1 operate at each sample */ i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_I2C_DELAY_CTRL_REG, (BIT_SLV0_DELAY_EN | BIT_SLV1_DELAY_EN)); /* Set I2C bus to VDD */ i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_YG_OFFS_TC_REG, BIT_I2C_MST_VDDIO); return 0; }
int twl4030_usb_reset(void) { TRACE_ENTRY; #if 0 twl4030_usb_clear_bits(OTG_CTRL, DMPULLDOWN | DPPULLDOWN); twl4030_usb_clear_bits(USB_INT_EN_RISE, ~0); twl4030_usb_clear_bits(USB_INT_EN_FALL, ~0); twl4030_usb_clear_bits(MCPC_IO_CTRL, ~TXDTYP); twl4030_usb_set_bits(MCPC_IO_CTRL, TXDTYP); twl4030_usb_clear_bits(OTHER_FUNC_CTRL, (BDIS_ACON_EN | FIVEWIRE_MODE)); twl4030_usb_clear_bits(OTHER_IFC_CTRL, ~0); twl4030_usb_clear_bits(OTHER_INT_EN_RISE, ~0); twl4030_usb_clear_bits(OTHER_INT_EN_FALL, ~0); twl4030_usb_clear_bits(OTHER_IFC_CTRL2, ~0); twl4030_usb_clear_bits(REG_CTRL_EN, ULPI_I2C_CONFLICT_INTEN); twl4030_usb_clear_bits(OTHER_FUNC_CTRL2, VBAT_TIMER_EN); #endif /* Enable writing to power configuration registers */ i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, PROTECT_KEY, 0xC0); i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, PROTECT_KEY, 0x0C); /* put VUSB3V1 LDO in active state */ i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, VUSB_DEDICATED2, 0); /* input to VUSB3V1 LDO is from VBAT, not VBUS */ i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, VUSB_DEDICATED1, 0x14); /* turn on 3.1V regulator */ i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, VUSB3V1_DEV_GRP, 0x20); i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, VUSB3V1_TYPE, 0); /* turn on 1.5V regulator */ i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, VUSB1V5_DEV_GRP, 0x20); i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, VUSB1V5_TYPE, 0); /* turn on 1.8V regulator */ i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, VUSB1V8_DEV_GRP, 0x20); i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, VUSB1V8_TYPE, 0); /* disable access to power configuration registers */ i2c_write_reg(TWL_I2C_BUS, TWL_PM_RECEIVER_ADDR, PROTECT_KEY, 0); /* turn on the phy */ uint8_t pwr = twl4030_usb_read(PHY_PWR_CTRL); pwr &= ~PHYPWD; twl4030_usb_write(PHY_PWR_CTRL, pwr); twl4030_usb_write(PHY_CLK_CTRL, twl4030_usb_read(PHY_CLK_CTRL) | (CLOCKGATING_EN | CLK32K_EN)); /* set DPLL i2c access mode */ twl4030_i2c_access(true); /* set ulpi mode */ twl4030_usb_clear_bits(IFC_CTRL, CARKITMODE); twl4030_usb_set_bits(POWER_CTRL, OTG_ENAB); twl4030_usb_write(FUNC_CTRL, XCVRSELECT_HS); // set high speed mode // twl4030_usb_write(FUNC_CTRL, XCVRSELECT_FS); // set full speed mode twl4030_i2c_access(false); return 0; }
static int twl4030_usb_write(uint8_t address, uint8_t data) { return i2c_write_reg(TWL_I2C_BUS, TWL_USB_ADDR, address, data); }
int main(void) { /* Configure Watch dog timer as an interval timer. WDTIFG is * set upon expiration of selected time interval, and PUC is not * generated, so there is no reset of the device. Also, WDTIE bit * remains unchanged, so you don't have to reset the WDT interrupt. * * WDTCTL is 16 bits and always needs to be accessed with * the upper 8 bits as the WDT password, WDTPW (0x5A). * Use ACLK for WDTCNT - selected with the WDTSSEL bit * Set WDTTMSEL bit to 1 for interval timer mode. * WDTIS0 and WDTIS1 set the interval. * 00 = WDT clock source/32768 **This is the PUC value * 01 = WDT clock source/8192 * 10 = WDT clock source/512 * 11 = WDT clock source/64 * With ACLK = 1.5kHz and dividing it by 32768, we get ~21.8 seconds * With ACLK = 1.5kHz and dividing it by 64, we get 42.6mS * between WDT interrupts. */ WDTCTL = WDTPW + WDTHOLD; initClocks(); /* Configure Bluetooth module */ hc05_init(__baud_to_uca0br(9600)); hc05_transmit("HC05 init\r\n",11); /* Initialize mpu6050 */ mpu6050_init(); hc05_transmit("mpu6050 init\r\n",14); /* Now we are ready for application code to run. Enable interrupts */ _BIS_SR(GIE); while(1) { if(data_received != 0) { switch(data_received) { case 'T': data_received = 0; mpu6050_temp(); break; case 'A': data_received = 0; mpu6050_accel(); break; case 'G': data_received = 0; mpu6050_gyro(); break; case 'g': data_received = 0; mpu6050_calibrate_gyros(); break; case 'M': data_received = 0; mpu6050_getAddress(); break; case 'W': data_received = 0; mpu6050_wakeup(); break; case 'S': data_received = 0; mpu6050_sleep(); break; case 'R': data_received = 0; dmp_mode = 0; motion_detect_mode = 0; mpu6050_reset(); break; case 'd': data_received = 0; mpu6050_dmpinit(); break; case 'E': data_received = 0; motion_detect_mode = 0; dmp_mode = 1; mpu6050_setDMPEnabled(true); P2DIR &= ~MPU6050_INT; // Input P2SEL &= ~MPU6050_INT; // Digital IO Psel and psel2 are 0 P2SEL2 &= ~MPU6050_INT; P2IES &= ~MPU6050_INT; // Edge select 0 = low to high P2IFG &= ~MPU6050_INT; // Clear the interrupt flag before enabling interrupt P2IE |= MPU6050_INT; // Interrupt enable //mpu6050_resetFIFO(); break; case 'e': dmp_mode = 0; data_received = 0; mpu6050_setDMPEnabled(false); break; case 'm': /* Itseems that I can have motion detect interrupts if I first call the dmpinit() function, then this code is run. I can probably narrow it down to a certain function call in the dmpinit() it will just take time */ sendAck(); motion_detect_mode = 1; dmp_mode = 0; mpu6050_setDMPEnabled(false); i2c_write_reg(MPU6050_RA_INT_PIN_CFG,0x10);//interrupt status cleared on any read //i2c_write_reg(MPU6050_RA_MOT_DETECT_CTRL,0x30); // add the 3 ms delay to accel put mpu6050_setMotionDetectionThreshold(threshold);//not sure... but I'm told it's 2mg per LSB so 0xFF would only be about 0.512g mpu6050_setMotionDetectionDuration(threshold_duration); // This duration will really change the snappiness and responsiveness of the motion detect (duh) so // it should be set to as low as possible, then set detection threshold to the appropriate value for punches or whatever mpu6050_setIntEnabled(0x40);//motion detect... based on the product specification document, I don't think motion detect can generate an interrupt on INT pin, // so we also set the data ready interrupt. mpu6050_configAccel(MPU6050_ACCEL_FS_16<<(MPU6050_ACONFIG_AFS_SEL_BIT-1)); data_received = 0; P2DIR &= ~MPU6050_INT; // Input P2SEL &= ~MPU6050_INT; // Digital IO Psel and psel2 are 0 P2SEL2 &= ~MPU6050_INT; P2IES &= ~MPU6050_INT; // Edge select 0 = low to high P2IFG &= ~MPU6050_INT; // Clear the interrupt flag before enabling interrupt P2IE |= MPU6050_INT; // Interrupt enable /*while(1) { if(mpu6050_getIntStatus() & 0x40) { //motion interrupt hc05_transmit("Motion\r\n",8); } }*/ break; case 'l': threshold = threshold - 1; mpu6050_setMotionDetectionThreshold(threshold); break; case 'p': threshold = threshold + 1; mpu6050_setMotionDetectionThreshold(threshold); break; case 'L': threshold_duration = threshold_duration - 5; mpu6050_setMotionDetectionDuration(threshold_duration); break; case 'P': threshold_duration = threshold_duration + 5; mpu6050_setMotionDetectionDuration(threshold_duration); break; // case 'h': // hc05_setspeed(115200); // data_received = 0; // break; //case 'k': // hc05_key(); // data_received = 0; // break; default: sendAck(); data_received = 0; break; } } if(mpu6050_interrupt) { if(dmp_mode) { mpuIntStatus = mpu6050_getIntStatus(); fifoCount = mpu6050_getFIFOCount(); if(fifoCount > 16) { fifoCount =16; } mpu6050_getFIFOBytes(mpu6050_buffer,fifoCount); /* This seems to keep the fifo operating. I probably need to read the fifo faster so it doesn't 'die' on me */ mpu6050_resetFIFO(); /* From J.Rowberg's library, the dmp packet output is: bytes 0-15 quaternion (32 bits) (w,x,y,z) but just use the first two bytes as 16 bit number bytes 16-27 gyro (32 bits) (gx,gy,gz) but just use the first two bytes as 16 bit number bytes 28-39 acceleration (32 bits) (ax,ay,az) but just use the first two bytes as 16 bit number */ teapotPacket[2] = mpu6050_buffer[0]; teapotPacket[3] = mpu6050_buffer[1]; teapotPacket[4] = mpu6050_buffer[4]; teapotPacket[5] = mpu6050_buffer[5]; teapotPacket[6] = mpu6050_buffer[8]; teapotPacket[7] = mpu6050_buffer[9]; teapotPacket[8] = mpu6050_buffer[12]; teapotPacket[9] = mpu6050_buffer[13]; teapotPacket[10] = mpuIntStatus; // I modified the packet to sent the interrupt status in this byte hc05_transmit(teapotPacket,14); teapotPacket[11]++; mpu6050_interrupt = 0; } else if (motion_detect_mode) { if(mpu6050_getIntStatus() & 0x40) { // Disable motion interrupts, get accel and gyro values until they aren't interesting // anymore, then quit and enable interrupt. mpu6050_setIntEnabled(0x00); //motion interrupt // hc05_transmit("Motion\r\n",8); for(uint8_t j = 0; j<100; j++) { mpu6050_accel(); delay_ms(2); // i2c_tx_buffer[0] = 0x3B; // i2c_tx_buffer_counter = 1; // i2c_transmit_to_receive(); // i2c_transmit(); // i2c_multireceive(6); // for(j = 0; j< 6; j++) { // TXData = i2c_rx_buffer[j]; /* These are div 16384 if +/-2g, 8192 if +/-4g, 4096 if +/-8g and 2048 if +/-16g*/ //accelX[j] = (i2c_rx_buffer[0]<<8 | i2c_rx_buffer[1]); //accelY[j] = (i2c_rx_buffer[2]<<8 | i2c_rx_buffer[3]); //accelZ[j] = (i2c_rx_buffer[4]<<8 | i2c_rx_buffer[5]); //sprintf(tempbuf,"%d %d %d\r\n",ax,ay,az); //sprintf(tempbuf,"E%d,%d,%d\r\n",ax,ay,az); // hc05_transmit(tempbuf,strlen(tempbuf)); // hc05_transmit((char*)ax,1); //hc05_transmit((char*)ay,1); //hc05_transmit((char*)az,1); //} //__delay_us(1000); //delay_ms(2); } // hc05_transmit((char*)accelX,2*ACCELBUFSIZE); // hc05_transmit((char*)accelY,2*ACCELBUFSIZE); // hc05_transmit((char*)accelZ,2*ACCELBUFSIZE); // mpu6050_getIntStatus(); mpu6050_setIntEnabled(0x40); } else { // sprintf(tempbuf,"Unknown interrupt\r\n"); // hc05_transmit(tempbuf,strlen(tempbuf)); } } else { // mpu6050_getIntStatus(); // Clear any other interrupts // sprintf(tempbuf,"Unknown mode & interrupt\r\n"); // hc05_transmit(tempbuf,strlen(tempbuf)); } } __bis_SR_register(LPM0_bits + GIE); } }
void adxl345_set_interrupt(const adxl345_t *dev) { assert(dev); DEBUG("[adxl345] Update interruptions configuration\n"); i2c_acquire(BUS); /* Set threshold */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_THRESH_TAP, dev->interrupt.thres_tap, 0); /* Set Map */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_INT_MAP, dev->interrupt.map, 0); /* Set Duration */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_TAP_DUR, dev->interrupt.thres_dur, 0); /* Enable axes */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_TAP_AXES, dev->interrupt.tap_axes, 0); /* Set source */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_INT_SOURCE, dev->interrupt.source, 0); /* Set latent threshold */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_TAP_LAT, dev->interrupt.thres_latent, 0); /* Set window threshold */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_TAP_WIN, dev->interrupt.thres_window, 0); /* Set activity threshold */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_THRESH_ACT, dev->interrupt.thres_act, 0); /* Set inactivity threshold */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_THRESH_INACT, dev->interrupt.thres_inact, 0); /* Set inactivity time */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_TIME_INACT, dev->interrupt.time_inact, 0); /* Set free-fall threshold */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_THRESH_FF, dev->interrupt.thres_ff, 0); /* Set free-fall time */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_TIME_FF, dev->interrupt.time_ff, 0); /* Set axis control */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_ACT_INACT_CTL, dev->interrupt.act_inact, 0); /* Enable interrupt */ i2c_write_reg(BUS, ADDR, ACCEL_ADXL345_INT_ENABLE, dev->interrupt.enable, 0); /* Release the bus */ i2c_release(BUS); }