![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
kuguzh
Dependencies: DmTftLibrary mbed
main.cpp@0:dd55ca105ef3, 2015-12-14 (annotated)
- Committer:
- TFuchsbichler
- Date:
- Mon Dec 14 15:25:49 2015 +0000
- Revision:
- 0:dd55ca105ef3
uiggzui; ; ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TFuchsbichler | 0:dd55ca105ef3 | 1 | /********************************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 2 | Copyright (c) 2014 DisplayModule. All rights reserved. |
TFuchsbichler | 0:dd55ca105ef3 | 3 | |
TFuchsbichler | 0:dd55ca105ef3 | 4 | Redistribution and use of this source code, part of this source code or any compiled binary |
TFuchsbichler | 0:dd55ca105ef3 | 5 | based on this source code is permitted as long as the above copyright notice and following |
TFuchsbichler | 0:dd55ca105ef3 | 6 | disclaimer is retained. |
TFuchsbichler | 0:dd55ca105ef3 | 7 | |
TFuchsbichler | 0:dd55ca105ef3 | 8 | DISCLAIMER: |
TFuchsbichler | 0:dd55ca105ef3 | 9 | THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES |
TFuchsbichler | 0:dd55ca105ef3 | 10 | NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. |
TFuchsbichler | 0:dd55ca105ef3 | 11 | ********************************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 12 | |
TFuchsbichler | 0:dd55ca105ef3 | 13 | /****************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 14 | * Tested on NUCLEO-F401RE, LPCXpresso11U68, LPCXpresso824-MAX platform. |
TFuchsbichler | 0:dd55ca105ef3 | 15 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 16 | |
TFuchsbichler | 0:dd55ca105ef3 | 17 | #include "mbed.h" |
TFuchsbichler | 0:dd55ca105ef3 | 18 | |
TFuchsbichler | 0:dd55ca105ef3 | 19 | #include "DmTftHX8353C.h" |
TFuchsbichler | 0:dd55ca105ef3 | 20 | #include "DmTftS6D0164.h" |
TFuchsbichler | 0:dd55ca105ef3 | 21 | #include "DmTftIli9325.h" |
TFuchsbichler | 0:dd55ca105ef3 | 22 | #include "DmTftIli9341.h" |
TFuchsbichler | 0:dd55ca105ef3 | 23 | #include "DmTftSsd2119.h" |
TFuchsbichler | 0:dd55ca105ef3 | 24 | #include "DmTftRa8875.h" |
TFuchsbichler | 0:dd55ca105ef3 | 25 | #include "DmTouch.h" |
TFuchsbichler | 0:dd55ca105ef3 | 26 | #include "DmTpFt6x06.h" |
TFuchsbichler | 0:dd55ca105ef3 | 27 | |
TFuchsbichler | 0:dd55ca105ef3 | 28 | /****************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 29 | * Typedefs and defines |
TFuchsbichler | 0:dd55ca105ef3 | 30 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 31 | |
TFuchsbichler | 0:dd55ca105ef3 | 32 | /* Note that there are restrictions on which platforms that can use printf |
TFuchsbichler | 0:dd55ca105ef3 | 33 | in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso) |
TFuchsbichler | 0:dd55ca105ef3 | 34 | use the same pins for USBRX/USBTX and display control. Printing will |
TFuchsbichler | 0:dd55ca105ef3 | 35 | cause the display to not work. Read more about this on the display's notebook |
TFuchsbichler | 0:dd55ca105ef3 | 36 | page. */ |
TFuchsbichler | 0:dd55ca105ef3 | 37 | //#define log(...) printf(__VA_ARGS__) |
TFuchsbichler | 0:dd55ca105ef3 | 38 | #define log(...) |
TFuchsbichler | 0:dd55ca105ef3 | 39 | |
TFuchsbichler | 0:dd55ca105ef3 | 40 | #if 1 |
TFuchsbichler | 0:dd55ca105ef3 | 41 | /* Displays without adapter */ |
TFuchsbichler | 0:dd55ca105ef3 | 42 | #define DM_PIN_SPI_MOSI p5 |
TFuchsbichler | 0:dd55ca105ef3 | 43 | #define DM_PIN_SPI_MISO p6 |
TFuchsbichler | 0:dd55ca105ef3 | 44 | #define DM_PIN_SPI_SCLK p7 |
TFuchsbichler | 0:dd55ca105ef3 | 45 | #define DM_PIN_CS_TOUCH p25 |
TFuchsbichler | 0:dd55ca105ef3 | 46 | #define DM_PIN_CS_TFT p21 |
TFuchsbichler | 0:dd55ca105ef3 | 47 | #define DM_PIN_CS_SDCARD p23 |
TFuchsbichler | 0:dd55ca105ef3 | 48 | #define DM_PIN_CS_FLASH p24 |
TFuchsbichler | 0:dd55ca105ef3 | 49 | #else |
TFuchsbichler | 0:dd55ca105ef3 | 50 | /* Displays with adapter */ |
TFuchsbichler | 0:dd55ca105ef3 | 51 | #define DM_PIN_SPI_MOSI p5 |
TFuchsbichler | 0:dd55ca105ef3 | 52 | #define DM_PIN_SPI_MISO p6 |
TFuchsbichler | 0:dd55ca105ef3 | 53 | #define DM_PIN_SPI_SCLK p7 |
TFuchsbichler | 0:dd55ca105ef3 | 54 | #define DM_PIN_CS_TOUCH p25 |
TFuchsbichler | 0:dd55ca105ef3 | 55 | #define DM_PIN_CS_TFT p21 |
TFuchsbichler | 0:dd55ca105ef3 | 56 | #define DM_PIN_CS_SDCARD p23 |
TFuchsbichler | 0:dd55ca105ef3 | 57 | #endif |
TFuchsbichler | 0:dd55ca105ef3 | 58 | |
TFuchsbichler | 0:dd55ca105ef3 | 59 | /****************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 60 | * Local variables |
TFuchsbichler | 0:dd55ca105ef3 | 61 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 62 | |
TFuchsbichler | 0:dd55ca105ef3 | 63 | /********* TFT DISPLAY INIT *********/ |
TFuchsbichler | 0:dd55ca105ef3 | 64 | DmTftIli9341 tft(p21, p22, p5, p6, p7); /* DmTftIli9341(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT28_105 and DM_TFT28_116*/ |
TFuchsbichler | 0:dd55ca105ef3 | 65 | |
TFuchsbichler | 0:dd55ca105ef3 | 66 | /********* TOUCH PANEL INIT *********/ |
TFuchsbichler | 0:dd55ca105ef3 | 67 | |
TFuchsbichler | 0:dd55ca105ef3 | 68 | DmTouch touch(DmTouch::DM_TFT28_105, p5, p6, p7); |
TFuchsbichler | 0:dd55ca105ef3 | 69 | |
TFuchsbichler | 0:dd55ca105ef3 | 70 | DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1); |
TFuchsbichler | 0:dd55ca105ef3 | 71 | DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1); |
TFuchsbichler | 0:dd55ca105ef3 | 72 | DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1); |
TFuchsbichler | 0:dd55ca105ef3 | 73 | #ifdef DM_PIN_CS_FLASH |
TFuchsbichler | 0:dd55ca105ef3 | 74 | DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1); |
TFuchsbichler | 0:dd55ca105ef3 | 75 | #endif |
TFuchsbichler | 0:dd55ca105ef3 | 76 | |
TFuchsbichler | 0:dd55ca105ef3 | 77 | /****************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 78 | * Global variables |
TFuchsbichler | 0:dd55ca105ef3 | 79 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 80 | |
TFuchsbichler | 0:dd55ca105ef3 | 81 | /****************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 82 | * Local functions |
TFuchsbichler | 0:dd55ca105ef3 | 83 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 84 | |
TFuchsbichler | 0:dd55ca105ef3 | 85 | Ticker Tick; |
TFuchsbichler | 0:dd55ca105ef3 | 86 | |
TFuchsbichler | 0:dd55ca105ef3 | 87 | float a; |
TFuchsbichler | 0:dd55ca105ef3 | 88 | int msek; |
TFuchsbichler | 0:dd55ca105ef3 | 89 | int sek; |
TFuchsbichler | 0:dd55ca105ef3 | 90 | int min; |
TFuchsbichler | 0:dd55ca105ef3 | 91 | int stund; |
TFuchsbichler | 0:dd55ca105ef3 | 92 | bool mode; |
TFuchsbichler | 0:dd55ca105ef3 | 93 | |
TFuchsbichler | 0:dd55ca105ef3 | 94 | |
TFuchsbichler | 0:dd55ca105ef3 | 95 | void zaehl() |
TFuchsbichler | 0:dd55ca105ef3 | 96 | { |
TFuchsbichler | 0:dd55ca105ef3 | 97 | if(mode==true) { |
TFuchsbichler | 0:dd55ca105ef3 | 98 | msek++; |
TFuchsbichler | 0:dd55ca105ef3 | 99 | if(msek==100) { |
TFuchsbichler | 0:dd55ca105ef3 | 100 | sek++; |
TFuchsbichler | 0:dd55ca105ef3 | 101 | msek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 102 | |
TFuchsbichler | 0:dd55ca105ef3 | 103 | } |
TFuchsbichler | 0:dd55ca105ef3 | 104 | |
TFuchsbichler | 0:dd55ca105ef3 | 105 | if(sek==60) { |
TFuchsbichler | 0:dd55ca105ef3 | 106 | min++; |
TFuchsbichler | 0:dd55ca105ef3 | 107 | sek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 108 | |
TFuchsbichler | 0:dd55ca105ef3 | 109 | } |
TFuchsbichler | 0:dd55ca105ef3 | 110 | |
TFuchsbichler | 0:dd55ca105ef3 | 111 | if(min==60) { |
TFuchsbichler | 0:dd55ca105ef3 | 112 | stund++; |
TFuchsbichler | 0:dd55ca105ef3 | 113 | min=0; |
TFuchsbichler | 0:dd55ca105ef3 | 114 | } |
TFuchsbichler | 0:dd55ca105ef3 | 115 | if(stund==24) { |
TFuchsbichler | 0:dd55ca105ef3 | 116 | msek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 117 | sek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 118 | min=0; |
TFuchsbichler | 0:dd55ca105ef3 | 119 | stund=0; |
TFuchsbichler | 0:dd55ca105ef3 | 120 | } |
TFuchsbichler | 0:dd55ca105ef3 | 121 | |
TFuchsbichler | 0:dd55ca105ef3 | 122 | } |
TFuchsbichler | 0:dd55ca105ef3 | 123 | |
TFuchsbichler | 0:dd55ca105ef3 | 124 | } |
TFuchsbichler | 0:dd55ca105ef3 | 125 | |
TFuchsbichler | 0:dd55ca105ef3 | 126 | void reset() |
TFuchsbichler | 0:dd55ca105ef3 | 127 | { |
TFuchsbichler | 0:dd55ca105ef3 | 128 | msek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 129 | sek=0; |
TFuchsbichler | 0:dd55ca105ef3 | 130 | min=0; |
TFuchsbichler | 0:dd55ca105ef3 | 131 | stund=0; |
TFuchsbichler | 0:dd55ca105ef3 | 132 | } |
TFuchsbichler | 0:dd55ca105ef3 | 133 | |
TFuchsbichler | 0:dd55ca105ef3 | 134 | /****************************************************************************** |
TFuchsbichler | 0:dd55ca105ef3 | 135 | * Main |
TFuchsbichler | 0:dd55ca105ef3 | 136 | *****************************************************************************/ |
TFuchsbichler | 0:dd55ca105ef3 | 137 | |
TFuchsbichler | 0:dd55ca105ef3 | 138 | int main() |
TFuchsbichler | 0:dd55ca105ef3 | 139 | { |
TFuchsbichler | 0:dd55ca105ef3 | 140 | log("init tft \r\n"); |
TFuchsbichler | 0:dd55ca105ef3 | 141 | mode=false; |
TFuchsbichler | 0:dd55ca105ef3 | 142 | tft.init(); |
TFuchsbichler | 0:dd55ca105ef3 | 143 | Tick.attach(&zaehl, 0.01); |
TFuchsbichler | 0:dd55ca105ef3 | 144 | |
TFuchsbichler | 0:dd55ca105ef3 | 145 | uint16_t x = 0; |
TFuchsbichler | 0:dd55ca105ef3 | 146 | uint16_t y = 0; |
TFuchsbichler | 0:dd55ca105ef3 | 147 | uint16_t w = tft.width(); |
TFuchsbichler | 0:dd55ca105ef3 | 148 | uint16_t h = tft.height(); |
TFuchsbichler | 0:dd55ca105ef3 | 149 | |
TFuchsbichler | 0:dd55ca105ef3 | 150 | bool down=false; |
TFuchsbichler | 0:dd55ca105ef3 | 151 | //Rectangles |
TFuchsbichler | 0:dd55ca105ef3 | 152 | tft.drawRectangle(25, 285, 74, 310,WHITE); |
TFuchsbichler | 0:dd55ca105ef3 | 153 | tft.drawRectangle(95, 285, 144, 310,WHITE); |
TFuchsbichler | 0:dd55ca105ef3 | 154 | tft.drawRectangle(165, 285,214, 310,WHITE); |
TFuchsbichler | 0:dd55ca105ef3 | 155 | tft.fillRectangle(26, 286, 73, 309, GREEN); |
TFuchsbichler | 0:dd55ca105ef3 | 156 | tft.fillRectangle(96, 286, 143, 309, RED); |
TFuchsbichler | 0:dd55ca105ef3 | 157 | //Text |
TFuchsbichler | 0:dd55ca105ef3 | 158 | tft.drawString(84, 30, "STOPWATCH"); |
TFuchsbichler | 0:dd55ca105ef3 | 159 | tft.drawString(30, 290, "START"); |
TFuchsbichler | 0:dd55ca105ef3 | 160 | tft.drawString(104, 290, "STOP"); |
TFuchsbichler | 0:dd55ca105ef3 | 161 | tft.drawString(170, 290, "RESET"); |
TFuchsbichler | 0:dd55ca105ef3 | 162 | |
TFuchsbichler | 0:dd55ca105ef3 | 163 | |
TFuchsbichler | 0:dd55ca105ef3 | 164 | touch.init(); |
TFuchsbichler | 0:dd55ca105ef3 | 165 | while (1) { |
TFuchsbichler | 0:dd55ca105ef3 | 166 | touch.readTouchData(x, y, down); |
TFuchsbichler | 0:dd55ca105ef3 | 167 | if(down==true&&x>=25&&x<=74&&y>=285&&y<=310) |
TFuchsbichler | 0:dd55ca105ef3 | 168 | mode=true; |
TFuchsbichler | 0:dd55ca105ef3 | 169 | |
TFuchsbichler | 0:dd55ca105ef3 | 170 | if(down==true&&x>=95&&x<=144&&y>=285&&y<=310) |
TFuchsbichler | 0:dd55ca105ef3 | 171 | mode=false; |
TFuchsbichler | 0:dd55ca105ef3 | 172 | |
TFuchsbichler | 0:dd55ca105ef3 | 173 | if(down==true&&x>=165&&x<=214&&y>=285&&y<=310) |
TFuchsbichler | 0:dd55ca105ef3 | 174 | reset(); |
TFuchsbichler | 0:dd55ca105ef3 | 175 | |
TFuchsbichler | 0:dd55ca105ef3 | 176 | tft.drawNumber(88,70,stund,2,1); |
TFuchsbichler | 0:dd55ca105ef3 | 177 | tft.drawString(104, 70, ":"); |
TFuchsbichler | 0:dd55ca105ef3 | 178 | tft.drawNumber(112,70,min,2,1); |
TFuchsbichler | 0:dd55ca105ef3 | 179 | tft.drawString(128, 70, ":"); |
TFuchsbichler | 0:dd55ca105ef3 | 180 | tft.drawNumber(136,70,sek,2,1); |
TFuchsbichler | 0:dd55ca105ef3 | 181 | tft.drawNumber(136,86,msek,2,1); |
TFuchsbichler | 0:dd55ca105ef3 | 182 | |
TFuchsbichler | 0:dd55ca105ef3 | 183 | down=false; |
TFuchsbichler | 0:dd55ca105ef3 | 184 | } |
TFuchsbichler | 0:dd55ca105ef3 | 185 | |
TFuchsbichler | 0:dd55ca105ef3 | 186 | } |