Subdirectory provided by Embedded Artists
Dependencies: DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos mbed-src
Dependents: lpc4088_displaymodule_hello_world_Sept_2018
Fork of DMSupport by
DMBoard.cpp@4:6fdcdf7aff8d, 2014-12-08 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Dec 08 12:48:44 2014 +0000
- Revision:
- 4:6fdcdf7aff8d
- Parent:
- 3:2fa7755f2cef
- Child:
- 5:c77fdb6e3438
Changed touch interface to report last point. Added GPIO-time-measuring support. Fixed USB Host MSD bug that caused HTTPServer to crash
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:6b68dac0d986 | 1 | /* |
embeddedartists | 0:6b68dac0d986 | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 0:6b68dac0d986 | 3 | * |
embeddedartists | 0:6b68dac0d986 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 0:6b68dac0d986 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 0:6b68dac0d986 | 6 | * You may obtain a copy of the License at |
embeddedartists | 0:6b68dac0d986 | 7 | * |
embeddedartists | 0:6b68dac0d986 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 0:6b68dac0d986 | 9 | * |
embeddedartists | 0:6b68dac0d986 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 0:6b68dac0d986 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 0:6b68dac0d986 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 0:6b68dac0d986 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 0:6b68dac0d986 | 14 | * limitations under the License. |
embeddedartists | 0:6b68dac0d986 | 15 | */ |
embeddedartists | 0:6b68dac0d986 | 16 | |
embeddedartists | 0:6b68dac0d986 | 17 | #include "mbed.h" |
embeddedartists | 0:6b68dac0d986 | 18 | #include "DMBoard.h" |
embeddedartists | 0:6b68dac0d986 | 19 | #include "InternalEEPROM.h" |
embeddedartists | 0:6b68dac0d986 | 20 | |
embeddedartists | 0:6b68dac0d986 | 21 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 0:6b68dac0d986 | 22 | #include "AR1021.h" |
embeddedartists | 0:6b68dac0d986 | 23 | #endif |
embeddedartists | 0:6b68dac0d986 | 24 | |
embeddedartists | 4:6fdcdf7aff8d | 25 | #if defined(DM_BOARD_ENABLE_MEASSURING_PINS) |
embeddedartists | 4:6fdcdf7aff8d | 26 | #include "meas.h" |
embeddedartists | 4:6fdcdf7aff8d | 27 | #endif |
embeddedartists | 4:6fdcdf7aff8d | 28 | |
embeddedartists | 0:6b68dac0d986 | 29 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 30 | * Defines and typedefs |
embeddedartists | 0:6b68dac0d986 | 31 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 32 | |
embeddedartists | 2:887c6b45e7fa | 33 | #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF) |
embeddedartists | 2:887c6b45e7fa | 34 | class DevNull : public Stream { |
embeddedartists | 2:887c6b45e7fa | 35 | |
embeddedartists | 2:887c6b45e7fa | 36 | public: |
embeddedartists | 2:887c6b45e7fa | 37 | DevNull(const char *name=NULL) : Stream(name) {} |
embeddedartists | 2:887c6b45e7fa | 38 | |
embeddedartists | 2:887c6b45e7fa | 39 | protected: |
embeddedartists | 2:887c6b45e7fa | 40 | virtual int _getc() {return 0;} |
embeddedartists | 2:887c6b45e7fa | 41 | virtual int _putc(int c) {return c;} |
embeddedartists | 2:887c6b45e7fa | 42 | }; |
embeddedartists | 2:887c6b45e7fa | 43 | |
embeddedartists | 2:887c6b45e7fa | 44 | static DevNull null("null"); |
embeddedartists | 2:887c6b45e7fa | 45 | #endif |
embeddedartists | 2:887c6b45e7fa | 46 | |
embeddedartists | 0:6b68dac0d986 | 47 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 48 | * Local variables |
embeddedartists | 0:6b68dac0d986 | 49 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 50 | |
embeddedartists | 0:6b68dac0d986 | 51 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 52 | * Private Functions |
embeddedartists | 0:6b68dac0d986 | 53 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 54 | |
embeddedartists | 0:6b68dac0d986 | 55 | DMBoard::DMBoard() : |
embeddedartists | 0:6b68dac0d986 | 56 | _initialized(false), |
embeddedartists | 0:6b68dac0d986 | 57 | #if defined(DM_BOARD_USE_MCI_FS) |
embeddedartists | 0:6b68dac0d986 | 58 | _mcifs("mci", P4_16), |
embeddedartists | 0:6b68dac0d986 | 59 | #endif |
embeddedartists | 0:6b68dac0d986 | 60 | #if defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 61 | _qspifs("qspi"), |
embeddedartists | 0:6b68dac0d986 | 62 | #endif |
embeddedartists | 0:6b68dac0d986 | 63 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 0:6b68dac0d986 | 64 | _touch(NULL), |
embeddedartists | 0:6b68dac0d986 | 65 | #endif |
embeddedartists | 0:6b68dac0d986 | 66 | _buzzer(P1_5), |
embeddedartists | 0:6b68dac0d986 | 67 | _button(p23), |
embeddedartists | 0:6b68dac0d986 | 68 | _led1(LED1), |
embeddedartists | 0:6b68dac0d986 | 69 | _led2(LED2), |
embeddedartists | 0:6b68dac0d986 | 70 | _led3(LED3), |
embeddedartists | 0:6b68dac0d986 | 71 | _led4(LED4) |
embeddedartists | 0:6b68dac0d986 | 72 | { |
embeddedartists | 0:6b68dac0d986 | 73 | } |
embeddedartists | 0:6b68dac0d986 | 74 | |
embeddedartists | 0:6b68dac0d986 | 75 | DMBoard::~DMBoard() |
embeddedartists | 0:6b68dac0d986 | 76 | { |
embeddedartists | 2:887c6b45e7fa | 77 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 0:6b68dac0d986 | 78 | if (_touch != NULL) { |
embeddedartists | 0:6b68dac0d986 | 79 | delete _touch; |
embeddedartists | 0:6b68dac0d986 | 80 | _touch = NULL; |
embeddedartists | 0:6b68dac0d986 | 81 | } |
embeddedartists | 2:887c6b45e7fa | 82 | #endif |
embeddedartists | 0:6b68dac0d986 | 83 | } |
embeddedartists | 0:6b68dac0d986 | 84 | |
embeddedartists | 0:6b68dac0d986 | 85 | DMBoard::BoardError DMBoard::readConfiguration() |
embeddedartists | 0:6b68dac0d986 | 86 | { |
embeddedartists | 0:6b68dac0d986 | 87 | InternalEEPROM mem; |
embeddedartists | 0:6b68dac0d986 | 88 | mem.init(); |
embeddedartists | 0:6b68dac0d986 | 89 | |
embeddedartists | 0:6b68dac0d986 | 90 | uint8_t* buff = (uint8_t*)malloc(mem.memorySize()); |
embeddedartists | 0:6b68dac0d986 | 91 | mem.read(0, 0, buff, mem.memorySize()); |
embeddedartists | 0:6b68dac0d986 | 92 | mem.powerDown(); |
embeddedartists | 0:6b68dac0d986 | 93 | #if 0 |
embeddedartists | 0:6b68dac0d986 | 94 | uint8_t* p = buff; |
embeddedartists | 2:887c6b45e7fa | 95 | _logger.printf("\n-------\nBEFORE:\n-------\n"); |
embeddedartists | 0:6b68dac0d986 | 96 | for (int i = 0; i < 63; i++) { |
embeddedartists | 0:6b68dac0d986 | 97 | for (int j = 0; j < 4; j++) { |
embeddedartists | 2:887c6b45e7fa | 98 | _logger.printf("0x%04x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", |
embeddedartists | 0:6b68dac0d986 | 99 | i, |
embeddedartists | 0:6b68dac0d986 | 100 | p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7], |
embeddedartists | 0:6b68dac0d986 | 101 | p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]); |
embeddedartists | 0:6b68dac0d986 | 102 | p += 16; |
embeddedartists | 0:6b68dac0d986 | 103 | } |
embeddedartists | 2:887c6b45e7fa | 104 | _logger.printf("\n"); |
embeddedartists | 0:6b68dac0d986 | 105 | } |
embeddedartists | 0:6b68dac0d986 | 106 | |
embeddedartists | 0:6b68dac0d986 | 107 | // find first non-zero page and write to that |
embeddedartists | 0:6b68dac0d986 | 108 | for (int page = 0; page < mem.numPages(); page++) { |
embeddedartists | 0:6b68dac0d986 | 109 | bool zeroPage = true; |
embeddedartists | 0:6b68dac0d986 | 110 | for (int i = 0; i < mem.pageSize(); i++) { |
embeddedartists | 0:6b68dac0d986 | 111 | if (buff[i + page*mem.pageSize()] != 0) { |
embeddedartists | 0:6b68dac0d986 | 112 | zeroPage = false; |
embeddedartists | 0:6b68dac0d986 | 113 | break; |
embeddedartists | 0:6b68dac0d986 | 114 | } |
embeddedartists | 0:6b68dac0d986 | 115 | } |
embeddedartists | 0:6b68dac0d986 | 116 | if (zeroPage) { |
embeddedartists | 2:887c6b45e7fa | 117 | _logger.printf("Will fill page 0x%04x (%d) with 0x00..0x3f\n", page, page); |
embeddedartists | 0:6b68dac0d986 | 118 | p = buff; |
embeddedartists | 0:6b68dac0d986 | 119 | for (int i = 0; i < mem.pageSize(); i++) { |
embeddedartists | 0:6b68dac0d986 | 120 | *p++ = i; |
embeddedartists | 0:6b68dac0d986 | 121 | } |
embeddedartists | 0:6b68dac0d986 | 122 | mem.write(page, 0, buff, mem.pageSize()); |
embeddedartists | 0:6b68dac0d986 | 123 | memset(buff, 0, mem.memorySize()); |
embeddedartists | 0:6b68dac0d986 | 124 | mem.read(0, 0, buff, mem.memorySize()); |
embeddedartists | 0:6b68dac0d986 | 125 | p = buff; |
embeddedartists | 2:887c6b45e7fa | 126 | _logger.printf("\n-------\nAFTER:\n-------\n"); |
embeddedartists | 0:6b68dac0d986 | 127 | for (int i = 0; i < 63; i++) { |
embeddedartists | 0:6b68dac0d986 | 128 | for (int j = 0; j < 4; j++) { |
embeddedartists | 2:887c6b45e7fa | 129 | _logger.printf("0x%04x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", |
embeddedartists | 0:6b68dac0d986 | 130 | i, |
embeddedartists | 0:6b68dac0d986 | 131 | p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7], |
embeddedartists | 0:6b68dac0d986 | 132 | p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]); |
embeddedartists | 0:6b68dac0d986 | 133 | p += 16; |
embeddedartists | 0:6b68dac0d986 | 134 | } |
embeddedartists | 2:887c6b45e7fa | 135 | _logger.printf("\n"); |
embeddedartists | 0:6b68dac0d986 | 136 | } |
embeddedartists | 0:6b68dac0d986 | 137 | break; |
embeddedartists | 0:6b68dac0d986 | 138 | } |
embeddedartists | 0:6b68dac0d986 | 139 | } |
embeddedartists | 0:6b68dac0d986 | 140 | #endif |
embeddedartists | 0:6b68dac0d986 | 141 | return Ok; |
embeddedartists | 0:6b68dac0d986 | 142 | } |
embeddedartists | 0:6b68dac0d986 | 143 | |
embeddedartists | 0:6b68dac0d986 | 144 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 0:6b68dac0d986 | 145 | DMBoard::BoardError DMBoard::readDisplayConfiguration(uint8_t** data, uint32_t* size) |
embeddedartists | 0:6b68dac0d986 | 146 | { |
embeddedartists | 0:6b68dac0d986 | 147 | uint32_t allocsize = 17*sizeof(uint32_t); |
embeddedartists | 0:6b68dac0d986 | 148 | uint32_t* stuff = (uint32_t*)malloc(allocsize); |
embeddedartists | 0:6b68dac0d986 | 149 | if (stuff == NULL) { |
embeddedartists | 0:6b68dac0d986 | 150 | return MemoryError; |
embeddedartists | 0:6b68dac0d986 | 151 | } |
embeddedartists | 0:6b68dac0d986 | 152 | #if defined(DM_BOARD_USE_4_3_DISPLAY_TMP) |
embeddedartists | 0:6b68dac0d986 | 153 | // Temporary setup, for a 4.3" display |
embeddedartists | 0:6b68dac0d986 | 154 | |
embeddedartists | 0:6b68dac0d986 | 155 | stuff[ 0] = 40, //horizontalBackPorch == HSYNC back porch |
embeddedartists | 0:6b68dac0d986 | 156 | stuff[ 1] = 5, //horizontalFrontPorch == HSYNC front porch |
embeddedartists | 0:6b68dac0d986 | 157 | stuff[ 2] = 2, //hsync == HSYNC width |
embeddedartists | 0:6b68dac0d986 | 158 | stuff[ 3] = 480, //width == Horizontal active area |
embeddedartists | 0:6b68dac0d986 | 159 | stuff[ 4] = 8, //verticalBackPorch == VSYNC back porch |
embeddedartists | 0:6b68dac0d986 | 160 | stuff[ 5] = 8, //verticalFrontPorch == VSYNC front porch |
embeddedartists | 0:6b68dac0d986 | 161 | stuff[ 6] = 2, //vsync == VSYNC width |
embeddedartists | 0:6b68dac0d986 | 162 | stuff[ 7] = 272, //height == Vertical display area |
embeddedartists | 0:6b68dac0d986 | 163 | stuff[ 8] = false, |
embeddedartists | 0:6b68dac0d986 | 164 | stuff[ 9] = false, |
embeddedartists | 0:6b68dac0d986 | 165 | stuff[10] = true, |
embeddedartists | 0:6b68dac0d986 | 166 | stuff[11] = true, |
embeddedartists | 0:6b68dac0d986 | 167 | stuff[12] = 1, |
embeddedartists | 0:6b68dac0d986 | 168 | stuff[13] = Display::Resolution_16bit_rgb565; |
embeddedartists | 0:6b68dac0d986 | 169 | stuff[14] = 9000000, //clock or 0 for external |
embeddedartists | 0:6b68dac0d986 | 170 | stuff[15] = 0, //LcdController::Tft, |
embeddedartists | 0:6b68dac0d986 | 171 | stuff[16] = false; |
embeddedartists | 0:6b68dac0d986 | 172 | #else |
embeddedartists | 0:6b68dac0d986 | 173 | // Temporary setup, for a 5" rogin display |
embeddedartists | 0:6b68dac0d986 | 174 | |
embeddedartists | 0:6b68dac0d986 | 175 | stuff[ 0] = 46, //horizontalBackPorch == HSYNC back porch |
embeddedartists | 0:6b68dac0d986 | 176 | stuff[ 1] = 20, //horizontalFrontPorch == HSYNC front porch |
embeddedartists | 0:6b68dac0d986 | 177 | stuff[ 2] = 2, //hsync == HSYNC width |
embeddedartists | 0:6b68dac0d986 | 178 | stuff[ 3] = 800, //width == Horizontal active area |
embeddedartists | 0:6b68dac0d986 | 179 | stuff[ 4] = 23, //verticalBackPorch == VSYNC back porch |
embeddedartists | 0:6b68dac0d986 | 180 | stuff[ 5] = 10, //verticalFrontPorch == VSYNC front porch |
embeddedartists | 0:6b68dac0d986 | 181 | stuff[ 6] = 3, //vsync == VSYNC width |
embeddedartists | 0:6b68dac0d986 | 182 | stuff[ 7] = 480, //height == Vertical display area |
embeddedartists | 0:6b68dac0d986 | 183 | stuff[ 8] = false, |
embeddedartists | 0:6b68dac0d986 | 184 | stuff[ 9] = false, |
embeddedartists | 0:6b68dac0d986 | 185 | stuff[10] = true, |
embeddedartists | 0:6b68dac0d986 | 186 | stuff[11] = true, |
embeddedartists | 0:6b68dac0d986 | 187 | stuff[12] = 1, |
embeddedartists | 0:6b68dac0d986 | 188 | stuff[13] = Display::Resolution_16bit_rgb565; |
embeddedartists | 0:6b68dac0d986 | 189 | stuff[14] = 30000000, //clock or 0 for external |
embeddedartists | 0:6b68dac0d986 | 190 | stuff[15] = 0, //LcdController::Tft, |
embeddedartists | 0:6b68dac0d986 | 191 | stuff[16] = false; |
embeddedartists | 0:6b68dac0d986 | 192 | #endif |
embeddedartists | 0:6b68dac0d986 | 193 | *data = (uint8_t*)&(stuff[0]); |
embeddedartists | 0:6b68dac0d986 | 194 | *size = allocsize; |
embeddedartists | 0:6b68dac0d986 | 195 | |
embeddedartists | 0:6b68dac0d986 | 196 | return Ok; |
embeddedartists | 0:6b68dac0d986 | 197 | } |
embeddedartists | 0:6b68dac0d986 | 198 | #endif |
embeddedartists | 0:6b68dac0d986 | 199 | |
embeddedartists | 0:6b68dac0d986 | 200 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 201 | * Public Functions |
embeddedartists | 0:6b68dac0d986 | 202 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 203 | |
embeddedartists | 0:6b68dac0d986 | 204 | DMBoard::BoardError DMBoard::init() |
embeddedartists | 0:6b68dac0d986 | 205 | { |
embeddedartists | 0:6b68dac0d986 | 206 | BoardError err = Ok; |
embeddedartists | 0:6b68dac0d986 | 207 | if (!_initialized) { |
embeddedartists | 0:6b68dac0d986 | 208 | do { |
embeddedartists | 0:6b68dac0d986 | 209 | // Turn off the buzzer |
embeddedartists | 0:6b68dac0d986 | 210 | _buzzer.period_ms(1); |
embeddedartists | 0:6b68dac0d986 | 211 | _buzzer = 0; |
embeddedartists | 0:6b68dac0d986 | 212 | |
embeddedartists | 0:6b68dac0d986 | 213 | // Make sure the button is configured correctly |
embeddedartists | 0:6b68dac0d986 | 214 | _button.mode(PullUp); |
embeddedartists | 0:6b68dac0d986 | 215 | |
embeddedartists | 0:6b68dac0d986 | 216 | // Turn off all LEDs |
embeddedartists | 0:6b68dac0d986 | 217 | _led1 = 1; |
embeddedartists | 0:6b68dac0d986 | 218 | _led2 = 1; |
embeddedartists | 0:6b68dac0d986 | 219 | _led3 = 0; |
embeddedartists | 0:6b68dac0d986 | 220 | _led4 = 0; |
embeddedartists | 0:6b68dac0d986 | 221 | |
embeddedartists | 2:887c6b45e7fa | 222 | // Make sure that the logger is always initialized even if |
embeddedartists | 2:887c6b45e7fa | 223 | // other initialization tasks fail |
embeddedartists | 2:887c6b45e7fa | 224 | _logger.init(); |
embeddedartists | 4:6fdcdf7aff8d | 225 | |
embeddedartists | 4:6fdcdf7aff8d | 226 | #if defined(DM_BOARD_ENABLE_MEASSURING_PINS) |
embeddedartists | 4:6fdcdf7aff8d | 227 | _INTERNAL_INIT_MEAS(); |
embeddedartists | 4:6fdcdf7aff8d | 228 | #endif |
embeddedartists | 2:887c6b45e7fa | 229 | |
embeddedartists | 2:887c6b45e7fa | 230 | #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF) |
embeddedartists | 2:887c6b45e7fa | 231 | // Kill all ouput of calls to printf() so that there is no |
embeddedartists | 2:887c6b45e7fa | 232 | // simultaneous calls into the non-thread-safe standard libraries. |
embeddedartists | 2:887c6b45e7fa | 233 | // User code should use the RtosLogger anyway. |
embeddedartists | 2:887c6b45e7fa | 234 | freopen("/null", "w", stdout); |
embeddedartists | 2:887c6b45e7fa | 235 | #endif |
embeddedartists | 2:887c6b45e7fa | 236 | |
embeddedartists | 3:2fa7755f2cef | 237 | #if defined(DM_BOARD_USE_QSPI) || defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 238 | if (SPIFI::instance().init() != SPIFI::Ok) { |
embeddedartists | 0:6b68dac0d986 | 239 | err = SpifiError; |
embeddedartists | 0:6b68dac0d986 | 240 | break; |
embeddedartists | 0:6b68dac0d986 | 241 | } |
embeddedartists | 0:6b68dac0d986 | 242 | #endif |
embeddedartists | 0:6b68dac0d986 | 243 | |
embeddedartists | 0:6b68dac0d986 | 244 | readConfiguration(); |
embeddedartists | 0:6b68dac0d986 | 245 | |
embeddedartists | 0:6b68dac0d986 | 246 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 0:6b68dac0d986 | 247 | if (Display::instance().init() != Display::Ok) { |
embeddedartists | 0:6b68dac0d986 | 248 | err = DisplayError; |
embeddedartists | 0:6b68dac0d986 | 249 | break; |
embeddedartists | 0:6b68dac0d986 | 250 | } |
embeddedartists | 0:6b68dac0d986 | 251 | #endif |
embeddedartists | 0:6b68dac0d986 | 252 | |
embeddedartists | 0:6b68dac0d986 | 253 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 0:6b68dac0d986 | 254 | //if (... configuration says AR1021...) { |
embeddedartists | 0:6b68dac0d986 | 255 | _touch = new AR1021(P2_27, P2_26, P2_22, P2_23, P2_25); |
embeddedartists | 4:6fdcdf7aff8d | 256 | // if (!_touch->init(Display::instance().width(), Display::instance().height())) { |
embeddedartists | 4:6fdcdf7aff8d | 257 | // err = TouchError; |
embeddedartists | 4:6fdcdf7aff8d | 258 | // break; |
embeddedartists | 4:6fdcdf7aff8d | 259 | // } |
embeddedartists | 4:6fdcdf7aff8d | 260 | int att; |
embeddedartists | 4:6fdcdf7aff8d | 261 | for (att = 1; att <= 3; att++) { |
embeddedartists | 4:6fdcdf7aff8d | 262 | if (_touch->init(Display::instance().width(), Display::instance().height())) { |
embeddedartists | 4:6fdcdf7aff8d | 263 | break; |
embeddedartists | 4:6fdcdf7aff8d | 264 | } |
embeddedartists | 4:6fdcdf7aff8d | 265 | _logger.printf("Failed to init touch, trying again...\n"); |
embeddedartists | 4:6fdcdf7aff8d | 266 | wait_ms(500); |
embeddedartists | 4:6fdcdf7aff8d | 267 | } |
embeddedartists | 4:6fdcdf7aff8d | 268 | if (att > 3) { |
embeddedartists | 0:6b68dac0d986 | 269 | err = TouchError; |
embeddedartists | 0:6b68dac0d986 | 270 | break; |
embeddedartists | 0:6b68dac0d986 | 271 | } |
embeddedartists | 0:6b68dac0d986 | 272 | //} |
embeddedartists | 0:6b68dac0d986 | 273 | #endif |
embeddedartists | 0:6b68dac0d986 | 274 | |
embeddedartists | 0:6b68dac0d986 | 275 | |
embeddedartists | 0:6b68dac0d986 | 276 | _initialized = true; |
embeddedartists | 0:6b68dac0d986 | 277 | } while(0); |
embeddedartists | 0:6b68dac0d986 | 278 | } |
embeddedartists | 0:6b68dac0d986 | 279 | return err; |
embeddedartists | 0:6b68dac0d986 | 280 | } |
embeddedartists | 0:6b68dac0d986 | 281 | |
embeddedartists | 2:887c6b45e7fa | 282 | void DMBoard::setLED(Leds led, bool on) |
embeddedartists | 0:6b68dac0d986 | 283 | { |
embeddedartists | 0:6b68dac0d986 | 284 | switch(led) { |
embeddedartists | 2:887c6b45e7fa | 285 | case Led1: |
embeddedartists | 0:6b68dac0d986 | 286 | _led1 = (on ? 0 : 1); |
embeddedartists | 0:6b68dac0d986 | 287 | break; |
embeddedartists | 2:887c6b45e7fa | 288 | case Led2: |
embeddedartists | 0:6b68dac0d986 | 289 | _led2 = (on ? 0 : 1); |
embeddedartists | 0:6b68dac0d986 | 290 | break; |
embeddedartists | 2:887c6b45e7fa | 291 | case Led3: |
embeddedartists | 0:6b68dac0d986 | 292 | _led3 = (on ? 1 : 0); |
embeddedartists | 0:6b68dac0d986 | 293 | break; |
embeddedartists | 2:887c6b45e7fa | 294 | case Led4: |
embeddedartists | 0:6b68dac0d986 | 295 | _led4 = (on ? 1 : 0); |
embeddedartists | 0:6b68dac0d986 | 296 | break; |
embeddedartists | 0:6b68dac0d986 | 297 | } |
embeddedartists | 0:6b68dac0d986 | 298 | } |
embeddedartists | 0:6b68dac0d986 | 299 | |
embeddedartists | 0:6b68dac0d986 | 300 | void DMBoard::buzzer(float value) |
embeddedartists | 0:6b68dac0d986 | 301 | { |
embeddedartists | 0:6b68dac0d986 | 302 | if (value < 0) { |
embeddedartists | 0:6b68dac0d986 | 303 | value = 0; |
embeddedartists | 0:6b68dac0d986 | 304 | } else if (value > 1) { |
embeddedartists | 0:6b68dac0d986 | 305 | value = 1; |
embeddedartists | 0:6b68dac0d986 | 306 | } |
embeddedartists | 0:6b68dac0d986 | 307 | _buzzer = value; |
embeddedartists | 0:6b68dac0d986 | 308 | } |
embeddedartists | 0:6b68dac0d986 | 309 | |
embeddedartists | 0:6b68dac0d986 | 310 | bool DMBoard::buttonPressed() |
embeddedartists | 0:6b68dac0d986 | 311 | { |
embeddedartists | 0:6b68dac0d986 | 312 | return _button.read() == 0; |
embeddedartists | 0:6b68dac0d986 | 313 | } |
embeddedartists | 0:6b68dac0d986 | 314 |