Facebook
From Bistre Madrill, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 194
  1.  
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * This notice applies to any and all portions of this file
  8.   * that are not between comment pairs USER CODE BEGIN and
  9.   * USER CODE END. Other portions of this file, whether
  10.   * inserted by the user or by software development tools
  11.   * are owned by their respective copyright owners.
  12.   *
  13.   * Copyright (c) 2018 STMicroelectronics International N.V.
  14.   * All rights reserved.
  15.   *
  16.   * Redistribution and use in source and binary forms, with or without
  17.   * modification, are permitted, provided that the following conditions are met:
  18.   *
  19.   * 1. Redistribution of source code must retain the above copyright notice,
  20.   *    this list of conditions and the following disclaimer.
  21.   * 2. Redistributions in binary form must reproduce the above copyright notice,
  22.   *    this list of conditions and the following disclaimer in the documentation
  23.   *    and/or other materials provided with the distribution.
  24.   * 3. Neither the name of STMicroelectronics nor the names of other
  25.   *    contributors to this software may be used to endorse or promote products
  26.   *    derived from this software without specific written permission.
  27.   * 4. This software, including modifications and/or derivative works of this
  28.   *    software, must execute solely and exclusively on microcontroller or
  29.   *    microprocessor devices manufactured by or for STMicroelectronics.
  30.   * 5. Redistribution and use of this software other than as permitted under
  31.   *    this license is void and will automatically terminate your rights under
  32.   *    this license.
  33.   *
  34.   * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  35.   * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  36.   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  37.   * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  38.   * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  39.   * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  40.   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  42.   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43.   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44.   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  45.   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46.   *
  47.   ******************************************************************************
  48.   */
  49. /* Includes ------------------------------------------------------------------*/
  50. #include "main.h"
  51. #include "stm32f7xx_hal.h"
  52. #include "cmsis_os.h"
  53. #include "lwip.h"
  54.  
  55. /* USER CODE BEGIN Includes */
  56. #include  <errno.h>
  57. #include  <sys/unistd.h>
  58.  
  59. #include "stm32746g_discovery_lcd.h"
  60. #include "Utilities/Fonts/fonts.h"
  61. #include "stm32746g_discovery_ts.h"
  62. #include "term_io.h"
  63. #include "dbgu.h"
  64. #include "ansi.h"
  65.  
  66. #include "FreeRTOS.h"
  67. #include "task.h"
  68. #include "queue.h"
  69.  
  70. #include "lwip/opt.h"
  71. #include "lwip/api.h"
  72. #include "lwip/apps/fs.h"
  73. #include "lwip/dhcp.h"
  74. #include "lwip/tcpip.h"
  75. #include "lwip/netdb.h"
  76. #include "lwip/sockets.h"
  77.  
  78. #include "lwip.h"
  79.  
  80. #include "wm8994/wm8994.h"
  81.  
  82. //
  83. #include "lwip/apps/mqtt.h"
  84.  
  85.  
  86. /* USER CODE END Includes */
  87.  
  88. /* Private variables ---------------------------------------------------------*/
  89. ADC_HandleTypeDef hadc3;
  90.  
  91. CRC_HandleTypeDef hcrc;
  92.  
  93. DCMI_HandleTypeDef hdcmi;
  94.  
  95. DMA2D_HandleTypeDef hdma2d;
  96.  
  97. I2C_HandleTypeDef hi2c1;
  98. I2C_HandleTypeDef hi2c3;
  99.  
  100. LTDC_HandleTypeDef hltdc;
  101.  
  102. QSPI_HandleTypeDef hqspi;
  103.  
  104. RTC_HandleTypeDef hrtc;
  105.  
  106. SAI_HandleTypeDef hsai_BlockA2;
  107. SAI_HandleTypeDef hsai_BlockB2;
  108.  
  109. SD_HandleTypeDef hsd1;
  110.  
  111. SPDIFRX_HandleTypeDef hspdif;
  112.  
  113. SPI_HandleTypeDef hspi2;
  114.  
  115. TIM_HandleTypeDef htim1;
  116. TIM_HandleTypeDef htim2;
  117. TIM_HandleTypeDef htim3;
  118. TIM_HandleTypeDef htim5;
  119. TIM_HandleTypeDef htim7;
  120. TIM_HandleTypeDef htim8;
  121. TIM_HandleTypeDef htim12;
  122.  
  123. UART_HandleTypeDef huart1;
  124. UART_HandleTypeDef huart6;
  125.  
  126. SDRAM_HandleTypeDef hsdram1;
  127.  
  128. osThreadId defaultTaskHandle;
  129.  
  130. /* USER CODE BEGIN PV */
  131. /* Private variables ---------------------------------------------------------*/
  132.  
  133. /* USER CODE END PV */
  134.  
  135. /* Private function prototypes -----------------------------------------------*/
  136. void SystemClock_Config(void);
  137. static void MX_GPIO_Init(void);
  138. static void MX_I2C1_Init(void);
  139. static void MX_USART1_UART_Init(void);
  140. static void MX_USART6_UART_Init(void);
  141. void StartDefaultTask(void const * argument);
  142.  
  143. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  144.  
  145.  
  146.  
  147.  
  148.  
  149. /* USER CODE BEGIN PFP */
  150. /* Private function prototypes -----------------------------------------------*/
  151.  
  152. /* USER CODE END PFP */
  153.  
  154. /* USER CODE BEGIN 0 */
  155. void mainTask(void* p);
  156.  
  157. osThreadId netconn_thread_handle;
  158.  
  159. #define LCD_X_SIZE                      RK043FN48H_WIDTH
  160. #define LCD_Y_SIZE                      RK043FN48H_HEIGHT
  161.  
  162. #define PRINTF_USES_HAL_TX              0
  163.  
  164. int __io_putchar(int ch)
  165. {
  166.         uint8_t data = ch;
  167.         #if PRINTF_USES_HAL_TX
  168.                 HAL_StatusTypeDef status = HAL_UART_Transmit(&huart1, (uint8_t*)&data, len, 100);
  169.         #else
  170.                 while(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TXE) == RESET) { ; }
  171.                 huart1.Instance->TDR = (uint16_t)data;
  172.         #endif
  173.         return 0;
  174. }
  175.  
  176. char inkey(void)
  177. {
  178.         uint32_t flags = huart1.Instance->ISR;
  179.  
  180.         if((flags & UART_FLAG_RXNE) || (flags & UART_FLAG_ORE))
  181.         {
  182.                 __HAL_UART_CLEAR_OREFLAG(&huart1);
  183.                 return (huart1.Instance->RDR);
  184.         }
  185.         else
  186.                 return 0;
  187. }
  188.  
  189. //partially based on available code examples
  190. static void lcd_start(void)
  191. {
  192.   /* LCD Initialization */
  193.   BSP_LCD_Init();
  194.  
  195.   /* LCD Initialization */
  196.   BSP_LCD_LayerDefaultInit(0, (unsigned int)0xC0000000);
  197.   //BSP_LCD_LayerDefaultInit(1, (unsigned int)lcd_image_bg+(LCD_X_SIZE*LCD_Y_SIZE*4));
  198.   BSP_LCD_LayerDefaultInit(1, (unsigned int)0xC0000000+(LCD_X_SIZE*LCD_Y_SIZE*4));
  199.  
  200.   /* Enable the LCD */
  201.   BSP_LCD_DisplayOn();
  202.  
  203.   /* Select the LCD Background Layer  */
  204.   BSP_LCD_SelectLayer(0);
  205.  
  206.   /* Clear the Background Layer */
  207.   BSP_LCD_Clear(LCD_COLOR_WHITE);
  208.   BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  209.  
  210.   BSP_LCD_SetColorKeying(1,LCD_COLOR_WHITE);
  211.  
  212.   /* Select the LCD Foreground Layer  */
  213.   BSP_LCD_SelectLayer(1);
  214.  
  215.   /* Clear the Foreground Layer */
  216.   BSP_LCD_Clear(LCD_COLOR_WHITE);
  217.   BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  218.  
  219.   /* Configure the transparency for foreground and background :
  220.      Increase the transparency */
  221.   BSP_LCD_SetTransparency(0, 255);
  222.   BSP_LCD_SetTransparency(1, 255);
  223. }
  224.  
  225. //[rmv]
  226. void draw_button(int xPos, int yPos, int width, int height, uint32_t color, uint8_t* text);
  227. void draw_background(void)
  228. {
  229.         /* Select the LCD Background Layer  */
  230.         BSP_LCD_SelectLayer(0);
  231.         BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  232.         BSP_LCD_FillRect(0,0,LCD_X_SIZE,LCD_Y_SIZE);
  233.  
  234.         //select Foreground Layer
  235.         BSP_LCD_SelectLayer(1);
  236.         char greeting[] = "Hello";
  237.         draw_button(50,50,100,100,LCD_COLOR_MAGENTA,&greeting);
  238. }
  239.  
  240. void draw_button(int xPos, int yPos, int width, int height, uint32_t color, uint8_t* text){
  241.  
  242.         BSP_LCD_SelectLayer(0);
  243.         BSP_LCD_SetTextColor(color);
  244.         BSP_LCD_FillRect(xPos,yPos,width,height);
  245.         BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  246.         BSP_LCD_DisplayStringAt(xPos+5, yPos+5, text, 0);
  247.  
  248. }
  249.  
  250. void draw_chart(float* data){
  251.  
  252.     int chart_height = 220;
  253.     int chart_length = 450;
  254.     int chart_y_pos = 240;
  255.     int chart_x_pos = 20;
  256.  
  257.                 BSP_LCD_SelectLayer(0);
  258.                 BSP_LCD_Clear(LCD_COLOR_WHITE);
  259.  
  260.  
  261. //    BSP_LCD_FillTriangle(chart_length-10,chart_length-10,chart_length,chart_y_pos+5,chart_y_pos-5,chart_y_pos);
  262.     int n = 30; //sizeof(data)/sizeof(data[0]);
  263.     float max = data[0];
  264.     float min = 0;//data[0];
  265.  
  266.     for(int i=1; i<n; i++){
  267.       if(data[i] < min)
  268.           min = data[i];
  269.       if(data[i] > max)
  270.           max = data[i];
  271.     }
  272.     int min_i = 0;//min;
  273.     int max_i = max;
  274.     float coordinates_scale = chart_height-10/(max_i - min_i);
  275.     float amplitude = max - min; // ?
  276.     float scale = chart_height-10/amplitude; // ?
  277.  
  278. // draw scale
  279.     int y = chart_y_pos;
  280.     BSP_LCD_SetTextColor(LCD_COLOR_LIGHTGRAY);
  281.     for(int i=1;i<amplitude;i++){
  282.       BSP_LCD_DrawHLine(chart_x_pos,chart_y_pos-i*coordinates_scale,chart_length);
  283.     }
  284. //draw coordinates system
  285.     BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
  286.     BSP_LCD_DrawHLine(chart_x_pos,chart_y_pos,chart_length);
  287.     BSP_LCD_DrawVLine(chart_x_pos,chart_y_pos,chart_height);
  288.  
  289. // draw data
  290.   BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  291.  
  292.   int sample_len = chart_length/n;
  293.   for(int i=0; i<n-1; i++){
  294.     int x1,y1,x2,y2;
  295.     x1 = chart_x_pos + i * sample_len;
  296.     x2 = chart_x_pos + (i+1) * sample_len;
  297.     y1 = chart_y_pos - (data[i] - min_i)*coordinates_scale;
  298.     y2 = chart_y_pos - (data[i+1] - min_i)*coordinates_scale;
  299.     BSP_LCD_DrawLine(x1,y1,x2,y2);
  300.   }
  301.  
  302.         // draw arrow
  303.         BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
  304.         Point points[3];
  305.         points[0].X=chart_x_pos+5;
  306.         points[1].X=chart_x_pos-5;
  307.         points[2].X=chart_x_pos;
  308.  
  309.         points[0].Y=chart_y_pos-chart_height+10;
  310.         points[1].Y=chart_y_pos-chart_height+10;
  311.         points[2].Y=chart_y_pos-chart_height;
  312.         BSP_LCD_FillPolygon(points,3);
  313.  
  314.         points[0].X=chart_x_pos+chart_length-10;
  315.         points[1].X=chart_x_pos+chart_length;
  316.         points[2].X=chart_x_pos+chart_length-10;
  317.  
  318.         points[0].Y=chart_y_pos-5;
  319.         points[1].Y=chart_y_pos;
  320.         points[2].Y=chart_y_pos+5;
  321.         BSP_LCD_FillPolygon(points,3);
  322.         //BSP_LCD_FillPolygon(chart_x_pos-5,chart_x_pos-5,chart_x_pos+5,chart_height-10,chart_height,chart_height-10);
  323.  
  324.         BSP_LCD_SetFont(&Font12);
  325.  
  326.         for(i = 0; i <=25 ; i+=5){
  327.                 BSP_LCD_DisplayStringAt(chart_x_pos-10,chart_y_pos+5-5*i*coordinates_scale, (uint8_t*)i, LEFT_MODE);
  328.         }
  329. /*
  330.         BSP_LCD_DisplayStringAt(chart_x_pos-10,chart_y_pos+5, (uint8_t*)"0", LEFT_MODE);
  331.         BSP_LCD_DisplayStringAt(chart_x_pos-10,chart_y_pos+5-5*coordinates_scale, (uint8_t*)"5", LEFT_MODE);
  332.         BSP_LCD_DisplayStringAt(chart_x_pos-10,chart_y_pos+5-10*coordinates_scale, (uint8_t*)"10", LEFT_MODE);
  333.         BSP_LCD_DisplayStringAt(chart_x_pos-10,chart_y_pos+5-15*coordinates_scale, (uint8_t*)"15", LEFT_MODE);
  334.         BSP_LCD_DisplayStringAt(chart_x_pos-10,chart_y_pos+5-20*coordinates_scale, (uint8_t*)"20", LEFT_MODE);
  335.         BSP_LCD_DisplayStringAt(chart_x_pos-10,chart_y_pos+5-25*coordinates_scale, (uint8_t*)"25", LEFT_MODE);
  336.         }
  337. */
  338. static TS_StateTypeDef  TS_State;
  339.  
  340.  
  341. int initialize_touchscreen(void)
  342. {
  343.         uint8_t  status = 0;
  344.         status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
  345.         if(status != TS_OK) return -1;
  346.         return 0;
  347. }
  348.  
  349.  int print_data(char* data, int client_id, int len){
  350.         BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
  351.         BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  352.         BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  353.         if(client_id == 1){
  354.                 printf("%s\n",data);
  355.                 int i;
  356.                 for(i = 10; i < 70;i++)
  357.                         BSP_LCD_ClearStringLine(i);
  358.                 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
  359.                 BSP_LCD_FillRect(0.3*LCD_X_SIZE,0.1*LCD_Y_SIZE,10,50);
  360.                 BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  361.                 BSP_LCD_ClearStringLine(10);
  362.                 BSP_LCD_ClearStringLine(50);
  363.                 char target[100];
  364.  
  365.                 strncpy(target, data, len);
  366.                 target[len] = '\0';
  367.                 BSP_LCD_DisplayStringAt(0, 10, (uint8_t*)"Temperature1 is:", CENTER_MODE);
  368.                 BSP_LCD_DisplayStringAt(0, 50, (uint8_t*)target, CENTER_MODE);
  369.         }
  370.         else{
  371.         printf("%s\n",data);
  372.         char target[100];
  373.         BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
  374.                 BSP_LCD_FillRect(0.3*LCD_X_SIZE,0.1*LCD_Y_SIZE,10,50);
  375.                 BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  376.         strncpy(target, data, len);
  377.         target[len] = '\0';
  378.         BSP_LCD_DisplayStringAt(0, 70, (uint8_t*)"Temperature2 is:", CENTER_MODE);
  379.         BSP_LCD_DisplayStringAt(0, 110, (uint8_t*)target, CENTER_MODE);
  380.         }
  381. }
  382.  
  383.  
  384. /* USER CODE END 0 */
  385.  
  386. /**
  387.   * @brief  The application entry point.
  388.   *
  389.   * @retval None
  390.   */
  391. int main(void)
  392. {
  393.  
  394.  
  395.   float data[30] = {20.34,21.39,22.05,25.07,26.97,24.27,26.34,26.39,26.32,22.01,20.34,21.39,22.05,25.07,26.97,24.27,26.34,26.39,26.32,22.01,20.34,21.39,22.05,25.07,26.97,24.27,26.34,26.39,26.32,22.01};
  396.  
  397.   /* USER CODE BEGIN 1 */
  398.  
  399.   /* USER CODE END 1 */
  400.  
  401.   /* MCU Configuration----------------------------------------------------------*/
  402.  
  403.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  404.   HAL_Init();
  405.  
  406.   /* USER CODE BEGIN Init */
  407.  
  408.   /* USER CODE END Init */
  409.  
  410.   /* Configure the system clock */
  411.   SystemClock_Config();
  412.  
  413.   /* USER CODE BEGIN SysInit */
  414.  
  415.   /* USER CODE END SysInit */
  416.  
  417.   /* Initialize all configured peripherals */
  418.   MX_GPIO_Init();
  419.   MX_USART1_UART_Init();
  420.   MX_USART6_UART_Init();
  421.   /* USER CODE BEGIN 2 */
  422.   debug_init(&huart1);
  423.  
  424.   xprintf(ANSI_FG_GREEN "STM32F746 Discovery Project" ANSI_FG_DEFAULT "\n");
  425.  
  426.   printf("Regular printf\n");
  427.  
  428. lcd_start();
  429. draw_background();
  430. initialize_touchscreen();
  431. draw_chart(data);
  432.  
  433.   /* Create the thread(s) */
  434.   /* definition and creation of defaultTask */
  435.   osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
  436.   defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  437.  
  438.  
  439.   /* Start scheduler */
  440.   osKernelStart();
  441.  
  442.   /* We should never get here as control is now taken by the scheduler */
  443.  
  444.   /* Infinite loop */
  445.   /* USER CODE BEGIN WHILE */
  446.   while (1)
  447.   {
  448.  
  449.   }
  450.  
  451. }
  452.  
  453. /**
  454.   * @brief System Clock Configuration
  455.   * @retval None
  456.   */
  457. void SystemClock_Config(void)
  458. {
  459.  
  460.   RCC_OscInitTypeDef RCC_OscInitStruct;
  461.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  462.   RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
  463.  
  464.     /**Configure the main internal regulator output voltage
  465.     */
  466.   __HAL_RCC_PWR_CLK_ENABLE();
  467.  
  468.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  469.  
  470.     /**Initializes the CPU, AHB and APB busses clocks
  471.     */
  472.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  473.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  474.   RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  475.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  476.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  477.   RCC_OscInitStruct.PLL.PLLM = 25;
  478.   RCC_OscInitStruct.PLL.PLLN = 400;
  479.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  480.   RCC_OscInitStruct.PLL.PLLQ = 8;
  481.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  482.   {
  483.     _Error_Handler(__FILE__, __LINE__);
  484.   }
  485.  
  486.     /**Activate the Over-Drive mode
  487.     */
  488.   if (HAL_PWREx_EnableOverDrive() != HAL_OK)
  489.   {
  490.     _Error_Handler(__FILE__, __LINE__);
  491.   }
  492.  
  493.     /**Initializes the CPU, AHB and APB busses clocks
  494.     */
  495.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  496.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  497.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  498.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  499.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  500.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  501.  
  502.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) != HAL_OK)
  503.   {
  504.     _Error_Handler(__FILE__, __LINE__);
  505.   }
  506.  
  507.   PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPDIFRX|RCC_PERIPHCLK_LTDC
  508.                               |RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART1
  509.                               |RCC_PERIPHCLK_USART6|RCC_PERIPHCLK_SAI2
  510.                               |RCC_PERIPHCLK_I2C1|RCC_PERIPHCLK_I2C3
  511.                               |RCC_PERIPHCLK_SDMMC1|RCC_PERIPHCLK_CLK48;
  512.   PeriphClkInitStruct.PLLI2S.PLLI2SN = 100;
  513.   PeriphClkInitStruct.PLLI2S.PLLI2SP = RCC_PLLP_DIV2;
  514.   PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
  515.   PeriphClkInitStruct.PLLI2S.PLLI2SQ = 2;
  516.   PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
  517.   PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
  518.   PeriphClkInitStruct.PLLSAI.PLLSAIQ = 4;
  519.   PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV4;
  520.   PeriphClkInitStruct.PLLI2SDivQ = 1;
  521.   PeriphClkInitStruct.PLLSAIDivQ = 1;
  522.   PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
  523.   PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  524.   PeriphClkInitStruct.Sai2ClockSelection = RCC_SAI2CLKSOURCE_PLLSAI;
  525.   PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  526.   PeriphClkInitStruct.Usart6ClockSelection = RCC_USART6CLKSOURCE_PCLK2;
  527.   PeriphClkInitStruct.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
  528.   PeriphClkInitStruct.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1;
  529.   PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLLSAIP;
  530.   PeriphClkInitStruct.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_CLK48;
  531.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  532.   {
  533.     _Error_Handler(__FILE__, __LINE__);
  534.   }
  535.  
  536.     /**Configure the Systick interrupt time
  537.     */
  538.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  539.  
  540.     /**Configure the Systick
  541.     */
  542.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  543.  
  544.   /* SysTick_IRQn interrupt configuration */
  545.   HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
  546. }
  547.  
  548.  
  549.  
  550.  
  551. /* USART1 init function */
  552. static void MX_USART1_UART_Init(void)
  553. {
  554.  
  555.   huart1.Instance = USART1;
  556.   huart1.Init.BaudRate = 115200;
  557.   huart1.Init.WordLength = UART_WORDLENGTH_8B;
  558.   huart1.Init.StopBits = UART_STOPBITS_1;
  559.   huart1.Init.Parity = UART_PARITY_NONE;
  560.   huart1.Init.Mode = UART_MODE_TX_RX;
  561.   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  562.   huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  563.   huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  564.   huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  565.   if (HAL_UART_Init(&huart1) != HAL_OK)
  566.   {
  567.     _Error_Handler(__FILE__, __LINE__);
  568.   }
  569.  
  570. }
  571.  
  572. /* USART6 init function */
  573. static void MX_USART6_UART_Init(void)
  574. {
  575.  
  576.   huart6.Instance = USART6;
  577.   huart6.Init.BaudRate = 115200;
  578.   huart6.Init.WordLength = UART_WORDLENGTH_8B;
  579.   huart6.Init.StopBits = UART_STOPBITS_1;
  580.   huart6.Init.Parity = UART_PARITY_NONE;
  581.   huart6.Init.Mode = UART_MODE_TX_RX;
  582.   huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  583.   huart6.Init.OverSampling = UART_OVERSAMPLING_16;
  584.   huart6.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  585.   huart6.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  586.   if (HAL_UART_Init(&huart6) != HAL_OK)
  587.   {
  588.     _Error_Handler(__FILE__, __LINE__);
  589.   }
  590.  
  591. }
  592.  
  593.  
  594.  
  595. /** Configure pins as
  596.         * Analog
  597.         * Input
  598.         * Output
  599.         * EVENT_OUT
  600.         * EXTI
  601.      PB5   ------> USB_OTG_HS_ULPI_D7
  602.      PH4   ------> USB_OTG_HS_ULPI_NXT
  603.      PB13   ------> USB_OTG_HS_ULPI_D6
  604.      PB12   ------> USB_OTG_HS_ULPI_D5
  605.      PC0   ------> USB_OTG_HS_ULPI_STP
  606.      PC2   ------> USB_OTG_HS_ULPI_DIR
  607.      PA5   ------> USB_OTG_HS_ULPI_CK
  608.      PB10   ------> USB_OTG_HS_ULPI_D3
  609.      PA3   ------> USB_OTG_HS_ULPI_D0
  610.      PB1   ------> USB_OTG_HS_ULPI_D2
  611.      PB0   ------> USB_OTG_HS_ULPI_D1
  612.      PB11   ------> USB_OTG_HS_ULPI_D4
  613. */
  614. static void MX_GPIO_Init(void)
  615. {
  616.  
  617.   GPIO_InitTypeDef GPIO_InitStruct;
  618.  
  619.   /* GPIO Ports Clock Enable */
  620.   __HAL_RCC_GPIOE_CLK_ENABLE();
  621.   __HAL_RCC_GPIOG_CLK_ENABLE();
  622.   __HAL_RCC_GPIOB_CLK_ENABLE();
  623.   __HAL_RCC_GPIOD_CLK_ENABLE();
  624.   __HAL_RCC_GPIOC_CLK_ENABLE();
  625.   __HAL_RCC_GPIOA_CLK_ENABLE();
  626.   __HAL_RCC_GPIOJ_CLK_ENABLE();
  627.   __HAL_RCC_GPIOI_CLK_ENABLE();
  628.   __HAL_RCC_GPIOK_CLK_ENABLE();
  629.   __HAL_RCC_GPIOF_CLK_ENABLE();
  630.   __HAL_RCC_GPIOH_CLK_ENABLE();
  631.  
  632.   /*Configure GPIO pin Output Level */
  633.   HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET);
  634.  
  635.   /*Configure GPIO pin Output Level */
  636.   HAL_GPIO_WritePin(GPIOI, ARDUINO_D7_Pin|ARDUINO_D8_Pin, GPIO_PIN_RESET);
  637.  
  638.   /*Configure GPIO pin Output Level */
  639.   HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_Port, LCD_BL_CTRL_Pin, GPIO_PIN_SET);
  640.  
  641.   /*Configure GPIO pin Output Level */
  642.   HAL_GPIO_WritePin(LCD_DISP_GPIO_Port, LCD_DISP_Pin, GPIO_PIN_SET);
  643.  
  644.   /*Configure GPIO pin Output Level */
  645.   HAL_GPIO_WritePin(DCMI_PWR_EN_GPIO_Port, DCMI_PWR_EN_Pin, GPIO_PIN_RESET);
  646.  
  647.   /*Configure GPIO pin Output Level */
  648.   HAL_GPIO_WritePin(GPIOG, ARDUINO_D4_Pin|ARDUINO_D2_Pin|EXT_RST_Pin, GPIO_PIN_RESET);
  649.  
  650.   /*Configure GPIO pin : OTG_HS_OverCurrent_Pin */
  651.   GPIO_InitStruct.Pin = OTG_HS_OverCurrent_Pin;
  652.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  653.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  654.   HAL_GPIO_Init(OTG_HS_OverCurrent_GPIO_Port, &GPIO_InitStruct);
  655.  
  656.   /*Configure GPIO pins : ULPI_D7_Pin ULPI_D6_Pin ULPI_D5_Pin ULPI_D3_Pin
  657.                            ULPI_D2_Pin ULPI_D1_Pin ULPI_D4_Pin */
  658.   GPIO_InitStruct.Pin = ULPI_D7_Pin|ULPI_D6_Pin|ULPI_D5_Pin|ULPI_D3_Pin
  659.                           |ULPI_D2_Pin|ULPI_D1_Pin|ULPI_D4_Pin;
  660.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  661.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  662.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  663.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  664.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  665.  
  666.   /*Configure GPIO pin : OTG_FS_VBUS_Pin */
  667.   GPIO_InitStruct.Pin = OTG_FS_VBUS_Pin;
  668.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  669.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  670.   HAL_GPIO_Init(OTG_FS_VBUS_GPIO_Port, &GPIO_InitStruct);
  671.  
  672.   /*Configure GPIO pin : Audio_INT_Pin */
  673.   /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */
  674.   GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin;
  675.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  676.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  677.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  678.   HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);
  679.  
  680.   /*Configure GPIO pins : ARDUINO_D7_Pin ARDUINO_D8_Pin LCD_DISP_Pin */
  681.   GPIO_InitStruct.Pin = ARDUINO_D7_Pin|ARDUINO_D8_Pin|LCD_DISP_Pin;
  682.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  683.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  684.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  685.   HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
  686.  
  687.   /*Configure GPIO pin : uSD_Detect_Pin */
  688.   GPIO_InitStruct.Pin = uSD_Detect_Pin;
  689.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  690.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  691.   HAL_GPIO_Init(uSD_Detect_GPIO_Port, &GPIO_InitStruct);
  692.  
  693.   /*Configure GPIO pin : LCD_BL_CTRL_Pin */
  694.   GPIO_InitStruct.Pin = LCD_BL_CTRL_Pin;
  695.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  696.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  697.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  698.   HAL_GPIO_Init(LCD_BL_CTRL_GPIO_Port, &GPIO_InitStruct);
  699.  
  700.   /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */
  701.   GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin;
  702.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  703.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  704.   HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct);
  705.  
  706.   /*Configure GPIO pins : TP3_Pin NC2_Pin */
  707.   GPIO_InitStruct.Pin = TP3_Pin|NC2_Pin;
  708.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  709.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  710.   HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
  711.  
  712.   /*Configure GPIO pin : DCMI_PWR_EN_Pin */
  713.   GPIO_InitStruct.Pin = DCMI_PWR_EN_Pin;
  714.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  715.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  716.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  717.   HAL_GPIO_Init(DCMI_PWR_EN_GPIO_Port, &GPIO_InitStruct);
  718.  
  719.   /*Configure GPIO pin : LCD_INT_Pin */
  720.   GPIO_InitStruct.Pin = LCD_INT_Pin;
  721.   GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  722.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  723.   HAL_GPIO_Init(LCD_INT_GPIO_Port, &GPIO_InitStruct);
  724.  
  725.   /*Configure GPIO pin : ULPI_NXT_Pin */
  726.   GPIO_InitStruct.Pin = ULPI_NXT_Pin;
  727.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  728.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  729.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  730.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  731.   HAL_GPIO_Init(ULPI_NXT_GPIO_Port, &GPIO_InitStruct);
  732.  
  733.   /*Configure GPIO pins : ARDUINO_D4_Pin ARDUINO_D2_Pin EXT_RST_Pin */
  734.   GPIO_InitStruct.Pin = ARDUINO_D4_Pin|ARDUINO_D2_Pin|EXT_RST_Pin;
  735.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  736.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  737.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  738.   HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  739.  
  740.   /*Configure GPIO pins : ULPI_STP_Pin ULPI_DIR_Pin */
  741.   GPIO_InitStruct.Pin = ULPI_STP_Pin|ULPI_DIR_Pin;
  742.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  743.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  744.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  745.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  746.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  747.  
  748.   /*Configure GPIO pin : RMII_RXER_Pin */
  749.   GPIO_InitStruct.Pin = RMII_RXER_Pin;
  750.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  751.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  752.   HAL_GPIO_Init(RMII_RXER_GPIO_Port, &GPIO_InitStruct);
  753.  
  754.   /*Configure GPIO pins : ULPI_CLK_Pin ULPI_D0_Pin */
  755.   GPIO_InitStruct.Pin = ULPI_CLK_Pin|ULPI_D0_Pin;
  756.   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  757.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  758.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  759.   GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
  760.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  761.  
  762. }
  763.  
  764.  
  765.  
  766. /* USER CODE END 4 */
  767.  
  768. /* USER CODE BEGIN Header_StartDefaultTask */
  769. /**
  770.   * @brief  Function implementing the defaultTask thread.
  771.   * @param  argument: Not used
  772.   * @retval None
  773.   */
  774. /* USER CODE END Header_StartDefaultTask */
  775. static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status);
  776. static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len);
  777. static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags);
  778. static void mqtt_sub_request_cb(void *arg, err_t result);
  779. static void mqtt_pub_request_cb(void *arg, err_t result);
  780. int example_do_connect(mqtt_client_t *client)
  781. {
  782.   struct mqtt_connect_client_info_t ci;
  783.   err_t err;
  784.  
  785.   /* Setup an empty client info structure */
  786.   memset(&ci, 0, sizeof(ci));
  787.  
  788.   /* Minimal amount of information required is client identifier, so set it here */
  789.   ci.client_id = "lwip_test";
  790.  
  791.   /* Initiate client and connect to server, if this fails immediately an error code is returned
  792.      otherwise mqtt_connection_cb will be called with connection result after attempting
  793.      to establish a connection with the server.
  794.      For now MQTT version 3.1.1 is always used */
  795.   ip_addr_t ip_addr;
  796.   if(1 == ipaddr_aton( "192.168.0.101",&ip_addr)){
  797.         printf("Created ip");
  798.   }
  799.   err = mqtt_client_connect(client, &ip_addr, 1883, mqtt_connection_cb, 0, &ci);
  800.  
  801.   /* For now just print the result code if something goes wrong */
  802.   if(err != ERR_OK) {
  803.     printf("mqtt_connect return tutaj %d\n", err);
  804.         return 1;
  805.  
  806.   }
  807.   else{
  808.         printf("mqtt_connectbvgfdbgfdgfd\n");
  809.         return 0;
  810.   }
  811. }
  812.  
  813. static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status)
  814. {
  815.  
  816.   err_t err;
  817.   err_t err2;
  818.   if(status == MQTT_CONNECT_ACCEPTED) {
  819.     printf("mqtt_connection_cb: Successfully connected\n");
  820.  
  821.     /* Setup callback for incoming publish requests */
  822.     mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb, mqtt_incoming_data_cb, arg);
  823.  
  824.     /* Subscribe to a topic named "subtopic" with QoS level 1, call mqtt_sub_request_cb with result */
  825.     err = mqtt_subscribe(client, "esp/temperature/client2", 1, mqtt_sub_request_cb, arg);
  826.         err2 = mqtt_subscribe(client, "esp/temperature/client1", 1, mqtt_sub_request_cb, arg);
  827.  
  828.     if(err != ERR_OK || err2 != ERR_OK) {
  829.       printf("mqtt_subscribe return: %d\n", err);
  830.     }
  831.   } else {
  832.     printf("mqtt_connection_cb: Disconnected, reason: %d\n", status);
  833.     /* Its more nice to be connected, so try to reconnect */
  834.     example_do_connect(client);
  835.   }
  836.  
  837. }
  838.  
  839. static void mqtt_sub_request_cb(void *arg, err_t result)
  840. {
  841.   /* Just print the result code here for simplicity,
  842.      normal behaviour would be to take some action if subscribe fails like
  843.      notifying user, retry subscribe or disconnect from server */
  844.   printf("Subscribe result: %d\n", result);
  845.   if(result == ERR_OK){
  846.   printf("Subscribe result is OK!\n");
  847.   }
  848. }
  849.  
  850. //-----------------------------------------------------------------
  851. //3. Implementing callbacks for incoming publish and data
  852.  
  853. /* The idea is to demultiplex topic and create some reference to be used in data callbacks
  854.    Example here uses a global variable, better would be to use a member in arg
  855.    If RAM and CPU budget allows it, the easiest implementation might be to just take a copy of
  856.    the topic string and use it in mqtt_incoming_data_cb
  857. */
  858. static int inpub_id;
  859. static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len) // callback invoked when publish starts, contain topic and total length of payload
  860. {
  861.   printf("Incoming publish at topic %s with total length %u\n", topic, (unsigned int)tot_len);
  862.  
  863.   /* Decode topic string into a user defined reference */
  864.   if(strcmp(topic, "print_payload") == 0) {
  865.     inpub_id = 0;
  866.   } else if(topic[0] == 'A') {
  867.     /* All topics starting with 'A' might be handled at the same way */
  868.     inpub_id = 1;
  869.   } else if(strcmp(topic,"esp/temperature/client1") == 0){
  870.         inpub_id = 2;
  871.   }
  872.   else {
  873.     /* For all other topics */
  874.     inpub_id = 3;
  875.   }
  876. }
  877.  
  878. static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags) // callback for each fragment of payload that arrives
  879. {
  880.   printf("Incoming publish payload with length %d, flags %u\n", len, (unsigned int)flags);
  881.  
  882.   if(flags & MQTT_DATA_FLAG_LAST) {
  883.     /* Last fragment of payload received (or whole part if payload fits receive buffer
  884.        See MQTT_VAR_HEADER_BUFFER_LEN)  */
  885.  
  886.     /* Call function or do action depending on reference, in this case inpub_id */
  887.     if(inpub_id == 0) {
  888.       /* Don't trust the publisher, check zero termination */
  889.       if(data[len-1] == 0) {
  890.         printf("mqtt_incoming_data_cb: %s\n", (const char *)data);
  891.       }
  892.     } else if(inpub_id == 1) {
  893.       /* Call an 'A' function... */
  894.  
  895.           xprintf("Call an A function ...\n");
  896.  
  897.     } else if(inpub_id == 2){
  898.                 print_data((const char *)data, 1,len);
  899.         }
  900.         else {
  901.       //printf("mqtt_incoming_data_cb: Ignoring payload...\n");
  902.           printf("mqtt_incoming_data_cb: %s\n", (const char *)data);
  903.           print_data((const char *)data,2,len);
  904.     }
  905.   } else {
  906.     /* Handle fragmented payload, store in buffer, write to file or whatever */
  907.   }
  908.   //data = NULL;
  909. }
  910.  
  911. //-----------------------------------------------------------------
  912. //4. Using outgoing publish
  913.  static void mqtt_pub_request_cb(void *arg, err_t result)
  914. {
  915.   if(result != ERR_OK) {
  916.     printf("Publish result: %d\n", result);
  917.   }
  918. }
  919.  
  920. void example_publish(mqtt_client_t *client, void *arg)
  921. {
  922.   const char *pub_payload= "give_temperature";
  923.   err_t err;
  924.   u8_t qos = 2; /* 0 1 or 2, see MQTT specification */
  925.   u8_t retain = 0; /* No don't retain such crappy payload... */
  926.   err = mqtt_publish(client, "esp/temperature", pub_payload, strlen(pub_payload), qos, retain, mqtt_pub_request_cb, arg);
  927.   if(err != ERR_OK) {
  928.     printf("Publish err: %d\n", err);
  929.   }
  930. }
  931.  
  932. void create_menu(){
  933.  
  934.  
  935. }
  936. void StartDefaultTask(void const * argument)
  937. {
  938.   MX_LWIP_Init();
  939.  
  940.   /*MQTT */
  941.  
  942.   int tmp = 1;
  943.   mqtt_client_t static_client;
  944.   while(tmp == 1){
  945.         xprintf("Trying to connect\n");
  946.         vTaskDelay(1000);
  947.         tmp = example_do_connect(&static_client);
  948.         vTaskDelay(1000);
  949.   //xprintf("tutaj koniecx");
  950.   }
  951.  
  952.   for(;;)
  953.   {
  954.  
  955.         BSP_TS_GetState(&TS_State);
  956.         if(TS_State.touchDetected)
  957.         {
  958.                 BSP_LCD_Clear(LCD_COLOR_WHITE);
  959.                 BSP_LCD_SelectLayer(0);
  960.                 BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  961.                 BSP_LCD_FillRect(0,0,LCD_X_SIZE,LCD_Y_SIZE);
  962.  
  963.                 //select Foreground Layer
  964.                 BSP_LCD_SelectLayer(1);
  965.                 char greeting[] = "Hello";
  966.                 draw_button(50,50,100,100,LCD_COLOR_MAGENTA,&greeting);
  967.  
  968.         }
  969.  
  970.         char key = inkey();
  971.         if(key == 'p'){
  972.                 xprintf("Send message \n");
  973.                 example_publish(&static_client,2);
  974.         }
  975.  
  976.  
  977.         vTaskDelay(2);
  978.  
  979.   }
  980.   /* USER CODE END 5 */
  981. }
  982.  
  983. /**
  984.   * @brief  Period elapsed callback in non blocking mode
  985.   * @note   This function is called  when TIM6 interrupt took place, inside
  986.   * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  987.   * a global variable "uwTick" used as application time base.
  988.   * @param  htim : TIM handle
  989.   * @retval None
  990.   */
  991. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  992. {
  993.   /* USER CODE BEGIN Callback 0 */
  994.  
  995.   /* USER CODE END Callback 0 */
  996.   if (htim->Instance == TIM6) {
  997.     HAL_IncTick();
  998.   }
  999.   /* USER CODE BEGIN Callback 1 */
  1000.  
  1001.   /* USER CODE END Callback 1 */
  1002. }
  1003.  
  1004. /**
  1005.   * @brief  This function is executed in case of error occurrence.
  1006.   * @param  file: The file name as string.
  1007.   * @param  line: The line in file as a number.
  1008.   * @retval None
  1009.   */
  1010. void _Error_Handler(char *file, int line)
  1011. {
  1012.   /* USER CODE BEGIN Error_Handler_Debug */
  1013.   /* User can add his own implementation to report the HAL error return state */
  1014.   while(1)
  1015.   {
  1016.   }
  1017.   /* USER CODE END Error_Handler_Debug */
  1018. }
  1019.  
  1020. #ifdef  USE_FULL_ASSERT
  1021. /**
  1022.   * @brief  Reports the name of the source file and the source line number
  1023.   *         where the assert_param error has occurred.
  1024.   * @param  file: pointer to the source file name
  1025.   * @param  line: assert_param error line source number
  1026.   * @retval None
  1027.   */
  1028. void assert_failed(uint8_t* file, uint32_t line)
  1029. {
  1030.   /* USER CODE BEGIN 6 */
  1031.   /* User can add his own implementation to report the file name and line number,
  1032.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  1033.   /* USER CODE END 6 */
  1034. }
  1035. #endif /* USE_FULL_ASSERT */
  1036.  
  1037. /**
  1038.   * @}
  1039.   */
  1040.  
  1041. /**
  1042.   * @}
  1043.   */
  1044.  
  1045. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/