/* * ESPRESSIF MIT License * * Copyright (c) 2015 * * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "esp_common.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "pwm.h" #define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_MTDI_U #define PWM_0_OUT_IO_NUM 12 #define PWM_0_OUT_IO_FUNC FUNC_GPIO12 #define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTCK_U #define PWM_1_OUT_IO_NUM 13 #define PWM_1_OUT_IO_FUNC FUNC_GPIO13 #define PWM_2_OUT_IO_MUX PERIPHS_IO_MUX_MTMS_U #define PWM_2_OUT_IO_NUM 14 #define PWM_2_OUT_IO_FUNC FUNC_GPIO14 #define PWM_3_OUT_IO_MUX PERIPHS_IO_MUX_MTDO_U #define PWM_3_OUT_IO_NUM 15 #define PWM_3_OUT_IO_FUNC FUNC_GPIO15 //PWM period 500us(2Khz) #define PWM_PERIOD (500) /****************************************************************************** * FunctionName : user_rf_cal_sector_set * Description : SDK just reversed 4 sectors, used for rf init data and paramters. * We add this function to force users to set rf cal sector, since * we don't know which sector is free in user's application. * sector map for last several sectors : ABCCC * A : rf cal * B : rf init data * C : sdk parameters * Parameters : none * Returns : rf cal sector *******************************************************************************/ uint32 user_rf_cal_sector_set(void) { flash_size_map size_map = system_get_flash_size_map(); uint32 rf_cal_sec = 0; switch (size_map) { case FLASH_SIZE_4M_MAP_256_256: rf_cal_sec = 128 - 5; break; case FLASH_SIZE_8M_MAP_512_512: rf_cal_sec = 256 - 5; break; case FLASH_SIZE_16M_MAP_512_512: case FLASH_SIZE_16M_MAP_1024_1024: rf_cal_sec = 512 - 5; break; case FLASH_SIZE_32M_MAP_512_512: case FLASH_SIZE_32M_MAP_1024_1024: rf_cal_sec = 1024 - 5; break; case FLASH_SIZE_64M_MAP_1024_1024: rf_cal_sec = 2048 - 5; break; case FLASH_SIZE_128M_MAP_1024_1024: rf_cal_sec = 4096 - 5; break; default: rf_cal_sec = 0; break; } return rf_cal_sec; } /****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ //pwm out_put io uint32 io_info[][3] = { { PWM_0_OUT_IO_MUX, PWM_0_OUT_IO_FUNC, PWM_0_OUT_IO_NUM }, { PWM_1_OUT_IO_MUX, PWM_1_OUT_IO_FUNC, PWM_1_OUT_IO_NUM }, { PWM_2_OUT_IO_MUX, PWM_2_OUT_IO_FUNC, PWM_2_OUT_IO_NUM }, { PWM_3_OUT_IO_MUX, PWM_3_OUT_IO_FUNC, PWM_3_OUT_IO_NUM }, }; //dutys table uint32 dutys[][4] = { {250, 250, 250, 250}, }; //phase table int phase[][4] = { {0, 0, 50, -50}, }; void user_init(void) { printf("SDK version:%s\n", system_get_sdk_version()); pwm_init(PWM_PERIOD, dutys[0], 4, io_info); pwm_set_channel_reverse(0x1<<0); pwm_set_phases(phase[0]); pwm_start(); int count = 0; while(1) { if(count == 20) { //channel0, 1 output hight level. //channel2, 3 output low level. pwm_stop(0x3); printf("PWM stop\n"); } else if(count == 30){ pwm_start(); printf("PWM re-start\n"); count = 0; } count++; vTaskDelay(1000 / portTICK_RATE_MS); } }