kopia lustrzana https://github.com/peterhinch/micropython-nano-gui
Update driver pico_epaper_42.py.
rodzic
7e36ff6905
commit
40430abbf7
|
@ -63,7 +63,7 @@ access via the `Writer` and `CWriter` classes is documented
|
||||||
5.2.1 [EPD constructor args](./DRIVERS.md#521-epd-constructor-args)
|
5.2.1 [EPD constructor args](./DRIVERS.md#521-epd-constructor-args)
|
||||||
5.2.2 [EPD public methods](./DRIVERS.md#522-epd-public-methods)
|
5.2.2 [EPD public methods](./DRIVERS.md#522-epd-public-methods)
|
||||||
5.2.3 [EPD public bound variables](./DRIVERS.md#523-epd-public-bound-variables)
|
5.2.3 [EPD public bound variables](./DRIVERS.md#523-epd-public-bound-variables)
|
||||||
5.3 [Waveshare 400x300 Pi Pico display](./DRIVERS.md#53-waveshare-400x300-pi-pico-display) Can also be used with other hosts.
|
5.3 [Waveshare 400x300 Pi Pico display](./DRIVERS.md#53-waveshare-400x300-pi-pico-display) Excellent display can also be used with other hosts.
|
||||||
6. [EPD Asynchronous support](./DRIVERS.md#6-epd-asynchronous-support)
|
6. [EPD Asynchronous support](./DRIVERS.md#6-epd-asynchronous-support)
|
||||||
7. [Writing device drivers](./DRIVERS.md#7-writing-device-drivers)
|
7. [Writing device drivers](./DRIVERS.md#7-writing-device-drivers)
|
||||||
8. [Links](./DRIVERS.md#8-links)
|
8. [Links](./DRIVERS.md#8-links)
|
||||||
|
@ -1249,7 +1249,8 @@ following constructor args:
|
||||||
* `dc=None` A `Pin` instance defined as `Pin.OUT`.
|
* `dc=None` A `Pin` instance defined as `Pin.OUT`.
|
||||||
* `rst=None` A `Pin` instance defined as `Pin.OUT`.
|
* `rst=None` A `Pin` instance defined as `Pin.OUT`.
|
||||||
* `busy=None` A `Pin` instance defined as `Pin.IN, Pin.PULL_UP`.
|
* `busy=None` A `Pin` instance defined as `Pin.IN, Pin.PULL_UP`.
|
||||||
* `asyn=False` Set `True` for asynchronous applications.
|
* `asyn=False` Set `True` for asynchronous applications. Leave `False` for
|
||||||
|
microgui where the arg has no effect.
|
||||||
|
|
||||||
##### Synchronous methods
|
##### Synchronous methods
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,12 @@ EPD_partial_lut_bb1 = b"\x00\x19\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00
|
||||||
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
|
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
|
||||||
\x00\x00\x00\x00"
|
\x00\x00\x00\x00"
|
||||||
|
|
||||||
|
@micropython.viper
|
||||||
|
def _linv(dest:ptr8, source:ptr8, length:int):
|
||||||
|
for n in range(length):
|
||||||
|
c = source[n]
|
||||||
|
dest[n] = c ^ 0xFF
|
||||||
|
|
||||||
class EPD(framebuf.FrameBuffer):
|
class EPD(framebuf.FrameBuffer):
|
||||||
# A monochrome approach should be used for coding this. The rgb method ensures
|
# A monochrome approach should be used for coding this. The rgb method ensures
|
||||||
# nothing breaks if users specify colors.
|
# nothing breaks if users specify colors.
|
||||||
|
@ -245,33 +251,41 @@ class EPD(framebuf.FrameBuffer):
|
||||||
def ready(self):
|
def ready(self):
|
||||||
return not (self._busy or (self.busy_pin() == 0)) # 0 == busy
|
return not (self._busy or (self.busy_pin() == 0)) # 0 == busy
|
||||||
|
|
||||||
def _line(self, n, buf=bytearray(_BWIDTH)):
|
@micropython.native
|
||||||
img = self.mvb
|
def _line(self, start, buf=bytearray(_BWIDTH)): # Sending 50 bytes 40us at 10MHz, 12ms for 300 lines
|
||||||
s = n * _BWIDTH
|
_linv(buf, self.mvb[start:], _BWIDTH) # Invert image data for EPD
|
||||||
for x, b in enumerate(img[s : s + _BWIDTH]):
|
|
||||||
buf[x] = b ^ 0xFF
|
|
||||||
self.send_bytes(buf)
|
self.send_bytes(buf)
|
||||||
|
|
||||||
async def _as_show(self):
|
# Timing @10MHz/250MHz: full refresh 2.1s, partial 740ms
|
||||||
|
# Blocking with split=5 740/5=150ms
|
||||||
|
async def _as_show(self, split):
|
||||||
self.send_command(b"\x13")
|
self.send_command(b"\x13")
|
||||||
for j in range(_EPD_HEIGHT): # Loop would block ~300ms
|
lps = _EPD_HEIGHT // split
|
||||||
self._line(j)
|
idx = 0
|
||||||
|
#ttt = time.ticks_ms()
|
||||||
|
for _ in range(split): # For each segment
|
||||||
|
for _ in range(lps):
|
||||||
|
self._line(idx)
|
||||||
|
idx += _BWIDTH
|
||||||
await asyncio.sleep_ms(0)
|
await asyncio.sleep_ms(0)
|
||||||
|
#print("Time", time.ticks_diff(time.ticks_ms(), ttt))
|
||||||
self._updated.set()
|
self._updated.set()
|
||||||
self.send_command(b"\x12") # Async .display_on()
|
self.send_command(b"\x12") # Nonblocking .display_on()
|
||||||
while not self.busy_pin():
|
while not self.busy_pin():
|
||||||
await asyncio.sleep_ms(10) # About 1.7s
|
await asyncio.sleep_ms(0) # About 1.7s for full refresh
|
||||||
self._busy = False
|
self._busy = False
|
||||||
|
#print("Time", time.ticks_diff(time.ticks_ms(), ttt)) # ~630ms
|
||||||
|
|
||||||
async def do_refresh(self, split): # For micro-gui
|
async def do_refresh(self, split): # For micro-gui
|
||||||
await self._as_show()
|
assert (not self._busy), "Refresh while busy"
|
||||||
|
await self._as_show(split) # split=5
|
||||||
|
|
||||||
def show(self):
|
def show(self): # nanogui
|
||||||
if self._busy:
|
if self._busy:
|
||||||
raise RuntimeError('Cannot refresh: display is busy.')
|
raise RuntimeError('Cannot refresh: display is busy.')
|
||||||
self._busy = True # Immediate busy flag. Pin goes low much later.
|
self._busy = True # Immediate busy flag. Pin goes low much later.
|
||||||
if self._asyn:
|
if self._asyn:
|
||||||
asyncio.create_task(self._as_show())
|
asyncio.create_task(self._as_show(5)) # split into 5 segments
|
||||||
return
|
return
|
||||||
self.send_command(b"\x13")
|
self.send_command(b"\x13")
|
||||||
for j in range(_EPD_HEIGHT):
|
for j in range(_EPD_HEIGHT):
|
||||||
|
|
Ładowanie…
Reference in New Issue