Skip to content

Commit

Permalink
Merge pull request #131 from gyroflow/ssd1306-driver-cleanup
Browse files Browse the repository at this point in the history
[OLED Driver] Cleanup
  • Loading branch information
DusKing1 authored May 20, 2022
2 parents 6104029 + 85fdc31 commit 65afe82
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
task = task.Task()

from machine import Timer
timer0 = Timer(0) # 200Hz CRSF sender
timer0.init(period=5, mode=Timer.PERIODIC, callback=task.schedular)
timer0 = Timer(0) # 200Hz task scheduler
timer0.init(period=5, mode=Timer.PERIODIC, callback=task.scheduler)

import vram
if vram.camera_protocol == "Sony MTP":
Expand Down
6 changes: 3 additions & 3 deletions src/sha.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
{
"name": "entry.py",
"sha1": "dcfb9bcf7f914d138474958aafc073df7c1675bc"
"sha1": "e7033ef52ddba8682cff3ce0f0234bd9f7ad115a"
},
{
"name": "main.py",
Expand All @@ -46,7 +46,7 @@
},
{
"name": "ssd1306.py",
"sha1": "1a8acf9f1961c220a3d192cc393e25b0efbe2337"
"sha1": "b77e02e21a69cb5fc3eb53571c1a06d69f7fbc41"
},
{
"name": "startup.py",
Expand All @@ -58,7 +58,7 @@
},
{
"name": "task.py",
"sha1": "a1802ddd20285c220b7150b10d0578edc98fd733"
"sha1": "d5b5589e679c82177646c3d4456cb82865d7c311"
},
{
"name": "ui.py",
Expand Down
42 changes: 20 additions & 22 deletions src/ssd1306.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def __init__(self, width, height, i2c, reflash, addr=0x3c, external_vcc=False):
self.pages = self.height // 8
self.buffer = bytearray(self.pages * self.width)
self.framebuf = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MONO_VLSB)
self.cmd_temp = bytearray(2)
self.data_temp = bytearray(1)
self.temp = bytearray(2)
self.write_list = [b"\x40", None] # Co=0, D/C#=1
self.poweron()
self.init_display()
print(str(time.ticks_us()) + " [ OK ] SSD1306_I2C object")
Expand Down Expand Up @@ -87,14 +87,6 @@ def init_display(self):
else:
pass

def poweroff(self):
self.write_cmd(SET_DISP | 0x00)
def contrast(self, contrast):
self.write_cmd(SET_CONTRAST)
self.write_cmd(contrast)
def invert(self, invert):
self.write_cmd(SET_NORM_INV | (invert & 1))

def show(self):
for i in range(int(self.pages)):
vram.oled_tasklist.append(i)
Expand Down Expand Up @@ -130,13 +122,25 @@ def show_all(self):
self.write_data(self.buffer)

def write_cmd(self, cmd):
self.cmd_temp[0] = 0x80 # Co=1, D/C#=0
self.cmd_temp[1] = cmd
self.i2c.writeto(self.addr, self.cmd_temp)
self.temp[0] = 0x80 # Co=1, D/C#=0
self.temp[1] = cmd
self.i2c.writeto(self.addr, self.temp)
def write_data(self, buf):
self.data_temp[0] = 0x40 # Co=0, D/C#=1
gbuf = self.data_temp + buf
self.i2c.writeto(self.addr, gbuf)
self.write_list[1] = buf
self.i2c.writevto(self.addr, self.write_list)

def poweroff(self):
self.write_cmd(SET_DISP)
def poweron(self):
self.write_cmd(SET_DISP | 0x01)
def contrast(self, contrast):
self.write_cmd(SET_CONTRAST)
self.write_cmd(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 fill(self, col):
self.framebuf.fill(col)
Expand All @@ -156,11 +160,5 @@ def rect(self, x, y, w, h, col):
self.framebuf.rect(x, y, w, h, col)
def fill_rect(self, x, y, w, h, col):
self.framebuf.fill_rect(x, y, w, h, col)
def rotate(self, rotate):
self.write_cmd(SET_COM_OUT_DIR | ((rotate & 1) << 3))
self.write_cmd(SET_SEG_REMAP | (rotate & 1))
def blit(self, fbuf, x, y):
self.framebuf.blit(fbuf, x, y)

def poweron(self):
pass
6 changes: 3 additions & 3 deletions src/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

class Task:
def __init__(self):
print(str(time.ticks_us()) + " [Create] Task schedular")
print(str(time.ticks_us()) + " [Create] Task scheduler")
self.crsf = crsf.CRSF()
self.mem_opt_interval = 100 # gc per 100ms
self.battery = peripherals.Battery()
self.buttons = peripherals.Buttons()
self.ui = ui.UI_Logic()
print(str(time.ticks_us()) + " [ OK ] Task schedular")
print(str(time.ticks_us()) + " [ OK ] Task scheduler")

def mem_opt(self):
gc.enable()
gc.collect()
gc.disable()

def schedular(self, t):
def scheduler(self, t):
self.mem_opt_interval -= 5

# task1 - CRSF sender
Expand Down

0 comments on commit 65afe82

Please sign in to comment.