Example #1
0
/**
 * Put the capacitive keyboard on standby
 */
void cap_deinit(void) {
	if (!cap_enabled)
		return;

	exti_detach_interrupt((afio_exti_num) (PIN_MAP[CAPTOUCH_GPIO].gpio_bit));

	// Disable MPR121 scanning, in case the chip is on
	mpr121Write(ELE_CFG, 0x00);
	mpr121Write(SFT_RST, 0x63); // send softreset to put IC in low power state (stop mode).

	return;
}
Example #2
0
void cap_init(void) {

	// 63 2 4 1 63 2 4 1 0 8 4
	cap_set_mhd_r(63);
	cap_set_nhd_r(2);
	cap_set_ncl_r(4);
	cap_set_fdl_r(1);
	cap_set_mhd_f(63);
	cap_set_nhd_f(2);
	cap_set_ncl_r(4);
	cap_set_fdl_f(1);
	cap_set_dbr(0);
	cap_set_touch_threshold(8);
	cap_set_release_threshold(4);

	/**
	gpio_set_mode(PIN_MAP[BOARD_I2C_SDA].gpio_device, PIN_MAP[BOARD_I2C_SDA].gpio_bit, GPIO_OUTPUT_PP);
	gpio_set_mode(PIN_MAP[BOARD_I2C_SCL].gpio_device, PIN_MAP[BOARD_I2C_SCL].gpio_bit, GPIO_OUTPUT_PP);
	gpio_write_bit(PIN_MAP[BOARD_I2C_SDA].gpio_device, PIN_MAP[BOARD_I2C_SDA].gpio_bit, 1);
	gpio_write_bit(PIN_MAP[BOARD_I2C_SCL].gpio_device, PIN_MAP[BOARD_I2C_SCL].gpio_bit, 1);
	delay_us(1000);
	gpio_set_mode(PIN_MAP[BOARD_I2C_SDA].gpio_device, PIN_MAP[BOARD_I2C_SDA].gpio_bit, GPIO_INPUT_PD); // Can also be floating, but PD is safer if components misplaced.
	gpio_set_mode(PIN_MAP[BOARD_I2C_SCL].gpio_device, PIN_MAP[BOARD_I2C_SCL].gpio_bit, GPIO_INPUT_PD);
	*/

	i2c = CAPTOUCH_I2C;
	i2c_init(i2c);
	i2c_master_enable(i2c, I2C_BUS_RESET);

	mpr121Write(0x80, 0x63); // soft reset
	delay_us(1000);
	mpr121Write(ELE_CFG, 0x00);   // disable electrodes for config
	delay_us(100);

	// Section A and B - R (rise) F (fall) T (touch)
	mpr121Write(MHD_R, cap_mhd_r); // (1 to 63)
	mpr121Write(NHD_R, cap_nhd_r); // (1 to 63)
	mpr121Write(NCL_R, cap_ncl_r); // (0 to 255)
	mpr121Write(FDL_R, cap_fdl_r); // (0 to 255)

	mpr121Write(MHD_F, cap_mhd_f); // (1 to 63) largest value to pass through filer
	mpr121Write(NHD_F, cap_nhd_f); // (1 to 63) maximum change allowed
	mpr121Write(NCL_F, cap_ncl_f); // (0 to 255) number of samples required to determine non-noise
	mpr121Write(FDL_F, cap_fdl_f); // (0 to 255) rate of filter operation, larger = slower.

	// Section D
	// Set the Filter Configuration
	// Set ESI2

	// was 0x01, 0x25
	mpr121Write(AFE_CONF, 0x01); //AFE_CONF  0x5C
	mpr121Write(FIL_CFG, 0x04); //FIL_CFG   0x5D

	// Section F
	mpr121Write(ATO_CFG0, 0x0B); // ATO_CFG0 0x7B

	// limits
	// was0xFF,0x00,0x0E
	mpr121Write(ATO_CFGU, 0x9C); // ATO_CFGU 0x7D
	mpr121Write(ATO_CFGL, 0x65); // ATO_CFGL 0x7E
	mpr121Write(ATO_CFGT, 0x8C); // ATO_CFGT 0x7F

	// enable debouncing
	mpr121Write(DBR, cap_dbr); // set debouncing, in this case 7 for both touch and release.

	// Section C
	// This group sets touch and release thresholds for each electrode
	mpr121Write(ELE0_T, cap_touch_threshold);
	mpr121Write(ELE0_R, cap_release_threshold);
	mpr121Write(ELE1_T, cap_touch_threshold);
	mpr121Write(ELE1_R, cap_release_threshold);
	mpr121Write(ELE2_T, cap_touch_threshold);
	mpr121Write(ELE2_R, cap_release_threshold);
	mpr121Write(ELE3_T, cap_touch_threshold);
	mpr121Write(ELE3_R, cap_release_threshold);
	mpr121Write(ELE4_T, cap_touch_threshold);
	mpr121Write(ELE4_R, cap_release_threshold);
	mpr121Write(ELE5_T, cap_touch_threshold);
	mpr121Write(ELE5_R, cap_release_threshold);
	mpr121Write(ELE6_T, cap_touch_threshold);
	mpr121Write(ELE6_R, cap_release_threshold);
	mpr121Write(ELE7_T, cap_touch_threshold);
	mpr121Write(ELE7_R, cap_release_threshold);
	mpr121Write(ELE8_T, cap_touch_threshold);
	mpr121Write(ELE8_R, cap_release_threshold);
	mpr121Write(ELE9_T, cap_touch_threshold);
	mpr121Write(ELE9_R, cap_release_threshold);
	mpr121Write(ELE10_T, cap_touch_threshold);
	mpr121Write(ELE10_R, cap_release_threshold);
	mpr121Write(ELE11_T, cap_touch_threshold);
	mpr121Write(ELE11_R, cap_release_threshold);

	delay_us(100);

	// Section E
	// Electrode Configuration
	// Enable 6 Electrodes and set to run mode
	// Set ELE_CFG to 0x00 to return to standby mode
	mpr121Write(ELE_CFG, 0x0C);   // Enables all 12 Electrodes
	delay_us(100);

	// This can also be FLOATING, but PU is safer if components misplaced.
	gpio_set_mode(PIN_MAP[CAPTOUCH_GPIO].gpio_device,
			PIN_MAP[CAPTOUCH_GPIO].gpio_bit, GPIO_INPUT_PU);
	exti_attach_interrupt((afio_exti_num) (PIN_MAP[CAPTOUCH_GPIO].gpio_bit),
			gpio_exti_port(PIN_MAP[CAPTOUCH_GPIO].gpio_device), cap_change,
			EXTI_FALLING);

	// Clears the first interrupt
	uint32_t ts = realtime_get_unixtime();
	for (int n = 0; n < 16; n++)
		press_time[n] = ts;
	for (int n = 0; n < 16; n++)
		release_time[n] = ts;
	press_time_any = ts;
	release_time_any = ts;

	// Set the cap_enabled flag to remember the captouch is on
	cap_enabled = 1;

	return;
}
void DetectTouch::mpr121QuickConfig(void)
{
  mpr121Write(ELE_CFG, 0x00);
  //mpr121Write(0x5c, 0x10);
 // mpr121Write(FIL_CFG, 0x24);
  
  // Section A
  // This group controls filtering when data is > baseline.
  mpr121Write(MHD_R, 0x01);
  mpr121Write(NHD_R, 0x01);
  mpr121Write(NCL_R, 0x00);
  mpr121Write(FDL_R, 0x00);

  // Section B
  // This group controls filtering when data is < baseline.
  mpr121Write(MHD_F, 0x01);
  mpr121Write(NHD_F, 0x01);
  mpr121Write(NCL_F, 0xFF);
  mpr121Write(FDL_F, 0x02);
  
  // Section C
  // This group sets touch and release thresholds for each electrode
  mpr121Write(ELE0_T, TOU_THRESH);
  mpr121Write(ELE0_R, REL_THRESH);
  mpr121Write(ELE1_T, TOU_THRESH);
  mpr121Write(ELE1_R, REL_THRESH);
  mpr121Write(ELE2_T, TOU_THRESH);
  mpr121Write(ELE2_R, REL_THRESH);
  mpr121Write(ELE3_T, TOU_THRESH);
  mpr121Write(ELE3_R, REL_THRESH);
  mpr121Write(ELE4_T, TOU_THRESH);
  mpr121Write(ELE4_R, REL_THRESH);
  mpr121Write(ELE5_T, TOU_THRESH);
  mpr121Write(ELE5_R, REL_THRESH);
  mpr121Write(ELE6_T, TOU_THRESH);
  mpr121Write(ELE6_R, REL_THRESH);
  mpr121Write(ELE7_T, TOU_THRESH);
  mpr121Write(ELE7_R, REL_THRESH);
  mpr121Write(ELE8_T, TOU_THRESH);
  mpr121Write(ELE8_R, REL_THRESH);
  mpr121Write(ELE9_T, TOU_THRESH);
  mpr121Write(ELE9_R, REL_THRESH);
  mpr121Write(ELE10_T, TOU_THRESH);
  mpr121Write(ELE10_R, REL_THRESH);
  mpr121Write(ELE11_T, TOU_THRESH);
  mpr121Write(ELE11_R, REL_THRESH);
  
  mpr121Write(MHDPROXR, 0xff);
  mpr121Write(NHDPROXR, 0xff);
  mpr121Write(NCLPROXR, 0x00);
  mpr121Write(FDLPROXR, 0x00);
  mpr121Write(MHDPROXF, 0x01);
  mpr121Write(NHDPROXF, 0x01);
  mpr121Write(NCLPROXF, 0xff);
  mpr121Write(FDLPROXF, 0xff);
  mpr121Write(NHDPROXT, 0x00);
  mpr121Write(NCLPROXT, 0x00);
  mpr121Write(FDLPROXT, 0x00);
  // Section D
  // Set the Filter Configuration
  // Set ESI2
  mpr121Write(FIL_CFG, 0xb3);
  
  // Section E
  // Electrode Configuration
  // Enable 6 Electrodes and set tELE_CFG to 0x00 to return to standby mode
  mpr121Write(ELE_CFG, 0x0C);	// Enables all 12 Electrodes
  //mpr121Write(ELE_CFG, 0x06);		// Enable first 6 electrodes
  
  // Section F
  // Enable Auto Config and auto Reconfig
  //mpr121Write(ATO_CFG0, 0x0B);
  //mpr121Write(ATO_CFGU, 0xCA);	// USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V   mpr121Write(ATO_CFGL, 0x82);	// LSL = 0.65*USL = 0x82 @3.3V
  //mpr121Write(ATO_CFGT, 0xB6);	// Target = 0.9*USL = 0xB5 @3.3V
}