QuickMpr121
QuickMpr121.cpp
1 /*
2  * QuickMpr121 Arduino library by somewhatlurker
3  * =============================================
4  *
5  * QuickMpr121 is a library for using MPR121 capacitive touch sensing ICs.
6  * More info in QuickMpr121.h, or read the docs.
7  *
8  * Copyright 2020 somewhatlurker, MIT license
9  */
10 
11 #include "QuickMpr121.h"
12 
13 byte mpr121::i2cReadBuf[MPR121_I2C_BUFLEN];
14 
15 #if MPR121_SAVE_MEMORY
16  short mpr121::electrodeDataBuf[13];
17  byte mpr121::electrodeBaselineBuf[13];
18  byte mpr121::electrodeCDCBuf[13];
19  mpr121FilterCDT mpr121::electrodeCDTBuf[13];
20  #if !MPR121_USE_BITFIELDS
21  bool mpr121::electrodeOORBuf[15];
22  #endif
23 #endif // MPR121_SAVE_MEMORY
24 
25 // Writes a value to an MPR121 register.
26 void mpr121::writeRegister(mpr121Register addr, byte value) {
27  i2cWire->beginTransmission(i2cAddr);
28  i2cWire->write(addr);
29  i2cWire->write(value);
30  i2cWire->endTransmission();
31 }
32 
33 // Reads bytes from consecutive MPR121 registers, starting at addr.
34 // Max count is equal to the MPR121_I2C_BUFLEN define.
35 byte* mpr121::readRegister(mpr121Register addr, byte count) {
36  if (count > MPR121_I2C_BUFLEN)
37  count = MPR121_I2C_BUFLEN;
38 
39  // write the address to read from
40  i2cWire->beginTransmission(i2cAddr);
41  i2cWire->write(addr);
42  i2cWire->endTransmission(false); // use false to restart instead of stopping
43 
44  i2cWire->requestFrom(i2cAddr, count, (byte)true); // sendStop is true by default where supported, but setting it guarantees support
45 
46  byte readnum = 0;
47  while (i2cWire->available() && readnum < count)
48  {
49  i2cReadBuf[readnum] = i2cWire->read();
50  readnum++;
51  }
52 
53  // if not fully read, clear additional bytes to avoid returning old data
54  for ( ; readnum < count; readnum++)
55  {
56  i2cReadBuf[readnum] = 0;
57  }
58 
59  return i2cReadBuf;
60 }
61 
62 
63 // Checks if an electrode number and count are valid and suitable for use.
64 // Returns true if they can be used or false if the caller should immediately return.
65 // This function may modify electrode and/or count to keep them in bounds as necessary
66 bool mpr121::checkElectrodeNum(byte &electrode, byte &count) {
67  if (electrode > 12)
68  return false;
69 
70  if (electrode + count > 13)
71  count = 13 - electrode;
72 
73  return true;
74 }
75 
76 // Checks if an electrode number is valid and suitable for use.
77 // Returns true if it can be used or false if the caller should immediately return.
78 // This function may modify electrode to keep it in bounds as necessary
79 bool mpr121::checkElectrodeNum(byte &electrode) {
80  if (electrode > 12)
81  return false;
82 
83  return true;
84 }
85 
86 // Checks if a GPIO pin number and count are valid and suitable for use.
87 // Returns true if they can be used or false if the caller should immediately return.
88 // This function may modify pin and/or count to keep them in bounds as necessary
89 bool mpr121::checkGPIOPinNum(byte &pin, byte &count) {
90  if (pin < 4 || pin > 11)
91  return false;
92 
93  if (pin + count > 12)
94  count = 12 - pin;
95 
96  return true;
97 }
98 
99 // Checks if a GPIO pin number is valid and suitable for use.
100 // Returns true if it can be used or false if the caller should immediately return.
101 // This function may modify pin to keep it in bounds as necessary
102 bool mpr121::checkGPIOPinNum(byte &pin) {
103  if (pin < 4 || pin > 11)
104  return false;
105 
106  return true;
107 }
108 
109 
110 // Sets the touch and release thresholds for consecutive electrodes.
111 // (AN3892)
112 void mpr121::setElectrodeThresholds(byte electrode, byte count, byte touchThreshold, byte releaseThreshold) {
113  if (!checkElectrodeNum(electrode, count))
114  return;
115 
116  for (byte i = 0; i < count; i++) {
117  writeRegister((mpr121Register)(MPRREG_ELE0_TOUCH_THRESHOLD + (i+electrode)*2), touchThreshold);
118  writeRegister((mpr121Register)(MPRREG_ELE0_RELEASE_THRESHOLD + (i+electrode)*2), releaseThreshold);
119  }
120 }
121 
122 
123 // Sets the "Max Half Delta" baseline filter values.
124 // Max: 63
125 // (AN3891)
126 void mpr121::setMHD(byte rising, byte falling) {
127  writeRegister(MPRREG_MHD_RISING, rising);
128  writeRegister(MPRREG_MHD_FALLING, falling);
129 }
130 
131 // Sets the "Noise Half Delta" baseline filter values.
132 // Max: 63
133 // (AN3891)
134 void mpr121::setNHD(byte rising, byte falling, byte touched) {
135  writeRegister(MPRREG_NHD_AMOUNT_RISING, rising);
136  writeRegister(MPRREG_NHD_AMOUNT_FALLING, falling);
137  writeRegister(MPRREG_NHD_AMOUNT_TOUCHED, touched);
138 }
139 
140 // Sets the "Noise Count Limit" baseline filter values.
141 // (AN3891)
142 void mpr121::setNCL(byte rising, byte falling, byte touched) {
143  writeRegister(MPRREG_NCL_RISING, rising);
144  writeRegister(MPRREG_NCL_FALLING, falling);
145  writeRegister(MPRREG_NCL_TOUCHED, touched);
146 }
147 
148 // Sets the "Filter Delay Limit" baseline filter values.
149 // (AN3891)
150 void mpr121::setFDL(byte rising, byte falling, byte touched) {
151  writeRegister(MPRREG_FDL_RISING, rising);
152  writeRegister(MPRREG_FDL_FALLING, falling);
153  writeRegister(MPRREG_NCL_TOUCHED, touched);
154 }
155 
156 
157 // Sets the "Max Half Delta" baseline filter values for proximity detection.
158 // Max: 63
159 // (AN3891/AN3893)
160 void mpr121::setMHDProx(byte rising, byte falling) {
161  writeRegister(MPRREG_ELEPROX_MHD_RISING, rising);
162  writeRegister(MPRREG_ELEPROX_MHD_FALLING, falling);
163 }
164 
165 // Sets the "Noise Half Delta" baseline filter values for proximity detection.
166 // Max: 63
167 // (AN3891/AN3893)
168 void mpr121::setNHDProx(byte rising, byte falling, byte touched) {
169  writeRegister(MPRREG_ELEPROX_NHD_AMOUNT_RISING, rising);
170  writeRegister(MPRREG_ELEPROX_NHD_AMOUNT_FALLING, falling);
171  writeRegister(MPRREG_ELEPROX_NHD_AMOUNT_TOUCHED, touched);
172 }
173 
174 // Sets the "Noise Count Limit" baseline filter values for proximity detection.
175 // (AN3891/AN3893)
176 void mpr121::setNCLProx(byte rising, byte falling, byte touched) {
177  writeRegister(MPRREG_ELEPROX_NCL_RISING, rising);
178  writeRegister(MPRREG_ELEPROX_NCL_FALLING, falling);
179  writeRegister(MPRREG_ELEPROX_NCL_TOUCHED, touched);
180 }
181 
182 // Sets the "Filter Delay Limit" baseline filter values for proximity detection.
183 // (AN3891/AN3893)
184 void mpr121::setFDLProx(byte rising, byte falling, byte touched) {
185  writeRegister(MPRREG_ELEPROX_FDL_RISING, rising);
186  writeRegister(MPRREG_ELEPROX_FDL_FALLING, falling);
187  writeRegister(MPRREG_ELEPROX_NCL_TOUCHED, touched);
188 }
189 
190 
191 // Sets the debounce counts.
192 // A detection must be held for this many readings before the status register is updated.
193 // Max: 7
194 void mpr121::setDebounce(byte touchNumber, byte releaseNumber) {
195  touchNumber &= 0b0111;
196  releaseNumber &= 0b0111;
197 
198  writeRegister(MPRREG_DEBOUNCE, (touchNumber << 4) | releaseNumber);
199 }
200 
201 
202 // Sets "Filter Configuration".
203 // (AN3890)
204 //
205 // FFI: "First Filter Iterations"
206 // CDC: Global "Charge Discharge Current" (μA), not used if autoconfig is enabled (Max 63, Default 16)
207 // CDT: Global "Charge Discharge Time" (μs), not used if autoconfig is enabled
208 // SFI: "Second Filter Iterations"
209 // ESI: "Electrode Sample Interval" (ms)
210 //
211 // Response time is equal to SFI * ESI in ms.
212 void mpr121::setFilterConfig(mpr121FilterFFI FFI, byte CDC, mpr121FilterCDT CDT, mpr121FilterSFI SFI, mpr121FilterESI ESI) {
213  byte FFI_2 = (byte)FFI & 0b00000011;
214  byte CDC_6 = CDC & 0b00111111;
215  byte CDT_3 = (byte)CDT & 0b00000111;
216  byte SFI_2 = (byte)SFI & 0b00000011;
217  byte ESI_3 = (byte)ESI & 0b00000111;
218 
219  writeRegister(MPRREG_FILTER_GLOBAL_CDC_CONFIG, (FFI_2 << 6) | CDC_6);
220  writeRegister(MPRREG_FILTER_GLOBAL_CDT_CONFIG, (CDT_3 << 5) | (SFI_2 << 3) | ESI_3);
221 
222  // update FFI in autoconf
223  byte autoConf = readRegister(MPRREG_AUTOCONFIG_CONTROL_0) & 0b00111111;
224  autoConf |= (FFI_2 << 6);
225  writeRegister(MPRREG_AUTOCONFIG_CONTROL_0, autoConf);
226 }
227 
228 
229 // Sets "Electrode Configuration".
230 //
231 // CL: Calibration lock (baseline tracking and initial value settings)
232 // ELEPROX_EN: Run with these electrodes used for proximity detection
233 // ELE_EN: Run with this number of electrodes to scan, starting from ELE0 (excludes ELEPROX)
234 void mpr121::setElectrodeConfiguration(mpr121ElectrodeConfigCL CL, mpr121ElectrodeConfigProx ELEPROX_EN, byte ELE_EN) {
235  byte CL_2 = CL & 0b00000011;
236  byte ELEPROX_EN_2 = ELEPROX_EN & 0b00000011;
237  byte ELE_EN_4 = ELE_EN & 0b00001111;
238 
239  writeRegister(MPRREG_ELECTRODE_CONFIG, (CL_2 << 6) | (ELEPROX_EN_2 << 4) | ELE_EN_4);
240 }
241 
242 
243 
244 // Sets "Auto-Configure" settings.
245 // (AN3889/datasheet)
246 //
247 // USL: "Up-Side Limit" -- Calculate this as `256L * (supplyMillivolts - 700) / supplyMillivolts`. If unsure, use the value for 1.8V supply (156).
248 // LSL: "Low-Side Limit" -- Calculate this as `USL * 0.65`. If unsure, use the value for 1.8V supply (101).
249 // TL: "Target Level" -- Calculate this as `USL * 0.9`. If unsure, use the value for 1.8V supply (140).
250 // RETRY: Number of retries for failed config before setting the out of range flag.
251 // BVA: "Baseline Value Adjust" -- Changes how the baseline registers will be set after auto-configuration completes
252 // ARE: "Automatic Reconfiguration Enable" -- Out of range (failed) channels will be reconfigured every sampling interval
253 // ACE: "Automatic Configuration Enable" -- Perform auto-configuration when entering run mode
254 // SCTS: "Skip Charge Time Search" -- Skip CDT search and use the already-set CDTx or global CDT. This results in a shorter time to configure, but the designer must supply appropriate values.
255 // OORIE: "Out-of-range interrupt enable" -- Trigger an interrupt when a channel is determined to be out of range
256 // ARFIE: "Auto-reconfiguration fail interrupt enable" -- Trigger an interrupt when auto-reconfiguration fails
257 // ACFIE: "Auto-configuration fail interrupt enable" -- Trigger an interrupt when auto-configuration fails
258 void mpr121::setAutoConfig(byte USL, byte LSL, byte TL, mpr121AutoConfigRetry RETRY, mpr121AutoConfigBVA BVA, bool ARE, bool ACE, bool SCTS, bool OORIE, bool ARFIE, bool ACFIE) {
259  byte FFI = (readRegister(MPRREG_AFE_CONFIG) >> 6) & 0b00000011;
260  byte RETRY_2 = RETRY & 0b00000011;
261  byte BVA_2 = BVA & 0b00000011;
262 
263  writeRegister(MPRREG_AUTOCONFIG_USL, USL);
264  writeRegister(MPRREG_AUTOCONFIG_LSL, LSL);
265  writeRegister(MPRREG_AUTOCONFIG_TL, TL);
266  writeRegister(MPRREG_AUTOCONFIG_CONTROL_0, (FFI << 6) | (RETRY_2 << 4) | (BVA_2 << 2) | ((ARE ? 1 : 0) << 1) | (ACE ? 1 : 0));
267  writeRegister(MPRREG_AUTOCONFIG_CONTROL_1, ((SCTS ? 1 : 0) << 7) | ((OORIE ? 1 : 0) << 2) | ((ARFIE ? 1 : 0) << 1) | (ACFIE ? 1 : 0));
268 }
269 
270 
271 // Sets the GPIO PWM value for consecutive pins.
272 // (AN3894)
273 //
274 // Max value is 15
275 // Pin 9 apparently has a logic bug and pin 10 must also have its data set high for it to work.
276 // (https://community.nxp.com/thread/305474)
277 void mpr121::setPWM(byte pin, byte count, byte value) {
278  if (!checkGPIOPinNum(pin, count))
279  return;
280 
281  pin -= 4; // easier to make it 0-indexed now
282 
283  byte value_4 = value & 0b1111;
284 
285  mpr121Register reg = MPRREG_PWM_DUTY_0;
286  byte regVal = 0;
287 
288  for (byte i = 0; i < count; i++) {
289  if (i == 0 || (pin + i) % 2 == 0) { // if just starting or moving to a new register's start
290  reg = (mpr121Register)(MPRREG_PWM_DUTY_0 + (pin + i)/2);
291  regVal = readRegister(reg);
292  }
293 
294  if ((pin + i) % 2 == 0)
295  regVal = (regVal & 0b11110000) | value_4;
296  else
297  regVal = (regVal & 0b00001111) | (value_4 << 4);
298 
299  if ((pin + i) % 2 == 1 || i == count - 1) // if the last of a register or the last iteration
300  writeRegister(reg, regVal);
301  }
302 }
303 
304 
305 // Creates an MPR121 device with sane default settings.
306 // addr: The I2C address to use. If not specified (or ==0), the next valid address will be chosen automatically.
307 //wire: You can pass in an alternative TwoWire instance.
308 mpr121::mpr121(byte addr, TwoWire *wire)
309 {
310  static byte usedAddresses = 0;
311 
312  if (addr == 0) {
313  if (!bitRead(usedAddresses, 0)) {
314  addr = 0x5a;
315  }
316  else if (!bitRead(usedAddresses, 1)) {
317  addr = 0x5b;
318  }
319  else if (!bitRead(usedAddresses, 2)) {
320  addr = 0x5c;
321  }
322  else if (!bitRead(usedAddresses, 3)) {
323  addr = 0x5d;
324  }
325  else {
326  addr = 0x5a; // at least fall back to *an* mpr121 if all addresses are taken
327  }
328  }
329 
330  if (addr >= 0x5a && addr <= 0x5d)
331  bitSet(usedAddresses, 0x5a - addr);
332 
333  i2cAddr = addr;
334  i2cWire = wire;
335 
336  // values from getting started guide
337  // MHDrising = 0x01;
338  // MHDfalling = 0x01;
339  // NHDrising = 0x01;
340  // NHDfalling = 0x01;
341  // NHDtouched = 0x00; // ?
342  // NCLrising = 0x00;
343  // NCLfalling = 0xff;
344  // NCLtouched = 0x00; // ?
345  // FDLrising = 0x00;
346  // FDLfalling = 0x02;
347  // FDLtouched = 0x00; // ?
348 
349  // values from AN3893
350  // MHDrisingProx = 0xff;
351  // MHDfallingProx = 0x01;
352  // NHDrisingProx = 0xff;
353  // NHDfallingProx = 0x01;
354  // NHDtouchedProx = 0x00;
355  // NCLrisingProx = 0x00;
356  // NCLfallingProx = 0xff;
357  // NCLtouchedProx = 0x00;
358  // FDLrisingProx = 0x00;
359  // FDLfallingProx = 0xff;
360  // FDLtouchedProx = 0x00;
361 
362  // adjusted values
363  MHDrising = 0x01;
364  MHDfalling = 0x01;
365  NHDrising = 0x01;
366  NHDfalling = 0x03;
367  NHDtouched = 0x00;
368  NCLrising = 0x04;
369  NCLfalling = 0xc0;
370  NCLtouched = 0x00;
371  FDLrising = 0x00;
372  FDLfalling = 0x02;
373  FDLtouched = 0x00;
374 
375  // no clue what might be good here lol
376  MHDrisingProx = 0x20;
377  MHDfallingProx = 0x01;
378  NHDrisingProx = 0x10;
379  NHDfallingProx = 0x03;
380  NHDtouchedProx = 0x00;
381  NCLrisingProx = 0x04;
382  NCLfallingProx = 0xc0;
383  NCLtouchedProx = 0x00;
384  FDLrisingProx = 0x00;
385  FDLfallingProx = 0x80;
386  FDLtouchedProx = 0x00;
387 
388  for (byte i = 0; i < 13; i++)
389  {
390  touchThresholds[i] = 0x0f;
391  releaseThresholds[i] = 0x0a;
392  }
393 
394  debounceTouch = 0x00;
395  debounceRelease = 0x00;
396 
397  FFI = MPR_FFI_6;
398  globalCDC = 16;
400  SFI = MPR_SFI_4;
401  ESI = MPR_ESI_1; // 4 samples, 1ms rate ==> 4ms response time
402 
405 
406  autoConfigUSL = 0;
407  autoConfigLSL = 0;
408  autoConfigTL = 0;
413 
414  autoConfigSkipChargeTime = false;
415  autoConfigInterruptOOR = false;
416  autoConfigInterruptARF = false;
417  autoConfigInterruptACF = false;
418 }
419 
420 
421 // Reads one touch state bool.
422 // Also use this for reading GPIO inputs.
423 //
424 // When multiple touches must be read, using the variant that returns data for all 13 is preferred.
425 // This should implement some form of caching -- use electrodeTouchCache/electrodeTouchBuf (depending on MPR121_USE_BITFIELDS) and electrodeTouchCacheMicros
426 bool mpr121::readTouchState(byte electrode) {
427  if (!checkElectrodeNum(electrode))
428  return false;
429 
430  unsigned long microsNow = micros();
431  if (microsNow > electrodeTouchCacheMicros + 500 || microsNow < electrodeTouchCacheMicros) { // cache for 500 microseconds
432  electrodeTouchCacheMicros = microsNow;
433  #if MPR121_USE_BITFIELDS
434  electrodeTouchCache = readTouchState();
435  #else
436  // this line actually isn't needed, because the data would already be in electrodeTouchBuf after calling readTouchState()
437  // memcpy(electrodeTouchBuf, readTouchState(), sizeof(electrodeTouchBuf));
438  readTouchState();
439  #endif
440  }
441 
442  #if MPR121_USE_BITFIELDS
443  return bitRead(electrodeTouchCache, electrode);
444  #else
445  return electrodeTouchBuf[electrode];
446  #endif
447 }
448 
449 
450 #if MPR121_USE_BITFIELDS
451  // Reads the 13 touch state bits.
452  // Also use this for reading GPIO inputs.
454  byte* rawdata = readRegister(MPRREG_ELE0_TO_ELE7_TOUCH_STATUS, 2);
455  return rawdata[0] | ((rawdata[1] & 0b00011111) << 8);
456  }
457 
458  // Reads the 15 out of range bits.
459  // [13]: auto-config fail flag
460  // [14]: auto-reconfig fail flag
462  byte* rawdata = readRegister(MPRREG_ELE0_TO_ELE7_OOR_STATUS, 2);
463  byte autoConfBits = ((rawdata[1] & 0b10000000) >> 2) | (rawdata[1] & 0b01000000);
464  return rawdata[0] | ((rawdata[1] & 0b00011111) << 8) | (autoConfBits << 8);
465  }
466 #else // MPR121_USE_BITFIELDS
467  // Reads the 13 touch state bools.
468  // Also use this for reading GPIO inputs.
469  bool* mpr121::readTouchState() {
470  byte* rawdata = readRegister(MPRREG_ELE0_TO_ELE7_TOUCH_STATUS, 2);
471 
472  electrodeTouchBuf[0] = bitRead(rawdata[0], 0);
473  electrodeTouchBuf[1] = bitRead(rawdata[0], 1);
474  electrodeTouchBuf[2] = bitRead(rawdata[0], 2);
475  electrodeTouchBuf[3] = bitRead(rawdata[0], 3);
476  electrodeTouchBuf[4] = bitRead(rawdata[0], 4);
477  electrodeTouchBuf[5] = bitRead(rawdata[0], 5);
478  electrodeTouchBuf[6] = bitRead(rawdata[0], 6);
479  electrodeTouchBuf[7] = bitRead(rawdata[0], 7);
480 
481  electrodeTouchBuf[8] = bitRead(rawdata[1], 0);
482  electrodeTouchBuf[9] = bitRead(rawdata[1], 1);
483  electrodeTouchBuf[10] = bitRead(rawdata[1], 2);
484  electrodeTouchBuf[11] = bitRead(rawdata[1], 3);
485  electrodeTouchBuf[12] = bitRead(rawdata[1], 4);
486 
487  // electrodeTouchBuf[13] = bitRead(rawdata[1], 7);
488 
489  return electrodeTouchBuf;
490  }
491 
492  // Reads the 15 out of range bools.
493  // [13]: auto-config fail flag
494  // [14]: auto-reconfig fail flag
495  bool* mpr121::readOORState() {
496  byte* rawdata = readRegister(MPRREG_ELE0_TO_ELE7_OOR_STATUS, 2);
497 
498  electrodeOORBuf[0] = bitRead(rawdata[0], 0);
499  electrodeOORBuf[1] = bitRead(rawdata[0], 1);
500  electrodeOORBuf[2] = bitRead(rawdata[0], 2);
501  electrodeOORBuf[3] = bitRead(rawdata[0], 3);
502  electrodeOORBuf[4] = bitRead(rawdata[0], 4);
503  electrodeOORBuf[5] = bitRead(rawdata[0], 5);
504  electrodeOORBuf[6] = bitRead(rawdata[0], 6);
505  electrodeOORBuf[7] = bitRead(rawdata[0], 7);
506 
507  electrodeOORBuf[8] = bitRead(rawdata[1], 0);
508  electrodeOORBuf[9] = bitRead(rawdata[1], 1);
509  electrodeOORBuf[10] = bitRead(rawdata[1], 2);
510  electrodeOORBuf[11] = bitRead(rawdata[1], 3);
511  electrodeOORBuf[12] = bitRead(rawdata[1], 4);
512 
513  electrodeOORBuf[13] = bitRead(rawdata[1], 7);
514  electrodeOORBuf[14] = bitRead(rawdata[1], 6);
515 
516  return electrodeOORBuf;
517  }
518 #endif // MPR121_USE_BITFIELDS
519 
520 
521 // Reads the over current flag.
522 // (over current on REXT pin, probably shouldn't happen in normal operation)
524  return bitRead(readRegister(MPRREG_ELE8_TO_ELEPROX_TOUCH_STATUS), 7);
525 }
526 
527 // Clears the over current flag.
528 // (over current on REXT pin, probably shouldn't happen in normal operation)
530  writeRegister(MPRREG_ELE8_TO_ELEPROX_TOUCH_STATUS, 0b10000000);
531 }
532 
533 
534 // Reads filtered analog data for consecutive electrodes.
535 short* mpr121::readElectrodeData(byte electrode, byte count) {
536  if (!checkElectrodeNum(electrode, count))
537  return electrodeDataBuf;
538 
539  byte* rawdata = readRegister((mpr121Register)(MPRREG_ELE0_FILTERED_DATA_LSB + electrode*2), count*2);
540 
541  for (byte i = 0; i < count; i++) {
542  electrodeDataBuf[electrode + i] = rawdata[i*2] | ((rawdata[i*2 + 1] & 0b00000011) << 8);
543  }
544 
545  return &electrodeDataBuf[electrode];
546 }
547 
548 // Reads baseline values for consecutive electrodes.
549 byte* mpr121::readElectrodeBaseline(byte electrode, byte count) {
550  if (!checkElectrodeNum(electrode, count))
551  return electrodeBaselineBuf;
552 
553  byte* rawdata = readRegister((mpr121Register)(MPRREG_ELE0_BASELINE + electrode), count);
554 
555  for (byte i = 0; i < count; i++) {
556  electrodeBaselineBuf[electrode + i] = rawdata[i];
557  }
558 
559  return &electrodeBaselineBuf[electrode];
560 }
561 
562 // Write a baseline value to consecutive electrodes.
563 void mpr121::writeElectrodeBaseline(byte electrode, byte count, byte value) {
564  if (!checkElectrodeNum(electrode, count))
565  return;
566 
567  for (byte i = 0; i < count; i++) {
568  writeRegister((mpr121Register)(MPRREG_ELE0_BASELINE + (i+electrode)), value);
569  }
570 }
571 
572 // A quick way to set all touchThresholds and releaseThresholds.
573 // prox: Whether to set proximity detection thresholds too.
574 void mpr121::setAllThresholds(byte touched, byte released, bool prox) {
575  byte maxElectrode = 11;
576  if (prox)
577  maxElectrode = 12;
578 
579  for (byte i = 0; i <= maxElectrode; i++) {
580  touchThresholds[i] = touched;
581  releaseThresholds[i] = released;
582  }
583 }
584 
585 
586 // Reads per-electrode "Charge Discharge Current" (μA) for consecutive electrodes.
587 // Max: 63
588 byte* mpr121::readElectrodeCDC(byte electrode, byte count) {
589  if (!checkElectrodeNum(electrode, count))
590  return electrodeCDCBuf;
591 
592  byte* rawdata = readRegister((mpr121Register)(MPRREG_ELE0_CDC + electrode), count);
593 
594  for (byte i = 0; i < count; i++) {
595  electrodeCDCBuf[electrode + i] = rawdata[i];
596  }
597 
598  return &electrodeCDCBuf[electrode];
599 }
600 
601 // Writes per-electrode "Charge Discharge Current" (μA) for consecutive electrodes.
602 // Max: 63
603 void mpr121::writeElectrodeCDC(byte electrode, byte count, byte value) {
604  if (!checkElectrodeNum(electrode, count))
605  return;
606 
607  for (byte i = 0; i < count; i++) {
608  writeRegister((mpr121Register)(MPRREG_ELE0_CDC + (electrode + i)), value);
609  }
610 }
611 
612 // Reads per-electrode "Charge Discharge Time" (μs) for consecutive electrodes.
613 mpr121FilterCDT* mpr121::readElectrodeCDT(byte electrode, byte count) {
614  if (!checkElectrodeNum(electrode, count))
615  return electrodeCDTBuf;
616 
617  byte* rawdata = readRegister((mpr121Register)(MPRREG_ELE0_ELE1_CDT + electrode/2), (electrode % 2 == 0 ? (count+1) / 2 : (count+2) / 2));
618 
619  for (byte i = 0; i < count; i++) {
620  mpr121FilterCDT value;
621  if (electrode % 2 == 0)
622  value = (mpr121FilterCDT)(( rawdata[i / 2] >> (i % 2 == 0 ? 0 : 4) ) & 0b111);
623  else
624  value = (mpr121FilterCDT)(( rawdata[(i+1) / 2] >> (i % 2 == 0 ? 4 : 0) ) & 0b111);
625 
626  electrodeCDTBuf[electrode + i] = value;
627  }
628 
629  return &electrodeCDTBuf[electrode];
630 }
631 
632 // Writes per-electrode "Charge Discharge Time" (μs) for consecutive electrodes.
633 void mpr121::writeElectrodeCDT(byte electrode, byte count, mpr121FilterCDT value) {
634  if (!checkElectrodeNum(electrode, count))
635  return;
636 
637  byte value_3 = value & 0b111;
638 
639  mpr121Register reg = MPRREG_ELE0_ELE1_CDT;
640  byte regVal = 0;
641 
642  for (byte i = 0; i < count; i++) {
643  if (i == 0 || (electrode + i) % 2 == 0) { // if just starting or moving to a new register's start
644  reg = (mpr121Register)(MPRREG_ELE0_ELE1_CDT + (electrode + i)/2);
645  regVal = readRegister(reg);
646  }
647 
648  if ((electrode + i) % 2 == 0)
649  regVal = (regVal & 0b11110000) | value_3;
650  else
651  regVal = (regVal & 0b00001111) | (value_3 << 4);
652 
653  if ((electrode + i) % 2 == 1 || i == count - 1) // if the last of a register or the last iteration
654  writeRegister(reg, regVal);
655  }
656 }
657 
658 
659 // Sets pin mode for consecutive GPIO pins.
660 // GPIO can be used on pins 4-11 when they aren't used for sensing.
661 // Use mode MPR_GPIO_MODE_OUTPUT_OPENDRAIN_HIGH for direct LED driving -- it can source up to 12mA.
662 void mpr121::setGPIOMode(byte pin, byte count, mpr121GPIOMode mode) {
663  if (!checkGPIOPinNum(pin, count))
664  return;
665 
666  pin -= 4; // easier to make it 0-indexed now
667 
668 
669  byte enableByte = readRegister(MPRREG_GPIO_ENABLE);
670 
671  // disable the modified outputs while changing stuff around
672  for (byte i = 0; i < count; i++) {
673  bitClear(enableByte, pin + i);
674  }
675  writeRegister(MPRREG_GPIO_ENABLE, enableByte);
676 
677  if (mode == MPR_GPIO_MODE_DISABLED)
678  return; // all done, no need to worry about other values
679 
680 
681  byte tempByte;
682  bool tempVal;
683 
684  // set direction
685  tempByte = readRegister(MPRREG_GPIO_DIRECTION);
686  tempVal = bitRead(mode, 2); // settings are bit-packed into the enum to save doing lookups
687  for (byte i = 0; i < count; i++) {
688  bitWrite(tempByte, pin + i, tempVal);
689  }
690  writeRegister(MPRREG_GPIO_DIRECTION, tempByte);
691 
692  // set control 0 (enable internal resistors or open drain mode)
693  tempByte = readRegister(MPRREG_GPIO_CONTROL_0);
694  tempVal = bitRead(mode, 1);
695  for (byte i = 0; i < count; i++) {
696  bitWrite(tempByte, pin + i, tempVal);
697  }
698  writeRegister(MPRREG_GPIO_CONTROL_0, tempByte);
699 
700  // set control 1 (internal resistor or open drain level)
701  tempByte = readRegister(MPRREG_GPIO_CONTROL_1);
702  tempVal = bitRead(mode, 0);
703  for (byte i = 0; i < count; i++) {
704  bitWrite(tempByte, pin + i, tempVal);
705  }
706  writeRegister(MPRREG_GPIO_CONTROL_1, tempByte);
707 
708 
709  // set enable to final value
710  tempVal = bitRead(mode, 3);
711  for (byte i = 0; i < count; i++) {
712  bitWrite(enableByte, pin + i, tempVal);
713  }
714  writeRegister(MPRREG_GPIO_ENABLE, enableByte);
715 }
716 
717 
718 // Writes a digital value to consecutive GPIO pins.
719 void mpr121::writeGPIODigital(byte pin, byte count, bool value) {
720  if (!checkGPIOPinNum(pin, count))
721  return;
722 
723  // disable PWM for affected pins
724  // (doesn't use 0-indexed GPIO pin number)
725  setPWM(pin, count, 0);
726 
727  pin -= 4; // easier to make it 0-indexed now
728 
729 
730  mpr121Register reg = value ? MPRREG_GPIO_DATA_SET : MPRREG_GPIO_DATA_CLEAR;
731 
732  byte tempByte = 0;
733  for (byte i = 0; i < count; i++) {
734  bitSet(tempByte, pin + i);
735  }
736  writeRegister(reg, tempByte);
737 }
738 
739 
740 // Writes an "analog" (PWM) value to consecutive GPIO pins.
741 // Max value is 15
742 // Pin 9 apparently has a logic bug and pin 10 must also have its data set high for it to work.
743 // (see https://community.nxp.com/thread/305474)
744 void mpr121::writeGPIOAnalog(byte pin, byte count, byte value) {
745  if (!checkGPIOPinNum(pin, count))
746  return;
747 
748  // set PWM for affected pins
749  // (doesn't use 0-indexed GPIO pin number)
750  setPWM(pin, count, value);
751 
752  pin -= 4; // easier to make it 0-indexed now
753 
754 
755  mpr121Register reg = value == 0 ? MPRREG_GPIO_DATA_CLEAR : MPRREG_GPIO_DATA_SET;
756 
757  byte tempByte = 0;
758  for (byte i = 0; i < count; i++) {
759  bitSet(tempByte, pin + i);
760  }
761  writeRegister(reg, tempByte);
762 }
763 
764 
765 // Optional alternative to using Wire.begin() and Wire.setClock().
766 // Also has a built-in delay to ensure MPR121s are ready.
767 void mpr121::begin(unsigned long clock) {
768  while (millis() < 5)
769  delay(1);
770 
771  i2cWire->end(); // apparently some platforms have issues with double starts, I guess this fixes it
772  i2cWire->begin();
773  i2cWire->setClock(clock);
774 }
775 
776 
777 // Applies settings and enters run mode with a given number of electrodes.
778 // Very much based on the quick start guide (AN3944).
779 void mpr121::start(byte electrodes) {
780  stop();
781 
782  // restrict value of numeric properties with < 8 bits to actual sent values
783  MHDrising &= 0b00111111;
784  MHDfalling &= 0b00111111;
785  NHDrising &= 0b00111111;
786  NHDfalling &= 0b00111111;
787  NHDtouched &= 0b00111111;
788  MHDrisingProx &= 0b00111111;
789  MHDfallingProx &= 0b00111111;
790  NHDrisingProx &= 0b00111111;
791  NHDfallingProx &= 0b00111111;
792  NHDtouchedProx &= 0b00111111;
793  debounceTouch &= 0b0111;
794  debounceRelease &= 0b0111;
795  globalCDC &= 0b00111111;
796 
797  // set/calculate autoconfig values
798  if (autoConfigUSL == 0)
799  autoConfigUSL = 156;
800  if (autoConfigLSL == 0)
801  autoConfigLSL = autoConfigUSL * 0.65;
802  if (autoConfigTL == 0)
803  autoConfigTL = autoConfigUSL * 0.9;
804 
805  setMHD(MHDrising, MHDfalling);
806  setNHD(NHDrising, NHDfalling, NHDtouched);
807  setNCL(NCLrising, NCLfalling, NCLtouched);
808  setFDL(FDLrising, FDLfalling, FDLtouched);
809 
810  setMHDProx(MHDrisingProx, MHDfallingProx);
814 
815  for (byte i = 0; i < 13; i++)
816  {
817  mpr121::setElectrodeThresholds(i, touchThresholds[i], releaseThresholds[i]);
818  }
819 
820  setDebounce(debounceTouch, debounceRelease);
821 
822  setFilterConfig(FFI, globalCDC, globalCDT, SFI, ESI);
823 
826 
827  // OVCF blocks starting, so reset it
828  if (readOverCurrent())
830 
831  setElectrodeConfiguration(calLock, proxEnable, electrodes);
832 }
833 
834 // Exits run mode.
835 void mpr121::stop() {
836  byte oldConfig = readRegister(MPRREG_ELECTRODE_CONFIG);
837  writeRegister(MPRREG_ELECTRODE_CONFIG, oldConfig & 0b11000000);
838 }
839 
840 
841 // Checks if the MPR121 is in run mode.
843  return (readRegister(MPRREG_ELECTRODE_CONFIG) & 0b00111111) != 0;
844 }
845 
846 
847 // Resets the MPR121.
849  writeRegister(MPRREG_SOFT_RESET, 0x63);
850 }
851 
MPR_FFI_6
@ MPR_FFI_6
6 samples taken
Definition: QuickMpr121Enums.h:11
mpr121::SFI
mpr121FilterSFI SFI
"Second Filter Iterations" (number of samples taken for the second level of filtering)
Definition: QuickMpr121.h:355
mpr121::writeGPIODigital
void writeGPIODigital(byte pin, byte count, bool value)
Writes a digital value to consecutive GPIO pins.
Definition: QuickMpr121.cpp:719
mpr121::setGPIOMode
void setGPIOMode(byte pin, byte count, mpr121GPIOMode mode)
Sets pin mode for consecutive GPIO pins.
Definition: QuickMpr121.cpp:662
MPR_AUTOCONFIG_BVA_SET_CLEAR3
@ MPR_AUTOCONFIG_BVA_SET_CLEAR3
Baseline is set to the auto-config baseline with the lower 3 bits cleared.
Definition: QuickMpr121Enums.h:79
mpr121::readElectrodeCDT
mpr121FilterCDT * readElectrodeCDT(byte electrode, byte count)
Reads per-electrode "Charge Discharge Time" (μs) for consecutive electrodes.
Definition: QuickMpr121.cpp:613
mpr121::writeElectrodeCDT
void writeElectrodeCDT(byte electrode, byte count, mpr121FilterCDT value)
Writes per-electrode "Charge Discharge Time" (μs) for consecutive electrodes.
Definition: QuickMpr121.cpp:633
mpr121::begin
void begin(unsigned long clock=400000)
Optional alternative to using Wire.begin() and Wire.setClock().
Definition: QuickMpr121.cpp:767
mpr121::autoConfigLSL
byte autoConfigLSL
"Low-Side Limit" for auto calibration – if not set when starting, this will be automatically set base...
Definition: QuickMpr121.h:363
mpr121::calLock
mpr121ElectrodeConfigCL calLock
"Calibration Lock" (baseline tracking and initial value settings)
Definition: QuickMpr121.h:359
mpr121AutoConfigRetry
mpr121AutoConfigRetry
possible auto-configuration "retry" settings
Definition: QuickMpr121Enums.h:66
mpr121::clearOverCurrent
void clearOverCurrent()
Clears the over current flag.
Definition: QuickMpr121.cpp:529
MPR_CL_TRACKING_ENABLED
@ MPR_CL_TRACKING_ENABLED
Baseline tracking enabled, initial baseline value is current value in baseline value register.
Definition: QuickMpr121Enums.h:51
mpr121::autoConfigTL
byte autoConfigTL
"Target Level" for auto calibration – if not set when starting, this will be automatically set based ...
Definition: QuickMpr121.h:364
mpr121::releaseThresholds
byte releaseThresholds[13]
Release detection thresholds for ELE0-ELE11 and ELEPROX.
Definition: QuickMpr121.h:314
mpr121::NHDrising
byte NHDrising
"Noise Half Delta" rising baseline adjustment value (AN3891) – max: 63
Definition: QuickMpr121.h:319
mpr121::FDLrisingProx
byte FDLrisingProx
"Filter Delay Limit" rising value for proximity detection (AN3891/AN3893)
Definition: QuickMpr121.h:343
mpr121::autoConfigSkipChargeTime
bool autoConfigSkipChargeTime
"Skip Charge Time Search" will skip searching for charge time and use the already-set per-electrode o...
Definition: QuickMpr121.h:370
mpr121::globalCDC
byte globalCDC
Global "Charge Discharge Current" (μA), not used if autoconfig is enabled – max 63.
Definition: QuickMpr121.h:353
mpr121::NCLtouched
byte NCLtouched
"Noise Count Limit" touched baseline adjustment value (AN3891)
Definition: QuickMpr121.h:325
mpr121::FDLtouchedProx
byte FDLtouchedProx
"Filter Delay Limit" touched value for proximity detection (AN3891/AN3893)
Definition: QuickMpr121.h:345
mpr121::autoConfigInterruptARF
bool autoConfigInterruptARF
"Auto-reconfiguration fail interrupt enable" will trigger an interrupt when auto-reconfiguration fail...
Definition: QuickMpr121.h:374
mpr121::NCLrising
byte NCLrising
"Noise Count Limit" rising baseline adjustment value (AN3891)
Definition: QuickMpr121.h:323
mpr121FilterSFI
mpr121FilterSFI
possible "second filter iterations" settings
Definition: QuickMpr121Enums.h:30
MPR_CDT_0_5
@ MPR_CDT_0_5
0.5 microseconds
Definition: QuickMpr121Enums.h:20
mpr121::writeGPIOAnalog
void writeGPIOAnalog(byte pin, byte count, byte value)
Writes an "analog" (PWM) value to consecutive GPIO pins.
Definition: QuickMpr121.cpp:744
mpr121::writeElectrodeBaseline
void writeElectrodeBaseline(byte electrode, byte count, byte value)
Writes a baseline value to consecutive electrodes.
Definition: QuickMpr121.cpp:563
mpr121::NHDfalling
byte NHDfalling
"Noise Half Delta" falling baseline adjustment value (AN3891) – max: 63
Definition: QuickMpr121.h:320
mpr121::checkRunning
bool checkRunning()
Checks if the MPR121 is in run mode.
Definition: QuickMpr121.cpp:842
mpr121FilterFFI
mpr121FilterFFI
possible "first filter iterations" settings
Definition: QuickMpr121Enums.h:10
mpr121::autoConfigUSL
byte autoConfigUSL
"Up-Side Limit" for auto calibration – if not set when starting, this will be automatically set to th...
Definition: QuickMpr121.h:362
mpr121FilterCDT
mpr121FilterCDT
possible "charge discharge time" settings
Definition: QuickMpr121Enums.h:18
mpr121::proxEnable
mpr121ElectrodeConfigProx proxEnable
ELEPROX_EN: sets what electrodes will be used for proximity detection.
Definition: QuickMpr121.h:360
MPR_GPIO_MODE_DISABLED
@ MPR_GPIO_MODE_DISABLED
Pin is disabled.
Definition: QuickMpr121Enums.h:88
mpr121::softReset
void softReset()
Resets the MPR121.
Definition: QuickMpr121.cpp:848
mpr121::NCLfallingProx
byte NCLfallingProx
"Noise Count Limit" falling value for proximity detection (AN3891/AN3893)
Definition: QuickMpr121.h:340
mpr121::readElectrodeData
short * readElectrodeData(byte electrode, byte count)
Reads filtered analog data for consecutive electrodes.
Definition: QuickMpr121.cpp:535
mpr121::NHDrisingProx
byte NHDrisingProx
"Noise Half Delta" rising value for proximity detection (AN3891/AN3893) – max: 63
Definition: QuickMpr121.h:335
mpr121::stop
void stop()
Exits run mode.
Definition: QuickMpr121.cpp:835
MPR_SFI_4
@ MPR_SFI_4
4 samples taken
Definition: QuickMpr121Enums.h:31
mpr121::autoConfigInterruptACF
bool autoConfigInterruptACF
"Auto-configuration fail interrupt enable" will trigger an interrupt when auto-configuration fails
Definition: QuickMpr121.h:375
mpr121::NCLfalling
byte NCLfalling
"Noise Count Limit" falling baseline adjustment value (AN3891)
Definition: QuickMpr121.h:324
mpr121::setAllThresholds
void setAllThresholds(byte touched, byte released, bool prox)
A quick way to set all ::touchThresholds and ::releaseThresholds.
Definition: QuickMpr121.cpp:574
mpr121::autoConfigBaselineAdjust
mpr121AutoConfigBVA autoConfigBaselineAdjust
"Baseline Value Adjust" changes how the baseline registers will be set after auto-configuration compl...
Definition: QuickMpr121.h:366
mpr121::autoConfigRetry
mpr121AutoConfigRetry autoConfigRetry
Number of retries for failed auto-config before out of range will be set.
Definition: QuickMpr121.h:365
mpr121::NCLtouchedProx
byte NCLtouchedProx
"Noise Count Limit" touched value for proximity detection (AN3891/AN3893)
Definition: QuickMpr121.h:341
mpr121::readElectrodeCDC
byte * readElectrodeCDC(byte electrode, byte count)
Reads per-electrode "Charge Discharge Current" (μA) for consecutive electrodes.
Definition: QuickMpr121.cpp:588
mpr121::readOverCurrent
bool readOverCurrent()
Reads the over current flag.
Definition: QuickMpr121.cpp:523
mpr121::debounceRelease
byte debounceRelease
Set "Debounce" count for releases (times a detection must be sampled) – max: 7.
Definition: QuickMpr121.h:349
mpr121::NCLrisingProx
byte NCLrisingProx
"Noise Count Limit" rising value for proximity detection (AN3891/AN3893)
Definition: QuickMpr121.h:339
mpr121::autoConfigEnableReconfig
bool autoConfigEnableReconfig
"Automatic Reconfiguration Enable" will try to reconfigure out of range (failed) channels every sampl...
Definition: QuickMpr121.h:367
mpr121::MHDrisingProx
byte MHDrisingProx
"Max Half Delta" rising value for proximity detection (AN3891/AN3893) – max: 63
Definition: QuickMpr121.h:332
mpr121::globalCDT
mpr121FilterCDT globalCDT
Global "Charge Discharge Time" (μs), not used if autoconfig is enabled.
Definition: QuickMpr121.h:354
mpr121ElectrodeConfigProx
mpr121ElectrodeConfigProx
possible "proximity enable" settings
Definition: QuickMpr121Enums.h:58
mpr121::NHDfallingProx
byte NHDfallingProx
"Noise Half Delta" falling value for proximity detection (AN3891/AN3893) – max: 63
Definition: QuickMpr121.h:336
mpr121::readTouchState
short readTouchState()
Reads the 13 touch state bits.
Definition: QuickMpr121.cpp:453
mpr121::MHDfalling
byte MHDfalling
"Max Half Delta" falling baseline adjustment value (AN3891) – max: 63
Definition: QuickMpr121.h:317
mpr121::readOORState
short readOORState()
Reads the 15 out of range bits.
Definition: QuickMpr121.cpp:461
mpr121::FDLfallingProx
byte FDLfallingProx
"Filter Delay Limit" falling value for proximity detection (AN3891/AN3893)
Definition: QuickMpr121.h:344
mpr121::touchThresholds
byte touchThresholds[13]
Touch detection thresholds for ELE0-ELE11 and ELEPROX.
Definition: QuickMpr121.h:313
mpr121::FDLfalling
byte FDLfalling
"Filter Delay Limit" falling baseline adjustment value (AN3891)
Definition: QuickMpr121.h:328
mpr121GPIOMode
mpr121GPIOMode
GPIO pin modes.
Definition: QuickMpr121Enums.h:84
mpr121::NHDtouched
byte NHDtouched
"Noise Half Delta" touched baseline adjustment value (AN3891) – max: 63
Definition: QuickMpr121.h:321
MPR_ESI_1
@ MPR_ESI_1
1 ms
Definition: QuickMpr121Enums.h:39
mpr121::debounceTouch
byte debounceTouch
Set "Debounce" count for touches (times a detection must be sampled) – max: 7.
Definition: QuickMpr121.h:348
MPR_ELEPROX_DISABLED
@ MPR_ELEPROX_DISABLED
Proximity detection disabled.
Definition: QuickMpr121Enums.h:59
mpr121::MHDrising
byte MHDrising
"Max Half Delta" rising baseline adjustment value (AN3891) – max: 63
Definition: QuickMpr121.h:316
mpr121FilterESI
mpr121FilterESI
possible "electrode sample interval" settings
Definition: QuickMpr121Enums.h:38
mpr121::FDLtouched
byte FDLtouched
"Filter Delay Limit" touched baseline adjustment value (AN3891)
Definition: QuickMpr121.h:329
mpr121::FDLrising
byte FDLrising
"Filter Delay Limit" rising baseline adjustment value (AN3891)
Definition: QuickMpr121.h:327
mpr121::mpr121
mpr121(byte addr=0, TwoWire *wire=&Wire)
Creates an MPR121 device with sane default settings.
Definition: QuickMpr121.cpp:308
mpr121ElectrodeConfigCL
mpr121ElectrodeConfigCL
possible "calibration lock" settings
Definition: QuickMpr121Enums.h:50
mpr121::NHDtouchedProx
byte NHDtouchedProx
"Noise Half Delta" touched value for proximity detection (AN3891/AN3893) – max: 63
Definition: QuickMpr121.h:337
mpr121::MHDfallingProx
byte MHDfallingProx
"Max Half Delta" falling value for proximity detection (AN3891/AN3893) – max: 63
Definition: QuickMpr121.h:333
mpr121AutoConfigBVA
mpr121AutoConfigBVA
possible auto-configuration "baseline value adjust" settings
Definition: QuickMpr121Enums.h:76
mpr121::ESI
mpr121FilterESI ESI
"Electrode Sample Interval" (ms)
Definition: QuickMpr121.h:356
mpr121Register
mpr121Register
all MPR121 registers
Definition: QuickMpr121Enums.h:98
mpr121::readElectrodeBaseline
byte * readElectrodeBaseline(byte electrode, byte count)
Reads baseline values for consecutive electrodes.
Definition: QuickMpr121.cpp:549
mpr121::FFI
mpr121FilterFFI FFI
"First Filter Iterations" (number of samples taken for the first level of filtering)
Definition: QuickMpr121.h:352
mpr121::start
void start(byte electrodes)
Applies settings and enters run mode with a given number of electrodes.
Definition: QuickMpr121.cpp:779
MPR_AUTOCONFIG_RETRY_DISABLED
@ MPR_AUTOCONFIG_RETRY_DISABLED
No retries.
Definition: QuickMpr121Enums.h:67
mpr121::autoConfigEnableCalibration
bool autoConfigEnableCalibration
"Automatic Configuration Enable" will enable/disable auto-configuration when entering run mode
Definition: QuickMpr121.h:368
mpr121::writeElectrodeCDC
void writeElectrodeCDC(byte electrode, byte count, byte value)
Writes per-electrode "Charge Discharge Current" (μA) for consecutive electrodes.
Definition: QuickMpr121.cpp:603
mpr121::autoConfigInterruptOOR
bool autoConfigInterruptOOR
"Out-of-range interrupt enable" will trigger an interrupt when a channel is determined to be out of r...
Definition: QuickMpr121.h:373