Add lcd_draw_img_from_llfs_file and lcd_draw_gif_from_llfs_file
This commit is contained in:
2023-12-03 22:01:14 +01:00
parent 0704473bc5
commit d77fca56b7
3 changed files with 57 additions and 1 deletions

View File

@@ -165,6 +165,7 @@ Note that when an image exceeds the X or Y size of the LCD display, the image wi
#### Drawing a BMP from the filesystem to the LCD
```c
void lcd_draw_img_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos);
void lcd_draw_img_from_llfs_file(llfs_file_t* file, uint32_t x_pos, uint32_t y_pos);
```
```c
@@ -175,10 +176,13 @@ void main(void) {
lcd_init(true);
...
lcd_draw_img_from_fs("st.bmp", 0, 0);
...
llfs_file_t* file = llfs_open("st.bmp");
lcd_draw_img_from_llfs_file(file, 50, 50);
}
```
This function expects the name of the BMP image as argument, together with the X and Y coordinates.
This function expects the name of the BMP image as argument or a pointer to the llfs_file_t struct, together with the X and Y coordinates.
Note that this function only works for BMP images and not raw images and when an image exceeds the X or Y size of the LCD display, the image will go out of the visible LCD area.
@@ -186,6 +190,7 @@ Note that this function only works for BMP images and not raw images and when an
```c
lcd_gif_t* lcd_draw_gif(uint8_t* src, size_t size, uint32_t x_pos, uint32_t y_pos);
lcd_gif_t* lcd_draw_gif_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos);
lcd_gif_t* lcd_draw_gif_from_llfs_file(llfs_file_t* file, uint32_t x_pos, uint32_t y_pos);
```
```c
#include "lcd_api.h"
@@ -201,6 +206,10 @@ void main(void) {
// From the filesystem
lcd_gif_t* gif = lcd_draw_gif_from_fs("st.gif", 0, 0);
// From a llfs_file_t struct
llfs_file_t* file = llfs_open("st.gif");
lcd_gif_t* gif = lcd_draw_gif_from_llfs_file(file, 0, 0);
if (gif == NULL) {
LOG_WARNING("GIF could not be drawn");
}

View File

@@ -145,6 +145,16 @@ void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos);
*/
void lcd_draw_img_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos);
/**
* @brief Draw BMP image on screen by specifying the llfs_file_t, the BMP image has in the file system
* Draw BMP image from C array to the LCD screen at position X, Y by specifying the BMP image name on the filesystem
* Supports ARGB8888, RGB565, RGB888
*
* @param file pointer to the llfs_file_t
* @param x_pos X-position
* @param y_pos Y-position
*/
void lcd_draw_img_from_llfs_file(llfs_file_t* file, uint32_t x_pos, uint32_t y_pos);
/**
* @brief Clear LCD text
* Clears the text drawn on the LCD screen
@@ -201,6 +211,19 @@ lcd_gif_t* lcd_draw_gif(uint8_t* src, size_t size, uint32_t x_pos, uint32_t y_po
*/
lcd_gif_t* lcd_draw_gif_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos);
/**
* @brief Draw GIF image on screen from filesystem
* Draw GIF image from filesystem to the LCD screen at position X, Y
* @warning If the GIF has a loop count specified, it will stop after the specified amount of loops and the lcd_git_t handle will be invalidated
* @note Before drawing over a GIF, make sure to call lcd_stop_gif(), otherwise the GIF will keep overwriting the screen
*
* @param file The pointer to the llfs_file_t
* @param x_pos The X position on the screen
* @param y_pos The Y position on the screen
* @return lcd_gif_t* A handle to the GIF image, NULL if the GIF could not be opened
*/
lcd_gif_t* lcd_draw_gif_from_llfs_file(llfs_file_t* file, uint32_t x_pos, uint32_t y_pos);
/**
* @brief Stop a GIF from playing
* Frees the GIF slot and stops the GIF from playing

View File

@@ -3,6 +3,7 @@
* @brief LCD API implementation
* @author Tim S.
* @author Lorenz C.
* @author Sander S.
*/
#include "lcd_api.h"
@@ -169,6 +170,16 @@ void lcd_draw_img_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos) {
LOG_WARN(TAG, "File \"%s\" not found", name);
}
void lcd_draw_img_from_llfs_file(llfs_file_t* file, uint32_t x_pos, uint32_t y_pos) {
LOG_INFO(TAG, "Displaying BMP image from llfs file: @x=%lu, @y=%lu", x_pos, y_pos);
BSP_LCD_SelectLayer(0);
if (file == NULL) {
LOG_WARN(TAG, "File not found");
return;
}
BSP_LCD_DrawBitmap(x_pos, y_pos, (uint8_t*)file->data);
}
void lcd_clear_text(void) {
LOG_INFO(TAG, "Clear text");
BSP_LCD_SelectLayer(1);
@@ -248,6 +259,19 @@ lcd_gif_t* lcd_draw_gif_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos
return gif;
}
lcd_gif_t* lcd_draw_gif_from_llfs_file(llfs_file_t* file, uint32_t x_pos, uint32_t y_pos) {
BSP_LCD_SelectLayer(0);
lcd_gif_t* gif;
if (file == NULL) {
LOG_WARN(TAG, "File not found");
return NULL;
}
// Draw the GIF using the file data
gif = lcd_draw_gif((uint8_t*)file->data, file->len, x_pos, y_pos);
return gif;
}
void lcd_stop_gif(lcd_gif_t* gif) {
free_gif_slot(gif);
}