Skip to content

Commit 6ceb9e4

Browse files
committed
Add hardware scrolling functionalities.
Changes to be committed: modified: drivers/display/ssd1306.py The scroll method in the MicroPython's ssd1306 class is based on FrameBuffer class's scroll().That may leave a footprint of the previous colors in the FrameBuffer. By adopting the modified version of the ssd1306 class written by Tim Toliver, we add the following methods to the ssd1306 class: - clear():clear the OLED. - hw_scroll_h(direction=True, interval=FRAMES_5):continuously scroll to right/left. - direction: True/False, scroll to right/left. - interval: - SSD1306.FRAMES_2 - SSD1306.FRAMES_3 - SSD130.FRAMES_4 - SSD130.FRAMES_5 - SSD130.FRAMES_25 - SSD130.FRAMES_64 - SSD130.FRAMES_128 - SSD130.FRAMES_256 One frame approximate 9.19ms. - hw_scroll_diag(direction=True, interval=FRAMES_5, offset=1):continuously scroll to up-right/up-left. - offset: vertical offset per scroll. - hw_scroll_off():stop scrolling.
1 parent 44818d1 commit 6ceb9e4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

drivers/display/ssd1306.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,25 @@
2323
SET_PRECHARGE = const(0xD9)
2424
SET_VCOM_DESEL = const(0xDB)
2525
SET_CHARGE_PUMP = const(0x8D)
26+
SET_HWSCROLL_OFF = const(0x2e)
27+
SET_HWSCROLL_ON = const(0x2f)
28+
SET_HWSCROLL_RIGHT = const(0x26)
29+
SET_HWSCROLL_LEFT = const(0x27)
30+
SET_HWSCROLL_VR = const(0x29)
31+
SET_HWSCROLL_VL = const(0x2a)
2632

2733
# Subclassing FrameBuffer provides support for graphics primitives
2834
# http://docs.micropython.org/en/latest/pyboard/library/framebuf.html
2935
class SSD1306(framebuf.FrameBuffer):
36+
FRAMES_2 = 0x07
37+
FRAMES_3 = 0x04
38+
FRAMES_4 = 0x05
39+
FRAMES_5 = 0x00
40+
FRAMES_25 = 0x06
41+
FRAMES_64 = 0x01
42+
FRAMES_128 = 0x02
43+
FRAMES_256 = 0x03
44+
3045
def __init__(self, width, height, external_vcc):
3146
self.width = width
3247
self.height = height
@@ -108,6 +123,49 @@ def show(self):
108123
self.write_cmd(self.pages - 1)
109124
self.write_data(self.buffer)
110125

126+
def clear(self):
127+
self.fill(0)
128+
self.show()
129+
130+
def hw_scroll_off(self):
131+
self.write_cmd(SET_HWSCROLL_OFF) # turn off scroll
132+
133+
def hw_scroll_h(
134+
self,
135+
direction=True, # True/False: right/left
136+
interval=FRAMES_5 # one frame ≓ 9.2ms
137+
):
138+
self.write_cmd(SET_HWSCROLL_OFF) # turn off hardware scroll per SSD1306 datasheet
139+
if not direction:
140+
self.write_cmd(SET_HWSCROLL_LEFT)
141+
else:
142+
self.write_cmd(SET_HWSCROLL_RIGHT)
143+
self.write_cmd(0x00) # dummy byte
144+
self.write_cmd(0x00) # start page = page 0
145+
self.write_cmd(interval) # interval
146+
self.write_cmd(0x07) # end page = page 7
147+
self.write_cmd(0x00) # dummy byte
148+
self.write_cmd(0xff) # dummy byte
149+
self.write_cmd(SET_HWSCROLL_ON) # activate scroll
150+
151+
def hw_scroll_diag(
152+
self,
153+
direction=True, # True/False: right/left
154+
interval=FRAMES_5, # one frame ≓ 9.2ms
155+
offset=1 # vertical offset per scroll
156+
):
157+
158+
self.write_cmd(SET_HWSCROLL_OFF) # turn off hardware scroll per SSD1306 datasheet
159+
if not direction:
160+
self.write_cmd(SET_HWSCROLL_VL)
161+
else:
162+
self.write_cmd(SET_HWSCROLL_VR)
163+
self.write_cmd(0x00) # dummy byte
164+
self.write_cmd(0x00) # start page = page 0
165+
self.write_cmd(interval) # interval
166+
self.write_cmd(0x07) # end page = page 7
167+
self.write_cmd(offset) # vertical offset per scroll
168+
self.write_cmd(SET_HWSCROLL_ON) # activate scroll
111169

112170
class SSD1306_I2C(SSD1306):
113171
def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False):

0 commit comments

Comments
 (0)