From 93bdd14efbba2a3677cabce560f9060494b3c014 Mon Sep 17 00:00:00 2001 From: nitinseshadri <61258126+nitinseshadri@users.noreply.github.com> Date: Sat, 15 Mar 2025 12:11:35 -0400 Subject: [PATCH 1/2] Add API for hardware cursor --- src/ce/include/sys/lcd.h | 74 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/src/ce/include/sys/lcd.h b/src/ce/include/sys/lcd.h index 101256758..10d5e5074 100644 --- a/src/ce/include/sys/lcd.h +++ b/src/ce/include/sys/lcd.h @@ -2,7 +2,8 @@ * @file * @authors * Matt "MateoConLechuga" Waltz\n - * Jacob "jacobly" Young + * Jacob "jacobly" Young\n + * prime17569 * @brief CE PL111 LCD controller define file */ @@ -72,6 +73,77 @@ extern "C" { /** Total size of VRAM in bytes */ #define LCD_SIZE (LCD_WIDTH*LCD_HEIGHT*2) +/** Sets up the hardware cursor. */ +#define lcd_CrsrSetup() \ + lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(LCD_WIDTH - 1) << 16; \ + lcd_CrsrConfig = 0; \ + lcd_CrsrPalette0 = 0x00000000; \ + lcd_CrsrPalette1 = 0x00FFFFFF; \ + lcd_CrsrXY = 0; \ + lcd_CrsrClip = 0; + +/** + * Hardware cursor sizes. + */ +typedef enum { + LCD_CURSOR_SIZE_SMALL = 0, /**< Small size, 32x32, 256 bytes of packed 2bpp image data. */ + LCD_CURSOR_SIZE_LARGE = 1, /**< Large size, 64x64, 1024 bytes of packed 2bpp image data. */ +} lcd_cursor_size_t; + +/** + * Sets cursor size. + * + * @param[in] size The cursor size. + * @see lcd_cursor_size_t + */ +#define lcd_CrsrSetSize(size) \ + (lcd_CrsrConfig = ((lcd_CrsrConfig >> 1) << 1) | (size & 1)) + +/** + * Gets cursor size. + * + * @returns The cursor size. + * @see lcd_cursor_size_t + */ +#define lcd_CrsrGetSize() \ + ((lcd_cursor_size_t)(lcd_CrsrConfig & 1)) + +/** + * Sets cursor image. + * + * @param[in] data A pointer to 256 or 1024 bytes of packed 2bpp image data. + * @see lcd_cursor_size_t + * + * @note + * To use convimg to create the required data, add `bpp: 2` + * to the converts section in convimg.yaml corresponding + * to your image(s). + */ +#define lcd_CrsrSetImage(data) \ + (memcpy(lcd_CrsrImage, data, lcd_CrsrGetSize() == LCD_CURSOR_SIZE_LARGE ? lcd_CrsrImageLen64 : lcd_CrsrImageLen32)) + +/** + * Sets the position of the cursor on screen. + * + * @param[in] x X coordinate. + * @param[in] y Y coordinate. + */ +#define lcd_CrsrSetPosition(x, y) \ + lcd_CrsrX = x; \ + lcd_CrsrY = y; + +/** Shows the cursor. */ +#define lcd_CrsrShow() \ + lcd_CrsrCtrl = 1; + +/** Hides the cursor. */ +#define lcd_CrsrHide() \ + lcd_CrsrCtrl = 0; + +#define lcd_CrsrCleanup() \ + lcd_CrsrHide(); \ + lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(LCD_HEIGHT - 1) << 16; + #ifdef __cplusplus } #endif From 7d2d87767b81414ff62ba639b164de493c99ebd1 Mon Sep 17 00:00:00 2001 From: nitinseshadri <61258126+nitinseshadri@users.noreply.github.com> Date: Sat, 15 Mar 2025 14:02:07 -0400 Subject: [PATCH 2/2] Wrap macros in do-while construct as needed --- src/ce/include/sys/lcd.h | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/ce/include/sys/lcd.h b/src/ce/include/sys/lcd.h index 10d5e5074..36199cf72 100644 --- a/src/ce/include/sys/lcd.h +++ b/src/ce/include/sys/lcd.h @@ -75,12 +75,14 @@ extern "C" { /** Sets up the hardware cursor. */ #define lcd_CrsrSetup() \ +do { \ lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(LCD_WIDTH - 1) << 16; \ lcd_CrsrConfig = 0; \ lcd_CrsrPalette0 = 0x00000000; \ lcd_CrsrPalette1 = 0x00FFFFFF; \ lcd_CrsrXY = 0; \ - lcd_CrsrClip = 0; + lcd_CrsrClip = 0; \ +} while (0) /** * Hardware cursor sizes. @@ -97,7 +99,9 @@ typedef enum { * @see lcd_cursor_size_t */ #define lcd_CrsrSetSize(size) \ - (lcd_CrsrConfig = ((lcd_CrsrConfig >> 1) << 1) | (size & 1)) +do { \ + lcd_CrsrConfig = ((lcd_CrsrConfig >> 1) << 1) | (size & 1); \ +} while (0) /** * Gets cursor size. @@ -105,8 +109,7 @@ typedef enum { * @returns The cursor size. * @see lcd_cursor_size_t */ -#define lcd_CrsrGetSize() \ - ((lcd_cursor_size_t)(lcd_CrsrConfig & 1)) +#define lcd_CrsrGetSize() ((lcd_cursor_size_t)(lcd_CrsrConfig & 1)) /** * Sets cursor image. @@ -120,7 +123,9 @@ typedef enum { * to your image(s). */ #define lcd_CrsrSetImage(data) \ - (memcpy(lcd_CrsrImage, data, lcd_CrsrGetSize() == LCD_CURSOR_SIZE_LARGE ? lcd_CrsrImageLen64 : lcd_CrsrImageLen32)) +do { \ + memcpy(lcd_CrsrImage, data, lcd_CrsrGetSize() == LCD_CURSOR_SIZE_LARGE ? lcd_CrsrImageLen64 : lcd_CrsrImageLen32); \ +} while (0) /** * Sets the position of the cursor on screen. @@ -129,20 +134,28 @@ typedef enum { * @param[in] y Y coordinate. */ #define lcd_CrsrSetPosition(x, y) \ +do { \ lcd_CrsrX = x; \ - lcd_CrsrY = y; + lcd_CrsrY = y; \ +} while (0) /** Shows the cursor. */ #define lcd_CrsrShow() \ - lcd_CrsrCtrl = 1; +do { \ + lcd_CrsrCtrl = 1; \ +} while (0) /** Hides the cursor. */ #define lcd_CrsrHide() \ - lcd_CrsrCtrl = 0; +do { \ + lcd_CrsrCtrl = 0; \ +} while (0) #define lcd_CrsrCleanup() \ +do { \ lcd_CrsrHide(); \ - lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(LCD_HEIGHT - 1) << 16; + lcd_Timing2 = (uint32_t)(lcd_Timing2 & ~(uint32_t)0x03FF0000) | (uint32_t)(LCD_HEIGHT - 1) << 16; \ +} while (0) #ifdef __cplusplus }