Last active
January 24, 2024 03:35
-
-
Save Kiterai/53415b13736ec8358b3cef01c899a595 to your computer and use it in GitHub Desktop.
practice code for Waveshare RP2040-LCD-1.28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// based on demo code https://www.waveshare.com/wiki/RP2040-LCD-1.28#Demo | |
#include "DEV_Config.h" | |
#include "GUI_Paint.h" | |
#include "LCD_1in28.h" | |
#include <stdio.h> | |
uint16_t gen_rgb565(uint16_t r, uint16_t g, uint16_t b) { | |
uint16_t code = 0; | |
code |= (r & 0b11111); | |
code <<= 6; | |
code |= (g & 0b111111); | |
code <<= 5; | |
code |= (b & 0b11111); | |
return code; | |
} | |
int main(void) { | |
if (DEV_Module_Init() != 0) | |
return -1; | |
LCD_1IN28_Init(HORIZONTAL); | |
LCD_1IN28_Clear(WHITE); | |
DEV_SET_PWM(60); // set backlight | |
UDOUBLE Imagesize = LCD_1IN28_HEIGHT * LCD_1IN28_WIDTH * 2; | |
UWORD *BlackImage; | |
if ((BlackImage = (UWORD *)malloc(Imagesize)) == NULL) | |
{ | |
printf("Failed to apply for black memory...\r\n"); | |
exit(0); | |
} | |
Paint_NewImage((UBYTE *)BlackImage, LCD_1IN28.WIDTH, LCD_1IN28.HEIGHT, 0, WHITE); | |
Paint_SetScale(65); | |
Paint_Clear(WHITE); | |
for (uint16_t y = 0; y < 240; y++) | |
for (uint16_t x = 0; x < 240; x++) | |
Paint_DrawPoint(x, y, gen_rgb565(x, y, 0), DOT_PIXEL_1X1, DOT_FILL_RIGHTUP); | |
LCD_1IN28_Display(BlackImage); | |
DEV_Delay_ms(1000); | |
while (true) | |
{ | |
DEV_Delay_ms(100); | |
} | |
free(BlackImage); | |
BlackImage = NULL; | |
DEV_Module_Exit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment