CPP를
C로 포팅한것
FAST AVR UTFT
Library for C
(Not CPP)
SSD1289 / HY32D
VERY FAST!!!!
NOT Fully validated yet !!!
TIP : Run ATMEGA128A at 3.3V !!!!
no need for 'LEVEL CONVERTER'
UTFT is written in CPP
and FAST AVR UTFT is written in CPP too
http://gizmogarage.net/fast-avr-utft/
==> need AStudio 3.x.x to Compile code
CPP to C convertion : by Andy : http://www.nerdkits.com/forum/thread/2790/
I do implemented Fast AVR-UTFT' into c
==================================
==================================
// All thanks goes to :
// -------------------------------------------------------
// UTFT.cpp - Arduino/chipKit library support for Color TFT LCD Boards
// - Copyright (C)2010-2014 Henning Karlsen. All right reserved
// - http://electronics.henningkarlsen.com/
// FAST AVR UTFT - Gizmo Garage :
// - Copyright 2013(c) Ron Bessems All right reserved
// - http://gizmogarage.net/fast-avr-utft/
// CPP to C convertion : Andyi
// - http://www.nerdkits.com/forum/thread/2790/
// - Origine : To control Sainsmart 3.2 tft lcd test script
// -----------------------------------------------------
// Copyright 2014(c) turbocrazy All right reserved :
// I do not responsible anything, use at your own risk
// - http://turbocrazy.tistory.com/
// -----------------------------------------------------
Atmega128A is running
TFT LCD - HY32D in 3.3V
Compile code with AStudio 3.x.x
===================================================
Some delay is inserted to make slower
Initial - TOO SLOW
Using FAST AVR UTFT - TOo FAST!!!
// ---------------------------------------------------------------------------- // 2014.05.19 : Initial AVR_HY32D.c // ---------------------------------------------------------------------------- #include#include #include "ssd1289HY32D.h" #include "DefaultFonts.h" #include "color.h" // ---------------------------------------------------------------------------- static void updateColor(col64bit hsv) { hsv.h +=50; if ( hsv.h > 4095 ){hsv.h = 0;} col32bit c = hsva2rgba(hsv); setColor(c.r, c.g, c.b); } // ---------------------------------------------------------------------------- int main(void){ LcdON(); // lcd on is not strictly necessary for SSD1289 Init_SSD1289(PORTRAIT); // lcd_init produces a fuzzy coloured screen if it works cfont.font=0; _transparent=false; setFont(BigFont); // Set font //cfont.x_size=fontbyte(0); //cfont.y_size=fontbyte(1); //cfont.offset=fontbyte(2); //cfont.numchars=fontbyte(3); col32bit c; c.r=0xee; c.g=0xa; c.b=0x43; col64bit hsv = rgba2hsva(c); do{ // some example drawing clrScr(); fillScr(VGA_YELLOW); _delay_ms(50); fillScr(VGA_BLUE); _delay_ms(50); setColor2(VGA_RED); fillCircle(100,150, 50); _delay_ms(50); setColor(0,255,0); drawCircle(100,200,50); drawRect(60,270,100,300); fillRect(120,270,180,300); drawRoundrect(60,60,120,10); fillRoundrect(130,60,200,10); _delay_ms(100); setColor2(VGA_SILVER); drawLine(1,1,239,319); drawPixel(130,280); drawPixel(131,280); drawPixel(132,280); drawPixel(130,281); drawPixel(131,281); drawPixel(132,281); drawPixel(130,282); drawPixel(131,282); drawPixel(132,282); _delay_ms(100); // draw a filled rectangle of changing color for us. fillRect(10,50, 100,100); // draw some lines, a circle and a box. int margin = 20; int w = getDisplayXSize() - margin; int h = getDisplayYSize() - margin ; int midx = w/2 + margin/2; int midy = h/2 + margin/2; drawLine(margin, margin, margin, h); drawLine(margin, margin, w, margin); drawLine(w, h, margin, h); drawLine(w, h, w, margin); drawCircle(midx, midy, 100); for (int x=margin; x<= w;x+=10){ updateColor(hsv); drawLine(midx,midy, x,h); } for (int y=margin; y<= h;y+=10){ updateColor(hsv); drawLine(midx,midy, w,y); } for (int x=margin; x<= w;x+=10){ updateColor(hsv); drawLine(midx,midy, x,margin); } for (int y=margin; y<= h;y+=10){ updateColor(hsv); drawLine(midx,midy, margin,y); } print("Hi Hack a Day", 10,10,0); _delay_ms(100); }while(1); return 0; } // ----------------------------------------------------------------------------
// ---------------------------------------------------------------------------- // All thanks gose to : // ---------------------------------------------------------------------------- // UTFT.cpp - Arduino/chipKit library support for Color TFT LCD Boards // - Copyright (C)2010-2014 Henning Karlsen. All right reserved // - http://electronics.henningkarlsen.com/ // FAST AVR UTFT - Gizmo Garage : // - Copyright 2013(c) Ron Bessems All right reserved // - http://gizmogarage.net/fast-avr-utft/ // CPP to C convertion : Andyi // - http://www.nerdkits.com/forum/thread/2790/ // - Origine : To control Sainsmart 3.2 tft lcd test script // ---------------------------------------------------------------------------- // Copyright 2014(c) turbocrazy All right reserved : // I do not responsible anything, use at your own risk // - http://turbocrazy.tistory.com/ // ---------------------------------------------------------------------------- // 2014.05.19 : Initial version // 2014.05.20 : Add & convert to FAST AVR TFT // ---------------------------------------------------------------------------- // MCU TFT GLCD - HY32D // PORTHI 15 - 8 // PORTLO 7 - 0 // CS - PD0 // RS - PD1 // WR - PD2 // RD - Should be tied high to 3.3v // RESET - PD4 : no use // BackLight - PD5 : no use // ALE - define for LATCHED 16 bit // SDA - define for SERIAL // SCL - define for SERIAL // other GLCD pins // GND -> 0V // VCC -> 5V // LEDA -> 3.3V // ---------------------------------------------------------------------------- #include "ssd1289HY32D.h" // ---------------------------------------------------------------------------- // LCD_Init // ---------------------------------------------------------------------------- void Init_SSD1289(byte orientation) { orient=orientation; // PORTRAIT or LANDSCAPE display_model=SSD1289; // SSD1289, SSD1289_8 or SSD1289LATCHED for 3.2" or ST7735 for 1.8" disp_x_size=239; disp_y_size=319; display_transfer_mode=16; // ---- from FAST AVR UFTF DATA_PORT_LOW_DDR = 0xff; DATA_PORT_HIGH_DDR = 0xff; RS_PORT_DDR |= _BV( RS_PIN); WR_PORT_DDR |= _BV(WR_PIN); CS_PORT_DDR |= _BV(CS_PIN); RD_PORT_DDR |= _BV(RD_PIN); RD_PORT |= _BV(RD_PIN); RESET_PORT_DDR |= _BV(RESET_PIN); BACK_LIGHT_PORT |= _BV(BACK_LIGHT_PIN); BACK_LIGHT_DDR |= _BV(BACK_LIGHT_PIN); sbi(RESET_PORT, RESET_PIN); _delay_ms(5); cbi(RESET_PORT, RESET_PIN); _delay_ms(15); sbi(RESET_PORT, RESET_PIN); _delay_ms(15); cbi(CS_PORT, CS_PIN); LCD_Write_COM_DATA(0x00,0x0001); LCD_Write_COM_DATA(0x03,0xA8A4); LCD_Write_COM_DATA(0x0C,0x0000); LCD_Write_COM_DATA(0x0D,0x080C); LCD_Write_COM_DATA(0x0E,0x2B00); LCD_Write_COM_DATA(0x1E,0x00B7); LCD_Write_COM_DATA(0x01,0x2B3F); LCD_Write_COM_DATA(0x02,0x0600); LCD_Write_COM_DATA(0x10,0x0000); LCD_Write_COM_DATA(0x11,0x6070); LCD_Write_COM_DATA(0x05,0x0000); LCD_Write_COM_DATA(0x06,0x0000); LCD_Write_COM_DATA(0x16,0xEF1C); LCD_Write_COM_DATA(0x17,0x0003); LCD_Write_COM_DATA(0x07,0x0233); LCD_Write_COM_DATA(0x0B,0x0000); LCD_Write_COM_DATA(0x0F,0x0000); LCD_Write_COM_DATA(0x41,0x0000); LCD_Write_COM_DATA(0x42,0x0000); LCD_Write_COM_DATA(0x48,0x0000); LCD_Write_COM_DATA(0x49,0x013F); LCD_Write_COM_DATA(0x4A,0x0000); LCD_Write_COM_DATA(0x4B,0x0000); LCD_Write_COM_DATA(0x44,0xEF00); LCD_Write_COM_DATA(0x45,0x0000); LCD_Write_COM_DATA(0x46,0x013F); LCD_Write_COM_DATA(0x30,0x0707); LCD_Write_COM_DATA(0x31,0x0204); LCD_Write_COM_DATA(0x32,0x0204); LCD_Write_COM_DATA(0x33,0x0502); LCD_Write_COM_DATA(0x34,0x0507); LCD_Write_COM_DATA(0x35,0x0204); LCD_Write_COM_DATA(0x36,0x0204); LCD_Write_COM_DATA(0x37,0x0502); LCD_Write_COM_DATA(0x3A,0x0302); LCD_Write_COM_DATA(0x3B,0x0302); LCD_Write_COM_DATA(0x23,0x0000); LCD_Write_COM_DATA(0x24,0x0000); LCD_Write_COM_DATA(0x25,0x8000); LCD_Write_COM_DATA(0x4f,0x0000); LCD_Write_COM_DATA(0x4e,0x0000); LCD_Write_COM(0x22); sbi(CS_PORT, CS_PIN); } // ---------------------------------------------------------------------------- void setColor(byte r, byte g, byte b) { fch=((r&248)|g>>5); fcl=((g&28)<<3|b>>3); } void setColor2(word color) { fch=(byte)(color>>8); fcl=(byte)(color&0xFF); } word getColor(void) { return (fch<<8) | fcl; } void setBackcolor(byte r, byte g, byte b) { bch=((r&248)|g>>5); bcl=((g&28)<<3|b>>3); _transparent=false; } void setBackcolor2(uint32_t color) { if (color==VGA_TRANSPARENT) _transparent=true; else{ bch=(byte)(color>>8); bcl=(byte)(color & 0xFF); _transparent=false; } } word getBackcolor(void) { return (bch<<8) | bcl; } void setXY(word x1, word y1, word x2, word y2) { if (orient==LANDSCAPE){ swap(word, x1, y1); swap(word, x2, y2) y1=disp_y_size-y1; y2=disp_y_size-y2; swap(word, y1, y2) } SSD1289_setXY(x1,y1,x2,y2,x1,y1); SSD1289_dataFollows(); } void clrXY(void) { if (orient==PORTRAIT) setXY(0,0,disp_x_size,disp_y_size); else setXY(0,0,disp_y_size,disp_x_size); } void clrScr(void) { cbi(CS_PORT, CS_PIN); SSD1289_setXY(0,0, 239, 319, 0, 0); SSD1289_reg11(0x6040 |ID1|ID0|AM); SSD1289_dataFollows(); DATA_PORT_LOW = 0x00; DATA_PORT_HIGH = 0; fastfill((uint32_t)76800); DATA_PORT_LOW = 0xff; DATA_PORT_HIGH = 0xff; cbi(CS_PORT, CS_PIN); } void setPixel(word color) { LCD_Write_DATA((color>>8),(color&0xFF)); // rrrrrggggggbbbbb } void drawPixel(int x, int y) { cbi(CS_PORT, CS_PIN); setXY(x, y, x, y); setPixel((fch<<8)|fcl); sbi(CS_PORT, CS_PIN); } void fillScr(word color) { unsigned char ch, cl; ch=color>>8; cl=color & 0xFF; cbi(CS_PORT, CS_PIN); SSD1289_setXY(0,0, 239, 319, 0, 0); SSD1289_reg11(0x6040 |ID1|ID0|AM); SSD1289_dataFollows(); DATA_PORT_LOW = cl; DATA_PORT_HIGH = ch; fastfill((uint32_t)320*240); DATA_PORT_LOW = 0xff; DATA_PORT_HIGH = 0xff; sbi(CS_PORT, CS_PIN); } void fillScr2(byte r, byte g, byte b) { word color = ((r&248)<<8 | (g&252)<<3 | (b&248)>>3); fillScr(color); } void drawHLine(int x, int y, int l) { if (l<0){ l = -l; x -= l; } cbi(CS_PORT, CS_PIN); setXY(x, y, x+l, y); _fast_fill_16(fch,fcl,l); sbi(CS_PORT, CS_PIN); } void drawVLine(int x, int y, int l) { if (l<0){ l = -l; y -= l; } cbi(CS_PORT, CS_PIN); setXY(x, y, x, y+l); _fast_fill_16(fch,fcl,l); sbi(CS_PORT, CS_PIN); } void drawLine(int xa, int ya, int xb, int yb) { if (ya==yb){ drawHLine(xa, ya, xb-xa); return; } if (xa==xb){ drawVLine(xa, ya, yb-ya); return; } if (orient==LANDSCAPE){ swap(uint16_t, xa, ya); swap(uint16_t, xb, yb); ya=disp_y_size-ya; yb=disp_y_size-yb; } uint16_t dx = (uint16_t) abs(xb - xa); uint16_t dy = (uint16_t) abs(yb - ya); cbi(CS_PORT, CS_PIN); SSD1289_setXY(0,0, 239, 319, xa, ya); if ( dx < dy ){ if ( ya < yb ){ if ( xa < xb ) { SSD1289_reg11(0x6040 |ID1|ID0|AM); SSD1289_dataFollows(); fastlineAPP(fcl | fch << 8, xa, xb, ya, yb, dx, dy); }else{ SSD1289_reg11(0x6040 |ID1|ID0|AM); SSD1289_dataFollows(); fastlineANP(fcl | fch << 8, xa, xb, ya, yb, dx, dy); } }else{ if ( xa < xb ){ SSD1289_reg11(0x6040|ID0|AM); SSD1289_dataFollows(); fastlineAPN(fcl | fch << 8, xa, xb, ya, yb, dx, dy); }else{ SSD1289_reg11(0x6040|ID0|AM); SSD1289_dataFollows(); fastlineANN(fcl | fch << 8, xa, xb, ya, yb, dx, dy); } } }else{ if ( ya < yb ){ if ( xa < xb ){ SSD1289_reg11(0x6040 |ID1|ID0); SSD1289_dataFollows(); fastlineBPP(fcl | fch << 8, xa, xb, ya, yb, dx, dy); }else{ SSD1289_reg11(0x6040 |ID1); SSD1289_dataFollows(); fastlineBNP(fcl | fch << 8, xa, xb, ya, yb, dx, dy); } }else{ if ( xa < xb ){ SSD1289_reg11(0x6040 |ID0); SSD1289_dataFollows(); fastlineBPN(fcl | fch << 8, xa, xb, ya, yb, dx, dy); }else{ SSD1289_reg11(0x6040 |ID1); SSD1289_dataFollows(); fastlineBNN(fcl | fch << 8, xa, xb, ya, yb, dx, dy); } } } sbi(CS_PORT, CS_PIN); } // ---------------------------------------------------------------------------- void drawCircle(int x, int y, int radius) { int f = 1 - radius; int ddF_x = 1; int ddF_y = -2 * radius; int x1 = 0; int y1 = radius; cbi(CS_PORT, CS_PIN); setXY(x, y + radius, x, y + radius); LCD_Write_DATA(fch,fcl); setXY(x, y - radius, x, y - radius); LCD_Write_DATA(fch,fcl); setXY(x + radius, y, x + radius, y); LCD_Write_DATA(fch,fcl); setXY(x - radius, y, x - radius, y); LCD_Write_DATA(fch,fcl); while(x1 < y1){ if(f >= 0){ y1--; ddF_y += 2; f += ddF_y; } x1++; ddF_x += 2; f += ddF_x; setXY(x + x1, y + y1, x + x1, y + y1); LCD_Write_DATA(fch,fcl); setXY(x - x1, y + y1, x - x1, y + y1); LCD_Write_DATA(fch,fcl); setXY(x + x1, y - y1, x + x1, y - y1); LCD_Write_DATA(fch,fcl); setXY(x - x1, y - y1, x - x1, y - y1); LCD_Write_DATA(fch,fcl); setXY(x + y1, y + x1, x + y1, y + x1); LCD_Write_DATA(fch,fcl); setXY(x - y1, y + x1, x - y1, y + x1); LCD_Write_DATA(fch,fcl); setXY(x + y1, y - x1, x + y1, y - x1); LCD_Write_DATA(fch,fcl); setXY(x - y1, y - x1, x - y1, y - x1); LCD_Write_DATA(fch,fcl); } sbi(CS_PORT, CS_PIN); clrXY(); } // ---------------------------------------------------------------------------- void fillCircle(int x, int y, int radius) { int y1; int x1; for(y1=-radius; y1<=0; y1++) for(x1=-radius; x1<=0; x1++) if(x1*x1+y1*y1 <= radius*radius){ drawHLine(x+x1, y+y1, 2*(-x1)); drawHLine(x+x1, y-y1, 2*(-x1)); break; } } void drawRect(int x1, int y1, int x2, int y2) { if (x1>x2) swap(int, x1, x2); if (y1>y2) swap(int, y1, y2); drawHLine(x1, y1, x2-x1); drawHLine(x1, y2, x2-x1); drawVLine(x1, y1, y2-y1); drawVLine(x2, y1, y2-y1); } void drawRoundrect(int x1, int y1, int x2, int y2) { if (x1>x2) swap(int, x1, x2); if (y1>y2) swap(int, y1, y2); if ((x2-x1)>4 && (y2-y1)>4){ drawPixel(x1+1,y1+1); drawPixel(x2-1,y1+1); drawPixel(x1+1,y2-1); drawPixel(x2-1,y2-1); drawHLine(x1+2, y1, x2-x1-4); drawHLine(x1+2, y2, x2-x1-4); drawVLine(x1, y1+2, y2-y1-4); drawVLine(x2, y1+2, y2-y1-4); } } void fillRect(int x1, int y1, int x2, int y2) { if (x1>x2) swap(int, x1, x2); if (y1>y2) swap(int, y1, y2); cbi(CS_PORT, CS_PIN); setXY(x1, y1, x2, y2); _fast_fill_16(fch,fcl,(((long)(x2-x1)+1)*((long)(y2-y1)+1))); cbi(CS_PORT, CS_PIN); } void fillRoundrect(int x1, int y1, int x2, int y2) { if (x1>x2) swap(int, x1, x2); if (y1>y2) swap(int, y1, y2); if ((x2-x1)>4 && (y2-y1)>4){ int i; for (i=0; i<((y2-y1)/2)+1; i++){ switch(i){ case 0: drawHLine(x1+2, y1+i, x2-x1-4); drawHLine(x1+2, y2-i, x2-x1-4); break; case 1: drawHLine(x1+1, y1+i, x2-x1-2); drawHLine(x1+1, y2-i, x2-x1-2); break; default: drawHLine(x1, y1+i, x2-x1); drawHLine(x1, y2-i, x2-x1); } } } } // lcd on void LcdON(void) { cbi(CS_PORT, CS_PIN); sbi(CS_PORT, CS_PIN); } // ---------------------------------------------------------------------------- void setFont(const uint8_t* font) { cfont.font=font; cfont.x_size=fontbyte(0); cfont.y_size=fontbyte(1); cfont.offset=fontbyte(2); cfont.numchars=fontbyte(3); } const uint8_t* getFont(void) { return cfont.font; } uint8_t getFontXsize(void) { return cfont.x_size; } uint8_t getFontYsize(void) { return cfont.y_size; } void drawBitmap(int x, int y, int sx, int sy, const bitmapdatatype data, int scale) { unsigned int col; int tx, ty, tsx, tsy; if (scale==1){ if (orient==PORTRAIT){ cbi(CS_PORT, CS_PIN); SSD1289_setXY(x,y, x+sx-1, y+sy-1, x, y); SSD1289_reg11(0x6040 |ID0|ID1); SSD1289_dataFollows(); fastbitmap_16bit(sx*sy, (const uint16_t)data); sbi(CS_PORT, CS_PIN); }else{ cbi(CS_PORT, CS_PIN); swap(uint16_t, x, y); swap(uint16_t, sx,sy); y=disp_y_size-y; SSD1289_setXY( x, y - (sy -1), ( x + sx - 1 ),y,x, y - (sy-1) ); SSD1289_reg11(0x6040 |ID0|AM); SSD1289_dataFollows(); fastbitmap_16bit(sx*sy, (const uint16_t)data); sbi(CS_PORT, CS_PIN); } }else{ if (orient==PORTRAIT){ cbi(CS_PORT, CS_PIN); for (ty=0; ty>8,col & 0xff); } } sbi(CS_PORT, CS_PIN); }else{ cbi(CS_PORT, CS_PIN); for (ty=0; ty =0; tx--){ col=pgm_read_word(&data[(ty*sx)+tx]); for (tsx=0; tsx >8,col & 0xff); } } } sbi(CS_PORT, CS_PIN); } } } void drawBitmapR(int x, int y, int sx, int sy, const bitmapdatatype data, int deg, int rox, int roy) { unsigned int col; int tx, ty, newx, newy; //byte r, g, b; double radian; radian=deg*0.0175; if (deg==0) drawBitmapPB(x, y, sx, sy, data); else{ cbi(CS_PORT, CS_PIN); for (ty=0; ty >8,col & 0xff); } sbi(CS_PORT, CS_PIN); } } void drawBitmapPB(int x, int y, int sx, int sy, const bitmapdatatype data) { //unsigned int col; //int tx, ty, tc, tsx, tsy; //byte r, g, b; if (orient==PORTRAIT){ cbi(CS_PORT, CS_PIN); SSD1289_setXY(x,y, x+sx-1, y+sy-1, x, y); SSD1289_reg11(0x6040 |ID0|ID1); SSD1289_dataFollows(); fastbitmap_pb565((const uint16_t)data); sbi(CS_PORT, CS_PIN); }else{ cbi(CS_PORT, CS_PIN); swap(uint16_t, x, y); swap(uint16_t, sx,sy); y=disp_y_size-y; SSD1289_setXY( x, y - (sy -1), ( x + sx - 1 ),y,x, y - (sy-1) ); SSD1289_reg11(0x6040 |ID0|AM); SSD1289_dataFollows(); fastbitmap_pb565((const uint16_t)data); sbi(CS_PORT, CS_PIN); } } void printChar(byte c, int x, int y) { word temp; cbi(CS_PORT, CS_PIN); if (orient==PORTRAIT){ temp=((c-cfont.offset)*((cfont.x_size/8)*cfont.y_size))+4; uint16_t x1 = x; uint16_t x2 = x + cfont.x_size -1; uint16_t y1 = y; uint16_t y2 = y+cfont.y_size-1; SSD1289_setXY(x1,y1, x2, y2, x1, y1); SSD1289_reg11(0x6040 |ID0|ID1); SSD1289_dataFollows(); fastbitmap_1bit(cfont.y_size * cfont.x_size/8, (uint16_t)cfont.font + temp,(fch<<8)|fcl,(bch<<8)|bcl); }else{ temp=((c-cfont.offset)*((cfont.x_size/8)*cfont.y_size))+4; uint16_t x1 = x; uint16_t x2 = x + cfont.x_size -1; uint16_t y1 = y; uint16_t y2 = y+cfont.y_size-1; swap(uint16_t, x1, y1); swap(uint16_t, x2, y2) y1=disp_y_size-y1; y2=disp_y_size-y2; swap(uint16_t, y1, y2) SSD1289_setXY(x1,y1, x2, y2, x1, y2); SSD1289_reg11(0x6040 |ID0|AM); SSD1289_dataFollows(); fastbitmap_1bit(cfont.y_size * cfont.x_size/8, (uint16_t)cfont.font + temp,(fch<<8)|fcl,(bch<<8)|bcl); } sbi(CS_PORT, CS_PIN); } void rotateChar(byte c, int x, int y, int pos, int deg) { byte i,j,ch; word temp; int newx,newy; double radian; radian=deg*0.0175; cbi(CS_PORT, CS_PIN); temp=((c-cfont.offset)*((cfont.x_size/8)*cfont.y_size))+4; for(j=0;j
'uAVR' 카테고리의 다른 글
AVR에서 MDF화일 저장 - ASAM MCD-2MC (0) | 2019.11.02 |
---|---|
도트매트릭 LED 제어루틴 (0) | 2017.02.09 |
GLCD FONT convert to use for LED DOT Matrix (0) | 2017.01.21 |
윤덕용 교수님의 한글 GLCD 라이브러리 - 하위 제어포트 살리기 (0) | 2017.01.21 |
윤덕용 교수의 한글 GLCD 라이브러리 수정 - 그래픽 기능 추가 (0) | 2017.01.21 |