Skip to content

Commit

Permalink
bugfix of dynamic rotation automatic swap/flip setting for other touc…
Browse files Browse the repository at this point in the history
…h screens than XPT2046
  • Loading branch information
espHorst authored and gk committed Oct 29, 2018
1 parent 40f5d71 commit f3f8ee8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/GUIslice.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ bool gslc_Init(gslc_tsGui* pGui,void* pvDriver,gslc_tsPage* asPage,uint8_t nMaxP

#if defined(DRV_DISP_ADAGFX) || defined(DRV_DISP_ADAGFX_AS) || defined(DRV_DISP_TFT_ESPI) || defined(DRV_DISP_M5STACK)
pGui->nRotation = GSLC_ROTATE;
pGui->nSwapXY = ADATOUCH_SWAP_XY;
pGui->nFlipX = ADATOUCH_FLIP_X;
pGui->nFlipY = ADATOUCH_FLIP_Y;
pGui->nSwapXY = ADATOUCH_SWAP_XY ^ TOUCH_ROTATION_SWAPXY(GSLC_TOUCH_ROTATE);
pGui->nFlipX = ADATOUCH_FLIP_X ^ TOUCH_ROTATION_FLIPX (GSLC_TOUCH_ROTATE);
pGui->nFlipY = ADATOUCH_FLIP_Y ^ TOUCH_ROTATION_FLIPY (GSLC_TOUCH_ROTATE);
#endif

pGui->nPageMax = nMaxPage;
Expand Down
31 changes: 24 additions & 7 deletions src/GUIslice_config_ard.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ extern "C" {
#define ADAGFX_PIN_CLK

// Set Default rotation
// you can specify values 0,1,2,3, rotation is clockwise
// - Note that if you change this you will likely have to change
// ADATOUCH_FLIP_X & ADATOUCH_FLIP_Y as well to ensure that the touch screen
// GLSC_TOUCH_ROTATE as well to ensure that the touch screen
// orientation matches the display rotation
#define GSLC_ROTATE 1

Expand Down Expand Up @@ -194,8 +195,9 @@ extern "C" {


// Set Default rotation
// you can specify values 0,1,2,3, rotation is clockwise
// - Note that if you change this you will likely have to change
// ADATOUCH_FLIP_X & ADATOUCH_FLIP_Y as well to ensure that the touch screen
// GLSC_TOUCH_ROTATE as well to ensure that the touch screen
// orientation matches the display rotation
#define GSLC_ROTATE 1

Expand All @@ -215,8 +217,9 @@ extern "C" {


// Set Default rotation
// you can specify values 0,1,2,3, rotation is clockwise
// - Note that if you change this you will likely have to change
// ADATOUCH_FLIP_X & ADATOUCH_FLIP_Y as well to ensure that the touch screen
// GLSC_TOUCH_ROTATE as well to ensure that the touch screen
// orientation matches the display rotation
#define GSLC_ROTATE 1

Expand All @@ -227,8 +230,9 @@ extern "C" {
#define TFT_LIGHT_PIN 32 // display backlight

// Set Default rotation
// you can specify values 0,1,2,3, rotation is clockwise
// - Note that if you change this you will likely have to change
// ADATOUCH_FLIP_X & ADATOUCH_FLIP_Y as well to ensure that the touch screen
// GLSC_TOUCH_ROTATE as well to ensure that the touch screen
// orientation matches the display rotation
#define GSLC_ROTATE 0

Expand Down Expand Up @@ -352,14 +356,27 @@ extern "C" {

// -----------------------------------------------------------------------------

// Define any Touch Axis Swapping and Flipping

// Default rotation of the touch, you can specify values 0,1,2,3, rotation is clockwise
// it is useful to specify the GLSC_TOUCH_ROTATE_OFFSET as an offset to the GLSC_ROTATE,
// thus changing GLSC_ROTATE automatically adopts the GLSC_TOUCH_ROTATE
#define GSLC_TOUCH_ROTATE 1

// TODO: maybe those macros should be moved to one include file which is included by all drivers
#define TOUCH_ROTATION_DATA 0x6350
#define TOUCH_ROTATION_SWAPXY(rotation) ((( TOUCH_ROTATION_DATA >> ((rotation&0x03)*4) ) >> 2 ) & 0x01 )
#define TOUCH_ROTATION_FLIPX(rotation) ((( TOUCH_ROTATION_DATA >> ((rotation&0x03)*4) ) >> 1 ) & 0x01 )
#define TOUCH_ROTATION_FLIPY(rotation) ((( TOUCH_ROTATION_DATA >> ((rotation&0x03)*4) ) >> 0 ) & 0x01 )

// - Set any of the following to 1 to perform touch display
// remapping functions, 0 to disable. Use DBG_TOUCH to determine which
// remapping modes should be enabled for your display
// - Please refer to "docs/GUIslice_config_guide.xlsx" for detailed examples
#define ADATOUCH_SWAP_XY 1
// - NOTE: Both settings, GLSC_TOUCH_ROTATE and SWAP / FLIP are applied,
// try to set _SWAP_XY and _FLIP_X/Y to 0 and only use GLSC_TOUCH_ROTATE
#define ADATOUCH_SWAP_XY 0
#define ADATOUCH_FLIP_X 0
#define ADATOUCH_FLIP_Y 1
#define ADATOUCH_FLIP_Y 0

// Define the maximum number of touch events that are handled
// per gslc_Update() call. Normally this can be set to 1 but certain
Expand Down
9 changes: 4 additions & 5 deletions src/GUIslice_drv_adagfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ bool gslc_DrvRotateSwapFlip(gslc_tsGui* pGui, uint8_t nRotation, uint8_t nSwapXY
}

///
/// Change rotation, automatically adapt touchscreen axes swap/flip
/// Change rotation, automatically adapt touchscreen axes swap/flip based on nRotation vs GLSC_TOUCH_ROTATE
///
/// The function assumes that the touchscreen settings for swap and flip in GUIslice_config_ard.h
/// are valid for the rotation defined in GUIslice_config_ard.h
Expand All @@ -1336,10 +1336,9 @@ bool gslc_DrvRotateSwapFlip(gslc_tsGui* pGui, uint8_t nRotation, uint8_t nSwapXY
///
bool gslc_DrvRotate(gslc_tsGui* pGui, uint8_t nRotation)
{
nRotation = nRotation & 0x03;
uint8_t nSwapXY = (pGui->nSwapXY > 0) ^ ( (pGui->nRotation ^ nRotation) & 1 );
uint8_t nFlipX = (pGui->nFlipX > 0) ^ ( (pGui->nRotation ^ nRotation) >> 1 ) ^ ( (pGui->nRotation ^ nRotation) & 1 );
uint8_t nFlipY = (pGui->nFlipY > 0) ^ ( (pGui->nRotation ^ nRotation) >> 1 );
uint8_t nSwapXY = ADATOUCH_SWAP_XY ^ TOUCH_ROTATION_SWAPXY(GSLC_TOUCH_ROTATE - GSLC_ROTATE + nRotation);
uint8_t nFlipX = ADATOUCH_FLIP_X ^ TOUCH_ROTATION_FLIPX (GSLC_TOUCH_ROTATE - GSLC_ROTATE + nRotation);
uint8_t nFlipY = ADATOUCH_FLIP_Y ^ TOUCH_ROTATION_FLIPY (GSLC_TOUCH_ROTATE - GSLC_ROTATE + nRotation);
//Serial.print("s,x,y=");Serial.print(nSwapXY);Serial.print(',');Serial.print(nFlipX);Serial.print(',');Serial.println(nFlipY);;
return gslc_DrvRotateSwapFlip(pGui, nRotation, nSwapXY, nFlipX, nFlipY);
}
Expand Down

0 comments on commit f3f8ee8

Please sign in to comment.