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@9:a33326afd686, 2014-12-11 (annotated)
- Committer:
- embeddedartists
- Date:
- Thu Dec 11 18:23:07 2014 +0000
- Revision:
- 9:a33326afd686
- Parent:
- 5:c77fdb6e3438
- Child:
- 10:1ac4b213f0f7
Updated documentation
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 | 5:c77fdb6e3438 | 29 | |
embeddedartists | 5:c77fdb6e3438 | 30 | /****************************************************************************** |
embeddedartists | 5:c77fdb6e3438 | 31 | * Configuration Compatibility Control |
embeddedartists | 5:c77fdb6e3438 | 32 | *****************************************************************************/ |
embeddedartists | 5:c77fdb6e3438 | 33 | |
embeddedartists | 5:c77fdb6e3438 | 34 | #if defined(DM_BOARD_USE_USB_DEVICE) && defined(DM_BOARD_USE_USB_HOST) |
embeddedartists | 5:c77fdb6e3438 | 35 | #error The hardware supports either USB Device or USB Host - not both at the same time |
embeddedartists | 5:c77fdb6e3438 | 36 | #endif |
embeddedartists | 5:c77fdb6e3438 | 37 | |
embeddedartists | 0:6b68dac0d986 | 38 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 39 | * Defines and typedefs |
embeddedartists | 0:6b68dac0d986 | 40 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 41 | |
embeddedartists | 2:887c6b45e7fa | 42 | #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF) |
embeddedartists | 2:887c6b45e7fa | 43 | class DevNull : public Stream { |
embeddedartists | 2:887c6b45e7fa | 44 | |
embeddedartists | 2:887c6b45e7fa | 45 | public: |
embeddedartists | 2:887c6b45e7fa | 46 | DevNull(const char *name=NULL) : Stream(name) {} |
embeddedartists | 2:887c6b45e7fa | 47 | |
embeddedartists | 2:887c6b45e7fa | 48 | protected: |
embeddedartists | 2:887c6b45e7fa | 49 | virtual int _getc() {return 0;} |
embeddedartists | 2:887c6b45e7fa | 50 | virtual int _putc(int c) {return c;} |
embeddedartists | 2:887c6b45e7fa | 51 | }; |
embeddedartists | 2:887c6b45e7fa | 52 | |
embeddedartists | 2:887c6b45e7fa | 53 | static DevNull null("null"); |
embeddedartists | 2:887c6b45e7fa | 54 | #endif |
embeddedartists | 2:887c6b45e7fa | 55 | |
embeddedartists | 0:6b68dac0d986 | 56 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 57 | * Local variables |
embeddedartists | 0:6b68dac0d986 | 58 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 59 | |
embeddedartists | 0:6b68dac0d986 | 60 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 61 | * Private Functions |
embeddedartists | 0:6b68dac0d986 | 62 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 63 | |
embeddedartists | 0:6b68dac0d986 | 64 | DMBoard::DMBoard() : |
embeddedartists | 0:6b68dac0d986 | 65 | _initialized(false), |
embeddedartists | 0:6b68dac0d986 | 66 | #if defined(DM_BOARD_USE_MCI_FS) |
embeddedartists | 0:6b68dac0d986 | 67 | _mcifs("mci", P4_16), |
embeddedartists | 0:6b68dac0d986 | 68 | #endif |
embeddedartists | 0:6b68dac0d986 | 69 | #if defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 70 | _qspifs("qspi"), |
embeddedartists | 0:6b68dac0d986 | 71 | #endif |
embeddedartists | 0:6b68dac0d986 | 72 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 0:6b68dac0d986 | 73 | _touch(NULL), |
embeddedartists | 0:6b68dac0d986 | 74 | #endif |
embeddedartists | 0:6b68dac0d986 | 75 | _buzzer(P1_5), |
embeddedartists | 0:6b68dac0d986 | 76 | _button(p23), |
embeddedartists | 0:6b68dac0d986 | 77 | _led1(LED1), |
embeddedartists | 0:6b68dac0d986 | 78 | _led2(LED2), |
embeddedartists | 0:6b68dac0d986 | 79 | _led3(LED3), |
embeddedartists | 0:6b68dac0d986 | 80 | _led4(LED4) |
embeddedartists | 0:6b68dac0d986 | 81 | { |
embeddedartists | 0:6b68dac0d986 | 82 | } |
embeddedartists | 0:6b68dac0d986 | 83 | |
embeddedartists | 0:6b68dac0d986 | 84 | DMBoard::~DMBoard() |
embeddedartists | 0:6b68dac0d986 | 85 | { |
embeddedartists | 2:887c6b45e7fa | 86 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 0:6b68dac0d986 | 87 | if (_touch != NULL) { |
embeddedartists | 0:6b68dac0d986 | 88 | delete _touch; |
embeddedartists | 0:6b68dac0d986 | 89 | _touch = NULL; |
embeddedartists | 0:6b68dac0d986 | 90 | } |
embeddedartists | 2:887c6b45e7fa | 91 | #endif |
embeddedartists | 0:6b68dac0d986 | 92 | } |
embeddedartists | 0:6b68dac0d986 | 93 | |
embeddedartists | 0:6b68dac0d986 | 94 | DMBoard::BoardError DMBoard::readConfiguration() |
embeddedartists | 0:6b68dac0d986 | 95 | { |
embeddedartists | 0:6b68dac0d986 | 96 | InternalEEPROM mem; |
embeddedartists | 0:6b68dac0d986 | 97 | mem.init(); |
embeddedartists | 0:6b68dac0d986 | 98 | |
embeddedartists | 0:6b68dac0d986 | 99 | uint8_t* buff = (uint8_t*)malloc(mem.memorySize()); |
embeddedartists | 0:6b68dac0d986 | 100 | mem.read(0, 0, buff, mem.memorySize()); |
embeddedartists | 0:6b68dac0d986 | 101 | mem.powerDown(); |
embeddedartists | 0:6b68dac0d986 | 102 | #if 0 |
embeddedartists | 0:6b68dac0d986 | 103 | uint8_t* p = buff; |
embeddedartists | 2:887c6b45e7fa | 104 | _logger.printf("\n-------\nBEFORE:\n-------\n"); |
embeddedartists | 0:6b68dac0d986 | 105 | for (int i = 0; i < 63; i++) { |
embeddedartists | 0:6b68dac0d986 | 106 | for (int j = 0; j < 4; j++) { |
embeddedartists | 2:887c6b45e7fa | 107 | _logger.printf("0x%04x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", |
embeddedartists | 0:6b68dac0d986 | 108 | i, |
embeddedartists | 0:6b68dac0d986 | 109 | p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7], |
embeddedartists | 0:6b68dac0d986 | 110 | p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]); |
embeddedartists | 0:6b68dac0d986 | 111 | p += 16; |
embeddedartists | 0:6b68dac0d986 | 112 | } |
embeddedartists | 2:887c6b45e7fa | 113 | _logger.printf("\n"); |
embeddedartists | 0:6b68dac0d986 | 114 | } |
embeddedartists | 0:6b68dac0d986 | 115 | |
embeddedartists | 0:6b68dac0d986 | 116 | // find first non-zero page and write to that |
embeddedartists | 0:6b68dac0d986 | 117 | for (int page = 0; page < mem.numPages(); page++) { |
embeddedartists | 0:6b68dac0d986 | 118 | bool zeroPage = true; |
embeddedartists | 0:6b68dac0d986 | 119 | for (int i = 0; i < mem.pageSize(); i++) { |
embeddedartists | 0:6b68dac0d986 | 120 | if (buff[i + page*mem.pageSize()] != 0) { |
embeddedartists | 0:6b68dac0d986 | 121 | zeroPage = false; |
embeddedartists | 0:6b68dac0d986 | 122 | break; |
embeddedartists | 0:6b68dac0d986 | 123 | } |
embeddedartists | 0:6b68dac0d986 | 124 | } |
embeddedartists | 0:6b68dac0d986 | 125 | if (zeroPage) { |
embeddedartists | 2:887c6b45e7fa | 126 | _logger.printf("Will fill page 0x%04x (%d) with 0x00..0x3f\n", page, page); |
embeddedartists | 0:6b68dac0d986 | 127 | p = buff; |
embeddedartists | 0:6b68dac0d986 | 128 | for (int i = 0; i < mem.pageSize(); i++) { |
embeddedartists | 0:6b68dac0d986 | 129 | *p++ = i; |
embeddedartists | 0:6b68dac0d986 | 130 | } |
embeddedartists | 0:6b68dac0d986 | 131 | mem.write(page, 0, buff, mem.pageSize()); |
embeddedartists | 0:6b68dac0d986 | 132 | memset(buff, 0, mem.memorySize()); |
embeddedartists | 0:6b68dac0d986 | 133 | mem.read(0, 0, buff, mem.memorySize()); |
embeddedartists | 0:6b68dac0d986 | 134 | p = buff; |
embeddedartists | 2:887c6b45e7fa | 135 | _logger.printf("\n-------\nAFTER:\n-------\n"); |
embeddedartists | 0:6b68dac0d986 | 136 | for (int i = 0; i < 63; i++) { |
embeddedartists | 0:6b68dac0d986 | 137 | for (int j = 0; j < 4; j++) { |
embeddedartists | 2:887c6b45e7fa | 138 | _logger.printf("0x%04x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", |
embeddedartists | 0:6b68dac0d986 | 139 | i, |
embeddedartists | 0:6b68dac0d986 | 140 | p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7], |
embeddedartists | 0:6b68dac0d986 | 141 | p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]); |
embeddedartists | 0:6b68dac0d986 | 142 | p += 16; |
embeddedartists | 0:6b68dac0d986 | 143 | } |
embeddedartists | 2:887c6b45e7fa | 144 | _logger.printf("\n"); |
embeddedartists | 0:6b68dac0d986 | 145 | } |
embeddedartists | 0:6b68dac0d986 | 146 | break; |
embeddedartists | 0:6b68dac0d986 | 147 | } |
embeddedartists | 0:6b68dac0d986 | 148 | } |
embeddedartists | 0:6b68dac0d986 | 149 | #endif |
embeddedartists | 0:6b68dac0d986 | 150 | return Ok; |
embeddedartists | 0:6b68dac0d986 | 151 | } |
embeddedartists | 0:6b68dac0d986 | 152 | |
embeddedartists | 0:6b68dac0d986 | 153 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 0:6b68dac0d986 | 154 | DMBoard::BoardError DMBoard::readDisplayConfiguration(uint8_t** data, uint32_t* size) |
embeddedartists | 0:6b68dac0d986 | 155 | { |
embeddedartists | 0:6b68dac0d986 | 156 | uint32_t allocsize = 17*sizeof(uint32_t); |
embeddedartists | 0:6b68dac0d986 | 157 | uint32_t* stuff = (uint32_t*)malloc(allocsize); |
embeddedartists | 0:6b68dac0d986 | 158 | if (stuff == NULL) { |
embeddedartists | 0:6b68dac0d986 | 159 | return MemoryError; |
embeddedartists | 0:6b68dac0d986 | 160 | } |
embeddedartists | 0:6b68dac0d986 | 161 | #if defined(DM_BOARD_USE_4_3_DISPLAY_TMP) |
embeddedartists | 0:6b68dac0d986 | 162 | // Temporary setup, for a 4.3" display |
embeddedartists | 0:6b68dac0d986 | 163 | |
embeddedartists | 0:6b68dac0d986 | 164 | stuff[ 0] = 40, //horizontalBackPorch == HSYNC back porch |
embeddedartists | 0:6b68dac0d986 | 165 | stuff[ 1] = 5, //horizontalFrontPorch == HSYNC front porch |
embeddedartists | 0:6b68dac0d986 | 166 | stuff[ 2] = 2, //hsync == HSYNC width |
embeddedartists | 0:6b68dac0d986 | 167 | stuff[ 3] = 480, //width == Horizontal active area |
embeddedartists | 0:6b68dac0d986 | 168 | stuff[ 4] = 8, //verticalBackPorch == VSYNC back porch |
embeddedartists | 0:6b68dac0d986 | 169 | stuff[ 5] = 8, //verticalFrontPorch == VSYNC front porch |
embeddedartists | 0:6b68dac0d986 | 170 | stuff[ 6] = 2, //vsync == VSYNC width |
embeddedartists | 0:6b68dac0d986 | 171 | stuff[ 7] = 272, //height == Vertical display area |
embeddedartists | 0:6b68dac0d986 | 172 | stuff[ 8] = false, |
embeddedartists | 0:6b68dac0d986 | 173 | stuff[ 9] = false, |
embeddedartists | 0:6b68dac0d986 | 174 | stuff[10] = true, |
embeddedartists | 0:6b68dac0d986 | 175 | stuff[11] = true, |
embeddedartists | 0:6b68dac0d986 | 176 | stuff[12] = 1, |
embeddedartists | 0:6b68dac0d986 | 177 | stuff[13] = Display::Resolution_16bit_rgb565; |
embeddedartists | 0:6b68dac0d986 | 178 | stuff[14] = 9000000, //clock or 0 for external |
embeddedartists | 0:6b68dac0d986 | 179 | stuff[15] = 0, //LcdController::Tft, |
embeddedartists | 0:6b68dac0d986 | 180 | stuff[16] = false; |
embeddedartists | 0:6b68dac0d986 | 181 | #else |
embeddedartists | 0:6b68dac0d986 | 182 | // Temporary setup, for a 5" rogin display |
embeddedartists | 0:6b68dac0d986 | 183 | |
embeddedartists | 0:6b68dac0d986 | 184 | stuff[ 0] = 46, //horizontalBackPorch == HSYNC back porch |
embeddedartists | 0:6b68dac0d986 | 185 | stuff[ 1] = 20, //horizontalFrontPorch == HSYNC front porch |
embeddedartists | 0:6b68dac0d986 | 186 | stuff[ 2] = 2, //hsync == HSYNC width |
embeddedartists | 0:6b68dac0d986 | 187 | stuff[ 3] = 800, //width == Horizontal active area |
embeddedartists | 0:6b68dac0d986 | 188 | stuff[ 4] = 23, //verticalBackPorch == VSYNC back porch |
embeddedartists | 0:6b68dac0d986 | 189 | stuff[ 5] = 10, //verticalFrontPorch == VSYNC front porch |
embeddedartists | 0:6b68dac0d986 | 190 | stuff[ 6] = 3, //vsync == VSYNC width |
embeddedartists | 0:6b68dac0d986 | 191 | stuff[ 7] = 480, //height == Vertical display area |
embeddedartists | 0:6b68dac0d986 | 192 | stuff[ 8] = false, |
embeddedartists | 0:6b68dac0d986 | 193 | stuff[ 9] = false, |
embeddedartists | 0:6b68dac0d986 | 194 | stuff[10] = true, |
embeddedartists | 0:6b68dac0d986 | 195 | stuff[11] = true, |
embeddedartists | 0:6b68dac0d986 | 196 | stuff[12] = 1, |
embeddedartists | 0:6b68dac0d986 | 197 | stuff[13] = Display::Resolution_16bit_rgb565; |
embeddedartists | 0:6b68dac0d986 | 198 | stuff[14] = 30000000, //clock or 0 for external |
embeddedartists | 0:6b68dac0d986 | 199 | stuff[15] = 0, //LcdController::Tft, |
embeddedartists | 0:6b68dac0d986 | 200 | stuff[16] = false; |
embeddedartists | 0:6b68dac0d986 | 201 | #endif |
embeddedartists | 0:6b68dac0d986 | 202 | *data = (uint8_t*)&(stuff[0]); |
embeddedartists | 0:6b68dac0d986 | 203 | *size = allocsize; |
embeddedartists | 0:6b68dac0d986 | 204 | |
embeddedartists | 0:6b68dac0d986 | 205 | return Ok; |
embeddedartists | 0:6b68dac0d986 | 206 | } |
embeddedartists | 0:6b68dac0d986 | 207 | #endif |
embeddedartists | 0:6b68dac0d986 | 208 | |
embeddedartists | 0:6b68dac0d986 | 209 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 210 | * Public Functions |
embeddedartists | 0:6b68dac0d986 | 211 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 212 | |
embeddedartists | 0:6b68dac0d986 | 213 | DMBoard::BoardError DMBoard::init() |
embeddedartists | 0:6b68dac0d986 | 214 | { |
embeddedartists | 0:6b68dac0d986 | 215 | BoardError err = Ok; |
embeddedartists | 0:6b68dac0d986 | 216 | if (!_initialized) { |
embeddedartists | 0:6b68dac0d986 | 217 | do { |
embeddedartists | 0:6b68dac0d986 | 218 | // Turn off the buzzer |
embeddedartists | 0:6b68dac0d986 | 219 | _buzzer.period_ms(1); |
embeddedartists | 0:6b68dac0d986 | 220 | _buzzer = 0; |
embeddedartists | 0:6b68dac0d986 | 221 | |
embeddedartists | 0:6b68dac0d986 | 222 | // Make sure the button is configured correctly |
embeddedartists | 0:6b68dac0d986 | 223 | _button.mode(PullUp); |
embeddedartists | 0:6b68dac0d986 | 224 | |
embeddedartists | 0:6b68dac0d986 | 225 | // Turn off all LEDs |
embeddedartists | 0:6b68dac0d986 | 226 | _led1 = 1; |
embeddedartists | 0:6b68dac0d986 | 227 | _led2 = 1; |
embeddedartists | 0:6b68dac0d986 | 228 | _led3 = 0; |
embeddedartists | 0:6b68dac0d986 | 229 | _led4 = 0; |
embeddedartists | 0:6b68dac0d986 | 230 | |
embeddedartists | 2:887c6b45e7fa | 231 | // Make sure that the logger is always initialized even if |
embeddedartists | 2:887c6b45e7fa | 232 | // other initialization tasks fail |
embeddedartists | 2:887c6b45e7fa | 233 | _logger.init(); |
embeddedartists | 4:6fdcdf7aff8d | 234 | |
embeddedartists | 4:6fdcdf7aff8d | 235 | #if defined(DM_BOARD_ENABLE_MEASSURING_PINS) |
embeddedartists | 4:6fdcdf7aff8d | 236 | _INTERNAL_INIT_MEAS(); |
embeddedartists | 4:6fdcdf7aff8d | 237 | #endif |
embeddedartists | 2:887c6b45e7fa | 238 | |
embeddedartists | 2:887c6b45e7fa | 239 | #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF) |
embeddedartists | 2:887c6b45e7fa | 240 | // Kill all ouput of calls to printf() so that there is no |
embeddedartists | 2:887c6b45e7fa | 241 | // simultaneous calls into the non-thread-safe standard libraries. |
embeddedartists | 2:887c6b45e7fa | 242 | // User code should use the RtosLogger anyway. |
embeddedartists | 2:887c6b45e7fa | 243 | freopen("/null", "w", stdout); |
embeddedartists | 2:887c6b45e7fa | 244 | #endif |
embeddedartists | 2:887c6b45e7fa | 245 | |
embeddedartists | 3:2fa7755f2cef | 246 | #if defined(DM_BOARD_USE_QSPI) || defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 247 | if (SPIFI::instance().init() != SPIFI::Ok) { |
embeddedartists | 0:6b68dac0d986 | 248 | err = SpifiError; |
embeddedartists | 0:6b68dac0d986 | 249 | break; |
embeddedartists | 0:6b68dac0d986 | 250 | } |
embeddedartists | 0:6b68dac0d986 | 251 | #endif |
embeddedartists | 0:6b68dac0d986 | 252 | |
embeddedartists | 0:6b68dac0d986 | 253 | readConfiguration(); |
embeddedartists | 0:6b68dac0d986 | 254 | |
embeddedartists | 0:6b68dac0d986 | 255 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 0:6b68dac0d986 | 256 | if (Display::instance().init() != Display::Ok) { |
embeddedartists | 0:6b68dac0d986 | 257 | err = DisplayError; |
embeddedartists | 0:6b68dac0d986 | 258 | break; |
embeddedartists | 0:6b68dac0d986 | 259 | } |
embeddedartists | 0:6b68dac0d986 | 260 | #endif |
embeddedartists | 0:6b68dac0d986 | 261 | |
embeddedartists | 0:6b68dac0d986 | 262 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 0:6b68dac0d986 | 263 | //if (... configuration says AR1021...) { |
embeddedartists | 0:6b68dac0d986 | 264 | _touch = new AR1021(P2_27, P2_26, P2_22, P2_23, P2_25); |
embeddedartists | 4:6fdcdf7aff8d | 265 | int att; |
embeddedartists | 4:6fdcdf7aff8d | 266 | for (att = 1; att <= 3; att++) { |
embeddedartists | 4:6fdcdf7aff8d | 267 | if (_touch->init(Display::instance().width(), Display::instance().height())) { |
embeddedartists | 4:6fdcdf7aff8d | 268 | break; |
embeddedartists | 4:6fdcdf7aff8d | 269 | } |
embeddedartists | 4:6fdcdf7aff8d | 270 | _logger.printf("Failed to init touch, trying again...\n"); |
embeddedartists | 4:6fdcdf7aff8d | 271 | wait_ms(500); |
embeddedartists | 4:6fdcdf7aff8d | 272 | } |
embeddedartists | 4:6fdcdf7aff8d | 273 | if (att > 3) { |
embeddedartists | 0:6b68dac0d986 | 274 | err = TouchError; |
embeddedartists | 0:6b68dac0d986 | 275 | break; |
embeddedartists | 0:6b68dac0d986 | 276 | } |
embeddedartists | 0:6b68dac0d986 | 277 | //} |
embeddedartists | 0:6b68dac0d986 | 278 | #endif |
embeddedartists | 0:6b68dac0d986 | 279 | |
embeddedartists | 0:6b68dac0d986 | 280 | |
embeddedartists | 0:6b68dac0d986 | 281 | _initialized = true; |
embeddedartists | 0:6b68dac0d986 | 282 | } while(0); |
embeddedartists | 0:6b68dac0d986 | 283 | } |
embeddedartists | 0:6b68dac0d986 | 284 | return err; |
embeddedartists | 0:6b68dac0d986 | 285 | } |
embeddedartists | 0:6b68dac0d986 | 286 | |
embeddedartists | 2:887c6b45e7fa | 287 | void DMBoard::setLED(Leds led, bool on) |
embeddedartists | 0:6b68dac0d986 | 288 | { |
embeddedartists | 0:6b68dac0d986 | 289 | switch(led) { |
embeddedartists | 2:887c6b45e7fa | 290 | case Led1: |
embeddedartists | 0:6b68dac0d986 | 291 | _led1 = (on ? 0 : 1); |
embeddedartists | 0:6b68dac0d986 | 292 | break; |
embeddedartists | 2:887c6b45e7fa | 293 | case Led2: |
embeddedartists | 0:6b68dac0d986 | 294 | _led2 = (on ? 0 : 1); |
embeddedartists | 0:6b68dac0d986 | 295 | break; |
embeddedartists | 2:887c6b45e7fa | 296 | case Led3: |
embeddedartists | 0:6b68dac0d986 | 297 | _led3 = (on ? 1 : 0); |
embeddedartists | 0:6b68dac0d986 | 298 | break; |
embeddedartists | 2:887c6b45e7fa | 299 | case Led4: |
embeddedartists | 0:6b68dac0d986 | 300 | _led4 = (on ? 1 : 0); |
embeddedartists | 0:6b68dac0d986 | 301 | break; |
embeddedartists | 0:6b68dac0d986 | 302 | } |
embeddedartists | 0:6b68dac0d986 | 303 | } |
embeddedartists | 0:6b68dac0d986 | 304 | |
embeddedartists | 5:c77fdb6e3438 | 305 | void DMBoard::buzzer(int frequency, int duration_ms) |
embeddedartists | 0:6b68dac0d986 | 306 | { |
embeddedartists | 5:c77fdb6e3438 | 307 | if (frequency <= 0) { |
embeddedartists | 5:c77fdb6e3438 | 308 | _buzzer = 0; |
embeddedartists | 5:c77fdb6e3438 | 309 | } else { |
embeddedartists | 5:c77fdb6e3438 | 310 | _buzzer.period_us(1000000/frequency); |
embeddedartists | 5:c77fdb6e3438 | 311 | _buzzer = 0.5; |
embeddedartists | 0:6b68dac0d986 | 312 | } |
embeddedartists | 5:c77fdb6e3438 | 313 | if (duration_ms > 0) { |
embeddedartists | 5:c77fdb6e3438 | 314 | Thread::wait(duration_ms); |
embeddedartists | 5:c77fdb6e3438 | 315 | _buzzer = 0; |
embeddedartists | 5:c77fdb6e3438 | 316 | } |
embeddedartists | 0:6b68dac0d986 | 317 | } |
embeddedartists | 0:6b68dac0d986 | 318 | |
embeddedartists | 0:6b68dac0d986 | 319 | bool DMBoard::buttonPressed() |
embeddedartists | 0:6b68dac0d986 | 320 | { |
embeddedartists | 0:6b68dac0d986 | 321 | return _button.read() == 0; |
embeddedartists | 0:6b68dac0d986 | 322 | } |