Skip to content

Commit e2da806

Browse files
authored
Merge branch 'master' into TheKitty-patch-103
2 parents a200bb6 + 4d7e075 commit e2da806

17 files changed

Lines changed: 2178 additions & 1 deletion

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import board
2+
import displayio
3+
import adafruit_displayio_ssd1306
4+
import terminalio
5+
import adafruit_ds3231
6+
from adafruit_display_text import label
7+
8+
displayio.release_displays()
9+
10+
i2c = board.I2C()
11+
display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
12+
oled = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
13+
14+
rtc = adafruit_ds3231.DS3231(i2c)
15+
16+
17+
# The first time you run this code, you must set the time!
18+
# You must set year, month, date, hour, minute, second and weekday.
19+
# struct_time order: year, month, day (date), hour, minute, second, weekday , yearday, isdst
20+
# yearday is not supported, isdst can be set but we don't do anything with it at this time
21+
22+
# UNCOMMENT THE FOLLOWING FOUR LINES THE FIRST TIME YOU RUN THE CODE TO SET THE TIME!
23+
# import time
24+
# set_time = time.struct_time((2019, 8, 16, 23, 59, 45, 4, -1, -1))
25+
# print("Setting time to:", set_time)
26+
# rtc.datetime = set_time
27+
28+
# Comment out the above four lines again after setting the time!
29+
30+
31+
font = terminalio.FONT
32+
33+
while True:
34+
current = rtc.datetime
35+
36+
hour = current.tm_hour % 12
37+
if hour == 0:
38+
hour = 12
39+
40+
am_pm = "AM"
41+
if current.tm_hour / 12 >= 1:
42+
am_pm = "PM"
43+
44+
time_display = "%d:%02d:%02d %s" % (hour, current.tm_min, current.tm_sec, am_pm)
45+
date_display = "%d/%d/%d" % (current.tm_mon, current.tm_mday, current.tm_year)
46+
text_display = "CircuitPython Time"
47+
48+
clock = label.Label(font, text=time_display)
49+
date = label.Label(font, text=date_display)
50+
text = label.Label(font, text=text_display)
51+
52+
(_, _, width, _) = clock.bounding_box
53+
clock.x = 128 // 2 - width // 2
54+
clock.y = 5
55+
56+
(_, _, width, _) = date.bounding_box
57+
date.x = 128 // 2 - width // 2
58+
date.y = 15
59+
60+
(_, _, width, _) = text.bounding_box
61+
text.x = 128 // 2 - width // 2
62+
text.y = 25
63+
64+
watch_group = displayio.Group()
65+
watch_group.append(clock)
66+
watch_group.append(date)
67+
watch_group.append(text)
68+
69+
oled.show(watch_group)

M4_Eyes/DMAbuddy.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Very infrequently the jobStatus member in Adafruit_ZeroDMA gets out of
2+
// sync and the screen DMA updates lock up. This is a hacky workaround.
3+
// jobStatus is a protected member of Adafruit_ZeroDMA, we can't reset it
4+
// directly in the sketch, but a subclass can. So we have this minimal
5+
// subclass with a DMA-channel-toggle-off-on-and-jobStatus-reset function.
6+
7+
class DMAbuddy : public Adafruit_ZeroDMA {
8+
public:
9+
// Call this function when a DMA stall is detected:
10+
void fix(void) {
11+
// We literally just switch the channel off and on again to fix it...
12+
DMAC->Channel[channel].CHCTRLA.bit.ENABLE = 0; // Disable channel
13+
DMAC->Channel[channel].CHCTRLA.bit.ENABLE = 1; // Enable channel
14+
jobStatus = DMA_STATUS_OK; // Back in business!
15+
}
16+
};

0 commit comments

Comments
 (0)