Added custom fonts. Added triangle drawing function
Dependents: sc100016x4lcd REVO_Updated_Steering Driving_game Arkanoid_v1 ... more
Diff: KS0108.h
- Revision:
- 2:03d27b3fce6e
- Parent:
- 1:a368f2688222
- Child:
- 4:bdc04bb2ffc1
--- a/KS0108.h Wed Jan 05 00:01:45 2011 +0000 +++ b/KS0108.h Fri Jan 28 01:08:45 2011 +0000 @@ -23,18 +23,18 @@ #ifndef KS0108_H #define KS0108_H -#define VERSION 1 +#define VERSION 1.1 #include "mbed.h" #include "SystemFont5x7.h" /************************************************************************************/ // Commands -#define LCD_ON 0x3F -#define LCD_OFF 0x3E -#define LCD_SET_ADD 0x40 +#define LCD_ON 0x3F +#define LCD_OFF 0x3E +#define LCD_SET_ADD 0x40 #define LCD_SET_PAGE 0xB8 -#define LCD_DISP_START 0xC0 +#define LCD_DISP_START 0xC0 //Controller directives #define LEFT 1 @@ -43,8 +43,8 @@ #define NONE 4 // Colors -#define BLACK 0xFF -#define WHITE 0x00 +#define BLACK 0xFF +#define WHITE 0x00 //Screen dimensions #define SCREEN_HEIGHT 64 @@ -66,13 +66,23 @@ /**************************************************************************************/ // Font Indices -#define FONT_LENGTH 0 +#define FONT_LENGTH 0 #define FONT_FIXED_WIDTH 2 -#define FONT_HEIGHT 3 -#define FONT_FIRST_CHAR 4 -#define FONT_CHAR_COUNT 5 +#define FONT_HEIGHT 3 +#define FONT_FIRST_CHAR 4 +#define FONT_CHAR_COUNT 5 #define FONT_WIDTH_TABLE 6 +/*************************************************************************************/ +#define MAX_IMG_SIZE 127*64 + +typedef struct { + unsigned int imgWidth; + unsigned int imgHeight; + unsigned char imgarray[MAX_IMG_SIZE]; +}Image; + +/**************************************************************************************/ typedef struct { unsigned int x; @@ -86,68 +96,71 @@ class KS0108 { public: - /*Constructor, initializes the lcd on the respective pins. - * - *@param pins - *@param databus - */ + + /** + *@brief Constructor, initializes the lcd on the respective pins. + *@param control pins RST,DI,RW,E,CS2,CS1 + *@param databus DB0-DB7 data pins + *@return none + */ KS0108 (PinName _RST,PinName _DI, PinName _RW, PinName _E, PinName _CS1, PinName _CS2, PinName DB0, PinName DB1, PinName DB2, PinName DB3, PinName DB4, PinName DB5, PinName DB6, PinName DB7); - /*Write instruction to the specific controller. - * - *@param Command command to send - *@param side controller side can be LEFT or RIGHT + /** + *@brief Write instruction to the specific controller. + *@param Command command to send to the controller + *@param side controller side can be LEFT or RIGHT *@return none * */ void WriteInstruction(unsigned int Command,unsigned int side); - /*Write data to the controller. + /** + *@brief Write data byte to the controller. + *@param data data send to the controller chip + *@param side selected controller can be LEFT or RIGHT + *@return none * - *@param data data to send - *@param side controller side can be LEFT or RIGHT - * - *@return none */ void WriteData(unsigned int data ,unsigned char side); - /*Write data to the screen on specific page and column - * - *@param page page varies from0-7 for each side - *@param col col varies from 0-64 for each side - *@param data info to be written on given coordinates - *@return none - * - */ + /** + *@brief Write data byte to the screen on specific page and column + *@param page page varies from 0-7 for each side + *@param col col varies from 0-64 for each side + *@param data info to be written on given coordinates + *@return none + * + */ void WriteDataColPag(unsigned int page, unsigned int col, unsigned int data); - - /*Read data from diplay - * + /** + *@brief Read data from display *@param none - *@return data + *@return none * */ unsigned int ReadData(); - /*Read status of display , and check if it's busy - * + /** + *@brief Read status of display , and check if it's busy *@param none - *@return status status of display + *@return status status of display * */ unsigned int ReadStatus(); - /*Select controller + /** + *@brief Select controller chip * - *@param side controller side can be LEFT or RIGHT + *@param side controller side can be LEFT or RIGHT *@return none * */ void SelectSide(unsigned char side); - /*Clears display + /** + *@brief Clears display * *@param none *@return none @@ -157,50 +170,55 @@ /*******************************Graphic functions************************************************/ - /*Set pixel to specific location on the screen. - *@param x page varies from 0-128 - *@param y col varies from 0-64 - *@param color color of pixel, can be BLACK or WHITE - *@return none - * - */ + /** + *@brief Set pixel to specific location on the screen. + *@param x coordinate varies from 0-128 + *@param y col varies from 0-64 + *@param color color of pixel, can be BLACK or WHITE + *@return none + * + */ void SetPixel( unsigned int x, unsigned int y, unsigned int color); - /*Draw a horizontal line - *@param Xaxis1 - *@param Xaxis2 - *@param Yaxis + /** + *@brief Draws a line from x1,y1 to x2,y1 + *@param Xaxis1 x coordinate of one side + *@param Xaxis2 x coordinate of one side + *@param Yaxis y coordinate both points *@param color can be BLACK or WHITE *@return none * */ - void HLine(unsigned int Xaxis1, unsigned int Xaxis2 ,unsigned int Yaxis,unsigned int color); + void HLine(unsigned int Xaxis1, unsigned int Xaxis2 ,unsigned int Yaxis,unsigned int color); - /*Draw a horizontal line + /** + *@brief Draw a horizontal line *@param Xaxis1 *@param Xaxis2 - *@param Yaxis + *@param width *@param color can be BLACK or WHITE *@return none * */ void HLineShort(unsigned int Xaxis, unsigned int Yaxis,unsigned int width ,unsigned int color); - /*Draw a vertical line - *@param Xaxis1 - *@param Xaxis2 - *@param Yaxis + /** + *@brief Draws a vertical line + *@param Xaxis + *@param Yaxis1 + *@param Yaxis2 *@param color can be BLACK or WHITE *@return none * */ void VLine(unsigned int Xaxis, unsigned int Yaxis1 ,unsigned int Yaxis2,unsigned int color); - /*Draw a vertical line - *@param Xaxis1 - *@param Xaxis2 + /** + *@brief Draw a vertical line of a given width starting from X, Y + *@param Xaxis *@param Yaxis + *@param height Height of line *@param color can be BLACK or WHITE *@return none * @@ -208,12 +226,12 @@ void VLineShort(unsigned int Xaxis,unsigned int Yaxis, unsigned int height ,unsigned int color); - /* - *Draws a line from x1,y1 to x2,y2 - *@param lX1 x coordinate of one side - *@param lY1 y coordinate of one side - *@param lX2 x coordinate of other side - *@param lY2 y coordinate of other side + /** + *@brief Draws a line from x1,y1 to x2,y2. + *@param x1 x coordinate of one side + *@param y1 y coordinate of one side + *@param x2 x coordinate of other side + *@param y2 y coordinate of other side *@param color can be BLACK or WHITE *@return none * @@ -221,8 +239,8 @@ void Line(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2, unsigned int color); - /* - *Draws a slanty line . + /** + *@brief Draws a slanty line from x1,y1 to x2,y2 *@param lX1 x coordinate of one side *@param lY1 y coordinate of one side *@param lX2 x coordinate of other side @@ -233,18 +251,20 @@ */ void SlantyLine(unsigned int lX1, unsigned int lY1, unsigned int lX2,unsigned int lY2,unsigned int color); - /* - *Draws a line from x,y at given degree from inner_radius to outer_radius. - *@param Xaxis1 - *@param Xaxis2 - *@param Yaxis + /** + *@brief Draws a line from x,y at given degree from inner_radius to outer_radius. + *@param x + *@param y + *@param inner_radius + *@param outer_radius *@param color can be BLACK or WHITE *@return none * */ void DegreeLine(unsigned int x, int y,unsigned int degree,unsigned int inner_radius,unsigned int outer_radius, unsigned int color); - /*Draw a filled reactangle + /** + *@brief Draw a filled reactangle * *@param Xaxis1 *@param Yaxis1 @@ -256,7 +276,8 @@ */ void FullRectangle(unsigned int Xaxis1, unsigned int Yaxis1, unsigned int Xaxis2 ,unsigned int Yaxis2,unsigned int color); - /*Draw an empty rectangle + /** + *@brief Draw an empty rectangle *@param Xaxis1 *@param Yaxis1 *@param Xaxis2 @@ -268,11 +289,13 @@ void EmptyRectangle(unsigned int Xaxis1,unsigned int Yaxis1, unsigned int Xaxis2,unsigned int Yaxis2,unsigned int color); - /*Draw a rectangle with round corners - *@param Xaxis1 - *@param Yaxis1 - *@param Xaxis2 - *@param Yaxis2 + /** + *@brief Draw a rectangle with round corners + *@param Xaxis1 x-coordinate of the top left point + *@param Yaxis1 y-coordinate of the top left point + *@param width rectangle width + *@param height rectangle height + *@param radius radius of the edges *@param color can be BLACK or WHITE *@return none * @@ -282,11 +305,10 @@ /* *Draws an empty circle centered a x,y with radius R and specific color. - *@param lX1 x coordinate of one side - *@param lY1 y coordinate of one side - *@param lX2 x coordinate of other side - *@param lY2 y coordinate of other side - *@param color can be BLACK or WHITE + *@param CenterX center x coordinate + *@param CenterY center y coordinate + *@param Radius circle radius + *@param color Color can be BLACK or WHITE *@return none * */ @@ -299,19 +321,19 @@ * http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm * Adapted from arduino lib * - *@param CenterX - *@param CenterY - *@param Radius - *@param color + *@param CenterX center x coordinate + *@param CenterY center y coordinate + *@param Radius circle radius + *@param color Color can be BLACK or WHITE */ void FullCircle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color); /* *Draws an ellipse. - *@param lX1 x coordinate of one side - *@param lY1 y coordinate of one side - *@param lX2 x coordinate of other side - *@param lY2 y coordinate of other side + *@param CX x coordinate of one side + *@param CY y coordinate of one side + *@param XRadius x coordinate of other side + *@param YRadius y coordinate of other side *@param color can be BLACK or WHITE *@return none * @@ -319,23 +341,10 @@ * */ void PlotEllipse(long CX, long CY, long XRadius,long YRadius, int color); - - /* - *Helper function for drawing an ellipse. - *@param CX x coordinate of one side - *@param CY y coordinate of one side - *@param X x coordinate of other side - *@param Y y coordinate of other side - *@param color can be BLACK or WHITE - *@return none - * - * Portted the algorithm found at http://homepage.smc.edu/kennedy_john/belipse.pdf - * - */ void Plot4EllipsePoints(long CX,long CY, long X, long Y, int color); - /* - *Draws an image on screen. + /** + *@brief Draws an image on screen. *@param PictureData 128x64 image array *@return none * @@ -343,8 +352,20 @@ */ void FullScreenBMP (unsigned char *PictureData); - /* - *Round a double + + /** + *@brief Draw a 1 bit bmp image at specified coordinates + * + *@param image struct containing img size and array + *@param x x-coordinate + *@param y y-coordinate + *@param color can be BLACK or WHITE + *@return none + */ + void CustomImage(Image* image,unsigned int x, unsigned int y, unsigned int color); + + /** + *@brief Round a double *@param double *@return value * @@ -352,55 +373,52 @@ double dfloor( double value ); - /* - *Print a char on the specified coordinates - *@param page row coordinate - *@param col y coordinate - *@param c character from systemfont - *@return none - * - * - */ + /** + *@brief Print a character on specified coordinates + * + *@param page row + *@param col column + *@param c integer value + *@return none + */ void Putc (int page, int col,unsigned char c); - /* - *Print a string on the specified coordinates. - *@param x row coordinate - *@param y y coordinate - *@param str character string - *@return none - * - * - */ + /** + *@brief Print a string on specified coordinates + * + *@param str char array + *@param x row + *@param y column + *@return none + */ void PutString(unsigned int x, unsigned int y,char* str); - /* - *Print a float on the specified coordiantes. - *@param val float number - *@param x row coordinate - *@param y y coordinate - *@return none - * - * - */ + /** + *@brief Print a float on specified coordinates + * + *@param val float value + *@param x row + *@param y column + *@return none + */ void PrintFloat(float val, unsigned int x,unsigned int y); - /* - *Print an integer on th specified coordinates. - *@param val integer number - *@param x row coordinate - *@param y column coordinate - *@return none - * - */ + /** + *@brief Print an integer on specified coordinates + * + *@param val integer value + *@param x row + *@param y column + *@return none + */ void PrintInteger(int val,unsigned int x,unsigned int y); - /* - *Moves cursor to x,y. - *@param x x coordinate - *@param y y coordinate + /** + *@brief Set cursor to specified coordinates + * + *@param x row + *@param y column *@return none - * */ void CursorXY( unsigned int x, unsigned int y);