* drivers/lcd/ssd1306.h
*
* SPDX-License-Identifier: Apache-2.0
*
* 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.
*
****************************************************************************/
#ifndef __DRIVERS_LCD_SSD1306_H
#define __DRIVERS_LCD_SSD1306_H
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/ssd1306.h>
* Pre-processor Definitions
****************************************************************************/
#if !defined(CONFIG_LCD_SH1106_OLED_132) && \
!defined(CONFIG_LCD_UG2864HSWEG01) && \
!defined(CONFIG_LCD_UG2832HSWEG04) && \
!defined(CONFIG_LCD_DD12864WO4A) && \
!defined(CONFIG_LCD_HILETGO) && \
!defined(CONFIG_LCD_SSD1306_CUSTOM)
# error "Unknown and unsupported SSD1306 LCD"
#endif
#if defined(CONFIG_LCD_PORTRAIT) || defined(CONFIG_LCD_RPORTRAIT)
# warning "No support for portrait modes"
# undef CONFIG_LCD_LANDSCAPE
# define CONFIG_LCD_LANDSCAPE 1
# undef CONFIG_LCD_PORTRAIT
# undef CONFIG_LCD_RLANDSCAPE
# undef CONFIG_LCD_RPORTRAIT
#endif
* Pre-processor Definitions
****************************************************************************/
#ifndef CONFIG_NX_BGCOLOR
# define CONFIG_NX_BGCOLOR SSD1306_Y1_BLACK
#endif
#define SSD1306_SETCOLL(ad) (0x00 | ((ad) & 0x0f))
#define SSD1306_SETCOLH(ad) (0x10 | ((ad) & 0x0f))
#define SSD1306_STARTLINE(ln) (0x40 | ((ln) & 0x3f))
#define SSD1306_CONTRAST_MODE (0x81)
# define SSD1306_CONTRAST(c) (c)
#define SSD1306_SEGREMAP(m) (0xa0 | ((m) & 0x01))
# define SSD1306_REMAPRIGHT SSD1306_SEGREMAP(0)
# define SSD1306_REMAPPLEFT SSD1306_SEGREMAP(1)
#define SSD1306_EDISPOFFON(s) (0xa4 | ((s) & 0x01))
# define SSD1306_EDISPOFF SSD1306_EDISPOFFON(0)
# define SSD1306_EDISPON SSD1306_EDISPOFFON(1)
#define SSD1306_NORMREV(s) (0xa6 | ((s) & 0x01))
# define SSD1306_NORMAL SSD1306_NORMREV(0)
# define SSD1306_REVERSE SSD1306_NORMREV(1)
#define SSD1306_MRATIO_MODE (0xa8)
# define SSD1306_MRATIO(d) ((d) & 0x3f)
#define SSD1306_DCDC_MODE (0xad)
# define SSD1306_DCDC_OFF (0x8a)
# define SSD1306_DCDC_ON (0x8b)
#define SSD1306_DISPOFFON(s) (0xae | ((s) & 0x01))
# define SSD1306_DISPOFF SSD1306_DISPOFFON(0)
# define SSD1306_DISPON SSD1306_DISPOFFON(1)
#define SSD1306_PAGEADDR(a) (0xb0 | ((a) & 0x0f))
#define SSD1306_SCANDIR(d) (0xc0 | ((d) & 0x08))
# define SSD1306_SCANFROMCOM0 SSD1306_SCANDIR(0x00)
# define SSD1306_SCANTOCOM0 SSD1306_SCANDIR(0x08)
#define SSD1306_DISPOFFS_MODE (0xd3)
# define SSD1306_DISPOFFS(o) ((o) & 0x3f)
#define SSD1306_CLKDIV_SET (0xd5)
# define SSD1306_CLKDIV(f,d) ((((f) & 0x0f) << 4) | ((d) & 0x0f))
#define SSD1306_CHRGPER_SET (0xd9)
# define SSD1306_CHRGPER(d,p) ((((d) & 0x0f) << 4) | ((p) & 0x0f))
#define SSD1306_CMNPAD_CONFIG (0xda)
# define SSD1306_CMNPAD(c) ((0x02) | ((c) & 0x10))
#define SSD1306_VCOM_SET (0xdb)
# define SSD1306_VCOM(v) (v)
#define SSD1306_CHRPUMP_SET (0x8d)
# define SSD1306_CHRPUMP_ON (0x14)
# define SSD1306_CHRPUMP_OFF (0x10)
#define SSD1306_RMWSTART (0xe0)
#define SSD1306_NOP (0xe3)
#define SSD1306_END (0xee)
#define SSD1306_WRDATA(d) (d)
#define SSD1306_STATUS_BUSY (0x80)
#define SSD1306_STATUS_ONOFF (0x40)
#define SSD1306_RDDATA(d) (d)
#define SSD1309_PROTOFF (0xfd)
#define SSD1309_SETMEMORY (0x20)
# define SSD1309_MEMADDR(ma) ((ma) & 0x03)
*
* The SSD1306 display controller can handle a resolution of 132x64.
* The UG-2864HSWEG01 on the base board is 128x64; the UG-2832HSWEG04
* is 128x32.
*/
#if defined(CONFIG_LCD_UG2864HSWEG01)
# define SSD1306_DEV_NATIVE_XRES 128
# define SSD1306_DEV_NATIVE_YRES 64
# define SSD1306_DEV_XOFFSET 2
# define SSD1306_DEV_PAGES 8
# define SSD1306_DEV_CMNPAD 0x12
# undef IS_SSD1309
#elif defined(CONFIG_LCD_UG2832HSWEG04)
# define SSD1306_DEV_NATIVE_XRES 128
# define SSD1306_DEV_NATIVE_YRES 32
# define SSD1306_DEV_XOFFSET 2
# define SSD1306_DEV_PAGES 4
# define SSD1306_DEV_CMNPAD 0x02
# undef IS_SSD1309
#elif defined(CONFIG_LCD_SH1106_OLED_132)
# define SSD1306_DEV_NATIVE_XRES 128
# define SSD1306_DEV_NATIVE_YRES 64
# define SSD1306_DEV_XOFFSET 0
# define SSD1306_DEV_PAGES 8
# define SSD1306_DEV_CMNPAD 0x12
# undef IS_SSD1309
#elif defined(CONFIG_LCD_HILETGO)
# define SSD1306_DEV_NATIVE_XRES 128
# define SSD1306_DEV_NATIVE_YRES 64
# define SSD1306_DEV_XOFFSET 0
# define SSD1306_DEV_PAGES 8
# define SSD1306_DEV_CMNPAD 0x12
# undef IS_SSD1309
#elif defined(CONFIG_LCD_DD12864WO4A)
# define SSD1306_DEV_NATIVE_XRES 128
# define SSD1306_DEV_NATIVE_YRES 64
# define SSD1306_DEV_XOFFSET 0
# define SSD1306_DEV_PAGES 8
# define SSD1306_DEV_CMNPAD 0x10
# define IS_SSD1309 1
#elif defined(CONFIG_LCD_SSD1306_CUSTOM)
# define SSD1306_DEV_NATIVE_XRES CONFIG_LCD_SSD1306_CUSTOM_DEV_NATIVE_XRES
# define SSD1306_DEV_NATIVE_YRES CONFIG_LCD_SSD1306_CUSTOM_DEV_NATIVE_YRES
# define SSD1306_DEV_XOFFSET CONFIG_LCD_SSD1306_CUSTOM_DEV_XOFFSET
# define SSD1306_DEV_PAGES CONFIG_LCD_SSD1306_CUSTOM_DEV_PAGES
# define SSD1306_DEV_CMNPAD CONFIG_LCD_SSD1306_CUSTOM_DEV_CMNPAD
# undef IS_SSD1309
#endif
#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
# define SSD1306_DEV_XRES SSD1306_DEV_NATIVE_XRES
# define SSD1306_DEV_YRES SSD1306_DEV_NATIVE_YRES
#else
# define SSD1306_DEV_XRES SSD1306_DEV_NATIVE_YRES
# define SSD1306_DEV_YRES SSD1306_DEV_NATIVE_XRES
#endif
#define SSD1306_DEV_DUTY (SSD1306_DEV_NATIVE_YRES-1)
#if defined(CONFIG_LCD_SH1106_OLED_132)
# define SSD1306_DEV_XSTRIDE (SSD1306_DEV_XRES >> 3)
#else
# define SSD1306_DEV_XSTRIDE (SSD1306_DEV_XRES >> 3)
#endif
#define SSD1306_DEV_YSTRIDE (SSD1306_DEV_YRES >> 3)
#define SSD1306_DEV_BPP 1
#define SSD1306_DEV_COLORFMT FB_FMT_Y1
#define SSD1306_DEV_CONTRAST (128)
#define SSD1309_DEV_CONTRAST (255)
*
* Frame buffer size: 128 columns x 64 rows / 8 bits-per-pixel
* Row size: 128 columns x 8 rows-per-page / 8 bits-per-pixel
*/
#define SSD1306_DEV_FBSIZE (SSD1306_DEV_XSTRIDE * SSD1306_DEV_YRES)
#define SSD1306_DEV_ROWSIZE (SSD1306_DEV_XSTRIDE)
#if defined(CONFIG_LCD_UG2864HSWEG01)
# if defined(CONFIG_LCD_LANDSCAPE)
# undef SSD1306_DEV_REVERSEX
# undef SSD1306_DEV_REVERSEY
# elif defined(CONFIG_LCD_RLANDSCAPE)
# define SSD1306_DEV_REVERSEX 1
# define SSD1306_DEV_REVERSEY 1
# endif
#elif defined(CONFIG_LCD_UG2832HSWEG04)
# if defined(CONFIG_LCD_LANDSCAPE)
# define SSD1306_DEV_REVERSEX 1
# undef SSD1306_DEV_REVERSEY
# elif defined(CONFIG_LCD_RLANDSCAPE)
# undef SSD1306_DEV_REVERSEX
# define SSD1306_DEV_REVERSEY 1
# endif
#elif defined(CONFIG_LCD_SH1106_OLED_132)
# if defined(CONFIG_LCD_LANDSCAPE)
# undef SSD1306_DEV_REVERSEX
# define SSD1306_DEV_REVERSEY 1
# elif defined(CONFIG_LCD_RLANDSCAPE)
# define SSD1306_DEV_REVERSEX 1
# undef SSD1306_DEV_REVERSEY
# endif
#elif defined(CONFIG_LCD_DD12864WO4A)
# if defined(CONFIG_LCD_LANDSCAPE)
# define SSD1306_DEV_REVERSEX 1
# undef SSD1306_DEV_REVERSEY
# elif defined(CONFIG_LCD_RLANDSCAPE)
# undef SSD1306_DEV_REVERSEX
# define SSD1306_DEV_REVERSEY 1
# endif
#elif defined(CONFIG_LCD_SSD1306_CUSTOM)
# if defined(CONFIG_LCD_LANDSCAPE)
# define SSD1306_DEV_REVERSEX 1
# undef SSD1306_DEV_REVERSEY
# elif defined(CONFIG_LCD_RLANDSCAPE)
# undef SSD1306_DEV_REVERSEX
# define SSD1306_DEV_REVERSEY 1
# endif
#endif
#define LS_BIT (1 << 0)
#define MS_BIT (1 << 7)
* Public Type Definition
****************************************************************************/
struct ssd1306_dev_s
{
struct lcd_dev_s dev;
#ifdef CONFIG_LCD_SSD1306_SPI
FAR struct spi_dev_s *spi;
#else
FAR struct i2c_master_s *i2c;
uint8_t addr;
#endif
uint8_t devno;
uint8_t contrast;
bool on;
bool is_conf;
FAR const struct ssd1306_priv_s *board_priv;
* mode. Since there is 1 BPP and access is byte-by-byte, it is necessary
* to keep a shadow copy of the framebuffer memory. At 128x64, this
* amounts to 1 KB.
*/
uint8_t fb[SSD1306_DEV_FBSIZE];
uint8_t runbuffer[SSD1306_DEV_ROWSIZE];
};
* Public Function Prototypes
****************************************************************************/
int ssd1306_sendbyte(FAR struct ssd1306_dev_s *priv, uint8_t regval);
int ssd1306_sendblk(FAR struct ssd1306_dev_s *priv, uint8_t *data,
uint8_t len);
#ifdef CONFIG_LCD_SSD1306_SPI
void ssd1306_select(FAR struct ssd1306_dev_s *priv, bool cs);
void ssd1306_cmddata(FAR struct ssd1306_dev_s *priv, bool cmd);
void ssd1306_configspi(FAR struct spi_dev_s *spi);
#else
# define ssd1306_select(priv, cs)
# define ssd1306_cmddata(priv, cmd)
# define ssd1306_configspi(spi)
#endif
#endif