182 lines
4.8 KiB
C
182 lines
4.8 KiB
C
/**
|
|
* @file lv_port_disp_templ.c
|
|
*
|
|
*/
|
|
|
|
/*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
|
|
#if 1
|
|
|
|
/*********************
|
|
* INCLUDES
|
|
*********************/
|
|
#include "lv_port_disp.h"
|
|
#include <stdbool.h>
|
|
|
|
#include "stm32f4xx_hal.h"
|
|
#include "lcd.h"
|
|
|
|
#define MY_DISP_HOR_RES LV_HOR_RES_MAX
|
|
#define MY_DISP_VER_RES LV_VER_RES_MAX
|
|
|
|
/*********************
|
|
* DEFINES
|
|
*********************/
|
|
#ifndef MY_DISP_HOR_RES
|
|
#warning Please define or replace the macro MY_DISP_HOR_RES with the actual screen width, default value 320 is used for now.
|
|
#define MY_DISP_HOR_RES 320
|
|
#endif
|
|
|
|
#ifndef MY_DISP_VER_RES
|
|
#warning Please define or replace the macro MY_DISP_HOR_RES with the actual screen height, default value 240 is used for now.
|
|
#define MY_DISP_VER_RES 240
|
|
#endif
|
|
|
|
/**********************
|
|
* TYPEDEFS
|
|
**********************/
|
|
|
|
/**********************
|
|
* STATIC PROTOTYPES
|
|
**********************/
|
|
static void disp_init(void);
|
|
|
|
static void disp_flush(lv_display_t * disp, const lv_area_t * area, uint8_t * px_map);
|
|
//static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
|
|
// const lv_area_t * fill_area, lv_color_t color);
|
|
|
|
/**********************
|
|
* STATIC VARIABLES
|
|
**********************/
|
|
|
|
/**********************
|
|
* MACROS
|
|
**********************/
|
|
|
|
/**********************
|
|
* GLOBAL FUNCTIONS
|
|
**********************/
|
|
|
|
void lv_port_disp_init(void)
|
|
{
|
|
/*-------------------------
|
|
* Initialize your display
|
|
* -----------------------*/
|
|
disp_init();
|
|
|
|
/*-----------------------------
|
|
* Create a buffer for drawing
|
|
*----------------------------*/
|
|
lv_display_t * lcd_disp = lv_display_create(MY_DISP_HOR_RES,MY_DISP_VER_RES);
|
|
lv_display_set_flush_cb(lcd_disp,disp_flush);
|
|
|
|
uint8_t * buf1 = NULL;
|
|
uint8_t * buf2 = NULL;
|
|
|
|
uint32_t buf_size = MY_DISP_HOR_RES * MY_DISP_VER_RES / 10 * lv_color_format_get_size(lv_display_get_color_format(
|
|
lcd_disp));
|
|
|
|
buf1 = lv_malloc(buf_size);
|
|
if(buf1 == NULL) {
|
|
LV_LOG_ERROR("display draw buffer malloc failed");
|
|
return;
|
|
}
|
|
|
|
buf2 = lv_malloc(buf_size);
|
|
if(buf2 == NULL) {
|
|
LV_LOG_ERROR("display buffer malloc failed");
|
|
lv_free(buf1);
|
|
return;
|
|
}
|
|
lv_display_set_buffers(lcd_disp, buf1, buf2, buf_size, LV_DISPLAY_RENDER_MODE_PARTIAL);
|
|
|
|
}
|
|
|
|
/**********************
|
|
* STATIC FUNCTIONS
|
|
**********************/
|
|
|
|
/*Initialize your display and the required peripherals.*/
|
|
static void disp_init(void)
|
|
{
|
|
/*You code here*/
|
|
LCD_Init();
|
|
}
|
|
|
|
volatile bool disp_flush_enabled = true;
|
|
|
|
/* Enable updating the screen (the flushing process) when disp_flush() is called by LVGL
|
|
*/
|
|
void disp_enable_update(void)
|
|
{
|
|
disp_flush_enabled = true;
|
|
}
|
|
|
|
/* Disable updating the screen (the flushing process) when disp_flush() is called by LVGL
|
|
*/
|
|
void disp_disable_update(void)
|
|
{
|
|
disp_flush_enabled = false;
|
|
}
|
|
|
|
/*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.*/
|
|
static void disp_flush(lv_display_t * disp, const lv_area_t * area, uint8_t * px_map)
|
|
{
|
|
if(disp_flush_enabled) {
|
|
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
|
|
|
|
|
|
int32_t x;
|
|
int32_t y;
|
|
|
|
uint16_t *color = (uint16_t *)px_map;
|
|
|
|
|
|
for(y = area->y1; y <= area->y2; y++) {
|
|
for(x = area->x1; x <= area->x2; x++) {
|
|
/*Put a pixel to the display. For example:*/
|
|
/*put_px(x, y, *color_p)*/
|
|
|
|
LCD_DrawPoint(x,y,*color);
|
|
color++;
|
|
}
|
|
}
|
|
|
|
//LCD_Fill(area->x1,area->y1,area->x2,area->y2,(uint16_t)color_p->full);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/*IMPORTANT!!!
|
|
*Inform the graphics library that you are ready with the flushing*/
|
|
lv_disp_flush_ready(disp);
|
|
}
|
|
|
|
/*OPTIONAL: GPU INTERFACE*/
|
|
|
|
/*If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color*/
|
|
//static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
|
|
// const lv_area_t * fill_area, lv_color_t color)
|
|
//{
|
|
// /*It's an example code which should be done by your GPU*/
|
|
// int32_t x, y;
|
|
// dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
|
|
//
|
|
// for(y = fill_area->y1; y <= fill_area->y2; y++) {
|
|
// for(x = fill_area->x1; x <= fill_area->x2; x++) {
|
|
// dest_buf[x] = color;
|
|
// }
|
|
// dest_buf+=dest_width; /*Go to the next line*/
|
|
// }
|
|
//}
|
|
|
|
|
|
#else /*Enable this file at the top*/
|
|
|
|
/*This dummy typedef exists purely to silence -Wpedantic.*/
|
|
typedef int keep_pedantic_happy;
|
|
#endif
|