mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-08-06 15:15:15 +08:00
Merge branch 'bugfix/update_pwm_lib_for_v2.x' into 'release/v2.x.x'
update pwm lib for release/v2.xx See merge request sdk/ESP8266_RTOS_SDK!187
This commit is contained in:
128
examples/pwm_test/Makefile
Normal file
128
examples/pwm_test/Makefile
Normal file
@ -0,0 +1,128 @@
|
||||
#############################################################
|
||||
# Required variables for each makefile
|
||||
# Discard this section from all parent makefiles
|
||||
# Expected variables (with automatic defaults):
|
||||
# CSRCS (all "C" files in the dir)
|
||||
# SUBDIRS (all subdirs with a Makefile)
|
||||
# GEN_LIBS - list of libs to be generated ()
|
||||
# GEN_IMAGES - list of object file images to be generated ()
|
||||
# GEN_BINS - list of binaries to be generated ()
|
||||
# COMPONENTS_xxx - a list of libs/objs in the form
|
||||
# subdir/lib to be extracted and rolled up into
|
||||
# a generated lib/image xxx.a ()
|
||||
#
|
||||
TARGET = eagle
|
||||
#FLAVOR = release
|
||||
FLAVOR = debug
|
||||
|
||||
#EXTRA_CCFLAGS += -u
|
||||
|
||||
ifndef PDIR # {
|
||||
GEN_IMAGES= eagle.app.v6.out
|
||||
GEN_BINS= eagle.app.v6.bin
|
||||
SPECIAL_MKTARGETS=$(APP_MKTARGETS)
|
||||
SUBDIRS= \
|
||||
user
|
||||
endif # } PDIR
|
||||
|
||||
LDDIR = $(SDK_PATH)/ld
|
||||
|
||||
CCFLAGS += -Os
|
||||
|
||||
TARGET_LDFLAGS = \
|
||||
-nostdlib \
|
||||
-Wl,-EL \
|
||||
--longcalls \
|
||||
--text-section-literals
|
||||
|
||||
ifeq ($(FLAVOR),debug)
|
||||
TARGET_LDFLAGS += -g -O2
|
||||
endif
|
||||
|
||||
ifeq ($(FLAVOR),release)
|
||||
TARGET_LDFLAGS += -g -O0
|
||||
endif
|
||||
|
||||
COMPONENTS_eagle.app.v6 = \
|
||||
user/libuser.a
|
||||
|
||||
LINKFLAGS_eagle.app.v6 = \
|
||||
-L$(SDK_PATH)/lib \
|
||||
-Wl,--gc-sections \
|
||||
-nostdlib \
|
||||
-T$(LD_FILE) \
|
||||
-Wl,--no-check-sections \
|
||||
-u call_user_start \
|
||||
-Wl,-static \
|
||||
-Wl,--start-group \
|
||||
-lcirom \
|
||||
-lcrypto \
|
||||
-lespconn \
|
||||
-lespnow \
|
||||
-lfreertos \
|
||||
-lgcc \
|
||||
-lhal \
|
||||
-ljson \
|
||||
-llwip \
|
||||
-lmain \
|
||||
-lmirom \
|
||||
-lnet80211 \
|
||||
-lnopoll \
|
||||
-lphy \
|
||||
-lpp \
|
||||
-lsmartconfig \
|
||||
-lspiffs \
|
||||
-lssl \
|
||||
-lwpa \
|
||||
-lwps \
|
||||
-lpwm \
|
||||
$(DEP_LIBS_eagle.app.v6) \
|
||||
-Wl,--end-group
|
||||
|
||||
DEPENDS_eagle.app.v6 = \
|
||||
$(LD_FILE) \
|
||||
$(LDDIR)/eagle.rom.addr.v6.ld
|
||||
|
||||
#############################################################
|
||||
# Configuration i.e. compile options etc.
|
||||
# Target specific stuff (defines etc.) goes in here!
|
||||
# Generally values applying to a tree are captured in the
|
||||
# makefile at its root level - these are then overridden
|
||||
# for a subtree within the makefile rooted therein
|
||||
#
|
||||
|
||||
#UNIVERSAL_TARGET_DEFINES = \
|
||||
|
||||
# Other potential configuration flags include:
|
||||
# -DTXRX_TXBUF_DEBUG
|
||||
# -DTXRX_RXBUF_DEBUG
|
||||
# -DWLAN_CONFIG_CCX
|
||||
CONFIGURATION_DEFINES = -DICACHE_FLASH
|
||||
|
||||
DEFINES += \
|
||||
$(UNIVERSAL_TARGET_DEFINES) \
|
||||
$(CONFIGURATION_DEFINES)
|
||||
|
||||
DDEFINES += \
|
||||
$(UNIVERSAL_TARGET_DEFINES) \
|
||||
$(CONFIGURATION_DEFINES)
|
||||
|
||||
|
||||
#############################################################
|
||||
# Recursion Magic - Don't touch this!!
|
||||
#
|
||||
# Each subtree potentially has an include directory
|
||||
# corresponding to the common APIs applicable to modules
|
||||
# rooted at that subtree. Accordingly, the INCLUDE PATH
|
||||
# of a module can only contain the include directories up
|
||||
# its parent path, and not its siblings
|
||||
#
|
||||
# Required for each makefile to inherit from the parent
|
||||
#
|
||||
|
||||
INCLUDES := $(INCLUDES) -I $(PDIR)include
|
||||
sinclude $(SDK_PATH)/Makefile
|
||||
|
||||
.PHONY: FORCE flash
|
||||
FORCE:
|
||||
|
172
examples/pwm_test/gen_misc.bat
Executable file
172
examples/pwm_test/gen_misc.bat
Executable file
@ -0,0 +1,172 @@
|
||||
@echo off
|
||||
|
||||
Rem ******NOTICE******
|
||||
Rem MUST set SDK_PATH & BIN_PATH firstly!!!
|
||||
Rem example:
|
||||
Rem set SDK_PATH=/c/esp_iot_sdk_freertos
|
||||
Rem set BIN_PATH=/c/esp8266_bin
|
||||
|
||||
set SDK_PATH=""
|
||||
set BIN_PATH=""
|
||||
|
||||
echo gen_misc.bat version 20150911
|
||||
echo .
|
||||
|
||||
if not %SDK_PATH% == "" (
|
||||
echo SDK_PATH: %SDK_PATH%
|
||||
) else (
|
||||
echo ERROR: Please set SDK_PATH in gen_misc.bat firstly, exit!!!
|
||||
goto end
|
||||
)
|
||||
|
||||
if not %BIN_PATH% == "" (
|
||||
echo BIN_PATH: %BIN_PATH%
|
||||
) else (
|
||||
echo ERROR: Please set BIN_PATH in gen_misc.bat firstly, exit!!!
|
||||
goto end
|
||||
)
|
||||
|
||||
echo .
|
||||
echo Please check SDK_PATH/BIN_PATH, enter (Y/y) to continue:
|
||||
set input=default
|
||||
set /p input=
|
||||
|
||||
if not %input% == Y (
|
||||
if not %input% == y (
|
||||
goto end
|
||||
)
|
||||
)
|
||||
|
||||
echo .
|
||||
echo Please follow below steps(1-5) to generate specific bin(s):
|
||||
echo STEP 1: use boot_v1.2+ by default
|
||||
set boot=new
|
||||
|
||||
echo boot mode: %boot%
|
||||
echo.
|
||||
|
||||
echo STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin)
|
||||
set input=default
|
||||
set /p input=enter (0/1/2, default 0):
|
||||
|
||||
if %input% equ 1 (
|
||||
if %boot% equ none (
|
||||
set app=0
|
||||
echo choose no boot before
|
||||
echo generate bin: eagle.flash.bin+eagle.irom0text.bin
|
||||
) else (
|
||||
set app=1
|
||||
echo generate bin: user1.bin
|
||||
)
|
||||
) else (
|
||||
if %input% equ 2 (
|
||||
if %boot% equ none (
|
||||
set app=0
|
||||
echo choose no boot before
|
||||
echo generate bin: eagle.flash.bin+eagle.irom0text.bin
|
||||
) else (
|
||||
set app=2
|
||||
echo generate bin: user2.bin
|
||||
)
|
||||
) else (
|
||||
if %boot% neq none (
|
||||
set boot=none
|
||||
echo ignore boot
|
||||
)
|
||||
set app=0
|
||||
echo generate bin: eagle.flash.bin+eagle.irom0text.bin
|
||||
))
|
||||
|
||||
echo.
|
||||
|
||||
echo STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz)
|
||||
set input=default
|
||||
set /p input=enter (0/1/2/3, default 2):
|
||||
|
||||
if %input% equ 0 (
|
||||
set spi_speed=20
|
||||
) else (
|
||||
if %input% equ 1 (
|
||||
set spi_speed=26.7
|
||||
) else (
|
||||
if %input% equ 3 (
|
||||
set spi_speed=80
|
||||
) else (
|
||||
set spi_speed=40
|
||||
)))
|
||||
|
||||
echo spi speed: %spi_speed% MHz
|
||||
echo.
|
||||
|
||||
echo STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT)
|
||||
set input=default
|
||||
set /p input=enter (0/1/2/3, default 0):
|
||||
|
||||
if %input% equ 1 (
|
||||
set spi_mode=QOUT
|
||||
) else (
|
||||
if %input% equ 2 (
|
||||
set spi_mode=DIO
|
||||
) else (
|
||||
if %input% equ 3 (
|
||||
set spi_mode=DOUT
|
||||
) else (
|
||||
set spi_mode=QIO
|
||||
)))
|
||||
|
||||
echo spi mode: %spi_mode%
|
||||
echo.
|
||||
|
||||
echo STEP 5: choose flash size and map
|
||||
echo 0= 512KB( 256KB+ 256KB)
|
||||
echo 2=1024KB( 512KB+ 512KB)
|
||||
echo 3=2048KB( 512KB+ 512KB)
|
||||
echo 4=4096KB( 512KB+ 512KB)
|
||||
echo 5=2048KB(1024KB+1024KB)
|
||||
echo 6=4096KB(1024KB+1024KB)
|
||||
set input=default
|
||||
set /p input=enter (0/1/2/3/4/5/6, default 0):
|
||||
|
||||
if %input% equ 2 (
|
||||
set spi_size_map=2
|
||||
echo spi size: 1024KB
|
||||
echo spi ota map: 512KB + 512KB
|
||||
) else (
|
||||
if %input% equ 3 (
|
||||
set spi_size_map=3
|
||||
echo spi size: 2048KB
|
||||
echo spi ota map: 512KB + 512KB
|
||||
) else (
|
||||
if %input% equ 4 (
|
||||
set spi_size_map=4
|
||||
echo spi size: 4096KB
|
||||
echo spi ota map: 512KB + 512KB
|
||||
) else (
|
||||
if %input% equ 5 (
|
||||
set spi_size_map=5
|
||||
echo spi size: 2048KB
|
||||
echo spi ota map: 1024KB + 1024KB
|
||||
) else (
|
||||
if %input% equ 6 (
|
||||
set spi_size_map=6
|
||||
echo spi size: 4096KB
|
||||
echo spi ota map: 1024KB + 1024KB
|
||||
) else (
|
||||
set spi_size_map=0
|
||||
echo spi size: 512KB
|
||||
echo spi ota map: 256KB + 256KB
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
echo.
|
||||
echo start...
|
||||
echo.
|
||||
|
||||
make clean
|
||||
|
||||
make COMPILE=xcc BOOT=%boot% APP=%app% SPI_SPEED=%spi_speed% SPI_MODE=%spi_mode% SPI_SIZE_MAP=%spi_size_map%
|
||||
|
||||
:end
|
191
examples/pwm_test/gen_misc.sh
Executable file
191
examples/pwm_test/gen_misc.sh
Executable file
@ -0,0 +1,191 @@
|
||||
#!/bin/bash
|
||||
|
||||
:<<!
|
||||
******NOTICE******
|
||||
MUST set SDK_PATH & BIN_PATH firstly!!!
|
||||
example:
|
||||
export SDK_PATH=~/esp_iot_sdk_freertos
|
||||
export BIN_PATH=~/esp8266_bin
|
||||
!
|
||||
|
||||
export SDK_PATH=$SDK_PATH
|
||||
export BIN_PATH=$BIN_PATH
|
||||
|
||||
echo "gen_misc.sh version 20150911"
|
||||
echo ""
|
||||
|
||||
if [ $SDK_PATH ]; then
|
||||
echo "SDK_PATH:"
|
||||
echo "$SDK_PATH"
|
||||
echo ""
|
||||
else
|
||||
echo "ERROR: Please export SDK_PATH in gen_misc.sh firstly, exit!!!"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ $BIN_PATH ]; then
|
||||
echo "BIN_PATH:"
|
||||
echo "$BIN_PATH"
|
||||
echo ""
|
||||
else
|
||||
echo "ERROR: Please export BIN_PATH in gen_misc.sh firstly, exit!!!"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "Please check SDK_PATH & BIN_PATH, enter (Y/y) to continue:"
|
||||
read input
|
||||
|
||||
if [[ $input != Y ]] && [[ $input != y ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
echo "Please follow below steps(1-5) to generate specific bin(s):"
|
||||
echo "STEP 1: use boot_v1.2+ by default"
|
||||
boot=new
|
||||
|
||||
echo "boot mode: $boot"
|
||||
echo ""
|
||||
|
||||
echo "STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin)"
|
||||
echo "enter (0/1/2, default 0):"
|
||||
read input
|
||||
|
||||
if [ -z "$input" ]; then
|
||||
if [ $boot != none ]; then
|
||||
boot=none
|
||||
echo "ignore boot"
|
||||
fi
|
||||
app=0
|
||||
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
|
||||
elif [ $input == 1 ]; then
|
||||
if [ $boot == none ]; then
|
||||
app=0
|
||||
echo "choose no boot before"
|
||||
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
|
||||
else
|
||||
app=1
|
||||
echo "generate bin: user1.bin"
|
||||
fi
|
||||
elif [ $input == 2 ]; then
|
||||
if [ $boot == none ]; then
|
||||
app=0
|
||||
echo "choose no boot before"
|
||||
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
|
||||
else
|
||||
app=2
|
||||
echo "generate bin: user2.bin"
|
||||
fi
|
||||
else
|
||||
if [ $boot != none ]; then
|
||||
boot=none
|
||||
echo "ignore boot"
|
||||
fi
|
||||
app=0
|
||||
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
echo "STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz)"
|
||||
echo "enter (0/1/2/3, default 2):"
|
||||
read input
|
||||
|
||||
if [ -z "$input" ]; then
|
||||
spi_speed=40
|
||||
elif [ $input == 0 ]; then
|
||||
spi_speed=20
|
||||
elif [ $input == 1 ]; then
|
||||
spi_speed=26.7
|
||||
elif [ $input == 3 ]; then
|
||||
spi_speed=80
|
||||
else
|
||||
spi_speed=40
|
||||
fi
|
||||
|
||||
echo "spi speed: $spi_speed MHz"
|
||||
echo ""
|
||||
|
||||
echo "STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT)"
|
||||
echo "enter (0/1/2/3, default 0):"
|
||||
read input
|
||||
|
||||
if [ -z "$input" ]; then
|
||||
spi_mode=QIO
|
||||
elif [ $input == 1 ]; then
|
||||
spi_mode=QOUT
|
||||
elif [ $input == 2 ]; then
|
||||
spi_mode=DIO
|
||||
elif [ $input == 3 ]; then
|
||||
spi_mode=DOUT
|
||||
else
|
||||
spi_mode=QIO
|
||||
fi
|
||||
|
||||
echo "spi mode: $spi_mode"
|
||||
echo ""
|
||||
|
||||
echo "STEP 5: choose spi size and map"
|
||||
echo " 0= 512KB( 256KB+ 256KB)"
|
||||
echo " 2=1024KB( 512KB+ 512KB)"
|
||||
echo " 3=2048KB( 512KB+ 512KB)"
|
||||
echo " 4=4096KB( 512KB+ 512KB)"
|
||||
echo " 5=2048KB(1024KB+1024KB)"
|
||||
echo " 6=4096KB(1024KB+1024KB)"
|
||||
echo " 7=4096KB(2048KB+2048KB) not support ,just for compatible with nodeMCU board"
|
||||
echo " 8=8192KB(1024KB+1024KB)"
|
||||
echo " 9=16384KB(1024KB+1024KB)"
|
||||
echo "enter (0/2/3/4/5/6/7/8/9, default 0):"
|
||||
read input
|
||||
|
||||
if [ -z "$input" ]; then
|
||||
spi_size_map=0
|
||||
echo "spi size: 512KB"
|
||||
echo "spi ota map: 256KB + 256KB"
|
||||
elif [ $input == 2 ]; then
|
||||
spi_size_map=2
|
||||
echo "spi size: 1024KB"
|
||||
echo "spi ota map: 512KB + 512KB"
|
||||
elif [ $input == 3 ]; then
|
||||
spi_size_map=3
|
||||
echo "spi size: 2048KB"
|
||||
echo "spi ota map: 512KB + 512KB"
|
||||
elif [ $input == 4 ]; then
|
||||
spi_size_map=4
|
||||
echo "spi size: 4096KB"
|
||||
echo "spi ota map: 512KB + 512KB"
|
||||
elif [ $input == 5 ]; then
|
||||
spi_size_map=5
|
||||
echo "spi size: 2048KB"
|
||||
echo "spi ota map: 1024KB + 1024KB"
|
||||
elif [ $input == 6 ]; then
|
||||
spi_size_map=6
|
||||
echo "spi size: 4096KB"
|
||||
echo "spi ota map: 1024KB + 1024KB"
|
||||
elif [ $input == 7 ]; then
|
||||
spi_size_map=7
|
||||
echo"not support ,just for compatible with nodeMCU board"
|
||||
exit
|
||||
elif [ $input == 8 ]; then
|
||||
spi_size_map=8
|
||||
echo "spi size: 8192KB"
|
||||
echo "spi ota map: 1024KB + 1024KB"
|
||||
elif [ $input == 9 ]; then
|
||||
spi_size_map=9
|
||||
echo "spi size: 16384KB"
|
||||
echo "spi ota map: 1024KB + 1024KB"
|
||||
else
|
||||
spi_size_map=0
|
||||
echo "spi size: 512KB"
|
||||
echo "spi ota map: 256KB + 256KB"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
echo "start..."
|
||||
echo ""
|
||||
|
||||
make clean
|
||||
|
||||
make BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE_MAP=$spi_size_map
|
29
examples/pwm_test/include/user_config.h
Normal file
29
examples/pwm_test/include/user_config.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __USER_CONFIG_H__
|
||||
#define __USER_CONFIG_H__
|
||||
|
||||
#endif
|
||||
|
56
examples/pwm_test/readme.txt
Normal file
56
examples/pwm_test/readme.txt
Normal file
@ -0,0 +1,56 @@
|
||||
This is a simple project template.
|
||||
|
||||
sample_lib is an example for multi-level folder Makefile, notice the folder structure and each Makefile, you can get the clue.
|
||||
|
||||
|
||||
HOWTO:
|
||||
1. Copy this folder to anywhere.
|
||||
Example:
|
||||
Copy to ~/workspace/project_template
|
||||
You can rename this folder as you like.
|
||||
|
||||
2. Export SDK_PATH and BIN_PATH.
|
||||
Example:
|
||||
Your SDK path is ~/esp_iot_rtos_sdk, and want generate bin at ~/esp8266_bin.
|
||||
Do follow steps:
|
||||
1>. export SDK_PATH=~/esp_iot_rtos_sdk
|
||||
2>. export BIN_PATH=~/esp8266_bin
|
||||
SDK and project are seperate, you can update SDK without change your project.
|
||||
|
||||
3. Enter project_template folder, run ./gen_misc.sh, and follow the tips and steps.
|
||||
|
||||
|
||||
Compile Options:
|
||||
(1) COMPILE
|
||||
Possible value: xcc
|
||||
Default value:
|
||||
If not set, use gcc by default.
|
||||
|
||||
(2) BOOT
|
||||
Possible value: none/old/new
|
||||
none: no need boot
|
||||
old: use boot_v1.1
|
||||
new: use boot_v1.2
|
||||
Default value: new
|
||||
|
||||
(3) APP
|
||||
Possible value: 0/1/2
|
||||
0: original mode, generate eagle.app.v6.flash.bin and eagle.app.v6.irom0text.bin
|
||||
1: generate user1
|
||||
2: generate user2
|
||||
Default value: 0
|
||||
|
||||
(3) SPI_SPEED
|
||||
Possible value: 20/26.7/40/80
|
||||
Default value: 40
|
||||
|
||||
(4) SPI_MODE
|
||||
Possible value: QIO/QOUT/DIO/DOUT
|
||||
Default value: QIO
|
||||
|
||||
(4) SPI_SIZE_MAP
|
||||
Possible value: 0/2/3/4/5/6
|
||||
Default value: 0
|
||||
|
||||
For example:
|
||||
make COMPILE=gcc BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=0
|
44
examples/pwm_test/user/Makefile
Normal file
44
examples/pwm_test/user/Makefile
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
#############################################################
|
||||
# Required variables for each makefile
|
||||
# Discard this section from all parent makefiles
|
||||
# Expected variables (with automatic defaults):
|
||||
# CSRCS (all "C" files in the dir)
|
||||
# SUBDIRS (all subdirs with a Makefile)
|
||||
# GEN_LIBS - list of libs to be generated ()
|
||||
# GEN_IMAGES - list of images to be generated ()
|
||||
# COMPONENTS_xxx - a list of libs/objs in the form
|
||||
# subdir/lib to be extracted and rolled up into
|
||||
# a generated lib/image xxx.a ()
|
||||
#
|
||||
ifndef PDIR
|
||||
GEN_LIBS = libuser.a
|
||||
endif
|
||||
|
||||
|
||||
#############################################################
|
||||
# Configuration i.e. compile options etc.
|
||||
# Target specific stuff (defines etc.) goes in here!
|
||||
# Generally values applying to a tree are captured in the
|
||||
# makefile at its root level - these are then overridden
|
||||
# for a subtree within the makefile rooted therein
|
||||
#
|
||||
#DEFINES +=
|
||||
|
||||
#############################################################
|
||||
# Recursion Magic - Don't touch this!!
|
||||
#
|
||||
# Each subtree potentially has an include directory
|
||||
# corresponding to the common APIs applicable to modules
|
||||
# rooted at that subtree. Accordingly, the INCLUDE PATH
|
||||
# of a module can only contain the include directories up
|
||||
# its parent path, and not its siblings
|
||||
#
|
||||
# Required for each makefile to inherit from the parent
|
||||
#
|
||||
|
||||
INCLUDES := $(INCLUDES) -I $(PDIR)include
|
||||
INCLUDES += -I ./
|
||||
PDIR := ../$(PDIR)
|
||||
sinclude $(PDIR)Makefile
|
||||
|
144
examples/pwm_test/user/user_main.c
Normal file
144
examples/pwm_test/user/user_main.c
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* ESPRSSIF MIT License
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
|
||||
*
|
||||
@ -25,118 +25,189 @@
|
||||
#ifndef __PWM_H__
|
||||
#define __PWM_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \defgroup Driver_APIs Driver APIs
|
||||
* @brief Driver APIs
|
||||
*/
|
||||
|
||||
/** @addtogroup Driver_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** \defgroup PWM_Driver_APIs PWM Driver APIs
|
||||
* @brief PWM driver APIs
|
||||
*/
|
||||
|
||||
/** @addtogroup PWM_Driver_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
struct pwm_param {
|
||||
uint32 period; /**< PWM period */
|
||||
uint32 freq; /**< PWM frequency */
|
||||
uint32 duty[8]; /**< PWM duty */
|
||||
};
|
||||
|
||||
#define PWM_DEPTH 1023
|
||||
|
||||
/**
|
||||
* @brief PWM function initialization, including GPIO, frequency and duty cycle.
|
||||
* @brief PWM function initialization, including GPIO, frequency and duty cycle.
|
||||
*
|
||||
* @attention This API can be called only once.
|
||||
*
|
||||
* @param uint32 period : pwm frequency
|
||||
* @param uint32 *duty : duty cycle
|
||||
* @param uint32 pwm_channel_num : PWM channel number
|
||||
* @param uint32 (*pin_info_list)[3] : GPIO parameter of PWM channel, it is a pointer
|
||||
* of n x 3 array which defines GPIO register, IO
|
||||
* reuse of corresponding pin and GPIO number.
|
||||
* @param uint32_t period : PWM period, unit : us.
|
||||
* e.g.: For 1KHz PWM, period is 1000 us.
|
||||
* @param uint32_t *duty : duty cycle of each channels.
|
||||
* @param uint32_t pwm_channel_num : PWM channel number, maximum is 8
|
||||
* @param uint32_t (*pin_info_list)[3] : GPIO parameter of PWM channel, it is a pointer
|
||||
* of n x 3 array which defines GPIO register, IO reuse of corresponding pin and GPIO number.
|
||||
*
|
||||
* @return null
|
||||
* @return null
|
||||
*/
|
||||
void pwm_init(uint32 period, uint32 *duty, uint32 pwm_channel_num, uint32(*pin_info_list)[3]);
|
||||
void pwm_init(uint32_t period, uint32_t *duty, uint32_t pwm_channel_num, uint32_t(*pin_info_list)[3]);
|
||||
|
||||
/**
|
||||
* @brief Set the duty cycle of a PWM channel.
|
||||
* @brief Set the duty cycle of a PWM channel.
|
||||
* Set the time that high level or low(if you reverse the output of this channel)
|
||||
* signal will last, the duty cycle cannot exceed the period.
|
||||
*
|
||||
* @attention After set configuration, pwm_start needs to be called to take effect.
|
||||
*
|
||||
* Set the time that high level signal will last, duty depends on period,
|
||||
* the maximum value can be 1023.
|
||||
*
|
||||
* @param uint32_t duty : duty cycle
|
||||
* @param uint8_t channel_num : PWM channel number
|
||||
* the channel_num cannot exceed the value initialized by pwm_init.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
void pwm_set_duty(uint32_t duty, uint8_t channel_num);
|
||||
|
||||
/**
|
||||
* @brief Get the duty cycle of a PWM channel.
|
||||
*
|
||||
* @param uint8_t channel_num : PWM channel number
|
||||
* the channel_num cannot exceed the value initialized by pwm_init.
|
||||
*
|
||||
* @return Duty cycle of specified channel
|
||||
*/
|
||||
uint32_t pwm_get_duty(uint8_t channel_num);
|
||||
|
||||
/**
|
||||
* @brief Set PWM period, unit : us.
|
||||
*
|
||||
* @attention After set configuration, pwm_start needs to be called to take effect.
|
||||
*
|
||||
* @param uint32 duty : duty cycle
|
||||
* @param uint8 channel : PWM channel number
|
||||
* @param uint32_t period : PWM period, unit : us
|
||||
* For example, for 1KHz PWM, period is 1000.
|
||||
*
|
||||
* @return null
|
||||
* @return null
|
||||
*/
|
||||
void pwm_set_duty(uint32 duty, uint8 channel);
|
||||
void pwm_set_period(uint32_t period);
|
||||
|
||||
/**
|
||||
* @brief Get the duty cycle of a PWM channel.
|
||||
* @brief Get PWM period, unit : us.
|
||||
*
|
||||
* @param uint8 channel : PWM channel number
|
||||
* @param null
|
||||
*
|
||||
* @return Duty cycle of PWM output.
|
||||
* @return PWM period, unit : us
|
||||
*/
|
||||
uint32 pwm_get_duty(uint8 channel);
|
||||
uint32_t pwm_get_period(void);
|
||||
|
||||
/**
|
||||
* @brief Set PWM period, unit : us.
|
||||
*
|
||||
* For example, for 1KHz PWM, period is 1000 us.
|
||||
*
|
||||
* @attention After set configuration, pwm_start needs to be called to take effect.
|
||||
*
|
||||
* @param uint32 period : PWM period, unit : us.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
void pwm_set_period(uint32 period);
|
||||
|
||||
/**
|
||||
* @brief Get PWM period, unit : us.
|
||||
*
|
||||
* @param null
|
||||
*
|
||||
* @return PWM period, unit : us.
|
||||
*/
|
||||
uint32 pwm_get_period(void);
|
||||
|
||||
/**
|
||||
* @brief Starts PWM.
|
||||
* @brief Starts PWM.
|
||||
*
|
||||
* @attention This function needs to be called after PWM configuration is changed.
|
||||
*
|
||||
* @param null
|
||||
* @param null
|
||||
*
|
||||
* @return null
|
||||
* @return null
|
||||
*/
|
||||
void pwm_start(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @brief Stop all PWM channel.
|
||||
* Stop PWM and set the output of each channel to the specified level.
|
||||
* Calling pwm_start can re-start PWM output.
|
||||
*
|
||||
* @param uint32_t stop_level : Out put level after PWM is stoped
|
||||
* e.g.: We initialize 8 channels, if stop_level_mask = 0x0f,
|
||||
* channel 0,1,2 and 3 will output high level, and channel 4,5,6 and 7 will output low level.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
void pwm_stop(uint32_t stop_level_mask);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @brief Set the duty cycle of all channels.
|
||||
*
|
||||
* @attention After set configuration, pwm_start needs to be called to take effect.
|
||||
*
|
||||
* @param uint32_t *duty : An array that store the duty cycle of each channel,
|
||||
* the array elements number needs to be the same as the number of channels.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
void pwm_set_dutys(uint32_t *duty);
|
||||
|
||||
/**
|
||||
* @brief Set the phase of a PWM channel.
|
||||
*
|
||||
* @attention After set configuration, pwm_start needs to be called to take effect.
|
||||
*
|
||||
* @param int phase : The phase of this PWM channel, the phase range is (-180 ~ 180).
|
||||
* @param uint8_t channel_num : PWM channel number
|
||||
* the channel_num cannot exceed the value initialized by pwm_init.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
void pwm_set_phase(int phase, uint8_t channel_num);
|
||||
|
||||
/**
|
||||
* @brief Set the phase of all channels.
|
||||
*
|
||||
* @attention After set configuration, pwm_start needs to be called to take effect.
|
||||
*
|
||||
* @param int *phase : An array that store the phase of each channel,
|
||||
* the array elements number needs to be the same as the number of channels.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
void pwm_set_phases(int *phase);
|
||||
|
||||
/**
|
||||
* @brief Get the phase of a PWM channel.
|
||||
*
|
||||
* @param uint8_t channel_num : PWM channel number
|
||||
* the channel_num cannot exceed the value initialized by pwm_init.
|
||||
*
|
||||
* @return PWM phase of specified channel.
|
||||
*/
|
||||
int pwm_get_phase(uint8_t channel_num);
|
||||
|
||||
/**
|
||||
* @brief Set PWM period and duty of each PWM channel.
|
||||
*
|
||||
* @attention After set configuration, pwm_start needs to be called to take effect.
|
||||
*
|
||||
* @param uint32_t period : PWM period, unit : us
|
||||
* For example, for 1KHz PWM, period is 1000.
|
||||
* @param uint32_t *duty : An array that store the duty cycle of each channel,
|
||||
* the array elements number needs to be the same as the number of channels.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
void pwm_set_period_dutys(uint32_t period, uint32_t *duty);
|
||||
|
||||
/**
|
||||
* @brief Set the inverting output PWM channel.
|
||||
*
|
||||
* @attention After set configuration, pwm_start needs to be called to take effect.
|
||||
*
|
||||
* @param uint16_t channel_mask : The channel bitmask that used to reverse the output
|
||||
* e.g.: We initialize 8 channels, if channel_mask = 0x0f, channels 0, 1, 2 and 3 will reverse the output.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
void pwm_set_channel_reverse(uint16_t channel_mask);
|
||||
|
||||
/**
|
||||
* @brief Clear the inverting output PWM channel.
|
||||
* This function only works for the PWM channel that is already in the inverted output states.
|
||||
*
|
||||
* @attention After set configuration, pwm_start needs to be called to take effect.
|
||||
*
|
||||
* @param uint16_t channel_mask : The channel bitmask that need to clear
|
||||
* e.g.: The outputs of channels 0, 1, 2 and 3 are already in inverted state. If channel_mask = 0x07,
|
||||
* the output of channel 0, 1, and 2 will return to normal, the channel 3 will keep inverting output.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
void pwm_clear_channel_reverse(uint16_t channel_mask);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
BIN
lib/libpwm.a
BIN
lib/libpwm.a
Binary file not shown.
Reference in New Issue
Block a user