Experimenting with a RISC-V controller
Posted: 22 Feb 2023, 05:56
I feel like I'm a bit of an anomaly in the "modern" mechanical keyboard scene. When most people are building 40%, 30%, single switch boards, I've latched on to a 130% layout and keep dragging it through revision after revision. It features an incredibly naive matrix design that's 23 rows x 7 columns (so that software wise, each row can just be a straight listing of all keys included). Add LEDs, an encoder, and an OLED, and you're looking at 37 GPIOs to cover the board.
The problem is that the "go-to" controller for a large keyboard is the Teensy++. It's expensive at best, and now it's discontinued, so supplies are running thin, even of "questionable" likely bootleg ones. A lot of the new-generation of ARM boards (i. e. the common STM32F103 boards and the Raspberry Pi Pico) don't have enough GPIOs, and many of the ones that do have enough are pretty spendy.
So I've got a growing stack of PCBs that, should I decide to populate, will be difficult to source a controller for. I could redesign the PCBs to use a soldered-on AT90USB1286, but even those are hard to source at times, and I hate SMD soldering.
I recently found what looks to be a "dream" controller: the WCH CH32V305RBT6, in the form of Muse Lab's "nanoCH32V305" breakout board. The board offers 42 GPIOs, all of which are exposed on the outer edge of the board and only one of which is encumbered (onboard LED), a USB-C connector, and can be programmed without a special cable/tool. It's also six US dollars (or about 11 by the time postage from China is considered), so significantly cheaper than the Teensy++. I'm also a fan of WCH's generally zany product line; I spent a lot of last year on a hobby project using their CH375/376 "USB disc to random 8-bit bus" part.
So I had two problems. First, while the pinout is convenient for a scratch build, it's useless for an existing PCB, and I wanted to at least proof-of-concept it as capable of driving a full 130% board. Once I had gotten it working with a hard-wired 5x4 macro pad from my parts box, I prepared an "interposer" PCB: you attach pins on the bottom in a layout the size and shape of a Teensy++, which are in turn wired to holes you route to the nanoCH32V305. This was the smaller problem; throw $10 at JLCPCB and you've got more of them than you'll ever need. I was able to wire up one of my existing PCBs, and it worked with the same bodges you have to apply to the Teensy++.
The bigger problem is firmware. It's a RISC-V CPU, and I suspect a QMK or similar port is very far off. Entertainingly, there was a basic "sample HID device" package in the SDK. This provided support for wiring four pushbuttons to act as W/A/S/D and four more to simulate moving the mouse. I've spent the last two months iterating on it, and have been able to build out a modestly functional firmware from this start.
https://gitlab.com/hakfoo1/ch32v-keyboard
It's still probably delicate in a lot of ways, and could probably be refined further-- I'm not sure I've got debouncing perfectly dialed in, and it doesn't fail gracefully in every possible scenario. (I had some issues with the board going unresponsive after rebooting between operating systems that I'm not sure are resolved) but it's becoming a fairly usable proof of concept.
The problem is that the "go-to" controller for a large keyboard is the Teensy++. It's expensive at best, and now it's discontinued, so supplies are running thin, even of "questionable" likely bootleg ones. A lot of the new-generation of ARM boards (i. e. the common STM32F103 boards and the Raspberry Pi Pico) don't have enough GPIOs, and many of the ones that do have enough are pretty spendy.
So I've got a growing stack of PCBs that, should I decide to populate, will be difficult to source a controller for. I could redesign the PCBs to use a soldered-on AT90USB1286, but even those are hard to source at times, and I hate SMD soldering.
I recently found what looks to be a "dream" controller: the WCH CH32V305RBT6, in the form of Muse Lab's "nanoCH32V305" breakout board. The board offers 42 GPIOs, all of which are exposed on the outer edge of the board and only one of which is encumbered (onboard LED), a USB-C connector, and can be programmed without a special cable/tool. It's also six US dollars (or about 11 by the time postage from China is considered), so significantly cheaper than the Teensy++. I'm also a fan of WCH's generally zany product line; I spent a lot of last year on a hobby project using their CH375/376 "USB disc to random 8-bit bus" part.
So I had two problems. First, while the pinout is convenient for a scratch build, it's useless for an existing PCB, and I wanted to at least proof-of-concept it as capable of driving a full 130% board. Once I had gotten it working with a hard-wired 5x4 macro pad from my parts box, I prepared an "interposer" PCB: you attach pins on the bottom in a layout the size and shape of a Teensy++, which are in turn wired to holes you route to the nanoCH32V305. This was the smaller problem; throw $10 at JLCPCB and you've got more of them than you'll ever need. I was able to wire up one of my existing PCBs, and it worked with the same bodges you have to apply to the Teensy++.
The bigger problem is firmware. It's a RISC-V CPU, and I suspect a QMK or similar port is very far off. Entertainingly, there was a basic "sample HID device" package in the SDK. This provided support for wiring four pushbuttons to act as W/A/S/D and four more to simulate moving the mouse. I've spent the last two months iterating on it, and have been able to build out a modestly functional firmware from this start.
https://gitlab.com/hakfoo1/ch32v-keyboard
It's still probably delicate in a lot of ways, and could probably be refined further-- I'm not sure I've got debouncing perfectly dialed in, and it doesn't fail gracefully in every possible scenario. (I had some issues with the board going unresponsive after rebooting between operating systems that I'm not sure are resolved) but it's becoming a fairly usable proof of concept.