VSF Documented
vsf_disp_ssd1306.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17#ifndef __VSF_DISP_SSD1306_H__
18#define __VSF_DISP_SSD1306_H__
19
20/*============================ INCLUDES ======================================*/
21
23
24#if VSF_USE_UI == ENABLED && VSF_DISP_USE_SSD1306 == ENABLED
25
26#include "../common/vsf_disp_solomon_systech_common.h"
27
28#if defined(__VSF_DISP_SSD1306_CLASS_IMPLEMENT)
29# undef __VSF_DISP_SSD1306_CLASS_IMPLEMENT
30# define __VSF_CLASS_IMPLEMENT__
31#endif
32
33#include "utilities/ooc_class.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/*============================ MACROS ========================================*/
40
41#define VSF_SSD1306_PORT_IIC 0
42#define VSF_SSD1306_PORT_SPI 1
43#define VSF_SSD1306_PORT_EBI 2
44
45#ifndef VSF_SSD1306_CFG_PORT
46# define VSF_SSD1306_CFG_PORT VSF_SSD1306_PORT_IIC
47#endif
48
49#define SSD1306_SET_DISPLAY_ON(__ON) (0xAE | ((__ON) ? 1 : 0))
50#define SSD1306_SET_DISPLAY_START_LINE(__LINE) (0x40 | ((__LINE) & 0x3F))
51#define SSD1306_SET_POAGE_START_ADDRESS(__PAGE) (0xB0 | ((__PAGE) & 0x07))
52#define SSD1306_SET_COM_OUTPUT_SCAN_DIRECTION(__DIR) (0xC0 | ((__DIR) ? 0x08 : 0x00))
53#define SSD1306_SET_CONTRAST_CONTROL (0x81)
54#define SSD1306_SET_SEGMENT_REMAP(__REMAP) (0xA0 | ((__REMAP) ? 1 : 0))
55#define SSD1306_SET_INVERSE_DISPLAY(__INVERSE) (0xA6 | ((__INVERSE) ? 1 : 0))
56#define SSD1306_SET_MULTIPLEX_RATIO (0xA8)
57#define SSD1306_SET_DISPLAY_OFFSET (0xD3)
58#define SSD1306_SET_OSC_DIV (0xD5)
59#define SSD1306_SET_PRECHARGE_PERIOD (0xD9)
60#define SSD1306_SET_COM_PIN (0xDA)
61#define SSD1306_SET_VCOMH (0xDB)
62#define SSD1306_CHARGE_PUMP (0x8D)
63
64#define SSD1306_SET_ADDRESS_MODE (0x20)
65# define SSD1306_ADDRESS_MODE_HORIZONTAL (0x00)
66# define SSD1306_ADDRESS_MODE_VERTICAL (0x01)
67# define SSD1306_ADDRESS_MODE_PAGE (0x02)
68#define SSD1306_SET_COLUMN_ADDRESS (0x21)
69#define SSD1306_SET_PAGE_ADDRESS (0x22)
70
71/*============================ MACROFIED FUNCTIONS ===========================*/
72
73// TODO: add more parameters
74#if VSF_SSD1306_CFG_PORT == VSF_SSD1306_PORT_IIC
75# define VSF_DISP_SSD1306_IIC_INIT_SEQ(__LINE, __CONTRAST, __INVERSE, __DIRECTION)\
76 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_DISPLAY_ON(0)), \
77 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_DISPLAY_START_LINE(0)),\
78 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_COM_OUTPUT_SCAN_DIRECTION(__DIRECTION)),\
79 \
80 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_CONTRAST_CONTROL), \
81 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(__CONTRAST), \
82 \
83 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_SEGMENT_REMAP(1)), \
84 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_INVERSE_DISPLAY(__INVERSE)),\
85 \
86 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_MULTIPLEX_RATIO), \
87 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I((__LINE) - 1), \
88 \
89 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_DISPLAY_OFFSET), \
90 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(0), \
91 \
92 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_OSC_DIV), \
93 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(0xF0), \
94 \
95 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_PRECHARGE_PERIOD), \
96 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(0x22), \
97 \
98 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_COM_PIN), \
99 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(0x02), \
100 \
101 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_VCOMH), \
102 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(0x20), \
103 \
104 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_CHARGE_PUMP), \
105 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(0x15), \
106 \
107 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_DISPLAY_ON(1)), \
108 \
109 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_SET_ADDRESS_MODE), \
110 VSF_DISP_SOLOMON_SYSTECH_IIC_WRITE_I(SSD1306_ADDRESS_MODE_HORIZONTAL)
111#elif VSF_SSD1306_CFG_PORT == VSF_SSD1306_PORT_SPI
112#elif VSF_SSD1306_CFG_PORT == VSF_SSD1306_PORT_EBI
113#endif
114
115/*============================ TYPES =========================================*/
116
118 public_member(
119 implement(vk_disp_t)
120
122 implement_ex(vsf_disp_solomon_systech_hw_iic_t, hw)
123 const uint8_t *init_seq;
124 const uint16_t init_seq_len;
125#elif VSF_SSD1306_CFG_PORT == VSF_SSD1306_PORT_SPI
126 implement_ex(vsf_disp_solomon_systech_hw_spi_t, hw)
127#elif VSF_SSD1306_CFG_PORT == VSF_SSD1306_PORT_EBI
128 implement_ex(vsf_disp_solomon_systech_hw_ebi_t, hw)
129#endif
130 )
131
132 private_member(
133 vsf_eda_t eda;
134 struct {
135 struct {
136 vk_disp_area_t area;
137 uint8_t *buffer;
138 } refresh;
139 } ctx;
140
141 bool is_inited;
142 bool is_area_set;
143#if VSF_SSD1306_CFG_PORT == VSF_SSD1306_PORT_IIC
144 uint8_t set_area_cmd_buffer[6 * 2];
145#elif VSF_SSD1306_CFG_PORT == VSF_SSD1306_PORT_SPI
146#elif VSF_SSD1306_CFG_PORT == VSF_SSD1306_PORT_EBI
147#endif
149};
150
151/*============================ GLOBAL VARIABLES ==============================*/
152
154
155/*============================ PROTOTYPES ====================================*/
156
157#ifdef __cplusplus
158}
159#endif
160
161#endif // VSF_USE_UI
162#endif // __VSF_DISP_SSD1306_H__
Definition vsf_disp.h:149
Definition vsf_disp_ssd1306.h:117
Definition vsf_disp.h:173
Definition vsf_eda.h:766
#define vsf_class(__name)
Definition ooc_class.h:48
unsigned short uint16_t
Definition stdint.h:7
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_disp.h:144
Definition vsf_disp_solomon_systech_common.h:61
Definition vsf_disp_solomon_systech_common.h:45
Definition vsf_disp_solomon_systech_common.h:49
#define VSF_SSD1306_CFG_PORT
Definition vsf_disp_ssd1306.h:46
const vk_disp_drv_t vk_disp_drv_ssd1306
Definition vsf_disp_ssd1306.c:48
#define VSF_SSD1306_PORT_IIC
Definition vsf_disp_ssd1306.h:41