/* * File: digole.h * Author: guihongsun * * Created on March 16, 2014, 5:54 PM */ #ifndef DIGOLE_H #define DIGOLE_H #ifdef __cplusplus extern "C" { #endif #include #include #include typedef uint8_t u8g_uint_t; typedef int8_t u8g_int_t; typedef const unsigned char u8g_pgm_uint8_t; typedef const unsigned char u8g_fntpgm_uint8_t; #define U8G_FONT_HEIGHT_MODE_TEXT 0 #define U8G_FONT_HEIGHT_MODE_XTEXT 1 #define U8G_FONT_HEIGHT_MODE_ALL 2 #if defined(U8G_16BIT) typedef uint16_t u8g_uint_t; typedef int16_t u8g_int_t; #else //typedef uint8_t u8g_uint_t; //typedef int8_t u8g_int_t; #endif #if defined(__AVR__) #define U8G_PROGMEM U8G_SECTION(".progmem.data") typedef uint8_t PROGMEM u8g_pgm_uint8_t; typedef uint8_t u8g_fntpgm_uint8_t; #define u8g_pgm_read(adr) pgm_read_byte_near(adr) #define U8G_PSTR(s) PSTR(s) #else #define U8G_PROGMEM typedef const unsigned char u8g_pgm_uint8_t; typedef const unsigned char u8g_fntpgm_uint8_t; #endif /*Memory reserved by digole display functions, don't modify it * We use BANK 14 for our functions, so you can use other 15 banks for yourself program */ #define _TEXT_ 0 #define _GRAPH_ 1 #define CALL_DIGOLE_DRIVER asm("call 0x80") #define EE_BASE 0XE00 persistent unsigned char digole_reserve[256] @ EE_BASE; persistent unsigned char digole_command @ EE_BASE + 0; //command need to be lunch persistent unsigned char digole_mode @ EE_BASE + 1; /* display mode, one of U8G_MODE_xxx */ persistent unsigned char digole_dir @ EE_BASE + 2; persistent unsigned char digole_color @ EE_BASE + 3; persistent int digole_x @ EE_BASE + 4; persistent int digole_y @ EE_BASE + 6; persistent int digole_char_x @ EE_BASE + 8; persistent int digole_char_y @ EE_BASE + 10; persistent const far unsigned char *digole_font @ EE_BASE + 12; /* regular font for all text procedures, 0 to default */ persistent const far unsigned char *digole_adr @ EE_BASE + 15; persistent const far unsigned char *digole_ROM_ptr @ EE_BASE + 18; persistent int digole_Gx @ EE_BASE + 22; persistent int digole_Gy @ EE_BASE + 24; persistent unsigned char digole_pattern @ EE_BASE + 26; persistent unsigned char digole_in @ EE_BASE + 27; persistent union { struct { unsigned LCDtype : 3; unsigned E_KS0108 : 1; unsigned CS1_KS0108 : 1; unsigned CS2_KS0108 : 1; unsigned ST7565type : 2; }; } digole_uniconfig_bits @ EE_BASE + 28; persistent unsigned char digole_uniconfig @ EE_BASE + 28; persistent unsigned char digole_monobuffer @ EE_BASE + 29; //for mono display, if set this to 1, the drawing is on the RAM buffer, then update to screen //draw image function parameters persistent unsigned char digole_img_format @ EE_BASE + 30; persistent int digole_img_x @ EE_BASE + 32; persistent int digole_img_y @ EE_BASE + 34; persistent int digole_img_width @ EE_BASE + 36; persistent int digole_img_height @ EE_BASE + 38; //graphic function parameters persistent int digole_graph_width @ EE_BASE + 30; persistent int digole_graph_height @ EE_BASE + 32; persistent int digole_graph_x0 @ EE_BASE + 34; persistent int digole_graph_y0 @ EE_BASE + 36; persistent int digole_graph_x1 @ EE_BASE + 38; persistent int digole_graph_y1 @ EE_BASE + 40; //draw circle parameters persistent int digole_cc_x0 @ EE_BASE + 30; persistent int digole_cc_y0 @ EE_BASE + 32; persistent int digole_cc_r @ EE_BASE + 34; persistent unsigned char digole_cc_fill @ EE_BASE + 36; //Text parameters persistent unsigned char digole_Text_ch @ EE_BASE + 30; //character to be displayed persistent unsigned char digole_Text_x @ EE_BASE + 31; //colunm position to be displayed persistent unsigned char digole_Text_y @ EE_BASE + 32; //row position to be displayed //draw arc parameters persistent int digole_arc_x0 @ EE_BASE + 42; persistent int digole_arc_y0 @ EE_BASE + 44; persistent int digole_arc_r @ EE_BASE + 46; persistent int digole_arc_startAngle @ EE_BASE + 48; persistent int digole_arc_endAngle @ EE_BASE + 50; persistent unsigned char digole_arc_type @ EE_BASE + 52; persistent struct { //RGB color system unsigned char R; //Hi for 65K color unsigned char G; //Lo for 65K color unsigned char B; } digole_RGB @ EE_BASE + 54; persistent struct { //RGB color system unsigned char R; //Hi for 65K color unsigned char G; //Lo for 65K color unsigned char B; } digole_tmpc @ EE_BASE + 57; //persistent unsigned char digole_reserved0[14] @ EE_BASE + 60; persistent struct { unsigned int w; //screen width in pixel unsigned int h; //screen height in pixel unsigned char c; //screen color: 0=mono, 1=256color, 2=65K color, 3=262K color unsigned char firmwareV; //firmware version } digole_screen_info @ EE_BASE + 60; persistent unsigned char inst_refresh @ EE_BASE + 66; //if the value=1, force the driver to refresh the screen each drawing time if display buffer enabled #ifdef _12864OLED_ persistent unsigned char digole_disp_buffer[1024] @0xA00; #endif //end of memory reservation #ifdef __cplusplus } #endif //setting functions void initDisplay(void); //initiate the display void setRotation(unsigned char dir); //set display direction void undoRotation(void); // void setFont(unsigned char *userfont); //set user font to current font, font structure compatible with u8glib void setMode(unsigned char mode); //set the drawing mode, NOT '!',OR '|', XOR '^', COPY 'C', AND '&' available, it affect all following out put void setColor256(unsigned char color); //set 256 color, for mono display, only 0 and 1 available, affect all following out put void setColor(unsigned char color); //same as setColor256 void setColor65K(unsigned int color); //set 256 color, for mono display, only 0 and 1 available, affect all following out put void setColor262K(unsigned Red, unsigned Green, unsigned Blue); //set a true color for color display, affect all following out put void setBackLight(unsigned char onoff); //set back light ON/OFF, 1=on, 0=off, for OLED, there isn't backlight, it will same as screen on/off void setScreenOnOff(unsigned char onoff); //set the display on/off, 1=on, 0=off void clearScreen(unsigned char color); //clear screen with one byte color void setPrintPos(unsigned char x, unsigned char y, unsigned char TG); //set text position use current font data or grpahic position:TG=1 //Text functions void setTextPosBack(void); //set the Text position back to one character, only one time allowed void nextTextLine(void); //move to next row void setTextPosAbs(unsigned char x, unsigned char y); //set the current Text position as pixel void setTextPosOffset(signed char xoff, signed char yoff); //change the offset of current text position in pixel void setContrast(unsigned char contrast); //only for module which allow software contrast setting (ST7565, 0.96" color OLED) void setUniversalAdapter(unsigned char); void printChar(unsigned char ch); void printString(const unsigned char *); //display a string, the string must end by 0 void drawStr(int x, int y, const unsigned char *str); //draw string at x,y void printDEC(int d); void printOCT(int d); void printHEX(int d); void printFloat(float d, unsigned char a); //Graphic functions void setPattern(unsigned char pattern); //set line pattern void drawPixel(int x, int y); //draw a pixel at x,y void getPixel(int x, int y); //get a pixel value on screen to digole_tmpc structure void setGraphPos(int x, int y); //set current graphic position in pixel, it affect lineto void drawLine(int x0, int y0, int x1, int y1); //draw a line void drawHLine(int x0, int y0, int x1); //draw a horizontal line void drawLineTo(int x, int y); //draw line from current position to new position //void rectangle(int x0, int y0, int x1, int y1, char fill); //draw a rectangle, if fill==1, fill it void drawBox(int x0, int y0, int width, int height); //draw filled rectangle void drawFrame(int x0, int y0, int width, int height); //draw unfilled rectangle void drawCircle(int x0, int y0, int r, unsigned char fill); //draw a circle, if fill==1, fill it void moveArea(int x0, int y0, int width, int height, char offset_x, char offset_y); //move area on screen from x0,y0 with size:width,height to a offset void drawBitmap(int x, int y, int width, int height, const unsigned char *data); //1 byte represent 8 pixels void drawBitmap256(int x, int y, int width, int height, const unsigned char *data); //1 byte represent 1 pixel void drawBitmap65K(int x, int y, int width, int height, const unsigned char *data); //2 bytes represent 1 pixel void drawBitmap262K(int x, int y, int width, int height, const unsigned char *data); //3 bytes represent 1 pixel void drawArc(int x, int y, int r, int startAngle, int endAngle); void refreshScreen(void); void refreshScreen(void) { digole_command = 99; CALL_DIGOLE_DRIVER; } void initDisplay(void) //reset and initiate the display { digole_command = 0; CALL_DIGOLE_DRIVER; } void setRotation(unsigned char dir) { digole_dir = dir; digole_command = 1; CALL_DIGOLE_DRIVER; } void undoRotation(void) { digole_dir = 0; digole_command = 1; CALL_DIGOLE_DRIVER; } void setFont(unsigned char *userfont) { digole_font = userfont; digole_command = 2; CALL_DIGOLE_DRIVER; } void setMode(unsigned char mode) { digole_mode = mode; } void setColor256(unsigned char color) { digole_RGB.R = color; digole_command = 3; CALL_DIGOLE_DRIVER; } void setColor65K(unsigned int color) { digole_RGB.R = color >> 8, digole_RGB.G = color & 255; digole_command = 4; CALL_DIGOLE_DRIVER; } void setColor262K(unsigned Red, unsigned Green, unsigned Blue) { digole_RGB.R = Red, digole_RGB.G = Green, digole_RGB.B = Blue; digole_command = 5; CALL_DIGOLE_DRIVER; } void setBackLight(unsigned char onoff) { digole_in = onoff; digole_command = 7; CALL_DIGOLE_DRIVER; } void setScreenOnOff(unsigned char onoff) { digole_in = onoff; digole_command = 6; CALL_DIGOLE_DRIVER; } void setContrast(unsigned char contrast) { //only for module which allow software contrast setting (ST7565, 0.96" color OLED) digole_in = contrast; digole_command = 13; CALL_DIGOLE_DRIVER; } void setUniversalAdapter(unsigned char config) { digole_in = config; digole_command = 14; CALL_DIGOLE_DRIVER; } void clearScreen(unsigned char color) { unsigned char R, G, B; R = digole_RGB.R, G = digole_RGB.G, B = digole_RGB.B; digole_RGB.R = color; digole_command = 3; CALL_DIGOLE_DRIVER; digole_command = 8; CALL_DIGOLE_DRIVER; digole_RGB.R = R, digole_RGB.G = G, digole_RGB.B = B; } //Text functions void setPrintPos(unsigned char x, unsigned char y, unsigned char TG) { if (TG == _TEXT_) { //set text position as Row/Column digole_Text_x = x; digole_Text_y = y; digole_command = 11; CALL_DIGOLE_DRIVER; } else { digole_Gx = x; digole_Gy = y; } } void nextTextLine(void) { printString("\n\r"); } void setTextPosBack(void) { digole_command = 12; CALL_DIGOLE_DRIVER; } void setTextPosAbs(unsigned char x, unsigned char y) { digole_char_x = x; digole_char_y = y; } void setTextPosOffset(signed char xoffset, signed char yoffset) { digole_char_x += xoffset; digole_char_y += yoffset; } void printChar(unsigned char ch) { digole_Text_ch = ch; digole_command = 15; CALL_DIGOLE_DRIVER; } void printString(const unsigned char *str) { digole_ROM_ptr = str; digole_command = 16; CALL_DIGOLE_DRIVER; /*/ int i; i = 0; digole_command = 15; while(str[i]!=0) { digole_Text_ch = str[i]; CALL_DIGOLE_DRIVER; i++; } */ } void drawStr(int x, int y, const unsigned char *str) { setPrintPos(x, y, _TEXT_); printString(str); } void printDEC(int d) { unsigned char buf[20]; sprintf(&buf, "%d", d); printString((const unsigned char *) buf); } void printOCT(int d) { unsigned char buf[20]; sprintf(&buf, "%o", d); printString((const unsigned char *) buf); } void printHEX(int d) { unsigned char buf[20]; sprintf(&buf, "%X", d); printString((const unsigned char *) buf); } void printFloat(float d, unsigned char a) { unsigned char buf[20]; sprintf(&buf, "%.*f", a, d); printString((const unsigned char *) buf); } //Graphic functions void setPattern(unsigned char pattern) { digole_pattern = pattern; } void drawPixel(int x, int y) { digole_x = x; digole_y = y; digole_command = 20; CALL_DIGOLE_DRIVER; } void getPixel(int x, int y) { digole_x = x; digole_y = y; digole_command = 21; CALL_DIGOLE_DRIVER; } void drawLine(int x0, int y0, int x1, int y1) { digole_graph_x0 = x0; digole_graph_y0 = y0; digole_graph_x1 = x1; digole_graph_y1 = y1; digole_command = 22; CALL_DIGOLE_DRIVER; } void drawHLine(int x0, int y0, int x1) { drawLine(x0, y0, x1, y0); } void drawLineTo(int x, int y) { digole_graph_x0 = digole_Gx; digole_graph_y0 = digole_Gy; digole_graph_x1 = x; digole_graph_y1 = y; digole_command = 22; CALL_DIGOLE_DRIVER; } void drawBox(int x0, int y0, int width, int height) { digole_graph_x0 = x0; digole_graph_y0 = y0; digole_graph_width = width; digole_graph_height = height; digole_command = 31; CALL_DIGOLE_DRIVER; } void drawFrame(int x0, int y0, int width, int height) { digole_graph_x0 = x0; digole_graph_y0 = y0; digole_graph_width = width; digole_graph_height = height; digole_command = 32; CALL_DIGOLE_DRIVER; } void drawCircle(int x0, int y0, int r, unsigned char fill) { digole_cc_x0 = x0; digole_cc_y0 = y0; digole_cc_r = r; digole_cc_fill = fill; digole_command = 26; CALL_DIGOLE_DRIVER; } void moveArea(int x0, int y0, int width, int height, char offset_x, char offset_y) { digole_graph_x0 = x0; digole_graph_y0 = y0; digole_graph_x1 = x0 + offset_x; digole_graph_y1 = y0 + offset_y; digole_graph_width = width; digole_graph_height = height; digole_command = 24; CALL_DIGOLE_DRIVER; } void drawBitmap(int x, int y, int width, int height, const unsigned char *data) { digole_img_x = x; digole_img_y = y; digole_img_width = width; digole_img_height = height; digole_ROM_ptr = data; digole_img_format = 0; digole_command = 40; CALL_DIGOLE_DRIVER; } void drawBitmap256(int x, int y, int width, int height, const unsigned char *data) { digole_img_x = x; digole_img_y = y; digole_img_width = width; digole_img_height = height; digole_ROM_ptr = data; digole_img_format = 1; digole_command = 40; CALL_DIGOLE_DRIVER; } void drawBitmap65K(int x, int y, int width, int height, const unsigned char *data) { digole_img_x = x; digole_img_y = y; digole_img_width = width; digole_img_height = height; digole_ROM_ptr = data; digole_img_format = 2; digole_command = 40; CALL_DIGOLE_DRIVER; } void drawBitmap262K(int x, int y, int width, int height, const unsigned char *data) { digole_img_x = x; digole_img_y = y; digole_img_width = width; digole_img_height = height; digole_ROM_ptr = data; digole_img_format = 3; digole_command = 40; CALL_DIGOLE_DRIVER; } void setColor(unsigned char color) { setColor256(color); } void drawArc(int x, int y, int r, int startAngle, int endAngle) { //no function right now /* digole_arc_x0=x; digole_arc_y0=y; digole_arc_r=r; digole_arc_startAngle=startAngle; digole_arc_endAngle=endAngle; digole_command=27; CALL_DIGOLE_DRIVER; */ } #define CPU_SPD_64M()\ { \ OSCCON = 0B11110000; \ OSCTUNE = 0B01000000; \ } #define CPU_SPD_32M()\ { \ OSCCON = 0B11100000; \ OSCTUNE = 0B01000000; \ } #define CPU_SPD_16M()\ { \ OSCCON = 0B11110000; \ OSCTUNE = 0B00000000; \ } #define CPU_SPD_8M()\ { \ OSCCON = 0B11100000; \ OSCTUNE = 0B00000000; \ } #define CPU_SPD_4M()\ { \ OSCCON = 0B11010000; \ OSCTUNE = 0B00000000; \ } #define CPU_SPD_2M()\ { \ OSCCON = 0B11000000; \ OSCTUNE = 0B00000000; \ } #define CPU_SPD_1M()\ { \ OSCCON = 0B10110000; \ OSCTUNE = 0B00000000; \ } #define CPU_SPD_500K()\ { \ OSCCON = 0B10100000; \ OSCTUNE = 0B00000000; \ } #endif /* DIGOLE_H */