void lcd_draw_string(int x, int y, char *str) { printf("lcd draw string: %s\n", str); unsigned char cmd[3] = { 0xDB, 0, 0 }; cmd[2] = x; cmd[1] = y; lcd_send_data(cmd, 3); lcd_send_data((unsigned char*)str, strlen(str)); lcd_send_byte('\0'); lcd_delay(); return; int i = 0; while (*str != '\0') { lcd_send_data((unsigned char *)str, 1); ++str; ++i; if (i % 16 == 0 && *str != '\0') { lcd_send_byte('\0'); usleep(1000); cmd[2] = (x+i)*5; lcd_send_data(cmd, 3); } } lcd_send_byte('\0'); lcd_delay(); }
void lcd_int_disp(int16_t number) { uint16_t divider; uint16_t tmp; //value of the oldest digit in number if(number < 0) { lcd_send_data('-'); number -= 2*number; } _Bool previous_displayed=0; //10000 means that highest displayed number has 5 digits + sign for(divider = 10000;divider >0;divider/=10) { tmp = number/divider; if(tmp == 0 && previous_displayed==0) continue; previous_displayed=1; lcd_send_data('0'+tmp); number -= tmp*divider; } }
void lcd_init_device(void) { lcd_send_reg(LCD_REG_UNKNOWN_00); lcd_send_data(0x00); lcd_send_reg(LCD_REG_UNKNOWN_01); lcd_send_data(0x48); lcd_send_reg(LCD_REG_UNKNOWN_05); lcd_send_data(0x0f); x_offset = 16; }
void lcd_draw_image(int x, int y, int width, int height, unsigned char *data) { unsigned char cmd[] = { 0xFD, 0, 0, 0, 0 }; int width_bytes = (width+7) / 8; cmd[1] = y; cmd[2] = x; cmd[3] = width_bytes; cmd[4] = height; lcd_send_data(cmd, 5); lcd_send_data(data, width_bytes*height); lcd_delay(); }
void lcd_text(char txt[]) { unsigned char c; while( (c = *(txt++)) != 0x00 ) lcd_send_data(c); }
/* turn the display upside down (call lcd_update() afterwards) */ void lcd_set_flip(bool yesno) { int flip = (yesno) ? 0x88 : 0x48; x_offset = (yesno) ? 4 : 16; lcd_send_reg(LCD_REG_UNKNOWN_01); lcd_send_data(flip); }
void lcd_print(long num, const int waitms) { char buffer[20]; char *bufferp = buffer; int len = 0; long temp = num; while ( temp ) { ++len; temp /= 10; } if ( !len ) { buffer[0] = '0'; buffer[1] = 0; } else while ( num ) { buffer[len] = 0; for ( int i=len-1 ; i>=0 ; --i ) { buffer[i] = '0' + num%10; num /= 10; } } while ( *bufferp ) { lcd_send_data( *(bufferp++) ); if ( waitms ) delay_ms(waitms); } }
static void ipod_update_display(struct display *p, int sx, int sy, int mx, int my) { unsigned short cursor_pos; unsigned short y; cursor_pos = sx + (sy * fontheight(p) * 0x20); for ( y = sy * fontheight(p); y < my * fontheight(p); y++ ) { unsigned char *img_data; unsigned char x; /* move the cursor */ lcd_cmd_and_data(0x11, cursor_pos >> 8, cursor_pos & 0xff); /* setup for printing */ lcd_prepare_cmd(0x12); /* cursor pos * image data width */ img_data = &ipod_scr[y * p->line_length + sx * 2]; /* 160/8 -> 20 == loops 20 times */ for ( x = sx; x < mx; x++ ) { /* display a character */ lcd_send_data(*(img_data + 1), *img_data); img_data += 2; } /* update cursor pos counter */ cursor_pos += 0x20; } }
/* send LCD command and data */ static void lcd_cmd_and_data(int cmd, int data_lo, int data_hi) { lcd_prepare_cmd(cmd); lcd_send_data(data_lo, data_hi); }
void lcd_print(const char *str, const int waitms) { for ( int i=0 ; str[i] ; ++i ) { lcd_send_data( str[i] ); if ( waitms ) delay_ms(waitms); } }
void lcd_str_disp(const char string[]) { while(*string != '\0') { lcd_send_data(*string); string++; } }
void lcd_str_disp_delay(const char string[]) { while(*string != '\0') { lcd_send_data(*string); string++; _delay_ms(100); } }
void lcd_port_disp(char port_number) { uint8_t port_val; port_number=toupper(port_number); uint8_t flag; switch(port_number) { case 'A': port_val = PORTA; break; case 'B': port_val = PORTB; break; case 'C': port_val = PORTC; break; case 'D': port_val = PORTD; break; default : port_val = 0x00; break; } lcd_clr(); lcd_set_pos2(&beg); lcd_str_disp("PORT"); lcd_send_data(port_number); lcd_set_pos2(&line2); lcd_str_disp("0b"); //displays bits from highest to lowest for(flag = 0x80; flag > 0; flag >>= 1 ) { if(port_val & flag) lcd_send_data('1'); else lcd_send_data('0'); } }
void lcd_set_backlight(int open) { unsigned char cmd[] = { 0xB5, 0x00 }; cmd[1] = open == 0 ? 0 : 1; lcd_send_data(cmd, 2); lcd_delay(); }
void screen_update(void) { lcd_send_data(screen_buffer); }
/* Performance function to blit a YUV bitmap directly to the LCD */ void lcd_blit_yuv(unsigned char * const src[3], int src_x, int src_y, int stride, int x, int y, int width, int height) { int h; width = (width + 1) & ~1; lcd_send_reg(LCD_REG_HORIZ_ADDR_START); lcd_send_data(y); lcd_send_reg(LCD_REG_HORIZ_ADDR_END); lcd_send_data(y + height - 1); lcd_send_reg(LCD_REG_VERT_ADDR_START); lcd_send_data(x + x_offset); lcd_send_reg(LCD_REG_VERT_ADDR_END); lcd_send_data(x + width - 1 + x_offset); lcd_send_reg(LCD_REG_WRITE_DATA_2_GRAM); const int stride_div_csub_x = stride/CSUB_X; h=0; while (1) { /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */ const unsigned char *ysrc = src[0] + stride * src_y + src_x; const int uvoffset = stride_div_csub_x * (src_y/CSUB_Y) + (src_x/CSUB_X); const unsigned char *usrc = src[1] + uvoffset; const unsigned char *vsrc = src[2] + uvoffset; int pixels_to_write; if (h==0) { while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_READY)); LCD2_BLOCK_CONFIG = 0; if (height == 0) break; pixels_to_write = (width * height) * 2; h = height; /* calculate how much we can do in one go */ if (pixels_to_write > 0x10000) { h = (0x10000/2) / width; pixels_to_write = (width * h) * 2; } height -= h; LCD2_BLOCK_CTRL = 0x10000080; LCD2_BLOCK_CONFIG = 0xc0010000 | (pixels_to_write - 1); LCD2_BLOCK_CTRL = 0x34000000; } lcd_yuv_write_inner_loop(ysrc,usrc,vsrc,width); src_y++; h--; } while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_READY)); LCD2_BLOCK_CONFIG = 0; }
void lcd_char_disp(char unsigned sign) { lcd_send_data((uint8_t)sign); }
void lcd_set_invert_display(bool yesno) { int invert = (yesno) ? 0x40 : 0x00; lcd_send_reg(LCD_REG_UNKNOWN_00); lcd_send_data(invert); }
/* Update a fraction of the display. */ void lcd_update_rect(int x, int y, int width, int height) { unsigned long *addr; int new_x, new_width; /* Ensure x and width are both even - so we can read 32-bit aligned data from lcd_framebuffer */ new_x = x&~1; new_width = width&~1; if (new_x+new_width < x+width) new_width += 2; x = new_x; width = new_width; if (x + width >= LCD_WIDTH) width = LCD_WIDTH - x; if (y + height >= LCD_HEIGHT) height = LCD_HEIGHT - y; if ((width <= 0) || (height <= 0)) return; /* Nothing left to do. */ lcd_send_reg(LCD_REG_HORIZ_ADDR_START); lcd_send_data(y); lcd_send_reg(LCD_REG_HORIZ_ADDR_END); lcd_send_data(y + height - 1); lcd_send_reg(LCD_REG_VERT_ADDR_START); lcd_send_data(x + x_offset); lcd_send_reg(LCD_REG_VERT_ADDR_END); lcd_send_data(x + width - 1 + x_offset); lcd_send_reg(LCD_REG_WRITE_DATA_2_GRAM); addr = (unsigned long*)&lcd_framebuffer[y][x]; while (height > 0) { int c, r; int h, pixels_to_write; pixels_to_write = (width * height) * 2; h = height; /* calculate how much we can do in one go */ if (pixels_to_write > 0x10000) { h = (0x10000/2) / width; pixels_to_write = (width * h) * 2; } LCD2_BLOCK_CTRL = 0x10000080; LCD2_BLOCK_CONFIG = 0xc0010000 | (pixels_to_write - 1); LCD2_BLOCK_CTRL = 0x34000000; /* for each row */ for (r = 0; r < h; r++) { /* for each column */ for (c = 0; c < width; c += 2) { while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_TXOK)); /* output 2 pixels */ LCD2_BLOCK_DATA = *addr++; } addr += (LCD_WIDTH - width)/2; } while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_READY)); LCD2_BLOCK_CONFIG = 0; height -= h; } }
static void lcd_write_reg(unsigned cmd, unsigned data) { lcd_send_cmd(cmd); lcd_send_data(data); }
static void lcd_write_reg_ex(unsigned cmd, unsigned data0, unsigned data1) { lcd_send_cmd(cmd); lcd_send_data(data0); lcd_send_data(data1); }
void lcd_int2(unsigned char val) { lcd_send_data( (val / 10)%10 + '0'); lcd_send_data( (val % 10) + '0'); }
void lcd_char(unsigned char letter) { lcd_send_data(letter); }
void lcd_clear(int fd) { unsigned char cmd[] = { 0xF4, 0xBB, 0xBB, 0xBB }; lcd_send_data(cmd, 4); lcd_delay(); }
void lcd_text_P(PGM_P txt) { unsigned char c; while ((c = pgm_read_byte(txt++))) lcd_send_data(c); }
void lcd_show_logo(void) { lcd_send_data(logo_data); }