Skip to content

Commit

Permalink
drivers/display/ssd1306.py: Add rotate method.
Browse files Browse the repository at this point in the history
And clean up (make more efficient) display set-up commands.
  • Loading branch information
mcauser authored and dpgeorge committed May 6, 2021
1 parent 8ff3520 commit 9eea51b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions drivers/display/ssd1306.py
Expand Up @@ -37,12 +37,12 @@ def __init__(self, width, height, external_vcc):

def init_display(self):
for cmd in (
SET_DISP | 0x00, # off
SET_DISP, # display off
# address setting
SET_MEM_ADDR,
0x00, # horizontal
# resolution and layout
SET_DISP_START_LINE | 0x00,
SET_DISP_START_LINE, # start at line 0
SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0
SET_MUX_RATIO,
self.height - 1,
Expand All @@ -66,14 +66,14 @@ def init_display(self):
# charge pump
SET_CHARGE_PUMP,
0x10 if self.external_vcc else 0x14,
SET_DISP | 0x01,
SET_DISP | 0x01, # display on
): # on
self.write_cmd(cmd)
self.fill(0)
self.show()

def poweroff(self):
self.write_cmd(SET_DISP | 0x00)
self.write_cmd(SET_DISP)

def poweron(self):
self.write_cmd(SET_DISP | 0x01)
Expand All @@ -85,6 +85,10 @@ def contrast(self, contrast):
def invert(self, invert):
self.write_cmd(SET_NORM_INV | (invert & 1))

def rotate(self, rotate):
self.write_cmd(SET_COM_OUT_DIR | ((rotate & 1) << 3))
self.write_cmd(SET_SEG_REMAP | (rotate & 1))

def show(self):
x0 = 0
x1 = self.width - 1
Expand Down

0 comments on commit 9eea51b

Please sign in to comment.