Close

Programming with CH55xduino, mapping the 3 keys

A project log for RGB macropad custom firmware

Custom firmware for the CH552 found in those USB RGB macropads with a rotaty knob

biemsterbiemster 03/08/2023 at 17:030 Comments

After a lot of headaches why I couldn't get to the bootloader, you can see in the previous log I finally succeeded. So next step: get some code running on it.

As I did not want to fiddle with some clip all the time, I decided to go with the Arduino port by Deqing:

https://hackaday.io/project/172143-ch55xduino

https://github.com/DeqingSun/ch55xduino

Not only is it a breeze to upload new firmware with this, it also comes with a ton of example code! The only downside I can think of is that it takes up quite a chunk of available space, but since this macropad should only monitor the buttons, and light the LEDs, I guess it will be fine.

In my great wisdom I decided to screw the whole thing together without tracing what connects to which pins, so that will be trial and error. For the next log. I already trial-and-errored the 3 keys:

#include <Serial.h>

unsigned long prev_ms = 0;
const long interval_ms = 300;

uint8_t BUTTON_LEFT = 11;
uint8_t BUTTON_RIGHT = 16;
uint8_t BUTTON_MIDDLE = 17;

void setup() {
  pinMode(BUTTON_LEFT, INPUT_PULLUP);
  pinMode(BUTTON_RIGHT, INPUT_PULLUP);
  pinMode(BUTTON_MIDDLE, INPUT_PULLUP);
}

void loop() {
  const long now_ms = millis();
  if(now_ms > prev_ms +interval_ms) {
    prev_ms = now_ms;
    int buttonState = digitalRead(BUTTON_LEFT) ? 0 : 1;
    buttonState += digitalRead(BUTTON_MIDDLE) ? 0 : 2;
    buttonState += digitalRead(BUTTON_RIGHT) ? 0 : 4;
    USBSerial_println(buttonState);
  }
}

Great fun! And would be for sure a couple days more work if not for the work of Deqing. Thanks!

Next up is the rotary encoder, and the LEDs. Pins that are left are: P1.4 P1.5 P3.0 P3.1 P3.2 P3.3 P3.4

My guess is that the encoder is something like a HW-040 and the LEDS are WS2812's or APA102 or the like. But who knows!

Discussions