Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better abstraction API #6

Open
micw opened this issue Dec 7, 2016 · 1 comment
Open

Better abstraction API #6

micw opened this issue Dec 7, 2016 · 1 comment

Comments

@micw
Copy link

micw commented Dec 7, 2016

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
Copy link
Owner

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:

  • "original" ESP boards (ESP-07, ESP-12, ...) don't have any D1,D2, ... pins, but GPIOs 0 to 16, which are clearly labeled on its silkscreen. Using Arduino naming on these boards would be confusing, at least.
  • The Atmel HW PWM has different modes, timer predividers, ... whereas this SW PWM has a single mode with coupled PWM frequency and resolution.
  • If your ESP board has its GPIOs labeled D1, D2 ... but does not provide any documentation how these are mapped to the ESP8266 GPIOs, you should give the vendor a hit with the cluebat.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants