Droni e Droidi / Mbed OS F746NG_TestAll

Dependencies:   TS_DISCO_F746NG LCD_DISCO_F746NG BSP_DISCO_F746NG BUTTON_GROUP Arduino

Committer:
MaxScorda
Date:
Mon Dec 21 00:02:17 2020 +0000
Revision:
4:0ce191d3f0ce
Parent:
3:e7e663758e6d
Child:
5:19f1743cecb1
sub

Who changed what in which revision?

UserRevisionLine numberNew 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 3:e7e663758e6d 27 const int Y0 = 5;
MaxScorda 3:e7e663758e6d 28 const int X1 = 30;
MaxScorda 3:e7e663758e6d 29 const int Y1 = 100;
MaxScorda 4:0ce191d3f0ce 30 const int DimX=BSP_LCD_GetXSize()-1;
MaxScorda 4:0ce191d3f0ce 31 const int DimY=BSP_LCD_GetYSize()-1;
MaxScorda 3:e7e663758e6d 32
MaxScorda 3:e7e663758e6d 33 const uint32_t BACK_COLOR = 0xFF006A6C; // teal green
MaxScorda 3:e7e663758e6d 34 const uint32_t INACTIVE = BACK_COLOR & 0xE0FFFFFF; // color for inactive button
MaxScorda 3:e7e663758e6d 35 const string STR[4] = {"Button1", "Button2", "Button3", "Button4"};
MaxScorda 3:e7e663758e6d 36 ButtonGroup bGroup(BSP_LCD_, ts_, 10, Y0, 66, 40, LCD_COLOR_BLUE, BACK_COLOR, 4, STR, 5, 5, 3);
MaxScorda 3:e7e663758e6d 37
MaxScorda 3:e7e663758e6d 38 const string STR_SW[2] = {"ON", "OFF"};
MaxScorda 3:e7e663758e6d 39 ButtonGroup sw(BSP_LCD_, ts_, 10, 160, 66, 40, LCD_COLOR_GREEN, BACK_COLOR, 2, STR_SW, 5, 0, 2);
MaxScorda 3:e7e663758e6d 40 Button reset(BSP_LCD_, ts_, 410, Y0, 60, 40, LCD_COLOR_BLUE, BACK_COLOR, "Reset", Font12);
MaxScorda 3:e7e663758e6d 41
MaxScorda 3:e7e663758e6d 42
MaxScorda 3:e7e663758e6d 43 const string MULTI[2] = {"ON", "OFF"};
MaxScorda 3:e7e663758e6d 44 ButtonGroup multiTouch(BSP_LCD_, ts_, 300, Y0+100, 60, 40, LCD_COLOR_BLUE, BACK_COLOR, 2, MULTI, 5, 0, 2);
MaxScorda 3:e7e663758e6d 45 // End of button group setting
MaxScorda 3:e7e663758e6d 46
MaxScorda 3:e7e663758e6d 47 //Touch
MaxScorda 3:e7e663758e6d 48 # define NUMLAYER 2
MaxScorda 3:e7e663758e6d 49 TS_StateTypeDef TS_State;
MaxScorda 3:e7e663758e6d 50 uint8_t status;
MaxScorda 3:e7e663758e6d 51
MaxScorda 2:65480fe798bf 52 #include "Functions.h"
MaxScorda 1:3fca41f3ed30 53
sunsmile2015 0:f40a402e1725 54 // Socket demo
MaxScorda 1:3fca41f3ed30 55 int main()
MaxScorda 1:3fca41f3ed30 56 {
MaxScorda 3:e7e663758e6d 57 //Tasto
MaxScorda 3:e7e663758e6d 58 button.rise(&PressButton);
MaxScorda 1:3fca41f3ed30 59
MaxScorda 2:65480fe798bf 60 //MILLIS
MaxScorda 3:e7e663758e6d 61 // millisStart();
MaxScorda 1:3fca41f3ed30 62
MaxScorda 1:3fca41f3ed30 63 //display
MaxScorda 1:3fca41f3ed30 64 BSP_LCD_Init();
MaxScorda 3:e7e663758e6d 65 BSP_LCD_DisplayOn();
MaxScorda 3:e7e663758e6d 66 /* Initialize the LCD Layers */
MaxScorda 3:e7e663758e6d 67 BSP_LCD_LayerRgb565Init(0, LCD_FB_START_ADDRESS);
MaxScorda 3:e7e663758e6d 68 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 69 SetLayer( 0);
MaxScorda 3:e7e663758e6d 70 // BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
MaxScorda 3:e7e663758e6d 71 // BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
MaxScorda 4:0ce191d3f0ce 72 BSP_LCD_Clear(LCD_COLOR_BLACK);
MaxScorda 4:0ce191d3f0ce 73 BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
MaxScorda 4:0ce191d3f0ce 74 BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
MaxScorda 3:e7e663758e6d 75
MaxScorda 4:0ce191d3f0ce 76 BSP_LCD_DrawRect(0, 0, DimX/3, 40);
MaxScorda 4:0ce191d3f0ce 77 BSP_LCD_DrawRect(DimX/3+5, 0, ((DimX*2)/3)-5, 40);
MaxScorda 4:0ce191d3f0ce 78 BSP_LCD_DrawRect(40, 45, DimX-80, DimY-45-45);
MaxScorda 4:0ce191d3f0ce 79 BSP_LCD_DrawRect(0, DimY-40, DimX, 40);
MaxScorda 3:e7e663758e6d 80 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
MaxScorda 4:0ce191d3f0ce 81 BSP_LCD_.SetFont(&Font8);
MaxScorda 4:0ce191d3f0ce 82 BSP_LCD_DisplayStringAt(0, LINE(2), (uint8_t *)"Test All 0.2", LEFT_MODE);
MaxScorda 1:3fca41f3ed30 83
MaxScorda 3:e7e663758e6d 84 // touch
MaxScorda 3:e7e663758e6d 85 status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
MaxScorda 4:0ce191d3f0ce 86 BSP_LCD_.SetFont(&Font12);
MaxScorda 3:e7e663758e6d 87 if (status != TS_OK) {
MaxScorda 4:0ce191d3f0ce 88 BSP_LCD_DisplayStringAt(100, LINE(3), (uint8_t *)"TOUCHSCREEN INIT FAIL", LEFT_MODE);
MaxScorda 3:e7e663758e6d 89 } else {
MaxScorda 4:0ce191d3f0ce 90 BSP_LCD_DisplayStringAt(100, LINE(3), (uint8_t *)"TOUCHSCREEN INIT OK", LEFT_MODE);
MaxScorda 3:e7e663758e6d 91 }
MaxScorda 1:3fca41f3ed30 92
MaxScorda 3:e7e663758e6d 93 // Buttons
MaxScorda 3:e7e663758e6d 94 reset.Draw(INACTIVE, LCD_COLOR_GRAY);
MaxScorda 3:e7e663758e6d 95 multiTouch.Draw(0, LCD_COLOR_DARKBLUE);
MaxScorda 3:e7e663758e6d 96 BSP_LCD_.DisplayStringAt(250, Y0+80, (uint8_t *)"Multi-touch ON, OFF", LEFT_MODE);
MaxScorda 3:e7e663758e6d 97 BSP_LCD_.SetFont(&Font20);
MaxScorda 3:e7e663758e6d 98 BSP_LCD_.DisplayStringAt(120, 250, (uint8_t *)"02/22 22:36", LEFT_MODE);
MaxScorda 3:e7e663758e6d 99
MaxScorda 3:e7e663758e6d 100
MaxScorda 3:e7e663758e6d 101 // ethernet interface
sunsmile2015 0:f40a402e1725 102 printf("Ethernet socket example\n");
MaxScorda 1:3fca41f3ed30 103 int i=net.set_network(IP,MASK,GATEWAY);
sunsmile2015 0:f40a402e1725 104 net.connect();
sunsmile2015 0:f40a402e1725 105
sunsmile2015 0:f40a402e1725 106 // Show the network address
sunsmile2015 0:f40a402e1725 107 const char *ip = net.get_ip_address();
sunsmile2015 0:f40a402e1725 108 const char *netmask = net.get_netmask();
sunsmile2015 0:f40a402e1725 109 const char *gateway = net.get_gateway();
sunsmile2015 0:f40a402e1725 110 printf("IP address: %s\n", ip ? ip : "None");
sunsmile2015 0:f40a402e1725 111 printf("Netmask: %s\n", netmask ? netmask : "None");
sunsmile2015 0:f40a402e1725 112 printf("Gateway: %s\n", gateway ? gateway : "None");
sunsmile2015 0:f40a402e1725 113
sunsmile2015 0:f40a402e1725 114 // Open a socket on the network interface, and create a TCP connection to mbed.org
sunsmile2015 0:f40a402e1725 115 TCPSocket socket;
MaxScorda 1:3fca41f3ed30 116
sunsmile2015 0:f40a402e1725 117 socket.open(&net);
sunsmile2015 0:f40a402e1725 118 socket.connect("api.ipify.org", 80);
sunsmile2015 0:f40a402e1725 119 char *buffer = new char[256];
sunsmile2015 0:f40a402e1725 120
sunsmile2015 0:f40a402e1725 121 // Send an HTTP request
sunsmile2015 0:f40a402e1725 122 strcpy(buffer, "GET / HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n");
sunsmile2015 0:f40a402e1725 123 int scount = socket.send(buffer, strlen(buffer));
sunsmile2015 0:f40a402e1725 124 printf("sent %d [%.*s]\n", scount, strstr(buffer, "\r\n")-buffer, buffer);
sunsmile2015 0:f40a402e1725 125
sunsmile2015 0:f40a402e1725 126 // Recieve an HTTP response and print out the response line
sunsmile2015 0:f40a402e1725 127 int rcount = socket.recv(buffer, 256);
sunsmile2015 0:f40a402e1725 128 printf("recv %d [%.*s]\n", rcount, strstr(buffer, "\r\n")-buffer, buffer);
sunsmile2015 0:f40a402e1725 129
sunsmile2015 0:f40a402e1725 130 // The api.ipify.org service also gives us the device's external IP address
sunsmile2015 0:f40a402e1725 131 const char *payload = strstr(buffer, "\r\n\r\n")+4;
sunsmile2015 0:f40a402e1725 132 printf("External IP address: %.*s\n", rcount-(payload-buffer), payload);
sunsmile2015 0:f40a402e1725 133
sunsmile2015 0:f40a402e1725 134 // Close the socket to return its memory and bring down the network interface
sunsmile2015 0:f40a402e1725 135 socket.close();
sunsmile2015 0:f40a402e1725 136 delete[] buffer;
sunsmile2015 0:f40a402e1725 137
sunsmile2015 0:f40a402e1725 138 // Bring down the ethernet interface
sunsmile2015 0:f40a402e1725 139 net.disconnect();
sunsmile2015 0:f40a402e1725 140 printf("Done\n");
MaxScorda 1:3fca41f3ed30 141
MaxScorda 1:3fca41f3ed30 142
MaxScorda 1:3fca41f3ed30 143
MaxScorda 1:3fca41f3ed30 144 while(1) {
MaxScorda 3:e7e663758e6d 145 GestioneButton();
MaxScorda 3:e7e663758e6d 146 GestioneTouch();
MaxScorda 1:3fca41f3ed30 147 }
sunsmile2015 0:f40a402e1725 148 }