Paul Staron / Mbed 2 deprecated KL25Z_DCF77_OLED160

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers OLED160G1.h Source File

OLED160G1.h

00001 /**
00002  * mbed library for 4D Systems uOLED-160-G1
00003  *
00004  */
00005 
00006 #ifndef _OLED160G1_H_
00007 #define _OLED160G1_H_
00008 
00009 
00010 #define OLED_BAUDRATE                       256000  // 300 baud to 256kbaud supported (256k not always stable?)
00011 #define OLED_INIT_DELAY                     1100    // milliseconds
00012 
00013 // Initialisation routine
00014 #define OLED_DETECT_BAUDRATE                0x55
00015 
00016 // Drawing routines
00017 #define OLED_CLEAR                          0x45
00018 #define OLED_BKGCOLOR                       0x42
00019 #define OLED_COPYPASTE                      0x63
00020 #define OLED_PEN_SIZE                       0x70
00021 
00022 // Graphics
00023 #define OLED_LINE                           0x4C
00024 #define OLED_CIRCLE                         0x43
00025 #define OLED_CIRCLEFILL                     0x69
00026 #define OLED_PUTPIXEL                       0x50
00027 #define OLED_READPIXEL                      0x52
00028 #define OLED_RECTANGLE                      0x72
00029 
00030 // Text properties
00031 #define OLED_TEXT                           0x73
00032 #define OLED_SETFONTSIZE                    0x46
00033 #define OLED_FONT5X7                        0x00
00034 #define OLED_FONT8X8                        0x01
00035 #define OLED_FONT8X12                       0x02
00036 #define OLED_TEXTFORMATED                   0x54
00037 #define OLED_SET_TEXT_BACKGROUND_TYPE       0x4F
00038 #define OLED_SET_BACKGROUND_COLOR           0x42
00039 #define OLED_SET_TEXT_TRANSPARENT           0x00
00040 #define OLED_SET_TEXT_OPAQUE                0x01
00041 
00042 // OLED Control
00043 #define OLED_COMMAND_CONTROL                0x59
00044 #define OLED_COMMAND_DISPLAY                0x01
00045 #define OLED_COMMAND_CONTRAST               0x02
00046 #define OLED_COMMAND_POWER                  0x03
00047 
00048 // Responses
00049 #define OLED_ACK                            0x06  // Ok
00050 #define OLED_NAK                            0x15  // Error
00051 
00052 // Colours
00053 #define OLED_WHITE                          0xFFFF
00054 #define OLED_BLACK                          0x0000
00055 #define OLED_BLUE                           0xA6BF
00056 #define OLED_RED                            0xF800
00057 #define OLED_GREEN                          0x2500
00058 
00059 #define red_min 0//150
00060 #define red_max 255
00061 #define blue_min 0//185
00062 #define blue_max 255
00063 #define green_min 0//195
00064 #define green_max 255
00065 
00066 
00067 class OLED160G1 : public Stream {
00068 public:
00069 
00070     /**
00071      * Default constructor.
00072      */
00073     OLED160G1(PinName serialTx, PinName serialRx, PinName resetPin);
00074     
00075     /**
00076      * Reset the display using the reset pin (the reset pin is active-low).
00077      */
00078     void resetDisplay();
00079 
00080     /**
00081      * Initialise OLED display.
00082      */
00083     void init();
00084 
00085     /**
00086      * Processes responses (ACK or NAK) from the OLED. A new command cannot be sent to the OLED until a NAK is received, so
00087      * this function waits for the minimum time needed.
00088      */
00089     void getResponse();
00090 
00091     /**
00092      * Clear the OLED screen.
00093      */
00094     void eraseScreen();
00095     
00096     /**
00097      * Calculate 16-bit value from RGB (0 to 63, 565 format)
00098      */
00099     int toRGB(int red, int green, int blue);
00100     
00101     /**
00102      * 
00103      */
00104     void drawPixel(char x, char y, int color);
00105     
00106     /**
00107      * 
00108      */
00109     void drawLine(char x1, char y1, char x2, char y2, int color);
00110     
00111     /**
00112      * 
00113      */
00114     void drawRectangle(char x, char y, char width, char height, int color);
00115     
00116     /**
00117      * 
00118      */
00119     void drawCircle(char x, char y, char radius, int color);
00120     
00121     /**
00122      * Set font size, for use with printf() or OLED_DrawSingleChar(); all other functions override this setting.
00123      *
00124      * @param : fontSize can be: OLED_FONT5X7, OLED_FONT8X8, or OLED_FONT8X12
00125      */
00126     void setFontSize(char fontSize);
00127     
00128     /**
00129      * Set font color, for use with printf(); all other functions override this setting.
00130      */
00131     void setFontColor(int fontColor);
00132     
00133     /**
00134      * Set the "pen size".
00135      *
00136      * @param penSize : 0 to draw solid objects; 1 to draw wireframe objects.
00137      */
00138     void setPenSize(char penSize);
00139     
00140     /**
00141      * Set whether or not text is drawn with an opaque or transparent background.
00142      *
00143      * @param : textBackgroundType can be OLED_SET_TEXT_TRANSPARENT or OLED_SET_TEXT_OPAQUE
00144      */
00145     void setTextBackgroundType(char textBackgroundType);
00146     
00147     /**
00148      * 
00149      */
00150     void setBackgroundColor(int color);
00151     
00152     /**
00153      * 
00154      */
00155     void drawText(char column, char row, char font_size, char *mytext, int color);
00156     
00157     /**
00158      * Draw a single ASCII character at the specified location.
00159      */
00160     void drawSingleChar(char column, char row, char theChar, int color);
00161     
00162     /**
00163      * Display control functions, such as display ON/OFF, contrast and power-up/power-down.
00164      *
00165      * @param value : can be 0x00 to 0x0F is mode is OLED_COMMAND_CONTRAST. Default contrast value is 0x08.
00166      */
00167     void displayControl(char mode, char value);
00168     
00169     /**
00170      * 
00171      */
00172     char getPenSize();
00173     
00174     /**
00175      * Get number of text rows
00176      */
00177     int rows(); //TODO: must depend on font size
00178     
00179     /**
00180      * Get number of text columns
00181      */
00182     int columns();
00183     
00184     /**
00185      * Set text cursor location
00186      */
00187     virtual void locate(int column, int row);
00188     
00189     /**
00190      * 
00191      */
00192     int lastCount;
00193     
00194     /**
00195      * 
00196      */
00197     int NAKCount;
00198     
00199 protected:
00200     virtual int _putc(int value);
00201     virtual int _getc();
00202     
00203     /**
00204      * Text cursor column number
00205      */
00206     short _column;
00207     
00208     /**
00209      * Text cursor row number
00210      */
00211     short _row;
00212     
00213     char _fontSize;
00214     char _penSize;
00215     int _fontColor;
00216     
00217 private:
00218     Serial s;
00219     DigitalOut  reset;
00220 };
00221 
00222 #endif