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
Display/BiosTouch.cpp@26:a65fbb4bde5c, 2015-01-22 (annotated)
- Committer:
- embeddedartists
- Date:
- Thu Jan 22 16:04:54 2015 +0100
- Revision:
- 26:a65fbb4bde5c
- Parent:
- 24:9a677afc86f1
- Child:
- 28:8ae20cb0b943
- Changed BIOS version info to BOARD_ID.MAJ.MIN.REV
- Added support for interrupt drive I2C for the BIOS
Who changed what in which revision?
User | Revision | Line number | New 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 handleI2CInterrupt(); |
embeddedartists | 26:a65fbb4bde5c | 45 | void handleNewData(touch_coordinate_t* coord, int num); |
embeddedartists | 22:1a58a518435c | 46 | void changeTouchInterrupt(bool enable, bool rising); |
embeddedartists | 22:1a58a518435c | 47 | TouchPanel::TouchError read(touch_coordinate_t* coord, int num); |
embeddedartists | 22:1a58a518435c | 48 | void run(); |
embeddedartists | 22:1a58a518435c | 49 | FunctionPointer* setListener(FunctionPointer* listener); |
embeddedartists | 22:1a58a518435c | 50 | private: |
embeddedartists | 26:a65fbb4bde5c | 51 | Mail<touch_mail_t, NUM_MAILS> _mailbox; |
embeddedartists | 22:1a58a518435c | 52 | Mutex _mutex; |
embeddedartists | 22:1a58a518435c | 53 | touch_coordinate_t* _latest; |
embeddedartists | 22:1a58a518435c | 54 | InterruptIn _touchIRQ; |
embeddedartists | 22:1a58a518435c | 55 | bios_header_t* _bios; |
embeddedartists | 22:1a58a518435c | 56 | void* _biosData; |
embeddedartists | 22:1a58a518435c | 57 | int _points; |
embeddedartists | 22:1a58a518435c | 58 | FunctionPointer* _listener; |
embeddedartists | 26:a65fbb4bde5c | 59 | uint32_t _lostData; |
embeddedartists | 26:a65fbb4bde5c | 60 | uint32_t _dbgAdded; |
embeddedartists | 26:a65fbb4bde5c | 61 | uint32_t _dbgRemoved; |
embeddedartists | 22:1a58a518435c | 62 | }; |
embeddedartists | 22:1a58a518435c | 63 | |
embeddedartists | 22:1a58a518435c | 64 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 65 | * Local variables |
embeddedartists | 22:1a58a518435c | 66 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 67 | |
embeddedartists | 26:a65fbb4bde5c | 68 | static TouchHandler* theTouchHandler = NULL; // ugly but needed for IRQ |
embeddedartists | 26:a65fbb4bde5c | 69 | |
embeddedartists | 22:1a58a518435c | 70 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 71 | * Private Functions |
embeddedartists | 22:1a58a518435c | 72 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 73 | |
embeddedartists | 26:a65fbb4bde5c | 74 | static void touch_i2c0_irq_handler() |
embeddedartists | 26:a65fbb4bde5c | 75 | { |
embeddedartists | 26:a65fbb4bde5c | 76 | if (theTouchHandler != NULL) { |
embeddedartists | 26:a65fbb4bde5c | 77 | theTouchHandler->handleI2CInterrupt(); |
embeddedartists | 26:a65fbb4bde5c | 78 | } |
embeddedartists | 26:a65fbb4bde5c | 79 | } |
embeddedartists | 26:a65fbb4bde5c | 80 | |
embeddedartists | 22:1a58a518435c | 81 | BiosTouch::BiosTouch() : |
embeddedartists | 22:1a58a518435c | 82 | _initialized(false), |
embeddedartists | 22:1a58a518435c | 83 | _haveInfo(false), |
embeddedartists | 22:1a58a518435c | 84 | _poweredOn(false), |
embeddedartists | 22:1a58a518435c | 85 | //_touchIRQ(P2_25), |
embeddedartists | 22:1a58a518435c | 86 | _bios(NULL), |
embeddedartists | 22:1a58a518435c | 87 | _biosData(NULL), |
embeddedartists | 22:1a58a518435c | 88 | _handlerThread(NULL), |
embeddedartists | 22:1a58a518435c | 89 | _handler(NULL), |
embeddedartists | 22:1a58a518435c | 90 | _supportsTouch(false) |
embeddedartists | 22:1a58a518435c | 91 | { |
embeddedartists | 22:1a58a518435c | 92 | } |
embeddedartists | 22:1a58a518435c | 93 | |
embeddedartists | 22:1a58a518435c | 94 | BiosTouch::~BiosTouch() |
embeddedartists | 22:1a58a518435c | 95 | { |
embeddedartists | 22:1a58a518435c | 96 | // _bios and _biosData are deallocated by BiosLoader |
embeddedartists | 22:1a58a518435c | 97 | |
embeddedartists | 22:1a58a518435c | 98 | if (_handlerThread != NULL) { |
embeddedartists | 22:1a58a518435c | 99 | delete _handlerThread; |
embeddedartists | 22:1a58a518435c | 100 | _handlerThread = NULL; |
embeddedartists | 22:1a58a518435c | 101 | } |
embeddedartists | 22:1a58a518435c | 102 | if (_handler != NULL) { |
embeddedartists | 22:1a58a518435c | 103 | delete _handler; |
embeddedartists | 22:1a58a518435c | 104 | _handler = NULL; |
embeddedartists | 22:1a58a518435c | 105 | } |
embeddedartists | 22:1a58a518435c | 106 | } |
embeddedartists | 22:1a58a518435c | 107 | |
embeddedartists | 22:1a58a518435c | 108 | // Function called from the BIOS |
embeddedartists | 22:1a58a518435c | 109 | static void touchIrqEnabler(uint32_t arg, bool enable, bool rising) |
embeddedartists | 22:1a58a518435c | 110 | { |
embeddedartists | 22:1a58a518435c | 111 | ((TouchHandler*)arg)->changeTouchInterrupt(enable, rising); |
embeddedartists | 26:a65fbb4bde5c | 112 | } |
embeddedartists | 26:a65fbb4bde5c | 113 | |
embeddedartists | 26:a65fbb4bde5c | 114 | // Function called from the BIOS |
embeddedartists | 26:a65fbb4bde5c | 115 | static void touchNewData(uint32_t arg, touch_coordinate_t* coords, int num) |
embeddedartists | 26:a65fbb4bde5c | 116 | { |
embeddedartists | 26:a65fbb4bde5c | 117 | ((TouchHandler*)arg)->handleNewData(coords, num); |
embeddedartists | 22:1a58a518435c | 118 | } |
embeddedartists | 22:1a58a518435c | 119 | |
embeddedartists | 22:1a58a518435c | 120 | static void touchTask(void const* args) |
embeddedartists | 22:1a58a518435c | 121 | { |
embeddedartists | 22:1a58a518435c | 122 | ((TouchHandler*)args)->run(); |
embeddedartists | 22:1a58a518435c | 123 | } |
embeddedartists | 22:1a58a518435c | 124 | |
embeddedartists | 22:1a58a518435c | 125 | |
embeddedartists | 22:1a58a518435c | 126 | void TouchHandler::run() |
embeddedartists | 22:1a58a518435c | 127 | { |
embeddedartists | 22:1a58a518435c | 128 | RtosLog* log = DMBoard::instance().logger(); |
embeddedartists | 26:a65fbb4bde5c | 129 | |
embeddedartists | 22:1a58a518435c | 130 | _latest = (touch_coordinate_t*)malloc(_points*sizeof(touch_coordinate_t)); |
embeddedartists | 22:1a58a518435c | 131 | if (_latest == NULL) { |
embeddedartists | 22:1a58a518435c | 132 | log->printf("Failed to allocate memory for touch events\n"); |
embeddedartists | 22:1a58a518435c | 133 | mbed_die(); |
embeddedartists | 22:1a58a518435c | 134 | } |
embeddedartists | 22:1a58a518435c | 135 | memset(_latest, 0, _points*sizeof(touch_coordinate_t)); |
embeddedartists | 22:1a58a518435c | 136 | while(true) { |
embeddedartists | 26:a65fbb4bde5c | 137 | SET_MEAS_PIN_1(); |
embeddedartists | 26:a65fbb4bde5c | 138 | osEvent evt = _mailbox.get(osWaitForever); |
embeddedartists | 26:a65fbb4bde5c | 139 | CLR_MEAS_PIN_1(); |
embeddedartists | 26:a65fbb4bde5c | 140 | if (evt.status == osEventMail) { |
embeddedartists | 26:a65fbb4bde5c | 141 | touch_mail_t* mail = (touch_mail_t*)evt.value.p; |
embeddedartists | 26:a65fbb4bde5c | 142 | memcpy(_latest, mail->touch, mail->num * sizeof(touch_coordinate_t)); |
embeddedartists | 26:a65fbb4bde5c | 143 | _mailbox.free(mail); |
embeddedartists | 26:a65fbb4bde5c | 144 | _dbgRemoved++; |
embeddedartists | 26:a65fbb4bde5c | 145 | if (_points == 1) { |
embeddedartists | 26:a65fbb4bde5c | 146 | log->printf("{%3d,%3d,%d} at %u/%u, with %u lost\n", |
embeddedartists | 26:a65fbb4bde5c | 147 | _latest[0].x, |
embeddedartists | 26:a65fbb4bde5c | 148 | _latest[0].y, |
embeddedartists | 26:a65fbb4bde5c | 149 | _latest[0].z, |
embeddedartists | 26:a65fbb4bde5c | 150 | _dbgRemoved, _dbgAdded, |
embeddedartists | 26:a65fbb4bde5c | 151 | _lostData); |
embeddedartists | 24:9a677afc86f1 | 152 | } else { |
embeddedartists | 26:a65fbb4bde5c | 153 | log->printf("{%d,%d,%d,%d,%d} at %u/%u, with %u lost\n", |
embeddedartists | 26:a65fbb4bde5c | 154 | _latest[0].z, |
embeddedartists | 26:a65fbb4bde5c | 155 | _latest[1].z, |
embeddedartists | 26:a65fbb4bde5c | 156 | _latest[2].z, |
embeddedartists | 26:a65fbb4bde5c | 157 | _latest[3].z, |
embeddedartists | 26:a65fbb4bde5c | 158 | _latest[4].z, |
embeddedartists | 26:a65fbb4bde5c | 159 | _dbgRemoved, _dbgAdded, |
embeddedartists | 26:a65fbb4bde5c | 160 | _lostData); |
embeddedartists | 24:9a677afc86f1 | 161 | } |
embeddedartists | 26:a65fbb4bde5c | 162 | } else { |
embeddedartists | 26:a65fbb4bde5c | 163 | log->printf("got non-mail event: 0x%x\n", evt.status); |
embeddedartists | 26:a65fbb4bde5c | 164 | continue; |
embeddedartists | 26:a65fbb4bde5c | 165 | } |
embeddedartists | 26:a65fbb4bde5c | 166 | _mutex.lock(); |
embeddedartists | 26:a65fbb4bde5c | 167 | FunctionPointer* fp = _listener; |
embeddedartists | 26:a65fbb4bde5c | 168 | _mutex.unlock(); |
embeddedartists | 26:a65fbb4bde5c | 169 | |
embeddedartists | 26:a65fbb4bde5c | 170 | if (fp != NULL) { |
embeddedartists | 26:a65fbb4bde5c | 171 | fp->call(); |
embeddedartists | 26:a65fbb4bde5c | 172 | } |
embeddedartists | 22:1a58a518435c | 173 | } |
embeddedartists | 22:1a58a518435c | 174 | } |
embeddedartists | 22:1a58a518435c | 175 | |
embeddedartists | 22:1a58a518435c | 176 | TouchPanel::TouchError TouchHandler::read(touch_coordinate_t* coord, int num) |
embeddedartists | 22:1a58a518435c | 177 | { |
embeddedartists | 22:1a58a518435c | 178 | if (num > _points || num < 1) { |
embeddedartists | 22:1a58a518435c | 179 | return TouchPanel::TouchError_InvalidParam; |
embeddedartists | 22:1a58a518435c | 180 | } |
embeddedartists | 22:1a58a518435c | 181 | _mutex.lock(); |
embeddedartists | 22:1a58a518435c | 182 | memcpy(coord, _latest, num*sizeof(touch_coordinate_t)); |
embeddedartists | 22:1a58a518435c | 183 | _mutex.unlock(); |
embeddedartists | 22:1a58a518435c | 184 | |
embeddedartists | 22:1a58a518435c | 185 | return TouchPanel::TouchError_Ok; |
embeddedartists | 22:1a58a518435c | 186 | } |
embeddedartists | 22:1a58a518435c | 187 | |
embeddedartists | 22:1a58a518435c | 188 | void TouchHandler::handleTouchInterrupt() |
embeddedartists | 22:1a58a518435c | 189 | { |
embeddedartists | 22:1a58a518435c | 190 | SET_MEAS_PIN_2(); |
embeddedartists | 26:a65fbb4bde5c | 191 | _bios->touchIrqHandler(_biosData); |
embeddedartists | 26:a65fbb4bde5c | 192 | CLR_MEAS_PIN_2(); |
embeddedartists | 26:a65fbb4bde5c | 193 | } |
embeddedartists | 26:a65fbb4bde5c | 194 | |
embeddedartists | 26:a65fbb4bde5c | 195 | void TouchHandler::handleI2CInterrupt() |
embeddedartists | 26:a65fbb4bde5c | 196 | { |
embeddedartists | 26:a65fbb4bde5c | 197 | SET_MEAS_PIN_3(); |
embeddedartists | 26:a65fbb4bde5c | 198 | _bios->touchI2CIRQHandler(_biosData); |
embeddedartists | 26:a65fbb4bde5c | 199 | CLR_MEAS_PIN_3(); |
embeddedartists | 26:a65fbb4bde5c | 200 | } |
embeddedartists | 26:a65fbb4bde5c | 201 | |
embeddedartists | 26:a65fbb4bde5c | 202 | void TouchHandler::handleNewData(touch_coordinate_t* coord, int num) |
embeddedartists | 26:a65fbb4bde5c | 203 | { |
embeddedartists | 26:a65fbb4bde5c | 204 | SET_MEAS_PIN_4(); |
embeddedartists | 26:a65fbb4bde5c | 205 | touch_mail_t* mail = _mailbox.alloc(0); |
embeddedartists | 26:a65fbb4bde5c | 206 | if (mail == NULL) { |
embeddedartists | 26:a65fbb4bde5c | 207 | //DMBoard::instance().logger()->printf("Lost touch event\n"); |
embeddedartists | 26:a65fbb4bde5c | 208 | _lostData++; |
embeddedartists | 26:a65fbb4bde5c | 209 | } else { |
embeddedartists | 26:a65fbb4bde5c | 210 | _dbgAdded++; |
embeddedartists | 26:a65fbb4bde5c | 211 | mail->num = (num < NUM_COORDS) ? num : NUM_COORDS; |
embeddedartists | 26:a65fbb4bde5c | 212 | memcpy(&mail->touch, coord, mail->num*sizeof(touch_coordinate_t)); |
embeddedartists | 26:a65fbb4bde5c | 213 | _mailbox.put(mail); |
embeddedartists | 22:1a58a518435c | 214 | } |
embeddedartists | 26:a65fbb4bde5c | 215 | CLR_MEAS_PIN_4(); |
embeddedartists | 22:1a58a518435c | 216 | } |
embeddedartists | 22:1a58a518435c | 217 | |
embeddedartists | 22:1a58a518435c | 218 | void TouchHandler::changeTouchInterrupt(bool enable, bool rising) |
embeddedartists | 22:1a58a518435c | 219 | { |
embeddedartists | 22:1a58a518435c | 220 | if (enable) { |
embeddedartists | 22:1a58a518435c | 221 | if (rising) { |
embeddedartists | 22:1a58a518435c | 222 | _touchIRQ.rise(this, &TouchHandler::handleTouchInterrupt); |
embeddedartists | 22:1a58a518435c | 223 | } else { |
embeddedartists | 22:1a58a518435c | 224 | _touchIRQ.fall(this, &TouchHandler::handleTouchInterrupt); |
embeddedartists | 22:1a58a518435c | 225 | } |
embeddedartists | 22:1a58a518435c | 226 | } else { |
embeddedartists | 22:1a58a518435c | 227 | if (rising) { |
embeddedartists | 22:1a58a518435c | 228 | _touchIRQ.rise(NULL); |
embeddedartists | 22:1a58a518435c | 229 | } else { |
embeddedartists | 22:1a58a518435c | 230 | _touchIRQ.fall(NULL); |
embeddedartists | 22:1a58a518435c | 231 | } |
embeddedartists | 22:1a58a518435c | 232 | } |
embeddedartists | 22:1a58a518435c | 233 | } |
embeddedartists | 22:1a58a518435c | 234 | |
embeddedartists | 22:1a58a518435c | 235 | FunctionPointer* TouchHandler::setListener(FunctionPointer* listener) |
embeddedartists | 22:1a58a518435c | 236 | { |
embeddedartists | 22:1a58a518435c | 237 | _mutex.lock(); |
embeddedartists | 22:1a58a518435c | 238 | FunctionPointer* old = _listener; |
embeddedartists | 22:1a58a518435c | 239 | _listener = listener; |
embeddedartists | 22:1a58a518435c | 240 | _mutex.unlock(); |
embeddedartists | 22:1a58a518435c | 241 | return old; |
embeddedartists | 22:1a58a518435c | 242 | } |
embeddedartists | 22:1a58a518435c | 243 | |
embeddedartists | 22:1a58a518435c | 244 | |
embeddedartists | 22:1a58a518435c | 245 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 246 | * Public Functions |
embeddedartists | 22:1a58a518435c | 247 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 248 | |
embeddedartists | 22:1a58a518435c | 249 | BiosTouch::TouchError BiosTouch::init() |
embeddedartists | 22:1a58a518435c | 250 | { |
embeddedartists | 22:1a58a518435c | 251 | TouchError result = TouchError_Ok; |
embeddedartists | 22:1a58a518435c | 252 | if (!_initialized) { |
embeddedartists | 22:1a58a518435c | 253 | do { |
embeddedartists | 22:1a58a518435c | 254 | if (BiosLoader::instance().params(&_bios, &_biosData) != DMBoard::Ok) { |
embeddedartists | 22:1a58a518435c | 255 | result = TouchError_ConfigError; |
embeddedartists | 22:1a58a518435c | 256 | break; |
embeddedartists | 22:1a58a518435c | 257 | } |
embeddedartists | 22:1a58a518435c | 258 | |
embeddedartists | 22:1a58a518435c | 259 | result = (TouchError)_bios->touchInformation(_biosData, &_supportsTouch, &_supportsTouchCalibration, &_touchIsResistive, &_touchNumFingers); |
embeddedartists | 22:1a58a518435c | 260 | if (result != TouchError_Ok) { |
embeddedartists | 22:1a58a518435c | 261 | break; |
embeddedartists | 22:1a58a518435c | 262 | } |
embeddedartists | 22:1a58a518435c | 263 | _haveInfo = true; |
embeddedartists | 22:1a58a518435c | 264 | |
embeddedartists | 22:1a58a518435c | 265 | // is it supported at all? |
embeddedartists | 22:1a58a518435c | 266 | if (!_supportsTouch) { |
embeddedartists | 22:1a58a518435c | 267 | result = TouchError_TouchNotSupported; |
embeddedartists | 22:1a58a518435c | 268 | break; |
embeddedartists | 22:1a58a518435c | 269 | } |
embeddedartists | 22:1a58a518435c | 270 | |
embeddedartists | 26:a65fbb4bde5c | 271 | NVIC_DisableIRQ(I2C0_IRQn); |
embeddedartists | 26:a65fbb4bde5c | 272 | NVIC_SetVector(I2C0_IRQn, (uint32_t)touch_i2c0_irq_handler); |
embeddedartists | 26:a65fbb4bde5c | 273 | _handler = theTouchHandler = new TouchHandler(_bios, _biosData, _touchNumFingers); |
embeddedartists | 26:a65fbb4bde5c | 274 | NVIC_EnableIRQ(I2C0_IRQn); |
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 | 22:1a58a518435c | 286 | _handlerThread = new Thread(touchTask, _handler); |
embeddedartists | 22:1a58a518435c | 287 | |
embeddedartists | 22:1a58a518435c | 288 | _initialized = true; |
embeddedartists | 22:1a58a518435c | 289 | } while(0); |
embeddedartists | 22:1a58a518435c | 290 | |
embeddedartists | 22:1a58a518435c | 291 | if (!_initialized) { |
embeddedartists | 22:1a58a518435c | 292 | if (_handler != NULL) { |
embeddedartists | 22:1a58a518435c | 293 | delete _handler; |
embeddedartists | 22:1a58a518435c | 294 | _handler = NULL; |
embeddedartists | 26:a65fbb4bde5c | 295 | theTouchHandler = 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 | *resistive = _touchIsResistive; |
embeddedartists | 22:1a58a518435c | 331 | *maxPoints = _touchNumFingers; |
embeddedartists | 22:1a58a518435c | 332 | *calibrated = _supportsTouchCalibration; |
embeddedartists | 22:1a58a518435c | 333 | } |
embeddedartists | 22:1a58a518435c | 334 | return err; |
embeddedartists | 22:1a58a518435c | 335 | } |
embeddedartists | 22:1a58a518435c | 336 | |
embeddedartists | 22:1a58a518435c | 337 | bool BiosTouch::isTouchSupported() |
embeddedartists | 22:1a58a518435c | 338 | { |
embeddedartists | 22:1a58a518435c | 339 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 22:1a58a518435c | 340 | if (_haveInfo) { |
embeddedartists | 22:1a58a518435c | 341 | return _supportsTouch; |
embeddedartists | 22:1a58a518435c | 342 | } |
embeddedartists | 22:1a58a518435c | 343 | #endif |
embeddedartists | 22:1a58a518435c | 344 | return false; |
embeddedartists | 22:1a58a518435c | 345 | } |
embeddedartists | 22:1a58a518435c | 346 | |
embeddedartists | 22:1a58a518435c | 347 | BiosTouch::TouchError BiosTouch::calibrateStart() |
embeddedartists | 22:1a58a518435c | 348 | { |
embeddedartists | 22:1a58a518435c | 349 | TouchError err = TouchError_Ok; |
embeddedartists | 22:1a58a518435c | 350 | if (!_initialized) { |
embeddedartists | 22:1a58a518435c | 351 | err = TouchError_NoInit; |
embeddedartists | 22:1a58a518435c | 352 | } else { |
embeddedartists | 22:1a58a518435c | 353 | err = (TouchError)_bios->touchCalibrateStart(_biosData); |
embeddedartists | 22:1a58a518435c | 354 | } |
embeddedartists | 22:1a58a518435c | 355 | return err; |
embeddedartists | 22:1a58a518435c | 356 | } |
embeddedartists | 22:1a58a518435c | 357 | |
embeddedartists | 22:1a58a518435c | 358 | BiosTouch::TouchError BiosTouch::getNextCalibratePoint(uint16_t* x, uint16_t* y, bool* last) |
embeddedartists | 22:1a58a518435c | 359 | { |
embeddedartists | 22:1a58a518435c | 360 | TouchError err = TouchError_Ok; |
embeddedartists | 22:1a58a518435c | 361 | if (!_initialized) { |
embeddedartists | 22:1a58a518435c | 362 | err = TouchError_NoInit; |
embeddedartists | 22:1a58a518435c | 363 | } else { |
embeddedartists | 22:1a58a518435c | 364 | err = (TouchError)_bios->touchGetNextCalibPoint(_biosData, x, y, last); |
embeddedartists | 22:1a58a518435c | 365 | } |
embeddedartists | 22:1a58a518435c | 366 | return err; |
embeddedartists | 22:1a58a518435c | 367 | } |
embeddedartists | 22:1a58a518435c | 368 | |
embeddedartists | 22:1a58a518435c | 369 | BiosTouch::TouchError BiosTouch::waitForCalibratePoint(bool* morePoints, uint32_t timeout) |
embeddedartists | 22:1a58a518435c | 370 | { |
embeddedartists | 22:1a58a518435c | 371 | TouchError err = TouchError_Ok; |
embeddedartists | 22:1a58a518435c | 372 | if (!_initialized) { |
embeddedartists | 22:1a58a518435c | 373 | err = TouchError_NoInit; |
embeddedartists | 22:1a58a518435c | 374 | } else { |
embeddedartists | 22:1a58a518435c | 375 | err = (TouchError)_bios->touchWaitForCalibratePoint(_biosData, morePoints, timeout); |
embeddedartists | 22:1a58a518435c | 376 | } |
embeddedartists | 22:1a58a518435c | 377 | return err; |
embeddedartists | 22:1a58a518435c | 378 | } |
embeddedartists | 22:1a58a518435c | 379 | |
embeddedartists | 22:1a58a518435c | 380 | FunctionPointer* BiosTouch::setListener(FunctionPointer* listener) |
embeddedartists | 22:1a58a518435c | 381 | { |
embeddedartists | 22:1a58a518435c | 382 | if (_initialized) { |
embeddedartists | 22:1a58a518435c | 383 | return _handler->setListener(listener); |
embeddedartists | 22:1a58a518435c | 384 | } |
embeddedartists | 22:1a58a518435c | 385 | return NULL; |
embeddedartists | 22:1a58a518435c | 386 | } |