This repository contains various projects and utilities for working with the CH32V003 microcontroller.
Older hardware (InspireMatrix):
-
.github:workflows: GitHub Actions workflows.Doxyfile: Doxygen configuration.
-
.vscode:-
settings.json: VSCode settings:"C_Cpp.default.compilerPath": "riscv-none-elf-gcc",
To set the default compiler to
riscv-none-elf-gccfor IDE integration. -
-
ch32v003_stt- Simple spoken digit recognition.
- Originally from https://github.com/brian-smith-github/ch32v003_stt
- Read its README.md for more information.
-
ch32v003fun-
driver.h: Contains the most frequently used functions for the CH32V003. -
i2c_events.h: Contains some frequently used I2C functions written manually. -
i2c_tx.c,i2c_tx.h,oled_min.c,oled_min.h: Contains some frequently used functions for the SSD1306 OLED display. Comes from https://github.com/eric15342335/inspirelab-game -
ws2812b_simple.h: Contains one function for controlling the WS2812B LEDs. You need to declare the following variables in your code: Infunconfig.h:#define FUNCONF_SYSTICK_USE_HCLK 1
In your code (e.g.
main.c):#define WS2812BSIMPLE_IMPLEMENTATION // ... #include "ws2812b_simple.h"
-
Originally from the
extralibsfolder in https://github.com/cnlohr/ch32v003fun
-
-
data-
buttons.h: Button ADC calibration data.Contains two sets of data, one for the first prototype
InspireMatrixand one for the second prototypeInspireComputer(which uses two ADC channels for buttons). If you are using theInspireComputer, declare the following infunconfig.h:#define INTERNAL_INSPIRE_MATRIX
-
colors.h: Contains the color palette for theInspireMatrixorInspireComputer.One global variable
led_array[]act as buffer to store the color data to be displayed. Provides functions to manipulate theled_array[]buffer. -
fonts.h: Display numbers and characters in the size of 3x5 on WS2812B LEDs. -
music.h: Frequencies, durations and functions for playing music using a buzzer. To play sound, useJOY_sound().
-
-
emulator- Support development of basic embedded system software on Windows/MacOS without requiring physical hardware.
- Aims to achieve function compatibility with the
ch32v003funlibrary.
-
i2c-comm- Communication between two boards using I2C protocol. The code contains a master and a slave.
-
misclibgcc.arequired by thech32v003funlibrary on MacOS. See here for more information.
-
movingnum- Animations of numbers moving from right to left, bottom to top. Uses math instead of hard coding.
Demonstrates the use of
fonts.h.
- Animations of numbers moving from right to left, bottom to top. Uses math instead of hard coding.
Demonstrates the use of
-
paint-cursor- Draw images on
InspireMatrixwith direction buttons and matrix buttons - Connection:
- PD2: SW (Analog to Digital PIN)
- PC6: IN (WS2812B Data PIN)
- Draw images on
-
paint- Paint on
InspireMatrix.
- Paint on
-
rv-asm- Coding RISC-V Compressed instructions on a board with buttons, and showing the result on the matrix.
- Originally from https://github.com/mnurzia/rv
-
rv-dis(Working in progress)- Disassemble RISC-V compressed instructions and print the result on an external OLED display (e.g. SSD1306).
- Originally from https://github.com/michaeljclark/riscv-disassembler
-
testing- This folder contains a bunch of test programs that are subject to change, and are not guaranteed to work for your specific hardware.
Note
Both savepaint and save-rvasm implements an filesystem structure.
-
savepaint- Add saving and loading features.
- Combines
paint,movingcar,snake-gameandtic-tac-toe - How to play:
- Before first icon appearing, hold Y to clear all the saved paints.
- After first icon appearing, use
UPandDOWNto select apps. - Use
LEFTto use the selected app. - Integrated
paint:- Press 64 (or
NUM_LEDSbuttons) to toggle between foreground color and background color. - Press X or Y to change the foreground or background color.
- Press
UPbutton to load a saved paint. - Press
DOWNbutton to save the current paint.
- Press 64 (or
- Integrated
movingcar:- Currently 64 buttons are divided into left and right section.
- For each row (8 buttons), left four buttons correspond to
Left Wheel Forward,Left Wheel Backward,Right Wheel Forward,Right Wheel Backward. - For each row (8 buttons), right four buttons correspond to
Red,Green,BlueandSpecial Command(Currently not used). The LEDs will display the colors when the motor is running. - E.g. if buttons (counting from left) 1, 3, 5 are pressed, the car will go forward and displays red on the entire screen.
- Special: If all 8 buttons are pressed, the program will go back the first instruction to execute.
- Integrated
snake-game:- Press Y to start.
- Use
up / down / left / rightto move the snake.
- Integrated
tic-tac-toe:- Press any of the empty spot to play.
- When any of the app ends, press
Yto go back to the main menu. (NVIC_SystemReset()is called)
-
save-rvasm- Add saving and loading features
- Uses
rv-asm. - How to play:
- Before the load save menu appear, hold
Xto clear all the saved paints. - Pick a saved program to load. Each program size is 32 instructions (hence 64 bytes / 1 page in the filesystem).
- Press
Yto load the default program (Smile face) instead of loading a saved program. You must choose this if no program are saved. - Use
UPandDOWNto navigate the instruction pages. The top 32 LEDs in light pink indicates which page is currently displayed. E.g. 1 LED on => page 1 => Instruction 1 and 2. - Use
Yto execute the program. - The button
32LEDs are used to display the current instruction, with the active bit highlighted asblue. - Notes when writing programs:
- You
MUSTend your program with anecall(a.k.a0x0073) to exit the program.
- You
- Before the load save menu appear, hold
-
snake-game- Porting the classic snake game to
InspireMatrix, which has8x8=64LEDs andup / down / left / rightcontrols.
- Porting the classic snake game to
-
tic-tac-toe- Play tic-tac-toe with a bot
- Press button to start
- Green is player while Red is the bot
- Try to win it (very easy)
#ifndef _FUNCONFIG_H // Guard
#define _FUNCONFIG_H
#define CH32V003 1 // Required
#define FUNCONF_USE_DEBUGPRINTF 0
#define FUNCONF_USE_UARTPRINTF 1 // For printf() over UART (Use Hercules to view)
#define FUNCONF_UART_PRINTF_BAUD 115200 // Baud rate
// Connect UTX pin to RX pin in WCH-LinkE
// Newly created definitions
#define horizontalButtons 8
#define verticalButtons 8
#define NUM_LEDS (horizontalButtons * verticalButtons)
// Not required for the new InspireComputer board
// For GameConsole, need to define the following
// and connect buzzer pin to RX.
// Affects ch32v003fun.h SystemInit() UART printf initialization.
// #define CH32V003J4M6_USE_PD6_AS_UART_TX
// Required for WS2812B LEDs `ws2812b_simple.h`
#define FUNCONF_SYSTICK_USE_HCLK 1
#endifTwo options are available for compilation:
-
make- Compile and output
*.hexand*.binfiles which can be used for flashing the program into CH32V003.
- Compile and output
-
make emulator- Compile an executable using
GCCwhich runs natively on your operating system, simulating behaviour on real hardware.
- Compile an executable using
Great thanks to these projects (LICENSE included):
- https://github.com/cnlohr/ch32v003fun
- https://github.com/brian-smith-github/ch32v003_stt
- https://github.com/mnurzia/rv
- https://github.com/michaeljclark/riscv-disassembler
- https://github.com/hexeguitar/ch32v003fun_libs
-
https://github.com/eric15342335/inspirelab-game
- A game console based on the
CH32V003J4M6MCU. - Originally from https://github.com/wagiminator/CH32V003-GameConsole
- A game console based on the
-
https://github.com/eric15342335/BitNetMCU
- Receives image data via UART and predict the digit using an ML model.
- Originally from https://github.com/cpldcpu/BitNetMCU
