Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for LCD hardware cursor #556

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 86 additions & 1 deletion src/ce/include/sys/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand Down Expand Up @@ -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
Expand Down