diff --git a/src/ce/include/sys/lcd.h b/src/ce/include/sys/lcd.h index 101256758..36199cf72 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,90 @@ extern "C" { /** Total size of VRAM in bytes */ #define LCD_SIZE (LCD_WIDTH*LCD_HEIGHT*2) +/** 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; \ +} while (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) \ +do { \ + lcd_CrsrConfig = ((lcd_CrsrConfig >> 1) << 1) | (size & 1); \ +} while (0) + +/** + * 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) \ +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. + * + * @param[in] x X coordinate. + * @param[in] y Y coordinate. + */ +#define lcd_CrsrSetPosition(x, y) \ +do { \ + lcd_CrsrX = x; \ + lcd_CrsrY = y; \ +} while (0) + +/** Shows the cursor. */ +#define lcd_CrsrShow() \ +do { \ + lcd_CrsrCtrl = 1; \ +} while (0) + +/** Hides the cursor. */ +#define lcd_CrsrHide() \ +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; \ +} while (0) + #ifdef __cplusplus } #endif