Skip to content

Commit 9dcd6c0

Browse files
committed
Merge branch 'Inkplate6FLICKTouchSupport' of https://github.com/SolderedElectronics/Inkplate-Arduino-library into Inkplate6FLICKTouchSupport
2 parents b3a1dcd + e29a81e commit 9dcd6c0

File tree

6 files changed

+120
-110
lines changed

6 files changed

+120
-110
lines changed

src/include/Frontlight.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#include "Frontlight.h"
2020
#include "defines.h"
2121

22-
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || defined(ARDUINO_INKPLATE6FLICK)
22+
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || \
23+
defined(ARDUINO_INKPLATE6FLICK)
2324

2425
/**
2526
* @brief setFrontlight function sets frontlight intensity for inkplate

src/include/Frontlight.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#ifndef __FRONTLIGHT_H__
1919
#define __FRONTLIGHT_H__
2020

21-
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || defined(ARDUINO_INKPLATE6FLICK)
21+
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || \
22+
defined(ARDUINO_INKPLATE6FLICK)
2223

2324
#include "Arduino.h"
2425
#include "Wire.h"

src/include/System.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
#define RTC_7PF 0
7777
#define RTC_12_5PF 1
7878

79-
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || defined(ARDUINO_INKPLATE6FLICK)
79+
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || \
80+
defined(ARDUINO_INKPLATE6FLICK)
8081
#include "Frontlight.h"
8182
#ifdef ARDUINO_INKPLATE6FLICK
8283
#include "TouchCypress.h"
@@ -106,7 +107,8 @@ class System : public Esp,
106107
virtual public Expander,
107108
#endif
108109

109-
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || defined(ARDUINO_INKPLATE6FLICK)
110+
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || \
111+
defined(ARDUINO_INKPLATE6FLICK)
110112
public Touch,
111113
public Frontlight,
112114
#endif

src/include/TouchCypress.cpp

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#ifdef ARDUINO_INKPLATE6FLICK
2222

2323
// Macro helpers.
24-
#define TS_GET_BOOTLOADERMODE(reg) (((reg) & 0x10) >> 4)
24+
#define TS_GET_BOOTLOADERMODE(reg) (((reg)&0x10) >> 4)
2525

2626
// Interrupt function callback for Touch Interruput event.
2727
static volatile bool _tsFlag = false;
@@ -111,7 +111,8 @@ bool Touch::tsInit(uint8_t _pwrState)
111111
tsReset();
112112

113113
// Try to ping it.
114-
if(!tsPing(5)) return false;
114+
if (!tsPing(5))
115+
return false;
115116

116117
// Issue a SW reset.
117118
tsSendCommand(0x01);
@@ -171,7 +172,7 @@ void Touch::tsShutdown()
171172
*
172173
* @param uint8_t *b
173174
* pointer to store register content
174-
*
175+
*
175176
* @note Array must be at least 15 bytes long.
176177
*/
177178
void Touch::tsGetRawData(uint8_t *b)
@@ -381,18 +382,19 @@ void Touch::tsScale(struct cypressTouchData *_touchData, uint16_t _xSize, uint16
381382
* @brief Set power mode of the Touchscreen Controller. There are 3 modes
382383
* CYPRESS_TOUCH_OPERATE_MODE - Normal mode (fast response, higher accuracy, higher power consumption).
383384
* 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+
*
388389
* @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]
391392
*/
392393
void Touch::tsSetPowerState(uint8_t _s)
393394
{
394395
// 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))
396398
{
397399
// Set new power mode setting.
398400
tsSendCommand(_s);
@@ -431,7 +433,7 @@ bool Touch::tsAvailable()
431433
// Private members.
432434
/**
433435
* @brief Enable or disable power to the Touchscreen Controller.
434-
*
436+
*
435437
* @param bool _pwr
436438
* true - Enable power to the Touchscreen/Touchscreen Controller.
437439
* false - Disable power to the Touchscreen/Touchscreen Controller to reduce power
@@ -467,9 +469,9 @@ void Touch::tsPower(bool _pwr)
467469
}
468470

469471
/**
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
471473
* Touchscreen Controller.
472-
*
474+
*
473475
*/
474476
void Touch::tsEnd()
475477
{
@@ -485,7 +487,7 @@ void Touch::tsEnd()
485487

486488
/**
487489
* @brief Method does a HW reset by using RST pin on the Touchscreen/Touchscreen Controller.
488-
*
490+
*
489491
*/
490492
void Touch::tsReset()
491493
{
@@ -500,7 +502,7 @@ void Touch::tsReset()
500502

501503
/**
502504
* @brief Method executes a SW reset by using I2C command.
503-
*
505+
*
504506
*/
505507
void Touch::tsSwReset()
506508
{
@@ -513,11 +515,11 @@ void Touch::tsSwReset()
513515

514516
/**
515517
* @brief Function reads bootloader registers from the Touchscreen Controller.
516-
*
518+
*
517519
* @param struct cyttspBootloaderData *_blDataPtr
518520
* Defined in TouchCypressTypedefs.h, pointer to the struct cyttspBootloaderData to
519521
* store bootloader registers data.
520-
*
522+
*
521523
* @return bool
522524
* true - Loading bootloader data register was successfull.
523525
* false - Loading bootloader data from the registers has failed.
@@ -527,7 +529,8 @@ bool Touch::tsLoadBootloaderRegs(struct cyttspBootloaderData *_blDataPtr)
527529
// Bootloader temp. registers array.
528530
uint8_t _bootloaderData[16];
529531

530-
if (!tsReadI2CRegs(CYPRESS_TOUCH_BASE_ADDR, _bootloaderData, 16)) return false;
532+
if (!tsReadI2CRegs(CYPRESS_TOUCH_BASE_ADDR, _bootloaderData, 16))
533+
return false;
531534

532535
// Parse Bootloader data into typedef struct.
533536
memcpy(_blDataPtr, _bootloaderData, 16);
@@ -538,23 +541,22 @@ bool Touch::tsLoadBootloaderRegs(struct cyttspBootloaderData *_blDataPtr)
538541
/**
539542
* @brief Method forces Touchscreen Controller to exit bootloader mode and enters normal
540543
* operating mode - to load preloaded firmware (possibly TTSP - TrueTouch Standard Product Firmware).
541-
*
544+
*
542545
* @return bool
543546
* true - Touchscreen Controller quit bootloader mode and loaded TTSP FW that is currently executing.
544547
* false - Touchscreen Controller failed to exit bootloader mode.
545-
*
548+
*
546549
* @note It exiting bootloader mode fails reading touch events will fail. Do not go further with the code for the
547550
* Touchscreen.
548551
*/
549552
bool Touch::tsExitBootLoaderMode()
550553
{
551554
// 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.
558560
};
559561

560562
// Write bootloader settings.
@@ -569,23 +571,24 @@ bool Touch::tsExitBootLoaderMode()
569571
tsLoadBootloaderRegs(&_bootloaderData);
570572

571573
// Check for validity.
572-
if (TS_GET_BOOTLOADERMODE(_bootloaderData.bl_status)) return false;
574+
if (TS_GET_BOOTLOADERMODE(_bootloaderData.bl_status))
575+
return false;
573576

574577
// If everything went ok return true.
575578
return true;
576579
}
577580

578581
/**
579582
* @brief Set Touchscreen Controller into System Info mode.
580-
*
583+
*
581584
* @param struct cyttspSysinfoData *_sysDataPtr
582585
* Defined cypressTouchTypedefs.h, pointer to the struct for the system info registers.
583-
*
586+
*
584587
* @return bool
585588
* true - System Info mode usccessfully set.
586589
* 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.
589592
*/
590593
bool Touch::tsSetSysInfoMode(struct cyttspSysinfoData *_sysDataPtr)
591594
{
@@ -622,14 +625,14 @@ bool Touch::tsSetSysInfoMode(struct cyttspSysinfoData *_sysDataPtr)
622625

623626
/**
624627
* @brief Set System info registers into their default state.
625-
*
628+
*
626629
* @param struct cyttspSysinfoData *_sysDataPtr
627630
* Defined in TouchCypressTypedefs.h, poinet to the struct for the system info registers.
628-
*
631+
*
629632
* @return bool
630633
* true - Registers are set successfully.
631634
* false - Setting registers has failed.
632-
*
635+
*
633636
* @note Stop the tuchscreen code from executing if this fails, touch data will be invalid.
634637
*/
635638
bool Touch::tsSetSysInfoRegs(struct cyttspSysinfoData *_sysDataPtr)
@@ -642,7 +645,8 @@ bool Touch::tsSetSysInfoRegs(struct cyttspSysinfoData *_sysDataPtr)
642645
uint8_t _regs[] = {_sysDataPtr->act_intrvl, _sysDataPtr->tch_tmout, _sysDataPtr->lp_intrvl};
643646

644647
// 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;
646650

647651
// Wait a little bit.
648652
delay(20);
@@ -654,7 +658,7 @@ bool Touch::tsSetSysInfoRegs(struct cyttspSysinfoData *_sysDataPtr)
654658
/**
655659
* @brief Method does handshake for the Touchscreen/Touchscreen Controller to confirm successfull read
656660
* new touch report data.
657-
*
661+
*
658662
* @note Handshake must be done on every new touch event from the Interrupt.
659663
*/
660664
void Touch::tsHandshake()
@@ -697,18 +701,18 @@ bool Touch::tsPing(int _retries)
697701

698702
/**
699703
* @brief Method sends I2C command to the Touchscreen Controller IC.
700-
*
704+
*
701705
* @param uint8_t _cmd
702-
* I2C command for the Touchscreen Controller IC.
703-
*
706+
* I2C command for the Touchscreen Controller IC.
707+
*
704708
* @return true - Command is succesfully send and executed.
705709
* false - I2C command send failed.
706710
*/
707711
bool Touch::tsSendCommand(uint8_t _cmd)
708712
{
709713
// Init I2C communication.
710714
Wire.beginTransmission(CPYRESS_TOUCH_I2C_ADDR);
711-
715+
712716
// I'm not sure about this?
713717
// Write I2C sub-address (register address).
714718
Wire.write(CYPRESS_TOUCH_BASE_ADDR);
@@ -720,23 +724,23 @@ bool Touch::tsSendCommand(uint8_t _cmd)
720724
delay(20);
721725

722726
// Send to I2C!
723-
return Wire.endTransmission() == 0?true:false;
727+
return Wire.endTransmission() == 0 ? true : false;
724728
}
725729

726730
/**
727731
* @brief Method reads multiple I2C registers at once from the touchscreen controller and save them into buffer.
728-
*
732+
*
729733
* @param uint8_t _cmd
730734
* I2C command for the Touchscreen Controller.
731735
* @param uint8_t *_buffer
732-
* Buffer for the bytes read from the Touchscreen Controller.
736+
* Buffer for the bytes read from the Touchscreen Controller.
733737
* @param int _len
734738
* How many bytes to read from the I2C (Touchscreen Controller).
735-
*
739+
*
736740
* @return bool
737741
* true - I2C register read was successfull.
738742
* false - I2C register read failed.
739-
*
743+
*
740744
* @note More than 32 bytes can be read at the same time.
741745
*/
742746
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)
759763
while (_len > 0)
760764
{
761765
// Check for the size of the remaining buffer.
762-
int _i2cLen = _len > 32?32:_len;
766+
int _i2cLen = _len > 32 ? 32 : _len;
763767

764768
// Read the bytes from the I2C.
765769
Wire.requestFrom(CPYRESS_TOUCH_I2C_ADDR, _i2cLen);
766770
Wire.readBytes(_buffer + _index, _i2cLen);
767-
771+
768772
// Update the buffer index position.
769773
_index += _i2cLen;
770774

@@ -778,18 +782,18 @@ bool Touch::tsReadI2CRegs(uint8_t _cmd, uint8_t *_buffer, int _len)
778782

779783
/**
780784
* @brief Method writes multiple I2C registers at once to the touchscreen controller from buffer provided.
781-
*
785+
*
782786
* @param uint8_t _cmd
783787
* I2C command for the Touchscreen Controller.
784788
* @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.
786790
* @param int _len
787791
* How many bytes to write to the I2C (Touchscreen Controller).
788-
*
792+
*
789793
* @return bool
790794
* true - I2C register write was successfull.
791795
* false - I2C register write failed.
792-
*
796+
*
793797
* @note More than 32 bytes can be written at the same time.
794798
*/
795799
bool Touch::tsWriteI2CRegs(uint8_t _cmd, uint8_t *_buffer, int _len)

src/include/TouchCypress.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,31 @@
4242
#include "TouchCypressTypedefs.h"
4343

4444
// Cypress Touch IC I2C address (7 bit I2C address).
45-
#define CPYRESS_TOUCH_I2C_ADDR 0x24
45+
#define CPYRESS_TOUCH_I2C_ADDR 0x24
4646

4747
// GPIOs for touchscreen controller.
4848
//#define CYPRESS_TOUCH_PWR_MOS_PIN IO_PIN_B4
4949
//#define CYPRESS_TOUCH_RST_PIN IO_PIN_B2
5050

5151
// Cypress touchscreen controller I2C regs.
52-
#define CYPRESS_TOUCH_BASE_ADDR 0x00
53-
#define CYPRESS_TOUCH_SOFT_RST_MODE 0x01
54-
#define CYPRESS_TOUCH_SYSINFO_MODE 0x10
55-
#define CYPRESS_TOUCH_OPERATE_MODE 0x00
56-
#define CYPRESS_TOUCH_LOW_POWER_MODE 0x04
57-
#define CYPRESS_TOUCH_DEEP_SLEEP_MODE 0x02
58-
#define CYPRESS_TOUCH_REG_ACT_INTRVL 0x1D
52+
#define CYPRESS_TOUCH_BASE_ADDR 0x00
53+
#define CYPRESS_TOUCH_SOFT_RST_MODE 0x01
54+
#define CYPRESS_TOUCH_SYSINFO_MODE 0x10
55+
#define CYPRESS_TOUCH_OPERATE_MODE 0x00
56+
#define CYPRESS_TOUCH_LOW_POWER_MODE 0x04
57+
#define CYPRESS_TOUCH_DEEP_SLEEP_MODE 0x02
58+
#define CYPRESS_TOUCH_REG_ACT_INTRVL 0x1D
5959

6060
// Active Power state scanning/processing refresh interval
61-
#define CYPRESS_TOUCH_ACT_INTRVL_DFLT 0x00 /* ms */
61+
#define CYPRESS_TOUCH_ACT_INTRVL_DFLT 0x00 /* ms */
6262
// Low Power state scanning/processing refresh interval
63-
#define CYPRESS_TOUCH_LP_INTRVL_DFLT 0x0A /* ms */
63+
#define CYPRESS_TOUCH_LP_INTRVL_DFLT 0x0A /* ms */
6464
// Touch timeout for the Active power */
65-
#define CYPRESS_TOUCH_TCH_TMOUT_DFLT 0xFF /* ms */
65+
#define CYPRESS_TOUCH_TCH_TMOUT_DFLT 0xFF /* ms */
6666

6767
// Max X and Y sizes reported by the TSC.
68-
#define CYPRESS_TOUCH_MAX_X 682
69-
#define CYPRESS_TOUCH_MAX_Y 1023
68+
#define CYPRESS_TOUCH_MAX_X 682
69+
#define CYPRESS_TOUCH_MAX_Y 1023
7070

7171
/**
7272
* @brief Touch class holds functionality for interaction with touchscreen

0 commit comments

Comments
 (0)