82
project/Core/Inc/website_backend.h
Normal file
82
project/Core/Inc/website_backend.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* @file website_backend.h
|
||||
* @brief Backend for the website to operate
|
||||
* @author Toon B.
|
||||
*/
|
||||
|
||||
#ifndef INC_WEBSITE_BACKEND_
|
||||
#define INC_WEBSITE_BACKEND_
|
||||
|
||||
/* Include headers C lib */
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Defines */
|
||||
#define LOGGER_LEVEL_ALL
|
||||
#define STR_MAX 200
|
||||
#define CLR_MAX 11
|
||||
#define IMG_X 0
|
||||
#define IMG_Y 0
|
||||
#define SD_IMG "st.bmp"
|
||||
|
||||
/* Include headers */
|
||||
#include "log.h"
|
||||
#include "lwip.h"
|
||||
#include "httpd.h"
|
||||
#include "lwip/apps/fs.h"
|
||||
#include "llfs.h"
|
||||
#include "lcd_api.h"
|
||||
|
||||
/**
|
||||
* @fn void wbe_init(void)
|
||||
* @brief Initialise the http server. It also sets the beginning screen
|
||||
* of the display.
|
||||
*/
|
||||
void wbe_init(void);
|
||||
|
||||
/**
|
||||
* @fn int fs_open_custom(struct fs_file*, const char*)
|
||||
* @brief Function is called when the frontend wants to reach/open a file
|
||||
* or endpoint on the backend.
|
||||
*
|
||||
* @param[in] file, the file pointer of the file that the frontend wants
|
||||
* @param[in] name, the name of the file or endpoint that the frontend asks for
|
||||
* @return[out] returns 0 if file or endpoint was not found, 1 if it was found
|
||||
*/
|
||||
int fs_open_custom(struct fs_file* file, const char* name);
|
||||
|
||||
/**
|
||||
* @fn void fs_close_custom(struct fs_file*)
|
||||
* @brief Called when closing files and endpoints
|
||||
*
|
||||
* @param[in] file, the file pointer of the file that the frontend wants
|
||||
*/
|
||||
void fs_close_custom(struct fs_file* file);
|
||||
|
||||
/**
|
||||
* @fn void httpd_cgi_handler(struct fs_file*, const char*, int, char**, char**)
|
||||
* @brief When data is send from the frontend to the backend with the CGI
|
||||
* tag and parameters, this function is called. With this comes parameters that
|
||||
* we want to read for further use.
|
||||
*
|
||||
* @param[in] file, the file pointer of the file that the frontend wants
|
||||
* @param[in] uri, the URI that is given to the backend from the frontend (here cgi)
|
||||
* @param[in] num_parm, the number of parameters that is given with the URI
|
||||
* @param[in] pc_param, contains the name of each parameter
|
||||
* @param[in] pc_value, is the value of each parameter
|
||||
*/
|
||||
void httpd_cgi_handler(struct fs_file* file, const char* uri, int num_parm, char** pc_param, char** pc_value);
|
||||
|
||||
/**
|
||||
* @fn void wbe_display(const char*, const uint32_t, const uint32_t, const char*)
|
||||
* @brief Function displays the sentence, its color, the background and the given
|
||||
* image on the LCD screen.
|
||||
*
|
||||
* @param[in] txt, is the text string that needs to be displayed
|
||||
* @param[in] txt_color, the color of the wanted string
|
||||
* @param[in] background_color, color of the background of the screen
|
||||
* @param[in] image, name of the wanted image to be displayed
|
||||
*/
|
||||
void wbe_display(const char* txt, const uint32_t txt_color, const uint32_t background_color, const char* image);
|
||||
|
||||
#endif /* INC_WEBSITE_BACKEND_ */
|
||||
262768
project/Core/Src/llfs_data.c
262768
project/Core/Src/llfs_data.c
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,20 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "modbus_tcp.h"
|
||||
#include "UDP_broadcast.h"
|
||||
#include "tcp_cmd.h"
|
||||
#include "website_backend.h"
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
@@ -85,453 +86,434 @@ static void MX_QUADSPI_Init(void);
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void) {
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_LTDC_Init();
|
||||
MX_USART1_UART_Init();
|
||||
MX_DMA2D_Init();
|
||||
MX_FMC_Init();
|
||||
MX_LWIP_Init();
|
||||
MX_QUADSPI_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_LTDC_Init();
|
||||
MX_USART1_UART_Init();
|
||||
MX_DMA2D_Init();
|
||||
MX_FMC_Init();
|
||||
MX_LWIP_Init();
|
||||
MX_QUADSPI_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* Initialize QSPI */
|
||||
BSP_QSPI_Init();
|
||||
BSP_QSPI_MemoryMappedMode();
|
||||
WRITE_REG(QUADSPI->LPTR, 0xFFF);
|
||||
/* Initialize QSPI */
|
||||
BSP_QSPI_Init();
|
||||
BSP_QSPI_MemoryMappedMode();
|
||||
WRITE_REG(QUADSPI->LPTR, 0xFFF);
|
||||
|
||||
/* Clear terminal */
|
||||
printf(CLEAR_SCREEN);
|
||||
/* Clear terminal */
|
||||
printf(CLEAR_SCREEN);
|
||||
|
||||
/* Initialize the LCD */
|
||||
lcd_init(true);
|
||||
/* Initialize the LCD */
|
||||
lcd_init(true);
|
||||
|
||||
/* Initialize the filesystem */
|
||||
llfs_init();
|
||||
/* Initialize the filesystem */
|
||||
llfs_init();
|
||||
|
||||
/* Initialize the tftp server */
|
||||
tftp_server_init();
|
||||
|
||||
/* Initialize tcp command interface*/
|
||||
tcp_cmd_init();
|
||||
/* Initialize the tftp server */
|
||||
tftp_server_init();
|
||||
|
||||
/* Initialize Modbus*/
|
||||
modbus_init();
|
||||
|
||||
/* Initialize the MQTT application */
|
||||
mqtt_application_init();
|
||||
/* Initialize tcp command interface*/
|
||||
tcp_cmd_init();
|
||||
|
||||
// Initialize the UDP broadcast service
|
||||
/* Initialize Modbus*/
|
||||
modbus_init();
|
||||
|
||||
if (udp_broadcast_init(10,255) != ERR_OK){
|
||||
LOG_WARN(TAG,"error initializing udp connection, check warnings from udp_broadcast_init() or udp_broadcast_connection_init()");
|
||||
}
|
||||
if (udp_broadcast_set_owner_details("Joran", "Van Nieuwenhoven") != ERR_OK){
|
||||
LOG_WARN(TAG,"error setting owner's details");
|
||||
}
|
||||
/* Initialize the MQTT application */
|
||||
mqtt_application_init();
|
||||
|
||||
/* USER CODE END 2 */
|
||||
// Initialize the UDP broadcast service
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
if (udp_broadcast_init(10, 255) != ERR_OK) {
|
||||
LOG_WARN(TAG,
|
||||
"error initializing udp connection, check warnings from udp_broadcast_init() or udp_broadcast_connection_init()");
|
||||
}
|
||||
if (udp_broadcast_set_owner_details("Joran", "Van Nieuwenhoven") != ERR_OK) {
|
||||
LOG_WARN(TAG, "error setting owner's details");
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
MX_LWIP_Process();
|
||||
lcd_task();
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
/* Initialize website backend */
|
||||
wbe_init();
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1) {
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
MX_LWIP_Process();
|
||||
lcd_task();
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void) {
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
/** Configure LSE Drive Capability
|
||||
*/
|
||||
HAL_PWR_EnableBkUpAccess();
|
||||
/** Configure LSE Drive Capability
|
||||
*/
|
||||
HAL_PWR_EnableBkUpAccess();
|
||||
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = 25;
|
||||
RCC_OscInitStruct.PLL.PLLN = 400;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 2;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = 25;
|
||||
RCC_OscInitStruct.PLL.PLLN = 400;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 2;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Activate the Over-Drive mode
|
||||
*/
|
||||
if (HAL_PWREx_EnableOverDrive() != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Activate the Over-Drive mode
|
||||
*/
|
||||
if (HAL_PWREx_EnableOverDrive() != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA2D Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_DMA2D_Init(void)
|
||||
{
|
||||
* @brief DMA2D Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_DMA2D_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||
|
||||
/* USER CODE END DMA2D_Init 0 */
|
||||
/* USER CODE END DMA2D_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||
/* USER CODE BEGIN DMA2D_Init 1 */
|
||||
|
||||
/* USER CODE END DMA2D_Init 1 */
|
||||
hdma2d.Instance = DMA2D;
|
||||
hdma2d.Init.Mode = DMA2D_M2M;
|
||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||
hdma2d.Init.OutputOffset = 0;
|
||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||
/* USER CODE END DMA2D_Init 1 */
|
||||
hdma2d.Instance = DMA2D;
|
||||
hdma2d.Init.Mode = DMA2D_M2M;
|
||||
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
|
||||
hdma2d.Init.OutputOffset = 0;
|
||||
hdma2d.LayerCfg[1].InputOffset = 0;
|
||||
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
|
||||
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
||||
hdma2d.LayerCfg[1].InputAlpha = 0;
|
||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||
|
||||
/* USER CODE END DMA2D_Init 2 */
|
||||
/* USER CODE END DMA2D_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LTDC Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_LTDC_Init(void)
|
||||
{
|
||||
* @brief LTDC Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_LTDC_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN LTDC_Init 0 */
|
||||
/* USER CODE BEGIN LTDC_Init 0 */
|
||||
|
||||
/* USER CODE END LTDC_Init 0 */
|
||||
/* USER CODE END LTDC_Init 0 */
|
||||
|
||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
||||
LTDC_LayerCfgTypeDef pLayerCfg1 = {0};
|
||||
LTDC_LayerCfgTypeDef pLayerCfg = {0};
|
||||
LTDC_LayerCfgTypeDef pLayerCfg1 = {0};
|
||||
|
||||
/* USER CODE BEGIN LTDC_Init 1 */
|
||||
/* USER CODE BEGIN LTDC_Init 1 */
|
||||
|
||||
/* USER CODE END LTDC_Init 1 */
|
||||
hltdc.Instance = LTDC;
|
||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
||||
hltdc.Init.HorizontalSync = 40;
|
||||
hltdc.Init.VerticalSync = 9;
|
||||
hltdc.Init.AccumulatedHBP = 53;
|
||||
hltdc.Init.AccumulatedVBP = 11;
|
||||
hltdc.Init.AccumulatedActiveW = 533;
|
||||
hltdc.Init.AccumulatedActiveH = 283;
|
||||
hltdc.Init.TotalWidth = 565;
|
||||
hltdc.Init.TotalHeigh = 285;
|
||||
hltdc.Init.Backcolor.Blue = 0;
|
||||
hltdc.Init.Backcolor.Green = 255;
|
||||
hltdc.Init.Backcolor.Red = 0;
|
||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
pLayerCfg.WindowX0 = 0;
|
||||
pLayerCfg.WindowX1 = 480;
|
||||
pLayerCfg.WindowY0 = 0;
|
||||
pLayerCfg.WindowY1 = 272;
|
||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB1555;
|
||||
pLayerCfg.Alpha = 255;
|
||||
pLayerCfg.Alpha0 = 0;
|
||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
||||
pLayerCfg.FBStartAdress = 0;
|
||||
pLayerCfg.ImageWidth = 480;
|
||||
pLayerCfg.ImageHeight = 272;
|
||||
pLayerCfg.Backcolor.Blue = 0;
|
||||
pLayerCfg.Backcolor.Green = 0;
|
||||
pLayerCfg.Backcolor.Red = 0;
|
||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
pLayerCfg1.WindowX0 = 0;
|
||||
pLayerCfg1.WindowX1 = 480;
|
||||
pLayerCfg1.WindowY0 = 0;
|
||||
pLayerCfg1.WindowY1 = 272;
|
||||
pLayerCfg1.PixelFormat = LTDC_PIXEL_FORMAT_ARGB1555;
|
||||
pLayerCfg1.Alpha = 255;
|
||||
pLayerCfg1.Alpha0 = 0;
|
||||
pLayerCfg1.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
||||
pLayerCfg1.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
||||
pLayerCfg1.FBStartAdress = 0;
|
||||
pLayerCfg1.ImageWidth = 480;
|
||||
pLayerCfg1.ImageHeight = 272;
|
||||
pLayerCfg1.Backcolor.Blue = 0;
|
||||
pLayerCfg1.Backcolor.Green = 0;
|
||||
pLayerCfg1.Backcolor.Red = 0;
|
||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg1, 1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN LTDC_Init 2 */
|
||||
/* USER CODE END LTDC_Init 1 */
|
||||
hltdc.Instance = LTDC;
|
||||
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
||||
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
||||
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
||||
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
||||
hltdc.Init.HorizontalSync = 40;
|
||||
hltdc.Init.VerticalSync = 9;
|
||||
hltdc.Init.AccumulatedHBP = 53;
|
||||
hltdc.Init.AccumulatedVBP = 11;
|
||||
hltdc.Init.AccumulatedActiveW = 533;
|
||||
hltdc.Init.AccumulatedActiveH = 283;
|
||||
hltdc.Init.TotalWidth = 565;
|
||||
hltdc.Init.TotalHeigh = 285;
|
||||
hltdc.Init.Backcolor.Blue = 0;
|
||||
hltdc.Init.Backcolor.Green = 255;
|
||||
hltdc.Init.Backcolor.Red = 0;
|
||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
pLayerCfg.WindowX0 = 0;
|
||||
pLayerCfg.WindowX1 = 480;
|
||||
pLayerCfg.WindowY0 = 0;
|
||||
pLayerCfg.WindowY1 = 272;
|
||||
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB1555;
|
||||
pLayerCfg.Alpha = 255;
|
||||
pLayerCfg.Alpha0 = 0;
|
||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
||||
pLayerCfg.FBStartAdress = 0;
|
||||
pLayerCfg.ImageWidth = 480;
|
||||
pLayerCfg.ImageHeight = 272;
|
||||
pLayerCfg.Backcolor.Blue = 0;
|
||||
pLayerCfg.Backcolor.Green = 0;
|
||||
pLayerCfg.Backcolor.Red = 0;
|
||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
pLayerCfg1.WindowX0 = 0;
|
||||
pLayerCfg1.WindowX1 = 480;
|
||||
pLayerCfg1.WindowY0 = 0;
|
||||
pLayerCfg1.WindowY1 = 272;
|
||||
pLayerCfg1.PixelFormat = LTDC_PIXEL_FORMAT_ARGB1555;
|
||||
pLayerCfg1.Alpha = 255;
|
||||
pLayerCfg1.Alpha0 = 0;
|
||||
pLayerCfg1.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
||||
pLayerCfg1.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
||||
pLayerCfg1.FBStartAdress = 0;
|
||||
pLayerCfg1.ImageWidth = 480;
|
||||
pLayerCfg1.ImageHeight = 272;
|
||||
pLayerCfg1.Backcolor.Blue = 0;
|
||||
pLayerCfg1.Backcolor.Green = 0;
|
||||
pLayerCfg1.Backcolor.Red = 0;
|
||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg1, 1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN LTDC_Init 2 */
|
||||
|
||||
/* USER CODE END LTDC_Init 2 */
|
||||
/* USER CODE END LTDC_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QUADSPI Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_QUADSPI_Init(void)
|
||||
{
|
||||
* @brief QUADSPI Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_QUADSPI_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN QUADSPI_Init 0 */
|
||||
/* USER CODE BEGIN QUADSPI_Init 0 */
|
||||
|
||||
/* USER CODE END QUADSPI_Init 0 */
|
||||
/* USER CODE END QUADSPI_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN QUADSPI_Init 1 */
|
||||
/* USER CODE BEGIN QUADSPI_Init 1 */
|
||||
|
||||
/* USER CODE END QUADSPI_Init 1 */
|
||||
/* QUADSPI parameter configuration*/
|
||||
hqspi.Instance = QUADSPI;
|
||||
hqspi.Init.ClockPrescaler = 1;
|
||||
hqspi.Init.FifoThreshold = 4;
|
||||
hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
|
||||
hqspi.Init.FlashSize = 16;
|
||||
hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_6_CYCLE;
|
||||
hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
|
||||
hqspi.Init.FlashID = QSPI_FLASH_ID_1;
|
||||
hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
|
||||
if (HAL_QSPI_Init(&hqspi) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN QUADSPI_Init 2 */
|
||||
/* USER CODE END QUADSPI_Init 1 */
|
||||
/* QUADSPI parameter configuration*/
|
||||
hqspi.Instance = QUADSPI;
|
||||
hqspi.Init.ClockPrescaler = 1;
|
||||
hqspi.Init.FifoThreshold = 4;
|
||||
hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
|
||||
hqspi.Init.FlashSize = 16;
|
||||
hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_6_CYCLE;
|
||||
hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
|
||||
hqspi.Init.FlashID = QSPI_FLASH_ID_1;
|
||||
hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
|
||||
if (HAL_QSPI_Init(&hqspi) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN QUADSPI_Init 2 */
|
||||
|
||||
/* USER CODE END QUADSPI_Init 2 */
|
||||
/* USER CODE END QUADSPI_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_USART1_UART_Init(void)
|
||||
{
|
||||
* @brief USART1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_USART1_UART_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN USART1_Init 0 */
|
||||
/* USER CODE BEGIN USART1_Init 0 */
|
||||
|
||||
/* USER CODE END USART1_Init 0 */
|
||||
/* USER CODE END USART1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN USART1_Init 1 */
|
||||
/* USER CODE BEGIN USART1_Init 1 */
|
||||
|
||||
/* USER CODE END USART1_Init 1 */
|
||||
huart1.Instance = USART1;
|
||||
huart1.Init.BaudRate = 115200;
|
||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
||||
huart1.Init.Parity = UART_PARITY_NONE;
|
||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN USART1_Init 2 */
|
||||
/* USER CODE END USART1_Init 1 */
|
||||
huart1.Instance = USART1;
|
||||
huart1.Init.BaudRate = 115200;
|
||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
||||
huart1.Init.Parity = UART_PARITY_NONE;
|
||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||
if (HAL_UART_Init(&huart1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN USART1_Init 2 */
|
||||
|
||||
/* USER CODE END USART1_Init 2 */
|
||||
/* USER CODE END USART1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/* FMC initialization function */
|
||||
static void MX_FMC_Init(void)
|
||||
{
|
||||
static void MX_FMC_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN FMC_Init 0 */
|
||||
/* USER CODE BEGIN FMC_Init 0 */
|
||||
|
||||
/* USER CODE END FMC_Init 0 */
|
||||
/* USER CODE END FMC_Init 0 */
|
||||
|
||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
||||
FMC_SDRAM_TimingTypeDef SdramTiming = {0};
|
||||
|
||||
/* USER CODE BEGIN FMC_Init 1 */
|
||||
/* USER CODE BEGIN FMC_Init 1 */
|
||||
|
||||
/* USER CODE END FMC_Init 1 */
|
||||
/* USER CODE END FMC_Init 1 */
|
||||
|
||||
/** Perform the SDRAM1 memory initialization sequence
|
||||
*/
|
||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
||||
/* hsdram1.Init */
|
||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK1;
|
||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_1;
|
||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_DISABLE;
|
||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;
|
||||
/* SdramTiming */
|
||||
SdramTiming.LoadToActiveDelay = 16;
|
||||
SdramTiming.ExitSelfRefreshDelay = 16;
|
||||
SdramTiming.SelfRefreshTime = 16;
|
||||
SdramTiming.RowCycleDelay = 16;
|
||||
SdramTiming.WriteRecoveryTime = 16;
|
||||
SdramTiming.RPDelay = 16;
|
||||
SdramTiming.RCDDelay = 16;
|
||||
/** Perform the SDRAM1 memory initialization sequence
|
||||
*/
|
||||
hsdram1.Instance = FMC_SDRAM_DEVICE;
|
||||
/* hsdram1.Init */
|
||||
hsdram1.Init.SDBank = FMC_SDRAM_BANK1;
|
||||
hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
||||
hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
||||
hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16;
|
||||
hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
||||
hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_1;
|
||||
hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
||||
hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_DISABLE;
|
||||
hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE;
|
||||
hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;
|
||||
/* SdramTiming */
|
||||
SdramTiming.LoadToActiveDelay = 16;
|
||||
SdramTiming.ExitSelfRefreshDelay = 16;
|
||||
SdramTiming.SelfRefreshTime = 16;
|
||||
SdramTiming.RowCycleDelay = 16;
|
||||
SdramTiming.WriteRecoveryTime = 16;
|
||||
SdramTiming.RPDelay = 16;
|
||||
SdramTiming.RCDDelay = 16;
|
||||
|
||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
|
||||
{
|
||||
Error_Handler( );
|
||||
}
|
||||
if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN FMC_Init 2 */
|
||||
/* USER CODE BEGIN FMC_Init 2 */
|
||||
|
||||
/* USER CODE END FMC_Init 2 */
|
||||
/* USER CODE END FMC_Init 2 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOJ_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOK_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOI_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOJ_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOK_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOI_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_Port, LCD_BL_CTRL_Pin, GPIO_PIN_RESET);
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_Port, LCD_BL_CTRL_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOI, LED_Pin|LCD_DISP_Pin, GPIO_PIN_RESET);
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOI, LED_Pin | LCD_DISP_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : LCD_BL_CTRL_Pin */
|
||||
GPIO_InitStruct.Pin = LCD_BL_CTRL_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(LCD_BL_CTRL_GPIO_Port, &GPIO_InitStruct);
|
||||
/*Configure GPIO pin : LCD_BL_CTRL_Pin */
|
||||
GPIO_InitStruct.Pin = LCD_BL_CTRL_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(LCD_BL_CTRL_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : LED_Pin LCD_DISP_Pin */
|
||||
GPIO_InitStruct.Pin = LED_Pin|LCD_DISP_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
|
||||
/*Configure GPIO pins : LED_Pin LCD_DISP_Pin */
|
||||
GPIO_InitStruct.Pin = LED_Pin | LCD_DISP_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : BUTTON_Pin */
|
||||
GPIO_InitStruct.Pin = BUTTON_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(BUTTON_GPIO_Port, &GPIO_InitStruct);
|
||||
/*Configure GPIO pin : BUTTON_Pin */
|
||||
GPIO_InitStruct.Pin = BUTTON_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(BUTTON_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void) {
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1) {
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
|
||||
326
project/Core/Src/website_backend.c
Normal file
326
project/Core/Src/website_backend.c
Normal file
@@ -0,0 +1,326 @@
|
||||
/**
|
||||
* @file website_backend.h
|
||||
* @brief Backend for the website to operate
|
||||
* @author Toon B.
|
||||
*/
|
||||
|
||||
// Includes
|
||||
#include "website_backend.h"
|
||||
|
||||
// Static functions
|
||||
static size_t wbe_get_images(char* images_string, size_t file_count_fs);
|
||||
static inline void wbe_build_infostring(const llfs_file_t* file_list, char* info_string, const size_t cnt);
|
||||
static void wbe_decoding_url(const char* encoded, char* decoded);
|
||||
static uint32_t wbe_color_value(const char* rgb);
|
||||
|
||||
void wbe_init(void) {
|
||||
|
||||
httpd_init();
|
||||
LOG_DEBUG("WBE", "Initialize webserver");
|
||||
|
||||
// Set starting LCD screen
|
||||
wbe_display("Please Edit Me !", LCD_GREEN, LCD_BLACK, SD_IMG);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int fs_open_custom(struct fs_file* file, const char* name) {
|
||||
|
||||
// Variables
|
||||
llfs_file_t *wanted_file = llfs_file_open(name + 1);
|
||||
size_t buffer_len = 0;
|
||||
static char image_stringbuffer[STR_MAX] = "";
|
||||
|
||||
// The wanted file was found in the filesystem
|
||||
if (wanted_file != NULL) {
|
||||
|
||||
// Debug info
|
||||
LOG_DEBUG("WBE", "The file : %s was found", wanted_file->name);
|
||||
|
||||
// Give the information about the file to the client
|
||||
file->data = (const char*)wanted_file->data;
|
||||
file->len = (int)wanted_file->len;
|
||||
file->index = (int)wanted_file->len;
|
||||
file->is_custom_file = 1;
|
||||
file->pextension = NULL;
|
||||
file->flags = FS_FILE_FLAGS_HEADER_INCLUDED;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* The endpoint '/images.info' is called when the client wants to call for the
|
||||
* information string that contains the names of the available images.
|
||||
*/
|
||||
if (strncmp(name, "/images.info", strlen("/images.info")) == 0) {
|
||||
|
||||
// Create the information string for the images in the filesystem
|
||||
buffer_len = wbe_get_images(image_stringbuffer, llfs_file_count());
|
||||
|
||||
// Give the string back to the client
|
||||
file->data = image_stringbuffer;
|
||||
file->len = (int)buffer_len;
|
||||
file->index = (int)buffer_len;
|
||||
file->is_custom_file = 1;
|
||||
file->pextension = NULL;
|
||||
file->flags = FS_FILE_FLAGS_HEADER_INCLUDED;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Endpoint when client wants to send information to the backend
|
||||
if (strncmp(name, "/cgi", 3) == 0) {
|
||||
|
||||
// Give the original index.html back to the client
|
||||
wanted_file = llfs_file_open("index.html");
|
||||
|
||||
if (wanted_file != NULL) {
|
||||
file->data = (const char*)wanted_file->data;
|
||||
file->len = (int)wanted_file->len;
|
||||
file->index = (int)wanted_file->len;
|
||||
file->is_custom_file = 1;
|
||||
file->pextension = NULL;
|
||||
file->flags = FS_FILE_FLAGS_HEADER_INCLUDED;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fs_close_custom(struct fs_file* file) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void wbe_get_images(char*, size_t)
|
||||
* @brief Function searches filesystem for files with extention ".bmp" and ".gif" and put them
|
||||
* combined in a string that needs to be send to the frontend.
|
||||
*
|
||||
* @param[in] images_string, string that will contain the image names
|
||||
* @param[in] file_count_fs, the number of files in the filesystem
|
||||
*/
|
||||
static size_t wbe_get_images(char* images_string, size_t file_count_fs) {
|
||||
|
||||
// Allocate space for the files
|
||||
llfs_file_t file_list[file_count_fs];
|
||||
|
||||
size_t file_count_bmp = 0;
|
||||
size_t file_count_gif = 0;
|
||||
|
||||
// Reset string
|
||||
strcpy(images_string, "");
|
||||
|
||||
// Get all the ".bmp" and ".gif" files
|
||||
file_count_bmp = llfs_file_list(file_list, file_count_fs, ".bmp");
|
||||
file_count_gif = llfs_file_list(file_list + file_count_bmp, file_count_fs, ".gif");
|
||||
|
||||
// Create the info string
|
||||
wbe_build_infostring(file_list, images_string, file_count_gif + file_count_bmp);
|
||||
|
||||
// Debug info
|
||||
LOG_DEBUG("WBE", "Images string : %s ", images_string);
|
||||
|
||||
// Return the length of the string
|
||||
return strlen(images_string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void wbe_build_infostring(const llfs_file_t*, char*, const size_t)
|
||||
* @brief Function adds the names of the files in "file_list" and adds them in "infoStr".
|
||||
* The names are seperated by '|' characters.
|
||||
*
|
||||
* @param[in] file_list, list with files
|
||||
* @param[in] info_string, string that will contain the filenames
|
||||
* @param[in] cnt, the number of files
|
||||
*/
|
||||
static inline void wbe_build_infostring(const llfs_file_t* file_list, char* info_string, const size_t cnt) {
|
||||
|
||||
// Add the filenames to the info string
|
||||
for (size_t i = 0; i < cnt; ++i) {
|
||||
|
||||
strncat(info_string, file_list[i].name, strlen(file_list[i].name));
|
||||
strncat(info_string, "|", 2);
|
||||
}
|
||||
|
||||
//Remove last seperator '|'
|
||||
info_string[strlen(info_string) - 1] = '\0';
|
||||
|
||||
}
|
||||
|
||||
void httpd_cgi_handler(struct fs_file* file, const char* uri, int num_parm, char** pc_param, char** pc_value) {
|
||||
|
||||
// Variables
|
||||
uint32_t vktxt = LCD_GREEN;
|
||||
uint32_t vka = LCD_BLACK;
|
||||
|
||||
// Allocate space for parameters
|
||||
char vtxt[STR_MAX]; // The sentence that we want to print on the LCD.
|
||||
char vfo[STR_MAX]; // Name of the selected image on the website.
|
||||
char s_vktxt[CLR_MAX]; // The color of the sentence. (in #RGB)
|
||||
char s_vka[CLR_MAX]; // Color of the background. (also in #RGB)
|
||||
|
||||
if (strcmp("/cgi", uri) == 0) {
|
||||
|
||||
for (size_t i = 0; i < num_parm; ++i) {
|
||||
|
||||
// The given sentence
|
||||
if (strcmp("vtxt", pc_param[i]) == 0) {
|
||||
wbe_decoding_url(pc_value[i], vtxt);
|
||||
}
|
||||
|
||||
// The color of the sentence
|
||||
if (strcmp("vktxt", pc_param[i]) == 0) {
|
||||
wbe_decoding_url(pc_value[i], s_vktxt);
|
||||
|
||||
// Convert to hex value
|
||||
if (s_vktxt != NULL) {
|
||||
vktxt = wbe_color_value(s_vktxt);
|
||||
}
|
||||
}
|
||||
|
||||
// Color of the background
|
||||
if (strcmp("vka", pc_param[i]) == 0) {
|
||||
wbe_decoding_url(pc_value[i], s_vka);
|
||||
|
||||
// convert to hex value
|
||||
if (s_vka != NULL) {
|
||||
vka = wbe_color_value(s_vka);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Name of the image
|
||||
if (strcmp("vfo", pc_param[i]) == 0) {
|
||||
wbe_decoding_url(pc_value[i], vfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Debug info
|
||||
LOG_DEBUG("WBE", "CGI DATA : %s , %x , %x , %s", vtxt, vktxt, vka, vfo);
|
||||
|
||||
// Display on LCD
|
||||
wbe_display(vtxt, vktxt, vka, vfo);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void wbe_decoding_url(const char*, char*)
|
||||
* @brief The given information from the CGI parameters are URL encoded.
|
||||
* This function translates this encoded string in a readable
|
||||
* decoded string. The lengthe of "char* decoded" is at least the
|
||||
* length of "char* encoded" + 1.
|
||||
*
|
||||
* @param[in] encoded, the encoded URL string that needs to be decoded
|
||||
* @param[in] decoded, string that will contain the decoded URL.
|
||||
*/
|
||||
static void wbe_decoding_url(const char* encoded, char* decoded) {
|
||||
|
||||
// Variables
|
||||
char *endptr;
|
||||
size_t decoded_index = 0;
|
||||
size_t encoded_length = strlen(encoded);
|
||||
uint32_t hex_val;
|
||||
|
||||
for (size_t i = 0; i < encoded_length; ++i) {
|
||||
|
||||
// If we encounter a %xx, decode it to ascii
|
||||
if ((encoded[i] == '%') && (i + 2 < encoded_length)) {
|
||||
|
||||
// Decode %xx
|
||||
hex_val = (uint32_t)strtoul(&encoded[i + 1], &endptr, 16);
|
||||
|
||||
// Check for conversion errors
|
||||
if (endptr == &encoded[i + 1] || *endptr != '\0') {
|
||||
LOG_DEBUG("WBE", "URL text conversion error");
|
||||
}
|
||||
|
||||
decoded[decoded_index++] = (char)hex_val;
|
||||
|
||||
// Skip 2 characters
|
||||
i += 2;
|
||||
|
||||
// If we encounter a +, add a space character
|
||||
} else if (encoded[i] == '+') {
|
||||
|
||||
decoded[decoded_index++] = ' ';
|
||||
|
||||
// If no % or +, just put what stands in 'encoded'
|
||||
} else {
|
||||
|
||||
decoded[decoded_index++] = encoded[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Finish the string
|
||||
decoded[decoded_index] = '\0';
|
||||
|
||||
}
|
||||
|
||||
static uint32_t wbe_color_value(const char* rgb) {
|
||||
|
||||
// Variables
|
||||
char *endptr;
|
||||
uint32_t color = LCD_BLACK;
|
||||
char argb[11] = "0xff";
|
||||
|
||||
// Create argb string (also, skip the '#' char)
|
||||
strncat(argb, rgb + 1, strlen(rgb + 1));
|
||||
|
||||
// Get argb value
|
||||
color = (uint32_t)strtoul(argb, &endptr, 16);
|
||||
|
||||
// Check for conversion errors
|
||||
if (*endptr != '\0') {
|
||||
color = LCD_BLACK;
|
||||
LOG_DEBUG("WBE", "URL color conversion error");
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void wbe_display(const char* txt, const uint32_t txt_color, const uint32_t bg_color, const char* image) {
|
||||
|
||||
// Variables
|
||||
lcd_gif_t *gif;
|
||||
char *extension;
|
||||
|
||||
// clear the screen
|
||||
lcd_clear_text();
|
||||
lcd_clear_images();
|
||||
|
||||
// Display the text and the background
|
||||
lcd_set_bg_color_layer0(bg_color);
|
||||
lcd_display_text(txt, 10, 10, txt_color, bg_color, LCD_FONT16);
|
||||
|
||||
// Get the extension of the file
|
||||
extension = llfs_get_filename_ext(image);
|
||||
|
||||
// Check extension
|
||||
if (extension != NULL) {
|
||||
// Draw bmp
|
||||
if (strcmp(extension, "bmp") == 0) {
|
||||
lcd_draw_img_from_fs(image, IMG_X, IMG_Y);
|
||||
|
||||
// Draw gif
|
||||
} else if (strcmp(extension, "gif") == 0) {
|
||||
gif = lcd_draw_gif_from_fs(image, IMG_X, IMG_Y);
|
||||
|
||||
if (gif == NULL) {
|
||||
LOG_DEBUG("WBE", "GIF could not be drawn");
|
||||
}
|
||||
|
||||
// If nothing, then draw the standard image
|
||||
} else {
|
||||
lcd_draw_img_from_fs(SD_IMG, IMG_X, IMG_Y);
|
||||
}
|
||||
|
||||
// If nothing, then draw the standard image
|
||||
} else {
|
||||
lcd_draw_img_from_fs(SD_IMG, IMG_X, IMG_Y);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user