Added 128x32 support
authorKevin Townsend <kevin@ktownsend.com>
Wed, 18 Jan 2012 20:24:59 +0000 (21:24 +0100)
committerKevin Townsend <kevin@ktownsend.com>
Wed, 18 Jan 2012 20:24:59 +0000 (21:24 +0100)
drivers/lcd/bitmap/ssd1306/ssd1306.c
drivers/lcd/bitmap/ssd1306/ssd1306.h

index fce409b..0766e67 100644 (file)
@@ -14,7 +14,7 @@
 
     Software License Agreement (BSD License)
 
-    Copyright (c) 2010, microBuilder SARL
+    Copyright (c) 2012, microBuilder SARL
     All rights reserved.
 
     Redistribution and use in source and binary forms, with or without
@@ -106,6 +106,12 @@ static void ssd1306DrawChar(uint16_t x, uint16_t y, uint8_t c, struct FONT_DEF f
 {
   uint8_t col, column[font.u8Width];
 
+  // Make sure we are exceeding the display limits
+  // This also gets checked in ssd1306DrawPixel, but if we start
+  // outside the limits we can avoid some unecessary work at the outset
+  if ((x > SSD1306_LCDWIDTH) || (y > SSD1306_LCDHEIGHT))
+    return;
+
   // Check if the requested character is available
   if ((c >= font.u8FirstChar) && (c <= font.u8LastChar))
   {
@@ -166,43 +172,75 @@ void ssd1306Init(uint8_t vccstate)
   DELAY(10);
   gpioSetValue(SSD1306_RST_PORT, SSD1306_RST_PIN, 1);
 
-  // Initialisation sequence
-  CMD(SSD1306_DISPLAYOFF);                    // 0xAE
-  CMD(SSD1306_SETLOWCOLUMN | 0x0);            // low col = 0
-  CMD(SSD1306_SETHIGHCOLUMN | 0x0);           // hi col = 0
-  CMD(SSD1306_SETSTARTLINE | 0x0);            // line #0
-  CMD(SSD1306_SETCONTRAST);                   // 0x81
-  if (vccstate == SSD1306_EXTERNALVCC) 
-    { CMD(0x9F) }
-  else 
-    { CMD(0xCF) }
-  CMD(0xa1);                                  // setment remap 95 to 0 (?)
-  CMD(SSD1306_NORMALDISPLAY);                 // 0xA6
-  CMD(SSD1306_DISPLAYALLON_RESUME);           // 0xA4
-  CMD(SSD1306_SETMULTIPLEX);                  // 0xA8
-  CMD(0x3F);                                  // 0x3F 1/64 duty
-  CMD(SSD1306_SETDISPLAYOFFSET);              // 0xD3
-  CMD(0x0);                                   // no offset
-  CMD(SSD1306_SETDISPLAYCLOCKDIV);            // 0xD5
-  CMD(0x80);                                  // the suggested ratio 0x80
-  CMD(SSD1306_SETPRECHARGE);                  // 0xd9
-  if (vccstate == SSD1306_EXTERNALVCC) 
-    { CMD(0x22) }
-  else 
-    { CMD(0xF1) }
-  CMD(SSD1306_SETCOMPINS);                    // 0xDA
-  CMD(0x12);                                  // disable COM left/right remap
-  CMD(SSD1306_SETVCOMDETECT);                 // 0xDB
-  CMD(0x40);                                  // 0x20 is default?
-  CMD(SSD1306_MEMORYMODE);                    // 0x20
-  CMD(0x00);                                  // 0x0 act like ks0108
-  CMD(SSD1306_SEGREMAP | 0x1);
-  CMD(SSD1306_COMSCANDEC);
-  CMD(SSD1306_CHARGEPUMP);                    //0x8D
-  if (vccstate == SSD1306_EXTERNALVCC) 
-    { CMD(0x10) }
-  else 
-    { CMD(0x14) }
+  #if defined SSD1306_128_32
+    // Init sequence taken from datasheet for UG-2832HSWEG04 (128x32 OLED module)
+    CMD(SSD1306_DISPLAYOFF);                    // 0xAE
+    CMD(SSD1306_SETDISPLAYCLOCKDIV);            // 0xD5
+    CMD(0x80);                                  // the suggested ratio 0x80
+    CMD(SSD1306_SETMULTIPLEX);                  // 0xA8
+    CMD(0x1F);
+    CMD(SSD1306_SETDISPLAYOFFSET);              // 0xD3
+    CMD(0x0);                                   // no offset
+    CMD(SSD1306_SETSTARTLINE | 0x0);            // line #0
+    CMD(SSD1306_CHARGEPUMP);                    // 0x8D
+    if (vccstate == SSD1306_EXTERNALVCC) 
+      { CMD(0x10) }
+    else 
+      { CMD(0x14) }
+    CMD(SSD1306_SEGREMAP | 0x1);
+    CMD(SSD1306_COMSCANDEC);
+    CMD(SSD1306_SETCOMPINS);                    // 0xDA
+    CMD(0x02);
+    CMD(SSD1306_SETCONTRAST);                   // 0x81
+    if (vccstate == SSD1306_EXTERNALVCC) 
+      { CMD(0x9F) }
+    else 
+      { CMD(0xCF) }
+    CMD(SSD1306_SETPRECHARGE);                  // 0xd9
+    if (vccstate == SSD1306_EXTERNALVCC) 
+      { CMD(0x22) }
+    else 
+      { CMD(0xF1) }
+    CMD(SSD1306_SETVCOMDETECT);                 // 0xDB
+    CMD(0x40);                                  // 0x20 is default?
+    CMD(SSD1306_DISPLAYALLON_RESUME);           // 0xA4
+    CMD(SSD1306_NORMALDISPLAY);                 // 0xA6
+  #endif
+
+  #if defined SSD1306_128_64
+    // Init sequence taken from datasheet for UG-2864HSWEG01 (128x64 OLED module)
+    CMD(SSD1306_DISPLAYOFF);                    // 0xAE
+    CMD(SSD1306_SETDISPLAYCLOCKDIV);            // 0xD5
+    CMD(0x80);                                  // the suggested ratio 0x80
+    CMD(SSD1306_SETMULTIPLEX);                  // 0xA8
+    CMD(0x3F);
+    CMD(SSD1306_SETDISPLAYOFFSET);              // 0xD3
+    CMD(0x0);                                   // no offset
+    CMD(SSD1306_SETSTARTLINE | 0x0);            // line #0
+    CMD(SSD1306_CHARGEPUMP);                    // 0x8D
+    if (vccstate == SSD1306_EXTERNALVCC) 
+      { CMD(0x10) }
+    else 
+      { CMD(0x14) }
+    CMD(SSD1306_SEGREMAP | 0x1);
+    CMD(SSD1306_COMSCANDEC);
+    CMD(SSD1306_SETCOMPINS);                    // 0xDA
+    CMD(0x12);
+    CMD(SSD1306_SETCONTRAST);                   // 0x81
+    if (vccstate == SSD1306_EXTERNALVCC) 
+      { CMD(0x9F) }
+    else 
+      { CMD(0xCF) }
+    CMD(SSD1306_SETPRECHARGE);                  // 0xd9
+    if (vccstate == SSD1306_EXTERNALVCC) 
+      { CMD(0x22) }
+    else 
+      { CMD(0xF1) }
+    CMD(SSD1306_SETVCOMDETECT);                 // 0xDB
+    CMD(0x40);                                  // 0x20 is default?
+    CMD(SSD1306_DISPLAYALLON_RESUME);           // 0xA4
+    CMD(SSD1306_NORMALDISPLAY);                 // 0xA6
+  #endif
 
   // Enabled the OLED panel
   CMD(SSD1306_DISPLAYON);
index 1854188..d9e9960 100644 (file)
@@ -2,14 +2,14 @@
 /*! 
     @file     ssd1306.h
     @author   K. Townsend (microBuilder.eu)
-    @date     22 March 2010
+    @date     18 January 2012
     @version  0.10
 
     @section LICENSE
 
     Software License Agreement (BSD License)
 
-    Copyright (c) 2010, microBuilder SARL
+    Copyright (c) 2012, microBuilder SARL
     All rights reserved.
 
     Redistribution and use in source and binary forms, with or without
 
 #include "drivers/lcd/smallfonts.h"
 
+/*=========================================================================
+    SSD1306 Displays
+    -----------------------------------------------------------------------
+    The driver is used in multiple displays (128x64, 128x32, etc.).
+    Select the appropriate display below to create an appropriately
+    sized framebuffer, etc.
+
+    SSD1306_128_64  128x64 pixel display
+
+    SSD1306_128_32  128x32 pixel display
+
+    You also need to set the LCDWIDTH and LCDHEIGHT defines to an 
+    appropriate size
+
+    -----------------------------------------------------------------------*/
+    // #define SSD1306_128_64
+    #define SSD1306_128_32
+/*=========================================================================*/
+
+#if defined SSD1306_128_64 && defined SSD1306_128_32
+  #error "Only one SSD1306 display can be specified at once in ssd1306.h"
+#endif
+#if !defined SSD1306_128_64 && !defined SSD1306_128_32
+  #error "At least one SSD1306 display must be specified in ssd1306.h"
+#endif
+
+#if defined SSD1306_128_64
+  #define SSD1306_LCDWIDTH                  128
+  #define SSD1306_LCDHEIGHT                 64
+#endif
+#if defined SSD1306_128_32
+  #define SSD1306_LCDWIDTH                  128
+  #define SSD1306_LCDHEIGHT                 32
+#endif
+
 // Pin Definitions
 #define SSD1306_DC_PORT                    (2)     // Data/Command
 #define SSD1306_DC_PIN                     (1)
@@ -54,8 +89,6 @@
 #define SSD1306_SDAT_PORT                  (2)     // Serial Data
 #define SSD1306_SDAT_PIN                   (6)
 
-#define SSD1306_LCDWIDTH                  128
-#define SSD1306_LCDHEIGHT                 64
 
 // Commands
 #define SSD1306_SETCONTRAST               0x81
This page took 0.028374 seconds and 4 git commands to generate.