Demo Embedded Swift Demo - Album on Imgur
This is just a quick demo post, I'll likely post some code to github over the weekendfor anyone interested. I have Embedded Swift running on a Teensy 4.0 now, and running some demo code on a SSD1351 over SPI. Not only that, the display is using DMA for SPI writes! (And writing in full 18bit color mode, tricky on these little guys).
I had this display running on linux with SwiftyGPIO in the past (and c++ on teensys too) and built these demos for it then. Same code runs the demos! (well, I upgraded both a little bit... but the same code runs on a Teensy that runs on a RaspberryPi). The Matrix Rain demo I initially translated from the python library luma.oled (link to its matrix example), this version I beefed the lines up a bit to look psuedo-glyphy. The Game of Life demo however is my own cursed set theory implementation of Game of Life in Swift. For any GoL fans, my Swift generation update function is literally this (plus some extras defining the operators and such
):
func SΚΉ(_ S: π) -> π {
N[S] | { c in β(N(c) β© S)β == 3 β¨ (β(N(c) β© S)β == 2 β§ c β S) }
}
Even better, back when I wrote the raspi/SwiftyGPIO variant, I came up with a sweet idea for dev iteration... SwiftUI Previews!! I'm basically building a HAL + Graphics abstraction layer that works across everything and lets you run the same drawing code on a mac looking at SwiftUI previews, or on a Raspi, or an embedded target. "It's protocols, all the way down"
Open Source code coming soon I promise! I just REALLY wanted to demo this! The Graphics layer in itself is really neat and something I'd aspired to write it 3-4 years ago, but the state of swift generics were fighting me on it then. Now with SE-0452's Integer Value generics I can finally have something like FixedFramebuffer<let W, let H, ColorSpace> where a device declares its resolution and colorspace at compiletime and generics fold and pack things in, making it compatible with everything from HDR colors to 1-bit, the output device tells code what to use
Oh I also took advantage of SE-0483 InlineArrays for a few things as well
they work great for LUTs