Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TS_DISCO_F746NG LCD_DISCO_F746NG BSP_DISCO_F746NG BUTTON_GROUP Arduino
main.cpp@5:19f1743cecb1, 2020-12-21 (annotated)
- Committer:
- MaxScorda
- Date:
- Mon Dec 21 00:57:41 2020 +0000
- Revision:
- 5:19f1743cecb1
- Parent:
- 4:0ce191d3f0ce
- Child:
- 6:ba00a5cd9466
start spaces
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| MaxScorda | 4:0ce191d3f0ce | 1 | //https://os.mbed.com/teams/ST/code/BSP_DISCO_F746NG/docs/tip/stm32746g__discovery__lcd_8c.html |
| sunsmile2015 | 0:f40a402e1725 | 2 | #include "mbed.h" |
| sunsmile2015 | 0:f40a402e1725 | 3 | #include "EthernetInterface.h" |
| MaxScorda | 2:65480fe798bf | 4 | |
| MaxScorda | 1:3fca41f3ed30 | 5 | #include "stm32746g_discovery_lcd.h" |
| MaxScorda | 1:3fca41f3ed30 | 6 | #include "stm32746g_discovery_ts.h" |
| MaxScorda | 1:3fca41f3ed30 | 7 | |
| MaxScorda | 3:e7e663758e6d | 8 | #include "button_group.hpp" |
| MaxScorda | 3:e7e663758e6d | 9 | using namespace ButGrp; |
| MaxScorda | 3:e7e663758e6d | 10 | TS_DISCO_F746NG ts_; |
| MaxScorda | 3:e7e663758e6d | 11 | LCD_DISCO_F746NG BSP_LCD_; |
| MaxScorda | 2:65480fe798bf | 12 | |
| MaxScorda | 1:3fca41f3ed30 | 13 | char str[255]; |
| MaxScorda | 1:3fca41f3ed30 | 14 | #define IP "192.168.1.175" |
| MaxScorda | 1:3fca41f3ed30 | 15 | #define GATEWAY "192.168.1.1" |
| MaxScorda | 1:3fca41f3ed30 | 16 | #define MASK "255.255.255.0" |
| sunsmile2015 | 0:f40a402e1725 | 17 | |
| MaxScorda | 3:e7e663758e6d | 18 | |
| sunsmile2015 | 0:f40a402e1725 | 19 | // Network interface |
| sunsmile2015 | 0:f40a402e1725 | 20 | EthernetInterface net; |
| sunsmile2015 | 0:f40a402e1725 | 21 | |
| MaxScorda | 1:3fca41f3ed30 | 22 | DigitalOut led1(LED1); |
| MaxScorda | 1:3fca41f3ed30 | 23 | InterruptIn button(USER_BUTTON); |
| MaxScorda | 3:e7e663758e6d | 24 | |
| MaxScorda | 3:e7e663758e6d | 25 | // |
| MaxScorda | 3:e7e663758e6d | 26 | // Setting of button group |
| MaxScorda | 5:19f1743cecb1 | 27 | |
| MaxScorda | 4:0ce191d3f0ce | 28 | const int DimX=BSP_LCD_GetXSize()-1; |
| MaxScorda | 4:0ce191d3f0ce | 29 | const int DimY=BSP_LCD_GetYSize()-1; |
| MaxScorda | 3:e7e663758e6d | 30 | |
| MaxScorda | 3:e7e663758e6d | 31 | const uint32_t BACK_COLOR = 0xFF006A6C; // teal green |
| MaxScorda | 3:e7e663758e6d | 32 | const uint32_t INACTIVE = BACK_COLOR & 0xE0FFFFFF; // color for inactive button |
| MaxScorda | 3:e7e663758e6d | 33 | const string STR[4] = {"Button1", "Button2", "Button3", "Button4"}; |
| MaxScorda | 5:19f1743cecb1 | 34 | ButtonGroup bGroup(BSP_LCD_, ts_, 10, 5, 66, 40, LCD_COLOR_BLUE, BACK_COLOR, 4, STR, 5, 5, 3); |
| MaxScorda | 3:e7e663758e6d | 35 | |
| MaxScorda | 3:e7e663758e6d | 36 | const string STR_SW[2] = {"ON", "OFF"}; |
| MaxScorda | 3:e7e663758e6d | 37 | ButtonGroup sw(BSP_LCD_, ts_, 10, 160, 66, 40, LCD_COLOR_GREEN, BACK_COLOR, 2, STR_SW, 5, 0, 2); |
| MaxScorda | 5:19f1743cecb1 | 38 | Button reset(BSP_LCD_, ts_, 410, 5, 60, 40, LCD_COLOR_BLUE, BACK_COLOR, "Reset", Font12); |
| MaxScorda | 3:e7e663758e6d | 39 | |
| MaxScorda | 3:e7e663758e6d | 40 | const string MULTI[2] = {"ON", "OFF"}; |
| MaxScorda | 5:19f1743cecb1 | 41 | ButtonGroup multiTouch(BSP_LCD_, ts_, 300, 5+100, 60, 40, LCD_COLOR_BLUE, BACK_COLOR, 2, MULTI, 5, 0, 2); |
| MaxScorda | 3:e7e663758e6d | 42 | // End of button group setting |
| MaxScorda | 3:e7e663758e6d | 43 | |
| MaxScorda | 3:e7e663758e6d | 44 | //Touch |
| MaxScorda | 3:e7e663758e6d | 45 | # define NUMLAYER 2 |
| MaxScorda | 3:e7e663758e6d | 46 | TS_StateTypeDef TS_State; |
| MaxScorda | 3:e7e663758e6d | 47 | uint8_t status; |
| MaxScorda | 3:e7e663758e6d | 48 | |
| MaxScorda | 2:65480fe798bf | 49 | #include "Functions.h" |
| MaxScorda | 1:3fca41f3ed30 | 50 | |
| sunsmile2015 | 0:f40a402e1725 | 51 | // Socket demo |
| MaxScorda | 1:3fca41f3ed30 | 52 | int main() |
| MaxScorda | 1:3fca41f3ed30 | 53 | { |
| MaxScorda | 3:e7e663758e6d | 54 | //Tasto |
| MaxScorda | 3:e7e663758e6d | 55 | button.rise(&PressButton); |
| MaxScorda | 1:3fca41f3ed30 | 56 | |
| MaxScorda | 2:65480fe798bf | 57 | //MILLIS |
| MaxScorda | 3:e7e663758e6d | 58 | // millisStart(); |
| MaxScorda | 1:3fca41f3ed30 | 59 | |
| MaxScorda | 5:19f1743cecb1 | 60 | // DISPLAY |
| MaxScorda | 1:3fca41f3ed30 | 61 | BSP_LCD_Init(); |
| MaxScorda | 3:e7e663758e6d | 62 | BSP_LCD_DisplayOn(); |
| MaxScorda | 3:e7e663758e6d | 63 | /* Initialize the LCD Layers */ |
| MaxScorda | 3:e7e663758e6d | 64 | BSP_LCD_LayerRgb565Init(0, LCD_FB_START_ADDRESS); |
| MaxScorda | 3:e7e663758e6d | 65 | BSP_LCD_LayerRgb565Init(1, LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*NUMLAYER)); //Reserve memory art SRAM acc. resolution and color format |
| MaxScorda | 3:e7e663758e6d | 66 | SetLayer( 0); |
| MaxScorda | 3:e7e663758e6d | 67 | // BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); |
| MaxScorda | 3:e7e663758e6d | 68 | // BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); |
| MaxScorda | 4:0ce191d3f0ce | 69 | BSP_LCD_Clear(LCD_COLOR_BLACK); |
| MaxScorda | 4:0ce191d3f0ce | 70 | BSP_LCD_SetBackColor(LCD_COLOR_BLACK); |
| MaxScorda | 4:0ce191d3f0ce | 71 | BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); |
| MaxScorda | 5:19f1743cecb1 | 72 | //frames |
| MaxScorda | 4:0ce191d3f0ce | 73 | BSP_LCD_DrawRect(0, 0, DimX/3, 40); |
| MaxScorda | 4:0ce191d3f0ce | 74 | BSP_LCD_DrawRect(DimX/3+5, 0, ((DimX*2)/3)-5, 40); |
| MaxScorda | 4:0ce191d3f0ce | 75 | BSP_LCD_DrawRect(40, 45, DimX-80, DimY-45-45); |
| MaxScorda | 4:0ce191d3f0ce | 76 | BSP_LCD_DrawRect(0, DimY-40, DimX, 40); |
| MaxScorda | 3:e7e663758e6d | 77 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
| MaxScorda | 5:19f1743cecb1 | 78 | BSP_LCD_.SetFont(&Font12); |
| MaxScorda | 5:19f1743cecb1 | 79 | BSP_LCD_DisplayStringAt(3, LINE(0), (uint8_t *)" Test All 0.2 ", LEFT_MODE); |
| MaxScorda | 1:3fca41f3ed30 | 80 | |
| MaxScorda | 3:e7e663758e6d | 81 | // touch |
| MaxScorda | 3:e7e663758e6d | 82 | status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); |
| MaxScorda | 4:0ce191d3f0ce | 83 | BSP_LCD_.SetFont(&Font12); |
| MaxScorda | 3:e7e663758e6d | 84 | if (status != TS_OK) { |
| MaxScorda | 5:19f1743cecb1 | 85 | BSP_LCD_DisplayStringAt(300, LINE(4), (uint8_t *)"TOUCHSCREEN INIT FAIL", LEFT_MODE); |
| MaxScorda | 3:e7e663758e6d | 86 | } else { |
| MaxScorda | 5:19f1743cecb1 | 87 | BSP_LCD_DisplayStringAt(300, LINE(4), (uint8_t *)"TOUCHSCREEN INIT OK", LEFT_MODE); |
| MaxScorda | 3:e7e663758e6d | 88 | } |
| MaxScorda | 5:19f1743cecb1 | 89 | Button::SetMultiTouch(false); |
| MaxScorda | 1:3fca41f3ed30 | 90 | |
| MaxScorda | 3:e7e663758e6d | 91 | // Buttons |
| MaxScorda | 3:e7e663758e6d | 92 | reset.Draw(INACTIVE, LCD_COLOR_GRAY); |
| MaxScorda | 3:e7e663758e6d | 93 | multiTouch.Draw(0, LCD_COLOR_DARKBLUE); |
| MaxScorda | 5:19f1743cecb1 | 94 | BSP_LCD_.DisplayStringAt(250, 5+80, (uint8_t *)"Multi-touch ON, OFF", LEFT_MODE); |
| MaxScorda | 3:e7e663758e6d | 95 | BSP_LCD_.SetFont(&Font20); |
| MaxScorda | 3:e7e663758e6d | 96 | BSP_LCD_.DisplayStringAt(120, 250, (uint8_t *)"02/22 22:36", LEFT_MODE); |
| MaxScorda | 3:e7e663758e6d | 97 | |
| MaxScorda | 3:e7e663758e6d | 98 | |
| MaxScorda | 3:e7e663758e6d | 99 | // ethernet interface |
| sunsmile2015 | 0:f40a402e1725 | 100 | printf("Ethernet socket example\n"); |
| MaxScorda | 1:3fca41f3ed30 | 101 | int i=net.set_network(IP,MASK,GATEWAY); |
| sunsmile2015 | 0:f40a402e1725 | 102 | net.connect(); |
| sunsmile2015 | 0:f40a402e1725 | 103 | |
| sunsmile2015 | 0:f40a402e1725 | 104 | // Show the network address |
| sunsmile2015 | 0:f40a402e1725 | 105 | const char *ip = net.get_ip_address(); |
| sunsmile2015 | 0:f40a402e1725 | 106 | const char *netmask = net.get_netmask(); |
| sunsmile2015 | 0:f40a402e1725 | 107 | const char *gateway = net.get_gateway(); |
| sunsmile2015 | 0:f40a402e1725 | 108 | printf("IP address: %s\n", ip ? ip : "None"); |
| sunsmile2015 | 0:f40a402e1725 | 109 | printf("Netmask: %s\n", netmask ? netmask : "None"); |
| sunsmile2015 | 0:f40a402e1725 | 110 | printf("Gateway: %s\n", gateway ? gateway : "None"); |
| sunsmile2015 | 0:f40a402e1725 | 111 | |
| sunsmile2015 | 0:f40a402e1725 | 112 | // Open a socket on the network interface, and create a TCP connection to mbed.org |
| sunsmile2015 | 0:f40a402e1725 | 113 | TCPSocket socket; |
| MaxScorda | 1:3fca41f3ed30 | 114 | |
| sunsmile2015 | 0:f40a402e1725 | 115 | socket.open(&net); |
| sunsmile2015 | 0:f40a402e1725 | 116 | socket.connect("api.ipify.org", 80); |
| sunsmile2015 | 0:f40a402e1725 | 117 | char *buffer = new char[256]; |
| sunsmile2015 | 0:f40a402e1725 | 118 | |
| sunsmile2015 | 0:f40a402e1725 | 119 | // Send an HTTP request |
| sunsmile2015 | 0:f40a402e1725 | 120 | strcpy(buffer, "GET / HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n"); |
| sunsmile2015 | 0:f40a402e1725 | 121 | int scount = socket.send(buffer, strlen(buffer)); |
| sunsmile2015 | 0:f40a402e1725 | 122 | printf("sent %d [%.*s]\n", scount, strstr(buffer, "\r\n")-buffer, buffer); |
| sunsmile2015 | 0:f40a402e1725 | 123 | |
| sunsmile2015 | 0:f40a402e1725 | 124 | // Recieve an HTTP response and print out the response line |
| sunsmile2015 | 0:f40a402e1725 | 125 | int rcount = socket.recv(buffer, 256); |
| sunsmile2015 | 0:f40a402e1725 | 126 | printf("recv %d [%.*s]\n", rcount, strstr(buffer, "\r\n")-buffer, buffer); |
| sunsmile2015 | 0:f40a402e1725 | 127 | |
| sunsmile2015 | 0:f40a402e1725 | 128 | // The api.ipify.org service also gives us the device's external IP address |
| sunsmile2015 | 0:f40a402e1725 | 129 | const char *payload = strstr(buffer, "\r\n\r\n")+4; |
| sunsmile2015 | 0:f40a402e1725 | 130 | printf("External IP address: %.*s\n", rcount-(payload-buffer), payload); |
| sunsmile2015 | 0:f40a402e1725 | 131 | |
| sunsmile2015 | 0:f40a402e1725 | 132 | // Close the socket to return its memory and bring down the network interface |
| sunsmile2015 | 0:f40a402e1725 | 133 | socket.close(); |
| sunsmile2015 | 0:f40a402e1725 | 134 | delete[] buffer; |
| sunsmile2015 | 0:f40a402e1725 | 135 | |
| sunsmile2015 | 0:f40a402e1725 | 136 | // Bring down the ethernet interface |
| sunsmile2015 | 0:f40a402e1725 | 137 | net.disconnect(); |
| sunsmile2015 | 0:f40a402e1725 | 138 | printf("Done\n"); |
| MaxScorda | 1:3fca41f3ed30 | 139 | |
| MaxScorda | 1:3fca41f3ed30 | 140 | |
| MaxScorda | 1:3fca41f3ed30 | 141 | |
| MaxScorda | 1:3fca41f3ed30 | 142 | while(1) { |
| MaxScorda | 3:e7e663758e6d | 143 | GestioneButton(); |
| MaxScorda | 3:e7e663758e6d | 144 | GestioneTouch(); |
| MaxScorda | 1:3fca41f3ed30 | 145 | } |
| sunsmile2015 | 0:f40a402e1725 | 146 | } |