A board support package for the LPC4088 Display Module.

Dependencies:   DM_HttpServer DM_USBHost

Dependents:   lpc4088_displaymodule_emwin lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI ... more

Fork of DMSupport by EmbeddedArtists AB

Committer:
embeddedartists
Date:
Wed Oct 23 06:59:29 2019 +0000
Revision:
41:e06e764ff4fd
Parent:
33:8a0a99d54bf8
Updates related to mbed OS 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 22:1a58a518435c 1 /*
embeddedartists 22:1a58a518435c 2 * Copyright 2014 Embedded Artists AB
embeddedartists 22:1a58a518435c 3 *
embeddedartists 22:1a58a518435c 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 22:1a58a518435c 5 * you may not use this file except in compliance with the License.
embeddedartists 22:1a58a518435c 6 * You may obtain a copy of the License at
embeddedartists 22:1a58a518435c 7 *
embeddedartists 22:1a58a518435c 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 22:1a58a518435c 9 *
embeddedartists 22:1a58a518435c 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 22:1a58a518435c 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 22:1a58a518435c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 22:1a58a518435c 13 * See the License for the specific language governing permissions and
embeddedartists 22:1a58a518435c 14 * limitations under the License.
embeddedartists 22:1a58a518435c 15 */
embeddedartists 22:1a58a518435c 16
embeddedartists 22:1a58a518435c 17 #include "mbed.h"
embeddedartists 22:1a58a518435c 18 #include "BiosTouch.h"
embeddedartists 22:1a58a518435c 19 #include "BiosLoader.h"
embeddedartists 22:1a58a518435c 20 #include "DMBoard.h"
embeddedartists 22:1a58a518435c 21 #include "bios.h"
embeddedartists 22:1a58a518435c 22 #include "meas.h"
embeddedartists 22:1a58a518435c 23
embeddedartists 22:1a58a518435c 24 /******************************************************************************
embeddedartists 22:1a58a518435c 25 * Defines and typedefs
embeddedartists 22:1a58a518435c 26 *****************************************************************************/
embeddedartists 22:1a58a518435c 27
embeddedartists 26:a65fbb4bde5c 28 #define NUM_COORDS 5
embeddedartists 26:a65fbb4bde5c 29 #define NUM_MAILS 10
embeddedartists 26:a65fbb4bde5c 30 typedef struct {
embeddedartists 26:a65fbb4bde5c 31 touch_coordinate_t touch[NUM_COORDS];
embeddedartists 26:a65fbb4bde5c 32 int num;
embeddedartists 26:a65fbb4bde5c 33 } touch_mail_t;
embeddedartists 26:a65fbb4bde5c 34
embeddedartists 22:1a58a518435c 35 #define SIG_NEW_DATA 0x1
embeddedartists 22:1a58a518435c 36 class TouchHandler {
embeddedartists 22:1a58a518435c 37 public:
embeddedartists 22:1a58a518435c 38 TouchHandler(bios_header_t* bios, void* biosData, int num) :
embeddedartists 22:1a58a518435c 39 _latest(NULL), _touchIRQ(P2_25), _bios(bios),
embeddedartists 26:a65fbb4bde5c 40 _biosData(biosData), _points(num),
embeddedartists 26:a65fbb4bde5c 41 _listener(NULL), _lostData(0),
embeddedartists 26:a65fbb4bde5c 42 _dbgAdded(0), _dbgRemoved(0) {}
embeddedartists 22:1a58a518435c 43 void handleTouchInterrupt();
embeddedartists 26:a65fbb4bde5c 44 void handleNewData(touch_coordinate_t* coord, int num);
embeddedartists 28:8ae20cb0b943 45 void changeTouchInterrupt(bool enable, touch_irq_trigger_t trigger);
embeddedartists 22:1a58a518435c 46 TouchPanel::TouchError read(touch_coordinate_t* coord, int num);
embeddedartists 22:1a58a518435c 47 void run();
embeddedartists 41:e06e764ff4fd 48 void setListener(Callback<void()> listener);
embeddedartists 22:1a58a518435c 49 private:
embeddedartists 26:a65fbb4bde5c 50 Mail<touch_mail_t, NUM_MAILS> _mailbox;
embeddedartists 22:1a58a518435c 51 Mutex _mutex;
embeddedartists 22:1a58a518435c 52 touch_coordinate_t* _latest;
embeddedartists 22:1a58a518435c 53 InterruptIn _touchIRQ;
embeddedartists 22:1a58a518435c 54 bios_header_t* _bios;
embeddedartists 22:1a58a518435c 55 void* _biosData;
embeddedartists 22:1a58a518435c 56 int _points;
embeddedartists 41:e06e764ff4fd 57 Callback<void()> _listener;
embeddedartists 26:a65fbb4bde5c 58 uint32_t _lostData;
embeddedartists 26:a65fbb4bde5c 59 uint32_t _dbgAdded;
embeddedartists 26:a65fbb4bde5c 60 uint32_t _dbgRemoved;
embeddedartists 22:1a58a518435c 61 };
embeddedartists 22:1a58a518435c 62
embeddedartists 22:1a58a518435c 63 /******************************************************************************
embeddedartists 22:1a58a518435c 64 * Local variables
embeddedartists 22:1a58a518435c 65 *****************************************************************************/
embeddedartists 22:1a58a518435c 66
embeddedartists 22:1a58a518435c 67 /******************************************************************************
embeddedartists 22:1a58a518435c 68 * Private Functions
embeddedartists 22:1a58a518435c 69 *****************************************************************************/
embeddedartists 22:1a58a518435c 70
embeddedartists 22:1a58a518435c 71 BiosTouch::BiosTouch() :
embeddedartists 22:1a58a518435c 72 _initialized(false),
embeddedartists 22:1a58a518435c 73 _haveInfo(false),
embeddedartists 22:1a58a518435c 74 _poweredOn(false),
embeddedartists 22:1a58a518435c 75 //_touchIRQ(P2_25),
embeddedartists 22:1a58a518435c 76 _bios(NULL),
embeddedartists 22:1a58a518435c 77 _biosData(NULL),
embeddedartists 22:1a58a518435c 78 _handlerThread(NULL),
embeddedartists 22:1a58a518435c 79 _handler(NULL),
embeddedartists 22:1a58a518435c 80 _supportsTouch(false)
embeddedartists 22:1a58a518435c 81 {
embeddedartists 22:1a58a518435c 82 }
embeddedartists 22:1a58a518435c 83
embeddedartists 22:1a58a518435c 84 BiosTouch::~BiosTouch()
embeddedartists 22:1a58a518435c 85 {
embeddedartists 22:1a58a518435c 86 // _bios and _biosData are deallocated by BiosLoader
embeddedartists 22:1a58a518435c 87
embeddedartists 22:1a58a518435c 88 if (_handlerThread != NULL) {
embeddedartists 22:1a58a518435c 89 delete _handlerThread;
embeddedartists 22:1a58a518435c 90 _handlerThread = NULL;
embeddedartists 22:1a58a518435c 91 }
embeddedartists 22:1a58a518435c 92 if (_handler != NULL) {
embeddedartists 22:1a58a518435c 93 delete _handler;
embeddedartists 22:1a58a518435c 94 _handler = NULL;
embeddedartists 22:1a58a518435c 95 }
embeddedartists 22:1a58a518435c 96 }
embeddedartists 22:1a58a518435c 97
embeddedartists 22:1a58a518435c 98 // Function called from the BIOS
embeddedartists 28:8ae20cb0b943 99 static void touchIrqEnabler(uint32_t arg, bool enable, touch_irq_trigger_t trigger)
embeddedartists 22:1a58a518435c 100 {
embeddedartists 28:8ae20cb0b943 101 ((TouchHandler*)arg)->changeTouchInterrupt(enable, trigger);
embeddedartists 26:a65fbb4bde5c 102 }
embeddedartists 26:a65fbb4bde5c 103
embeddedartists 26:a65fbb4bde5c 104 // Function called from the BIOS
embeddedartists 26:a65fbb4bde5c 105 static void touchNewData(uint32_t arg, touch_coordinate_t* coords, int num)
embeddedartists 26:a65fbb4bde5c 106 {
embeddedartists 26:a65fbb4bde5c 107 ((TouchHandler*)arg)->handleNewData(coords, num);
embeddedartists 22:1a58a518435c 108 }
embeddedartists 22:1a58a518435c 109
embeddedartists 22:1a58a518435c 110 static void touchTask(void const* args)
embeddedartists 22:1a58a518435c 111 {
embeddedartists 22:1a58a518435c 112 ((TouchHandler*)args)->run();
embeddedartists 22:1a58a518435c 113 }
embeddedartists 22:1a58a518435c 114
embeddedartists 22:1a58a518435c 115
embeddedartists 22:1a58a518435c 116 void TouchHandler::run()
embeddedartists 22:1a58a518435c 117 {
embeddedartists 22:1a58a518435c 118 RtosLog* log = DMBoard::instance().logger();
embeddedartists 26:a65fbb4bde5c 119
embeddedartists 22:1a58a518435c 120 _latest = (touch_coordinate_t*)malloc(_points*sizeof(touch_coordinate_t));
embeddedartists 22:1a58a518435c 121 if (_latest == NULL) {
embeddedartists 22:1a58a518435c 122 log->printf("Failed to allocate memory for touch events\n");
embeddedartists 22:1a58a518435c 123 mbed_die();
embeddedartists 22:1a58a518435c 124 }
embeddedartists 22:1a58a518435c 125 memset(_latest, 0, _points*sizeof(touch_coordinate_t));
embeddedartists 33:8a0a99d54bf8 126 if (_points > 1) {
embeddedartists 33:8a0a99d54bf8 127 // multitouch - inject end event if missing
embeddedartists 33:8a0a99d54bf8 128 uint32_t maxDelay = osWaitForever;
embeddedartists 33:8a0a99d54bf8 129 while(true) {
embeddedartists 33:8a0a99d54bf8 130 osEvent evt = _mailbox.get(maxDelay);
embeddedartists 33:8a0a99d54bf8 131 if (evt.status == osEventMail) {
embeddedartists 33:8a0a99d54bf8 132 touch_mail_t* mail = (touch_mail_t*)evt.value.p;
embeddedartists 33:8a0a99d54bf8 133 memcpy(_latest, mail->touch, mail->num * sizeof(touch_coordinate_t));
embeddedartists 33:8a0a99d54bf8 134 _mailbox.free(mail);
embeddedartists 33:8a0a99d54bf8 135 _dbgRemoved++;
embeddedartists 33:8a0a99d54bf8 136 maxDelay = 25; // wait up to 25ms for next event before injecting a "pen up" event
embeddedartists 33:8a0a99d54bf8 137 } else if (evt.status == osEventTimeout) {
embeddedartists 33:8a0a99d54bf8 138 int numNonZero = 0;
embeddedartists 33:8a0a99d54bf8 139 for (int i = 0; i < _points; i++) {
embeddedartists 33:8a0a99d54bf8 140 if (_latest[i].z > 0) {
embeddedartists 33:8a0a99d54bf8 141 numNonZero++;
embeddedartists 33:8a0a99d54bf8 142 }
embeddedartists 33:8a0a99d54bf8 143 _latest[i].z = 0;
embeddedartists 33:8a0a99d54bf8 144 }
embeddedartists 33:8a0a99d54bf8 145 maxDelay = osWaitForever;
embeddedartists 33:8a0a99d54bf8 146 if (numNonZero == 0) {
embeddedartists 33:8a0a99d54bf8 147 // last event was a pen-up event so no need to inject one
embeddedartists 33:8a0a99d54bf8 148 //log->printf("skip penup\n");
embeddedartists 33:8a0a99d54bf8 149 continue;
embeddedartists 33:8a0a99d54bf8 150 }
embeddedartists 33:8a0a99d54bf8 151 //log->printf("inject penup\n");
embeddedartists 33:8a0a99d54bf8 152 } else {
embeddedartists 33:8a0a99d54bf8 153 log->printf("got non-mail event: 0x%x\n", evt.status);
embeddedartists 33:8a0a99d54bf8 154 continue;
embeddedartists 33:8a0a99d54bf8 155 }
embeddedartists 33:8a0a99d54bf8 156
embeddedartists 41:e06e764ff4fd 157 if (_listener) {
embeddedartists 41:e06e764ff4fd 158 _listener();
embeddedartists 33:8a0a99d54bf8 159 }
embeddedartists 26:a65fbb4bde5c 160 }
embeddedartists 33:8a0a99d54bf8 161 } else {
embeddedartists 33:8a0a99d54bf8 162 // normal singe-touch
embeddedartists 33:8a0a99d54bf8 163 while(true) {
embeddedartists 33:8a0a99d54bf8 164 osEvent evt = _mailbox.get(osWaitForever);
embeddedartists 33:8a0a99d54bf8 165 if (evt.status == osEventMail) {
embeddedartists 33:8a0a99d54bf8 166 touch_mail_t* mail = (touch_mail_t*)evt.value.p;
embeddedartists 33:8a0a99d54bf8 167 memcpy(_latest, mail->touch, mail->num * sizeof(touch_coordinate_t));
embeddedartists 33:8a0a99d54bf8 168 _mailbox.free(mail);
embeddedartists 33:8a0a99d54bf8 169 _dbgRemoved++;
embeddedartists 33:8a0a99d54bf8 170 } else {
embeddedartists 33:8a0a99d54bf8 171 log->printf("got non-mail event: 0x%x\n", evt.status);
embeddedartists 33:8a0a99d54bf8 172 continue;
embeddedartists 33:8a0a99d54bf8 173 }
embeddedartists 33:8a0a99d54bf8 174
embeddedartists 41:e06e764ff4fd 175 if (_listener) {
embeddedartists 41:e06e764ff4fd 176 _listener();
embeddedartists 33:8a0a99d54bf8 177 }
embeddedartists 26:a65fbb4bde5c 178 }
embeddedartists 22:1a58a518435c 179 }
embeddedartists 22:1a58a518435c 180 }
embeddedartists 22:1a58a518435c 181
embeddedartists 22:1a58a518435c 182 TouchPanel::TouchError TouchHandler::read(touch_coordinate_t* coord, int num)
embeddedartists 22:1a58a518435c 183 {
embeddedartists 22:1a58a518435c 184 if (num > _points || num < 1) {
embeddedartists 22:1a58a518435c 185 return TouchPanel::TouchError_InvalidParam;
embeddedartists 22:1a58a518435c 186 }
embeddedartists 22:1a58a518435c 187 _mutex.lock();
embeddedartists 22:1a58a518435c 188 memcpy(coord, _latest, num*sizeof(touch_coordinate_t));
embeddedartists 22:1a58a518435c 189 _mutex.unlock();
embeddedartists 22:1a58a518435c 190
embeddedartists 22:1a58a518435c 191 return TouchPanel::TouchError_Ok;
embeddedartists 22:1a58a518435c 192 }
embeddedartists 22:1a58a518435c 193
embeddedartists 22:1a58a518435c 194 void TouchHandler::handleTouchInterrupt()
embeddedartists 22:1a58a518435c 195 {
embeddedartists 26:a65fbb4bde5c 196 _bios->touchIrqHandler(_biosData);
embeddedartists 26:a65fbb4bde5c 197 }
embeddedartists 26:a65fbb4bde5c 198
embeddedartists 26:a65fbb4bde5c 199 void TouchHandler::handleNewData(touch_coordinate_t* coord, int num)
embeddedartists 26:a65fbb4bde5c 200 {
embeddedartists 26:a65fbb4bde5c 201 touch_mail_t* mail = _mailbox.alloc(0);
embeddedartists 26:a65fbb4bde5c 202 if (mail == NULL) {
embeddedartists 26:a65fbb4bde5c 203 //DMBoard::instance().logger()->printf("Lost touch event\n");
embeddedartists 26:a65fbb4bde5c 204 _lostData++;
embeddedartists 26:a65fbb4bde5c 205 } else {
embeddedartists 26:a65fbb4bde5c 206 _dbgAdded++;
embeddedartists 26:a65fbb4bde5c 207 mail->num = (num < NUM_COORDS) ? num : NUM_COORDS;
embeddedartists 26:a65fbb4bde5c 208 memcpy(&mail->touch, coord, mail->num*sizeof(touch_coordinate_t));
embeddedartists 26:a65fbb4bde5c 209 _mailbox.put(mail);
embeddedartists 22:1a58a518435c 210 }
embeddedartists 22:1a58a518435c 211 }
embeddedartists 22:1a58a518435c 212
embeddedartists 28:8ae20cb0b943 213 void TouchHandler::changeTouchInterrupt(bool enable, touch_irq_trigger_t trigger)
embeddedartists 22:1a58a518435c 214 {
embeddedartists 28:8ae20cb0b943 215 switch (trigger) {
embeddedartists 28:8ae20cb0b943 216 case TOUCH_IRQ_RISING_EDGE:
embeddedartists 28:8ae20cb0b943 217 if (enable) {
embeddedartists 41:e06e764ff4fd 218 _touchIRQ.rise(callback(this, &TouchHandler::handleTouchInterrupt));
embeddedartists 28:8ae20cb0b943 219 } else {
embeddedartists 28:8ae20cb0b943 220 _touchIRQ.rise(NULL);
embeddedartists 28:8ae20cb0b943 221 }
embeddedartists 28:8ae20cb0b943 222 break;
embeddedartists 28:8ae20cb0b943 223
embeddedartists 28:8ae20cb0b943 224 case TOUCH_IRQ_FALLING_EDGE:
embeddedartists 28:8ae20cb0b943 225 if (enable) {
embeddedartists 41:e06e764ff4fd 226 _touchIRQ.fall(callback(this, &TouchHandler::handleTouchInterrupt));
embeddedartists 28:8ae20cb0b943 227 } else {
embeddedartists 28:8ae20cb0b943 228 _touchIRQ.fall(NULL);
embeddedartists 28:8ae20cb0b943 229 }
embeddedartists 28:8ae20cb0b943 230 break;
embeddedartists 28:8ae20cb0b943 231
embeddedartists 28:8ae20cb0b943 232 case TOUCH_IRQ_HIGH_LEVEL:
embeddedartists 28:8ae20cb0b943 233 case TOUCH_IRQ_LOW_LEVEL:
embeddedartists 28:8ae20cb0b943 234 default:
embeddedartists 28:8ae20cb0b943 235 DMBoard::instance().logger()->printf("BIOS requests unknown trigger type %d\n", trigger);
embeddedartists 28:8ae20cb0b943 236 break;
embeddedartists 22:1a58a518435c 237 }
embeddedartists 22:1a58a518435c 238 }
embeddedartists 22:1a58a518435c 239
embeddedartists 41:e06e764ff4fd 240 void TouchHandler::setListener(Callback<void()> listener)
embeddedartists 22:1a58a518435c 241 {
embeddedartists 22:1a58a518435c 242 _mutex.lock();
embeddedartists 22:1a58a518435c 243 _listener = listener;
embeddedartists 22:1a58a518435c 244 _mutex.unlock();
embeddedartists 22:1a58a518435c 245 }
embeddedartists 22:1a58a518435c 246
embeddedartists 22:1a58a518435c 247
embeddedartists 22:1a58a518435c 248 /******************************************************************************
embeddedartists 22:1a58a518435c 249 * Public Functions
embeddedartists 22:1a58a518435c 250 *****************************************************************************/
embeddedartists 22:1a58a518435c 251
embeddedartists 22:1a58a518435c 252 BiosTouch::TouchError BiosTouch::init()
embeddedartists 22:1a58a518435c 253 {
embeddedartists 22:1a58a518435c 254 TouchError result = TouchError_Ok;
embeddedartists 22:1a58a518435c 255 if (!_initialized) {
embeddedartists 22:1a58a518435c 256 do {
embeddedartists 22:1a58a518435c 257 if (BiosLoader::instance().params(&_bios, &_biosData) != DMBoard::Ok) {
embeddedartists 22:1a58a518435c 258 result = TouchError_ConfigError;
embeddedartists 22:1a58a518435c 259 break;
embeddedartists 22:1a58a518435c 260 }
embeddedartists 22:1a58a518435c 261
embeddedartists 28:8ae20cb0b943 262 result = (TouchError)_bios->touchInformation(_biosData, &_supportsTouch, &_supportsTouchCalibration, &_touchNumFingers);
embeddedartists 22:1a58a518435c 263 if (result != TouchError_Ok) {
embeddedartists 22:1a58a518435c 264 break;
embeddedartists 22:1a58a518435c 265 }
embeddedartists 22:1a58a518435c 266 _haveInfo = true;
embeddedartists 22:1a58a518435c 267
embeddedartists 22:1a58a518435c 268 // is it supported at all?
embeddedartists 22:1a58a518435c 269 if (!_supportsTouch) {
embeddedartists 22:1a58a518435c 270 result = TouchError_TouchNotSupported;
embeddedartists 22:1a58a518435c 271 break;
embeddedartists 22:1a58a518435c 272 }
embeddedartists 22:1a58a518435c 273
embeddedartists 28:8ae20cb0b943 274 _handler = new TouchHandler(_bios, _biosData, _touchNumFingers);
embeddedartists 22:1a58a518435c 275
embeddedartists 26:a65fbb4bde5c 276 result = (TouchError)_bios->touchInit(_biosData, touchIrqEnabler, (uint32_t)_handler, touchNewData, (uint32_t)_handler);
embeddedartists 22:1a58a518435c 277 if (result != TouchError_Ok) {
embeddedartists 22:1a58a518435c 278 break;
embeddedartists 22:1a58a518435c 279 }
embeddedartists 22:1a58a518435c 280
embeddedartists 22:1a58a518435c 281 result = (TouchError)_bios->touchPowerUp(_biosData);
embeddedartists 22:1a58a518435c 282 if (result != TouchError_Ok) {
embeddedartists 22:1a58a518435c 283 break;
embeddedartists 22:1a58a518435c 284 }
embeddedartists 22:1a58a518435c 285
embeddedartists 41:e06e764ff4fd 286 _handlerThread = new Thread();
embeddedartists 41:e06e764ff4fd 287 _handlerThread->start(callback(touchTask, _handler));
embeddedartists 22:1a58a518435c 288
embeddedartists 22:1a58a518435c 289 _initialized = true;
embeddedartists 22:1a58a518435c 290 } while(0);
embeddedartists 22:1a58a518435c 291
embeddedartists 22:1a58a518435c 292 if (!_initialized) {
embeddedartists 22:1a58a518435c 293 if (_handler != NULL) {
embeddedartists 22:1a58a518435c 294 delete _handler;
embeddedartists 22:1a58a518435c 295 _handler = NULL;
embeddedartists 22:1a58a518435c 296 }
embeddedartists 22:1a58a518435c 297 }
embeddedartists 22:1a58a518435c 298 }
embeddedartists 22:1a58a518435c 299 return result;
embeddedartists 22:1a58a518435c 300 }
embeddedartists 22:1a58a518435c 301
embeddedartists 22:1a58a518435c 302 BiosTouch::TouchError BiosTouch::read(touch_coordinate_t &coord)
embeddedartists 22:1a58a518435c 303 {
embeddedartists 22:1a58a518435c 304 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 305 if (!_initialized) {
embeddedartists 22:1a58a518435c 306 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 307 } else {
embeddedartists 22:1a58a518435c 308 err = _handler->read(&coord, 1);
embeddedartists 22:1a58a518435c 309 }
embeddedartists 22:1a58a518435c 310 return err;
embeddedartists 22:1a58a518435c 311 }
embeddedartists 22:1a58a518435c 312
embeddedartists 22:1a58a518435c 313 BiosTouch::TouchError BiosTouch::read(touch_coordinate_t* coord, int num)
embeddedartists 22:1a58a518435c 314 {
embeddedartists 22:1a58a518435c 315 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 316 if (!_initialized) {
embeddedartists 22:1a58a518435c 317 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 318 } else {
embeddedartists 22:1a58a518435c 319 err = _handler->read(coord, num);
embeddedartists 22:1a58a518435c 320 }
embeddedartists 22:1a58a518435c 321 return err;
embeddedartists 22:1a58a518435c 322 }
embeddedartists 22:1a58a518435c 323
embeddedartists 22:1a58a518435c 324 BiosTouch::TouchError BiosTouch::info(bool* resistive, int* maxPoints, bool* calibrated)
embeddedartists 22:1a58a518435c 325 {
embeddedartists 22:1a58a518435c 326 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 327 if (!_haveInfo) {
embeddedartists 22:1a58a518435c 328 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 329 } else {
embeddedartists 22:1a58a518435c 330 *maxPoints = _touchNumFingers;
embeddedartists 22:1a58a518435c 331 *calibrated = _supportsTouchCalibration;
embeddedartists 22:1a58a518435c 332 }
embeddedartists 22:1a58a518435c 333 return err;
embeddedartists 22:1a58a518435c 334 }
embeddedartists 22:1a58a518435c 335
embeddedartists 22:1a58a518435c 336 bool BiosTouch::isTouchSupported()
embeddedartists 22:1a58a518435c 337 {
embeddedartists 22:1a58a518435c 338 #if defined(DM_BOARD_USE_TOUCH)
embeddedartists 22:1a58a518435c 339 if (_haveInfo) {
embeddedartists 22:1a58a518435c 340 return _supportsTouch;
embeddedartists 22:1a58a518435c 341 }
embeddedartists 22:1a58a518435c 342 #endif
embeddedartists 22:1a58a518435c 343 return false;
embeddedartists 22:1a58a518435c 344 }
embeddedartists 22:1a58a518435c 345
embeddedartists 22:1a58a518435c 346 BiosTouch::TouchError BiosTouch::calibrateStart()
embeddedartists 22:1a58a518435c 347 {
embeddedartists 22:1a58a518435c 348 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 349 if (!_initialized) {
embeddedartists 22:1a58a518435c 350 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 351 } else {
embeddedartists 22:1a58a518435c 352 err = (TouchError)_bios->touchCalibrateStart(_biosData);
embeddedartists 22:1a58a518435c 353 }
embeddedartists 22:1a58a518435c 354 return err;
embeddedartists 22:1a58a518435c 355 }
embeddedartists 22:1a58a518435c 356
embeddedartists 22:1a58a518435c 357 BiosTouch::TouchError BiosTouch::getNextCalibratePoint(uint16_t* x, uint16_t* y, bool* last)
embeddedartists 22:1a58a518435c 358 {
embeddedartists 22:1a58a518435c 359 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 360 if (!_initialized) {
embeddedartists 22:1a58a518435c 361 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 362 } else {
embeddedartists 22:1a58a518435c 363 err = (TouchError)_bios->touchGetNextCalibPoint(_biosData, x, y, last);
embeddedartists 22:1a58a518435c 364 }
embeddedartists 22:1a58a518435c 365 return err;
embeddedartists 22:1a58a518435c 366 }
embeddedartists 22:1a58a518435c 367
embeddedartists 22:1a58a518435c 368 BiosTouch::TouchError BiosTouch::waitForCalibratePoint(bool* morePoints, uint32_t timeout)
embeddedartists 22:1a58a518435c 369 {
embeddedartists 22:1a58a518435c 370 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 371 if (!_initialized) {
embeddedartists 22:1a58a518435c 372 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 373 } else {
embeddedartists 22:1a58a518435c 374 err = (TouchError)_bios->touchWaitForCalibratePoint(_biosData, morePoints, timeout);
embeddedartists 22:1a58a518435c 375 }
embeddedartists 22:1a58a518435c 376 return err;
embeddedartists 22:1a58a518435c 377 }
embeddedartists 22:1a58a518435c 378
embeddedartists 41:e06e764ff4fd 379 void BiosTouch::setListener(Callback<void()> listener)
embeddedartists 22:1a58a518435c 380 {
embeddedartists 22:1a58a518435c 381 if (_initialized) {
embeddedartists 41:e06e764ff4fd 382 _handler->setListener(listener);
embeddedartists 22:1a58a518435c 383 }
embeddedartists 22:1a58a518435c 384 }