From 4c45455ff07d92529b2b52839008299a1aa4ba93 Mon Sep 17 00:00:00 2001 From: xiongyu Date: Thu, 16 May 2019 15:38:54 +0800 Subject: [PATCH] bugfix(pwm): fix pwm channel num type error Fixes https://github.com/espressif/ESP8266_RTOS_SDK/issues/588 --- components/esp8266/driver/pwm.c | 4 ++-- components/esp8266/include/driver/pwm.h | 4 ++-- examples/peripherals/pwm/README.md | 2 +- .../peripherals/pwm/main/pwm_example_main.c | 6 +++--- examples/peripherals/pwm/wave.png | Bin 1073 -> 1088 bytes 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/esp8266/driver/pwm.c b/components/esp8266/driver/pwm.c index 376aa756..73c3d0f8 100644 --- a/components/esp8266/driver/pwm.c +++ b/components/esp8266/driver/pwm.c @@ -514,7 +514,7 @@ static esp_err_t pwm_obj_free(void) return ESP_OK; } -static esp_err_t pwm_obj_malloc(uint32_t channel_num) +static esp_err_t pwm_obj_malloc(uint8_t channel_num) { pwm_obj = (pwm_obj_t *)heap_caps_malloc(sizeof(pwm_obj_t), MALLOC_CAP_8BIT); @@ -539,7 +539,7 @@ static esp_err_t pwm_obj_malloc(uint32_t channel_num) return ESP_OK; } -esp_err_t pwm_init(uint32_t period, uint32_t *duties, uint32_t channel_num, const uint32_t *pin_num) +esp_err_t pwm_init(uint32_t period, uint32_t *duties, uint8_t channel_num, const uint32_t *pin_num) { PWM_CHECK(pwm_obj == NULL, "pwm has been initialized", ESP_FAIL); PWM_CHECK(channel_num <= MAX_PWM_CHANNEL, "Channel num out of range", ESP_ERR_INVALID_ARG); diff --git a/components/esp8266/include/driver/pwm.h b/components/esp8266/include/driver/pwm.h index cc1f643c..c457ba91 100644 --- a/components/esp8266/include/driver/pwm.h +++ b/components/esp8266/include/driver/pwm.h @@ -27,7 +27,7 @@ extern "C" { * @param period PWM period, unit: us. * e.g. For 1KHz PWM, period is 1000 us. Do not set the period below 20us. * @param duties duty cycle of each channels. - * @param pwm_channel_num PWM channel number, maximum is 8 + * @param channel_num PWM channel number, maximum is 8 * @param pin_num GPIO number of PWM channel * * @return @@ -35,7 +35,7 @@ extern "C" { * - ESP_ERR_INVALID_ARG Parameter error * - ESP_FAIL Init error */ -esp_err_t pwm_init(uint32_t period, uint32_t *duties, uint32_t pwm_channel_num, const uint32_t *pin_num); +esp_err_t pwm_init(uint32_t period, uint32_t *duties, uint8_t channel_num, const uint32_t *pin_num); /** * @brief PWM function uninstall diff --git a/examples/peripherals/pwm/README.md b/examples/peripherals/pwm/README.md index 91df1ad2..c073186b 100644 --- a/examples/peripherals/pwm/README.md +++ b/examples/peripherals/pwm/README.md @@ -47,7 +47,7 @@ I (220) gpio: GPIO[12]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldo I (225) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 I (247) gpio: GPIO[14]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 I (251) gpio: GPIO[15]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (265) pwm: --- PWM v3.0 +I (265) pwm: --- PWM v3.2 I (20276) main: PWM stop diff --git a/examples/peripherals/pwm/main/pwm_example_main.c b/examples/peripherals/pwm/main/pwm_example_main.c index 989b4648..e7f1df5d 100644 --- a/examples/peripherals/pwm/main/pwm_example_main.c +++ b/examples/peripherals/pwm/main/pwm_example_main.c @@ -30,8 +30,8 @@ #define PWM_2_OUT_IO_NUM 14 #define PWM_3_OUT_IO_NUM 15 -// PWM period 500us(2Khz), same as depth -#define PWM_PERIOD (500) +// PWM period 1000us(1Khz), same as depth +#define PWM_PERIOD (1000) static const char *TAG = "pwm_example"; @@ -45,7 +45,7 @@ const uint32_t pin_num[4] = { // duties table, real_duty = duties[x]/PERIOD uint32_t duties[4] = { - 250, 250, 250, 250, + 500, 500, 500, 500, }; // phase table, delay = (phase[x]/360)*PERIOD diff --git a/examples/peripherals/pwm/wave.png b/examples/peripherals/pwm/wave.png index a7ace1e401b1a7f7e2254c29c3e5e99420f13d83..7c52a98b8d4c67a07b3600f6b677851d621ee397 100644 GIT binary patch literal 1088 zcmeAS@N?(olHy`uVBq!ia0y~yV6p+SS8^}`$pw)GB0!3{*vT`5gM;JtL;nXru4IX8 zL`iUdT1k0gQ7S`vUVd(>ZgFx^YHD6_Mt;eA=KXd+EtfrA978JRyuIt#^~gb@A#kdU z<9R{^c)33A`U=UB*B4JeU|*SY`=a-Q_Bs1@H7@tx@~_E%uipHsQos1?H!eS~ z5@_JL$fV%Bh2eyNE`yN^Hwss8`|YomlKbT2?xonWH6NTH5!Yt(p=SPbVQZb&uj)VT z&WWG()?0da?K*ZwY}%owC4Vx0Qp2&{N+$Ke%g?8PiH_t9T{* zbFHg5|4jJ4=iJNJQq{lI)*te-`}%6nt60DIy9X%pp0?;NBE4r-#i&~MS-S7hmyb`R z4H-@p*m4jVNw}lXkhkXArghBokG-#k#h%sj{N)obTK(KT{pXd{#lLpV+4nbwp9xP= zIQFz`x1IXoc7FZ*O>)f#6Mk6DdH=aaDkU=f|K$6rzb}Ejcl-QT1$?Q>r|#KIaeZc) zqc3k~J~2;XI8gr-f0Dr+V@T;MIqF*JgU52W%|2xQS++5sY5)0`uZwFh? zR*XL`F5fu*^K8CF*X85t5|$QxR;t#)dR}_22WQ%mvv4FO#m!l Bo4^17 literal 1073 zcmeAS@N?(olHy`uVBq!ia0y~yV0;Q>&*xwQk{)xy)PNLov6E*A2M5RPhyD+MT*(sG zh?3y^w370~qEv?Ty!_l$-Qwh;)YQDt>Plz91?#%vZ!-5vzNWs5sF~7s4ew#x3+n<8>+~>IPppwI(IgZ)ng(-Q| zkGkYZ{Ey!L+;g|j?odI_>3Mgyy(kUMyIR+1@OGna_R(CtuGv>rYqww83DavpU)mmi z`M9WZ@iVLQ_adT;b!W$%UiN5fg&fm`1=ksPt9Y?c!5&Cg!k zkMV_L&DUQwb>?f@k19Mjl=#*Lq$E=!c#7uzm+_OIep=dk-RGJIzkAnziM!@ss9SyK z%rf!aV&|P1FmnzxA`?GJE=>Hn{-L7Sv!|6r__S@mn5yjhybZ_B12a8?r>mdKI;Vst E02|WifB*mh