-
Notifications
You must be signed in to change notification settings - Fork 159
ch32v: Add SPI HAL with DMA support #838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Lint Results
Found 7 issues on changed lines in 4 files:
- examples/wch/ch32v/src/i2c_dma.zig: 1 issue
- examples/wch/ch32v/src/spi_loopback.zig: 1 issue
- examples/wch/ch32v/src/spi_ssd1306.zig: 1 issue
- port/wch/ch32v/src/hals/spi.zig: 4 issues
ℹ️ Additional issues on unchanged lines
The following 23 issue(s) exist but are not on lines changed in this PR:
drivers/sensor/ICM-20948.zig:27: TODO style comments need to have a linked microzig issue on the same line.
drivers/sensor/ICM-20948.zig:200: TODO style comments need to have a linked microzig issue on the same line.
drivers/sensor/ICM-20948.zig:208: TODO style comments need to have a linked microzig issue on the same line.
drivers/sensor/ICM-20948.zig:230: TODO style comments need to have a linked microzig issue on the same line.
drivers/sensor/ICM-20948.zig:494: TODO style comments need to have a linked microzig issue on the same line.
drivers/sensor/ICM-20948.zig:535: Suggestion: Rename `Accel_data_unscaled` to `AccelDataUnscaled`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:556: Suggestion: Rename `Accel_data` to `AccelData`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:599: Suggestion: Rename `Gyro_data_unscaled` to `GyroDataUnscaled`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:620: Suggestion: Rename `Gyro_data` to `GyroData`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:827: Suggestion: Rename `Mag_data_unscaled` to `MagDataUnscaled`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:868: Suggestion: Rename `Mag_data` to `MagData`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:886: Suggestion: Rename `TestI2CDevice` to `Test_I2C_Device`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/dma.zig:18: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:47: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:263: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:16: Suggestion: Rename `DmaRegs` to `DMA_Regs`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:16: Suggestion: Rename `Datagram_Device` to `DatagramDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:17: Suggestion: Rename `Stream_Device` to `StreamDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:19: Suggestion: Rename `Clock_Device` to `ClockDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:20: Suggestion: Rename `I2CError` to `I2C_Error`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:21: Suggestion: Rename `I2CAddress` to `I2C_Address`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/gpio.zig:68: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/gpio.zig:119: TODO style comments need to have a linked microzig issue on the same line.
Updating with new lint results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Lint Results
Found 6 issues on changed lines in 3 files:
- examples/wch/ch32v/src/spi_loopback.zig: 1 issue
- examples/wch/ch32v/src/spi_ssd1306.zig: 1 issue
- port/wch/ch32v/src/hals/spi.zig: 4 issues
ℹ️ Additional issues on unchanged lines
The following 23 issue(s) exist but are not on lines changed in this PR:
drivers/sensor/ICM-20948.zig:27: TODO style comments need to have a linked microzig issue on the same line.
drivers/sensor/ICM-20948.zig:200: TODO style comments need to have a linked microzig issue on the same line.
drivers/sensor/ICM-20948.zig:208: TODO style comments need to have a linked microzig issue on the same line.
drivers/sensor/ICM-20948.zig:230: TODO style comments need to have a linked microzig issue on the same line.
drivers/sensor/ICM-20948.zig:494: TODO style comments need to have a linked microzig issue on the same line.
drivers/sensor/ICM-20948.zig:535: Suggestion: Rename `Accel_data_unscaled` to `AccelDataUnscaled`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:556: Suggestion: Rename `Accel_data` to `AccelData`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:599: Suggestion: Rename `Gyro_data_unscaled` to `GyroDataUnscaled`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:620: Suggestion: Rename `Gyro_data` to `GyroData`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:827: Suggestion: Rename `Mag_data_unscaled` to `MagDataUnscaled`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:868: Suggestion: Rename `Mag_data` to `MagData`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
drivers/sensor/ICM-20948.zig:886: Suggestion: Rename `TestI2CDevice` to `Test_I2C_Device`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/dma.zig:18: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:47: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:263: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:16: Suggestion: Rename `DmaRegs` to `DMA_Regs`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:16: Suggestion: Rename `Datagram_Device` to `DatagramDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:17: Suggestion: Rename `Stream_Device` to `StreamDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:19: Suggestion: Rename `Clock_Device` to `ClockDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:20: Suggestion: Rename `I2CError` to `I2C_Error`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:21: Suggestion: Rename `I2CAddress` to `I2C_Address`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/gpio.zig:68: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/gpio.zig:119: TODO style comments need to have a linked microzig issue on the same line.
Updating with new lint results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Lint Results
Found 6 issues on changed lines in 3 files:
- examples/wch/ch32v/src/spi_loopback.zig: 1 issue
- examples/wch/ch32v/src/spi_ssd1306.zig: 1 issue
- port/wch/ch32v/src/hals/spi.zig: 4 issues
ℹ️ Additional issues on unchanged lines
The following 11 issue(s) exist but are not on lines changed in this PR:
port/wch/ch32v/src/hals/dma.zig:18: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:47: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:263: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:16: Suggestion: Rename `DmaRegs` to `DMA_Regs`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:16: Suggestion: Rename `Datagram_Device` to `DatagramDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:17: Suggestion: Rename `Stream_Device` to `StreamDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:19: Suggestion: Rename `Clock_Device` to `ClockDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:20: Suggestion: Rename `I2CError` to `I2C_Error`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:21: Suggestion: Rename `I2CAddress` to `I2C_Address`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/gpio.zig:68: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/gpio.zig:119: TODO style comments need to have a linked microzig issue on the same line.
| var rx_buffer: [64]u8 = undefined; // Increased to handle 32-byte pattern | ||
|
|
||
| // SPI modes to test (all 4 combinations of CPOL and CPHA) | ||
| const SpiMode = struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Rename SpiMode to SPI_Mode, it should be more in line with our style guidelines. This automation is not perfect so take it with a grain of salt.
| } | ||
|
|
||
| // Digital_IO wrapper for D/C pin | ||
| const DC_Pin_Wrapper = struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Rename DC_Pin_Wrapper to DC_PinWrapper, it should be more in line with our style guidelines. This automation is not perfect so take it with a grain of salt.
…pheral enum methods)
Updating with new lint results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Lint Results
Found 3 issues on changed lines in 2 files:
- examples/wch/ch32v/src/spi_loopback.zig: 1 issue
- port/wch/ch32v/src/hals/spi.zig: 2 issues
ℹ️ Additional issues on unchanged lines
The following 11 issue(s) exist but are not on lines changed in this PR:
port/wch/ch32v/src/hals/dma.zig:18: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:47: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:263: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:16: Suggestion: Rename `DmaRegs` to `DMA_Regs`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:16: Suggestion: Rename `Datagram_Device` to `DatagramDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:17: Suggestion: Rename `Stream_Device` to `StreamDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:19: Suggestion: Rename `Clock_Device` to `ClockDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:20: Suggestion: Rename `I2CError` to `I2C_Error`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:21: Suggestion: Rename `I2CAddress` to `I2C_Address`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/gpio.zig:68: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/gpio.zig:119: TODO style comments need to have a linked microzig issue on the same line.
| var rx_buffer: [64]u8 = undefined; // Increased to handle 32-byte pattern | ||
|
|
||
| // SPI modes to test (all 4 combinations of CPOL and CPHA) | ||
| const SpiMode = struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Rename SpiMode to SPI_Mode, it should be more in line with our style guidelines. This automation is not perfect so take it with a grain of salt.
|
|
||
| if (total_len >= dma_cfg.threshold) { | ||
| // For vectored DMA, we need to send chunks sequentially | ||
| // TODO: Optimize with scatter-gather DMA in the future |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO style comments need to have a linked microzig issue on the same line.
|
|
||
| if (total_len >= dma_cfg.threshold) { | ||
| // For vectored DMA, we need to read chunks sequentially | ||
| // TODO: Optimize with scatter-gather DMA in the future |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO style comments need to have a linked microzig issue on the same line.
Updating with new lint results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Lint Results
Found 2 issues on changed lines in 1 file:
- port/wch/ch32v/src/hals/spi.zig: 2 issues
ℹ️ Additional issues on unchanged lines
The following 11 issue(s) exist but are not on lines changed in this PR:
port/wch/ch32v/src/hals/dma.zig:18: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:47: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:263: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/dma.zig:16: Suggestion: Rename `DmaRegs` to `DMA_Regs`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:16: Suggestion: Rename `Datagram_Device` to `DatagramDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:17: Suggestion: Rename `Stream_Device` to `StreamDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:19: Suggestion: Rename `Clock_Device` to `ClockDevice`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:20: Suggestion: Rename `I2CError` to `I2C_Error`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/drivers.zig:21: Suggestion: Rename `I2CAddress` to `I2C_Address`, it _should_ be more in line with our [style guidelines](https://microzig.tech/docs/contributing/). This automation is not perfect so take it with a grain of salt.
port/wch/ch32v/src/hals/gpio.zig:68: TODO style comments need to have a linked microzig issue on the same line.
port/wch/ch32v/src/hals/gpio.zig:119: TODO style comments need to have a linked microzig issue on the same line.
|
|
||
| if (total_len >= dma_cfg.threshold) { | ||
| // For vectored DMA, we need to send chunks sequentially | ||
| // TODO: Optimize with scatter-gather DMA in the future |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO style comments need to have a linked microzig issue on the same line.
|
|
||
| if (total_len >= dma_cfg.threshold) { | ||
| // For vectored DMA, we need to read chunks sequentially | ||
| // TODO: Optimize with scatter-gather DMA in the future |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO style comments need to have a linked microzig issue on the same line.
Summary
Adds a complete SPI HAL implementation for CH32V (specifically CH32V203) with optional DMA support, following the proven I2C HAL pattern.
Key Features:
DMA Integration:
Examples Included:
Implementation Notes:
inline forfor compile-time mode iteration in examplesIDR→INDRfor CH32VTested On:
--release=smallbuilds🤖 This PR is 100% AI-generated using Claude Code (claude.ai/code). No human edits were made to any code in this PR. The entire implementation—from architecture design through DMA integration to working examples—was created through conversation with Claude Sonnet 4.5.
(Ok not 100% anymore, I made some changes)
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com