Fix ESP8266 compiler error

This commit is contained in:
fvanroie 2020-04-11 20:10:54 +02:00
parent 51c9af9086
commit 6b0150a624
2 changed files with 194 additions and 191 deletions

View File

@ -8,9 +8,9 @@
#include "pins_arduino.h" #include "pins_arduino.h"
#ifdef __AVR #ifdef __AVR
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#elif defined(ESP8266) #elif defined(ESP8266)
#include <pgmspace.h> #include <pgmspace.h>
#endif #endif
#include "TouchScreen.h" #include "TouchScreen.h"
@ -22,39 +22,44 @@
#define NUMSAMPLES 2 #define NUMSAMPLES 2
TSPoint::TSPoint(void) { TSPoint::TSPoint(void)
{
x = y = 0; x = y = 0;
} }
TSPoint::TSPoint(int16_t x0, int16_t y0, int16_t z0) { TSPoint::TSPoint(int16_t x0, int16_t y0, int16_t z0)
{
x = x0; x = x0;
y = y0; y = y0;
z = z0; z = z0;
} }
bool TSPoint::operator==(TSPoint p1) { bool TSPoint::operator==(TSPoint p1)
{
return ((p1.x == x) && (p1.y == y) && (p1.z == z)); return ((p1.x == x) && (p1.y == y) && (p1.z == z));
} }
bool TSPoint::operator!=(TSPoint p1) { bool TSPoint::operator!=(TSPoint p1)
{
return ((p1.x != x) || (p1.y != y) || (p1.z != z)); return ((p1.x != x) || (p1.y != y) || (p1.z != z));
} }
#if (NUMSAMPLES > 2) #if(NUMSAMPLES > 2)
static void insert_sort(int array[], uint8_t size) { static void insert_sort(int array[], uint8_t size)
{
uint8_t j; uint8_t j;
int save; int save;
for (int i = 1; i < size; i++) { for(int i = 1; i < size; i++) {
save = array[i]; save = array[i];
for (j = i; j >= 1 && save < array[j - 1]; j--) for(j = i; j >= 1 && save < array[j - 1]; j--) array[j] = array[j - 1];
array[j] = array[j - 1];
array[j] = save; array[j] = save;
} }
} }
#endif #endif
TSPoint TouchScreen::getPoint(void) { TSPoint TouchScreen::getPoint(void)
{
int x, y, z; int x, y, z;
int samples[NUMSAMPLES]; int samples[NUMSAMPLES];
uint8_t i, valid; uint8_t i, valid;
@ -66,7 +71,7 @@ TSPoint TouchScreen::getPoint(void) {
pinMode(_xp, OUTPUT); pinMode(_xp, OUTPUT);
pinMode(_xm, OUTPUT); pinMode(_xm, OUTPUT);
#if defined (USE_FAST_PINIO) #if defined(USE_FAST_PINIO)
*xp_port |= xp_pin; *xp_port |= xp_pin;
*xm_port &= ~xm_pin; *xm_port &= ~xm_pin;
#else #else
@ -78,8 +83,8 @@ TSPoint TouchScreen::getPoint(void) {
delayMicroseconds(20); // Fast ARM chips need to allow voltages to settle delayMicroseconds(20); // Fast ARM chips need to allow voltages to settle
#endif #endif
for (i=0; i<NUMSAMPLES; i++) { for(i = 0; i < NUMSAMPLES; i++) {
#if defined (ESP32_WIFI_TOUCH) && defined (ESP32) #if defined(ESP32_WIFI_TOUCH) && defined(ESP32)
samples[i] = analogRead(aYP); samples[i] = analogRead(aYP);
#else #else
samples[i] = analogRead(_yp); samples[i] = analogRead(_yp);
@ -92,21 +97,21 @@ TSPoint TouchScreen::getPoint(void) {
#if NUMSAMPLES == 2 #if NUMSAMPLES == 2
// Allow small amount of measurement noise, because capacitive // Allow small amount of measurement noise, because capacitive
// coupling to a TFT display's signals can induce some noise. // coupling to a TFT display's signals can induce some noise.
if (samples[0] - samples[1] < -NOISE_LEVEL || samples[0] - samples[1] > NOISE_LEVEL) { if(samples[0] - samples[1] < -NOISE_LEVEL || samples[0] - samples[1] > NOISE_LEVEL) {
valid = 0; valid = 0;
} else { } else {
samples[1] = (samples[0] + samples[1]) >> 1; // average 2 samples samples[1] = (samples[0] + samples[1]) >> 1; // average 2 samples
} }
#endif #endif
x = (ADC_MAX-samples[NUMSAMPLES/2]); x = (ADC_MAX - samples[NUMSAMPLES / 2]);
pinMode(_xp, INPUT); pinMode(_xp, INPUT);
pinMode(_xm, INPUT); pinMode(_xm, INPUT);
pinMode(_yp, OUTPUT); pinMode(_yp, OUTPUT);
pinMode(_ym, OUTPUT); pinMode(_ym, OUTPUT);
#if defined (USE_FAST_PINIO) #if defined(USE_FAST_PINIO)
*ym_port &= ~ym_pin; *ym_port &= ~ym_pin;
*yp_port |= yp_pin; *yp_port |= yp_pin;
#else #else
@ -114,13 +119,12 @@ TSPoint TouchScreen::getPoint(void) {
digitalWrite(_yp, HIGH); digitalWrite(_yp, HIGH);
#endif #endif
#ifdef __arm__ #ifdef __arm__
delayMicroseconds(20); // Fast ARM chips need to allow voltages to settle delayMicroseconds(20); // Fast ARM chips need to allow voltages to settle
#endif #endif
for (i=0; i<NUMSAMPLES; i++) { for(i = 0; i < NUMSAMPLES; i++) {
#if defined (ESP32_WIFI_TOUCH) && defined (ESP32) #if defined(ESP32_WIFI_TOUCH) && defined(ESP32)
samples[i] = analogRead(aXM); samples[i] = analogRead(aXM);
#else #else
samples[i] = analogRead(_xm); samples[i] = analogRead(_xm);
@ -133,14 +137,14 @@ TSPoint TouchScreen::getPoint(void) {
#if NUMSAMPLES == 2 #if NUMSAMPLES == 2
// Allow small amount of measurement noise, because capacitive // Allow small amount of measurement noise, because capacitive
// coupling to a TFT display's signals can induce some noise. // coupling to a TFT display's signals can induce some noise.
if (samples[0] - samples[1] < -NOISE_LEVEL || samples[0] - samples[1] > NOISE_LEVEL) { if(samples[0] - samples[1] < -NOISE_LEVEL || samples[0] - samples[1] > NOISE_LEVEL) {
valid = 0; valid = 0;
} else { } else {
samples[1] = (samples[0] + samples[1]) >> 1; // average 2 samples samples[1] = (samples[0] + samples[1]) >> 1; // average 2 samples
} }
#endif #endif
y = (ADC_MAX-samples[NUMSAMPLES/2]); y = (ADC_MAX - samples[NUMSAMPLES / 2]);
// Set X+ to ground // Set X+ to ground
// Set Y- to VCC // Set Y- to VCC
@ -148,7 +152,7 @@ TSPoint TouchScreen::getPoint(void) {
pinMode(_xp, OUTPUT); pinMode(_xp, OUTPUT);
pinMode(_yp, INPUT); pinMode(_yp, INPUT);
#if defined (USE_FAST_PINIO) #if defined(USE_FAST_PINIO)
*xp_port &= ~xp_pin; *xp_port &= ~xp_pin;
*ym_port |= ym_pin; *ym_port |= ym_pin;
#else #else
@ -156,8 +160,7 @@ TSPoint TouchScreen::getPoint(void) {
digitalWrite(_ym, HIGH); digitalWrite(_ym, HIGH);
#endif #endif
#if defined(ESP32_WIFI_TOUCH) && defined(ESP32)
#if defined (ESP32_WIFI_TOUCH) && defined (ESP32)
int z1 = analogRead(aXM); int z1 = analogRead(aXM);
int z2 = analogRead(aYP); int z2 = analogRead(aYP);
#else #else
@ -165,7 +168,7 @@ TSPoint TouchScreen::getPoint(void) {
int z2 = analogRead(_yp); int z2 = analogRead(_yp);
#endif #endif
if (_rxplate != 0) { if(_rxplate != 0) {
// now read the x // now read the x
float rtouch; float rtouch;
rtouch = z2; rtouch = z2;
@ -173,29 +176,29 @@ TSPoint TouchScreen::getPoint(void) {
rtouch -= 1; rtouch -= 1;
rtouch *= x; rtouch *= x;
rtouch *= _rxplate; rtouch *= _rxplate;
rtouch /= ADC_MAX+1; rtouch /= ADC_MAX + 1;
z = rtouch; z = rtouch;
} else { } else {
z = (ADC_MAX-(z2-z1)); z = (ADC_MAX - (z2 - z1));
} }
if (! valid) { if(!valid) {
z = 0; z = 0;
} }
return TSPoint(x, y, z); return TSPoint(x, y, z);
} }
TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rxplate = 0)
uint16_t rxplate=0) { {
_yp = yp; _yp = yp;
_xm = xm; _xm = xm;
_ym = ym; _ym = ym;
_xp = xp; _xp = xp;
_rxplate = rxplate; _rxplate = rxplate;
#if defined (USE_FAST_PINIO) #if defined(USE_FAST_PINIO)
xp_port = portOutputRegister(digitalPinToPort(_xp)); xp_port = portOutputRegister(digitalPinToPort(_xp));
yp_port = portOutputRegister(digitalPinToPort(_yp)); yp_port = portOutputRegister(digitalPinToPort(_yp));
xm_port = portOutputRegister(digitalPinToPort(_xm)); xm_port = portOutputRegister(digitalPinToPort(_xm));
@ -210,7 +213,8 @@ TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym,
pressureThreshhold = 10; pressureThreshhold = 10;
} }
int TouchScreen::readTouchX(void) { int TouchScreen::readTouchX(void)
{
pinMode(_yp, INPUT); pinMode(_yp, INPUT);
pinMode(_ym, INPUT); pinMode(_ym, INPUT);
digitalWrite(_yp, LOW); digitalWrite(_yp, LOW);
@ -221,15 +225,15 @@ int TouchScreen::readTouchX(void) {
pinMode(_xm, OUTPUT); pinMode(_xm, OUTPUT);
digitalWrite(_xm, LOW); digitalWrite(_xm, LOW);
#if defined (ESP32_WIFI_TOUCH) && defined (ESP32) #if defined(ESP32_WIFI_TOUCH) && defined(ESP32)
return (ADC_MAX-analogRead(aYP)); return (ADC_MAX - analogRead(aYP));
#else #else
return (ADC_MAX-analogRead(_yp)); return (ADC_MAX - analogRead(_yp));
#endif #endif
} }
int TouchScreen::readTouchY(void)
int TouchScreen::readTouchY(void) { {
pinMode(_xp, INPUT); pinMode(_xp, INPUT);
pinMode(_xm, INPUT); pinMode(_xm, INPUT);
digitalWrite(_xp, LOW); digitalWrite(_xp, LOW);
@ -240,15 +244,15 @@ int TouchScreen::readTouchY(void) {
pinMode(_ym, OUTPUT); pinMode(_ym, OUTPUT);
digitalWrite(_ym, LOW); digitalWrite(_ym, LOW);
#if defined (ESP32_WIFI_TOUCH) && defined (ESP32) #if defined(ESP32_WIFI_TOUCH) && defined(ESP32)
return (ADC_MAX-analogRead(aXM)); return (ADC_MAX - analogRead(aXM));
#else #else
return (ADC_MAX-analogRead(_xm)); return (ADC_MAX - analogRead(_xm));
#endif #endif
} }
uint16_t TouchScreen::pressure(void)
uint16_t TouchScreen::pressure(void) { {
// Set X+ to ground // Set X+ to ground
pinMode(_xp, OUTPUT); pinMode(_xp, OUTPUT);
digitalWrite(_xp, LOW); digitalWrite(_xp, LOW);
@ -263,7 +267,7 @@ uint16_t TouchScreen::pressure(void) {
digitalWrite(_yp, LOW); digitalWrite(_yp, LOW);
pinMode(_yp, INPUT); pinMode(_yp, INPUT);
#if defined (ESP32_WIFI_TOUCH) && defined (ESP32) #if defined(ESP32_WIFI_TOUCH) && defined(ESP32)
int z1 = analogRead(aXM); int z1 = analogRead(aXM);
int z2 = analogRead(aYP); int z2 = analogRead(aYP);
#else #else
@ -271,8 +275,7 @@ uint16_t TouchScreen::pressure(void) {
int z2 = analogRead(_yp); int z2 = analogRead(_yp);
#endif #endif
if(_rxplate != 0) {
if (_rxplate != 0) {
// now read the x // now read the x
float rtouch; float rtouch;
rtouch = z2; rtouch = z2;
@ -280,10 +283,10 @@ uint16_t TouchScreen::pressure(void) {
rtouch -= 1; rtouch -= 1;
rtouch *= readTouchX(); rtouch *= readTouchX();
rtouch *= _rxplate; rtouch *= _rxplate;
rtouch /= ADC_MAX+1; rtouch /= ADC_MAX + 1;
return rtouch; return rtouch;
} else { } else {
return (ADC_MAX-(z2-z1)); return (ADC_MAX - (z2 - z1));
} }
} }

View File

@ -24,7 +24,7 @@ typedef volatile uint8_t RwReg;
#if defined(ARDUINO_STM32_FEATHER) #if defined(ARDUINO_STM32_FEATHER)
typedef volatile uint32 RwReg; typedef volatile uint32 RwReg;
#endif #endif
#if defined(ARDUINO_FEATHER52) || defined(ESP32) #if defined(ARDUINO_FEATHER52) || defined(ESP32) || defined(ESP8266)
typedef volatile uint32_t RwReg; typedef volatile uint32_t RwReg;
#endif #endif