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

Is it compatible with Arduino SDK? #12

Closed Denages closed 7 years ago

Denages commented 7 years ago

I'm trying to run example code, but have no results. PWM not working.

#include "pwm.c"

#define PWM_CHANNELS 5
#define SDK_PWM_PERIOD_COMPAT_MODE 1
const uint32_t period = 5000; // * 200ns ^= 1 kHz
uint32 pwm_duty_init[PWM_CHANNELS] = {500, 500, 500, 500, 500};

uint32 io_info[PWM_CHANNELS][3] = {
    // MUX, FUNC, PIN
    {PERIPHS_IO_MUX_MTDI_U,  FUNC_GPIO12, 12},
    {PERIPHS_IO_MUX_MTDO_U,  FUNC_GPIO15, 15},
    {PERIPHS_IO_MUX_MTCK_U,  FUNC_GPIO13, 13},
    {PERIPHS_IO_MUX_MTMS_U,  FUNC_GPIO14, 14},
    {PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5 ,  5},
};

void setup() {
  pwm_init(period, pwm_duty_init, PWM_CHANNELS, io_info);
  pwm_start();
}

void loop() {
}
fgather commented 7 years ago

You have to set the respective pins to output mode. E.g. :

pinMode(15,OUTPUT);

for GPIO15

StefanBruens commented 7 years ago

Another Arduino stupidity. GPIO directions and mode are set by pwm_init(...), but Arduino knows better ...