2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2018-02-15 17:43:05 +01:00
|
|
|
* drivers/lcd/ssd1306_base.c
|
2020-10-27 13:22:36 +01:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Driver for Univision UG-2864HSWEG01 OLED display or UG-2832HSWEG04 both
|
2020-10-27 13:22:36 +01:00
|
|
|
* with the Univision SSD1306 controller in SPI mode and Densitron
|
|
|
|
* DD-12864WO-4A with SSD1309 in SPI mode.
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* References:
|
2020-10-27 13:22:36 +01:00
|
|
|
* 1. Product Specification, Part Name: OEL Display Module, Part ID:
|
2012-12-26 21:04:57 +01:00
|
|
|
* UG-2864HSWEG01, Doc No: SAS1-9046-B, Univision Technology Inc.
|
2020-10-27 13:22:36 +01:00
|
|
|
* 2. Product Specification, Part Name: OEL Display Module, Part ID:
|
|
|
|
* UG-2832HSWEG04, Doc No.: SAS1-B020-B, Univision Technology Inc.
|
|
|
|
* 3. SSD1306, 128 X 64 Dot Matrix OLED/PLED, Preliminary Segment/Common
|
|
|
|
* Driver with Controller, Solomon Systech
|
|
|
|
* 4. SSD1309, 128 x 64 Dot Matrix OLED/PLED Segment/Common Driver with
|
|
|
|
* Controller, Solomon Systech
|
2021-03-04 07:10:42 +01:00
|
|
|
*/
|
2020-10-27 13:22:36 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2012-12-26 21:04:57 +01:00
|
|
|
* Device memory organization:
|
|
|
|
*
|
|
|
|
* +----------------------------+
|
|
|
|
* | Column |
|
|
|
|
* --------+----+---+---+---+-...-+-----+
|
|
|
|
* Page | 0 | 1 | 2 | 3 | ... | 127 |
|
|
|
|
* --------+----+---+---+---+-...-+-----+
|
|
|
|
* Page 0 | D0 | X | | | | |
|
|
|
|
* | D1 | X | | | | |
|
|
|
|
* | D2 | X | | | | |
|
|
|
|
* | D3 | X | | | | |
|
|
|
|
* | D4 | X | | | | |
|
|
|
|
* | D5 | X | | | | |
|
|
|
|
* | D6 | X | | | | |
|
|
|
|
* | D7 | X | | | | |
|
|
|
|
* --------+----+---+---+---+-...-+-----+
|
|
|
|
* Page 1 | | | | | | |
|
|
|
|
* --------+----+---+---+---+-...-+-----+
|
|
|
|
* Page 2 | | | | | | |
|
|
|
|
* --------+----+---+---+---+-...-+-----+
|
|
|
|
* Page 3 | | | | | | |
|
|
|
|
* --------+----+---+---+---+-...-+-----+
|
|
|
|
* Page 4 | | | | | | |
|
|
|
|
* --------+----+---+---+---+-...-+-----+
|
|
|
|
* Page 5 | | | | | | |
|
|
|
|
* --------+----+---+---+---+-...-+-----+
|
|
|
|
* Page 6 | | | | | | |
|
|
|
|
* --------+----+---+---+---+-...-+-----+
|
|
|
|
* Page 7 | | | | | | |
|
|
|
|
* --------+----+---+---+---+-...-+-----+
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
* ----------------------------------+--------------------------------------
|
|
|
|
* Landscape Display: | Reverse Landscape Display:
|
|
|
|
* --------+----------------------+ | --------+--------------------------+
|
|
|
|
* | Column | | | Column |
|
|
|
|
* --------+---+---+---+-..-+-----+ | --------+-----+-----+-----+-..-+---+
|
|
|
|
* Page 0 | 0 | 1 | 2 | | 127 | | Page 7 | 127 | 126 | 125 | | 0 |
|
|
|
|
* --------+---+---+---+-..-+-----+ | --------+-----+-----+-----+-..-+---+
|
|
|
|
* Page 1 | V | | Page 6 | ^ |
|
|
|
|
* --------+---+---+---+-..-+-----+ | --------+-----+-----+-----+-..-+---+
|
|
|
|
* Page 2 | V | | Page 5 | ^ |
|
|
|
|
* --------+---+---+---+-..-+-----+ | --------+-----+-----+-----+-..-+---+
|
|
|
|
* Page 3 | V | | Page 4 | ^ |
|
|
|
|
* --------+---+---+---+-..-+-----+ | --------+-----+-----+-----+-..-+---+
|
|
|
|
* Page 4 | V | | Page 3 | ^ |
|
|
|
|
* --------+---+---+---+-..-+-----+ | --------+-----+-----+-----+-..-+---+
|
|
|
|
* Page 5 | V | | Page 2 | ^ |
|
|
|
|
* --------+---+---+---+-..-+-----+ | --------+-----+-----+-----+-..-+---+
|
|
|
|
* Page 6 | V | | Page 1 | ^ |
|
|
|
|
* --------+---+---+---+-..-+-----+ | --------+-----+-----+-----+-..-+---+
|
|
|
|
* Page 7 | V | | Page 0 | ^ |
|
|
|
|
* --------+---+---+---+-..-+-----+ | --------+-----+-----+-----+-..-+---+
|
|
|
|
* ----------------------------------+--------------------------------------
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
* -----------------------------------+-------------------------------------
|
2012-12-26 21:04:57 +01:00
|
|
|
* Portrait Display: | Reverse Portrait Display:
|
|
|
|
* -----------+---------------------+ | -----------+---------------------+
|
|
|
|
* | Page | | | Page |
|
|
|
|
* -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
|
|
|
|
* Column 0 | 0 | 1 | 2 | | 7 | | Column 127 | 7 | 6 | 5 | | 0 |
|
|
|
|
* -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
|
|
|
|
* Column 1 | > > > > > | | Column 126 | |
|
|
|
|
* -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
|
|
|
|
* Column 2 | | | Column 125 | |
|
|
|
|
* -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
|
|
|
|
* ... | | | ... | |
|
|
|
|
* -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
|
|
|
|
* Column 127 | | | Column 0 | < < < < < |
|
|
|
|
* -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
|
2020-10-27 13:22:36 +01:00
|
|
|
* -----------------------------------+-------------------------------------
|
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2012-12-26 21:04:57 +01:00
|
|
|
* Included Files
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2012-12-26 21:04:57 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
2016-01-30 15:00:16 +01:00
|
|
|
#include <nuttx/i2c/i2c_master.h>
|
2013-07-01 16:11:54 +02:00
|
|
|
#include <nuttx/spi/spi.h>
|
2012-12-26 21:04:57 +01:00
|
|
|
#include <nuttx/lcd/lcd.h>
|
2013-06-23 22:39:56 +02:00
|
|
|
#include <nuttx/lcd/ssd1306.h>
|
2020-12-24 13:53:17 +01:00
|
|
|
#include <nuttx/signal.h>
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
#include <arch/irq.h>
|
|
|
|
|
2015-07-15 19:46:28 +02:00
|
|
|
#include "ssd1306.h"
|
2015-07-15 19:21:54 +02:00
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
#ifdef CONFIG_LCD_SSD1306
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2015-07-15 19:21:54 +02:00
|
|
|
* Private Function Prototypes
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* LCD Data Transfer Methods */
|
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
static int ssd1306_putrun(fb_coord_t row, fb_coord_t col,
|
|
|
|
FAR const uint8_t *buffer, size_t npixels);
|
2020-10-27 13:22:36 +01:00
|
|
|
static int ssd1306_getrun(fb_coord_t row, fb_coord_t col,
|
|
|
|
FAR uint8_t *buffer, size_t npixels);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* LCD Configuration */
|
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
static int ssd1306_getvideoinfo(FAR struct lcd_dev_s *dev,
|
|
|
|
FAR struct fb_videoinfo_s *vinfo);
|
2020-10-27 13:22:36 +01:00
|
|
|
static int ssd1306_getplaneinfo(FAR struct lcd_dev_s *dev,
|
|
|
|
unsigned int planeno,
|
2013-06-23 22:39:56 +02:00
|
|
|
FAR struct lcd_planeinfo_s *pinfo);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* LCD RGB Mapping */
|
|
|
|
|
|
|
|
#ifdef CONFIG_FB_CMAP
|
|
|
|
# error "RGB color mapping not supported by this driver"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Cursor Controls */
|
|
|
|
|
|
|
|
#ifdef CONFIG_FB_HWCURSOR
|
|
|
|
# error "Cursor control not supported by this driver"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* LCD Specific Controls */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
static int ssd1306_getpower(struct lcd_dev_s *dev);
|
|
|
|
static int ssd1306_setpower(struct lcd_dev_s *dev, int power);
|
|
|
|
static int ssd1306_getcontrast(struct lcd_dev_s *dev);
|
2020-10-27 13:22:36 +01:00
|
|
|
static int ssd1306_setcontrast(struct lcd_dev_s *dev,
|
|
|
|
unsigned int contrast);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
static int ssd1306_do_disponoff(struct ssd1306_dev_s *priv, bool on);
|
|
|
|
static int ssd1306_configuredisplay(struct ssd1306_dev_s *priv);
|
|
|
|
static int ssd1306_redrawfb(struct ssd1306_dev_s *priv);
|
2017-08-22 16:40:27 +02:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2012-12-26 21:04:57 +01:00
|
|
|
* Private Data
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* This is working memory allocated by the LCD driver for each LCD device
|
|
|
|
* and for each color plane. This memory will hold one raster line of data.
|
|
|
|
* The size of the allocated run buffer must therefore be at least
|
|
|
|
* (bpp * xres / 8). Actual alignment of the buffer must conform to the
|
|
|
|
* bitwidth of the underlying pixel type.
|
|
|
|
*
|
|
|
|
* If there are multiple planes, they may share the same working buffer
|
|
|
|
* because different planes will not be operate on concurrently. However,
|
|
|
|
* if there are multiple LCD devices, they must each have unique run buffers.
|
|
|
|
*/
|
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
static uint8_t g_runbuffer[SSD1306_DEV_ROWSIZE];
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* This structure describes the overall LCD video controller */
|
|
|
|
|
|
|
|
static const struct fb_videoinfo_s g_videoinfo =
|
|
|
|
{
|
2017-08-22 16:32:52 +02:00
|
|
|
.fmt = SSD1306_DEV_COLORFMT, /* Color format: B&W */
|
2013-06-23 22:39:56 +02:00
|
|
|
.xres = SSD1306_DEV_XRES, /* Horizontal resolution in pixel columns */
|
|
|
|
.yres = SSD1306_DEV_YRES, /* Vertical resolution in pixel rows */
|
|
|
|
.nplanes = 1, /* Number of color planes supported */
|
2012-12-26 21:04:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This is the standard, NuttX Plane information object */
|
|
|
|
|
|
|
|
static const struct lcd_planeinfo_s g_planeinfo =
|
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
.putrun = ssd1306_putrun, /* Put a run into LCD memory */
|
|
|
|
.getrun = ssd1306_getrun, /* Get a run from LCD memory */
|
|
|
|
.buffer = (FAR uint8_t *)g_runbuffer, /* Run scratch buffer */
|
|
|
|
.bpp = SSD1306_DEV_BPP, /* Bits-per-pixel */
|
2012-12-26 21:04:57 +01:00
|
|
|
};
|
|
|
|
|
2017-08-22 16:46:00 +02:00
|
|
|
/* This is the outside visible interface for the OLED driver */
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2017-08-22 16:46:00 +02:00
|
|
|
static const struct lcd_dev_s g_oleddev_dev =
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
2017-08-22 16:46:00 +02:00
|
|
|
/* LCD Configuration */
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2017-08-22 16:46:00 +02:00
|
|
|
.getvideoinfo = ssd1306_getvideoinfo,
|
|
|
|
.getplaneinfo = ssd1306_getplaneinfo,
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2017-08-22 16:46:00 +02:00
|
|
|
/* LCD RGB Mapping -- Not supported */
|
2020-10-27 13:22:36 +01:00
|
|
|
|
2017-08-22 16:46:00 +02:00
|
|
|
/* Cursor Controls -- Not supported */
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2017-08-22 16:46:00 +02:00
|
|
|
/* LCD Specific Controls */
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2017-08-22 16:46:00 +02:00
|
|
|
.getpower = ssd1306_getpower,
|
|
|
|
.setpower = ssd1306_setpower,
|
|
|
|
.getcontrast = ssd1306_getcontrast,
|
|
|
|
.setcontrast = ssd1306_setcontrast,
|
2012-12-26 21:04:57 +01:00
|
|
|
};
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* This is the OLED driver instance. Only a single device is supported
|
|
|
|
* for now.
|
|
|
|
*/
|
2017-08-22 16:46:00 +02:00
|
|
|
|
|
|
|
static struct ssd1306_dev_s g_oleddev;
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2012-12-26 21:04:57 +01:00
|
|
|
* Private Functions
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2013-06-23 22:39:56 +02:00
|
|
|
* Name: ssd1306_putrun
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This method can be used to write a partial raster line to the LCD.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* row - Starting row to write to (range: 0 <= row < yres)
|
|
|
|
* col - Starting column to write to (range: 0 <= col <= xres-npixels)
|
|
|
|
* buffer - The buffer containing the run to be written to the LCD
|
|
|
|
* npixels - The number of pixels to write to the LCD
|
|
|
|
* (range: 0 < npixels <= xres-col)
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
|
2020-10-27 13:22:36 +01:00
|
|
|
static int ssd1306_putrun(fb_coord_t row, fb_coord_t col,
|
|
|
|
FAR const uint8_t *buffer,
|
2013-06-23 22:39:56 +02:00
|
|
|
size_t npixels)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
2013-06-23 22:39:56 +02:00
|
|
|
FAR struct ssd1306_dev_s *priv = (FAR struct ssd1306_dev_s *)&g_oleddev;
|
2012-12-26 21:04:57 +01:00
|
|
|
FAR uint8_t *fbptr;
|
|
|
|
FAR uint8_t *ptr;
|
|
|
|
uint8_t devcol;
|
|
|
|
uint8_t fbmask;
|
|
|
|
uint8_t page;
|
|
|
|
uint8_t usrmask;
|
|
|
|
int pixlen;
|
|
|
|
uint8_t i;
|
2018-02-19 14:32:44 +01:00
|
|
|
int ret;
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("row: %d col: %d npixels: %d\n", row, col, npixels);
|
2012-12-26 21:04:57 +01:00
|
|
|
DEBUGASSERT(buffer);
|
|
|
|
|
|
|
|
/* Clip the run to the display */
|
|
|
|
|
|
|
|
pixlen = npixels;
|
2020-10-27 13:22:36 +01:00
|
|
|
if ((unsigned int)col + (unsigned int)pixlen >
|
|
|
|
(unsigned int)SSD1306_DEV_XRES)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
2013-06-23 22:39:56 +02:00
|
|
|
pixlen = (int)SSD1306_DEV_XRES - (int)col;
|
2012-12-26 21:04:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify that some portion of the run remains on the display */
|
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
if (pixlen <= 0 || row > SSD1306_DEV_YRES)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2013-06-24 20:37:02 +02:00
|
|
|
/* Perform coordinate conversion for reverse landscape mode.
|
|
|
|
* If the rows are reversed then rows are are a mirror reflection of
|
|
|
|
* top to bottom.
|
|
|
|
*/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2013-06-24 20:37:02 +02:00
|
|
|
#ifdef SSD1306_DEV_REVERSEY
|
2020-10-27 13:22:36 +01:00
|
|
|
row = (SSD1306_DEV_YRES - 1) - row;
|
2013-06-24 20:37:02 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If the column is switched then the start of the run is the mirror of
|
|
|
|
* the end of the run.
|
|
|
|
*
|
|
|
|
* col+pixlen-1
|
|
|
|
* col |
|
|
|
|
* 0 | | XRES
|
|
|
|
* . S>>>>>>E .
|
|
|
|
* . E<<<<<<S .
|
|
|
|
* | |
|
|
|
|
* | `-(XRES-1)-col
|
|
|
|
* ` (XRES-1)-col-(pixlen-1)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef SSD1306_DEV_REVERSEX
|
2020-10-27 13:22:36 +01:00
|
|
|
col = (SSD1306_DEV_XRES - 1) - col;
|
2013-06-24 20:37:02 +02:00
|
|
|
col -= (pixlen - 1);
|
2012-12-26 21:04:57 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get the page number. The range of 64 lines is divided up into eight
|
|
|
|
* pages of 8 lines each.
|
|
|
|
*/
|
|
|
|
|
|
|
|
page = row >> 3;
|
|
|
|
|
|
|
|
/* Update the shadow frame buffer memory. First determine the pixel
|
|
|
|
* position in the frame buffer memory. Pixels are organized like
|
|
|
|
* this:
|
|
|
|
*
|
|
|
|
* --------+---+---+---+---+-...-+-----+
|
|
|
|
* Segment | 0 | 1 | 2 | 3 | ... | 131 |
|
|
|
|
* --------+---+---+---+---+-...-+-----+
|
|
|
|
* D0 | | X | | | | |
|
|
|
|
* D1 | | X | | | | |
|
|
|
|
* D2 | | X | | | | |
|
|
|
|
* D3 | | X | | | | |
|
|
|
|
* D4 | | X | | | | |
|
|
|
|
* D5 | | X | | | | |
|
|
|
|
* D6 | | X | | | | |
|
2013-06-24 20:37:02 +02:00
|
|
|
* D7 | | X | | | | |
|
2012-12-26 21:04:57 +01:00
|
|
|
* --------+---+---+---+---+-...-+-----+
|
|
|
|
*
|
|
|
|
* So, in order to draw a white, horizontal line, at row 45. we
|
|
|
|
* would have to modify all of the bytes in page 45/8 = 5. We
|
|
|
|
* would have to set bit 45%8 = 5 in every byte in the page.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fbmask = 1 << (row & 7);
|
2013-06-23 22:39:56 +02:00
|
|
|
fbptr = &priv->fb[page * SSD1306_DEV_XRES + col];
|
2013-06-24 20:37:02 +02:00
|
|
|
#ifdef SSD1306_DEV_REVERSEX
|
|
|
|
ptr = fbptr + (pixlen - 1);
|
2012-12-26 21:04:57 +01:00
|
|
|
#else
|
|
|
|
ptr = fbptr;
|
|
|
|
#endif
|
2013-06-24 20:37:02 +02:00
|
|
|
|
2017-11-25 20:13:30 +01:00
|
|
|
#ifdef CONFIG_LCD_PACKEDMSFIRST
|
2012-12-26 21:04:57 +01:00
|
|
|
usrmask = MS_BIT;
|
|
|
|
#else
|
|
|
|
usrmask = LS_BIT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; i < pixlen; i++)
|
|
|
|
{
|
|
|
|
/* Set or clear the corresponding bit */
|
|
|
|
|
2013-06-24 20:37:02 +02:00
|
|
|
#ifdef SSD1306_DEV_REVERSEX
|
2012-12-26 21:04:57 +01:00
|
|
|
if ((*buffer & usrmask) != 0)
|
|
|
|
{
|
|
|
|
*ptr-- |= fbmask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ptr-- &= ~fbmask;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if ((*buffer & usrmask) != 0)
|
|
|
|
{
|
|
|
|
*ptr++ |= fbmask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ptr++ &= ~fbmask;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Inc/Decrement to the next source pixel */
|
|
|
|
|
2017-11-25 20:13:30 +01:00
|
|
|
#ifdef CONFIG_LCD_PACKEDMSFIRST
|
2012-12-26 21:04:57 +01:00
|
|
|
if (usrmask == LS_BIT)
|
|
|
|
{
|
|
|
|
buffer++;
|
|
|
|
usrmask = MS_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usrmask >>= 1;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (usrmask == MS_BIT)
|
|
|
|
{
|
|
|
|
buffer++;
|
|
|
|
usrmask = LS_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usrmask <<= 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Offset the column position to account for smaller horizontal
|
|
|
|
* display range.
|
|
|
|
*/
|
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
devcol = col + SSD1306_DEV_XOFFSET;
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Lock and select device */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_select(priv, true);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Select command transfer */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_cmddata(priv, true);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Set the starting position for the run */
|
2020-10-27 13:22:36 +01:00
|
|
|
|
2012-12-26 21:04:57 +01:00
|
|
|
/* Set the column address to the XOFFSET value */
|
2013-06-24 20:37:02 +02:00
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_SETCOLL(devcol & 0x0f));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_SETCOLH(devcol >> 4));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Set the page address */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_PAGEADDR(page));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Select data transfer */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_cmddata(priv, false);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Then transfer all of the data */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_sendblk(priv, fbptr, pixlen);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* De-select and unlock the device */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_select(priv, false);
|
2012-12-26 21:04:57 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# error "Configuration not implemented"
|
|
|
|
#endif
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2013-06-23 22:39:56 +02:00
|
|
|
* Name: ssd1306_getrun
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2013-06-24 20:37:02 +02:00
|
|
|
* This method can be used to read a partial raster line from the LCD.
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This method can be used to write a partial raster line to the LCD.
|
|
|
|
*
|
|
|
|
* row - Starting row to read from (range: 0 <= row < yres)
|
|
|
|
* col - Starting column to read read (range: 0 <= col <= xres-npixels)
|
|
|
|
* buffer - The buffer in which to return the run read from the LCD
|
|
|
|
* npixels - The number of pixels to read from the LCD
|
|
|
|
* (range: 0 < npixels <= xres-col)
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
|
2020-10-27 13:22:36 +01:00
|
|
|
static int ssd1306_getrun(fb_coord_t row, fb_coord_t col,
|
|
|
|
FAR uint8_t *buffer, size_t npixels)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
2013-06-23 22:39:56 +02:00
|
|
|
FAR struct ssd1306_dev_s *priv = &g_oleddev;
|
2012-12-26 21:04:57 +01:00
|
|
|
FAR uint8_t *fbptr;
|
|
|
|
uint8_t page;
|
|
|
|
uint8_t fbmask;
|
|
|
|
uint8_t usrmask;
|
|
|
|
int pixlen;
|
|
|
|
uint8_t i;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("row: %d col: %d npixels: %d\n", row, col, npixels);
|
2012-12-26 21:04:57 +01:00
|
|
|
DEBUGASSERT(buffer);
|
|
|
|
|
|
|
|
/* Clip the run to the display */
|
|
|
|
|
|
|
|
pixlen = npixels;
|
2020-10-27 13:22:36 +01:00
|
|
|
if ((unsigned int)col + (unsigned int)pixlen >
|
|
|
|
(unsigned int)SSD1306_DEV_XRES)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
2013-06-23 22:39:56 +02:00
|
|
|
pixlen = (int)SSD1306_DEV_XRES - (int)col;
|
2012-12-26 21:04:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify that some portion of the run is actually the display */
|
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
if (pixlen <= 0 || row > SSD1306_DEV_YRES)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-06-24 20:37:02 +02:00
|
|
|
/* Perform coordinate conversion for reverse landscape mode.
|
|
|
|
* If the rows are reversed then rows are are a mirror reflection of
|
|
|
|
* top to bottom.
|
|
|
|
*/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2013-06-24 20:37:02 +02:00
|
|
|
#ifdef SSD1306_DEV_REVERSEY
|
2020-10-27 13:22:36 +01:00
|
|
|
row = (SSD1306_DEV_YRES - 1) - row;
|
2013-06-24 20:37:02 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If the column is switched then the start of the run is the mirror of
|
|
|
|
* the end of the run.
|
|
|
|
*
|
|
|
|
* col+pixlen-1
|
|
|
|
* col |
|
|
|
|
* 0 | | XRES
|
|
|
|
* . S>>>>>>E .
|
|
|
|
* . E<<<<<<S .
|
|
|
|
* | |
|
|
|
|
* | `-(XRES-1)-col
|
|
|
|
* ` (XRES-1)-col-(pixlen-1)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef SSD1306_DEV_REVERSEX
|
2020-10-27 13:22:36 +01:00
|
|
|
col = (SSD1306_DEV_XRES - 1) - col;
|
2012-12-26 21:04:57 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Then transfer the display data from the shadow frame buffer memory */
|
2020-10-27 13:22:36 +01:00
|
|
|
|
2012-12-26 21:04:57 +01:00
|
|
|
/* Get the page number. The range of 64 lines is divided up into eight
|
|
|
|
* pages of 8 lines each.
|
|
|
|
*/
|
|
|
|
|
|
|
|
page = row >> 3;
|
|
|
|
|
|
|
|
/* Update the shadow frame buffer memory. First determine the pixel
|
|
|
|
* position in the frame buffer memory. Pixels are organized like
|
|
|
|
* this:
|
|
|
|
*
|
|
|
|
* --------+---+---+---+---+-...-+-----+
|
|
|
|
* Segment | 0 | 1 | 2 | 3 | ... | 131 |
|
|
|
|
* --------+---+---+---+---+-...-+-----+
|
|
|
|
* D0 | | X | | | | |
|
|
|
|
* D1 | | X | | | | |
|
|
|
|
* D2 | | X | | | | |
|
|
|
|
* D3 | | X | | | | |
|
|
|
|
* D4 | | X | | | | |
|
|
|
|
* D5 | | X | | | | |
|
|
|
|
* D6 | | X | | | | |
|
2013-06-24 20:37:02 +02:00
|
|
|
* D7 | | X | | | | |
|
2012-12-26 21:04:57 +01:00
|
|
|
* --------+---+---+---+---+-...-+-----+
|
|
|
|
*
|
|
|
|
* So, in order to draw a white, horizontal line, at row 45. we
|
|
|
|
* would have to modify all of the bytes in page 45/8 = 5. We
|
|
|
|
* would have to set bit 45%8 = 5 in every byte in the page.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fbmask = 1 << (row & 7);
|
2013-06-23 22:39:56 +02:00
|
|
|
fbptr = &priv->fb[page * SSD1306_DEV_XRES + col];
|
2013-06-24 20:37:02 +02:00
|
|
|
|
2017-11-25 20:13:30 +01:00
|
|
|
#ifdef CONFIG_LCD_PACKEDMSFIRST
|
2012-12-26 21:04:57 +01:00
|
|
|
usrmask = MS_BIT;
|
|
|
|
#else
|
|
|
|
usrmask = LS_BIT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; i < pixlen; i++)
|
|
|
|
{
|
|
|
|
/* Set or clear the corresponding bit */
|
2013-06-24 20:37:02 +02:00
|
|
|
|
|
|
|
#ifdef SSD1306_DEV_REVERSEX
|
2012-12-26 21:04:57 +01:00
|
|
|
uint8_t byte = *fbptr--;
|
|
|
|
#else
|
|
|
|
uint8_t byte = *fbptr++;
|
|
|
|
#endif
|
|
|
|
if ((byte & fbmask) != 0)
|
|
|
|
{
|
|
|
|
*buffer |= usrmask;
|
|
|
|
}
|
2017-08-22 16:42:40 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*buffer &= ~usrmask;
|
|
|
|
}
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2017-08-22 16:42:40 +02:00
|
|
|
/* Inc/Decrement to the next destination pixel. */
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2017-11-25 20:13:30 +01:00
|
|
|
#ifdef CONFIG_LCD_PACKEDMSFIRST
|
2012-12-26 21:04:57 +01:00
|
|
|
if (usrmask == LS_BIT)
|
|
|
|
{
|
|
|
|
buffer++;
|
|
|
|
usrmask = MS_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usrmask >>= 1;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (usrmask == MS_BIT)
|
|
|
|
{
|
|
|
|
buffer++;
|
|
|
|
usrmask = LS_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usrmask <<= 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# error "Configuration not implemented"
|
|
|
|
#endif
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2013-06-23 22:39:56 +02:00
|
|
|
* Name: ssd1306_getvideoinfo
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get information about the LCD video controller configuration.
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
static int ssd1306_getvideoinfo(FAR struct lcd_dev_s *dev,
|
|
|
|
FAR struct fb_videoinfo_s *vinfo)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
|
|
|
DEBUGASSERT(dev && vinfo);
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("fmt: %d xres: %d yres: %d nplanes: %d\n",
|
2020-10-27 13:22:36 +01:00
|
|
|
g_videoinfo.fmt, g_videoinfo.xres, g_videoinfo.yres,
|
|
|
|
g_videoinfo.nplanes);
|
2012-12-26 21:04:57 +01:00
|
|
|
memcpy(vinfo, &g_videoinfo, sizeof(struct fb_videoinfo_s));
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2013-06-23 22:39:56 +02:00
|
|
|
* Name: ssd1306_getplaneinfo
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get information about the configuration of each LCD color plane.
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
static int ssd1306_getplaneinfo(FAR struct lcd_dev_s *dev,
|
|
|
|
unsigned int planeno,
|
2013-06-23 22:39:56 +02:00
|
|
|
FAR struct lcd_planeinfo_s *pinfo)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
|
|
|
DEBUGASSERT(pinfo && planeno == 0);
|
2020-10-27 13:22:36 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("planeno: %d bpp: %d\n", planeno, g_planeinfo.bpp);
|
2012-12-26 21:04:57 +01:00
|
|
|
memcpy(pinfo, &g_planeinfo, sizeof(struct lcd_planeinfo_s));
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2013-06-23 22:39:56 +02:00
|
|
|
* Name: ssd1306_getpower
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2020-10-27 13:22:36 +01:00
|
|
|
* Get the LCD panel power status:
|
|
|
|
* 0: full off
|
|
|
|
* CONFIG_LCD_MAXPOWER: full on
|
|
|
|
* On backlit LCDs, this setting may correspond to the backlight setting.
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
static int ssd1306_getpower(FAR struct lcd_dev_s *dev)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
2013-06-23 22:39:56 +02:00
|
|
|
FAR struct ssd1306_dev_s *priv = (FAR struct ssd1306_dev_s *)dev;
|
2012-12-26 21:04:57 +01:00
|
|
|
DEBUGASSERT(priv);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("power: %s\n", priv->on ? "ON" : "OFF");
|
2012-12-26 21:04:57 +01:00
|
|
|
return priv->on ? CONFIG_LCD_MAXPOWER : 0;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2017-08-22 16:40:27 +02:00
|
|
|
* Name: ssd1306_do_disponoff
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enable/disable LCD panel power
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2017-08-22 16:40:27 +02:00
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
static int ssd1306_do_disponoff(struct ssd1306_dev_s *priv, bool on)
|
2017-08-22 16:40:27 +02:00
|
|
|
{
|
2018-02-19 14:32:44 +01:00
|
|
|
int ret;
|
|
|
|
|
2017-08-22 16:40:27 +02:00
|
|
|
/* Lock and select device */
|
|
|
|
|
|
|
|
ssd1306_select(priv, true);
|
|
|
|
|
|
|
|
/* Select command transfer */
|
|
|
|
|
|
|
|
ssd1306_cmddata(priv, true);
|
|
|
|
|
|
|
|
/* Turn the display on/off */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, (on ? SSD1306_DISPON : SSD1306_DISPOFF));
|
2017-08-22 16:40:27 +02:00
|
|
|
|
|
|
|
/* De-select and unlock the device */
|
|
|
|
|
|
|
|
ssd1306_cmddata(priv, false);
|
|
|
|
ssd1306_select(priv, false);
|
2018-02-19 14:32:44 +01:00
|
|
|
|
|
|
|
return ret;
|
2017-08-22 16:40:27 +02:00
|
|
|
}
|
|
|
|
|
2020-10-27 13:21:44 +01:00
|
|
|
/****************************************************************************
|
2013-06-23 22:39:56 +02:00
|
|
|
* Name: ssd1306_setpower
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2020-10-27 13:21:44 +01:00
|
|
|
* Enable/disable LCD panel power:
|
|
|
|
* 0: full off
|
|
|
|
* CONFIG_LCD_MAXPOWER: full on
|
|
|
|
* On backlit LCDs, this setting may correspond to the backlight setting.
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
2020-10-27 13:21:44 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2013-06-24 20:37:02 +02:00
|
|
|
static int ssd1306_setpower(FAR struct lcd_dev_s *dev, int power)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
2013-06-23 22:39:56 +02:00
|
|
|
struct ssd1306_dev_s *priv = (struct ssd1306_dev_s *)dev;
|
2018-02-19 14:32:44 +01:00
|
|
|
int ret;
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2020-10-27 13:21:44 +01:00
|
|
|
DEBUGASSERT(priv);
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("power: %d [%d]\n", power, priv->on ? CONFIG_LCD_MAXPOWER : 0);
|
2020-10-27 13:21:44 +01:00
|
|
|
DEBUGASSERT((unsigned)power <= CONFIG_LCD_MAXPOWER);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
if (power <= 0)
|
|
|
|
{
|
|
|
|
/* Turn the display off */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_do_disponoff(priv, false);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-26 21:04:57 +01:00
|
|
|
priv->on = false;
|
2017-08-22 16:40:27 +02:00
|
|
|
|
2022-05-24 14:46:28 +02:00
|
|
|
#ifdef CONFIG_SSD1306_POWEROFF_RECONFIGURE
|
|
|
|
|
|
|
|
/* Display is not configured anymore. */
|
|
|
|
|
|
|
|
priv->is_conf = false;
|
|
|
|
#else
|
|
|
|
|
2017-08-22 16:40:27 +02:00
|
|
|
/* Try turn off power completely */
|
|
|
|
|
|
|
|
if (priv->board_priv && priv->board_priv->set_vcc)
|
|
|
|
{
|
|
|
|
/* Do power off. */
|
|
|
|
|
|
|
|
if (priv->board_priv->set_vcc(false))
|
|
|
|
{
|
|
|
|
/* Display is completely powered off, not configured anymore. */
|
|
|
|
|
|
|
|
priv->is_conf = false;
|
|
|
|
}
|
|
|
|
}
|
2022-05-24 14:46:28 +02:00
|
|
|
#endif
|
2012-12-26 21:04:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-22 16:40:27 +02:00
|
|
|
if (priv->board_priv && priv->board_priv->set_vcc)
|
|
|
|
{
|
|
|
|
/* Do power on. */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
priv->board_priv->set_vcc(true);
|
2017-08-22 16:40:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv->is_conf)
|
|
|
|
{
|
|
|
|
/* Configure display and turn the display on */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_configuredisplay(priv);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-08-22 16:40:27 +02:00
|
|
|
|
|
|
|
/* Draw the framebuffer */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_redrawfb(priv);
|
2017-08-22 16:40:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Turn the display on */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_do_disponoff(priv, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
2017-08-22 16:40:27 +02:00
|
|
|
}
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
priv->on = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2013-06-23 22:39:56 +02:00
|
|
|
* Name: ssd1306_getcontrast
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the current contrast setting (0-CONFIG_LCD_MAXCONTRAST).
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
static int ssd1306_getcontrast(struct lcd_dev_s *dev)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
2013-06-23 22:39:56 +02:00
|
|
|
struct ssd1306_dev_s *priv = (struct ssd1306_dev_s *)dev;
|
2012-12-26 21:04:57 +01:00
|
|
|
DEBUGASSERT(priv);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("contrast: %d\n", priv->contrast);
|
2012-12-26 21:04:57 +01:00
|
|
|
return priv->contrast;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2013-06-23 22:39:56 +02:00
|
|
|
* Name: ssd1306_setcontrast
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set LCD panel contrast (0-CONFIG_LCD_MAXCONTRAST).
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
static int ssd1306_setcontrast(struct lcd_dev_s *dev, unsigned int contrast)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
2013-06-23 22:39:56 +02:00
|
|
|
struct ssd1306_dev_s *priv = (struct ssd1306_dev_s *)dev;
|
2012-12-26 21:04:57 +01:00
|
|
|
unsigned int scaled;
|
2018-02-19 14:32:44 +01:00
|
|
|
int ret;
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("contrast: %d\n", contrast);
|
2012-12-26 21:04:57 +01:00
|
|
|
DEBUGASSERT(priv);
|
|
|
|
|
|
|
|
/* Verify the contrast value */
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2012-12-26 21:04:57 +01:00
|
|
|
if (contrast > CONFIG_LCD_MAXCONTRAST)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Scale contrast: newcontrast = 255 * contrast / CONFIG_LCD_MAXCONTRAST
|
|
|
|
* Where contrast is in the range {1,255}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if CONFIG_LCD_MAXCONTRAST != 255
|
|
|
|
scaled = ((contrast << 8) - 1) / CONFIG_LCD_MAXCONTRAST;
|
|
|
|
#else
|
|
|
|
scaled = contrast;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Lock and select device */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_select(priv, true);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Select command transfer */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_cmddata(priv, true);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Set the contrast */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CONTRAST_MODE); /* Set contrast control register */
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CONTRAST(scaled)); /* Data 1: Set 1 of 256 contrast steps */
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-26 21:04:57 +01:00
|
|
|
priv->contrast = contrast;
|
|
|
|
|
|
|
|
/* De-select and unlock the device */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_select(priv, false);
|
2012-12-26 21:04:57 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2017-08-22 16:40:27 +02:00
|
|
|
* Name: ssd1306_configuredisplay
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2017-08-22 16:40:27 +02:00
|
|
|
* Setup LCD display.
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
static int ssd1306_configuredisplay(struct ssd1306_dev_s *priv)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
2018-02-19 14:32:44 +01:00
|
|
|
int ret;
|
|
|
|
|
2012-12-26 21:04:57 +01:00
|
|
|
/* Lock and select device */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_select(priv, true);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Select command transfer */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_cmddata(priv, true);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2013-01-01 15:55:01 +01:00
|
|
|
/* Configure OLED SPI or I/O, must be delayed 1-10ms */
|
|
|
|
|
2020-11-02 07:46:04 +01:00
|
|
|
nxsig_usleep(5000);
|
2013-01-01 15:55:01 +01:00
|
|
|
|
2012-12-26 21:04:57 +01:00
|
|
|
/* Configure the device */
|
|
|
|
|
2017-08-22 16:32:52 +02:00
|
|
|
#ifdef IS_SSD1309
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Unlock driver IC */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1309_PROTOFF);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Display off 0xae */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_DISPOFF);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set page addressing mode: 0x0, 0x01 or 0x02 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1309_SETMEMORY);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1309_MEMADDR(0x02));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set lower column address 0x00 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_SETCOLL(0));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set higher column address 0x10 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_SETCOLH(0));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set display start line 0x40 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_STARTLINE(0));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set page address (Can ignore) */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_PAGEADDR(0));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Contrast control 0x81 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CONTRAST_MODE);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Default contrast 0xff */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CONTRAST(SSD1309_DEV_CONTRAST));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set segment remap left 95 to 0 | 0xa1 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_REMAPPLEFT);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Normal display off 0xa4 (Can ignore) */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_EDISPOFF);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Normal (un-reversed) display mode 0xa6 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_NORMAL);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Multiplex ratio 0xa8 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_MRATIO_MODE);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Duty = 1/64 or 1/32 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_MRATIO(SSD1306_DEV_DUTY));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Com scan direction: Scan from COM[0] to COM[n-1] */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_SCANFROMCOM0);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set display offset 0xd3 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_DISPOFFS_MODE);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_DISPOFFS(0));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set clock divider 0xd5 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CLKDIV_SET);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* 0x70 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CLKDIV(7, 0));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set pre-charge period 0xd9 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CHRGPER_SET);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* 0xfa: Fh cycles for discharge and Ah cycles for pre-charge */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CHRGPER(0x0f, 0x0a));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set common pads / set com pins hardware configuration 0xda */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CMNPAD_CONFIG);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* 0x12 or 0x02 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CMNPAD(SSD1306_DEV_CMNPAD));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* set vcomh 0xdb */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_VCOM_SET);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_VCOM(0x3c));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-08-22 16:32:52 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Display off 0xae */
|
2018-02-19 14:32:44 +01:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_DISPOFF);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set lower column address 0x00 */
|
2018-02-19 14:32:44 +01:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_SETCOLL(0));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set higher column address 0x10 */
|
2018-02-19 14:32:44 +01:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_SETCOLH(0));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set display start line 0x40 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_STARTLINE(0));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Contrast control 0x81 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CONTRAST_MODE);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Default contrast 0xcf */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CONTRAST(SSD1306_DEV_CONTRAST));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set segment remap left 95 to 0 | 0xa1 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_REMAPPLEFT);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Normal (un-reversed) display mode 0xa6 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_NORMAL);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Multiplex ratio 0xa8 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_MRATIO_MODE);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Duty = 1/64 or 1/32 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_MRATIO(SSD1306_DEV_DUTY));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set display offset 0xd3 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_DISPOFFS_MODE);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_DISPOFFS(0));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set clock divider 0xd5 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CLKDIV_SET);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* 0x80 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CLKDIV(8, 0));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set pre-charge period 0xd9 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CHRGPER_SET);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* 0xf1 or 0x22 Enhanced mode */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CHRGPER(0x0f, 1));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set common pads / set com pins hardware configuration 0xda */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CMNPAD_CONFIG);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* 0x12 or 0x02 */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CMNPAD(SSD1306_DEV_CMNPAD));
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* set vcomh 0xdb */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_VCOM_SET);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_VCOM(0x40));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Set Charge Pump enable/disable 0x8d ssd1306 */
|
2015-07-15 19:21:54 +02:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CHRPUMP_SET);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* 0x14 close 0x10 */
|
2018-02-19 14:32:44 +01:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_CHRPUMP_ON);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-27 13:22:36 +01:00
|
|
|
|
2017-08-22 16:32:52 +02:00
|
|
|
#endif
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/* Display ON 0xaf */
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_DISPON);
|
2018-02-19 14:32:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* De-select and unlock the device */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_select(priv, false);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2020-11-02 07:46:04 +01:00
|
|
|
nxsig_usleep(100000);
|
2017-08-22 16:40:27 +02:00
|
|
|
|
|
|
|
priv->is_conf = true;
|
2018-02-19 14:32:44 +01:00
|
|
|
return OK;
|
2012-12-26 21:04:57 +01:00
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2017-08-22 16:40:27 +02:00
|
|
|
* Name: ssd1306_redrawfb
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2017-08-22 16:40:27 +02:00
|
|
|
* Redraw full framebuffer to display
|
2012-12-26 21:04:57 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - Reference to private driver structure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Caller has selected the OLED section.
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2012-12-26 21:04:57 +01:00
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
static int ssd1306_redrawfb(struct ssd1306_dev_s *priv)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
|
|
|
unsigned int page;
|
2018-02-19 14:32:44 +01:00
|
|
|
int ret;
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Lock and select device */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_select(priv, true);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Visit each page */
|
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
for (page = 0; page < SSD1306_DEV_PAGES; page++)
|
2012-12-26 21:04:57 +01:00
|
|
|
{
|
|
|
|
/* Select command transfer */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_cmddata(priv, true);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Set the column address to the XOFFSET value */
|
2013-06-24 20:37:02 +02:00
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_SETCOLL(SSD1306_DEV_XOFFSET));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_SETCOLH(0));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Set the page address */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_sendbyte(priv, SSD1306_PAGEADDR(page));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Select data transfer */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_cmddata(priv, false);
|
2012-12-26 21:04:57 +01:00
|
|
|
|
|
|
|
/* Transfer one page of the selected color */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
ret = ssd1306_sendblk(priv, &priv->fb[page * SSD1306_DEV_XRES],
|
|
|
|
SSD1306_DEV_XRES);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-26 21:04:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* De-select and unlock the device */
|
|
|
|
|
2015-07-15 19:21:54 +02:00
|
|
|
ssd1306_select(priv, false);
|
2018-02-19 14:32:44 +01:00
|
|
|
return OK;
|
2012-12-26 21:04:57 +01:00
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2017-08-22 16:40:27 +02:00
|
|
|
* Public Functions
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2017-08-22 16:40:27 +02:00
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2017-08-22 16:40:27 +02:00
|
|
|
* Name: ssd1306_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2020-10-27 13:22:36 +01:00
|
|
|
* Initialize the video hardware. The initial state of the OLED is
|
|
|
|
* fully initialized, display memory cleared, and the OLED ready
|
2017-08-22 16:40:27 +02:00
|
|
|
* to use, but with the power setting at 0 (full off == sleep mode).
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
* dev - A reference to the SPI/I2C driver instance.
|
|
|
|
* board_priv - Board specific structure.
|
|
|
|
* devno - A device number when there are multiple OLED devices.
|
|
|
|
* Currently must be zero.
|
2017-08-22 16:40:27 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
* On success, this function returns a reference to the LCD object for
|
|
|
|
* the specified OLED. NULL is returned on any failure.
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2017-08-22 16:40:27 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_LCD_SSD1306_SPI
|
|
|
|
FAR struct lcd_dev_s *ssd1306_initialize(FAR struct spi_dev_s *dev,
|
2020-10-27 13:22:36 +01:00
|
|
|
FAR const struct ssd1306_priv_s *board_priv,
|
|
|
|
unsigned int devno)
|
2017-08-22 16:40:27 +02:00
|
|
|
#else
|
|
|
|
FAR struct lcd_dev_s *ssd1306_initialize(FAR struct i2c_master_s *dev,
|
2020-10-27 13:22:36 +01:00
|
|
|
FAR const struct ssd1306_priv_s *board_priv,
|
|
|
|
unsigned int devno)
|
2017-08-22 16:40:27 +02:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
FAR struct ssd1306_dev_s *priv = &g_oleddev;
|
|
|
|
|
2017-08-22 16:46:00 +02:00
|
|
|
priv->dev = g_oleddev_dev;
|
|
|
|
|
2017-08-22 16:40:27 +02:00
|
|
|
DEBUGASSERT(dev && devno == 0);
|
|
|
|
|
|
|
|
priv->on = false;
|
|
|
|
priv->is_conf = false;
|
|
|
|
|
|
|
|
/* Register board specific functions */
|
|
|
|
|
|
|
|
priv->board_priv = board_priv;
|
|
|
|
|
|
|
|
#ifdef CONFIG_LCD_SSD1306_SPI
|
|
|
|
priv->spi = dev;
|
|
|
|
|
|
|
|
/* Configure the SPI */
|
|
|
|
|
|
|
|
ssd1306_configspi(priv->spi);
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* Remember the I2C configuration */
|
|
|
|
|
|
|
|
priv->i2c = dev;
|
|
|
|
priv->addr = CONFIG_SSD1306_I2CADDR;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialize the framebuffer */
|
|
|
|
|
|
|
|
memset(priv->fb, SSD1306_Y1_BLACK & 1 ? 0xff : 0x00, SSD1306_DEV_FBSIZE);
|
|
|
|
|
|
|
|
/* Power on and configure display */
|
|
|
|
|
|
|
|
ssd1306_setpower(&priv->dev, true);
|
|
|
|
|
|
|
|
return &priv->dev;
|
|
|
|
}
|
|
|
|
|
2020-10-27 13:22:36 +01:00
|
|
|
/****************************************************************************
|
2017-08-22 16:40:27 +02:00
|
|
|
* Name: ssd1306_fill
|
|
|
|
*
|
|
|
|
* Description:
|
2020-10-27 13:22:36 +01:00
|
|
|
* This non-standard method can be used to clear the entire display by
|
|
|
|
* writing one color to the display. This is much faster than writing a
|
|
|
|
* series of runs.
|
2017-08-22 16:40:27 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2020-10-27 13:22:36 +01:00
|
|
|
* dev - Reference to LCD object
|
|
|
|
* color - Desired color
|
2017-08-22 16:40:27 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Caller has selected the OLED section.
|
|
|
|
*
|
2020-10-27 13:22:36 +01:00
|
|
|
****************************************************************************/
|
2017-08-22 16:40:27 +02:00
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
int ssd1306_fill(FAR struct lcd_dev_s *dev, uint8_t color)
|
2017-08-22 16:40:27 +02:00
|
|
|
{
|
|
|
|
FAR struct ssd1306_dev_s *priv = (struct ssd1306_dev_s *)dev;
|
|
|
|
|
|
|
|
/* Make an 8-bit version of the selected color */
|
|
|
|
|
|
|
|
if (color & 1)
|
|
|
|
{
|
|
|
|
color = 0xff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the framebuffer */
|
|
|
|
|
|
|
|
memset(priv->fb, color, SSD1306_DEV_FBSIZE);
|
|
|
|
|
|
|
|
/* Draw the framebuffer */
|
|
|
|
|
2018-02-19 14:32:44 +01:00
|
|
|
return ssd1306_redrawfb(priv);
|
2017-08-22 16:40:27 +02:00
|
|
|
}
|
|
|
|
|
2013-06-23 22:39:56 +02:00
|
|
|
#endif /* CONFIG_LCD_SSD1306 */
|