FOSSASIA Badge Magic Open Firmware
Google Summer of Code 2024 - Final Submission Report
- Organization: FOSSASIA.
- Mentors: Francois Cartegnie, MarioB, Hong Phuc Dang, Rafael Lee, AnnTran, Bella Phan.
- Project Repository: badgemagic-firmware, badgemagic-hardware, badgemagic-case, badgemagic-android.
- Link to GSoC site for this project.
Project Overview
LED name badges are small matrix LEDs that can be written text, and images, and create animations over Bluetooth or USB connection. The Badge Magic app is an open-source app used to send data to these LED badges. However, the app is still limited and depends on these LED badge features. This project aims to implement an open-source firmware for this type of LED Badge that uses a CH582 microcontroller, adds more features, as a base example for later hacks, and merges it to the badgemagic-firmware repo of FOSSASIA.
Goals
- Receiving bitmap data from the app over BLE.
- Receiving bitmap data over USB.
- Saving bitmap data to flash.
- Displaying bitmap on screen.
- Animations: scroll leftwards, scroll , scroll up, scroll down, fixed, “animation”, “snowflake”, “picture”, “laser”.
- Buttons: turning on, turning off, entering Bluetooth download mode, adjusting brightness.
- Firmware Optimizing for low-power.
- Repurposing the LED Badge to an audio visualizer over Bluetooth.
- Drawing a schematic and creating a BOM list for referencing.
- Documentation for the firmware.
Accomplishments
The firmware now is capable of:
- Receiving bitmap data from the app over BLE.
- Having two 2 USB Composite Devices: HID and CDC-ACM.
- Receiving bitmap data over USB HID and CDC-ACM.
- Saving bitmap data to flash.
- Displaying bitmap on screen.
- Animations: scroll leftwards, scroll , scroll up, scroll down, fixed, “animation”, “snowflake”, “picture”, “laser”.
- Additional animations for hardcoded bitmap: scroll up, scroll down, infinite scroll.
- Animation and display version on charging state.
- Buttons: turning on, turning off, entering Bluetooth download mode, adjusting brightness.
I designed a open source hardware and a case along the way:
- Improved its design, made a PCB.
- Added a microphone to turn the badge to an audio visualizer.
- Wired the UART logging port to USB-C for a handy debugging instead of opening the case.
- Made a 3D case design.
Documentation for the firmware.
What’s left
I’ve exceeded designing a open source hardware and a case along the way. But this cost more time and so was not completed the audio visualizer.
Contributions
Community Bonding Period
- BadgeBLE: add description of uploading behavior - badgemagic-firmware#7
- Fix deployment pipeline to apk branch - badgemagic-android#902
- chore: fix build errors caused by lint check - badgemagic-android#903
- fix: Crash caused by missing permission - badgemagic-android#910
- fix: Crash due to old version of klock - badgemagic-android#911
- Fix warning flood - badgemagic-android#913
- fix android build check failed on PRs - badgemagic-android#914
- chore: remove ios CI check - badgemagic-android#919
- fix: Crash caused by missing permission on Android 12 - badgemagic-android#932
- fix: update prominent disclosures - badgemagic-android#934
- fix: remove completely location permissions - badgemagic-android#936
- Add KiCad schematics - badgemagic-hardware#8
Coding Period
Phase 1
- Add Platform, Parts list, Hardware specs to README.md - badgemagic-hardware#9
- fix: wrong connection - badgemagic-hardware#10
- Add basic Charlieplexing scan - badgemagic-firmware#10
- Add basic button functionalities - badgemagic-firmware#11
- Add brightness adjustment - badgemagic-firmware#12
- Add support for .xbm bitmap file - badgemagic-firmware#13
- Add dynamic framebuffer - badgemagic-firmware#14
- Add animations - badgemagic-firmware#15
- Add entering power-off mode - badgemagic-firmware#16
- Add bluetooth animation in ble download mode - badgemagic-firmware#17
- fix: first leds of the first two columns are switched - badgemagic-firmware#19
- Add build pipeline - badgemagic-firmware#20
- fix: missing deallocating - badgemagic-firmware#21
- fix: Framebuffer linked list is misplaced on append - badgemagic-firmware#28
- fix: Out of bounds on framebuffer access - badgemagic-firmware#29
- feat: Bluetooth LE initial setup - badgemagic-firmware#30
- feat: Save received data from BLE to flash - badgemagic-firmware#31
- feat: Receive data over USB - badgemagic-firmware#35
Phase 2
- fix: schematic regulator’s part number - badgemagic-hardware#12
- Badge Magic PCB layout - badgemagic-hardware#14
- fix: incompatible dimensions and unconnected leds - badgemagic-hardware#17
- fix: crash loop on new chip - badgemagic-firmware#45
- chore: Add release drafter - badgemagic-firmware#47
- feat: play all available bitmap slots sequentially - badgemagic-firmware#49
- feat: Charging status - badgemagic-firmware#50
- Prototype case - badgemagic-case#2
- feat: Add a build option for USB-C version - badgemagic-firmware#55
- feat: Automatically embedding version numbers - badgemagic-firmware#53
- chore: Update README for Installation, Usage and Development - badgemagic-firmware#58
Other Contributions
- fix: BLE won’t work on Android 11 and below badgemagic-android#968
- fix: pipeline broken on PR badgemagic-android#970
- chore: separated pipeline for pull request badgemagic-android#971
Conclusion
What did I learn
Bare-metal USB Device Implementation: At the moment, tinyusb
doesn’t support the CH582 chip. I implemented the USB device from the ground up without using any framework, which helped me better understand the USB protocol layer. Implementing a USB device on a bare-metal USB peripheral has always been on my learning list.
USB Device Class Implementation: I had basic experience working with USB HID devices using Obdev V-USB, but only manipulating data at the higher level of the HID layer. Throughout this project, I implemented both a USB HID and a USB CDC-ACM. This required studying the specifications to configure and understand the topology of each class.
BLE GATT and ATT Layer: Before this project, I had worked with BLE in a couple of projects but at a higher abstraction level. However, this project’s bare-metal BLE implementation allowed me to deepen my understanding of the GATT and ATT layers.
Git Force Push: Before joining GSoC for this project, I studied several projects, but they’re using mailing lists. For patches that needed improvements, contributors would resend updated versions to the list. I didn’t know how GitHub’s PR workflow worked until my mentor told me to use git rebase -i
and force push.
Communication: Before GSoC, I wasn’t familiar with how to contribute to a GitHub-hosted project, and I was initially hesitant to do so.
Collaboration: I learned how to properly use Scrum. The weekly meetings were highly effective in setting clear goals for the next steps.
Future Work
The work that left: Repurpose the LED Badge to an audio visualizer.
The ideas that came up, while doing this project, some of them were posted on the repo’s issue:
- Clock feature badgemagic-firmware#36
- Bitmap streaming badgemagic-firmware#41
- Turning the badge on/off remotely badgemagic-firmware#32
- Alway-on BLE badgemagic-firmware#34
- Flash firmware over BLE badgemagic-firmware#37
- Option to disable microphone badgemagic-hardware#18
The piece of hardware wating to get used: Using microphone on the badgemagic-hardware to implement the audio spectrum visualizer.
Images
Badge Magic Hardware: first test batch
Badge Magic Hardware: second test batch