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
// Interrupt function callback for Touch Interruput event.
27
27
static volatile bool _tsFlag = false ;
@@ -111,7 +111,8 @@ bool Touch::tsInit(uint8_t _pwrState)
111
111
tsReset ();
112
112
113
113
// Try to ping it.
114
- if (!tsPing (5 )) return false ;
114
+ if (!tsPing (5 ))
115
+ return false ;
115
116
116
117
// Issue a SW reset.
117
118
tsSendCommand (0x01 );
@@ -171,7 +172,7 @@ void Touch::tsShutdown()
171
172
*
172
173
* @param uint8_t *b
173
174
* pointer to store register content
174
- *
175
+ *
175
176
* @note Array must be at least 15 bytes long.
176
177
*/
177
178
void Touch::tsGetRawData (uint8_t *b)
@@ -381,18 +382,19 @@ void Touch::tsScale(struct cypressTouchData *_touchData, uint16_t _xSize, uint16
381
382
* @brief Set power mode of the Touchscreen Controller. There are 3 modes
382
383
* CYPRESS_TOUCH_OPERATE_MODE - Normal mode (fast response, higher accuracy, higher power consumption).
383
384
* Current ~ 15mA.
384
- * CYPRESS_TOUCH_LOW_POWER_MODE - After few seconds of inactivity, TSC goes into low power ode and periodically
385
- * goes into operating mode to check for touch event. Current ~4mA.
386
- * CYPRESS_TOUCH_DEEP_SLEEP_MODE - Disable TSC. Current ~25uA.
387
- *
385
+ * CYPRESS_TOUCH_LOW_POWER_MODE - After few seconds of inactivity, TSC goes into low power ode and
386
+ * periodically goes into operating mode to check for touch event. Current ~4mA. CYPRESS_TOUCH_DEEP_SLEEP_MODE - Disable
387
+ * TSC. Current ~25uA.
388
+ *
388
389
* @param uint8_t _s
389
- * Power mode - Can only be CYPRESS_TOUCH_OPERATE_MODE, CYPRESS_TOUCH_LOW_POWER_MODE or CYPRESS_TOUCH_DEEP_SLEEP_MODE.
390
- * [defined in TouchCypress.h]
390
+ * Power mode - Can only be CYPRESS_TOUCH_OPERATE_MODE, CYPRESS_TOUCH_LOW_POWER_MODE or
391
+ * CYPRESS_TOUCH_DEEP_SLEEP_MODE. [defined in TouchCypress.h]
391
392
*/
392
393
void Touch::tsSetPowerState (uint8_t _s)
393
394
{
394
395
// Check for the parameters.
395
- if ((_s == CYPRESS_TOUCH_DEEP_SLEEP_MODE) || (_s == CYPRESS_TOUCH_LOW_POWER_MODE) || (_s == CYPRESS_TOUCH_OPERATE_MODE))
396
+ if ((_s == CYPRESS_TOUCH_DEEP_SLEEP_MODE) || (_s == CYPRESS_TOUCH_LOW_POWER_MODE) ||
397
+ (_s == CYPRESS_TOUCH_OPERATE_MODE))
396
398
{
397
399
// Set new power mode setting.
398
400
tsSendCommand (_s);
@@ -431,7 +433,7 @@ bool Touch::tsAvailable()
431
433
// Private members.
432
434
/* *
433
435
* @brief Enable or disable power to the Touchscreen Controller.
434
- *
436
+ *
435
437
* @param bool _pwr
436
438
* true - Enable power to the Touchscreen/Touchscreen Controller.
437
439
* false - Disable power to the Touchscreen/Touchscreen Controller to reduce power
@@ -467,9 +469,9 @@ void Touch::tsPower(bool _pwr)
467
469
}
468
470
469
471
/* *
470
- * @brief Disable touchscreen. Detach interrupt, clear interrput flag, disable power to the
472
+ * @brief Disable touchscreen. Detach interrupt, clear interrput flag, disable power to the
471
473
* Touchscreen Controller.
472
- *
474
+ *
473
475
*/
474
476
void Touch::tsEnd ()
475
477
{
@@ -485,7 +487,7 @@ void Touch::tsEnd()
485
487
486
488
/* *
487
489
* @brief Method does a HW reset by using RST pin on the Touchscreen/Touchscreen Controller.
488
- *
490
+ *
489
491
*/
490
492
void Touch::tsReset ()
491
493
{
@@ -500,7 +502,7 @@ void Touch::tsReset()
500
502
501
503
/* *
502
504
* @brief Method executes a SW reset by using I2C command.
503
- *
505
+ *
504
506
*/
505
507
void Touch::tsSwReset ()
506
508
{
@@ -513,11 +515,11 @@ void Touch::tsSwReset()
513
515
514
516
/* *
515
517
* @brief Function reads bootloader registers from the Touchscreen Controller.
516
- *
518
+ *
517
519
* @param struct cyttspBootloaderData *_blDataPtr
518
520
* Defined in TouchCypressTypedefs.h, pointer to the struct cyttspBootloaderData to
519
521
* store bootloader registers data.
520
- *
522
+ *
521
523
* @return bool
522
524
* true - Loading bootloader data register was successfull.
523
525
* false - Loading bootloader data from the registers has failed.
@@ -527,7 +529,8 @@ bool Touch::tsLoadBootloaderRegs(struct cyttspBootloaderData *_blDataPtr)
527
529
// Bootloader temp. registers array.
528
530
uint8_t _bootloaderData[16 ];
529
531
530
- if (!tsReadI2CRegs (CYPRESS_TOUCH_BASE_ADDR, _bootloaderData, 16 )) return false ;
532
+ if (!tsReadI2CRegs (CYPRESS_TOUCH_BASE_ADDR, _bootloaderData, 16 ))
533
+ return false ;
531
534
532
535
// Parse Bootloader data into typedef struct.
533
536
memcpy (_blDataPtr, _bootloaderData, 16 );
@@ -538,23 +541,22 @@ bool Touch::tsLoadBootloaderRegs(struct cyttspBootloaderData *_blDataPtr)
538
541
/* *
539
542
* @brief Method forces Touchscreen Controller to exit bootloader mode and enters normal
540
543
* operating mode - to load preloaded firmware (possibly TTSP - TrueTouch Standard Product Firmware).
541
- *
544
+ *
542
545
* @return bool
543
546
* true - Touchscreen Controller quit bootloader mode and loaded TTSP FW that is currently executing.
544
547
* false - Touchscreen Controller failed to exit bootloader mode.
545
- *
548
+ *
546
549
* @note It exiting bootloader mode fails reading touch events will fail. Do not go further with the code for the
547
550
* Touchscreen.
548
551
*/
549
552
bool Touch::tsExitBootLoaderMode ()
550
553
{
551
554
// Bootloader command array.
552
- uint8_t _blCommandArry[] =
553
- {
554
- 0x00 , // File offset.
555
- 0xFF , // Command.
556
- 0xA5 , // Exit bootloader command.
557
- 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 // Default keys.
555
+ uint8_t _blCommandArry[] = {
556
+ 0x00 , // File offset.
557
+ 0xFF , // Command.
558
+ 0xA5 , // Exit bootloader command.
559
+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 // Default keys.
558
560
};
559
561
560
562
// Write bootloader settings.
@@ -569,23 +571,24 @@ bool Touch::tsExitBootLoaderMode()
569
571
tsLoadBootloaderRegs (&_bootloaderData);
570
572
571
573
// Check for validity.
572
- if (TS_GET_BOOTLOADERMODE (_bootloaderData.bl_status )) return false ;
574
+ if (TS_GET_BOOTLOADERMODE (_bootloaderData.bl_status ))
575
+ return false ;
573
576
574
577
// If everything went ok return true.
575
578
return true ;
576
579
}
577
580
578
581
/* *
579
582
* @brief Set Touchscreen Controller into System Info mode.
580
- *
583
+ *
581
584
* @param struct cyttspSysinfoData *_sysDataPtr
582
585
* Defined cypressTouchTypedefs.h, pointer to the struct for the system info registers.
583
- *
586
+ *
584
587
* @return bool
585
588
* true - System Info mode usccessfully set.
586
589
* false - System Info mode failed.
587
- *
588
- * @note As soon as this fails, stop the Touchscreen from executing, touch data will be invalid.
590
+ *
591
+ * @note As soon as this fails, stop the Touchscreen from executing, touch data will be invalid.
589
592
*/
590
593
bool Touch::tsSetSysInfoMode (struct cyttspSysinfoData *_sysDataPtr)
591
594
{
@@ -622,14 +625,14 @@ bool Touch::tsSetSysInfoMode(struct cyttspSysinfoData *_sysDataPtr)
622
625
623
626
/* *
624
627
* @brief Set System info registers into their default state.
625
- *
628
+ *
626
629
* @param struct cyttspSysinfoData *_sysDataPtr
627
630
* Defined in TouchCypressTypedefs.h, poinet to the struct for the system info registers.
628
- *
631
+ *
629
632
* @return bool
630
633
* true - Registers are set successfully.
631
634
* false - Setting registers has failed.
632
- *
635
+ *
633
636
* @note Stop the tuchscreen code from executing if this fails, touch data will be invalid.
634
637
*/
635
638
bool Touch::tsSetSysInfoRegs (struct cyttspSysinfoData *_sysDataPtr)
@@ -642,7 +645,8 @@ bool Touch::tsSetSysInfoRegs(struct cyttspSysinfoData *_sysDataPtr)
642
645
uint8_t _regs[] = {_sysDataPtr->act_intrvl , _sysDataPtr->tch_tmout , _sysDataPtr->lp_intrvl };
643
646
644
647
// Send the registers to the I2C. Check if failed. If failed, return false.
645
- if (!tsWriteI2CRegs (0x1D , _regs, 3 )) return false ;
648
+ if (!tsWriteI2CRegs (0x1D , _regs, 3 ))
649
+ return false ;
646
650
647
651
// Wait a little bit.
648
652
delay (20 );
@@ -654,7 +658,7 @@ bool Touch::tsSetSysInfoRegs(struct cyttspSysinfoData *_sysDataPtr)
654
658
/* *
655
659
* @brief Method does handshake for the Touchscreen/Touchscreen Controller to confirm successfull read
656
660
* new touch report data.
657
- *
661
+ *
658
662
* @note Handshake must be done on every new touch event from the Interrupt.
659
663
*/
660
664
void Touch::tsHandshake ()
@@ -697,18 +701,18 @@ bool Touch::tsPing(int _retries)
697
701
698
702
/* *
699
703
* @brief Method sends I2C command to the Touchscreen Controller IC.
700
- *
704
+ *
701
705
* @param uint8_t _cmd
702
- * I2C command for the Touchscreen Controller IC.
703
- *
706
+ * I2C command for the Touchscreen Controller IC.
707
+ *
704
708
* @return true - Command is succesfully send and executed.
705
709
* false - I2C command send failed.
706
710
*/
707
711
bool Touch::tsSendCommand (uint8_t _cmd)
708
712
{
709
713
// Init I2C communication.
710
714
Wire.beginTransmission (CPYRESS_TOUCH_I2C_ADDR);
711
-
715
+
712
716
// I'm not sure about this?
713
717
// Write I2C sub-address (register address).
714
718
Wire.write (CYPRESS_TOUCH_BASE_ADDR);
@@ -720,23 +724,23 @@ bool Touch::tsSendCommand(uint8_t _cmd)
720
724
delay (20 );
721
725
722
726
// Send to I2C!
723
- return Wire.endTransmission () == 0 ? true : false ;
727
+ return Wire.endTransmission () == 0 ? true : false ;
724
728
}
725
729
726
730
/* *
727
731
* @brief Method reads multiple I2C registers at once from the touchscreen controller and save them into buffer.
728
- *
732
+ *
729
733
* @param uint8_t _cmd
730
734
* I2C command for the Touchscreen Controller.
731
735
* @param uint8_t *_buffer
732
- * Buffer for the bytes read from the Touchscreen Controller.
736
+ * Buffer for the bytes read from the Touchscreen Controller.
733
737
* @param int _len
734
738
* How many bytes to read from the I2C (Touchscreen Controller).
735
- *
739
+ *
736
740
* @return bool
737
741
* true - I2C register read was successfull.
738
742
* false - I2C register read failed.
739
- *
743
+ *
740
744
* @note More than 32 bytes can be read at the same time.
741
745
*/
742
746
bool Touch::tsReadI2CRegs (uint8_t _cmd, uint8_t *_buffer, int _len)
@@ -759,12 +763,12 @@ bool Touch::tsReadI2CRegs(uint8_t _cmd, uint8_t *_buffer, int _len)
759
763
while (_len > 0 )
760
764
{
761
765
// Check for the size of the remaining buffer.
762
- int _i2cLen = _len > 32 ? 32 : _len;
766
+ int _i2cLen = _len > 32 ? 32 : _len;
763
767
764
768
// Read the bytes from the I2C.
765
769
Wire.requestFrom (CPYRESS_TOUCH_I2C_ADDR, _i2cLen);
766
770
Wire.readBytes (_buffer + _index, _i2cLen);
767
-
771
+
768
772
// Update the buffer index position.
769
773
_index += _i2cLen;
770
774
@@ -778,18 +782,18 @@ bool Touch::tsReadI2CRegs(uint8_t _cmd, uint8_t *_buffer, int _len)
778
782
779
783
/* *
780
784
* @brief Method writes multiple I2C registers at once to the touchscreen controller from buffer provided.
781
- *
785
+ *
782
786
* @param uint8_t _cmd
783
787
* I2C command for the Touchscreen Controller.
784
788
* @param uint8_t *_buffer
785
- * Buffer for the bytes that needs to be sent to the Touchscreen Controller.
789
+ * Buffer for the bytes that needs to be sent to the Touchscreen Controller.
786
790
* @param int _len
787
791
* How many bytes to write to the I2C (Touchscreen Controller).
788
- *
792
+ *
789
793
* @return bool
790
794
* true - I2C register write was successfull.
791
795
* false - I2C register write failed.
792
- *
796
+ *
793
797
* @note More than 32 bytes can be written at the same time.
794
798
*/
795
799
bool Touch::tsWriteI2CRegs (uint8_t _cmd, uint8_t *_buffer, int _len)
0 commit comments