Test application based on the AVR examples provided by ThaiEasyElec for their ELT240320ATP breakout board -- library works rather slow on the mbed platform.
main.cpp@0:4395705c8647, 2010-03-10 (annotated)
- Committer:
- robodude666
- Date:
- Wed Mar 10 21:17:41 2010 +0000
- Revision:
- 0:4395705c8647
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robodude666 | 0:4395705c8647 | 1 | // General Drivers |
robodude666 | 0:4395705c8647 | 2 | #include "mbed.h" |
robodude666 | 0:4395705c8647 | 3 | |
robodude666 | 0:4395705c8647 | 4 | #include "ClockControl.h" |
robodude666 | 0:4395705c8647 | 5 | |
robodude666 | 0:4395705c8647 | 6 | // QVGA LCD Drivers |
robodude666 | 0:4395705c8647 | 7 | |
robodude666 | 0:4395705c8647 | 8 | //////// |
robodude666 | 0:4395705c8647 | 9 | #include "font_courier.h" |
robodude666 | 0:4395705c8647 | 10 | |
robodude666 | 0:4395705c8647 | 11 | // LCD Control |
robodude666 | 0:4395705c8647 | 12 | DigitalOut lcd_rst(p13); |
robodude666 | 0:4395705c8647 | 13 | DigitalOut lcd_bl(p14); |
robodude666 | 0:4395705c8647 | 14 | DigitalOut lcd_rs(p15); |
robodude666 | 0:4395705c8647 | 15 | DigitalOut lcd_cs(p16); |
robodude666 | 0:4395705c8647 | 16 | DigitalOut lcd_rd(p17); |
robodude666 | 0:4395705c8647 | 17 | DigitalOut lcd_wr(p18); |
robodude666 | 0:4395705c8647 | 18 | |
robodude666 | 0:4395705c8647 | 19 | BusInOut lcd_db(p5, p6, p7, p8, p9, p10, p11, p12); |
robodude666 | 0:4395705c8647 | 20 | |
robodude666 | 0:4395705c8647 | 21 | // Touch Screen Control |
robodude666 | 0:4395705c8647 | 22 | /* |
robodude666 | 0:4395705c8647 | 23 | #define TC_CS_PORT &PORTB |
robodude666 | 0:4395705c8647 | 24 | #define TC_CS_PIN 4 |
robodude666 | 0:4395705c8647 | 25 | |
robodude666 | 0:4395705c8647 | 26 | #define TC_PEN_PORT &PORTB |
robodude666 | 0:4395705c8647 | 27 | #define TC_PEN_PINP PINB |
robodude666 | 0:4395705c8647 | 28 | #define TC_PEN_PIN 2 |
robodude666 | 0:4395705c8647 | 29 | |
robodude666 | 0:4395705c8647 | 30 | #define MOSI_PORT &PORTB |
robodude666 | 0:4395705c8647 | 31 | #define MOSI_PIN 5 |
robodude666 | 0:4395705c8647 | 32 | |
robodude666 | 0:4395705c8647 | 33 | #define SCK_PORT &PORTB |
robodude666 | 0:4395705c8647 | 34 | #define SCK_PIN 7 |
robodude666 | 0:4395705c8647 | 35 | */ |
robodude666 | 0:4395705c8647 | 36 | |
robodude666 | 0:4395705c8647 | 37 | //touch screen LCD configuration |
robodude666 | 0:4395705c8647 | 38 | //#define TS_ORN_PORTRAIT |
robodude666 | 0:4395705c8647 | 39 | |
robodude666 | 0:4395705c8647 | 40 | #ifdef TS_ORN_PORTRAIT |
robodude666 | 0:4395705c8647 | 41 | #define TS_SIZE_X 240 |
robodude666 | 0:4395705c8647 | 42 | #define TS_SIZE_Y 320 |
robodude666 | 0:4395705c8647 | 43 | #define TS_VAL_ENTRY_MOD 0x0030 |
robodude666 | 0:4395705c8647 | 44 | #define TS_INS_GRAM_ADX TS_INS_GRAM_HOR_AD |
robodude666 | 0:4395705c8647 | 45 | #define TS_INS_GRAM_ADY TS_INS_GRAM_VER_AD |
robodude666 | 0:4395705c8647 | 46 | #define TS_INS_START_ADX TS_INS_HOR_START_AD |
robodude666 | 0:4395705c8647 | 47 | #define TS_INS_END_ADX TS_INS_HOR_END_AD |
robodude666 | 0:4395705c8647 | 48 | #define TS_INS_START_ADY TS_INS_VER_START_AD |
robodude666 | 0:4395705c8647 | 49 | #define TS_INS_END_ADY TS_INS_VER_END_AD |
robodude666 | 0:4395705c8647 | 50 | #else |
robodude666 | 0:4395705c8647 | 51 | #define TS_SIZE_X 320 |
robodude666 | 0:4395705c8647 | 52 | #define TS_SIZE_Y 240 |
robodude666 | 0:4395705c8647 | 53 | #define TS_VAL_ENTRY_MOD 0x0028 |
robodude666 | 0:4395705c8647 | 54 | #define TS_INS_GRAM_ADX TS_INS_GRAM_VER_AD |
robodude666 | 0:4395705c8647 | 55 | #define TS_INS_GRAM_ADY TS_INS_GRAM_HOR_AD |
robodude666 | 0:4395705c8647 | 56 | #define TS_INS_START_ADX TS_INS_VER_START_AD |
robodude666 | 0:4395705c8647 | 57 | #define TS_INS_END_ADX TS_INS_VER_END_AD |
robodude666 | 0:4395705c8647 | 58 | #define TS_INS_START_ADY TS_INS_HOR_START_AD |
robodude666 | 0:4395705c8647 | 59 | #define TS_INS_END_ADY TS_INS_HOR_END_AD |
robodude666 | 0:4395705c8647 | 60 | #endif |
robodude666 | 0:4395705c8647 | 61 | |
robodude666 | 0:4395705c8647 | 62 | //pen status type definition |
robodude666 | 0:4395705c8647 | 63 | typedef enum |
robodude666 | 0:4395705c8647 | 64 | { |
robodude666 | 0:4395705c8647 | 65 | PST_NOTFOUND, |
robodude666 | 0:4395705c8647 | 66 | PST_DOWN, |
robodude666 | 0:4395705c8647 | 67 | PST_HOLD, |
robodude666 | 0:4395705c8647 | 68 | PST_UP |
robodude666 | 0:4395705c8647 | 69 | } pstatus_t; |
robodude666 | 0:4395705c8647 | 70 | |
robodude666 | 0:4395705c8647 | 71 | //#define so_pos_t short |
robodude666 | 0:4395705c8647 | 72 | |
robodude666 | 0:4395705c8647 | 73 | #ifndef so_pos_t |
robodude666 | 0:4395705c8647 | 74 | typedef short so_pos_t; |
robodude666 | 0:4395705c8647 | 75 | #endif |
robodude666 | 0:4395705c8647 | 76 | |
robodude666 | 0:4395705c8647 | 77 | ////// |
robodude666 | 0:4395705c8647 | 78 | |
robodude666 | 0:4395705c8647 | 79 | #define TS_INS_START_OSC 0x00 //data read at this instruction should be 0x0789 --> use for test connection |
robodude666 | 0:4395705c8647 | 80 | #define TS_INS_DRIV_OUT_CTRL 0x01 |
robodude666 | 0:4395705c8647 | 81 | #define TS_INS_DRIV_WAV_CTRL 0x02 |
robodude666 | 0:4395705c8647 | 82 | #define TS_INS_ENTRY_MOD 0x03 |
robodude666 | 0:4395705c8647 | 83 | #define TS_INS_RESIZE_CTRL 0x04 |
robodude666 | 0:4395705c8647 | 84 | #define TS_INS_DISP_CTRL1 0x07 |
robodude666 | 0:4395705c8647 | 85 | #define TS_INS_DISP_CTRL2 0x08 |
robodude666 | 0:4395705c8647 | 86 | #define TS_INS_DISP_CTRL3 0x09 |
robodude666 | 0:4395705c8647 | 87 | #define TS_INS_DISP_CTRL4 0x0A |
robodude666 | 0:4395705c8647 | 88 | #define TS_INS_RGB_DISP_IF_CTRL1 0x0C |
robodude666 | 0:4395705c8647 | 89 | #define TS_INS_FRM_MARKER_POS 0x0D |
robodude666 | 0:4395705c8647 | 90 | #define TS_INS_RGB_DISP_IF_CTRL2 0x0F |
robodude666 | 0:4395705c8647 | 91 | #define TS_INS_POW_CTRL1 0x10 |
robodude666 | 0:4395705c8647 | 92 | #define TS_INS_POW_CTRL2 0x11 |
robodude666 | 0:4395705c8647 | 93 | #define TS_INS_POW_CTRL3 0x12 |
robodude666 | 0:4395705c8647 | 94 | #define TS_INS_POW_CTRL4 0x13 |
robodude666 | 0:4395705c8647 | 95 | #define TS_INS_GRAM_HOR_AD 0x20 |
robodude666 | 0:4395705c8647 | 96 | #define TS_INS_GRAM_VER_AD 0x21 |
robodude666 | 0:4395705c8647 | 97 | #define TS_INS_RW_GRAM 0x22 |
robodude666 | 0:4395705c8647 | 98 | #define TS_INS_POW_CTRL7 0x29 |
robodude666 | 0:4395705c8647 | 99 | #define TS_INS_FRM_RATE_COL_CTRL 0x2B |
robodude666 | 0:4395705c8647 | 100 | #define TS_INS_GAMMA_CTRL1 0x30 |
robodude666 | 0:4395705c8647 | 101 | #define TS_INS_GAMMA_CTRL2 0x31 |
robodude666 | 0:4395705c8647 | 102 | #define TS_INS_GAMMA_CTRL3 0x32 |
robodude666 | 0:4395705c8647 | 103 | #define TS_INS_GAMMA_CTRL4 0x35 |
robodude666 | 0:4395705c8647 | 104 | #define TS_INS_GAMMA_CTRL5 0x36 |
robodude666 | 0:4395705c8647 | 105 | #define TS_INS_GAMMA_CTRL6 0x37 |
robodude666 | 0:4395705c8647 | 106 | #define TS_INS_GAMMA_CTRL7 0x38 |
robodude666 | 0:4395705c8647 | 107 | #define TS_INS_GAMMA_CTRL8 0x39 |
robodude666 | 0:4395705c8647 | 108 | #define TS_INS_GAMMA_CTRL9 0x3C |
robodude666 | 0:4395705c8647 | 109 | #define TS_INS_GAMMA_CTRL10 0x3D |
robodude666 | 0:4395705c8647 | 110 | #define TS_INS_HOR_START_AD 0x50 |
robodude666 | 0:4395705c8647 | 111 | #define TS_INS_HOR_END_AD 0x51 |
robodude666 | 0:4395705c8647 | 112 | #define TS_INS_VER_START_AD 0x52 |
robodude666 | 0:4395705c8647 | 113 | #define TS_INS_VER_END_AD 0x53 |
robodude666 | 0:4395705c8647 | 114 | #define TS_INS_GATE_SCAN_CTRL1 0x60 |
robodude666 | 0:4395705c8647 | 115 | #define TS_INS_GATE_SCAN_CTRL2 0x61 |
robodude666 | 0:4395705c8647 | 116 | #define TS_INS_GATE_SCAN_CTRL3 0x6A |
robodude666 | 0:4395705c8647 | 117 | #define TS_INS_PART_IMG1_DISP_POS 0x80 |
robodude666 | 0:4395705c8647 | 118 | #define TS_INS_PART_IMG1_START_AD 0x81 |
robodude666 | 0:4395705c8647 | 119 | #define TS_INS_PART_IMG1_END_AD 0x82 |
robodude666 | 0:4395705c8647 | 120 | #define TS_INS_PART_IMG2_DISP_POS 0x83 |
robodude666 | 0:4395705c8647 | 121 | #define TS_INS_PART_IMG2_START_AD 0x84 |
robodude666 | 0:4395705c8647 | 122 | #define TS_INS_PART_IMG2_END_AD 0x85 |
robodude666 | 0:4395705c8647 | 123 | #define TS_INS_PANEL_IF_CTRL1 0x90 |
robodude666 | 0:4395705c8647 | 124 | #define TS_INS_PANEL_IF_CTRL2 0x92 |
robodude666 | 0:4395705c8647 | 125 | #define TS_INS_PANEL_IF_CTRL3 0x93 |
robodude666 | 0:4395705c8647 | 126 | #define TS_INS_PANEL_IF_CTRL4 0x95 |
robodude666 | 0:4395705c8647 | 127 | #define TS_INS_PANEL_IF_CTRL5 0x97 |
robodude666 | 0:4395705c8647 | 128 | #define TS_INS_PANEL_IF_CTRL6 0x98 |
robodude666 | 0:4395705c8647 | 129 | |
robodude666 | 0:4395705c8647 | 130 | #define TS_COL_RED 0x001F |
robodude666 | 0:4395705c8647 | 131 | #define TS_COL_GREEN 0x07E0 |
robodude666 | 0:4395705c8647 | 132 | #define TS_COL_BLUE 0xF800 |
robodude666 | 0:4395705c8647 | 133 | #define TS_COL_YELLOW 0x07FF |
robodude666 | 0:4395705c8647 | 134 | #define TS_COL_PURPLE 0xF81F |
robodude666 | 0:4395705c8647 | 135 | #define TS_COL_BLACK 0x0000 |
robodude666 | 0:4395705c8647 | 136 | #define TS_COL_WHITE 0xFFFF |
robodude666 | 0:4395705c8647 | 137 | |
robodude666 | 0:4395705c8647 | 138 | #define ts_pos_t int |
robodude666 | 0:4395705c8647 | 139 | |
robodude666 | 0:4395705c8647 | 140 | typedef enum |
robodude666 | 0:4395705c8647 | 141 | { |
robodude666 | 0:4395705c8647 | 142 | TS_MODE_NORMAL, |
robodude666 | 0:4395705c8647 | 143 | TS_MODE_INVERSE, |
robodude666 | 0:4395705c8647 | 144 | TS_MODE_FULL, |
robodude666 | 0:4395705c8647 | 145 | } ts_mode_t; |
robodude666 | 0:4395705c8647 | 146 | |
robodude666 | 0:4395705c8647 | 147 | void TSLCDOutIns(unsigned short ins); //write instruction to LCD |
robodude666 | 0:4395705c8647 | 148 | void TSLCDOutDat(unsigned short dat); //write data to LCD |
robodude666 | 0:4395705c8647 | 149 | void TSLCDOutDat2(unsigned char dath,unsigned char datl); //write data to LCD |
robodude666 | 0:4395705c8647 | 150 | unsigned short TSLCDInIns(void); //read data from LCD |
robodude666 | 0:4395705c8647 | 151 | unsigned short TSLCDInDat(void); //read data from LCD |
robodude666 | 0:4395705c8647 | 152 | |
robodude666 | 0:4395705c8647 | 153 | void TSLCDRst(void); //pulse reset signal to LCD |
robodude666 | 0:4395705c8647 | 154 | void TSLCDInit(void); //initial LCD |
robodude666 | 0:4395705c8647 | 155 | void TSLCDShowPic2(ts_pos_t sx,ts_pos_t ex,ts_pos_t sy,ts_pos_t ey,const unsigned short *pic,ts_mode_t mode); |
robodude666 | 0:4395705c8647 | 156 | //show picture from code memory with specific size |
robodude666 | 0:4395705c8647 | 157 | void TSLCDFillRect(ts_pos_t sx,ts_pos_t ex,ts_pos_t sy,ts_pos_t ey,unsigned short color,ts_mode_t mode); //draw a rectangular |
robodude666 | 0:4395705c8647 | 158 | void TSLCDFillCirc(ts_pos_t cx,ts_pos_t cy,ts_pos_t rad,unsigned short color, ts_mode_t mode); //draw a circle |
robodude666 | 0:4395705c8647 | 159 | void TSLCDSetMargins(ts_pos_t xl,ts_pos_t xr,ts_pos_t yu,ts_pos_t yl); //set margins for FillRect,FillCirc |
robodude666 | 0:4395705c8647 | 160 | void TSLCDSetMarginsDefault(void); //reset margins to default value |
robodude666 | 0:4395705c8647 | 161 | |
robodude666 | 0:4395705c8647 | 162 | void TSLCDSetFontColor(unsigned short color); //set text's color |
robodude666 | 0:4395705c8647 | 163 | void TSLCDSetBackColor(unsigned short color); //set back color for TS_MODE_FULL |
robodude666 | 0:4395705c8647 | 164 | void TSLCDSetOffset(ts_pos_t x,ts_pos_t y); //set LCD offset for character display |
robodude666 | 0:4395705c8647 | 165 | void TSLCDPrintStr(unsigned char line,unsigned char column,char *str,ts_mode_t mode); //print string on LCD |
robodude666 | 0:4395705c8647 | 166 | void TSLCDPrintTxt(unsigned char line,unsigned char column,const char *txt,ts_mode_t mode); //print text from code memory |
robodude666 | 0:4395705c8647 | 167 | void TSLCDPrintCh(unsigned char line,unsigned char column,char c,ts_mode_t mode); //print a character on LCD |
robodude666 | 0:4395705c8647 | 168 | |
robodude666 | 0:4395705c8647 | 169 | |
robodude666 | 0:4395705c8647 | 170 | |
robodude666 | 0:4395705c8647 | 171 | #define FONT_BIT_WIDTH 8 |
robodude666 | 0:4395705c8647 | 172 | #define FONT_BYTE_HIGHT 2 |
robodude666 | 0:4395705c8647 | 173 | #define FONT_SIZE FONT_BIT_WIDTH*FONT_BYTE_HIGHT |
robodude666 | 0:4395705c8647 | 174 | |
robodude666 | 0:4395705c8647 | 175 | #define FONT_WIDTH FONT_BIT_WIDTH |
robodude666 | 0:4395705c8647 | 176 | #define FONT_HEIGHT FONT_BYTE_HIGHT*8 |
robodude666 | 0:4395705c8647 | 177 | |
robodude666 | 0:4395705c8647 | 178 | void TSLCDCharDisp(char charactor,ts_pos_t sx,ts_pos_t sy,ts_mode_t mode); //low level function to print a character on LCD |
robodude666 | 0:4395705c8647 | 179 | |
robodude666 | 0:4395705c8647 | 180 | unsigned char char_buf[FONT_BIT_WIDTH][FONT_BYTE_HIGHT]; |
robodude666 | 0:4395705c8647 | 181 | |
robodude666 | 0:4395705c8647 | 182 | void buf_store(unsigned char charactor); |
robodude666 | 0:4395705c8647 | 183 | |
robodude666 | 0:4395705c8647 | 184 | unsigned short font_color; |
robodude666 | 0:4395705c8647 | 185 | unsigned short back_color; |
robodude666 | 0:4395705c8647 | 186 | ts_pos_t offsetx, offsety; |
robodude666 | 0:4395705c8647 | 187 | ts_pos_t ts_margin_xl = 0; |
robodude666 | 0:4395705c8647 | 188 | ts_pos_t ts_margin_xr = TS_SIZE_X - 1; |
robodude666 | 0:4395705c8647 | 189 | ts_pos_t ts_margin_yu = 0; |
robodude666 | 0:4395705c8647 | 190 | ts_pos_t ts_margin_yl = TS_SIZE_Y - 1; |
robodude666 | 0:4395705c8647 | 191 | |
robodude666 | 0:4395705c8647 | 192 | #define TSLCDGetMarginXl() ts_margin_xl |
robodude666 | 0:4395705c8647 | 193 | #define TSLCDGetMarginXr() ts_margin_xr |
robodude666 | 0:4395705c8647 | 194 | #define TSLCDGetMarginYu() ts_margin_yu |
robodude666 | 0:4395705c8647 | 195 | #define TSLCDGetMarginYl() ts_margin_yl |
robodude666 | 0:4395705c8647 | 196 | |
robodude666 | 0:4395705c8647 | 197 | void TSLCDSetFontColor(unsigned short color) //set text's color |
robodude666 | 0:4395705c8647 | 198 | { |
robodude666 | 0:4395705c8647 | 199 | font_color = color; |
robodude666 | 0:4395705c8647 | 200 | } |
robodude666 | 0:4395705c8647 | 201 | |
robodude666 | 0:4395705c8647 | 202 | void TSLCDSetBackColor(unsigned short color) //set back color for TS_MODE_FULL |
robodude666 | 0:4395705c8647 | 203 | { |
robodude666 | 0:4395705c8647 | 204 | back_color = color; |
robodude666 | 0:4395705c8647 | 205 | } |
robodude666 | 0:4395705c8647 | 206 | |
robodude666 | 0:4395705c8647 | 207 | void TSLCDOutDat(unsigned short dat) //write data to LCD |
robodude666 | 0:4395705c8647 | 208 | { |
robodude666 | 0:4395705c8647 | 209 | lcd_rs.write(1); |
robodude666 | 0:4395705c8647 | 210 | |
robodude666 | 0:4395705c8647 | 211 | lcd_rd.write(1); |
robodude666 | 0:4395705c8647 | 212 | lcd_wr.write(0); |
robodude666 | 0:4395705c8647 | 213 | |
robodude666 | 0:4395705c8647 | 214 | lcd_db.output(); |
robodude666 | 0:4395705c8647 | 215 | |
robodude666 | 0:4395705c8647 | 216 | lcd_db = dat >> 8; |
robodude666 | 0:4395705c8647 | 217 | |
robodude666 | 0:4395705c8647 | 218 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 219 | lcd_cs.write(1); |
robodude666 | 0:4395705c8647 | 220 | |
robodude666 | 0:4395705c8647 | 221 | lcd_db = dat; |
robodude666 | 0:4395705c8647 | 222 | |
robodude666 | 0:4395705c8647 | 223 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 224 | lcd_cs.write(1); |
robodude666 | 0:4395705c8647 | 225 | |
robodude666 | 0:4395705c8647 | 226 | lcd_wr.write(1); |
robodude666 | 0:4395705c8647 | 227 | |
robodude666 | 0:4395705c8647 | 228 | lcd_db.input(); |
robodude666 | 0:4395705c8647 | 229 | } |
robodude666 | 0:4395705c8647 | 230 | |
robodude666 | 0:4395705c8647 | 231 | void TSLCDOutDat2(unsigned char dath,unsigned char datl) //write data to LCD |
robodude666 | 0:4395705c8647 | 232 | { |
robodude666 | 0:4395705c8647 | 233 | lcd_rs.write(1); |
robodude666 | 0:4395705c8647 | 234 | |
robodude666 | 0:4395705c8647 | 235 | lcd_rd.write(1); |
robodude666 | 0:4395705c8647 | 236 | lcd_wr.write(0); |
robodude666 | 0:4395705c8647 | 237 | |
robodude666 | 0:4395705c8647 | 238 | lcd_db.output(); |
robodude666 | 0:4395705c8647 | 239 | |
robodude666 | 0:4395705c8647 | 240 | lcd_db = dath; |
robodude666 | 0:4395705c8647 | 241 | |
robodude666 | 0:4395705c8647 | 242 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 243 | lcd_cs.write(1); |
robodude666 | 0:4395705c8647 | 244 | |
robodude666 | 0:4395705c8647 | 245 | lcd_db = datl; |
robodude666 | 0:4395705c8647 | 246 | |
robodude666 | 0:4395705c8647 | 247 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 248 | lcd_cs.write(1); |
robodude666 | 0:4395705c8647 | 249 | |
robodude666 | 0:4395705c8647 | 250 | lcd_wr.write(1); |
robodude666 | 0:4395705c8647 | 251 | |
robodude666 | 0:4395705c8647 | 252 | lcd_db.input(); |
robodude666 | 0:4395705c8647 | 253 | } |
robodude666 | 0:4395705c8647 | 254 | |
robodude666 | 0:4395705c8647 | 255 | void TSLCDOutIns(unsigned short ins) //write instruction to LCD |
robodude666 | 0:4395705c8647 | 256 | { |
robodude666 | 0:4395705c8647 | 257 | lcd_rs.write(0); |
robodude666 | 0:4395705c8647 | 258 | |
robodude666 | 0:4395705c8647 | 259 | lcd_rd.write(1); |
robodude666 | 0:4395705c8647 | 260 | lcd_wr.write(0); |
robodude666 | 0:4395705c8647 | 261 | |
robodude666 | 0:4395705c8647 | 262 | lcd_db.output(); |
robodude666 | 0:4395705c8647 | 263 | |
robodude666 | 0:4395705c8647 | 264 | lcd_db = ins >> 8; |
robodude666 | 0:4395705c8647 | 265 | |
robodude666 | 0:4395705c8647 | 266 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 267 | lcd_cs.write(1); |
robodude666 | 0:4395705c8647 | 268 | |
robodude666 | 0:4395705c8647 | 269 | lcd_db = ins; |
robodude666 | 0:4395705c8647 | 270 | |
robodude666 | 0:4395705c8647 | 271 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 272 | lcd_cs.write(1); |
robodude666 | 0:4395705c8647 | 273 | |
robodude666 | 0:4395705c8647 | 274 | lcd_wr.write(1); |
robodude666 | 0:4395705c8647 | 275 | |
robodude666 | 0:4395705c8647 | 276 | lcd_db.input(); |
robodude666 | 0:4395705c8647 | 277 | } |
robodude666 | 0:4395705c8647 | 278 | |
robodude666 | 0:4395705c8647 | 279 | unsigned short TSLCDInDat(void) //read data from LCD |
robodude666 | 0:4395705c8647 | 280 | { |
robodude666 | 0:4395705c8647 | 281 | unsigned short dat = 0; |
robodude666 | 0:4395705c8647 | 282 | |
robodude666 | 0:4395705c8647 | 283 | lcd_db.input(); |
robodude666 | 0:4395705c8647 | 284 | |
robodude666 | 0:4395705c8647 | 285 | lcd_rs.write(1); |
robodude666 | 0:4395705c8647 | 286 | |
robodude666 | 0:4395705c8647 | 287 | lcd_wr.write(1); |
robodude666 | 0:4395705c8647 | 288 | lcd_rd.write(0); |
robodude666 | 0:4395705c8647 | 289 | |
robodude666 | 0:4395705c8647 | 290 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 291 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 292 | dat = lcd_db; |
robodude666 | 0:4395705c8647 | 293 | lcd_cs.write(1); |
robodude666 | 0:4395705c8647 | 294 | |
robodude666 | 0:4395705c8647 | 295 | dat <<= 8; |
robodude666 | 0:4395705c8647 | 296 | |
robodude666 | 0:4395705c8647 | 297 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 298 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 299 | dat |= lcd_db; |
robodude666 | 0:4395705c8647 | 300 | lcd_cs.write(1); |
robodude666 | 0:4395705c8647 | 301 | |
robodude666 | 0:4395705c8647 | 302 | lcd_rd.write(1); |
robodude666 | 0:4395705c8647 | 303 | |
robodude666 | 0:4395705c8647 | 304 | return (dat); |
robodude666 | 0:4395705c8647 | 305 | } |
robodude666 | 0:4395705c8647 | 306 | |
robodude666 | 0:4395705c8647 | 307 | unsigned short TSLCDInIns(void) //read data from LCD |
robodude666 | 0:4395705c8647 | 308 | { |
robodude666 | 0:4395705c8647 | 309 | unsigned short ins = 0; |
robodude666 | 0:4395705c8647 | 310 | |
robodude666 | 0:4395705c8647 | 311 | lcd_db.input(); |
robodude666 | 0:4395705c8647 | 312 | |
robodude666 | 0:4395705c8647 | 313 | lcd_rs.write(0); |
robodude666 | 0:4395705c8647 | 314 | |
robodude666 | 0:4395705c8647 | 315 | lcd_wr.write(1); |
robodude666 | 0:4395705c8647 | 316 | lcd_rd.write(0); |
robodude666 | 0:4395705c8647 | 317 | |
robodude666 | 0:4395705c8647 | 318 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 319 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 320 | ins = lcd_db; |
robodude666 | 0:4395705c8647 | 321 | lcd_cs.write(1); |
robodude666 | 0:4395705c8647 | 322 | |
robodude666 | 0:4395705c8647 | 323 | ins <<= 8; |
robodude666 | 0:4395705c8647 | 324 | |
robodude666 | 0:4395705c8647 | 325 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 326 | lcd_cs.write(0); |
robodude666 | 0:4395705c8647 | 327 | ins |= lcd_db; |
robodude666 | 0:4395705c8647 | 328 | lcd_cs.write(1); |
robodude666 | 0:4395705c8647 | 329 | |
robodude666 | 0:4395705c8647 | 330 | lcd_rd.write(1); |
robodude666 | 0:4395705c8647 | 331 | |
robodude666 | 0:4395705c8647 | 332 | return (ins); |
robodude666 | 0:4395705c8647 | 333 | } |
robodude666 | 0:4395705c8647 | 334 | |
robodude666 | 0:4395705c8647 | 335 | void TSLCDRst(void) //pulse reset signal to LCD |
robodude666 | 0:4395705c8647 | 336 | { |
robodude666 | 0:4395705c8647 | 337 | lcd_rst.write(0); |
robodude666 | 0:4395705c8647 | 338 | wait_ms(50); |
robodude666 | 0:4395705c8647 | 339 | lcd_rst.write(1); |
robodude666 | 0:4395705c8647 | 340 | } |
robodude666 | 0:4395705c8647 | 341 | |
robodude666 | 0:4395705c8647 | 342 | void TSLCDInit(void) //initial LCD |
robodude666 | 0:4395705c8647 | 343 | { |
robodude666 | 0:4395705c8647 | 344 | wait_ms(100); |
robodude666 | 0:4395705c8647 | 345 | |
robodude666 | 0:4395705c8647 | 346 | TSLCDOutIns(0x00E5); |
robodude666 | 0:4395705c8647 | 347 | TSLCDOutDat(0x8000); //set the internal vcore voltage |
robodude666 | 0:4395705c8647 | 348 | TSLCDOutIns(TS_INS_START_OSC); |
robodude666 | 0:4395705c8647 | 349 | TSLCDOutDat(0x0001); //start oscillator |
robodude666 | 0:4395705c8647 | 350 | wait_ms(50); |
robodude666 | 0:4395705c8647 | 351 | |
robodude666 | 0:4395705c8647 | 352 | TSLCDOutIns(TS_INS_DRIV_OUT_CTRL); |
robodude666 | 0:4395705c8647 | 353 | TSLCDOutDat(0x0100); //set SS, SM |
robodude666 | 0:4395705c8647 | 354 | TSLCDOutIns(TS_INS_DRIV_WAV_CTRL); |
robodude666 | 0:4395705c8647 | 355 | TSLCDOutDat(0x0700); //set 1 line inversion |
robodude666 | 0:4395705c8647 | 356 | |
robodude666 | 0:4395705c8647 | 357 | TSLCDOutIns(TS_INS_ENTRY_MOD); |
robodude666 | 0:4395705c8647 | 358 | TSLCDOutDat(TS_VAL_ENTRY_MOD); //set GRAM write direction, BGR=0 |
robodude666 | 0:4395705c8647 | 359 | |
robodude666 | 0:4395705c8647 | 360 | TSLCDOutIns(TS_INS_RESIZE_CTRL); |
robodude666 | 0:4395705c8647 | 361 | TSLCDOutDat(0x0000); //no resizing |
robodude666 | 0:4395705c8647 | 362 | |
robodude666 | 0:4395705c8647 | 363 | TSLCDOutIns(TS_INS_DISP_CTRL2); |
robodude666 | 0:4395705c8647 | 364 | TSLCDOutDat(0x0202); //front & back porch periods = 2 |
robodude666 | 0:4395705c8647 | 365 | TSLCDOutIns(TS_INS_DISP_CTRL3); |
robodude666 | 0:4395705c8647 | 366 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 367 | TSLCDOutIns(TS_INS_DISP_CTRL4); |
robodude666 | 0:4395705c8647 | 368 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 369 | TSLCDOutIns(TS_INS_RGB_DISP_IF_CTRL1); |
robodude666 | 0:4395705c8647 | 370 | TSLCDOutDat(0x0000); //select system interface |
robodude666 | 0:4395705c8647 | 371 | TSLCDOutIns(TS_INS_FRM_MARKER_POS); |
robodude666 | 0:4395705c8647 | 372 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 373 | TSLCDOutIns(TS_INS_RGB_DISP_IF_CTRL2); |
robodude666 | 0:4395705c8647 | 374 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 375 | |
robodude666 | 0:4395705c8647 | 376 | TSLCDOutIns(TS_INS_POW_CTRL1); |
robodude666 | 0:4395705c8647 | 377 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 378 | TSLCDOutIns(TS_INS_POW_CTRL2); |
robodude666 | 0:4395705c8647 | 379 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 380 | TSLCDOutIns(TS_INS_POW_CTRL3); |
robodude666 | 0:4395705c8647 | 381 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 382 | TSLCDOutIns(TS_INS_POW_CTRL4); |
robodude666 | 0:4395705c8647 | 383 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 384 | wait_ms(200); |
robodude666 | 0:4395705c8647 | 385 | |
robodude666 | 0:4395705c8647 | 386 | TSLCDOutIns(TS_INS_POW_CTRL1); |
robodude666 | 0:4395705c8647 | 387 | TSLCDOutDat(0x17B0); |
robodude666 | 0:4395705c8647 | 388 | TSLCDOutIns(TS_INS_POW_CTRL2); |
robodude666 | 0:4395705c8647 | 389 | TSLCDOutDat(0x0137); |
robodude666 | 0:4395705c8647 | 390 | wait_ms(50); |
robodude666 | 0:4395705c8647 | 391 | |
robodude666 | 0:4395705c8647 | 392 | TSLCDOutIns(TS_INS_POW_CTRL3); |
robodude666 | 0:4395705c8647 | 393 | TSLCDOutDat(0x013C); |
robodude666 | 0:4395705c8647 | 394 | wait_ms(50); |
robodude666 | 0:4395705c8647 | 395 | |
robodude666 | 0:4395705c8647 | 396 | TSLCDOutIns(TS_INS_POW_CTRL4); |
robodude666 | 0:4395705c8647 | 397 | TSLCDOutDat(0x1400); |
robodude666 | 0:4395705c8647 | 398 | TSLCDOutIns(TS_INS_POW_CTRL7); |
robodude666 | 0:4395705c8647 | 399 | TSLCDOutDat(0x0007); |
robodude666 | 0:4395705c8647 | 400 | wait_ms(50); |
robodude666 | 0:4395705c8647 | 401 | |
robodude666 | 0:4395705c8647 | 402 | TSLCDOutIns(TS_INS_GRAM_HOR_AD); |
robodude666 | 0:4395705c8647 | 403 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 404 | TSLCDOutIns(TS_INS_GRAM_VER_AD); |
robodude666 | 0:4395705c8647 | 405 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 406 | |
robodude666 | 0:4395705c8647 | 407 | TSLCDOutIns(TS_INS_GAMMA_CTRL1); |
robodude666 | 0:4395705c8647 | 408 | TSLCDOutDat(0x0007); |
robodude666 | 0:4395705c8647 | 409 | TSLCDOutIns(TS_INS_GAMMA_CTRL2); |
robodude666 | 0:4395705c8647 | 410 | TSLCDOutDat(0x0504); |
robodude666 | 0:4395705c8647 | 411 | TSLCDOutIns(TS_INS_GAMMA_CTRL3); |
robodude666 | 0:4395705c8647 | 412 | TSLCDOutDat(0x0703); |
robodude666 | 0:4395705c8647 | 413 | TSLCDOutIns(TS_INS_GAMMA_CTRL4); |
robodude666 | 0:4395705c8647 | 414 | TSLCDOutDat(0x0002); |
robodude666 | 0:4395705c8647 | 415 | TSLCDOutIns(TS_INS_GAMMA_CTRL5); |
robodude666 | 0:4395705c8647 | 416 | TSLCDOutDat(0x0707); |
robodude666 | 0:4395705c8647 | 417 | TSLCDOutIns(TS_INS_GAMMA_CTRL6); |
robodude666 | 0:4395705c8647 | 418 | TSLCDOutDat(0x0406); |
robodude666 | 0:4395705c8647 | 419 | TSLCDOutIns(TS_INS_GAMMA_CTRL7); |
robodude666 | 0:4395705c8647 | 420 | TSLCDOutDat(0x0006); |
robodude666 | 0:4395705c8647 | 421 | TSLCDOutIns(TS_INS_GAMMA_CTRL8); |
robodude666 | 0:4395705c8647 | 422 | TSLCDOutDat(0x0404); |
robodude666 | 0:4395705c8647 | 423 | TSLCDOutIns(TS_INS_GAMMA_CTRL9); |
robodude666 | 0:4395705c8647 | 424 | TSLCDOutDat(0x0700); |
robodude666 | 0:4395705c8647 | 425 | TSLCDOutIns(TS_INS_GAMMA_CTRL10); |
robodude666 | 0:4395705c8647 | 426 | TSLCDOutDat(0x0A08); |
robodude666 | 0:4395705c8647 | 427 | |
robodude666 | 0:4395705c8647 | 428 | TSLCDOutIns(TS_INS_HOR_START_AD); |
robodude666 | 0:4395705c8647 | 429 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 430 | TSLCDOutIns(TS_INS_HOR_END_AD); |
robodude666 | 0:4395705c8647 | 431 | TSLCDOutDat(0x00EF); |
robodude666 | 0:4395705c8647 | 432 | TSLCDOutIns(TS_INS_VER_START_AD); |
robodude666 | 0:4395705c8647 | 433 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 434 | TSLCDOutIns(TS_INS_VER_END_AD); |
robodude666 | 0:4395705c8647 | 435 | TSLCDOutDat(0x013F); |
robodude666 | 0:4395705c8647 | 436 | TSLCDOutIns(TS_INS_GATE_SCAN_CTRL1); |
robodude666 | 0:4395705c8647 | 437 | TSLCDOutDat(0x2700); |
robodude666 | 0:4395705c8647 | 438 | TSLCDOutIns(TS_INS_GATE_SCAN_CTRL2); |
robodude666 | 0:4395705c8647 | 439 | TSLCDOutDat(0x0001); |
robodude666 | 0:4395705c8647 | 440 | TSLCDOutIns(TS_INS_GATE_SCAN_CTRL3); |
robodude666 | 0:4395705c8647 | 441 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 442 | |
robodude666 | 0:4395705c8647 | 443 | TSLCDOutIns(TS_INS_PART_IMG1_DISP_POS); |
robodude666 | 0:4395705c8647 | 444 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 445 | TSLCDOutIns(TS_INS_PART_IMG1_START_AD); |
robodude666 | 0:4395705c8647 | 446 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 447 | TSLCDOutIns(TS_INS_PART_IMG1_END_AD); |
robodude666 | 0:4395705c8647 | 448 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 449 | TSLCDOutIns(TS_INS_PART_IMG2_DISP_POS); |
robodude666 | 0:4395705c8647 | 450 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 451 | TSLCDOutIns(TS_INS_PART_IMG2_START_AD); |
robodude666 | 0:4395705c8647 | 452 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 453 | TSLCDOutIns(TS_INS_PART_IMG2_END_AD); |
robodude666 | 0:4395705c8647 | 454 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 455 | |
robodude666 | 0:4395705c8647 | 456 | TSLCDOutIns(TS_INS_PANEL_IF_CTRL1); |
robodude666 | 0:4395705c8647 | 457 | TSLCDOutDat(0x0010); |
robodude666 | 0:4395705c8647 | 458 | TSLCDOutIns(TS_INS_PANEL_IF_CTRL2); |
robodude666 | 0:4395705c8647 | 459 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 460 | TSLCDOutIns(TS_INS_PANEL_IF_CTRL3); |
robodude666 | 0:4395705c8647 | 461 | TSLCDOutDat(0x0003); |
robodude666 | 0:4395705c8647 | 462 | TSLCDOutIns(TS_INS_PANEL_IF_CTRL4); |
robodude666 | 0:4395705c8647 | 463 | TSLCDOutDat(0x0110); |
robodude666 | 0:4395705c8647 | 464 | TSLCDOutIns(TS_INS_PANEL_IF_CTRL5); |
robodude666 | 0:4395705c8647 | 465 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 466 | TSLCDOutIns(TS_INS_PANEL_IF_CTRL6); |
robodude666 | 0:4395705c8647 | 467 | TSLCDOutDat(0x0000); |
robodude666 | 0:4395705c8647 | 468 | |
robodude666 | 0:4395705c8647 | 469 | TSLCDOutIns(TS_INS_DISP_CTRL1); |
robodude666 | 0:4395705c8647 | 470 | TSLCDOutDat(0x0173); |
robodude666 | 0:4395705c8647 | 471 | } |
robodude666 | 0:4395705c8647 | 472 | |
robodude666 | 0:4395705c8647 | 473 | void TSLCDShowPic2(ts_pos_t sx,ts_pos_t ex,ts_pos_t sy,ts_pos_t ey,const unsigned short *pic,ts_mode_t mode) |
robodude666 | 0:4395705c8647 | 474 | //show picture from code memory with specific size |
robodude666 | 0:4395705c8647 | 475 | { |
robodude666 | 0:4395705c8647 | 476 | unsigned long k = 0; |
robodude666 | 0:4395705c8647 | 477 | unsigned short color; |
robodude666 | 0:4395705c8647 | 478 | unsigned int x,y; |
robodude666 | 0:4395705c8647 | 479 | unsigned int i,j; |
robodude666 | 0:4395705c8647 | 480 | if (sx < ts_margin_xl) |
robodude666 | 0:4395705c8647 | 481 | sx = ts_margin_xl; |
robodude666 | 0:4395705c8647 | 482 | if (ex > ts_margin_xr) |
robodude666 | 0:4395705c8647 | 483 | ex = ts_margin_xr; |
robodude666 | 0:4395705c8647 | 484 | if (sy < ts_margin_yu) |
robodude666 | 0:4395705c8647 | 485 | sy = ts_margin_yu; |
robodude666 | 0:4395705c8647 | 486 | if (ey > ts_margin_yl) |
robodude666 | 0:4395705c8647 | 487 | ey = ts_margin_yl; |
robodude666 | 0:4395705c8647 | 488 | |
robodude666 | 0:4395705c8647 | 489 | TSLCDOutIns(TS_INS_START_ADX); |
robodude666 | 0:4395705c8647 | 490 | TSLCDOutDat(sx); |
robodude666 | 0:4395705c8647 | 491 | TSLCDOutIns(TS_INS_END_ADX); |
robodude666 | 0:4395705c8647 | 492 | TSLCDOutDat(ex); |
robodude666 | 0:4395705c8647 | 493 | TSLCDOutIns(TS_INS_GRAM_ADX); |
robodude666 | 0:4395705c8647 | 494 | TSLCDOutDat(sx); |
robodude666 | 0:4395705c8647 | 495 | x = ex - sx + 1; |
robodude666 | 0:4395705c8647 | 496 | |
robodude666 | 0:4395705c8647 | 497 | #ifndef TS_ORN_PORTRAIT |
robodude666 | 0:4395705c8647 | 498 | sy = TS_SIZE_Y - 1 - sy; // mirror start y address |
robodude666 | 0:4395705c8647 | 499 | ey = TS_SIZE_Y - 1 - ey; // mirror end y address |
robodude666 | 0:4395705c8647 | 500 | TSLCDOutIns(TS_INS_START_ADY); |
robodude666 | 0:4395705c8647 | 501 | TSLCDOutDat(ey); |
robodude666 | 0:4395705c8647 | 502 | TSLCDOutIns(TS_INS_END_ADY); |
robodude666 | 0:4395705c8647 | 503 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 504 | TSLCDOutIns(TS_INS_GRAM_ADY); |
robodude666 | 0:4395705c8647 | 505 | TSLCDOutDat(sy);//fix from bug of v1_00 |
robodude666 | 0:4395705c8647 | 506 | y = sy - ey + 1; |
robodude666 | 0:4395705c8647 | 507 | #else |
robodude666 | 0:4395705c8647 | 508 | TSLCDOutIns(TS_INS_START_ADY); |
robodude666 | 0:4395705c8647 | 509 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 510 | TSLCDOutIns(TS_INS_END_ADY); |
robodude666 | 0:4395705c8647 | 511 | TSLCDOutDat(ey); |
robodude666 | 0:4395705c8647 | 512 | TSLCDOutIns(TS_INS_GRAM_ADY); |
robodude666 | 0:4395705c8647 | 513 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 514 | y = ey - sy + 1; |
robodude666 | 0:4395705c8647 | 515 | #endif |
robodude666 | 0:4395705c8647 | 516 | |
robodude666 | 0:4395705c8647 | 517 | TSLCDOutIns(TS_INS_RW_GRAM); |
robodude666 | 0:4395705c8647 | 518 | |
robodude666 | 0:4395705c8647 | 519 | if (mode == TS_MODE_FULL) |
robodude666 | 0:4395705c8647 | 520 | { |
robodude666 | 0:4395705c8647 | 521 | for (j=0; j<y; j++) |
robodude666 | 0:4395705c8647 | 522 | for (i=0; i<x; i++) |
robodude666 | 0:4395705c8647 | 523 | { |
robodude666 | 0:4395705c8647 | 524 | TSLCDOutDat(*(&pic[k])); |
robodude666 | 0:4395705c8647 | 525 | k++; |
robodude666 | 0:4395705c8647 | 526 | } |
robodude666 | 0:4395705c8647 | 527 | } |
robodude666 | 0:4395705c8647 | 528 | else |
robodude666 | 0:4395705c8647 | 529 | if (mode == TS_MODE_NORMAL) |
robodude666 | 0:4395705c8647 | 530 | { |
robodude666 | 0:4395705c8647 | 531 | for (j=0; j<y; j++) |
robodude666 | 0:4395705c8647 | 532 | for (i=0; i<x; i++) |
robodude666 | 0:4395705c8647 | 533 | { |
robodude666 | 0:4395705c8647 | 534 | if (*(&pic[k]) == TS_COL_WHITE) |
robodude666 | 0:4395705c8647 | 535 | { |
robodude666 | 0:4395705c8647 | 536 | color = TSLCDInDat(); // ignore invalid data |
robodude666 | 0:4395705c8647 | 537 | color = TSLCDInDat(); |
robodude666 | 0:4395705c8647 | 538 | TSLCDOutDat(color); |
robodude666 | 0:4395705c8647 | 539 | } |
robodude666 | 0:4395705c8647 | 540 | else |
robodude666 | 0:4395705c8647 | 541 | { |
robodude666 | 0:4395705c8647 | 542 | TSLCDOutDat(*(&pic[k])); |
robodude666 | 0:4395705c8647 | 543 | } |
robodude666 | 0:4395705c8647 | 544 | k++; |
robodude666 | 0:4395705c8647 | 545 | } |
robodude666 | 0:4395705c8647 | 546 | } |
robodude666 | 0:4395705c8647 | 547 | } |
robodude666 | 0:4395705c8647 | 548 | |
robodude666 | 0:4395705c8647 | 549 | void TSLCDFillRect(ts_pos_t sx,ts_pos_t ex,ts_pos_t sy,ts_pos_t ey,unsigned short color,ts_mode_t mode) //draw a rectangular |
robodude666 | 0:4395705c8647 | 550 | { |
robodude666 | 0:4395705c8647 | 551 | unsigned int x,y; |
robodude666 | 0:4395705c8647 | 552 | unsigned int i,j; |
robodude666 | 0:4395705c8647 | 553 | if (sx < ts_margin_xl) |
robodude666 | 0:4395705c8647 | 554 | sx = ts_margin_xl; |
robodude666 | 0:4395705c8647 | 555 | if (ex > ts_margin_xr) |
robodude666 | 0:4395705c8647 | 556 | ex = ts_margin_xr; |
robodude666 | 0:4395705c8647 | 557 | if (sy < ts_margin_yu) |
robodude666 | 0:4395705c8647 | 558 | sy = ts_margin_yu; |
robodude666 | 0:4395705c8647 | 559 | if (ey > ts_margin_yl) |
robodude666 | 0:4395705c8647 | 560 | ey = ts_margin_yl; |
robodude666 | 0:4395705c8647 | 561 | |
robodude666 | 0:4395705c8647 | 562 | TSLCDOutIns(TS_INS_START_ADX); |
robodude666 | 0:4395705c8647 | 563 | TSLCDOutDat(sx); |
robodude666 | 0:4395705c8647 | 564 | TSLCDOutIns(TS_INS_END_ADX); |
robodude666 | 0:4395705c8647 | 565 | TSLCDOutDat(ex); |
robodude666 | 0:4395705c8647 | 566 | TSLCDOutIns(TS_INS_GRAM_ADX); |
robodude666 | 0:4395705c8647 | 567 | TSLCDOutDat(sx); |
robodude666 | 0:4395705c8647 | 568 | x = ex - sx + 1; |
robodude666 | 0:4395705c8647 | 569 | |
robodude666 | 0:4395705c8647 | 570 | #ifndef TS_ORN_PORTRAIT |
robodude666 | 0:4395705c8647 | 571 | sy = TS_SIZE_Y - 1 - sy; // mirror start y address |
robodude666 | 0:4395705c8647 | 572 | ey = TS_SIZE_Y - 1 - ey; // mirror end y address |
robodude666 | 0:4395705c8647 | 573 | TSLCDOutIns(TS_INS_START_ADY); |
robodude666 | 0:4395705c8647 | 574 | TSLCDOutDat(ey); |
robodude666 | 0:4395705c8647 | 575 | TSLCDOutIns(TS_INS_END_ADY); |
robodude666 | 0:4395705c8647 | 576 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 577 | TSLCDOutIns(TS_INS_GRAM_ADY); |
robodude666 | 0:4395705c8647 | 578 | TSLCDOutDat(sy);//fix from bug of v1_00 |
robodude666 | 0:4395705c8647 | 579 | y = sy - ey + 1; |
robodude666 | 0:4395705c8647 | 580 | #else |
robodude666 | 0:4395705c8647 | 581 | TSLCDOutIns(TS_INS_START_ADY); |
robodude666 | 0:4395705c8647 | 582 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 583 | TSLCDOutIns(TS_INS_END_ADY); |
robodude666 | 0:4395705c8647 | 584 | TSLCDOutDat(ey); |
robodude666 | 0:4395705c8647 | 585 | TSLCDOutIns(TS_INS_GRAM_ADY); |
robodude666 | 0:4395705c8647 | 586 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 587 | y = ey - sy + 1; |
robodude666 | 0:4395705c8647 | 588 | #endif |
robodude666 | 0:4395705c8647 | 589 | |
robodude666 | 0:4395705c8647 | 590 | TSLCDOutIns(TS_INS_RW_GRAM); |
robodude666 | 0:4395705c8647 | 591 | |
robodude666 | 0:4395705c8647 | 592 | if ((mode == TS_MODE_NORMAL) || (mode == TS_MODE_FULL)) |
robodude666 | 0:4395705c8647 | 593 | { |
robodude666 | 0:4395705c8647 | 594 | for (j=0; j<y; j++) |
robodude666 | 0:4395705c8647 | 595 | for (i=0; i<x; i++) |
robodude666 | 0:4395705c8647 | 596 | { |
robodude666 | 0:4395705c8647 | 597 | TSLCDOutDat(color); |
robodude666 | 0:4395705c8647 | 598 | } |
robodude666 | 0:4395705c8647 | 599 | } |
robodude666 | 0:4395705c8647 | 600 | else |
robodude666 | 0:4395705c8647 | 601 | if (mode == TS_MODE_INVERSE) |
robodude666 | 0:4395705c8647 | 602 | { |
robodude666 | 0:4395705c8647 | 603 | for (j=0; j<y; j++) |
robodude666 | 0:4395705c8647 | 604 | for (i=0; i<x; i++) |
robodude666 | 0:4395705c8647 | 605 | { |
robodude666 | 0:4395705c8647 | 606 | color = TSLCDInDat(); // ignore invalid data |
robodude666 | 0:4395705c8647 | 607 | color = TSLCDInDat(); |
robodude666 | 0:4395705c8647 | 608 | TSLCDOutDat(~color); |
robodude666 | 0:4395705c8647 | 609 | } |
robodude666 | 0:4395705c8647 | 610 | } |
robodude666 | 0:4395705c8647 | 611 | } |
robodude666 | 0:4395705c8647 | 612 | |
robodude666 | 0:4395705c8647 | 613 | void TSLCDFillCirc(ts_pos_t cx,ts_pos_t cy,ts_pos_t rad,unsigned short color, ts_mode_t mode) //draw a circle |
robodude666 | 0:4395705c8647 | 614 | { |
robodude666 | 0:4395705c8647 | 615 | #ifndef TS_ORN_PORTRAIT |
robodude666 | 0:4395705c8647 | 616 | int sy_buf,ey_buf; |
robodude666 | 0:4395705c8647 | 617 | #endif |
robodude666 | 0:4395705c8647 | 618 | int sx,sy,ex,ey; |
robodude666 | 0:4395705c8647 | 619 | int i,j; |
robodude666 | 0:4395705c8647 | 620 | unsigned short color_buf; |
robodude666 | 0:4395705c8647 | 621 | unsigned short rad2 = rad*rad; |
robodude666 | 0:4395705c8647 | 622 | sx = cx - rad; |
robodude666 | 0:4395705c8647 | 623 | ex = cx + rad; |
robodude666 | 0:4395705c8647 | 624 | sy = cy - rad; |
robodude666 | 0:4395705c8647 | 625 | ey = cy + rad; |
robodude666 | 0:4395705c8647 | 626 | |
robodude666 | 0:4395705c8647 | 627 | if (sx < ts_margin_xl) |
robodude666 | 0:4395705c8647 | 628 | sx = ts_margin_xl; |
robodude666 | 0:4395705c8647 | 629 | if (ex > ts_margin_xr) |
robodude666 | 0:4395705c8647 | 630 | ex = ts_margin_xr; |
robodude666 | 0:4395705c8647 | 631 | if (sy < ts_margin_yu) |
robodude666 | 0:4395705c8647 | 632 | sy = ts_margin_yu; |
robodude666 | 0:4395705c8647 | 633 | if (ey > ts_margin_yl) |
robodude666 | 0:4395705c8647 | 634 | ey = ts_margin_yl; |
robodude666 | 0:4395705c8647 | 635 | |
robodude666 | 0:4395705c8647 | 636 | TSLCDOutIns(TS_INS_START_ADX); |
robodude666 | 0:4395705c8647 | 637 | TSLCDOutDat(sx); |
robodude666 | 0:4395705c8647 | 638 | TSLCDOutIns(TS_INS_END_ADX); |
robodude666 | 0:4395705c8647 | 639 | TSLCDOutDat(ex); |
robodude666 | 0:4395705c8647 | 640 | TSLCDOutIns(TS_INS_GRAM_ADX); |
robodude666 | 0:4395705c8647 | 641 | TSLCDOutDat(sx); |
robodude666 | 0:4395705c8647 | 642 | // x = ex - sx + 1; |
robodude666 | 0:4395705c8647 | 643 | |
robodude666 | 0:4395705c8647 | 644 | #ifndef TS_ORN_PORTRAIT |
robodude666 | 0:4395705c8647 | 645 | sy_buf = TS_SIZE_Y - 1 - sy; // mirror start y address |
robodude666 | 0:4395705c8647 | 646 | ey_buf = TS_SIZE_Y - 1 - ey; // mirror end y address |
robodude666 | 0:4395705c8647 | 647 | TSLCDOutIns(TS_INS_START_ADY); |
robodude666 | 0:4395705c8647 | 648 | TSLCDOutDat(ey_buf); |
robodude666 | 0:4395705c8647 | 649 | TSLCDOutIns(TS_INS_END_ADY); |
robodude666 | 0:4395705c8647 | 650 | TSLCDOutDat(sy_buf); |
robodude666 | 0:4395705c8647 | 651 | TSLCDOutIns(TS_INS_GRAM_ADY); |
robodude666 | 0:4395705c8647 | 652 | TSLCDOutDat(sy_buf);//fix from bug of v1_00 |
robodude666 | 0:4395705c8647 | 653 | // y = sy_buf - ey_buf + 1; |
robodude666 | 0:4395705c8647 | 654 | #else |
robodude666 | 0:4395705c8647 | 655 | TSLCDOutIns(TS_INS_START_ADY); |
robodude666 | 0:4395705c8647 | 656 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 657 | TSLCDOutIns(TS_INS_END_ADY); |
robodude666 | 0:4395705c8647 | 658 | TSLCDOutDat(ey); |
robodude666 | 0:4395705c8647 | 659 | TSLCDOutIns(TS_INS_GRAM_ADY); |
robodude666 | 0:4395705c8647 | 660 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 661 | // y = ey - sy + 1; |
robodude666 | 0:4395705c8647 | 662 | #endif |
robodude666 | 0:4395705c8647 | 663 | |
robodude666 | 0:4395705c8647 | 664 | TSLCDOutIns(TS_INS_RW_GRAM); |
robodude666 | 0:4395705c8647 | 665 | |
robodude666 | 0:4395705c8647 | 666 | if (mode == TS_MODE_NORMAL) |
robodude666 | 0:4395705c8647 | 667 | { |
robodude666 | 0:4395705c8647 | 668 | for (j=sy-cy; j<=ey-cy; j++) |
robodude666 | 0:4395705c8647 | 669 | for (i=sx-cx; i<=ex-cx; i++) |
robodude666 | 0:4395705c8647 | 670 | { |
robodude666 | 0:4395705c8647 | 671 | if ((i)*(i) + (j)*(j) < rad2) |
robodude666 | 0:4395705c8647 | 672 | { |
robodude666 | 0:4395705c8647 | 673 | TSLCDOutDat(color); |
robodude666 | 0:4395705c8647 | 674 | } |
robodude666 | 0:4395705c8647 | 675 | else |
robodude666 | 0:4395705c8647 | 676 | { |
robodude666 | 0:4395705c8647 | 677 | color_buf = TSLCDInDat(); // ignore invalid data |
robodude666 | 0:4395705c8647 | 678 | color_buf = TSLCDInDat(); |
robodude666 | 0:4395705c8647 | 679 | TSLCDOutDat(color_buf); |
robodude666 | 0:4395705c8647 | 680 | } |
robodude666 | 0:4395705c8647 | 681 | } |
robodude666 | 0:4395705c8647 | 682 | } |
robodude666 | 0:4395705c8647 | 683 | else |
robodude666 | 0:4395705c8647 | 684 | if (mode == TS_MODE_INVERSE) |
robodude666 | 0:4395705c8647 | 685 | { |
robodude666 | 0:4395705c8647 | 686 | for (j=sy-cy; j<=ey-cy; j++) |
robodude666 | 0:4395705c8647 | 687 | for (i=sx-cx; i<=ex-cx; i++) |
robodude666 | 0:4395705c8647 | 688 | { |
robodude666 | 0:4395705c8647 | 689 | if ((i)*(i) + (j)*(j) < rad2) |
robodude666 | 0:4395705c8647 | 690 | { |
robodude666 | 0:4395705c8647 | 691 | color_buf = TSLCDInDat(); // ignore invalid data |
robodude666 | 0:4395705c8647 | 692 | color_buf = TSLCDInDat(); |
robodude666 | 0:4395705c8647 | 693 | TSLCDOutDat(~color_buf); |
robodude666 | 0:4395705c8647 | 694 | } |
robodude666 | 0:4395705c8647 | 695 | else |
robodude666 | 0:4395705c8647 | 696 | { |
robodude666 | 0:4395705c8647 | 697 | color_buf = TSLCDInDat(); // ignore invalid data |
robodude666 | 0:4395705c8647 | 698 | color_buf = TSLCDInDat(); |
robodude666 | 0:4395705c8647 | 699 | TSLCDOutDat(color_buf); |
robodude666 | 0:4395705c8647 | 700 | } |
robodude666 | 0:4395705c8647 | 701 | } |
robodude666 | 0:4395705c8647 | 702 | } |
robodude666 | 0:4395705c8647 | 703 | else |
robodude666 | 0:4395705c8647 | 704 | if (mode == TS_MODE_FULL) |
robodude666 | 0:4395705c8647 | 705 | { |
robodude666 | 0:4395705c8647 | 706 | for (j=sy-cy; j<=ey-cy; j++) |
robodude666 | 0:4395705c8647 | 707 | for (i=sx-cx; i<=ex-cx; i++) |
robodude666 | 0:4395705c8647 | 708 | { |
robodude666 | 0:4395705c8647 | 709 | if ((i)*(i) + (j)*(j) < rad2) |
robodude666 | 0:4395705c8647 | 710 | { |
robodude666 | 0:4395705c8647 | 711 | TSLCDOutDat(color); |
robodude666 | 0:4395705c8647 | 712 | } |
robodude666 | 0:4395705c8647 | 713 | else |
robodude666 | 0:4395705c8647 | 714 | { |
robodude666 | 0:4395705c8647 | 715 | TSLCDOutDat(back_color); |
robodude666 | 0:4395705c8647 | 716 | } |
robodude666 | 0:4395705c8647 | 717 | } |
robodude666 | 0:4395705c8647 | 718 | } |
robodude666 | 0:4395705c8647 | 719 | } |
robodude666 | 0:4395705c8647 | 720 | |
robodude666 | 0:4395705c8647 | 721 | void TSLCDSetMargins(ts_pos_t xl,ts_pos_t xr,ts_pos_t yu,ts_pos_t yl) //set margins for FillRect,FillCirc |
robodude666 | 0:4395705c8647 | 722 | { |
robodude666 | 0:4395705c8647 | 723 | ts_margin_xl = xl; |
robodude666 | 0:4395705c8647 | 724 | ts_margin_xr = xr; |
robodude666 | 0:4395705c8647 | 725 | ts_margin_yu = yu; |
robodude666 | 0:4395705c8647 | 726 | ts_margin_yl = yl; |
robodude666 | 0:4395705c8647 | 727 | } |
robodude666 | 0:4395705c8647 | 728 | |
robodude666 | 0:4395705c8647 | 729 | void TSLCDSetMarginsDefault(void) //Reset margins to default value |
robodude666 | 0:4395705c8647 | 730 | { |
robodude666 | 0:4395705c8647 | 731 | ts_margin_xl = 0; |
robodude666 | 0:4395705c8647 | 732 | ts_margin_xr = TS_SIZE_X - 1; |
robodude666 | 0:4395705c8647 | 733 | ts_margin_yu = 0; |
robodude666 | 0:4395705c8647 | 734 | ts_margin_yl = TS_SIZE_Y - 1; |
robodude666 | 0:4395705c8647 | 735 | } |
robodude666 | 0:4395705c8647 | 736 | |
robodude666 | 0:4395705c8647 | 737 | void buf_store(unsigned char charactor) |
robodude666 | 0:4395705c8647 | 738 | { |
robodude666 | 0:4395705c8647 | 739 | unsigned char i,j; |
robodude666 | 0:4395705c8647 | 740 | int char_p = charactor*FONT_SIZE; |
robodude666 | 0:4395705c8647 | 741 | |
robodude666 | 0:4395705c8647 | 742 | for (i=0; i<FONT_BIT_WIDTH; i++) |
robodude666 | 0:4395705c8647 | 743 | for (j=0; j<FONT_BYTE_HIGHT; j++) |
robodude666 | 0:4395705c8647 | 744 | { |
robodude666 | 0:4395705c8647 | 745 | char_buf[i][j] = *(&font[char_p]); |
robodude666 | 0:4395705c8647 | 746 | char_p++; |
robodude666 | 0:4395705c8647 | 747 | } |
robodude666 | 0:4395705c8647 | 748 | } |
robodude666 | 0:4395705c8647 | 749 | |
robodude666 | 0:4395705c8647 | 750 | unsigned char buf_read(unsigned char column,unsigned char row) |
robodude666 | 0:4395705c8647 | 751 | { |
robodude666 | 0:4395705c8647 | 752 | unsigned char read_pixel; |
robodude666 | 0:4395705c8647 | 753 | |
robodude666 | 0:4395705c8647 | 754 | if (row < 8) |
robodude666 | 0:4395705c8647 | 755 | { |
robodude666 | 0:4395705c8647 | 756 | read_pixel = (char_buf[column][0] >> (7-row)) & 0x01; |
robodude666 | 0:4395705c8647 | 757 | } |
robodude666 | 0:4395705c8647 | 758 | else |
robodude666 | 0:4395705c8647 | 759 | { |
robodude666 | 0:4395705c8647 | 760 | row = row - 8; |
robodude666 | 0:4395705c8647 | 761 | read_pixel = (char_buf[column][1] >> (7-row)) & 0x01; |
robodude666 | 0:4395705c8647 | 762 | } |
robodude666 | 0:4395705c8647 | 763 | return (read_pixel); |
robodude666 | 0:4395705c8647 | 764 | } |
robodude666 | 0:4395705c8647 | 765 | |
robodude666 | 0:4395705c8647 | 766 | void TSLCDCharDisp(char charactor,ts_pos_t sx,ts_pos_t sy,ts_mode_t mode) //low level function to print a character on LCD |
robodude666 | 0:4395705c8647 | 767 | { |
robodude666 | 0:4395705c8647 | 768 | unsigned int x,y; |
robodude666 | 0:4395705c8647 | 769 | unsigned char i,j; |
robodude666 | 0:4395705c8647 | 770 | ts_pos_t ex,ey; |
robodude666 | 0:4395705c8647 | 771 | unsigned short c; |
robodude666 | 0:4395705c8647 | 772 | |
robodude666 | 0:4395705c8647 | 773 | ex = sx + FONT_WIDTH - 1; |
robodude666 | 0:4395705c8647 | 774 | ey = sy + FONT_HEIGHT - 1; |
robodude666 | 0:4395705c8647 | 775 | |
robodude666 | 0:4395705c8647 | 776 | buf_store(charactor - 0x20); |
robodude666 | 0:4395705c8647 | 777 | |
robodude666 | 0:4395705c8647 | 778 | TSLCDOutIns(TS_INS_START_ADX); |
robodude666 | 0:4395705c8647 | 779 | TSLCDOutDat(sx); |
robodude666 | 0:4395705c8647 | 780 | TSLCDOutIns(TS_INS_END_ADX); |
robodude666 | 0:4395705c8647 | 781 | TSLCDOutDat(ex); |
robodude666 | 0:4395705c8647 | 782 | TSLCDOutIns(TS_INS_GRAM_ADX); |
robodude666 | 0:4395705c8647 | 783 | TSLCDOutDat(sx); |
robodude666 | 0:4395705c8647 | 784 | x = ex - sx + 1; |
robodude666 | 0:4395705c8647 | 785 | |
robodude666 | 0:4395705c8647 | 786 | #ifndef TS_ORN_PORTRAIT |
robodude666 | 0:4395705c8647 | 787 | sy = TS_SIZE_Y - 1 - sy; // mirror start y address |
robodude666 | 0:4395705c8647 | 788 | ey = TS_SIZE_Y - 1 - ey; // mirror end y address |
robodude666 | 0:4395705c8647 | 789 | TSLCDOutIns(TS_INS_START_ADY); |
robodude666 | 0:4395705c8647 | 790 | TSLCDOutDat(ey); |
robodude666 | 0:4395705c8647 | 791 | TSLCDOutIns(TS_INS_END_ADY); |
robodude666 | 0:4395705c8647 | 792 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 793 | TSLCDOutIns(TS_INS_GRAM_ADY); |
robodude666 | 0:4395705c8647 | 794 | TSLCDOutDat(sy);//fix from bug of v1_00 |
robodude666 | 0:4395705c8647 | 795 | y = sy - ey + 1; |
robodude666 | 0:4395705c8647 | 796 | #else |
robodude666 | 0:4395705c8647 | 797 | TSLCDOutIns(TS_INS_START_ADY); |
robodude666 | 0:4395705c8647 | 798 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 799 | TSLCDOutIns(TS_INS_END_ADY); |
robodude666 | 0:4395705c8647 | 800 | TSLCDOutDat(ey); |
robodude666 | 0:4395705c8647 | 801 | TSLCDOutIns(TS_INS_GRAM_ADY); |
robodude666 | 0:4395705c8647 | 802 | TSLCDOutDat(sy); |
robodude666 | 0:4395705c8647 | 803 | y = ey - sy + 1; |
robodude666 | 0:4395705c8647 | 804 | #endif |
robodude666 | 0:4395705c8647 | 805 | |
robodude666 | 0:4395705c8647 | 806 | TSLCDOutIns(TS_INS_RW_GRAM); |
robodude666 | 0:4395705c8647 | 807 | |
robodude666 | 0:4395705c8647 | 808 | if (mode == TS_MODE_NORMAL) |
robodude666 | 0:4395705c8647 | 809 | { |
robodude666 | 0:4395705c8647 | 810 | for (j=y; j>0; j--) |
robodude666 | 0:4395705c8647 | 811 | for (i=0; i<x; i++) |
robodude666 | 0:4395705c8647 | 812 | { |
robodude666 | 0:4395705c8647 | 813 | if (buf_read(i,j)) |
robodude666 | 0:4395705c8647 | 814 | { |
robodude666 | 0:4395705c8647 | 815 | TSLCDOutDat(font_color); |
robodude666 | 0:4395705c8647 | 816 | } |
robodude666 | 0:4395705c8647 | 817 | else |
robodude666 | 0:4395705c8647 | 818 | { |
robodude666 | 0:4395705c8647 | 819 | c = TSLCDInDat(); // ignore invalid data |
robodude666 | 0:4395705c8647 | 820 | c = TSLCDInDat(); |
robodude666 | 0:4395705c8647 | 821 | TSLCDOutDat(c); |
robodude666 | 0:4395705c8647 | 822 | } |
robodude666 | 0:4395705c8647 | 823 | } |
robodude666 | 0:4395705c8647 | 824 | } |
robodude666 | 0:4395705c8647 | 825 | else |
robodude666 | 0:4395705c8647 | 826 | if (mode == TS_MODE_INVERSE) |
robodude666 | 0:4395705c8647 | 827 | { |
robodude666 | 0:4395705c8647 | 828 | for (j=0; j<y; j++) |
robodude666 | 0:4395705c8647 | 829 | for (i=0; i<x; i++) |
robodude666 | 0:4395705c8647 | 830 | { |
robodude666 | 0:4395705c8647 | 831 | c = TSLCDInDat(); // ignore invalid data |
robodude666 | 0:4395705c8647 | 832 | c = TSLCDInDat(); |
robodude666 | 0:4395705c8647 | 833 | if (buf_read(i,j)) |
robodude666 | 0:4395705c8647 | 834 | { |
robodude666 | 0:4395705c8647 | 835 | TSLCDOutDat(~c); |
robodude666 | 0:4395705c8647 | 836 | } |
robodude666 | 0:4395705c8647 | 837 | else |
robodude666 | 0:4395705c8647 | 838 | { |
robodude666 | 0:4395705c8647 | 839 | TSLCDOutDat(c); |
robodude666 | 0:4395705c8647 | 840 | } |
robodude666 | 0:4395705c8647 | 841 | } |
robodude666 | 0:4395705c8647 | 842 | } |
robodude666 | 0:4395705c8647 | 843 | else |
robodude666 | 0:4395705c8647 | 844 | if (mode == TS_MODE_FULL) |
robodude666 | 0:4395705c8647 | 845 | { |
robodude666 | 0:4395705c8647 | 846 | for (j=0; j<y; j++) |
robodude666 | 0:4395705c8647 | 847 | for (i=0; i<x; i++) |
robodude666 | 0:4395705c8647 | 848 | { |
robodude666 | 0:4395705c8647 | 849 | if (buf_read(i,j)) |
robodude666 | 0:4395705c8647 | 850 | { |
robodude666 | 0:4395705c8647 | 851 | TSLCDOutDat(font_color); |
robodude666 | 0:4395705c8647 | 852 | } |
robodude666 | 0:4395705c8647 | 853 | else |
robodude666 | 0:4395705c8647 | 854 | { |
robodude666 | 0:4395705c8647 | 855 | TSLCDOutDat(back_color); |
robodude666 | 0:4395705c8647 | 856 | } |
robodude666 | 0:4395705c8647 | 857 | } |
robodude666 | 0:4395705c8647 | 858 | } |
robodude666 | 0:4395705c8647 | 859 | } |
robodude666 | 0:4395705c8647 | 860 | |
robodude666 | 0:4395705c8647 | 861 | void TSLCDSetOffset(ts_pos_t x,ts_pos_t y) //set LCD offset for character display |
robodude666 | 0:4395705c8647 | 862 | { |
robodude666 | 0:4395705c8647 | 863 | offsetx = x; |
robodude666 | 0:4395705c8647 | 864 | offsety = y; |
robodude666 | 0:4395705c8647 | 865 | } |
robodude666 | 0:4395705c8647 | 866 | |
robodude666 | 0:4395705c8647 | 867 | void TSLCDPrintStr(unsigned char line,unsigned char column,char *str,ts_mode_t mode) //print string on LCD |
robodude666 | 0:4395705c8647 | 868 | { |
robodude666 | 0:4395705c8647 | 869 | int i = 0; |
robodude666 | 0:4395705c8647 | 870 | ts_pos_t posx,posy; |
robodude666 | 0:4395705c8647 | 871 | posx = offsetx + column*FONT_WIDTH; |
robodude666 | 0:4395705c8647 | 872 | posy = offsety + line*FONT_HEIGHT; |
robodude666 | 0:4395705c8647 | 873 | |
robodude666 | 0:4395705c8647 | 874 | while(str[i]) |
robodude666 | 0:4395705c8647 | 875 | { |
robodude666 | 0:4395705c8647 | 876 | TSLCDCharDisp(str[i],posx,posy,mode); |
robodude666 | 0:4395705c8647 | 877 | posx += FONT_WIDTH; |
robodude666 | 0:4395705c8647 | 878 | i++; |
robodude666 | 0:4395705c8647 | 879 | } |
robodude666 | 0:4395705c8647 | 880 | } |
robodude666 | 0:4395705c8647 | 881 | |
robodude666 | 0:4395705c8647 | 882 | void TSLCDPrintTxt(unsigned char line,unsigned char column,const char *txt,ts_mode_t mode) //print text from code memory |
robodude666 | 0:4395705c8647 | 883 | { |
robodude666 | 0:4395705c8647 | 884 | int i = 0; |
robodude666 | 0:4395705c8647 | 885 | ts_pos_t posx,posy; |
robodude666 | 0:4395705c8647 | 886 | posx = offsetx + column*FONT_WIDTH; |
robodude666 | 0:4395705c8647 | 887 | posy = offsety + line*FONT_HEIGHT; |
robodude666 | 0:4395705c8647 | 888 | |
robodude666 | 0:4395705c8647 | 889 | while((&txt[i])) |
robodude666 | 0:4395705c8647 | 890 | { |
robodude666 | 0:4395705c8647 | 891 | TSLCDCharDisp(*(&txt[i]),posx,posy,mode); |
robodude666 | 0:4395705c8647 | 892 | posx += FONT_WIDTH; |
robodude666 | 0:4395705c8647 | 893 | i++; |
robodude666 | 0:4395705c8647 | 894 | } |
robodude666 | 0:4395705c8647 | 895 | } |
robodude666 | 0:4395705c8647 | 896 | |
robodude666 | 0:4395705c8647 | 897 | void TSLCDPrintCh(unsigned char line,unsigned char column,char c,ts_mode_t mode) //print a character on LCD |
robodude666 | 0:4395705c8647 | 898 | { |
robodude666 | 0:4395705c8647 | 899 | ts_pos_t posx,posy; |
robodude666 | 0:4395705c8647 | 900 | posx = offsetx + column*FONT_WIDTH; |
robodude666 | 0:4395705c8647 | 901 | posy = offsety + line*FONT_HEIGHT; |
robodude666 | 0:4395705c8647 | 902 | |
robodude666 | 0:4395705c8647 | 903 | TSLCDCharDisp(c,posx,posy,mode); |
robodude666 | 0:4395705c8647 | 904 | } |
robodude666 | 0:4395705c8647 | 905 | ///// |
robodude666 | 0:4395705c8647 | 906 | |
robodude666 | 0:4395705c8647 | 907 | int main() { |
robodude666 | 0:4395705c8647 | 908 | |
robodude666 | 0:4395705c8647 | 909 | //setSystemFrequency(3, 1, 16, 1); |
robodude666 | 0:4395705c8647 | 910 | |
robodude666 | 0:4395705c8647 | 911 | // Do QVGA Setup Stuff |
robodude666 | 0:4395705c8647 | 912 | TSLCDRst(); |
robodude666 | 0:4395705c8647 | 913 | TSLCDInit(); |
robodude666 | 0:4395705c8647 | 914 | |
robodude666 | 0:4395705c8647 | 915 | wait_ms(100); |
robodude666 | 0:4395705c8647 | 916 | lcd_bl.write(1); |
robodude666 | 0:4395705c8647 | 917 | |
robodude666 | 0:4395705c8647 | 918 | TSLCDFillRect(0,TS_SIZE_X-1,0,TS_SIZE_Y-1,TS_COL_BLUE,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 919 | TSLCDFillRect(0,TS_SIZE_X-1,0,70,TS_COL_WHITE,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 920 | TSLCDSetFontColor(TS_COL_BLUE); |
robodude666 | 0:4395705c8647 | 921 | TSLCDPrintStr(2,6,"Testing ELT240320TP with AVR",TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 922 | TSLCDFillRect(20,80,90,130,TS_COL_BLACK,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 923 | TSLCDFillRect(30,90,100,140,TS_COL_YELLOW,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 924 | TSLCDFillRect(20,80,160,200,TS_COL_BLACK,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 925 | TSLCDFillRect(30,90,170,210,TS_COL_RED,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 926 | TSLCDFillRect(195,205,71,TS_SIZE_Y-1,TS_COL_WHITE,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 927 | TSLCDFillCirc(200,155,60,TS_COL_WHITE,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 928 | TSLCDFillCirc(200,155,50,TS_COL_BLUE,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 929 | TSLCDFillCirc(200,155,40,TS_COL_BLACK,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 930 | TSLCDFillCirc(200,155,30,TS_COL_RED,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 931 | |
robodude666 | 0:4395705c8647 | 932 | TSLCDFillRect(5, 15, 5, 15, TS_COL_GREEN,TS_MODE_NORMAL); |
robodude666 | 0:4395705c8647 | 933 | |
robodude666 | 0:4395705c8647 | 934 | while(1){} |
robodude666 | 0:4395705c8647 | 935 | } |