t

Dependencies:   DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos

Fork of DMSupport by Embedded Artists

Committer:
JVI_1556
Date:
Fri Oct 26 11:19:35 2018 +0000
Revision:
41:096931c776eb
Parent:
33:8a0a99d54bf8
test

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 22:1a58a518435c 48 FunctionPointer* setListener(FunctionPointer* 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 22:1a58a518435c 57 FunctionPointer* _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 _mutex.lock();
embeddedartists 33:8a0a99d54bf8 157 FunctionPointer* fp = _listener;
embeddedartists 33:8a0a99d54bf8 158 _mutex.unlock();
embeddedartists 33:8a0a99d54bf8 159
embeddedartists 33:8a0a99d54bf8 160 if (fp != NULL) {
embeddedartists 33:8a0a99d54bf8 161 fp->call();
embeddedartists 33:8a0a99d54bf8 162 }
embeddedartists 26:a65fbb4bde5c 163 }
embeddedartists 33:8a0a99d54bf8 164 } else {
embeddedartists 33:8a0a99d54bf8 165 // normal singe-touch
embeddedartists 33:8a0a99d54bf8 166 while(true) {
embeddedartists 33:8a0a99d54bf8 167 osEvent evt = _mailbox.get(osWaitForever);
embeddedartists 33:8a0a99d54bf8 168 if (evt.status == osEventMail) {
embeddedartists 33:8a0a99d54bf8 169 touch_mail_t* mail = (touch_mail_t*)evt.value.p;
embeddedartists 33:8a0a99d54bf8 170 memcpy(_latest, mail->touch, mail->num * sizeof(touch_coordinate_t));
embeddedartists 33:8a0a99d54bf8 171 _mailbox.free(mail);
embeddedartists 33:8a0a99d54bf8 172 _dbgRemoved++;
embeddedartists 33:8a0a99d54bf8 173 } else {
embeddedartists 33:8a0a99d54bf8 174 log->printf("got non-mail event: 0x%x\n", evt.status);
embeddedartists 33:8a0a99d54bf8 175 continue;
embeddedartists 33:8a0a99d54bf8 176 }
embeddedartists 33:8a0a99d54bf8 177 _mutex.lock();
embeddedartists 33:8a0a99d54bf8 178 FunctionPointer* fp = _listener;
embeddedartists 33:8a0a99d54bf8 179 _mutex.unlock();
embeddedartists 33:8a0a99d54bf8 180
embeddedartists 33:8a0a99d54bf8 181 if (fp != NULL) {
embeddedartists 33:8a0a99d54bf8 182 fp->call();
embeddedartists 33:8a0a99d54bf8 183 }
embeddedartists 26:a65fbb4bde5c 184 }
embeddedartists 22:1a58a518435c 185 }
embeddedartists 22:1a58a518435c 186 }
embeddedartists 22:1a58a518435c 187
embeddedartists 22:1a58a518435c 188 TouchPanel::TouchError TouchHandler::read(touch_coordinate_t* coord, int num)
embeddedartists 22:1a58a518435c 189 {
embeddedartists 22:1a58a518435c 190 if (num > _points || num < 1) {
embeddedartists 22:1a58a518435c 191 return TouchPanel::TouchError_InvalidParam;
embeddedartists 22:1a58a518435c 192 }
embeddedartists 22:1a58a518435c 193 _mutex.lock();
embeddedartists 22:1a58a518435c 194 memcpy(coord, _latest, num*sizeof(touch_coordinate_t));
embeddedartists 22:1a58a518435c 195 _mutex.unlock();
embeddedartists 22:1a58a518435c 196
embeddedartists 22:1a58a518435c 197 return TouchPanel::TouchError_Ok;
embeddedartists 22:1a58a518435c 198 }
embeddedartists 22:1a58a518435c 199
embeddedartists 22:1a58a518435c 200 void TouchHandler::handleTouchInterrupt()
embeddedartists 22:1a58a518435c 201 {
embeddedartists 26:a65fbb4bde5c 202 _bios->touchIrqHandler(_biosData);
embeddedartists 26:a65fbb4bde5c 203 }
embeddedartists 26:a65fbb4bde5c 204
embeddedartists 26:a65fbb4bde5c 205 void TouchHandler::handleNewData(touch_coordinate_t* coord, int num)
embeddedartists 26:a65fbb4bde5c 206 {
embeddedartists 26:a65fbb4bde5c 207 touch_mail_t* mail = _mailbox.alloc(0);
embeddedartists 26:a65fbb4bde5c 208 if (mail == NULL) {
embeddedartists 26:a65fbb4bde5c 209 //DMBoard::instance().logger()->printf("Lost touch event\n");
embeddedartists 26:a65fbb4bde5c 210 _lostData++;
embeddedartists 26:a65fbb4bde5c 211 } else {
embeddedartists 26:a65fbb4bde5c 212 _dbgAdded++;
embeddedartists 26:a65fbb4bde5c 213 mail->num = (num < NUM_COORDS) ? num : NUM_COORDS;
embeddedartists 26:a65fbb4bde5c 214 memcpy(&mail->touch, coord, mail->num*sizeof(touch_coordinate_t));
embeddedartists 26:a65fbb4bde5c 215 _mailbox.put(mail);
embeddedartists 22:1a58a518435c 216 }
embeddedartists 22:1a58a518435c 217 }
embeddedartists 22:1a58a518435c 218
embeddedartists 28:8ae20cb0b943 219 void TouchHandler::changeTouchInterrupt(bool enable, touch_irq_trigger_t trigger)
embeddedartists 22:1a58a518435c 220 {
embeddedartists 28:8ae20cb0b943 221 switch (trigger) {
embeddedartists 28:8ae20cb0b943 222 case TOUCH_IRQ_RISING_EDGE:
embeddedartists 28:8ae20cb0b943 223 if (enable) {
embeddedartists 28:8ae20cb0b943 224 _touchIRQ.rise(this, &TouchHandler::handleTouchInterrupt);
embeddedartists 28:8ae20cb0b943 225 } else {
embeddedartists 28:8ae20cb0b943 226 _touchIRQ.rise(NULL);
embeddedartists 28:8ae20cb0b943 227 }
embeddedartists 28:8ae20cb0b943 228 break;
embeddedartists 28:8ae20cb0b943 229
embeddedartists 28:8ae20cb0b943 230 case TOUCH_IRQ_FALLING_EDGE:
embeddedartists 28:8ae20cb0b943 231 if (enable) {
embeddedartists 28:8ae20cb0b943 232 _touchIRQ.fall(this, &TouchHandler::handleTouchInterrupt);
embeddedartists 28:8ae20cb0b943 233 } else {
embeddedartists 28:8ae20cb0b943 234 _touchIRQ.fall(NULL);
embeddedartists 28:8ae20cb0b943 235 }
embeddedartists 28:8ae20cb0b943 236 break;
embeddedartists 28:8ae20cb0b943 237
embeddedartists 28:8ae20cb0b943 238 case TOUCH_IRQ_HIGH_LEVEL:
embeddedartists 28:8ae20cb0b943 239 case TOUCH_IRQ_LOW_LEVEL:
embeddedartists 28:8ae20cb0b943 240 default:
embeddedartists 28:8ae20cb0b943 241 DMBoard::instance().logger()->printf("BIOS requests unknown trigger type %d\n", trigger);
embeddedartists 28:8ae20cb0b943 242 break;
embeddedartists 22:1a58a518435c 243 }
embeddedartists 22:1a58a518435c 244 }
embeddedartists 22:1a58a518435c 245
embeddedartists 22:1a58a518435c 246 FunctionPointer* TouchHandler::setListener(FunctionPointer* listener)
embeddedartists 22:1a58a518435c 247 {
embeddedartists 22:1a58a518435c 248 _mutex.lock();
embeddedartists 22:1a58a518435c 249 FunctionPointer* old = _listener;
embeddedartists 22:1a58a518435c 250 _listener = listener;
embeddedartists 22:1a58a518435c 251 _mutex.unlock();
embeddedartists 22:1a58a518435c 252 return old;
embeddedartists 22:1a58a518435c 253 }
embeddedartists 22:1a58a518435c 254
embeddedartists 22:1a58a518435c 255
embeddedartists 22:1a58a518435c 256 /******************************************************************************
embeddedartists 22:1a58a518435c 257 * Public Functions
embeddedartists 22:1a58a518435c 258 *****************************************************************************/
embeddedartists 22:1a58a518435c 259
embeddedartists 22:1a58a518435c 260 BiosTouch::TouchError BiosTouch::init()
embeddedartists 22:1a58a518435c 261 {
embeddedartists 22:1a58a518435c 262 TouchError result = TouchError_Ok;
embeddedartists 22:1a58a518435c 263 if (!_initialized) {
embeddedartists 22:1a58a518435c 264 do {
embeddedartists 22:1a58a518435c 265 if (BiosLoader::instance().params(&_bios, &_biosData) != DMBoard::Ok) {
embeddedartists 22:1a58a518435c 266 result = TouchError_ConfigError;
embeddedartists 22:1a58a518435c 267 break;
embeddedartists 22:1a58a518435c 268 }
embeddedartists 22:1a58a518435c 269
embeddedartists 28:8ae20cb0b943 270 result = (TouchError)_bios->touchInformation(_biosData, &_supportsTouch, &_supportsTouchCalibration, &_touchNumFingers);
embeddedartists 22:1a58a518435c 271 if (result != TouchError_Ok) {
embeddedartists 22:1a58a518435c 272 break;
embeddedartists 22:1a58a518435c 273 }
embeddedartists 22:1a58a518435c 274 _haveInfo = true;
embeddedartists 22:1a58a518435c 275
embeddedartists 22:1a58a518435c 276 // is it supported at all?
embeddedartists 22:1a58a518435c 277 if (!_supportsTouch) {
embeddedartists 22:1a58a518435c 278 result = TouchError_TouchNotSupported;
embeddedartists 22:1a58a518435c 279 break;
embeddedartists 22:1a58a518435c 280 }
embeddedartists 22:1a58a518435c 281
embeddedartists 28:8ae20cb0b943 282 _handler = new TouchHandler(_bios, _biosData, _touchNumFingers);
embeddedartists 22:1a58a518435c 283
embeddedartists 26:a65fbb4bde5c 284 result = (TouchError)_bios->touchInit(_biosData, touchIrqEnabler, (uint32_t)_handler, touchNewData, (uint32_t)_handler);
embeddedartists 22:1a58a518435c 285 if (result != TouchError_Ok) {
embeddedartists 22:1a58a518435c 286 break;
embeddedartists 22:1a58a518435c 287 }
embeddedartists 22:1a58a518435c 288
embeddedartists 22:1a58a518435c 289 result = (TouchError)_bios->touchPowerUp(_biosData);
embeddedartists 22:1a58a518435c 290 if (result != TouchError_Ok) {
embeddedartists 22:1a58a518435c 291 break;
embeddedartists 22:1a58a518435c 292 }
embeddedartists 22:1a58a518435c 293
embeddedartists 22:1a58a518435c 294 _handlerThread = new Thread(touchTask, _handler);
embeddedartists 22:1a58a518435c 295
embeddedartists 22:1a58a518435c 296 _initialized = true;
embeddedartists 22:1a58a518435c 297 } while(0);
embeddedartists 22:1a58a518435c 298
embeddedartists 22:1a58a518435c 299 if (!_initialized) {
embeddedartists 22:1a58a518435c 300 if (_handler != NULL) {
embeddedartists 22:1a58a518435c 301 delete _handler;
embeddedartists 22:1a58a518435c 302 _handler = NULL;
embeddedartists 22:1a58a518435c 303 }
embeddedartists 22:1a58a518435c 304 }
embeddedartists 22:1a58a518435c 305 }
embeddedartists 22:1a58a518435c 306 return result;
embeddedartists 22:1a58a518435c 307 }
embeddedartists 22:1a58a518435c 308
embeddedartists 22:1a58a518435c 309 BiosTouch::TouchError BiosTouch::read(touch_coordinate_t &coord)
embeddedartists 22:1a58a518435c 310 {
embeddedartists 22:1a58a518435c 311 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 312 if (!_initialized) {
embeddedartists 22:1a58a518435c 313 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 314 } else {
embeddedartists 22:1a58a518435c 315 err = _handler->read(&coord, 1);
embeddedartists 22:1a58a518435c 316 }
embeddedartists 22:1a58a518435c 317 return err;
embeddedartists 22:1a58a518435c 318 }
embeddedartists 22:1a58a518435c 319
embeddedartists 22:1a58a518435c 320 BiosTouch::TouchError BiosTouch::read(touch_coordinate_t* coord, int num)
embeddedartists 22:1a58a518435c 321 {
embeddedartists 22:1a58a518435c 322 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 323 if (!_initialized) {
embeddedartists 22:1a58a518435c 324 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 325 } else {
embeddedartists 22:1a58a518435c 326 err = _handler->read(coord, num);
embeddedartists 22:1a58a518435c 327 }
embeddedartists 22:1a58a518435c 328 return err;
embeddedartists 22:1a58a518435c 329 }
embeddedartists 22:1a58a518435c 330
embeddedartists 22:1a58a518435c 331 BiosTouch::TouchError BiosTouch::info(bool* resistive, int* maxPoints, bool* calibrated)
embeddedartists 22:1a58a518435c 332 {
embeddedartists 22:1a58a518435c 333 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 334 if (!_haveInfo) {
embeddedartists 22:1a58a518435c 335 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 336 } else {
embeddedartists 22:1a58a518435c 337 *maxPoints = _touchNumFingers;
embeddedartists 22:1a58a518435c 338 *calibrated = _supportsTouchCalibration;
embeddedartists 22:1a58a518435c 339 }
embeddedartists 22:1a58a518435c 340 return err;
embeddedartists 22:1a58a518435c 341 }
embeddedartists 22:1a58a518435c 342
embeddedartists 22:1a58a518435c 343 bool BiosTouch::isTouchSupported()
embeddedartists 22:1a58a518435c 344 {
embeddedartists 22:1a58a518435c 345 #if defined(DM_BOARD_USE_TOUCH)
embeddedartists 22:1a58a518435c 346 if (_haveInfo) {
embeddedartists 22:1a58a518435c 347 return _supportsTouch;
embeddedartists 22:1a58a518435c 348 }
embeddedartists 22:1a58a518435c 349 #endif
embeddedartists 22:1a58a518435c 350 return false;
embeddedartists 22:1a58a518435c 351 }
embeddedartists 22:1a58a518435c 352
embeddedartists 22:1a58a518435c 353 BiosTouch::TouchError BiosTouch::calibrateStart()
embeddedartists 22:1a58a518435c 354 {
embeddedartists 22:1a58a518435c 355 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 356 if (!_initialized) {
embeddedartists 22:1a58a518435c 357 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 358 } else {
embeddedartists 22:1a58a518435c 359 err = (TouchError)_bios->touchCalibrateStart(_biosData);
embeddedartists 22:1a58a518435c 360 }
embeddedartists 22:1a58a518435c 361 return err;
embeddedartists 22:1a58a518435c 362 }
embeddedartists 22:1a58a518435c 363
embeddedartists 22:1a58a518435c 364 BiosTouch::TouchError BiosTouch::getNextCalibratePoint(uint16_t* x, uint16_t* y, bool* last)
embeddedartists 22:1a58a518435c 365 {
embeddedartists 22:1a58a518435c 366 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 367 if (!_initialized) {
embeddedartists 22:1a58a518435c 368 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 369 } else {
embeddedartists 22:1a58a518435c 370 err = (TouchError)_bios->touchGetNextCalibPoint(_biosData, x, y, last);
embeddedartists 22:1a58a518435c 371 }
embeddedartists 22:1a58a518435c 372 return err;
embeddedartists 22:1a58a518435c 373 }
embeddedartists 22:1a58a518435c 374
embeddedartists 22:1a58a518435c 375 BiosTouch::TouchError BiosTouch::waitForCalibratePoint(bool* morePoints, uint32_t timeout)
embeddedartists 22:1a58a518435c 376 {
embeddedartists 22:1a58a518435c 377 TouchError err = TouchError_Ok;
embeddedartists 22:1a58a518435c 378 if (!_initialized) {
embeddedartists 22:1a58a518435c 379 err = TouchError_NoInit;
embeddedartists 22:1a58a518435c 380 } else {
embeddedartists 22:1a58a518435c 381 err = (TouchError)_bios->touchWaitForCalibratePoint(_biosData, morePoints, timeout);
embeddedartists 22:1a58a518435c 382 }
embeddedartists 22:1a58a518435c 383 return err;
embeddedartists 22:1a58a518435c 384 }
embeddedartists 22:1a58a518435c 385
embeddedartists 22:1a58a518435c 386 FunctionPointer* BiosTouch::setListener(FunctionPointer* listener)
embeddedartists 22:1a58a518435c 387 {
embeddedartists 22:1a58a518435c 388 if (_initialized) {
embeddedartists 22:1a58a518435c 389 return _handler->setListener(listener);
embeddedartists 22:1a58a518435c 390 }
embeddedartists 22:1a58a518435c 391 return NULL;
embeddedartists 22:1a58a518435c 392 }