# Rust based Microbit Typewriter
This is a brainstorm of building a [[Typewriter]] like the [[Freewrite Traveller]] with [[E-Ink]] display on the [[BBC Microbit]] using [[Embedded Rust]].
# Project description
## Hardware
- [[BBC Microbit]]
- [[waveshare 4.2 inch e-ink display]]
- [[PS2 Keyboard]]
## [[E-Ink]] emulator
I plan to use the [[waveshare 4.2 inch e-ink display]], but it's not here yet, and it would be useful to have an emulator anyway to work on the editor without having to flash a device on every change.
The emulator should:
- work with the same API as the real device
- simulate different refresh rates / be as close as possible to the physical behaviour
- partial refresh behaviour (ghosting, color flickering)
- emulate different types of display, with color and different refresh rates and behaviour?
- simulate burnin
- compile to wasm?
## Keyboard UI
use a clever navigation scheme instead of just arrows:
- jumpby paragraph
- jump by section
- bookmarks
- search / reverse search
- jump by sentence
- some kind of keyboard browser link selection (for example to quickly call up a table of contents and then select an entry, a bit like the url selection in kitty)
add commands to make editing easier
- fold/unfold paragraphs
- swap order of paragraphs
- assign "summaries" to each paragraph so that it shows up when folded (a bit like scrivener)
- basically a card / note based editing workflow but with text display (well, noone hinders us from using graphics)
## Graphical UI
I like the split screen / status bar at the bottom on the traveler, I guess it is similar to the status bar / message buffer at the bottom of the emacs window. This would show the zettelkasten number and other information
Library for freefont rendering:
- [GitHub - mooman219/fontdue: The fastest font renderer in the world, written in pure rust.](https://github.com/mooman219/fontdue)
## File management
note / zettelkasten functionality
- create folgezettel
- browse some kind of index
- quickly add and create a new note when typing (something like [[ ]] in obsidian, but with a way to quickly open it with just the keyboard.
- maybe there can be something all mapped to a super key that then shows an overlay of functions for say, the F** key row.
Multiple buffers with quickswap like the traveler
## Diagram rendering
diagram rendering
- like [[Mermaid]], maybe with some kind of split screen functionality
## Online functionality
online functionality
- sync with obsidian
- offline index of [[Obsidian]] note titles to autocomplete
- collaborative editing ([[CRDT]]s??)
## CAD in Rust
Iterating on casing 3D prints or [[CNC]], programmatically in [[Rust]] itself, so that code can be shared (for example, list of function keys, etc...)
# Planning
- Michael is interested in the embedded
- Here is a whole page about [[Rust]] ([[Embedded Rust]]) on the [[BBC Microbit]]):
- [Rust on the BBC micro:bit — Drogue IoT](https://blog.drogue.io/rust-and-microbit/)
- Driving the [[E-Ink]] display
- Needs the [[SPI]] bus
- Connecting a keyboard
- [[USB]] ? PS2 ? Scanning a matrix?
- It looks like the [[BBC Microbit]] has potentially support for [[USB]] [[OTG]]:
- - [HowTo: Connect a phone or tablet to the BBC micro:bit - microbit Forum - microbit - element14 Community](https://community.element14.com/learn/learning-center/stem-academy/microbit/f/forum/9344/howto-connect-a-phone-or-tablet-to-the-bbc-micro-bit)
- Connectivity of the hardware:
- I2c / SPI / UART
- Network connectivity
- We could do [[Collaborative Editing]] with [[CRDT]]s
- See lower down for [[Bluetooth]] information.
- Manuel is interesting learning Rust
- Michael and Manuel are both interested in writing "bigger" idiomatic Rust
- Editor data structures
- plain editing
- keyboard macros
- paragraph / sentence structure
- annotations
- etc...
- Emulator
- The EInk part of the emulator should actually emulate the SPI "protocol"
- Have it run in the browser with WASM?
- Battery Connectivity
- Networked part of it
- It looks like Bluetooth is the one BBC is pushing:
- [Bluetooth](https://tech.microbit.org/bluetooth/)
- [[Bluetooth GATT]] seems to be an RPC like layer on top of [[Bluetooth]]: [GATT | Introduction to Bluetooth Low Energy | Adafruit Learning System](https://learn.adafruit.com/introduction-to-bluetooth-low-energy/gatt)
- Host side [[Bluetooth]]
- [GitHub - deviceplug/btleplug: Rust Cross-Platform Host-Side Bluetooth LE Access Library](https://github.com/deviceplug/btleplug)
- Storage is an interesting part of it all
- Raw Block storage into the internal flash
- Use an SD Card over [[SPI]]
- [Lecture 12 - SPI and SD cards](http://www.dejazzer.com/ee379/lecture_notes/lec12_sd_card.pdf)
- implement [[VFAT]]
- [GitHub - rafalh/rust-fatfs: A FAT filesystem library implemented in Rust.](https://github.com/rafalh/rust-fatfs)
- Use an eeprom/flash chip over i2c
## What does the finished device look like?
Michael has a 60 percent [[Mechanical Keyboard]], and that's what Manuel also wants to use ultimately.
Michael has a USB-C connector and wants a device that he can plug the keyboard into and get going. Michael's device is the [Keyboardio Atreus](https://shop.keyboard.io/products/keyboardio-atreus), which seems to run a [[Opensource Software]] firmware for ATmega32U4 [[Atmel]].
The [[Atreus]] was first sold as a kit:
- [Atreus Keyboard Kit](https://atreus.technomancy.us/)
Which is why maybe the firmware is opensource, but is it still using the same layout?
- [GitHub - mostlyharmless-io/atreus42: keyboard controller firmware for Atmel AVR USB family](https://github.com/mostlyharmless-io/atreus42)
Here are the [[Schematics]]:
- [schematics/atreus at master · keyboardio/schematics · GitHub](https://github.com/keyboardio/schematics/tree/master/atreus)
Sadly it looks like [[USB]] is the only way to go, although the [[Firmware]] can be reprogrammed over [[SPI]].
Like a cyberdeck?
![[IDEA - Rust based Microbit Typewriter-1659033555264.jpeg]]
![[IDEA - Rust based Microbit Typewriter-1659033564686.jpeg]]
## How do you write Host/Embedded compatible code
```rust
display.BlitRectangle();
#[cfg("embedded")]
display = EINK::SPIDisplay();
#[cfg("wasm")]
display = WASM::EinkEmulator();
```
## Project Plan
### Week 1
#### Michael
- Display something on the E-Ink with the Microbit
- Keyboard to Microbit
- Can we get USB to work
#### Manuel
- Display text in the emulator
- Monospace bitmap font
- 💰 Flash font in microbit in separate section
- Run emulator in WASM
- Type text and render without editing
[[IDEA - Rust based Microbit Typewriter - Product Ideation - 2022-08-06]]
## Inspiration
### Typography inspiration
Textnoise iphone app:
![[IDEA - Rust based Microbit Typewriter-1664633730732.jpeg]]
- [TextNoise on the App Store](https://apps.apple.com/us/app/textnoise/id1506650265)
- Tractus Infinitus VR - App Store
![[IDEA - Rust based Microbit Typewriter-1664633761874.jpeg]]
- Episodic - App Store
> Episodic is an artwork that allows users to create a moving collage from disparate fragments. Contained within the app are black and white looping animations. Each animation is a short episode that can be repositioned and scaled allowing users to link together different segments to create a narrative and explore new relationships. The app reconfigures pop-up windows containing Flash animations originally
![[IDEA - Rust based Microbit Typewriter-1664633788800.jpeg]]
- Tiny Poems - App Store
> For the first time „tiny poems“ brings concrete minimal poetry to mobile devices like Apple Watch, iPhone and iPad. The pieces are optimized for the screen of the Apple Watch and show short and dynamic texts for the wrist. The poems reflect time and vanity and change constantly according to the continuosly passing time.
![[IDEA - Rust based Microbit Typewriter-1664633854922.jpeg]]
- konsonant - App Store
> Play with letters and sounds, build acoustic machines, control morphing clouds and experiment with the alphabet!
Enjoy the sounds and shapes of letters by line drawing, physics simulations or acoustic networks in the four sound games included in the app.
![[IDEA - Rust based Microbit Typewriter-1664633930592.jpeg]]
- unicode infinite - app store
> unicode infinite is a generative interactive infinite text video installation. It animates the glyphs of the basic multilingual plane of the unicode standard and presents this range of the human culture of writing as a polyphonic text video installation. Characters are appearing in a very fast sequence sorted by optical similarity that was calculated by an automatic recognition process.
![[IDEA - Rust based Microbit Typewriter-1664634401372.jpeg]]
![[IDEA - Rust based Microbit Typewriter-1664634415180.jpeg]]
- [TypeLoop - Add Text to Photos on the App Store](https://apps.apple.com/us/app/typeloop-add-text-to-photos/id1466721611)
![[IDEA - Rust based Microbit Typewriter-1664634445777.jpeg]]
This is quite interesting for [[PROJ - Thermal printer ideas]] as well
- [The Next Point of View - Behance](https://www.behance.net/gallery/64345213/The-Next-Point-of-View)
![[IDEA - Rust based Microbit Typewriter-1664634921362.jpeg]]
> Built from a standard typeface, we have developed a typographic behavior using interaction and three-dimensionality. Letters are set to change depending on the angle in which they’re looked from, this way, the user’s point of view becomes key in determining the shape of the typography.


- [BRUTAL typeface design on Behance](https://www.behance.net/gallery/36985115/BRUTAL-Typeface-Design)
![[IDEA - Rust based Microbit Typewriter-1664635014168.jpeg]]
![[IDEA - Rust based Microbit Typewriter-1664635031720.jpeg]]
### Digital Typewriter related stuff
Turning a map into a typewriter map:
- [Typewriter Cartography – somethingaboutmaps](https://somethingaboutmaps.wordpress.com/2018/11/26/typewriter-cartography/)
![[IDEA - Rust based Microbit Typewriter-1664635272836.jpeg]]
### Links about similar projects
By Zach from [[Zachtronics]]! He's reverse engineering an old electric typewriter. Actually a typewriter with ribbon matrix printer would be a great device to reverse engineer, you can probably find them cheap on ebay, the question of course is getting more ribbons.
- [The Programmable Typewriter](https://www.trashworldnews.com/typewriter/)
Writing with a keyboard and a [[Remarkable]] tablet:
- [Distraction Free Writing with a reMarkable Keyboard • Nick Temple](https://nicktemple.com/lifehack/remarkable-keyboard/)
A very similar project using a [[Raspberry Pi]], basically our first prototype:
- [Ultimate Writer: an Open Digital Typewriter](https://alternativebit.fr/posts/ultimate-writer/)
![[IDEA - Rust based Microbit Typewriter-1664635139529.jpeg]]
## Log
[[2022-10-01]]
- Added inspiration section
[[2022-08-06]]
- Big product brainstorm
[[2022-08-05]]
- discuss first MVPs
[[2022-07-28]]
- Discuss project with Michael