ch32-rs / ch32v00x-hal

HAL for the CH32V003 family of microcontrollers
29 stars 11 forks source link

OPA Control #12

Closed fred314159265 closed 3 months ago

fred314159265 commented 3 months ago

This implements control of the in-built operational amplifier, using the type-state pattern to ensure all the pins are in the correct mode and that they are not used for other purposes whilst the OPA is enabled.

I have done some basic tests that this works on a WeAct CH32V003F4U6 board. It is worth noting that by default, PD7 is acting as the NRST line, so not exactly usable for the op-amp input pin, but all the other are fine and so is very usable when using PA2 for the non-inverting input instead of PD7.

I have not done much embedded Rust, so any feedback welcome - I'm happy to make any changes as required 😊

andelf commented 3 months ago

I haven't looked into V003's OPA. I got a CH32X035's OPA working in https://github.com/ch32-rs/ch32x0-hal/blob/main/src/opa.rs.

fred314159265 commented 3 months ago

Thanks @andelf , the CH32X035's OPA looks much more capable and complex than the ch32v003's, it doesn't have any programmable gain or similar features from docs I've read - just relies on external feedback resistors/connections.

I have updated some item names to better match your implementation and also hopefully make thing clearer 😀

andelf commented 3 months ago

Many thanks. It works as expected.