Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of KS0108 by
Diff: KS0108.h
- Revision:
- 5:e4b50f4c13a8
- Parent:
- 4:bdc04bb2ffc1
--- a/KS0108.h Thu Feb 10 03:06:19 2011 +0000 +++ b/KS0108.h Mon May 02 19:05:30 2011 +0000 @@ -1,31 +1,9 @@ -/************************************************************************* -Copyright (c) 2010 Dimiter Kentri - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*******************************************************************************/ - #ifndef KS0108_H #define KS0108_H -#define VERSION 1.11 +#define VERSION 2.0 -#include "mbed.h" +#include <mbed.h> #include "SystemFont5x7.h" /************************************************************************************/ @@ -37,8 +15,8 @@ #define LCD_DISP_START 0xC0 //Controller directives -#define LEFT 1 -#define RIGHT 2 +#define LEFT 0 +#define RIGHT 1 #define BOTH 3 #define NONE 4 @@ -49,8 +27,10 @@ //Screen dimensions #define SCREEN_HEIGHT 64 #define SCREEN_WIDTH 128 +#define CHIP_WIDTH 64 /***********************************************************************************/ +//helper functions #define absDiff(x,y) ((x>y) ? (x-y) : (y-x)) #define swap(a,b) \ @@ -60,8 +40,7 @@ t=a;\ a=b;\ b=t;\ -} while(0) - +} while(0) /**************************************************************************************/ @@ -73,6 +52,15 @@ #define FONT_CHAR_COUNT 5 #define FONT_WIDTH_TABLE 6 + +/*************************Callback function definietion for fonts *********************/ +typedef unsigned int (*FontCallback)(unsigned int*); + +/*************************Callback function for reading font array*********************/ +static unsigned int ReadData(unsigned int* ptr) { + return *ptr; +} + /*************************************************************************************/ #define MAX_IMG_SIZE 128*64 @@ -82,7 +70,17 @@ unsigned char imgarray[MAX_IMG_SIZE]; }Image; -/**************************************************************************************/ + +typedef struct { + unsigned int x; + unsigned int y; + unsigned int page; +} LCDCoord; + + +/****************************************************************************************/ + + class KS0108 { public: @@ -114,6 +112,15 @@ */ void WriteData(unsigned int data ,unsigned char side); + + /** + *@brief Write data byte to the controller (overloaded function). + * + *@param data data send to the controller chip + *@return none + */ + void WriteData(unsigned int data); + /** *@brief Write data byte to the screen on specific page and column *@param page page varies from 0-7 for each side @@ -149,6 +156,17 @@ */ void SelectSide(unsigned char side); + + /** + *@brief Set cursor to specified coordinates + * + *@param x row + *@param y column + *@return none + */ + void GotoXY(unsigned int x, unsigned int y); + + /** *@brief Clears display * @@ -158,7 +176,7 @@ */ void ClearScreen(); - + /** *@brief Turn on display * @@ -312,8 +330,33 @@ */ void RoundRectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int radius, unsigned int color); + + /** + *Draws a triangle . + *@param + *@param + *@param + *@param + *@return none + * + */ + + void Triangle ( int topx, int topy, int rightx, int righty); + - /* + /** + *Draws a right angle triangle . + *@param + *@param + *@param + *@param + *@return none + * + */ + void RightTriangle ( int topx, int topy, int rightx, int righty); + + + /** *Draws an empty circle centered a x,y with radius R and specific color. *@param CenterX center x coordinate *@param CenterY center y coordinate @@ -324,7 +367,7 @@ */ void EmptyCircle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color); - /* + /** * Circle fill Code is merely a modification of the midpoint * circle algorithem which is an adaption of Bresenham's line algorithm * http://en.wikipedia.org/wiki/Midpoint_circle_algorithm @@ -338,7 +381,7 @@ */ void FullCircle(unsigned int CenterX, unsigned int CenterY, unsigned int Radius,unsigned int color); - /* + /** *Draws an ellipse. *@param CX x coordinate of one side *@param CY y coordinate of one side @@ -353,27 +396,7 @@ void PlotEllipse(long CX, long CY, long XRadius,long YRadius, int color); void Plot4EllipsePoints(long CX,long CY, long X, long Y, int color); - /** - *@brief Draws an image on screen. - *@param IamgeData 128x64 image array - *@return none - * - * - */ - void FullScreenBMP (unsigned char *ImageData); - - - /** - *@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 @@ -383,6 +406,38 @@ double dfloor( double value ); + /*****************************Bitmaps *****************************************************************/ + + /** + *@brief Draws an image on screen. + *@param PictureData 128x64 image array + *@return none + * + * + */ + void FullScreenBMP (unsigned char *ImageData); + + /** + *@brief Draw a 1-bit bitmap + * + *@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 DrawBitmap(const unsigned int * bitmap, unsigned int x, unsigned int y, unsigned int color); + + /** + *@brief Static function , mplemented to read an array + *@param ptr data array + *@return none + */ + unsigned int ReadArrayData(const unsigned int* ptr); + + + /*************************************Font functions **************************************/ + /** *@brief Print a character on specified coordinates * @@ -391,7 +446,7 @@ *@param c integer value *@return none */ - void Putc (int page, int col,unsigned char c); + void Putchar (int page, int col,unsigned char c); /** *@brief Print a string on specified coordinates @@ -423,17 +478,45 @@ */ void PrintInteger(int val,unsigned int x,unsigned int y); + + /** + *@brief Select a specific font + * + *@param font font array + *@param color font color , can be BLACK or WHITE + *@param callback function pointer to load font + *@return none + */ + void SelectFont(unsigned int* font,unsigned int color, FontCallback callback); + + /** - *@brief Set cursor to specified coordinates + *@brief Print a character * - *@param x row - *@param y column + *@param c char *@return none */ - void CursorXY( unsigned int x, unsigned int y); + int PrintChar(char c); - - + + /** + *@brief Print a character string + * + *@param str char string + *@return none + */ + void PrintString(char* str); + + + /** + *@brief Print a number + * + *@param n number + *@return none + */ + void PrintNumber(long n); + + private: BusInOut DB; DigitalOut RST; @@ -442,9 +525,15 @@ DigitalOut E; DigitalInOut CS2; DigitalInOut CS1; - + bool Inverted; + + LCDCoord Coord; + FontCallback FontRead ; + unsigned int FontColor; + unsigned int* Font; unsigned int color; - unsigned int* Font; + + };