Skip to content

Commit

Permalink
Add Touch Adapter for M5 Core2s FT6366
Browse files Browse the repository at this point in the history
  • Loading branch information
sieren committed Feb 7, 2021
1 parent bd673a3 commit e8c40c5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions components/m5stackcore2/M5Core2/src/M5TouchAdapter.cpp
@@ -0,0 +1,32 @@
#include "M5TouchAdapter.h"

// Emulates the native (resistive) TFT_eSPI touch interface using M5.Touch
#define TOUCH M5Touch::instance

uint8_t M5TouchAdapter::getTouchRaw(uint16_t *x, uint16_t *y) {
return getTouch(x, y);
}

uint16_t M5TouchAdapter::getTouchRawZ(void) {
return (TOUCH->ispressed()) ? 1000 : 0;
}

void M5TouchAdapter::convertRawXY(uint16_t *x, uint16_t *y) { return; }

uint8_t M5TouchAdapter::getTouch(uint16_t *x, uint16_t *y,
uint16_t threshold /* = 600 */) {
TOUCH->read();
if (TOUCH->points) {
*x = TOUCH->point[0].x;
*y = TOUCH->point[0].y;
return true;
}
return false;
}

void M5TouchAdapter::calibrateTouch(uint16_t *data, uint32_t color_fg,
uint32_t color_bg, uint8_t size) {
return;
}

void M5TouchAdapter::setTouch(uint16_t *data) { return; }
16 changes: 16 additions & 0 deletions components/m5stackcore2/M5Core2/src/M5TouchAdapter.h
@@ -0,0 +1,16 @@
#pragma once

#include "M5Touch.h"

class M5TouchAdapter {
public:
// Emulates the TFT_eSPI touch interface using M5.Touch
uint8_t getTouchRaw(uint16_t *x, uint16_t *y);
uint16_t getTouchRawZ(void);
void convertRawXY(uint16_t *x, uint16_t *y);
uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
void calibrateTouch(uint16_t *data, uint32_t color_fg, uint32_t color_bg,
uint8_t size);
void setTouch(uint16_t *data);
};
// #endif /* _M5DISPLAY_H_ */

0 comments on commit e8c40c5

Please sign in to comment.