esp-rs / esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
https://docs.esp-rs.org/esp-hal/
Apache License 2.0
640 stars 178 forks source link

Remove usages of raw register manipulation outside of PAC crates #1194

Open MabezDev opened 5 months ago

MabezDev commented 5 months ago

We currently have duplicates of these reg functions where the svd's don't have enough info, and we have to resort back to raw register writes. E.g: https://github.com/search?q=repo%3Aesp-rs%2Fesp-hal%20reg_set&type=code.

We should cleanup and modularise their usage/definitions across our chip line-up.

cc: @playfulFence who initially noticed the issue.

Edit by @playfulFence: Steps to resolve that issue (might be updated later):

bjoernQ commented 5 months ago

Maybe we could even avoid those functions and use something like https://crates.io/crates/tock-registers

But I think such code originates from 1:1 translation of esp-idf code - but once such code is known working, we could improve it

jessebraham commented 5 months ago

Maybe I'm missing something, but why are we going to all this effort instead of just fixing the PACs?

bjoernQ commented 5 months ago

Maybe I'm missing something, but why are we going to all this effort instead of just fixing the PACs?

That would certainly be the best solution for registers! I somehow thought of I2C_BBPLL which we also deal with in those places

MabezDev commented 5 months ago

Good idea! Let's do that instead, I've updated the title.

jessebraham commented 5 months ago

I don't think I will be able to do this any time soon unfortunately, but if somebody else wants to tackle it I can at least explain what needs to be done to them, so just lemme know. If nobody has tackled this in a month or two when I wrap up my currently projects then I will take care of it at that point.

playfulFence commented 2 weeks ago

Just to have some part of an investigation here: Most of the cases of manipulations with raw register addresses are related to regi2c_* functions, which has a tracking issue here https://github.com/esp-rs/esp-hal/issues/1740. Which means that this issue highly depends on it. At this point, I think, I will temporarily switch to analyzing regi2c_* functions.