#include #include #include #include #include #include #include #define LCD_DEVICE "/dev/lcd2002" /* IOCTL command definition - must be consistent with the driver */ #define LCD_IOCTL_MAGIC 'L' #define LCD_IOCTL_CLEAR _IO(LCD_IOCTL_MAGIC, 0) #define LCD_IOCTL_HOME _IO(LCD_IOCTL_MAGIC, 1) #define LCD_IOCTL_SET_CURSOR _IOW(LCD_IOCTL_MAGIC, 2, struct lcd_pos) #define LCD_IOCTL_DISPLAY_CTRL _IOW(LCD_IOCTL_MAGIC, 3, unsigned char[3]) struct lcd_pos { unsigned char col; unsigned char row; }; /* Display control parameters */ #define DISPLAY_ON 0x04 #define DISPLAY_OFF 0x00 #define CURSOR_ON 0x02 #define CURSOR_OFF 0x00 #define BLINK_ON 0x01 #define BLINK_OFF 0x00 int fd; void test_basic_display(void) { printf("Test 1: Basic Display\n"); ioctl(fd, LCD_IOCTL_CLEAR); usleep(100000); write(fd, "Hello, Intel ADL!", 17); sleep(2); /* write to the second line */ struct lcd_pos pos = {0, 1}; ioctl(fd, LCD_IOCTL_SET_CURSOR, &pos); write(fd, "N97 Platform", 12); sleep(2); } void test_cursor_and_blink(void) { printf("Test 2: Cursor and Blink\n"); ioctl(fd, LCD_IOCTL_CLEAR); write(fd, "Cursor Test:", 12); struct lcd_pos pos = {0, 1}; ioctl(fd, LCD_IOCTL_SET_CURSOR, &pos); write(fd, "See me?", 7); /* Turn on the cursor */ unsigned char ctrl[3] = {DISPLAY_ON, CURSOR_ON, BLINK_OFF}; ioctl(fd, LCD_IOCTL_DISPLAY_CTRL, ctrl); sleep(2); /* Turn on the flashing */ ctrl[2] = BLINK_ON; ioctl(fd, LCD_IOCTL_DISPLAY_CTRL, ctrl); sleep(2); /* return to normal*/ ctrl[1] = CURSOR_OFF; ctrl[2] = BLINK_OFF; ioctl(fd, LCD_IOCTL_DISPLAY_CTRL, ctrl); } void test_long_text_wrap(void) { printf("Test 3: Text Wrapping\n"); ioctl(fd, LCD_IOCTL_CLEAR); /* Write more than 20 characters to test automatic line wrapping */ write(fd, "This is a long text that should wrap to next line automatically", 61); sleep(3); } void test_special_chars(void) { printf("Test 4: Special Characters\n"); ioctl(fd, LCD_IOCTL_CLEAR); write(fd, "Line1\nLine2", 11); /* \nShould wrap */ sleep(2); ioctl(fd, LCD_IOCTL_CLEAR); write(fd, "Test\rOverwrite", 14); /* \rshould press Enter */ sleep(2); } void test_full_display(void) { printf("Test 5: Full 20x2 Display\n"); ioctl(fd, LCD_IOCTL_CLEAR); char line1[21], line2[21]; int i; /* the first line of numbers */ for (i = 0; i < 20; i++) line1[i] = '0' + (i % 10); line1[20] = '\0'; /* The second letter */ for (i = 0; i < 20; i++) line2[i] = 'A' + (i % 26); line2[20] = '\0'; write(fd, line1, 20); struct lcd_pos pos = {0, 1}; ioctl(fd, LCD_IOCTL_SET_CURSOR, &pos); write(fd, line2, 20); sleep(3); } void test_clear_and_home(void) { printf("Test 6: Clear and Home\n"); ioctl(fd, LCD_IOCTL_CLEAR); write(fd, "Clear in 2 sec...", 17); sleep(2); ioctl(fd, LCD_IOCTL_CLEAR); write(fd, "Cleared!", 8); sleep(1); ioctl(fd, LCD_IOCTL_HOME); sleep(1); } int main(int argc, char *argv[]) { printf("LCD2002 Test Program\n"); printf("Opening %s...\n", LCD_DEVICE); fd = open(LCD_DEVICE, O_WRONLY); if (fd < 0) { perror("Failed to open LCD device"); printf("Please check: sudo modprobe lcd2002_drv\n"); printf("Or: sudo mknod /dev/lcd2002 c \n"); return 1; } printf("LCD opened successfully\n\n"); /* Run Test */ test_basic_display(); printf("\n"); test_cursor_and_blink(); printf("\n"); test_long_text_wrap(); printf("\n"); test_special_chars(); printf("\n"); test_full_display(); printf("\n"); test_clear_and_home(); printf("\n"); /* End Display */ ioctl(fd, LCD_IOCTL_CLEAR); write(fd, "Test Complete!", 14); struct lcd_pos pos = {4, 1}; ioctl(fd, LCD_IOCTL_SET_CURSOR, &pos); write(fd, "Goodbye!", 8); sleep(2); ioctl(fd, LCD_IOCTL_CLEAR); close(fd); printf("All tests completed.\n"); return 0; }