aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2017-09-11 18:19:12 +1000
committerinmarket <andrewh@inmarket.com.au>2017-09-11 18:19:12 +1000
commit77994258c003552ebe5d05d78ab20150a0684649 (patch)
treeb8a8be2fe90341998afa59d716cc0e5786df8a67 /drivers
parent9b52fee21371fbfccdcee1b268b13fead41fb588 (diff)
downloaduGFX-77994258c003552ebe5d05d78ab20150a0684649.tar.gz
uGFX-77994258c003552ebe5d05d78ab20150a0684649.tar.bz2
uGFX-77994258c003552ebe5d05d78ab20150a0684649.zip
Add SSD1322 driver. Thanks to Andrey_13 (but with modifications)
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gdisp/SSD1322/SSD1322.h78
-rw-r--r--drivers/gdisp/SSD1322/board_SSD1322_template.h57
-rw-r--r--drivers/gdisp/SSD1322/gdisp_lld_SSD1322.c299
-rw-r--r--drivers/gdisp/SSD1322/gdisp_lld_config.h26
-rw-r--r--drivers/gdisp/SSD1322/readme.txt25
5 files changed, 485 insertions, 0 deletions
diff --git a/drivers/gdisp/SSD1322/SSD1322.h b/drivers/gdisp/SSD1322/SSD1322.h
new file mode 100644
index 00000000..4da9250b
--- /dev/null
+++ b/drivers/gdisp/SSD1322/SSD1322.h
@@ -0,0 +1,78 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
+
+#ifndef _SSD1322_H
+#define _SSD1322_H
+
+/**************************************************
+* LM320Y-256064 (SSD1322 driver)
+*
+* Pin Function SPI connections
+* ----+------------+----------
+* 1 VSS GND
+* 2 VBAT 3.3V-5V
+* 3 NC
+* 4 D0 SCLK Serial Clock
+* 5 D1 MOSI Serial Data Input
+* 6 D2 NC
+* 7 D3 GND
+* 8 D4 GND
+* 9 D5 GND
+* 10 D6 GND
+* 11 D7 GND
+* 12 #RD GND
+* 13 #WR GND
+* 14 DC Data / Command
+* 15 #RESET
+* 16 #CS Chip select
+*
+* Note: All logic pins are 3.3V max.
+*
+* BS1 BS0 Mode
+* --------+---------------------
+* 0 0 "4 Line SPI" 8-bit + DC pin
+* 0 1 "3 Line SPI" 9-bit DC is 9th bit
+* 1 0 8-bit 8080 parallel
+* 1 1 8-bit 6800 parallel
+*
+* Note: SPI mode is write only (MOSI)
+*
+**************************************************/
+
+#define CMD_ENABLE_GRAY_SCALE_TABLE 0x00
+#define CMD_SET_COLUMN_ADDR 0x15
+#define CMD_WRITE_RAM 0x5C
+#define CMD_READ_RAM 0x5D
+#define CMD_SET_ROW_ADDR 0x75
+#define CMD_SET_REMAP 0xA0
+#define CMD_SET_DISPLAY_START_LINE 0xA1
+#define CMD_SET_DISPLAY_OFFSET 0xA2
+#define CMD_SET_DISPLAY_MODE_OFF 0xA4
+#define CMD_SET_DISPLAY_MODE_ON 0xA5
+#define CMD_SET_DISPLAY_MODE_NORMAL 0xA6
+#define CMD_SET_DISPLAY_MODE_INVERSE 0xA7
+#define CMD_ENABLE_PARTIAL_DISPLAY 0xA8
+#define CMD_EXIT_PARTIAL_DISPLAY 0xA9
+#define CMD_SET_FUNCTION_SELECTION 0xAB
+#define CMD_SET_DISPLAY_OFF 0xAE
+#define CMD_SET_DISPLAY_ON 0xAF
+#define CMD_SET_PHASE_LENGTH 0xB1
+#define CMD_SET_CLOCK_DIVIDER 0xB3
+#define CMD_DISPLAY_ENHANCEMENT 0xB4
+#define CMD_SET_GPIO 0xB5
+#define CMD_SET_SECOND_PRECHARGE_PERIOD 0xB6
+#define CMD_SET_GRAY_SCALE_TABLE 0xB8
+#define CMD_SET_PRECHARGE_VOLTAGE 0xBB
+#define CMD_SET_DEFAULT_LINEAR_GRAY_SCALE_TABLE 0xB9
+#define CMD_SET_VCOMH_VOLTAGE 0xBE
+#define CMD_SET_CONTRAST_CURRENT 0xC1
+#define CMD_MASTER_CURRENT_CONTROL 0xC7
+#define CMD_SET_MULTIPLEX_RATIO 0xCA
+#define CMD_DISPLAY_ENHANCEMENT_B 0xD1
+#define CMD_SET_COMMAND_LOCK 0xFD
+
+#endif /* _SSD1322_H */
diff --git a/drivers/gdisp/SSD1322/board_SSD1322_template.h b/drivers/gdisp/SSD1322/board_SSD1322_template.h
new file mode 100644
index 00000000..11759a95
--- /dev/null
+++ b/drivers/gdisp/SSD1322/board_SSD1322_template.h
@@ -0,0 +1,57 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+#ifndef _GDISP_LLD_BOARD_H
+#define _GDISP_LLD_BOARD_H
+
+//Optional
+//#define SSD1322_USE_DMA
+
+#ifndef SSD1322_USE_DMA
+ #define SSD1322_USE_DMA FALSE
+#endif
+
+static GFXINLINE void init_board(GDisplay *g) {
+ (void) g;
+}
+
+static GFXINLINE void post_init_board(GDisplay *g) {
+ (void) g;
+}
+
+static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) {
+ (void) g;
+ (void) state;
+}
+
+static GFXINLINE void acquire_bus(GDisplay *g) {
+ (void) g;
+}
+
+static GFXINLINE void release_bus(GDisplay *g) {
+ (void) g;
+}
+
+
+static GFXINLINE void write_cmd(GDisplay *g, uint8_t cmd) {
+ (void) g;
+ (void) cmd;
+}
+
+static GFXINLINE void write_data(GDisplay *g, uint8_t data) {
+ (void) g;
+ (void) data;
+}
+
+#if SSD1322_USE_DMA
+ static GFXINLINE void write_data_DMA(GDisplay *g, uint8_t* data) {
+ (void) g;
+ (void) data;
+ }
+#endif // Use DMA
+
+#endif /* _GDISP_LLD_BOARD_H */
diff --git a/drivers/gdisp/SSD1322/gdisp_lld_SSD1322.c b/drivers/gdisp/SSD1322/gdisp_lld_SSD1322.c
new file mode 100644
index 00000000..38c711a8
--- /dev/null
+++ b/drivers/gdisp/SSD1322/gdisp_lld_SSD1322.c
@@ -0,0 +1,299 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+#include "gfx.h"
+
+#if GFX_USE_GDISP
+
+#define GDISP_DRIVER_VMT GDISPVMT_SSD1322
+#include "gdisp_lld_config.h"
+#include "../../../src/gdisp/gdisp_driver.h"
+
+#include "board_SSD1322.h"
+#include <string.h> // for memset
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+#ifndef GDISP_SCREEN_HEIGHT
+ #define GDISP_SCREEN_HEIGHT 64 // This controller should support 64
+#endif
+#ifndef GDISP_SCREEN_WIDTH
+ #define GDISP_SCREEN_WIDTH 256
+#endif
+#ifndef GDISP_INITIAL_CONTRAST
+ #define GDISP_INITIAL_CONTRAST 100
+#endif
+#ifndef GDISP_INITIAL_BACKLIGHT
+ #define GDISP_INITIAL_BACKLIGHT 100
+#endif
+#ifndef SSD1322_USE_DMA
+ #define SSD1322_USE_DMA FALSE
+#endif
+
+#define SSD1322_ROW_WIDTH (GDISP_SCREEN_WIDTH/2)
+
+#define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER<<0)
+
+#include "SSD1322.h"
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+// Some common routines and macros
+#define RAM(g) ((uint8_t *)g->priv)
+
+// Some common routines and macros
+#define xyaddr(x, y) ((x) + (y)*SSD1322_ROW_WIDTH)
+#define xybits(x, y, c) ((c)<<(((x)&1)<<2))
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * As this controller can't update on a pixel boundary we need to maintain the
+ * the entire display surface in memory so that we can do the necessary bit
+ * operations. Fortunately it is a small display in 4 bit grayscale.
+ * 64 * 128 / 2 = 4096 bytes.
+ */
+
+LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
+ // The private area is the display surface.
+ g->priv = gfxAlloc(GDISP_SCREEN_HEIGHT * SSD1322_ROW_WIDTH);
+
+ // Initialise the board interface
+ init_board(g);
+ post_init_board(g);
+
+ // Hardware reset
+ setpin_reset(g, TRUE);
+ gfxSleepMilliseconds(20);
+ setpin_reset(g, FALSE);
+ gfxSleepMilliseconds(200);
+
+
+ write_cmd(g,CMD_SET_COMMAND_LOCK);
+ write_data(g,0x12); // Unlock OLED driver IC
+
+ write_cmd(g,CMD_SET_DISPLAY_OFF);
+
+ write_cmd(g,CMD_SET_CLOCK_DIVIDER);
+ write_data(g,0x91);
+
+ write_cmd(g,CMD_SET_MULTIPLEX_RATIO);
+ write_data(g,0x3F); //duty = 1/64*,64 COMS are enabled
+
+ write_cmd(g,CMD_SET_DISPLAY_OFFSET);
+ write_data(g,0x00);
+
+ write_cmd(g,CMD_SET_DISPLAY_START_LINE); //set start line position
+ write_data(g,0x00);
+
+ write_cmd(g,CMD_SET_REMAP);
+ write_data(g,0x14); //Horizontal address increment,Disable Column Address Re-map,Enable Nibble Re-map,Scan from COM[N-1] to COM0,Disable COM Split Odd Even
+ write_data(g,0x11); //Enable Dual COM mode
+
+ write_cmd(g,0xB5); //GPIO
+ write_data(g,0x00);
+ //writeCommand(0x00);
+
+ write_cmd(g,CMD_SET_FUNCTION_SELECTION);
+ write_data(g,0x01);// selection external VDD
+
+ write_cmd(g,CMD_DISPLAY_ENHANCEMENT);
+ write_data(g,0xA0);// enables the external VSL
+ write_data(g,0xb5);// 0xfd,Enhanced low GS display quality;default is 0xb5(normal),
+
+ write_cmd(g,CMD_SET_CONTRAST_CURRENT);
+ write_data(g,0x7f); // 0xff default is 0x7f
+
+ write_cmd(g,CMD_MASTER_CURRENT_CONTROL);
+ write_data(g,0x0f); //default is 0x0f
+
+ write_cmd(g,0xB9); //GRAY TABLE,linear Gray Scale
+
+ write_cmd(g,CMD_SET_PHASE_LENGTH);
+ write_data(g,0xE2); // default is 0x74
+
+ write_cmd(g,CMD_DISPLAY_ENHANCEMENT_B);
+ write_data(g,0xA2); // Reserved;default is 0xa2(normal)
+ write_data(g,0x20);
+
+ write_cmd(g,CMD_SET_PRECHARGE_VOLTAGE);
+ write_data(g,0x1F); // 0.6xVcc
+
+ write_cmd(g,CMD_SET_SECOND_PRECHARGE_PERIOD);
+ write_data(g,0x08); // default
+
+ write_cmd(g,CMD_SET_VCOMH_VOLTAGE );
+ write_data(g,0x07); // 0.86xVcc;default is 0x04
+
+ write_cmd(g,CMD_SET_DISPLAY_MODE_NORMAL);
+
+ write_cmd(g,CMD_EXIT_PARTIAL_DISPLAY);
+
+ write_cmd(g,CMD_SET_DISPLAY_ON);
+ // Finish Init
+ post_init_board(g);
+
+
+
+ /* Initialise the GDISP structure */
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Orientation = GDISP_ROTATE_180;
+ g->g.Powermode = powerOn;
+ g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
+ g->g.Contrast = GDISP_INITIAL_CONTRAST;
+ return TRUE;
+}
+
+#if GDISP_HARDWARE_FLUSH
+ LLDSPEC void gdisp_lld_flush(GDisplay *g) {
+ uint8_t * ram;
+ unsigned cols,rows;
+
+ // Don't flush if we don't need it.
+ if (!(g->flags & GDISP_FLG_NEEDFLUSH))
+ return;
+
+ acquire_bus(g);
+ write_cmd(g, CMD_SET_COLUMN_ADDR); // range 28 to 91 for 256 pixels to x
+ write_data(g, 28);
+ write_data(g, GDISP_SCREEN_WIDTH/4 + 28 - 1);
+ write_cmd(g, CMD_SET_ROW_ADDR); // range 0 to 63 for 64 pixels
+ write_data(g, 0);
+ write_data(g, GDISP_SCREEN_HEIGHT-1);
+ write_cmd(g, CMD_WRITE_RAM);
+ ram = RAM(g);
+ #if SSD1322_USE_DMA
+ write_data_DMA(g, ram);
+ #else
+ for(rows = 0; rows < GDISP_SCREEN_HEIGHT; rows ++) {
+ for(cols = 0;cols < GDISP_SCREEN_WIDTH/2; cols ++) {
+ write_data(g, *ram++);
+ }
+ }
+ #endif
+ release_bus(g);
+ g->flags &= ~GDISP_FLG_NEEDFLUSH;
+ }
+#endif
+
+#if GDISP_HARDWARE_DRAWPIXEL
+ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
+ coord_t x, y;
+ uint8_t *ram;
+
+ switch(g->g.Orientation) {
+ default:
+ case GDISP_ROTATE_0:
+ x = g->p.x;
+ y = g->p.y;
+ break;
+ case GDISP_ROTATE_90:
+ x = g->p.y;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.x;
+ break;
+ case GDISP_ROTATE_180:
+ x = GDISP_SCREEN_WIDTH-1 - g->p.x;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.y;
+ break;
+ case GDISP_ROTATE_270:
+ x = GDISP_SCREEN_WIDTH-1 - g->p.y;
+ y = g->p.x;
+ break;
+ }
+ ram = RAM(g)+xyaddr(x,y);
+ *ram &= ~xybits(x, y, LLDCOLOR_MASK());
+ *ram |= xybits(x, y, gdispColor2Native(g->p.color));
+ g->flags |= GDISP_FLG_NEEDFLUSH;
+ }
+#endif
+
+#if GDISP_HARDWARE_PIXELREAD
+ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
+ coord_t x, y;
+ LLDCOLOR_TYPE c;
+
+ switch(g->g.Orientation) {
+ default:
+ case GDISP_ROTATE_0:
+ x = g->p.x;
+ y = g->p.y;
+ break;
+ case GDISP_ROTATE_90:
+ x = g->p.y;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.x;
+ break;
+ case GDISP_ROTATE_180:
+ x = GDISP_SCREEN_WIDTH-1 - g->p.x;
+ y = GDISP_SCREEN_HEIGHT-1 - g->p.y;
+ break;
+ case GDISP_ROTATE_270:
+ x = GDISP_SCREEN_WIDTH-1 - g->p.y;
+ y = g->p.x;
+ break;
+ }
+ c = (RAM(g)[xyaddr(x, y)]>>((x & 1)<<2)) & LLDCOLOR_MASK();
+ return gdispNative2Color(c);
+ }
+#endif
+
+#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
+ LLDSPEC void gdisp_lld_control(GDisplay *g) {
+ switch(g->p.x) {
+ case GDISP_CONTROL_POWER:
+ if (g->g.Powermode == (powermode_t)g->p.ptr)
+ return;
+ switch((powermode_t)g->p.ptr) {
+ case powerOff:
+ case powerSleep:
+ case powerDeepSleep:
+ acquire_bus(g);
+ write_cmd(g, CMD_SET_DISPLAY_MODE_OFF);
+ release_bus(g);
+ break;
+ case powerOn:
+ acquire_bus(g);
+ write_cmd(g, CMD_SET_DISPLAY_MODE_ON);
+ release_bus(g);
+ break;
+ default:
+ return;
+ }
+ g->g.Powermode = (powermode_t)g->p.ptr;
+ return;
+
+ case GDISP_CONTROL_ORIENTATION:
+ if (g->g.Orientation == (orientation_t)g->p.ptr)
+ return;
+ switch((orientation_t)g->p.ptr) {
+ /* Rotation is handled by the drawing routines */
+ case GDISP_ROTATE_0:
+ case GDISP_ROTATE_180:
+ g->g.Height = GDISP_SCREEN_HEIGHT;
+ g->g.Width = GDISP_SCREEN_WIDTH;
+ break;
+ case GDISP_ROTATE_90:
+ case GDISP_ROTATE_270:
+ g->g.Height = GDISP_SCREEN_WIDTH;
+ g->g.Width = GDISP_SCREEN_HEIGHT;
+ break;
+ default:
+ return;
+ }
+ g->g.Orientation = (orientation_t)g->p.ptr;
+ return;
+ }
+ }
+#endif // GDISP_NEED_CONTROL
+
+#endif // GFX_USE_GDISP
diff --git a/drivers/gdisp/SSD1322/gdisp_lld_config.h b/drivers/gdisp/SSD1322/gdisp_lld_config.h
new file mode 100644
index 00000000..8ede4bc6
--- /dev/null
+++ b/drivers/gdisp/SSD1322/gdisp_lld_config.h
@@ -0,0 +1,26 @@
+/*
+ * This file is subject to the terms of the GFX License. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://ugfx.org/license.html
+ */
+
+#ifndef _GDISP_LLD_CONFIG_H
+#define _GDISP_LLD_CONFIG_H
+
+#if GFX_USE_GDISP
+
+/*===========================================================================*/
+/* Driver hardware support. */
+/*===========================================================================*/
+
+#define GDISP_HARDWARE_FLUSH TRUE // This controller requires flushing
+#define GDISP_HARDWARE_DRAWPIXEL TRUE
+#define GDISP_HARDWARE_PIXELREAD TRUE
+#define GDISP_HARDWARE_CONTROL TRUE
+
+#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_GRAY16
+
+#endif /* GFX_USE_GDISP */
+
+#endif /* _GDISP_LLD_CONFIG_H */
diff --git a/drivers/gdisp/SSD1322/readme.txt b/drivers/gdisp/SSD1322/readme.txt
new file mode 100644
index 00000000..571dcd62
--- /dev/null
+++ b/drivers/gdisp/SSD1322/readme.txt
@@ -0,0 +1,25 @@
+Description:
+
+Driver for OLED with 4-wire serial interface and I2C/SPI interface
+
+Know restictions:
+- Driver works only with SSD1306 hooked up over I2C or SPI (include corresponding header)
+- Driver is written for 128x64 pixel displays (128x32 are only partly supported and need small further work)
+- Flushing is required for this driver
+
+To use this driver:
+
+1. Add in your gfxconf.h:
+ a) #define GFX_USE_GDISP TRUE
+
+ b) Any optional high level driver defines (see gdisp.h) eg: GDISP_NEED_MULTITHREAD
+
+ c) The following are optional - define them if you are not using the defaults below:
+ #define GDISP_SCREEN_WIDTH 128
+ #define GDISP_SCREEN_HEIGHT 64
+
+2. If you are not using a known board then create a gdisp_lld_board.h file according to
+ given example files (or just stick with them) and ensure it is on your include path.
+
+3. To your makefile add the following lines:
+ include $(GFXLIB)/drivers/gdisp/SSD1322/gdisp_lld.mk