Fork of SSD1289 lib for Landtiger board

Revision:
1:f4f77e6729cd
Parent:
0:d7202c9fc5db
Child:
2:799c4fb113c5
--- a/ssd1289.h	Wed Nov 21 05:13:24 2012 +0000
+++ b/ssd1289.h	Wed Nov 21 23:11:20 2012 +0000
@@ -1,38 +1,94 @@
-#ifndef SSD1286_H
+#ifndef SSD1289_H
 #define SSD1289_H
 
 #include "mbed.h"
+#include "fonts.h"
 
-typedef enum
+#define RGB( r, g, b )          ( ( ( ( r ) & 248 ) | ( ( g ) >> 5 ) ) << 8 ) | ( ( ( ( g ) & 28 ) << 3 ) | ( ( b ) >> 3 ) )
+#define COLOR_BLACK             RGB( 0x00, 0x00, 0x00 )
+#define COLOR_WHITE             RGB( 0xFF, 0xFF, 0xFF )
+#define COLOR_RED               RGB( 0xFF, 0x00, 0x00 )
+#define COLOR_GREEN             RGB( 0x00, 0xFF, 0x00 )
+#define COLOR_BLIUE             RGB( 0x00, 0x00, 0xFF )
+
+typedef enum Orientation_enum
 {
     PORTRAIT = 0,
     LANDSCAPE = 1,
 } orientation_t;
 
-typedef struct
+typedef enum Alignment_enum
+{
+    LEFT = 0,
+    CENTER = 9998,
+    RIGHT = 9999,
+} align_t;
+
+typedef struct Font_struct
 {
-    unsigned char* font;
-    unsigned char width;
-    unsigned char height;
-    unsigned char offset;
-    unsigned char numchars;
+    const    char* font;
+    unsigned char  width;
+    unsigned char  height;
+    unsigned char  offset;
+    unsigned char  numchars;
 } font_metrics_t;
 
+typedef unsigned short* bitmap_t;
+
 class SSD1289 : public Stream
 {
 public:
     SSD1289( PinName CS_PIN, PinName RESET_PIN, PinName RS_PIN, PinName WR_PIN, PinName RD_PIN, BusOut* DATA_PORT );
-    void Initialize( orientation_t orientation );
+    void Initialize( orientation_t orientation = LANDSCAPE );
+    
+    void SetForeground( unsigned short color = COLOR_WHITE );
+    void SetBackground( unsigned short color = COLOR_BLACK );
+    void SetFont( const char* font );
+    
+    void FillScreen( int color = -1 );
+    void ClearScreen( void );
+    void DrawPixel( unsigned short x, unsigned short y, int color = -2 );
+    void DrawLine( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
+    void DrawRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
+    void DrawRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
+    void FillRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
+    void FillRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
+    void DrawCircle( unsigned short x, unsigned short y, unsigned short radius, int color = -2 );
+    void FillCircle( unsigned short x, unsigned short y, unsigned short radius, int color = -2 );
+    void Print( const char *str, unsigned short x, unsigned short y, int fgColor = -2, int bgColor = -1, unsigned short deg = 0 );
+    void DrawBitmap( unsigned short x, unsigned short y, unsigned short sx, unsigned short sy, bitmap_t data, unsigned char scale = 1 );
+    void DrawBitmap( unsigned short x, unsigned short y, unsigned short sx, unsigned short sy, bitmap_t data, unsigned short deg, unsigned short rox, unsigned short roy );
+    
+    /*
+    void PrintNumI( long num, int x, int y );
+    void PrintNumF( double num, uint8_t dec, int x, int y, char divider = '.' );
+    */
     
 private:
     DigitalOut _lcd_pin_cs, _lcd_pin_reset, _lcd_pin_rs, _lcd_pin_wr, _lcd_pin_rd;
     BusOut* _lcd_port;
     orientation_t _orientation;
+    static const long _disp_width = 239;
+    static const long _disp_height = 319;
+    unsigned short _foreground, _background;
+    font_metrics_t _font;
 
 private:
     virtual void writeCmd( unsigned short cmd );
     virtual void writeData( unsigned short data );
     virtual void writeCmdData( unsigned short cmd, unsigned short data );
+    
+    void setXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 );
+    void clearXY( void );
+    void drawHLine( unsigned short x, unsigned short y, unsigned short len, int color = -2 );
+    void drawVLine( unsigned short x, unsigned short y, unsigned short len, int color = -2 );
+
+    void printChar( char c, unsigned short x, unsigned short y, int fgColor = -2, int bgColor = -1 );
+    void rotateChar( char c, unsigned short x, unsigned short y, int pos, int fgColor = -2, int bgColor = -1, unsigned short deg = 0 );
+    
+    // from Stream
+    virtual int _putc( int value );
+    virtual int _getc();
 };
 
 #endif /* SSD1289_H */