![](/media/cache/profiles/20200518_163046.jpg.50x50_q85.jpg)
TFT supercomputer display simulation using emwin graphics library for PSoC6 pioneer kit
main.cpp@8:3d6af4ab3907, 2022-05-23 (annotated)
- Committer:
- reedas
- Date:
- Mon May 23 14:20:15 2022 +0000
- Revision:
- 8:3d6af4ab3907
- Parent:
- 7:db53b8fbac48
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
reedas | 2:ad262f2c84ca | 1 | /* Hello World! for the Emwin TFT Library */ |
reedas | 1:402b32a1025f | 2 | |
romilly | 0:6beb6f498640 | 3 | #include "mbed.h" |
reedas | 1:402b32a1025f | 4 | #include "GUI.h" |
reedas | 1:402b32a1025f | 5 | #include "cy8ckit_028_tft.h" |
reedas | 2:ad262f2c84ca | 6 | |
reedas | 4:d129442ea4dd | 7 | #define LED_DIAMETER (16) |
reedas | 4:d129442ea4dd | 8 | #define LED_RADIUS (LED_DIAMETER/2) |
reedas | 4:d129442ea4dd | 9 | #define DISPLAY_X (320) |
reedas | 4:d129442ea4dd | 10 | #define DISPLAY_Y (240) |
reedas | 4:d129442ea4dd | 11 | #define NUMLEDS_X (DISPLAY_X/LED_DIAMETER) |
reedas | 4:d129442ea4dd | 12 | #define NUMLEDS_Y (DISPLAY_Y/LED_DIAMETER) |
reedas | 4:d129442ea4dd | 13 | #define LED_OFF (0) |
reedas | 4:d129442ea4dd | 14 | #define LED_ON (1) |
reedas | 6:f546a5504ac0 | 15 | #define TITLE_OFFSET (16+LED_RADIUS) |
reedas | 6:f546a5504ac0 | 16 | #undef COLOURED_LEDS |
reedas | 8:3d6af4ab3907 | 17 | //#define RED_FADE 1 |
reedas | 8:3d6af4ab3907 | 18 | //#define GREEN_FADE 1 |
reedas | 8:3d6af4ab3907 | 19 | //#define BLUE_FADE 1 |
reedas | 1:402b32a1025f | 20 | |
reedas | 1:402b32a1025f | 21 | void Display_Init(void) |
reedas | 1:402b32a1025f | 22 | { |
reedas | 4:d129442ea4dd | 23 | /* Initialise EmWin driver*/ |
reedas | 4:d129442ea4dd | 24 | GUI_Init(); |
reedas | 1:402b32a1025f | 25 | |
reedas | 1:402b32a1025f | 26 | /* Set font size, foreground and background Colours */ |
reedas | 1:402b32a1025f | 27 | GUI_SetFont(GUI_FONT_16B_1); |
reedas | 1:402b32a1025f | 28 | GUI_SetColor(GUI_WHITE); |
reedas | 1:402b32a1025f | 29 | GUI_SetBkColor(GUI_BLACK); |
romilly | 0:6beb6f498640 | 30 | |
reedas | 1:402b32a1025f | 31 | /* Clear screen and print splash screen */ |
reedas | 1:402b32a1025f | 32 | GUI_Clear(); |
reedas | 1:402b32a1025f | 33 | GUI_SetTextAlign(GUI_TA_HCENTER); |
reedas | 5:024a2880721e | 34 | GUI_DispStringAt("CITY3032 Super Computer", 160, 0); |
reedas | 1:402b32a1025f | 35 | } |
reedas | 1:402b32a1025f | 36 | |
reedas | 1:402b32a1025f | 37 | int main() |
reedas | 1:402b32a1025f | 38 | { |
reedas | 1:402b32a1025f | 39 | /* Initialise display */ |
reedas | 1:402b32a1025f | 40 | Display_Init(); |
reedas | 2:ad262f2c84ca | 41 | |
reedas | 4:d129442ea4dd | 42 | printf("Starting Supercomputer\r\n"); |
reedas | 1:402b32a1025f | 43 | |
reedas | 1:402b32a1025f | 44 | GUI_SetFont(GUI_FONT_8X16X2X2); |
reedas | 8:3d6af4ab3907 | 45 | |
reedas | 8:3d6af4ab3907 | 46 | bool RED_FADE = 0; |
reedas | 8:3d6af4ab3907 | 47 | bool GREEN_FADE = 1; |
reedas | 8:3d6af4ab3907 | 48 | bool BLUE_FADE = 0; |
reedas | 6:f546a5504ac0 | 49 | uint32_t array[NUMLEDS_X][NUMLEDS_Y]; |
reedas | 8:3d6af4ab3907 | 50 | uint32_t shade; |
reedas | 8:3d6af4ab3907 | 51 | int32_t decrement = 0x41; |
reedas | 8:3d6af4ab3907 | 52 | |
reedas | 4:d129442ea4dd | 53 | for (int j=0; j < NUMLEDS_Y; j++) { |
reedas | 4:d129442ea4dd | 54 | for (int i=0; i < NUMLEDS_X; i++) { |
reedas | 8:3d6af4ab3907 | 55 | array[i][j]=(RED_FADE?0x04ff0000:0)|(GREEN_FADE?0x0200ff00:0)|(BLUE_FADE?0x010000ff:0); |
reedas | 8:3d6af4ab3907 | 56 | GUI_SetColor((array[i][j])&0x00ffffff); |
reedas | 4:d129442ea4dd | 57 | } |
reedas | 4:d129442ea4dd | 58 | } |
reedas | 2:ad262f2c84ca | 59 | while(1) { |
reedas | 4:d129442ea4dd | 60 | int ledx = rand()%NUMLEDS_X; |
reedas | 4:d129442ea4dd | 61 | int ledy = rand()%NUMLEDS_Y; |
reedas | 8:3d6af4ab3907 | 62 | |
reedas | 8:3d6af4ab3907 | 63 | if ((array[ledx][ledy])&0x04000000) { // dim Blue |
reedas | 8:3d6af4ab3907 | 64 | shade = ((array[ledx][ledy])>>16)&0xff; |
reedas | 8:3d6af4ab3907 | 65 | if (array[ledx][ledy]&0x08000000) shade = (shade + decrement) & 0xfc; |
reedas | 8:3d6af4ab3907 | 66 | else shade = (shade - decrement) & 0xfc; |
reedas | 8:3d6af4ab3907 | 67 | array[ledx][ledy]=(array[ledx][ledy])&0xff00ffff; |
reedas | 8:3d6af4ab3907 | 68 | shade = shade << 16; |
reedas | 8:3d6af4ab3907 | 69 | array[ledx][ledy] = shade + array[ledx][ledy]; |
reedas | 8:3d6af4ab3907 | 70 | } |
reedas | 8:3d6af4ab3907 | 71 | if ((array[ledx][ledy])&0x02000000) { // dim Green |
reedas | 8:3d6af4ab3907 | 72 | shade = ((array[ledx][ledy])>>8)&0xff; |
reedas | 8:3d6af4ab3907 | 73 | if (array[ledx][ledy]&0x08000000) shade = (shade + decrement) & 0xfc; |
reedas | 8:3d6af4ab3907 | 74 | else shade = (shade - decrement) & 0xfc; |
reedas | 8:3d6af4ab3907 | 75 | array[ledx][ledy]=(array[ledx][ledy])&0xffff00ff; |
reedas | 8:3d6af4ab3907 | 76 | shade = shade << 8; |
reedas | 8:3d6af4ab3907 | 77 | array[ledx][ledy] = (uint32_t)shade + (uint32_t)array[ledx][ledy]; |
reedas | 8:3d6af4ab3907 | 78 | } |
reedas | 8:3d6af4ab3907 | 79 | if ((array[ledx][ledy])&0x01000000) { // dim Red |
reedas | 8:3d6af4ab3907 | 80 | shade = (array[ledx][ledy])&0xff; |
reedas | 8:3d6af4ab3907 | 81 | if (array[ledx][ledy]&0x08000000) shade = (shade + decrement) & 0xfc; |
reedas | 8:3d6af4ab3907 | 82 | else shade = (shade - decrement) & 0xfc; |
reedas | 8:3d6af4ab3907 | 83 | array[ledx][ledy]=(array[ledx][ledy])&0xffffff00; |
reedas | 8:3d6af4ab3907 | 84 | array[ledx][ledy] = (array[ledx][ledy] + shade); |
reedas | 8:3d6af4ab3907 | 85 | } |
reedas | 8:3d6af4ab3907 | 86 | |
reedas | 8:3d6af4ab3907 | 87 | |
reedas | 8:3d6af4ab3907 | 88 | if ((array[ledx][ledy]&0x00ffffff)==0) { |
reedas | 8:3d6af4ab3907 | 89 | if ((array[ledx][ledy]&0x08000000)) array[ledx][ledy] = (array[ledx][ledy]^0x08000000); |
reedas | 8:3d6af4ab3907 | 90 | else array[ledx][ledy] = (array[ledx][ledy]^0x08000000)^((rand()%2)?0x04000000:0)^((rand()%2)?0x02000000:0)^((rand()%2)?0x01000000:0); |
reedas | 8:3d6af4ab3907 | 91 | // uint32_t currentColour =(RED_FADE?0x00ff0000:0)|(GREEN_FADE?0x0000ff00:0)|(BLUE_FADE?0x000000ff:0); |
reedas | 8:3d6af4ab3907 | 92 | // GUI_SetColor(currentColour); |
reedas | 8:3d6af4ab3907 | 93 | // GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS); |
reedas | 3:a14b2aa7546e | 94 | } |
reedas | 4:d129442ea4dd | 95 | else { |
reedas | 8:3d6af4ab3907 | 96 | shade = (array[ledx][ledy])&0x00ffffff; |
reedas | 8:3d6af4ab3907 | 97 | GUI_SetColor(shade); |
reedas | 4:d129442ea4dd | 98 | GUI_FillCircle(LED_RADIUS+(ledx)*LED_DIAMETER, TITLE_OFFSET+LED_DIAMETER*(ledy), LED_RADIUS); |
reedas | 8:3d6af4ab3907 | 99 | if ((ledx==0)&&(ledy==0)) |
reedas | 8:3d6af4ab3907 | 100 | printf("%08x\n", array[ledx][ledy]); |
reedas | 5:024a2880721e | 101 | |
reedas | 4:d129442ea4dd | 102 | } |
reedas | 2:ad262f2c84ca | 103 | } |
romilly | 0:6beb6f498640 | 104 | } |
reedas | 1:402b32a1025f | 105 | |
reedas | 1:402b32a1025f | 106 | |
reedas | 1:402b32a1025f | 107 |