Skip to content

Conversation

@NoNamedCat
Copy link

This PR adds full support for the WCH CH32X035 RISC-V microcontroller.

Changes:

  • Added IS_CH32() macro in hardware_defines.h.
  • Added platform-specific implementation in internal/MozziGuts_impl_CH32.hpp.
  • Added configuration checks in internal/config_checks_CH32.h and registered them in internal/config_checks_generic.h.

tomcombriat and others added 17 commits April 18, 2025 19:27
parameter hence allowing for differently sized bufers to be used (for
instance with audio input)
Includes platform definitions, configuration checks, and core implementation for CH32 architecture.
… and check specifically for CH32X035 in implementation.
@tomcombriat
Copy link
Collaborator

Hi,
Thanks very much for this.

I tried to compile some of my sketches locally, but the platform is not recognized on my IDE. I installed support for the board by using this core: https://github.com/openwch/arduino_core_ch32. What is the core you use?

Also, I saw that the PR concerning FixMath has been dropped, is it not needed after all?

@NoNamedCat
Copy link
Author

Yeah is not needed. I have done some test without the FixMath PR and the library compile without that. Im using this URL for the board manager: https://github.com/openwch/board_manager_files/raw/main/package_ch32v_index.json.

Also I think that you will like this:

https://nonamedcat.github.io/MozziFlowEditor/

@sensorium
Copy link
Owner

Hey @NoNamedCat, the Flow Editor is awesome!

@tomcombriat
Copy link
Collaborator

Hi again,
I was using the same core but for some reason, in the Arduino IDE, the hardware define was not the same. I added one option there so that it does now compile there. Sorry for messing completely up the number of commits, this is due to merging your branch with Mozzi's master branch.

I can't unfortunately test it entirely because of lack of hardware, but I will try to have a close look soon!


The Flow Editor is neat! I did not manage to get the code updated from what is in the flow, it remains a blank script… Am I missing something?

Copy link
Collaborator

@tomcombriat tomcombriat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments on some details. Also, bonus if you can add documentation for the website (both README.md and extras/website/index.markdown).

Interesting platform, I have to get my hand on one!

Also, with a platform with that many ADC channels, do you have plan to implement async ADC reads?

* MozziGuts_impl_CH32.hpp
*
* Implementation for WCH CH32X035 (RISC-V) using Standard Peripheral Library (SPL)
*
Copy link
Collaborator

@tomcombriat tomcombriat Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add your name/pseudo here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s no need to include my pseudonym in the code or anywhere else. I just want to give back to the community that has given me so much (and while I’m at it, I’d like to say thank you for the Mozzi library and FixMath as well).
Asynchronous analog readings are definitely something that could improve this a lot, and I should implement them.
Right now, the port for this architecture works as it is, and I think it’s good enough for an initial release, but I’m definitely keeping this in mind.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course that's up to you, but most of Mozzi's files display such information, which also shows that this is a collaborative effort and helps to track back when things were done and who might be the expert. A new port is always a good thing :).
As per the ADC, I fully agree that this should go in without waiting for async.

long out = (long)f.l() + MOZZI_AUDIO_BIAS;

// Clamp to 16-bit unsigned range just in case
if (out < 0) out = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think this is un-necessary: having a check for every sample will incur some drawbacks on the CPU. Other platforms don't do it so users are usually used to take care of overflows.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right

long out = (long)f.l() + MOZZI_AUDIO_BIAS;
if (out < 0) out = 0;
out = out >> (MOZZI_AUDIO_BITS - 8);
if (out > 255) out = 255;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again. You are right.

@NoNamedCat
Copy link
Author

Left a few comments on some details. Also, bonus if you can add documentation for the website (both README.md and extras/website/index.markdown).

Interesting platform, I have to get my hand on one!

Also, with a platform with that many ADC channels, do you have plan to implement async ADC reads?

I can share the KiCad design files for the 28-pin board I'm using, or you can buy some ready-made boards on AliExpress.
This chip is really awesome for the price.
I've written several libraries for using its USB hardware (MIDI, HID mouse, HID gamepad, HID keyboard, and HID Composite — which combines mouse, keyboard, and gamepad at the same time).
I really like this chip, but since it's relatively new, I'm trying to make it more usable for my own projects while sharing everything I create with the community along the way.

@NoNamedCat
Copy link
Author

NoNamedCat commented Jan 19, 2026

Hi again, I was using the same core but for some reason, in the Arduino IDE, the hardware define was not the same. I added one option there so that it does now compile there. Sorry for messing completely up the number of commits, this is due to merging your branch with Mozzi's master branch.

I can't unfortunately test it entirely because of lack of hardware, but I will try to have a close look soon!

The Flow Editor is neat! I did not manage to get the code updated from what is in the flow, it remains a blank script… Am I missing something?

I broke so many things in a PR without knowing. Now is fixed.

image

// Configure Audio Bits based on Mode
#if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PWM)
#if !defined(MOZZI_AUDIO_BITS)
#define MOZZI_AUDIO_BITS 16 // Internal calc at 16, output scaled to 8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why not setting that to 8 in order first to be clearer about the output but also to avoid one extra shift in the output?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying out some computations with the 32-bit ALU in the MCU to help reduce noise in a Mozzi sketch prior to audio output, and I simply forgot to clean it up afterward. Thanks for catching that!

Implemented ADC1_IRQHandler and setupFastAnalogRead for CH32X035 using direct SPL calls. Added robust pin-to-channel mapping fallback logic.
Fixed RCC and ADC function names, removed non-existent calibration calls, and updated sample time constants to match WCH core v1.0.4. Verified compilation with arduino-cli.
@NoNamedCat
Copy link
Author

NoNamedCat commented Jan 21, 2026

Now the Mozzi output configuration is set correctly (8-bit). I've made the changes you requested and have also been working extensively on MozziFlowEditor. It now exports much cleaner code. I've also implemented non-blocking analog reads. I've tested several example patches, and they seem to work well, but this still requires a lot of testing. I'll keep working on it in my spare time, though I expect to be very busy for at least the next couple of weeks. Any feedback bugs, suggestions, or anything else is welcome!

@NoNamedCat
Copy link
Author

@tomcombriat. The port for the CH32X035 is now finished and stable. I have performed many test on actual hardware, and everything is functioning correctly, including the asynchronous ADC implementation.

@tomcombriat
Copy link
Collaborator

@NoNamedCat This is great, the addition of async ADC makes a lot of sense on such a board I think. Thank you very much for all of this. I also saw that you updated the documentation which is super.
I have very little time these days, for personal reasons, so I won't have the time to review thoughtfully any time soon. The fact that all the checks are passing indicates that nothing else is obviously broken, so I think this can likely go in with no or little change but I think it would still be nice if @sensorium or @tfry-git or me have the time to have a quick look before.

Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants