SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.
Dependencies: TSI USBDevice mbed-dev
Fork of SmartWheels by
Hardwares/ArduUTFT.cpp@57:0d8a155d511d, 2017-04-08 (annotated)
- Committer:
- hazheng
- Date:
- Sat Apr 08 15:58:52 2017 +0000
- Revision:
- 57:0d8a155d511d
- Parent:
- 56:7d3395ae022d
- Child:
- 79:bdbac82c979b
move the image processing to the main thread. Created the debug counter.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hazheng | 40:be98219930e4 | 1 | #include "ArduUTFT.h" |
hazheng | 40:be98219930e4 | 2 | |
hazheng | 57:0d8a155d511d | 3 | //#define SW_DEBUG |
hazheng | 40:be98219930e4 | 4 | #include "GlobalVariable.h" |
hazheng | 56:7d3395ae022d | 5 | |
hazheng | 40:be98219930e4 | 6 | #include "SWUSBServer.h" |
hazheng | 42:c4e1606087ff | 7 | #include "ArduUTFTFont.h" |
hazheng | 40:be98219930e4 | 8 | |
hazheng | 40:be98219930e4 | 9 | extern SPI g_spi_port; |
hazheng | 40:be98219930e4 | 10 | |
hazheng | 40:be98219930e4 | 11 | #define UTFT_DISP_TRANS_MODE 8 |
hazheng | 40:be98219930e4 | 12 | |
hazheng | 40:be98219930e4 | 13 | |
hazheng | 40:be98219930e4 | 14 | #define swap(type, i, j) {type t = i; i = j; j = t;} |
hazheng | 40:be98219930e4 | 15 | |
hazheng | 40:be98219930e4 | 16 | |
hazheng | 46:a5eb9bd3bb55 | 17 | #ifdef __cplusplus |
hazheng | 46:a5eb9bd3bb55 | 18 | extern "C" { |
hazheng | 46:a5eb9bd3bb55 | 19 | #endif |
hazheng | 46:a5eb9bd3bb55 | 20 | |
hazheng | 40:be98219930e4 | 21 | |
hazheng | 46:a5eb9bd3bb55 | 22 | static uint8_t * current_font = NULL; |
hazheng | 46:a5eb9bd3bb55 | 23 | static uint8_t font_x_size = 0; |
hazheng | 46:a5eb9bd3bb55 | 24 | static uint8_t font_y_size = 0; |
hazheng | 46:a5eb9bd3bb55 | 25 | static uint8_t font_offset = 0; |
hazheng | 46:a5eb9bd3bb55 | 26 | //static uint8_t font_numchars = 0; |
hazheng | 46:a5eb9bd3bb55 | 27 | |
hazheng | 46:a5eb9bd3bb55 | 28 | static uint8_t front_color_high = 0; |
hazheng | 46:a5eb9bd3bb55 | 29 | static uint8_t front_color_low = 0; |
hazheng | 46:a5eb9bd3bb55 | 30 | |
hazheng | 46:a5eb9bd3bb55 | 31 | |
hazheng | 46:a5eb9bd3bb55 | 32 | static DigitalOut utft_cs(PIN_AUC_CS, 1); |
hazheng | 46:a5eb9bd3bb55 | 33 | static DigitalOut utft_sd_cs(PIN_AUC_SD_CS, 1); |
hazheng | 46:a5eb9bd3bb55 | 34 | static DigitalOut utft_touch_cs(PIN_AUC_TOUCH_CS, 1); |
hazheng | 41:7b21c5e3599e | 35 | |
hazheng | 40:be98219930e4 | 36 | inline void ardu_cam_spi_write_8(int address, int value) |
hazheng | 40:be98219930e4 | 37 | { |
hazheng | 56:7d3395ae022d | 38 | #ifdef SW_DEBUG |
hazheng | 56:7d3395ae022d | 39 | g_sw_spi_lock.lock(); |
hazheng | 56:7d3395ae022d | 40 | #endif |
hazheng | 40:be98219930e4 | 41 | utft_cs = 0; |
hazheng | 40:be98219930e4 | 42 | g_spi_port.write(address | 0x80); |
hazheng | 40:be98219930e4 | 43 | g_spi_port.write(value); |
hazheng | 40:be98219930e4 | 44 | utft_cs = 1; |
hazheng | 56:7d3395ae022d | 45 | #ifdef SW_DEBUG |
hazheng | 56:7d3395ae022d | 46 | g_sw_spi_lock.unlock(); |
hazheng | 56:7d3395ae022d | 47 | #endif |
hazheng | 40:be98219930e4 | 48 | } |
hazheng | 40:be98219930e4 | 49 | |
hazheng | 40:be98219930e4 | 50 | inline uint8_t ardu_cam_spi_read_8(int address) |
hazheng | 40:be98219930e4 | 51 | { |
hazheng | 56:7d3395ae022d | 52 | #ifdef SW_DEBUG |
hazheng | 56:7d3395ae022d | 53 | g_sw_spi_lock.lock(); |
hazheng | 56:7d3395ae022d | 54 | #endif |
hazheng | 40:be98219930e4 | 55 | utft_cs = 0; |
hazheng | 40:be98219930e4 | 56 | g_spi_port.write(address & 0x7F); |
hazheng | 40:be98219930e4 | 57 | uint8_t value = static_cast<uint8_t>(g_spi_port.write(0x00)); |
hazheng | 40:be98219930e4 | 58 | utft_cs = 1; |
hazheng | 56:7d3395ae022d | 59 | #ifdef SW_DEBUG |
hazheng | 56:7d3395ae022d | 60 | g_sw_spi_lock.unlock(); |
hazheng | 56:7d3395ae022d | 61 | #endif |
hazheng | 40:be98219930e4 | 62 | return value; |
hazheng | 40:be98219930e4 | 63 | } |
hazheng | 40:be98219930e4 | 64 | |
hazheng | 41:7b21c5e3599e | 65 | inline void ardu_utft_write_COM_internal(uint8_t VL) |
hazheng | 40:be98219930e4 | 66 | { |
hazheng | 56:7d3395ae022d | 67 | #ifdef SW_DEBUG |
hazheng | 56:7d3395ae022d | 68 | g_sw_spi_lock.lock(); |
hazheng | 56:7d3395ae022d | 69 | #endif |
hazheng | 40:be98219930e4 | 70 | utft_cs = 0; |
hazheng | 40:be98219930e4 | 71 | g_spi_port.write(0xBE); |
hazheng | 40:be98219930e4 | 72 | g_spi_port.write(VL); |
hazheng | 40:be98219930e4 | 73 | utft_cs = 1; |
hazheng | 56:7d3395ae022d | 74 | #ifdef SW_DEBUG |
hazheng | 56:7d3395ae022d | 75 | g_sw_spi_lock.unlock(); |
hazheng | 56:7d3395ae022d | 76 | #endif |
hazheng | 40:be98219930e4 | 77 | } |
hazheng | 40:be98219930e4 | 78 | |
hazheng | 41:7b21c5e3599e | 79 | inline void ardu_utft_write_DATA_internal(uint8_t VH, uint8_t VL) |
hazheng | 40:be98219930e4 | 80 | { |
hazheng | 56:7d3395ae022d | 81 | #ifdef SW_DEBUG |
hazheng | 56:7d3395ae022d | 82 | g_sw_spi_lock.lock(); |
hazheng | 56:7d3395ae022d | 83 | #endif |
hazheng | 40:be98219930e4 | 84 | utft_cs = 0; |
hazheng | 40:be98219930e4 | 85 | g_spi_port.write(0xBF); |
hazheng | 40:be98219930e4 | 86 | g_spi_port.write(VH); |
hazheng | 41:7b21c5e3599e | 87 | utft_cs = 1; |
hazheng | 41:7b21c5e3599e | 88 | utft_cs = 0; |
hazheng | 40:be98219930e4 | 89 | g_spi_port.write(0xBF); |
hazheng | 40:be98219930e4 | 90 | g_spi_port.write(VL); |
hazheng | 40:be98219930e4 | 91 | utft_cs = 1; |
hazheng | 56:7d3395ae022d | 92 | #ifdef SW_DEBUG |
hazheng | 56:7d3395ae022d | 93 | g_sw_spi_lock.unlock(); |
hazheng | 56:7d3395ae022d | 94 | #endif |
hazheng | 40:be98219930e4 | 95 | } |
hazheng | 40:be98219930e4 | 96 | |
hazheng | 41:7b21c5e3599e | 97 | inline void ardu_utft_write_COM_DATA_internal(uint8_t com1, uint16_t dat1) |
hazheng | 40:be98219930e4 | 98 | { |
hazheng | 41:7b21c5e3599e | 99 | ardu_utft_write_COM_internal(com1); |
hazheng | 41:7b21c5e3599e | 100 | ardu_utft_write_DATA_internal((dat1 >> 8) & 0xFF, dat1); |
hazheng | 41:7b21c5e3599e | 101 | } |
hazheng | 41:7b21c5e3599e | 102 | |
hazheng | 41:7b21c5e3599e | 103 | void ardu_utft_write_DATA(uint8_t VH, uint8_t VL) |
hazheng | 41:7b21c5e3599e | 104 | { |
hazheng | 41:7b21c5e3599e | 105 | ardu_utft_write_DATA_internal(VH, VL); |
hazheng | 40:be98219930e4 | 106 | } |
hazheng | 40:be98219930e4 | 107 | |
hazheng | 40:be98219930e4 | 108 | void ardu_utft_init() |
hazheng | 40:be98219930e4 | 109 | { |
Bobymicjohn | 54:f1f5648dfacf | 110 | //char buf[20]; |
hazheng | 40:be98219930e4 | 111 | uint8_t VerNum = ardu_cam_spi_read_8(0x40); |
hazheng | 40:be98219930e4 | 112 | VerNum = ardu_cam_spi_read_8(0x40); |
hazheng | 40:be98219930e4 | 113 | |
hazheng | 40:be98219930e4 | 114 | |
Bobymicjohn | 54:f1f5648dfacf | 115 | //sprintf(buf, "UTFT Ver %#x", VerNum); |
Bobymicjohn | 54:f1f5648dfacf | 116 | //g_core.GetUSBServer().PushReliableMsg('D', buf); |
hazheng | 40:be98219930e4 | 117 | |
hazheng | 40:be98219930e4 | 118 | ardu_cam_spi_write_8(ARDUCHIP_TEST1_UTFT, ARDUCHIP_TEST_MSG_UTFT); |
hazheng | 40:be98219930e4 | 119 | uint8_t testV = ardu_cam_spi_read_8(ARDUCHIP_TEST1_UTFT); |
hazheng | 40:be98219930e4 | 120 | if(VerNum != ARDUCHIP_VER_NUM_UTFT || testV != ARDUCHIP_TEST_MSG_UTFT) |
hazheng | 40:be98219930e4 | 121 | { |
Bobymicjohn | 54:f1f5648dfacf | 122 | //g_core.GetUSBServer().PushReliableMsg('D', "UTFTInit Fai"); |
hazheng | 40:be98219930e4 | 123 | } |
hazheng | 40:be98219930e4 | 124 | else |
hazheng | 40:be98219930e4 | 125 | { |
Bobymicjohn | 54:f1f5648dfacf | 126 | //g_core.GetUSBServer().PushReliableMsg('D', "UTFTInit Suc"); |
hazheng | 40:be98219930e4 | 127 | } |
hazheng | 40:be98219930e4 | 128 | |
hazheng | 40:be98219930e4 | 129 | ardu_cam_set_mode(MCU2LCD_MODE); |
hazheng | 41:7b21c5e3599e | 130 | ardu_utft_write_COM_DATA_internal(0x00,0x0001); |
hazheng | 41:7b21c5e3599e | 131 | ardu_utft_write_COM_DATA_internal(0x03,0xA8A4); |
hazheng | 41:7b21c5e3599e | 132 | ardu_utft_write_COM_DATA_internal(0x0C,0x0000); |
hazheng | 41:7b21c5e3599e | 133 | ardu_utft_write_COM_DATA_internal(0x0D,0x080C); |
hazheng | 41:7b21c5e3599e | 134 | ardu_utft_write_COM_DATA_internal(0x0E,0x2B00); |
hazheng | 41:7b21c5e3599e | 135 | ardu_utft_write_COM_DATA_internal(0x1E,0x00B7); |
hazheng | 41:7b21c5e3599e | 136 | ardu_utft_write_COM_DATA_internal(0x01,0x6B3F); //693F |
hazheng | 41:7b21c5e3599e | 137 | ardu_utft_write_COM_DATA_internal(0x02,0x0600); |
hazheng | 41:7b21c5e3599e | 138 | ardu_utft_write_COM_DATA_internal(0x10,0x0000); |
hazheng | 41:7b21c5e3599e | 139 | ardu_utft_write_COM_DATA_internal(0x11,0x6078); |
hazheng | 41:7b21c5e3599e | 140 | ardu_utft_write_COM_DATA_internal(0x05,0x0000); |
hazheng | 41:7b21c5e3599e | 141 | ardu_utft_write_COM_DATA_internal(0x06,0x0000); |
hazheng | 41:7b21c5e3599e | 142 | ardu_utft_write_COM_DATA_internal(0x16,0xEF1C); |
hazheng | 41:7b21c5e3599e | 143 | ardu_utft_write_COM_DATA_internal(0x17,0x0003); |
hazheng | 41:7b21c5e3599e | 144 | ardu_utft_write_COM_DATA_internal(0x07,0x0233); |
hazheng | 41:7b21c5e3599e | 145 | ardu_utft_write_COM_DATA_internal(0x0B,0x0000); |
hazheng | 41:7b21c5e3599e | 146 | ardu_utft_write_COM_DATA_internal(0x0F,0x0000); |
hazheng | 41:7b21c5e3599e | 147 | ardu_utft_write_COM_DATA_internal(0x41,0x0000); |
hazheng | 41:7b21c5e3599e | 148 | ardu_utft_write_COM_DATA_internal(0x42,0x0000); |
hazheng | 41:7b21c5e3599e | 149 | ardu_utft_write_COM_DATA_internal(0x48,0x0000); |
hazheng | 41:7b21c5e3599e | 150 | ardu_utft_write_COM_DATA_internal(0x49,0x013F); |
hazheng | 41:7b21c5e3599e | 151 | ardu_utft_write_COM_DATA_internal(0x4A,0x0000); |
hazheng | 41:7b21c5e3599e | 152 | ardu_utft_write_COM_DATA_internal(0x4B,0x0000); |
hazheng | 41:7b21c5e3599e | 153 | ardu_utft_write_COM_DATA_internal(0x44,0xEF00); |
hazheng | 41:7b21c5e3599e | 154 | ardu_utft_write_COM_DATA_internal(0x45,0x0000); |
hazheng | 41:7b21c5e3599e | 155 | ardu_utft_write_COM_DATA_internal(0x46,0x013F); |
hazheng | 41:7b21c5e3599e | 156 | ardu_utft_write_COM_DATA_internal(0x30,0x0707); |
hazheng | 41:7b21c5e3599e | 157 | ardu_utft_write_COM_DATA_internal(0x31,0x0204); |
hazheng | 41:7b21c5e3599e | 158 | ardu_utft_write_COM_DATA_internal(0x32,0x0204); |
hazheng | 41:7b21c5e3599e | 159 | ardu_utft_write_COM_DATA_internal(0x33,0x0502); |
hazheng | 41:7b21c5e3599e | 160 | ardu_utft_write_COM_DATA_internal(0x34,0x0507); |
hazheng | 41:7b21c5e3599e | 161 | ardu_utft_write_COM_DATA_internal(0x35,0x0204); |
hazheng | 41:7b21c5e3599e | 162 | ardu_utft_write_COM_DATA_internal(0x36,0x0204); |
hazheng | 41:7b21c5e3599e | 163 | ardu_utft_write_COM_DATA_internal(0x37,0x0502); |
hazheng | 41:7b21c5e3599e | 164 | ardu_utft_write_COM_DATA_internal(0x3A,0x0302); |
hazheng | 41:7b21c5e3599e | 165 | ardu_utft_write_COM_DATA_internal(0x3B,0x0302); |
hazheng | 41:7b21c5e3599e | 166 | ardu_utft_write_COM_DATA_internal(0x23,0x0000); |
hazheng | 41:7b21c5e3599e | 167 | ardu_utft_write_COM_DATA_internal(0x24,0x0000); |
hazheng | 41:7b21c5e3599e | 168 | ardu_utft_write_COM_DATA_internal(0x25,0x8000); |
hazheng | 41:7b21c5e3599e | 169 | ardu_utft_write_COM_DATA_internal(0x4f,0x0000); |
hazheng | 41:7b21c5e3599e | 170 | ardu_utft_write_COM_DATA_internal(0x4e,0x0000); |
hazheng | 41:7b21c5e3599e | 171 | ardu_utft_write_COM_internal(0x22); |
hazheng | 41:7b21c5e3599e | 172 | |
hazheng | 41:7b21c5e3599e | 173 | //ardu_cam_spi_write_8(0x03, 0x04); //////////////// |
hazheng | 41:7b21c5e3599e | 174 | |
hazheng | 40:be98219930e4 | 175 | //setColor(255, 255, 255); |
hazheng | 40:be98219930e4 | 176 | //setBackColor(0, 0, 0); |
hazheng | 42:c4e1606087ff | 177 | //current_font = NULL; |
hazheng | 42:c4e1606087ff | 178 | ardu_utft_set_font(SmallFont); |
hazheng | 40:be98219930e4 | 179 | ardu_utft_clr_scr(); |
hazheng | 40:be98219930e4 | 180 | |
hazheng | 42:c4e1606087ff | 181 | ardu_utft_set_color(0, 255, 255); |
hazheng | 42:c4e1606087ff | 182 | ardu_utft_fill_rect(10, 20, 120, 70); |
hazheng | 42:c4e1606087ff | 183 | ardu_utft_set_color(255, 255, 255); |
hazheng | 42:c4e1606087ff | 184 | ardu_utft_print("TEST", 70, 40); |
hazheng | 40:be98219930e4 | 185 | } |
hazheng | 40:be98219930e4 | 186 | |
hazheng | 40:be98219930e4 | 187 | void ardu_cam_set_mode(uint8_t mode) |
hazheng | 40:be98219930e4 | 188 | { |
hazheng | 40:be98219930e4 | 189 | ///////////////////////////////// |
hazheng | 40:be98219930e4 | 190 | //Careful here!! |
hazheng | 41:7b21c5e3599e | 191 | ardu_cam_spi_write_8(0x02, 0x00); |
hazheng | 41:7b21c5e3599e | 192 | |
hazheng | 40:be98219930e4 | 193 | } |
hazheng | 40:be98219930e4 | 194 | |
hazheng | 40:be98219930e4 | 195 | void ardu_utft_clr_scr() |
hazheng | 40:be98219930e4 | 196 | { |
hazheng | 40:be98219930e4 | 197 | ardu_utft_reset_xy(); |
hazheng | 40:be98219930e4 | 198 | |
hazheng | 40:be98219930e4 | 199 | long i; |
hazheng | 40:be98219930e4 | 200 | for (i = 0; i < ((UTFT_DISP_X_SIZE + 1) * (UTFT_DISP_Y_SIZE + 1)); ++i) |
hazheng | 40:be98219930e4 | 201 | { |
hazheng | 41:7b21c5e3599e | 202 | ardu_utft_write_DATA_internal(0x00,0x00); |
hazheng | 40:be98219930e4 | 203 | } |
hazheng | 40:be98219930e4 | 204 | } |
hazheng | 40:be98219930e4 | 205 | |
hazheng | 40:be98219930e4 | 206 | void ardu_utft_reset_xy() |
hazheng | 40:be98219930e4 | 207 | { |
hazheng | 40:be98219930e4 | 208 | ardu_utft_set_xy(0, 0, UTFT_DISP_Y_SIZE, UTFT_DISP_X_SIZE); |
hazheng | 40:be98219930e4 | 209 | } |
hazheng | 40:be98219930e4 | 210 | |
hazheng | 40:be98219930e4 | 211 | void ardu_utft_set_xy(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) |
hazheng | 40:be98219930e4 | 212 | { |
hazheng | 40:be98219930e4 | 213 | ///////////////////////////// |
hazheng | 40:be98219930e4 | 214 | //Possible to be simplified |
hazheng | 40:be98219930e4 | 215 | swap(uint16_t, x1, y1); |
hazheng | 40:be98219930e4 | 216 | swap(uint16_t, x2, y2); |
hazheng | 42:c4e1606087ff | 217 | //y1 = UTFT_DISP_Y_SIZE - y1; //319 - 0 = 319 |
hazheng | 42:c4e1606087ff | 218 | //y2 = UTFT_DISP_Y_SIZE - y2; //319 - 300 = 19 |
hazheng | 42:c4e1606087ff | 219 | //swap(uint16_t, y1, y2); //y1 = 19, y2 = 319 |
hazheng | 40:be98219930e4 | 220 | ///////////////////////////// |
hazheng | 40:be98219930e4 | 221 | |
hazheng | 41:7b21c5e3599e | 222 | ardu_utft_write_COM_DATA_internal(0x44, (x2 << 8) + x1); |
hazheng | 42:c4e1606087ff | 223 | ardu_utft_write_COM_DATA_internal(0x45, UTFT_DISP_Y_SIZE - y2); //19 |
hazheng | 42:c4e1606087ff | 224 | ardu_utft_write_COM_DATA_internal(0x46, UTFT_DISP_Y_SIZE - y1); //319 |
hazheng | 41:7b21c5e3599e | 225 | ardu_utft_write_COM_DATA_internal(0x4e, x1); |
hazheng | 42:c4e1606087ff | 226 | ardu_utft_write_COM_DATA_internal(0x4f, UTFT_DISP_Y_SIZE - y2); |
hazheng | 41:7b21c5e3599e | 227 | ardu_utft_write_COM_internal(0x22); |
hazheng | 40:be98219930e4 | 228 | } |
hazheng | 40:be98219930e4 | 229 | |
hazheng | 40:be98219930e4 | 230 | void ardu_utft_set_color(uint8_t r, uint8_t g, uint8_t b) |
hazheng | 40:be98219930e4 | 231 | { |
hazheng | 40:be98219930e4 | 232 | front_color_high = ((r & 248) | g >> 5); |
hazheng | 40:be98219930e4 | 233 | front_color_low = ((g & 28) << 3 | b >> 3); |
hazheng | 40:be98219930e4 | 234 | } |
hazheng | 40:be98219930e4 | 235 | |
hazheng | 40:be98219930e4 | 236 | void ardu_utft_draw_rect(int x1, int y1, int x2, int y2) |
hazheng | 40:be98219930e4 | 237 | { |
hazheng | 40:be98219930e4 | 238 | if (x1>x2) |
hazheng | 40:be98219930e4 | 239 | { |
hazheng | 40:be98219930e4 | 240 | swap(int, x1, x2); |
hazheng | 40:be98219930e4 | 241 | } |
hazheng | 40:be98219930e4 | 242 | if (y1>y2) |
hazheng | 40:be98219930e4 | 243 | { |
hazheng | 40:be98219930e4 | 244 | swap(int, y1, y2); |
hazheng | 40:be98219930e4 | 245 | } |
hazheng | 40:be98219930e4 | 246 | |
hazheng | 40:be98219930e4 | 247 | ardu_utft_draw_hline(x1, y1, x2 - x1); |
hazheng | 40:be98219930e4 | 248 | ardu_utft_draw_hline(x1, y2, x2 - x1); |
hazheng | 40:be98219930e4 | 249 | ardu_utft_draw_vline(x1, y1, y2 - y1); |
hazheng | 40:be98219930e4 | 250 | ardu_utft_draw_vline(x2, y1, y2 - y1); |
hazheng | 40:be98219930e4 | 251 | } |
hazheng | 40:be98219930e4 | 252 | |
hazheng | 40:be98219930e4 | 253 | void ardu_utft_draw_hline(int x, int y, int l) |
hazheng | 40:be98219930e4 | 254 | { |
hazheng | 40:be98219930e4 | 255 | if (l<0) |
hazheng | 40:be98219930e4 | 256 | { |
hazheng | 40:be98219930e4 | 257 | l = -l; |
hazheng | 40:be98219930e4 | 258 | x -= l; |
hazheng | 40:be98219930e4 | 259 | } |
hazheng | 40:be98219930e4 | 260 | |
hazheng | 40:be98219930e4 | 261 | ardu_utft_set_xy(x, y, x+l, y); |
hazheng | 40:be98219930e4 | 262 | |
hazheng | 40:be98219930e4 | 263 | for (int i = 0; i < l + 1; ++i) |
hazheng | 40:be98219930e4 | 264 | { |
hazheng | 41:7b21c5e3599e | 265 | ardu_utft_write_DATA_internal(front_color_high, front_color_low); |
hazheng | 40:be98219930e4 | 266 | } |
hazheng | 40:be98219930e4 | 267 | |
hazheng | 40:be98219930e4 | 268 | ardu_utft_reset_xy(); |
hazheng | 40:be98219930e4 | 269 | } |
hazheng | 40:be98219930e4 | 270 | |
hazheng | 40:be98219930e4 | 271 | void ardu_utft_draw_vline(int x, int y, int l) |
hazheng | 40:be98219930e4 | 272 | { |
hazheng | 40:be98219930e4 | 273 | if (l<0) |
hazheng | 40:be98219930e4 | 274 | { |
hazheng | 40:be98219930e4 | 275 | l = -l; |
hazheng | 40:be98219930e4 | 276 | y -= l; |
hazheng | 40:be98219930e4 | 277 | } |
hazheng | 40:be98219930e4 | 278 | |
hazheng | 40:be98219930e4 | 279 | ardu_utft_set_xy(x, y, x, y+l); |
hazheng | 40:be98219930e4 | 280 | |
hazheng | 40:be98219930e4 | 281 | for (int i = 0; i < l + 1; ++i) |
hazheng | 40:be98219930e4 | 282 | { |
hazheng | 41:7b21c5e3599e | 283 | ardu_utft_write_DATA_internal(front_color_high, front_color_low); |
hazheng | 40:be98219930e4 | 284 | } |
hazheng | 40:be98219930e4 | 285 | |
hazheng | 40:be98219930e4 | 286 | ardu_utft_reset_xy(); |
hazheng | 42:c4e1606087ff | 287 | } |
hazheng | 42:c4e1606087ff | 288 | |
hazheng | 42:c4e1606087ff | 289 | |
hazheng | 42:c4e1606087ff | 290 | void ardu_utft_draw_pixel(int x, int y) |
hazheng | 42:c4e1606087ff | 291 | { |
hazheng | 42:c4e1606087ff | 292 | ardu_utft_set_xy(x, y, x, y); |
hazheng | 42:c4e1606087ff | 293 | ardu_utft_write_DATA_internal(front_color_high, front_color_low); |
hazheng | 42:c4e1606087ff | 294 | ardu_utft_reset_xy(); |
hazheng | 42:c4e1606087ff | 295 | } |
hazheng | 42:c4e1606087ff | 296 | |
hazheng | 42:c4e1606087ff | 297 | void ardu_utft_fill_rect(int x1, int y1, int x2, int y2) |
hazheng | 42:c4e1606087ff | 298 | { |
hazheng | 42:c4e1606087ff | 299 | if (x1 > x2) |
hazheng | 42:c4e1606087ff | 300 | { |
hazheng | 42:c4e1606087ff | 301 | swap(int, x1, x2); |
hazheng | 42:c4e1606087ff | 302 | } |
hazheng | 42:c4e1606087ff | 303 | if (y1 > y2) |
hazheng | 42:c4e1606087ff | 304 | { |
hazheng | 42:c4e1606087ff | 305 | swap(int, y1, y2); |
hazheng | 42:c4e1606087ff | 306 | } |
hazheng | 42:c4e1606087ff | 307 | |
hazheng | 42:c4e1606087ff | 308 | for (int i = 0; i < ((x2 - x1) / 2) + 1; ++i) |
hazheng | 42:c4e1606087ff | 309 | { |
hazheng | 42:c4e1606087ff | 310 | ardu_utft_draw_vline(x1 + i, y1, y2 - y1); |
hazheng | 42:c4e1606087ff | 311 | ardu_utft_draw_vline(x2 - i, y1, y2 - y1); |
hazheng | 42:c4e1606087ff | 312 | } |
hazheng | 42:c4e1606087ff | 313 | } |
hazheng | 42:c4e1606087ff | 314 | |
hazheng | 42:c4e1606087ff | 315 | void ardu_utft_set_font(uint8_t * font) |
hazheng | 42:c4e1606087ff | 316 | { |
hazheng | 42:c4e1606087ff | 317 | current_font = font; |
hazheng | 42:c4e1606087ff | 318 | font_x_size = font[0]; |
hazheng | 42:c4e1606087ff | 319 | font_y_size = font[1]; |
hazheng | 42:c4e1606087ff | 320 | font_offset = font[2]; |
hazheng | 46:a5eb9bd3bb55 | 321 | //font_numchars = font[3]; |
hazheng | 42:c4e1606087ff | 322 | } |
hazheng | 42:c4e1606087ff | 323 | |
hazheng | 42:c4e1606087ff | 324 | void ardu_utft_print_char(char c, int x, int y) |
hazheng | 42:c4e1606087ff | 325 | { |
hazheng | 42:c4e1606087ff | 326 | char i, ch; |
hazheng | 42:c4e1606087ff | 327 | |
hazheng | 42:c4e1606087ff | 328 | uint16_t temp = ((c - font_offset) * ((font_x_size / 8) * font_y_size)) + 4; |
hazheng | 42:c4e1606087ff | 329 | |
hazheng | 42:c4e1606087ff | 330 | for(uint8_t j = 0; j < font_y_size; ++j) |
hazheng | 42:c4e1606087ff | 331 | { |
hazheng | 42:c4e1606087ff | 332 | for (int zz = 0; zz < (font_x_size / 8); ++zz) |
hazheng | 42:c4e1606087ff | 333 | { |
hazheng | 42:c4e1606087ff | 334 | ch = current_font[temp + zz]; |
hazheng | 42:c4e1606087ff | 335 | for(i = 0; i < 8; ++i) |
hazheng | 42:c4e1606087ff | 336 | { |
hazheng | 42:c4e1606087ff | 337 | ardu_utft_set_xy(x + i + (zz * 8), y + j, x + i + (zz * 8) + 1, y + j + 1); |
hazheng | 42:c4e1606087ff | 338 | |
hazheng | 42:c4e1606087ff | 339 | if((ch & (1 << i)) != 0) |
hazheng | 42:c4e1606087ff | 340 | { |
hazheng | 42:c4e1606087ff | 341 | ardu_utft_write_DATA_internal(front_color_high, front_color_low); |
hazheng | 56:7d3395ae022d | 342 | } |
hazheng | 56:7d3395ae022d | 343 | else |
hazheng | 56:7d3395ae022d | 344 | { |
hazheng | 56:7d3395ae022d | 345 | ardu_utft_write_DATA_internal(0x00, 0x00); |
hazheng | 56:7d3395ae022d | 346 | } |
hazheng | 42:c4e1606087ff | 347 | } |
hazheng | 42:c4e1606087ff | 348 | } |
hazheng | 42:c4e1606087ff | 349 | temp += (font_x_size / 8); |
hazheng | 42:c4e1606087ff | 350 | } |
hazheng | 42:c4e1606087ff | 351 | |
hazheng | 42:c4e1606087ff | 352 | ardu_utft_reset_xy(); |
hazheng | 42:c4e1606087ff | 353 | } |
hazheng | 42:c4e1606087ff | 354 | |
hazheng | 42:c4e1606087ff | 355 | void ardu_utft_print(char * st, int x, int y) |
hazheng | 42:c4e1606087ff | 356 | { |
hazheng | 42:c4e1606087ff | 357 | int stl, i; |
hazheng | 42:c4e1606087ff | 358 | stl = strlen(st); |
hazheng | 42:c4e1606087ff | 359 | |
hazheng | 42:c4e1606087ff | 360 | if (x == UTFT_RIGHT) |
hazheng | 42:c4e1606087ff | 361 | x = (UTFT_DISP_Y_SIZE + 1) - (stl * font_x_size); |
hazheng | 42:c4e1606087ff | 362 | if (x == UTFT_CENTER) |
hazheng | 42:c4e1606087ff | 363 | x = ((UTFT_DISP_Y_SIZE + 1) - (stl * font_x_size)) / 2; |
hazheng | 42:c4e1606087ff | 364 | |
hazheng | 42:c4e1606087ff | 365 | for (i = 0; i < stl; ++i) |
hazheng | 42:c4e1606087ff | 366 | ardu_utft_print_char(*st++, x - (i * (font_x_size)), y); |
hazheng | 46:a5eb9bd3bb55 | 367 | } |
hazheng | 46:a5eb9bd3bb55 | 368 | |
hazheng | 46:a5eb9bd3bb55 | 369 | #ifdef __cplusplus |
hazheng | 46:a5eb9bd3bb55 | 370 | } |
hazheng | 46:a5eb9bd3bb55 | 371 | #endif |