How can I use ESP8266 library pwm.h? If I just include the library in my arduino project, I get an error: undefined reference to pwm_init
I need a 40khz sine wave for ultrasonic sensor and analogWrite works bad at high frequencies.
Sorry, if the answer is obvious, I have been googling the problem for a few hours and I can't find anything useful.
EDIT
I think this is the correct pwm.c file. Where do I have to put it? I tried adding just this file to my project but it doesn't work. I guess it has dependencies to other files in that library. But how do I even add C library to arduino project? And why it is not already included in ESP8266 core library if there is a header pwm.h?
The libpwm.a
is part of ESP8266 SDK, if you installed the ESP8266 Addon With the Arduino Boards Manager, this library should be in :
.arduino15/packages/esp8266/hardware/esp8266/<SDK Version>/tools/sdk/lib/libpwm.a
In order to use PWM, you should include in your sketch pwm.h
forcing C mangling :
extern "C" {
#include "pwm.h"
}
Then in order to link with libpwm.a
you should customize the link command creating a custom plateform configuration file .arduino15/packages/esp8266/hardware/esp8266/<SDK Version>/platform.local.txt
, adding
compiler.c.elf.extra_flags=-lpwm
You can also add this line in the plateform configuration file .arduino15/packages/esp8266/hardware/esp8266/<SDK Version>/platform.txt