StefanBruens / ESP8266_new_pwm

This is a drop-in replacement for the ESP8266 SDK PWM
GNU General Public License v2.0
196 stars 46 forks source link

Better abstraction API #6

Open micw opened 7 years ago

micw commented 7 years ago

Hello,

today I replaced my analogWrite() based stuff by you library. All my flicker-issues immediately disappeared - great work!

The only drawback for me is that the use of your library from an Arduino sketch is quite un-intuitive: I use the pre-defined pins D1...D3. I had to find out what the real GIPOs are (5,4 and 0). Then I had to find out the register names (PERIPHS_IO_MUX_GPIO5_U, PERIPHS_IO_MUX_GPIO4_U, PERIPHS_IO_MUX_GPIO0_U)

To write PWM values, I have to use indices (0,1,2), not GPIO pins or D1...D3. And I always have to call pwm_start() after each change.

It would be great if there where a wrapper around your lib, so that it can easily be used as library in arduino. What do you think about this?

Regards, Michael.

StefanBruens commented 7 years ago

First, glad you enjoy it 😄

Second, Arduino was developed for small Atmel uCs, and shoehorning it onto other uCs is IMHO not a very good idea:

So, if you prefer to use D1 as the GPIO name, as it is (mis-)labeled as such on your board, you can just use

#define D1 0
#define D2 1
...

in your code and use these as the indices.

If you want to omit the pwm_start() call, just wrap it together with the pwm_set_duty(...) call. Drawback is if you e.g. change 3 channels at the same time, you end up calling pwm_start() three times instead of once.