esp-hal
esp-hal copied to clipboard
TRNG driver
Copying from https://github.com/esp-rs/esp-hal/issues/1296#issuecomment-2004586786
Possible solutions:
- have two separate constructors for RNG (normal) and TRNG (will also take ADC peripheral so user won't be able to use them together)
- Just provide a
revert_trngfor user, which is not a good solution from the point of "user-friendliness" (and many other points I guess) - somehow ensure that revert_trng was called where and when needed after TRNG initialization (is it possible?)
First one sounds a bit "hacky", third one sounds impossible/difficult.
IDF seems to be using the second approach, which means that random_disable function is being provided to user "on his own risk" : https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/random.html
I like the IDF way in this case: We'll make "RNG" be "TRNG" by default, then provide function (revert_trng) to revert the "True" part and make it be just RNG again. However, it's not the most user-friendly approach, I'll think a bit more about other options.
On the other hand, having an explicit interface AND constructor for the TRNG is better then giving the "unsafe sword" to the user.
Feel free to post your thoughts here
Most of the progress is already done in my branch, I'll do a PR as soon as I can. https://github.com/playfulFence/esp-hal/tree/feature/trng_revert