/* USER CODE BEGIN Header */ /** ****************************************************************************** * File Name : freertos.c * Description : Code for freertos applications ****************************************************************************** * @attention * * Copyright (c) 2022 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 "FreeRTOS.h" #include "task.h" #include "main.h" #include "cmsis_os.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "bsp_button.h" #include "bsp_display.h" #include "bsp_flash.h" #include "bsp_led.h" #include "bsp_print.h" #include "bsp_ribus.h" #include "bsp_sdcard.h" #include "bsp_sdcard.h" #include "demo.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN Variables */ /* USER CODE END Variables */ /* Definitions for defaultTask */ osThreadId_t defaultTaskHandle; const osThreadAttr_t defaultTask_attributes = { .name = "defaultTask", //.stack_size = 512 * 4, .stack_size = 4096 * 4, .priority = (osPriority_t) osPriorityNormal, }; /* Definitions for VideoTask */ osThreadId_t VideoTaskHandle; const osThreadAttr_t VideoTask_attributes = { .name = "VideoTask", .stack_size = 4096 * 4, .priority = (osPriority_t) osPriorityNormal, }; /* Definitions for TouchGFXTask */ osThreadId_t TouchGFXTaskHandle; const osThreadAttr_t TouchGFXTask_attributes = { .name = "TouchGFXTask", //.stack_size = 8192 * 4, .stack_size = 2048 * 4, .priority = (osPriority_t) osPriorityNormal, }; /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ /* USER CODE END FunctionPrototypes */ void StartDefaultTask(void *argument); extern void videoTaskFunc(void *argument); extern void TouchGFX_Task(void *argument); void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ /* Hook prototypes */ void vApplicationIdleHook(void); void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName); /* USER CODE BEGIN 2 */ void vApplicationIdleHook( void ) { /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle task. It is essential that code added to this hook function never attempts to block in any way (for example, call xQueueReceive() with a block time specified, or call vTaskDelay()). If the application makes use of the vTaskDelete() API function (as this demo application does) then it is also important that vApplicationIdleHook() is permitted to return to its calling function, because it is the responsibility of the idle task to clean up memory allocated by the kernel to any task that has since been deleted. */ } /* USER CODE END 2 */ /* USER CODE BEGIN 4 */ void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName) { /* Run time stack overflow checking is performed if configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is called if a stack overflow is detected. */ } /* USER CODE END 4 */ /** * @brief FreeRTOS initialization * @param None * @retval None */ void MX_FREERTOS_Init(void) { #if 0 /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* USER CODE BEGIN RTOS_MUTEX */ /* add mutexes, ... */ /* USER CODE END RTOS_MUTEX */ /* USER CODE BEGIN RTOS_SEMAPHORES */ /* add semaphores, ... */ /* USER CODE END RTOS_SEMAPHORES */ /* USER CODE BEGIN RTOS_TIMERS */ /* start timers, add new ones, ... */ /* USER CODE END RTOS_TIMERS */ /* USER CODE BEGIN RTOS_QUEUES */ /* add queues, ... */ /* USER CODE END RTOS_QUEUES */ #endif /* Create the thread(s) */ /* creation of TouchGFXTask */ TouchGFXTaskHandle = osThreadNew(TouchGFX_Task, NULL, &TouchGFXTask_attributes); /* creation of defaultTask */ defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); /* creation of VideoTask */ //VideoTaskHandle = osThreadNew(videoTaskFunc, NULL, &VideoTask_attributes); /* creation of TouchGFXTask */ //TouchGFXTaskHandle = osThreadNew(TouchGFX_Task, NULL, &TouchGFXTask_attributes); #if 0 /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ /* add events, ... */ /* USER CODE END RTOS_EVENTS */ #endif } #include #include "lvgl/lvgl.h" #include "lvgl/demos/lv_demos.h" #include "lvgl/examples/lv_examples.h" #include "sndbx/pages/sndbx_pges.h" uint32_t app_custom_tick_get(void) { return osKernelGetTickCount(); } #define XRES_MAX 1280 #define YRES_MAX 800 #if 0 #define XRES 800 #define YRES 480 #elif 0 #define XRES 768 #define YRES 480 #endif #ifndef XRES #define XRES XRES_MAX #endif #ifndef YRES #define YRES YRES_MAX #endif #define XOFS ((XRES_MAX-XRES)/2) #define YOFS ((YRES_MAX-YRES)/2) #define USE_DMA2D 1 #define USE_DMA2D_IT 1 #define FB_ADDRESS 0xd0000000 #if !USE_DMA2D static void disp_flush_memcpy( lv_disp_drv_t* drv, const lv_area_t* area, lv_color_t* p_color ) { if( 0 || area->x2 < 0 || area->y2 < 0 || area->x1 > (int32_t)(XRES-1) || area->y1 > (int32_t)(YRES-1) ) { lv_disp_flush_ready(drv); return; } /*Truncate the area to the screen*/ int32_t act_x1 = area->x1 < 0 ? 0 : area->x1; int32_t act_y1 = area->y1 < 0 ? 0 : area->y1; int32_t act_x2 = area->x2 > (int32_t)(XRES-1) ? (int32_t)(XRES-1) : area->x2; int32_t act_y2 = area->y2 > (int32_t)(YRES-1) ? (int32_t)(YRES-1) : area->y2; lv_coord_t w = (act_x2-act_x1+1); uint16_t *fb16 = (uint16_t*)FB_ADDRESS; for( int32_t y = act_y1; y <= act_y2; ++y ) { long location = (act_x1+XOFS) + (y+YOFS)*XRES_MAX*2/2; memcpy( &fb16[location], (uint32_t*)p_color, (act_x2-act_x1+1)*2 ); p_color += w; } lv_disp_flush_ready(drv); } #else static void disp_flush_DMA2D( lv_disp_drv_t* drv, const lv_area_t* area, lv_color_t* p_color ); #endif static void _indev_read ( lv_indev_drv_t *drv, lv_indev_data_t *data ) { extern bool STM32TouchController_sampleTouch(int32_t *x, int32_t *y); int32_t x, y; if( STM32TouchController_sampleTouch(&x, &y) ) { data->state = LV_INDEV_STATE_PRESSED; data->point.x = x-XOFS; data->point.y = y-YOFS; } else { data->state = LV_INDEV_STATE_RELEASED; } #if 0 if( data->state == LV_INDEV_STATE_PRESSED ) { if(!backlightOn) BacklightOn(); else backlightOnTmr = BL_TIMER; } #endif } static lv_disp_drv_t disp_drv; #define DISP_BUF_SIZE (30u*XRES_MAX) static void hal_init(void) { static lv_color_t buf[ DISP_BUF_SIZE ]; static lv_disp_draw_buf_t draw_buf; #if USE_DMA2D && USE_DMA2D_IT lv_disp_draw_buf_init( &draw_buf, &buf[0], &buf[DISP_BUF_SIZE/2], DISP_BUF_SIZE/2 ); #else lv_disp_draw_buf_init( &draw_buf, buf, NULL, DISP_BUF_SIZE ); #endif lv_disp_drv_init( &disp_drv ); disp_drv.draw_buf = &draw_buf; #if USE_DMA2D disp_drv.flush_cb = disp_flush_DMA2D; #else disp_drv.flush_cb = disp_flush_memcpy; #endif disp_drv.hor_res = XRES; disp_drv.ver_res = YRES; lv_disp_drv_register( &disp_drv ); //BacklightOn(); //indev_init(); static lv_indev_drv_t indev_drv_touch; lv_indev_drv_init( &indev_drv_touch ); indev_drv_touch.type = LV_INDEV_TYPE_POINTER; indev_drv_touch.read_cb = _indev_read; lv_indev_drv_register( &indev_drv_touch ); } #if USE_DMA2D //static DMA2D_HandleTypeDef hdma2d; extern DMA2D_HandleTypeDef hdma2d; static uint8_t CopyImageToLcdFrameBuffer( void *pSrc, void *pDst, uint32_t xSize, uint32_t ySize); /* Flush the content of the internal buffer the specific area on the display * You can use DMA or any hardware acceleration to do this operation in the background but * 'lv_disp_flush_ready()' has to be called when finished*/ void disp_flush_DMA2D(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *p_color) { if( 0 || area->x2 < 0 || area->y2 < 0 || area->x1 > (int32_t)(XRES-1) || area->y1 > (int32_t)(YRES-1) ) { lv_disp_flush_ready(drv); return; } SCB_CleanInvalidateDCache(); SCB_InvalidateICache(); uint32_t address = FB_ADDRESS + ( ((XRES_MAX*area->y1) + area->x1)*2 ) ; CopyImageToLcdFrameBuffer( (void*)p_color, (void*)address, lv_area_get_width(area), lv_area_get_height(area) ); } //static void disp_clean_dcache(lv_disp_drv_t *drv) //{ // SCB_CleanInvalidateDCache(); //} #if USE_DMA2D_IT static void DMA2D_XferCpltCallback(DMA2D_HandleTypeDef* handle) { (void)handle; lv_disp_flush_ready(&disp_drv); } #endif uint8_t CopyImageToLcdFrameBuffer( void *pSrc, void *pDst, uint32_t xSize, uint32_t ySize ) { /* Configure the DMA2D Mode, Color Mode and output offset */ hdma2d.Init.Mode = DMA2D_M2M_PFC; hdma2d.Init.ColorMode = DMA2D_OUTPUT_RGB565; /* Output color out of PFC */ hdma2d.Init.AlphaInverted = DMA2D_REGULAR_ALPHA; /* No Output Alpha Inversion*/ hdma2d.Init.RedBlueSwap = DMA2D_RB_REGULAR; /* No Output Red & Blue swap */ #if USE_DMA2D_IT hdma2d.XferCpltCallback = DMA2D_XferCpltCallback; #endif hdma2d.Init.OutputOffset = XRES - xSize; hdma2d.Instance = DMA2D; if( HAL_DMA2D_Init(&hdma2d) != HAL_OK ) { lv_disp_flush_ready(&disp_drv); return 0; } #if USE_DMA2D_IT HAL_DMA2D_Start_IT(&hdma2d, (uint32_t)pSrc, (uint32_t)pDst, xSize, ySize ); #else HAL_DMA2D_Start(&hdma2d, (uint32_t)pSrc, (uint32_t)pDst, xSize, ySize ); HAL_DMA2D_PollForTransfer(&hdma2d, 20); lv_disp_flush_ready(&disp_drv); #endif return 0; } #endif void BSP_Reset ( void ) { HAL_NVIC_SystemReset(); } /* USER CODE BEGIN Header_StartDefaultTask */ /** * @brief Function implementing the defaultTask thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_StartDefaultTask */ void StartDefaultTask(void *argument) { /* USER CODE BEGIN StartDefaultTask */ /* Infinite loop */ //osDelay(500); #if 0 for(;;) { osDelay(1000); #if 0 uint32_t *p = (uint32_t *)0xd0000000; uint32_t *q = &p[1280*800*2/4]; for( ; p < q; ++p ) *p = ~*p; #elif 0 uint32_t *p = (uint32_t *)0xd0000000; for( uint32_t i = 0; i < 1280*800*2/4; ++i ) p[i] = ~p[i]; #else static bool white; memset( (void*)0xd0000000, white?0x20:0x00, 1280*800*2 ); white = !white; #endif } #elif 1 lv_init(); hal_init(); //lv_demo_benchmark(); //lv_demo_music(); //lv_demo_widgets(); //lv_example_chart_1(); //lv_example_chart_2(); //lv_example_meter_1(); //sndbx_pge_lvgl_apps_test(); //sndbx_pge_lv_examples_test(); //sndbx_pge_lv_ex_widgets_test(); //sndbx_pge_lv_ex_get_started_test(); void sndbx_app_plasma_ctrl( void ); sndbx_app_plasma_ctrl(); for(;;) { uint32_t del = lv_task_handler(); osDelay( del<5 ? del : 5 ); } #else //DEMO_Initialize(); for(;;) { //DEMO_Run(); osDelay(5); } #endif /* USER CODE END StartDefaultTask */ } /* Private application code --------------------------------------------------*/ /* USER CODE BEGIN Application */ /* USER CODE END Application */