Skip to content

Commit d31f378

Browse files
committed
lvgl: Add driver for SSD1306
This adds driver for SSD1306 display controller. Signed-off-by: Jerzy Kasenberg <[email protected]>
1 parent 2f2f4b0 commit d31f378

File tree

5 files changed

+265
-0
lines changed

5 files changed

+265
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
19+
pkg.name: hw/drivers/display/lvgl/oled/ssd1306
20+
pkg.description: LVGL display driver for SSD1306
21+
pkg.author: "Apache Mynewt <[email protected]>"
22+
pkg.homepage: "http://mynewt.apache.org/"
23+
pkg.keywords:
24+
25+
pkg.cflags:
26+
27+
pkg.deps:
28+
- "@apache-mynewt-core/hw/drivers/display/lcd_itf"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include <bsp/bsp.h>
21+
#include <hal/lv_hal_disp.h>
22+
#include <hal/hal_gpio.h>
23+
#include <lcd_itf.h>
24+
25+
/*
26+
* Fundamental Command Table
27+
*/
28+
#define SSD1306_SET_LOWER_COL_ADDRESS 0x00
29+
#define SSD1306_SET_LOWER_COL_ADDRESS_MASK 0x0f
30+
31+
#define SSD1306_SET_HIGHER_COL_ADDRESS 0x10
32+
#define SSD1306_SET_HIGHER_COL_ADDRESS_MASK 0x0f
33+
34+
#define SSD1306_SET_MEM_ADDRESSING_MODE 0x20
35+
#define SSD1306_SET_MEM_ADDRESSING_HORIZONTAL 0x00
36+
#define SSD1306_SET_MEM_ADDRESSING_VERTICAL 0x01
37+
#define SSD1306_SET_MEM_ADDRESSING_PAGE 0x02
38+
39+
#define SSD1306_SET_COLUMN_ADDRESS 0x21
40+
41+
#define SSD1306_SET_PAGE_ADDRESS 0x22
42+
43+
#define SSD1306_HORIZONTAL_SCROLL_SETUP 0x26
44+
45+
#define SSD1306_CONTINUOUS_VERTICAL_AND_HORIZONTAL_SCROLL_SETUP 0x29
46+
47+
#define SSD1306_DEACTIVATE_SCROLL 0x2e
48+
49+
#define SSD1306_ACTIVATE_SCROLL 0x2f
50+
51+
#define SSD1306_SET_START_LINE 0x40
52+
#define SSD1306_SET_START_LINE_MASK 0x3f
53+
54+
#define SSD1306_SET_CONTRAST_CTRL 0x81
55+
56+
#define SDD1406_CHARGE_PUMP_SETTING 0x8d
57+
#define SDD1406_CHARGE_PUMP_SETTING_DISABLE 0x10
58+
#define SDD1406_CHARGE_PUMP_SETTING_ENABLE 0x14
59+
60+
#define SSD1306_SET_SEGMENT_MAP_NORMAL 0xa0
61+
#define SSD1306_SET_SEGMENT_MAP_REMAPED 0xa1
62+
63+
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xa3
64+
65+
#define SSD1306_SET_ENTIRE_DISPLAY_OFF 0xa4
66+
#define SSD1306_SET_ENTIRE_DISPLAY_ON 0xa5
67+
68+
#define SSD1306_SET_NORMAL_DISPLAY 0xa6
69+
#define SSD1306_SET_REVERSE_DISPLAY 0xa7
70+
71+
#define SSD1306_SET_MULTIPLEX_RATIO 0xa8
72+
73+
#define SSD1306_DISPLAY_OFF 0xae
74+
#define SSD1306_DISPLAY_ON 0xaf
75+
76+
#define SSD1306_SET_PAGE_START_ADDRESS 0xb0
77+
#define SSD1306_SET_PAGE_START_ADDRESS_MASK 0x07
78+
79+
#define SSD1306_SET_COM_OUTPUT_SCAN_NORMAL 0xc0
80+
#define SSD1306_SET_COM_OUTPUT_SCAN_FLIPPED 0xc8
81+
82+
#define SSD1306_SET_DISPLAY_OFFSET 0xd3
83+
84+
#define SSD1306_SET_CLOCK_DIV_RATIO 0xd5
85+
86+
#define SSD1306_SET_CHARGE_PERIOD 0xd9
87+
88+
#define SSD1306_SET_PADS_HW_CONFIG 0xda
89+
90+
#define SSD1306_SET_VCOM_DESELECT_LEVEL 0xdb
91+
92+
#define SSD1306_NOP 0xe3
93+
94+
#define SSD1306_SET_PADS_HW_SEQUENTIAL 0x02
95+
#define SSD1306_SET_PADS_HW_ALTERNATIVE 0x12
96+
97+
#define SSD1306_SET_CHARGE_PUMP_ON 0x8d
98+
#define SSD1306_SET_CHARGE_PUMP_ON_DISABLED 0x10
99+
#define SSD1306_SET_CHARGE_PUMP_ON_ENABLED 0x14
100+
101+
#define SH1106_SET_DCDC_MODE 0xad
102+
#define SH1106_SET_DCDC_DISABLED 0x8a
103+
#define SH1106_SET_DCDC_ENABLED 0x8b
104+
105+
#define SSD1306_SET_PUMP_VOLTAGE_64 0x30
106+
#define SSD1306_SET_PUMP_VOLTAGE_74 0x31
107+
#define SSD1306_SET_PUMP_VOLTAGE_80 0x32
108+
#define SSD1306_SET_PUMP_VOLTAGE_90 0x33
109+
110+
#define SSD1306_READ_MODIFY_WRITE_START 0xe0
111+
#define SSD1306_READ_MODIFY_WRITE_END 0xee
112+
113+
#define SSD1306_CLOCK_DIV_RATIO 0x0
114+
#define SSD1306_CLOCK_FREQUENCY 0x8
115+
#define SSD1306_PANEL_VCOM_DESEL_LEVEL 0x20
116+
#define SSD1306_PANEL_PUMP_VOLTAGE SSD1306_SET_PUMP_VOLTAGE_90
117+
118+
LCD_SEQUENCE(init_cmds)
119+
LCD_SEQUENCE_LCD_CS_INACTIVATE(),
120+
LCD_SEQUENCE_LCD_DC_DATA(),
121+
/* command length, command, args */
122+
1, SSD1306_DISPLAY_OFF,
123+
2, SSD1306_SET_CLOCK_DIV_RATIO, (SSD1306_CLOCK_FREQUENCY << 4) | SSD1306_CLOCK_DIV_RATIO,
124+
2, SSD1306_SET_MULTIPLEX_RATIO, 0x3f,
125+
2, SSD1306_SET_DISPLAY_OFFSET, 0,
126+
1, SSD1306_SET_START_LINE + 0,
127+
2, SDD1406_CHARGE_PUMP_SETTING, SDD1406_CHARGE_PUMP_SETTING_ENABLE,
128+
2, SSD1306_SET_MEM_ADDRESSING_MODE, SSD1306_SET_MEM_ADDRESSING_HORIZONTAL,
129+
1, SSD1306_SET_SEGMENT_MAP_REMAPED,
130+
1, SSD1306_SET_COM_OUTPUT_SCAN_FLIPPED,
131+
132+
2, SSD1306_SET_PADS_HW_CONFIG, 0x12,
133+
2, SSD1306_SET_CONTRAST_CTRL, 0xcf,
134+
135+
2, SSD1306_SET_CHARGE_PERIOD, 0xF1,
136+
137+
2, SSD1306_SET_VCOM_DESELECT_LEVEL, 0x40,
138+
139+
1, SSD1306_DEACTIVATE_SCROLL,
140+
141+
1, SSD1306_SET_ENTIRE_DISPLAY_OFF,
142+
1, SSD1306_SET_NORMAL_DISPLAY,
143+
1, SSD1306_SET_START_LINE + 0,
144+
145+
3, SSD1306_SET_HIGHER_COL_ADDRESS, 0, 0xb0,
146+
147+
1, SSD1306_DISPLAY_ON,
148+
LCD_SEQUENCE_END
149+
150+
/**
151+
* Initialize the SSD1306 display controller
152+
*/
153+
void
154+
ssd1306_init(lv_disp_drv_t *driver)
155+
{
156+
lcd_command_sequence(init_cmds);
157+
}
158+
159+
void
160+
ssd1306_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p)
161+
{
162+
uint8_t page1 = area->y1 >> 3;
163+
uint8_t page2 = area->y2 >> 3;
164+
uint8_t *buf = (uint8_t *)color_p;
165+
uint8_t b[3];
166+
167+
b[0] = SSD1306_SET_COLUMN_ADDRESS;
168+
b[1] = (uint8_t)area->x1;
169+
b[2] = (uint8_t)area->x2;
170+
lcd_ift_write_cmd(b, 3);
171+
172+
b[0] = SSD1306_SET_PAGE_ADDRESS;
173+
b[1] = page1;
174+
b[2] = page2;
175+
lcd_ift_write_cmd(b, 3);
176+
177+
lcd_itf_write_color_data(area->x1, area->y1, area->x2, area->y2, buf);
178+
179+
lv_disp_flush_ready(drv);
180+
}
181+
182+
void
183+
ssd1306_set_px_cb(struct _lv_disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
184+
lv_color_t color, lv_opa_t opa)
185+
{
186+
uint16_t byte_index = x + ((y >> 3) * buf_w);
187+
uint8_t bit_index = y & 0x7;
188+
189+
if (color.full == 0) {
190+
buf[byte_index] |= 1 << bit_index;
191+
} else {
192+
buf[byte_index] &= ~(1 << bit_index);
193+
}
194+
}
195+
196+
void
197+
mynewt_lv_drv_init(lv_disp_drv_t *driver)
198+
{
199+
lcd_itf_init();
200+
driver->flush_cb = ssd1306_flush;
201+
driver->set_px_cb = ssd1306_set_px_cb;
202+
driver->hor_res = MYNEWT_VAL(LVGL_DISPLAY_HORIZONTAL_RESOLUTION);
203+
driver->ver_res = MYNEWT_VAL(LVGL_DISPLAY_VERTICAL_RESOLUTION);
204+
205+
ssd1306_init(driver);
206+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
19+
syscfg.defs:
20+
21+
syscfg.vals:
22+
LVGL_DISPLAY_HORIZONTAL_RESOLUTION: 128
23+
LVGL_DISPLAY_VERTICAL_RESOLUTION: 64
24+
25+
syscfg.restrictions:
26+
- LV_DISP_Y_ALIGN == 3

hw/drivers/display/lvgl/pkg.yml

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pkg.deps:
5858
- "@apache-mynewt-core/hw/hal"
5959
- "@apache-mynewt-core/hw/drivers/display/lcd_itf"
6060

61+
pkg.deps.LVGL_SSD1306:
62+
- "@apache-mynewt-core/hw/drivers/display/lvgl/oled/ssd1306"
6163
pkg.deps.LVGL_GC9A01:
6264
- "@apache-mynewt-core/hw/drivers/display/lvgl/tft/gc9a01"
6365
pkg.deps.LVGL_ILI9341:

hw/drivers/display/lvgl/syscfg.yml

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ syscfg.defs:
2222
LV_COLOR_16_SWAP changes order of 16 bit RGB value to
2323
better match 8 bit SPI protocol.
2424
value: 0
25+
LVGL_SSD1306:
26+
description: Enable SSD1306 display driver.
27+
value:
2528
LVGL_GC9A01:
2629
description: Enable GC9A01 display driver.
2730
value:

0 commit comments

Comments
 (0)