esp-hal icon indicating copy to clipboard operation
esp-hal copied to clipboard

Revise APIs ported from ESP32-HAL

Open bjoernQ opened this issue 2 years ago • 4 comments

Some of the APIs that just get straight ported from ESP32-HAL have a potential of being used wrong.

e.g. one could try to use ADC without ever calling enable_pin or for the (not yet merged) LEDC one could call getChannel with different pins but the same channel

In many places there are runtime checks but we can try to make use of the type-system to turn them into compile-time errors where possible


  • [x] ADC read currently does a runtime check if the given PIN is configured for ADC and panics if not
  • [x] it seems that one could assign pins multiple times to an RMT channel - there is a runtime error specified but it seems it's not checked
  • [x] LEDC: it's possible to create multiple instances since the constructor doesn't take the LEDC peripheral
  • [ ] LEDC: it's possible to call get_channel multiple times with the same channel and different PINs

bjoernQ avatar Jul 25 '22 10:07 bjoernQ

Would it be possible to create a task list in this issue to track which APIs need revising?

jessebraham avatar Jul 25 '22 19:07 jessebraham

Sure - I will add the things I identified - might not be an exhaustive list however

bjoernQ avatar Jul 26 '22 06:07 bjoernQ

What should get changed in a way that runtime-errors are turned into compile-time errors (or make it error out at all)

EDIT: task list moved to first post so that they are displayed on the Issues page

bjoernQ avatar Jul 26 '22 07:07 bjoernQ

LEDC: it's possible to create multiple instances since the constructor doesn't take the LEDC peripheral: closed with #181 ADC: read currently does a runtime check if the given PIN is configured for ADC and panics if not: closed with #184 RMT: it seems that one could assign pins multiple times to an RMT channel - there is a runtime error specified but it seems it's not checked: closed with #194

JurajSadel avatar Sep 06 '22 10:09 JurajSadel