21
21
#ifdef ARDUINO_INKPLATE6FLICK
22
22
23
23
// Macro helpers.
24
- #define TS_GET_BOOTLOADERMODE (reg ) (((reg) & 0x10 ) >> 4 )
24
+ #define TS_GET_BOOTLOADERMODE (reg ) (((reg)& 0x10 ) >> 4 )
25
25
26
26
/* *
27
27
* @brief touchInArea checks if touch occured in given rectangle area
39
39
*/
40
40
bool Touch::touchInArea (int16_t x1, int16_t y1, int16_t w, int16_t h)
41
41
{
42
-
43
42
}
44
43
45
44
/* *
@@ -64,7 +63,8 @@ bool Touch::tsInit(uint8_t _pwrState)
64
63
tsReset ();
65
64
66
65
// Try to ping it.
67
- if (!tsPing (5 )) return false ;
66
+ if (!tsPing (5 ))
67
+ return false ;
68
68
69
69
// Issue a SW reset.
70
70
tsSendCommand (0x01 );
@@ -121,12 +121,11 @@ void Touch::tsShutdown()
121
121
*
122
122
* @param uint8_t *b
123
123
* pointer to store register content
124
- *
124
+ *
125
125
* @note Array must be at least 15 bytes long.
126
126
*/
127
127
void Touch::tsGetRawData (uint8_t *b)
128
128
{
129
-
130
129
}
131
130
132
131
/* *
@@ -145,25 +144,25 @@ void Touch::tsGetRawData(uint8_t *b)
145
144
*/
146
145
uint8_t Touch::tsGetData (uint16_t *xPos, uint16_t *yPos)
147
146
{
148
-
149
147
}
150
148
151
149
/* *
152
150
* @brief Set power mode of the Touchscreen Controller. There are 3 modes
153
151
* CYPRESS_TOUCH_OPERATE_MODE - Normal mode (fast response, higher accuracy, higher power consumption).
154
152
* Current ~ 15mA.
155
- * CYPRESS_TOUCH_LOW_POWER_MODE - After few seconds of inactivity, TSC goes into low power ode and periodically
156
- * goes into operating mode to check for touch event. Current ~4mA.
157
- * CYPRESS_TOUCH_DEEP_SLEEP_MODE - Disable TSC. Current ~25uA.
158
- *
153
+ * CYPRESS_TOUCH_LOW_POWER_MODE - After few seconds of inactivity, TSC goes into low power ode and
154
+ * periodically goes into operating mode to check for touch event. Current ~4mA. CYPRESS_TOUCH_DEEP_SLEEP_MODE - Disable
155
+ * TSC. Current ~25uA.
156
+ *
159
157
* @param uint8_t _s
160
- * Power mode - Can only be CYPRESS_TOUCH_OPERATE_MODE, CYPRESS_TOUCH_LOW_POWER_MODE or CYPRESS_TOUCH_DEEP_SLEEP_MODE.
161
- * [defined in TouchCypress.h]
158
+ * Power mode - Can only be CYPRESS_TOUCH_OPERATE_MODE, CYPRESS_TOUCH_LOW_POWER_MODE or
159
+ * CYPRESS_TOUCH_DEEP_SLEEP_MODE. [defined in TouchCypress.h]
162
160
*/
163
161
void Touch::tsSetPowerState (uint8_t _s)
164
162
{
165
163
// Check for the parameters.
166
- if ((_s == CYPRESS_TOUCH_DEEP_SLEEP_MODE) || (_s == CYPRESS_TOUCH_LOW_POWER_MODE) || (_s == CYPRESS_TOUCH_OPERATE_MODE))
164
+ if ((_s == CYPRESS_TOUCH_DEEP_SLEEP_MODE) || (_s == CYPRESS_TOUCH_LOW_POWER_MODE) ||
165
+ (_s == CYPRESS_TOUCH_OPERATE_MODE))
167
166
{
168
167
// Set new power mode setting.
169
168
tsSendCommand (_s);
@@ -196,7 +195,8 @@ uint8_t Touch::tsGetPowerState()
196
195
bool Touch::tsAvailable ()
197
196
{
198
197
// Check for the handshake.
199
- if (_tsFlag) tsHandshake ();
198
+ if (_tsFlag)
199
+ tsHandshake ();
200
200
bool _temp = _tsFlag;
201
201
_tsFlag = false ;
202
202
return _temp;
@@ -206,7 +206,7 @@ bool Touch::tsAvailable()
206
206
// Private members.
207
207
/* *
208
208
* @brief Enable or disable power to the Touchscreen Controller.
209
- *
209
+ *
210
210
* @param bool _pwr
211
211
* true - Enable power to the Touchscreen/Touchscreen Controller.
212
212
* false - Disable power to the Touchscreen/Touchscreen Controller to reduce power
@@ -242,9 +242,9 @@ void Touch::tsPower(bool _pwr)
242
242
}
243
243
244
244
/* *
245
- * @brief Disable touchscreen. Detach interrupt, clear interrput flag, disable power to the
245
+ * @brief Disable touchscreen. Detach interrupt, clear interrput flag, disable power to the
246
246
* Touchscreen Controller.
247
- *
247
+ *
248
248
*/
249
249
void Touch::tsEnd ()
250
250
{
@@ -260,7 +260,7 @@ void Touch::tsEnd()
260
260
261
261
/* *
262
262
* @brief Method does a HW reset by using RST pin on the Touchscreen/Touchscreen Controller.
263
- *
263
+ *
264
264
*/
265
265
void Touch::tsReset ()
266
266
{
@@ -275,7 +275,7 @@ void Touch::tsReset()
275
275
276
276
/* *
277
277
* @brief Method executes a SW reset by using I2C command.
278
- *
278
+ *
279
279
*/
280
280
void Touch::tsSwReset ()
281
281
{
@@ -288,11 +288,11 @@ void Touch::tsSwReset()
288
288
289
289
/* *
290
290
* @brief Function reads bootloader registers from the Touchscreen Controller.
291
- *
291
+ *
292
292
* @param struct cyttspBootloaderData *_blDataPtr
293
293
* Defined in TouchCypressTypedefs.h, pointer to the struct cyttspBootloaderData to
294
294
* store bootloader registers data.
295
- *
295
+ *
296
296
* @return bool
297
297
* true - Loading bootloader data register was successfull.
298
298
* false - Loading bootloader data from the registers has failed.
@@ -302,7 +302,8 @@ bool Touch::tsLoadBootloaderRegs(struct cyttspBootloaderData *_blDataPtr)
302
302
// Bootloader temp. registers array.
303
303
uint8_t _bootloaderData[16 ];
304
304
305
- if (!tsReadI2CRegs (CYPRESS_TOUCH_BASE_ADDR, _bootloaderData, 16 )) return false ;
305
+ if (!tsReadI2CRegs (CYPRESS_TOUCH_BASE_ADDR, _bootloaderData, 16 ))
306
+ return false ;
306
307
307
308
// Parse Bootloader data into typedef struct.
308
309
memcpy (_blDataPtr, _bootloaderData, 16 );
@@ -313,23 +314,22 @@ bool Touch::tsLoadBootloaderRegs(struct cyttspBootloaderData *_blDataPtr)
313
314
/* *
314
315
* @brief Method forces Touchscreen Controller to exit bootloader mode and enters normal
315
316
* operating mode - to load preloaded firmware (possibly TTSP - TrueTouch Standard Product Firmware).
316
- *
317
+ *
317
318
* @return bool
318
319
* true - Touchscreen Controller quit bootloader mode and loaded TTSP FW that is currently executing.
319
320
* false - Touchscreen Controller failed to exit bootloader mode.
320
- *
321
+ *
321
322
* @note It exiting bootloader mode fails reading touch events will fail. Do not go further with the code for the
322
323
* Touchscreen.
323
324
*/
324
325
bool Touch::tsExitBootLoaderMode ()
325
326
{
326
327
// Bootloader command array.
327
- uint8_t _blCommandArry[] =
328
- {
329
- 0x00 , // File offset.
330
- 0xFF , // Command.
331
- 0xA5 , // Exit bootloader command.
332
- 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 // Default keys.
328
+ uint8_t _blCommandArry[] = {
329
+ 0x00 , // File offset.
330
+ 0xFF , // Command.
331
+ 0xA5 , // Exit bootloader command.
332
+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 // Default keys.
333
333
};
334
334
335
335
// Write bootloader settings.
@@ -344,23 +344,24 @@ bool Touch::tsExitBootLoaderMode()
344
344
tsLoadBootloaderRegs (&_bootloaderData);
345
345
346
346
// Check for validity.
347
- if (TS_GET_BOOTLOADERMODE (_bootloaderData.bl_status )) return false ;
347
+ if (TS_GET_BOOTLOADERMODE (_bootloaderData.bl_status ))
348
+ return false ;
348
349
349
350
// If everything went ok return true.
350
351
return true ;
351
352
}
352
353
353
354
/* *
354
355
* @brief Set Touchscreen Controller into System Info mode.
355
- *
356
+ *
356
357
* @param struct cyttspSysinfoData *_sysDataPtr
357
358
* Defined cypressTouchTypedefs.h, pointer to the struct for the system info registers.
358
- *
359
+ *
359
360
* @return bool
360
361
* true - System Info mode usccessfully set.
361
362
* false - System Info mode failed.
362
- *
363
- * @note As soon as this fails, stop the Touchscreen from executing, touch data will be invalid.
363
+ *
364
+ * @note As soon as this fails, stop the Touchscreen from executing, touch data will be invalid.
364
365
*/
365
366
bool Touch::tsSetSysInfoMode (struct cyttspSysinfoData *_sysDataPtr)
366
367
{
@@ -397,14 +398,14 @@ bool Touch::tsSetSysInfoMode(struct cyttspSysinfoData *_sysDataPtr)
397
398
398
399
/* *
399
400
* @brief Set System info registers into their default state.
400
- *
401
+ *
401
402
* @param struct cyttspSysinfoData *_sysDataPtr
402
403
* Defined in TouchCypressTypedefs.h, poinet to the struct for the system info registers.
403
- *
404
+ *
404
405
* @return bool
405
406
* true - Registers are set successfully.
406
407
* false - Setting registers has failed.
407
- *
408
+ *
408
409
* @note Stop the tuchscreen code from executing if this fails, touch data will be invalid.
409
410
*/
410
411
bool Touch::tsSetSysInfoRegs (struct cyttspSysinfoData *_sysDataPtr)
@@ -417,7 +418,8 @@ bool Touch::tsSetSysInfoRegs(struct cyttspSysinfoData *_sysDataPtr)
417
418
uint8_t _regs[] = {_sysDataPtr->act_intrvl , _sysDataPtr->tch_tmout , _sysDataPtr->lp_intrvl };
418
419
419
420
// Send the registers to the I2C. Check if failed. If failed, return false.
420
- if (!tsWriteI2CRegs (0x1D , _regs, 3 )) return false ;
421
+ if (!tsWriteI2CRegs (0x1D , _regs, 3 ))
422
+ return false ;
421
423
422
424
// Wait a little bit.
423
425
delay (20 );
@@ -429,7 +431,7 @@ bool Touch::tsSetSysInfoRegs(struct cyttspSysinfoData *_sysDataPtr)
429
431
/* *
430
432
* @brief Method does handshake for the Touchscreen/Touchscreen Controller to confirm successfull read
431
433
* new touch report data.
432
- *
434
+ *
433
435
* @note Handshake must be done on every new touch event from the Interrupt.
434
436
*/
435
437
void Touch::tsHandshake ()
@@ -472,18 +474,18 @@ bool Touch::tsPing(int _retries)
472
474
473
475
/* *
474
476
* @brief Method sends I2C command to the Touchscreen Controller IC.
475
- *
477
+ *
476
478
* @param uint8_t _cmd
477
- * I2C command for the Touchscreen Controller IC.
478
- *
479
+ * I2C command for the Touchscreen Controller IC.
480
+ *
479
481
* @return true - Command is succesfully send and executed.
480
482
* false - I2C command send failed.
481
483
*/
482
484
bool Touch::tsSendCommand (uint8_t _cmd)
483
485
{
484
486
// Init I2C communication.
485
487
Wire.beginTransmission (CPYRESS_TOUCH_I2C_ADDR);
486
-
488
+
487
489
// I'm not sure about this?
488
490
// Write I2C sub-address (register address).
489
491
Wire.write (CYPRESS_TOUCH_BASE_ADDR);
@@ -495,23 +497,23 @@ bool Touch::tsSendCommand(uint8_t _cmd)
495
497
delay (20 );
496
498
497
499
// Send to I2C!
498
- return Wire.endTransmission () == 0 ? true : false ;
500
+ return Wire.endTransmission () == 0 ? true : false ;
499
501
}
500
502
501
503
/* *
502
504
* @brief Method reads multiple I2C registers at once from the touchscreen controller and save them into buffer.
503
- *
505
+ *
504
506
* @param uint8_t _cmd
505
507
* I2C command for the Touchscreen Controller.
506
508
* @param uint8_t *_buffer
507
- * Buffer for the bytes read from the Touchscreen Controller.
509
+ * Buffer for the bytes read from the Touchscreen Controller.
508
510
* @param int _len
509
511
* How many bytes to read from the I2C (Touchscreen Controller).
510
- *
512
+ *
511
513
* @return bool
512
514
* true - I2C register read was successfull.
513
515
* false - I2C register read failed.
514
- *
516
+ *
515
517
* @note More than 32 bytes can be read at the same time.
516
518
*/
517
519
bool Touch::tsReadI2CRegs (uint8_t _cmd, uint8_t *_buffer, int _len)
@@ -534,12 +536,12 @@ bool Touch::tsReadI2CRegs(uint8_t _cmd, uint8_t *_buffer, int _len)
534
536
while (_len > 0 )
535
537
{
536
538
// Check for the size of the remaining buffer.
537
- int _i2cLen = _len > 32 ? 32 : _len;
539
+ int _i2cLen = _len > 32 ? 32 : _len;
538
540
539
541
// Read the bytes from the I2C.
540
542
Wire.requestFrom (CPYRESS_TOUCH_I2C_ADDR, _i2cLen);
541
543
Wire.readBytes (_buffer + _index, _i2cLen);
542
-
544
+
543
545
// Update the buffer index position.
544
546
_index += _i2cLen;
545
547
@@ -553,18 +555,18 @@ bool Touch::tsReadI2CRegs(uint8_t _cmd, uint8_t *_buffer, int _len)
553
555
554
556
/* *
555
557
* @brief Method writes multiple I2C registers at once to the touchscreen controller from buffer provided.
556
- *
558
+ *
557
559
* @param uint8_t _cmd
558
560
* I2C command for the Touchscreen Controller.
559
561
* @param uint8_t *_buffer
560
- * Buffer for the bytes that needs to be sent to the Touchscreen Controller.
562
+ * Buffer for the bytes that needs to be sent to the Touchscreen Controller.
561
563
* @param int _len
562
564
* How many bytes to write to the I2C (Touchscreen Controller).
563
- *
565
+ *
564
566
* @return bool
565
567
* true - I2C register write was successfull.
566
568
* false - I2C register write failed.
567
- *
569
+ *
568
570
* @note More than 32 bytes can be written at the same time.
569
571
*/
570
572
bool Touch::tsWriteI2CRegs (uint8_t _cmd, uint8_t *_buffer, int _len)
0 commit comments