Skip to content

Commit

Permalink
Merge pull request #244 from brilliantlabsAR/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
siliconwitch authored Jun 30, 2023
2 parents 6cde9d8 + 02f04cb commit 63e44b8
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 236 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ SRC_C += monocle-core/monocle-drivers.c
SRC_C += monocle-core/monocle-startup.c
SRC_C += mphalport.c

SRC_C += micropython/extmod/moduasyncio.c
SRC_C += micropython/extmod/modasyncio.c
SRC_C += micropython/extmod/modbinascii.c
SRC_C += micropython/extmod/modhashlib.c
SRC_C += micropython/extmod/modjson.c
Expand All @@ -120,11 +120,11 @@ SRC_C += micropython/extmod/vfs_reader.c
SRC_C += micropython/extmod/vfs.c
SRC_C += modules/bluetooth.c
SRC_C += modules/camera.c
SRC_C += modules/compression.c
SRC_C += modules/device.c
SRC_C += modules/display.c
SRC_C += modules/fpga.c
SRC_C += modules/led.c
SRC_C += modules/microphone.c
SRC_C += modules/rtt.c
SRC_C += modules/storage.c
SRC_C += modules/touch.c
Expand Down
2 changes: 1 addition & 1 deletion micropython
Submodule micropython updated 342 files
15 changes: 10 additions & 5 deletions modules/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,17 @@ def camera_module():

def microphone_module():
__test("microphone.record()", None)
__test("microphone.record(seconds=6.5)", None)
__test("microphone.record(seconds=4)", None)
__test("microphone.record(seconds=4.5)", None)
__test("microphone.record(sample_rate=4000)", ValueError)
__test("microphone.record(sample_rate=8000)", None)
__test("microphone.record(sample_rate=16000)", None)
__test("microphone.record(bit_depth=4)", ValueError)
__test("microphone.record(bit_depth=8)", None)
__test("microphone.record(bit_depth=16)", None)
time.sleep(0.5)
__test("len(microphone.read())", 127)
__test("len(microphone.read(samples=10))", 10)
__test("len(microphone.read(samples=128))", ValueError)
__test("microphone.compress([23432,24399,24300,24500])", b"[\x88")
__test("len(microphone.read(127))", 254)
__test("len(microphone.read(128))", ValueError)


def touch_module():
Expand Down
73 changes: 0 additions & 73 deletions modules/compression.c

This file was deleted.

62 changes: 24 additions & 38 deletions modules/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,40 +288,6 @@ def color(*args):
arg.color(args[-1])


def text_get_overlapping_y(l):
if len(l) == 0:
return
l = sorted(l, key=lambda obj: obj.y)
prev = l[0]
for obj in l[1:]:
if obj.y < prev.y + FONT_HEIGHT:
return (prev, obj)
prev = obj


def text_get_overlapping_xy(base, l):
if len(l) == 0:
return
sub = [base]
for obj in l:
if obj.x < base.x + base.width(base.string):
# Some overlapping on x coordinates, accumulate the row
sub.append(obj)
else:
# Since the l is sorted, we can stop checking here
break

# now also check the y coordinate for all the potential clashes
return text_get_overlapping_y(sub)


def text_get_overlapping(l):
for i in range(len(l)):
overlapping = text_get_overlapping_xy(l[i], l[i + 1:])
if overlapping is not None:
return overlapping


def update_colors(addr, l):
# new buffer for the FPGA API, starting with address 0x0000
buffer = bytearray(2)
Expand Down Expand Up @@ -354,14 +320,33 @@ def update_colors(addr, l):
def show_fbtext(l):
global fbtext_addr

# Make sure there was enough time to start the FPGA engine
while time.ticks_ms() < 1000:
pass

update_colors(0x4502, l)

# Text has no wrapper, we implement it locally.
# See https://streamlogic.io/docs/reify/nodes/#fbtext
buffer = bytearray(struct.pack(">H", fbtext_addr))
l = sorted(l, key=lambda obj: obj.x)
overlapping = text_get_overlapping(l)
if overlapping is not None:
raise TextOverlapError(f"{overlapping[0]} overlaps with {overlapping[1]}")

# Check for overlapping text
def box(obj):
x2 = obj.x + FONT_WIDTH * len(obj.string)
y2 = obj.y + FONT_HEIGHT
return obj.x, x2, obj.y, y2
for a in l:
ax1, ax2, ay1, ay2 = box(a)
for b in l:
if a is b:
continue
bx1, bx2, by1, by2 = box(b)
if ax1 <= bx2 and ax2 >= bx1:
if ay1 <= by2 and ay2 >= by1:
raise TextOverlapError(f"{a} overlaps with {b}")

# Render the text
for obj in l:
obj.fbtext(buffer)
if len(buffer) > 0:
Expand All @@ -370,11 +355,12 @@ def show_fbtext(l):
fpga.write(0x4503, buffer + b"\xFF\xFF\xFF")
fbtext_addr += FBTEXT_PAGE_SIZE
fbtext_addr %= FBTEXT_PAGE_SIZE * FBTEXT_NUM_PAGES
time.sleep_ms(20) # ensure the buffer swap has happened
time.sleep_ms(100) # ensure the buffer swap has happened


def show_vgr2d(l):
update_colors(0x4402, l)

# 0 is the address of the frame in the framebuffer in use.
# See https://streamlogic.io/docs/reify/nodes/#fbgraphics
# Offset: active display offset in buffer used if double buffering
Expand Down
3 changes: 1 addition & 2 deletions modules/frozen-manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
module("_test.py")
module("camera.py")
module("display.py")
module("microphone.py")
module("update.py")

include("$(MPY_DIR)/extmod/uasyncio/manifest.py")
include("$(MPY_DIR)/extmod/asyncio/manifest.py")
Loading

0 comments on commit 63e44b8

Please sign in to comment.