├── .gitattributes ├── .gitignore ├── IR_RemoteC ├── .cproject ├── .project ├── .settings │ └── org.eclipse.cdt.codan.core.prefs ├── Makefile ├── build │ ├── app.out │ ├── app_app.a │ ├── driver │ │ ├── EspIRremote.o │ │ ├── dht22.o │ │ ├── ds18b20.o │ │ ├── gpio16.o │ │ ├── i2c.o │ │ ├── i2c_bmp180.o │ │ ├── i2c_master.o │ │ ├── key.o │ │ ├── pwm.o │ │ ├── spi.o │ │ └── uart.o │ └── user │ │ ├── user_devicefind.o │ │ ├── user_esp_platform.o │ │ ├── user_esp_platform_timer.o │ │ ├── user_json.o │ │ ├── user_light.o │ │ ├── user_main.o │ │ ├── user_plug.o │ │ ├── user_sensor.o │ │ └── user_webserver.o ├── driver │ ├── EspIRremote.c │ ├── dht22.c │ ├── ds18b20.c │ ├── gpio16.c │ ├── i2c.c │ ├── i2c_bmp180.c │ ├── i2c_master.c │ ├── key.c │ ├── pwm.c │ ├── spi.c │ └── uart.c ├── firmware │ ├── eagle.flash.bin │ └── eagle.irom0text.bin ├── gen_misc.bat ├── gen_misc.sh ├── include │ ├── driver │ │ ├── EspIRremote.h │ │ ├── EspIRremoteInt.h │ │ ├── EspIRremoteTools.h │ │ ├── dht22.h │ │ ├── ds18b20.h │ │ ├── gpio16.h │ │ ├── i2c.h │ │ ├── i2c_bmp180.h │ │ ├── i2c_master.h │ │ ├── key.h │ │ ├── pwm.h │ │ ├── spi.h │ │ ├── spi_register.h │ │ ├── uart.h │ │ └── uart_register.h │ ├── espmissingincludes.h │ ├── ssl │ │ ├── cert.h │ │ └── private_key.h │ ├── user_config.h │ ├── user_devicefind.h │ ├── user_esp_platform.h │ ├── user_esp_platform_timer.h │ ├── user_iot_version.h │ ├── user_json.h │ ├── user_light.h │ ├── user_plug.h │ ├── user_sensor.h │ └── user_webserver.h ├── readme.txt └── user │ ├── user_devicefind.c │ ├── user_esp_platform.c │ ├── user_esp_platform_timer.c │ ├── user_json.c │ ├── user_light.c │ ├── user_main.c │ ├── user_plug.c │ ├── user_sensor.c │ └── user_webserver.c └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /IR_RemoteC/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | mingw32-make.exe 74 | -f ${ProjDirPath}/Makefile 75 | all 76 | true 77 | true 78 | true 79 | 80 | 81 | mingw32-make.exe 82 | -f ${ProjDirPath}/Makefile 83 | clean 84 | true 85 | true 86 | true 87 | 88 | 89 | mingw32-make.exe 90 | -f ${ProjDirPath}/Makefile 91 | flash 92 | true 93 | true 94 | true 95 | 96 | 97 | mingw32-make.exe 98 | -f ${ProjDirPath}/Makefile 99 | flashonefile 100 | true 101 | true 102 | true 103 | 104 | 105 | mingw32-make.exe 106 | -f ${ProjDirPath}/Makefile 107 | flashinit 108 | true 109 | true 110 | true 111 | 112 | 113 | mingw32-make.exe 114 | -f ${ProjDirPath}/Makefile 115 | flashboot 116 | true 117 | true 118 | true 119 | 120 | 121 | mingw32-make.exe 122 | -f ${ProjDirPath}/Makefile 123 | rebuild 124 | true 125 | true 126 | true 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /IR_RemoteC/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | IR_Remote 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /IR_RemoteC/.settings/org.eclipse.cdt.codan.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.cdt.codan.checkers.errnoreturn=Warning 3 | org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false} 4 | org.eclipse.cdt.codan.checkers.errreturnvalue=Error 5 | org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 6 | org.eclipse.cdt.codan.checkers.noreturn=Error 7 | org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false} 8 | org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error 9 | org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 10 | org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error 11 | org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 12 | org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning 13 | org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 14 | org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error 15 | org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 16 | org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning 17 | org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},no_break_comment\=>"no break",last_case_param\=>false,empty_case_param\=>false} 18 | org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning 19 | org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},unknown\=>false,exceptions\=>()} 20 | org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error 21 | org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 22 | org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning 23 | org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},skip\=>true} 24 | org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error 25 | org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 26 | org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error 27 | org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 28 | org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error 29 | org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 30 | org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error 31 | org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 32 | org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error 33 | org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 34 | org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error 35 | org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 36 | org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error 37 | org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 38 | org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info 39 | org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},pattern\=>"^[a-z]",macro\=>true,exceptions\=>()} 40 | org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning 41 | org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 42 | org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error 43 | org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 44 | org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error 45 | org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 46 | org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error 47 | org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 48 | org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=-Warning 49 | org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 50 | org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning 51 | org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 52 | org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning 53 | org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>()} 54 | org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning 55 | org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},paramNot\=>false} 56 | org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning 57 | org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},else\=>false,afterelse\=>false} 58 | org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error 59 | org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 60 | org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning 61 | org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true} 62 | org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning 63 | org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true} 64 | org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning 65 | org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>("@(\#)","$Id")} 66 | org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error 67 | org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} 68 | -------------------------------------------------------------------------------- /IR_RemoteC/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # 3 | # Root Level Makefile 4 | # 5 | # (c) by CHERTS 6 | # 7 | ############################################################# 8 | 9 | BUILD_BASE = build 10 | FW_BASE = firmware 11 | 12 | # Base directory for the compiler 13 | XTENSA_TOOLS_ROOT ?= c:/Espressif/xtensa-lx106-elf/bin 14 | 15 | # base directory of the ESP8266 SDK package, absolute 16 | SDK_BASE ?= c:/Espressif/ESP8266_SDK 17 | 18 | # esptool path and port 19 | SDK_TOOLS ?= c:/Espressif/utils 20 | ESPTOOL ?= $(SDK_TOOLS)/esptool.exe 21 | ESPPORT ?= COM6 22 | 23 | # BOOT = none 24 | # BOOT = old - boot_v1.1 25 | # BOOT = new - boot_v1.3+ 26 | BOOT?=none 27 | # APP = 0 - eagle.flash.bin + eagle.irom0text.bin 28 | # APP = 1 - user1.bin 29 | # APP = 2 - user2.bin 30 | APP?=0 31 | # SPI_SPEED = 20MHz, 26.7MHz, 40MHz, 80MHz 32 | SPI_SPEED?=40 33 | # SPI_MODE: QIO, QOUT, DIO, DOUT 34 | SPI_MODE?=QIO 35 | # SPI_SIZE: 256KB, 512KB, 1024KB, 2048KB, 4096KB 36 | SPI_SIZE?=512 37 | 38 | ifeq ($(BOOT), new) 39 | boot = new 40 | else 41 | ifeq ($(BOOT), old) 42 | boot = old 43 | else 44 | boot = none 45 | endif 46 | endif 47 | 48 | ifeq ($(APP), 1) 49 | app = 1 50 | else 51 | ifeq ($(APP), 2) 52 | app = 2 53 | else 54 | app = 0 55 | endif 56 | endif 57 | 58 | ifeq ($(SPI_SPEED), 26.7) 59 | freqdiv = 1 60 | flashimageoptions = -ff 26m 61 | else 62 | ifeq ($(SPI_SPEED), 20) 63 | freqdiv = 2 64 | flashimageoptions = -ff 20m 65 | else 66 | ifeq ($(SPI_SPEED), 80) 67 | freqdiv = 15 68 | flashimageoptions = -ff 80m 69 | else 70 | freqdiv = 0 71 | flashimageoptions = -ff 40m 72 | endif 73 | endif 74 | endif 75 | 76 | ifeq ($(SPI_MODE), QOUT) 77 | mode = 1 78 | flashimageoptions += -fm qout 79 | else 80 | ifeq ($(SPI_MODE), DIO) 81 | mode = 2 82 | flashimageoptions += -fm dio 83 | else 84 | ifeq ($(SPI_MODE), DOUT) 85 | mode = 3 86 | flashimageoptions += -fm dout 87 | else 88 | mode = 0 89 | flashimageoptions += -fm qio 90 | endif 91 | endif 92 | endif 93 | 94 | # flash larger than 1024KB only use 1024KB to storage user1.bin and user2.bin 95 | ifeq ($(SPI_SIZE), 256) 96 | size = 1 97 | flash = 256 98 | flashimageoptions += -fs 2m 99 | else 100 | ifeq ($(SPI_SIZE), 1024) 101 | size = 2 102 | flash = 1024 103 | flashimageoptions += -fs 8m 104 | else 105 | ifeq ($(SPI_SIZE), 2048) 106 | size = 3 107 | flash = 1024 108 | flashimageoptions += -fs 16m 109 | else 110 | ifeq ($(SPI_SIZE), 4096) 111 | size = 4 112 | flash = 1024 113 | flashimageoptions += -fs 32m 114 | else 115 | size = 0 116 | flash = 512 117 | flashimageoptions += -fs 4m 118 | endif 119 | endif 120 | endif 121 | endif 122 | 123 | ifeq ($(flash), 512) 124 | ifeq ($(app), 1) 125 | addr = 0x01000 126 | else 127 | ifeq ($(app), 2) 128 | addr = 0x41000 129 | endif 130 | endif 131 | else 132 | ifeq ($(flash), 1024) 133 | ifeq ($(app), 1) 134 | addr = 0x01000 135 | else 136 | ifeq ($(app), 2) 137 | addr = 0x81000 138 | endif 139 | endif 140 | endif 141 | endif 142 | 143 | # name for the target project 144 | TARGET = app 145 | 146 | # which modules (subdirectories) of the project to include in compiling 147 | MODULES = driver user 148 | EXTRA_INCDIR = include $(SDK_BASE)/../include 149 | 150 | # libraries used in this project, mainly provided by the SDK 151 | LIBS = c gcc hal phy pp net80211 lwip wpa pwm main json upgrade 152 | 153 | # compiler flags using during compilation of source files 154 | CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH 155 | CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions 156 | 157 | # linker flags used to generate the main object file 158 | LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static 159 | 160 | # linker script used for the above linkier step 161 | LD_SCRIPT = eagle.app.v6.ld 162 | 163 | ifneq ($(boot), none) 164 | ifneq ($(app),0) 165 | LD_SCRIPT = eagle.app.v6.$(boot).$(flash).app$(app).ld 166 | BIN_NAME = user$(app).$(flash).$(boot) 167 | endif 168 | else 169 | app = 0 170 | endif 171 | 172 | # various paths from the SDK used in this project 173 | SDK_LIBDIR = lib 174 | SDK_LDDIR = ld 175 | SDK_INCDIR = include include/json 176 | 177 | # select which tools to use as compiler, librarian and linker 178 | CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc 179 | CXX := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-g++ 180 | AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar 181 | LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc 182 | OBJCOPY := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objcopy 183 | OBJDUMP := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objdump 184 | 185 | # no user configurable options below here 186 | SRC_DIR := $(MODULES) 187 | BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) 188 | 189 | SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR)) 190 | SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR)) 191 | 192 | SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c*)) 193 | #SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) 194 | C_OBJ := $(patsubst %.c,%.o,$(SRC)) 195 | CXX_OBJ := $(patsubst %.cpp,%.o,$(C_OBJ)) 196 | OBJ := $(patsubst %.o,$(BUILD_BASE)/%.o,$(CXX_OBJ)) 197 | #OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) 198 | LIBS := $(addprefix -l,$(LIBS)) 199 | APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a) 200 | TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out) 201 | 202 | LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT)) 203 | 204 | INCDIR := $(addprefix -I,$(SRC_DIR)) 205 | EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) 206 | MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) 207 | 208 | FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1).bin) 209 | FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2).bin) 210 | 211 | V ?= $(VERBOSE) 212 | ifeq ("$(V)","1") 213 | Q := 214 | vecho := @true 215 | else 216 | Q := @ 217 | vecho := @echo 218 | endif 219 | 220 | vpath %.c $(SRC_DIR) 221 | vpath %.cpp $(SRC_DIR) 222 | 223 | define compile-objects 224 | $1/%.o: %.c 225 | $(vecho) "CC $$<" 226 | $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ 227 | $1/%.o: %.cpp 228 | $(vecho) "C+ $$<" 229 | $(Q) $(CXX) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CXXFLAGS) -c $$< -o $$@ 230 | endef 231 | 232 | .PHONY: all checkdirs clean 233 | 234 | all: checkdirs $(TARGET_OUT) 235 | 236 | $(TARGET_OUT): $(APP_AR) 237 | $(vecho) "LD $@" 238 | $(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@ 239 | $(vecho) "------------------------------------------------------------------------------" 240 | $(vecho) "Section info:" 241 | $(Q) $(OBJDUMP) -h -j .data -j .rodata -j .bss -j .text -j .irom0.text $@ 242 | $(vecho) "------------------------------------------------------------------------------" 243 | $(vecho) "Section info:" 244 | $(Q) $(SDK_TOOLS)/memanalyzer.exe $(OBJDUMP).exe $@ 245 | $(vecho) "------------------------------------------------------------------------------" 246 | $(vecho) "Run objcopy, please wait..." 247 | $(Q) $(OBJCOPY) --only-section .text -O binary $@ eagle.app.v6.text.bin 248 | $(Q) $(OBJCOPY) --only-section .data -O binary $@ eagle.app.v6.data.bin 249 | $(Q) $(OBJCOPY) --only-section .rodata -O binary $@ eagle.app.v6.rodata.bin 250 | $(Q) $(OBJCOPY) --only-section .irom0.text -O binary $@ eagle.app.v6.irom0text.bin 251 | $(vecho) "objcopy done" 252 | $(vecho) "Run gen_appbin.exe" 253 | ifeq ($(app), 0) 254 | $(Q) $(SDK_TOOLS)/gen_appbin.exe $@ 0 $(mode) $(freqdiv) $(size) 255 | $(Q) mv eagle.app.flash.bin $(FW_BASE)/eagle.flash.bin 256 | $(Q) mv eagle.app.v6.irom0text.bin $(FW_BASE)/eagle.irom0text.bin 257 | $(Q) rm eagle.app.v6.* 258 | $(vecho) "No boot needed." 259 | $(vecho) "Generate eagle.flash.bin and eagle.irom0text.bin successully in folder $(FW_BASE)." 260 | $(vecho) "eagle.flash.bin-------->0x00000" 261 | $(vecho) "eagle.irom0text.bin---->0x40000" 262 | else 263 | ifeq ($(boot), new) 264 | $(Q) $(SDK_TOOLS)/gen_appbin.exe $@ 2 $(mode) $(freqdiv) $(size) 265 | $(vecho) "Support boot_v1.3 and +" 266 | else 267 | $(Q) $(SDK_TOOLS)/gen_appbin.exe $@ 1 $(mode) $(freqdiv) $(size) 268 | $(vecho) "Support boot_v1.1 and +" 269 | endif 270 | $(Q) mv eagle.app.flash.bin $(FW_BASE)/upgrade/$(BIN_NAME).bin 271 | $(Q) rm eagle.app.v6.* 272 | $(vecho) "Generate $(BIN_NAME).bin successully in folder $(FW_BASE)/upgrade." 273 | $(vecho) "boot_v1.x.bin------->0x00000" 274 | $(vecho) "$(BIN_NAME).bin--->$(addr)" 275 | endif 276 | $(vecho) "Done" 277 | 278 | $(APP_AR): $(OBJ) 279 | $(vecho) "AR $@" 280 | $(Q) $(AR) cru $@ $^ 281 | 282 | checkdirs: $(BUILD_DIR) $(FW_BASE) 283 | 284 | $(BUILD_DIR): 285 | $(Q) mkdir -p $@ 286 | 287 | $(FW_BASE): 288 | $(Q) mkdir -p $@ 289 | $(Q) mkdir -p $@/upgrade 290 | 291 | flashonefile: all 292 | $(OBJCOPY) --only-section .text -O binary $(TARGET_OUT) eagle.app.v6.text.bin 293 | $(OBJCOPY) --only-section .data -O binary $(TARGET_OUT) eagle.app.v6.data.bin 294 | $(OBJCOPY) --only-section .rodata -O binary $(TARGET_OUT) eagle.app.v6.rodata.bin 295 | $(OBJCOPY) --only-section .irom0.text -O binary $(TARGET_OUT) eagle.app.v6.irom0text.bin 296 | $(SDK_TOOLS)/gen_appbin_old.exe $(TARGET_OUT) v6 297 | $(SDK_TOOLS)/gen_flashbin.exe eagle.app.v6.flash.bin eagle.app.v6.irom0text.bin 0x40000 298 | rm -f eagle.app.v6.data.bin 299 | rm -f eagle.app.v6.flash.bin 300 | rm -f eagle.app.v6.irom0text.bin 301 | rm -f eagle.app.v6.rodata.bin 302 | rm -f eagle.app.v6.text.bin 303 | rm -f eagle.app.sym 304 | mv eagle.app.flash.bin $(FW_BASE)/ 305 | $(vecho) "No boot needed." 306 | $(vecho) "Generate eagle.app.flash.bin successully in folder $(FW_BASE)." 307 | $(vecho) "eagle.app.flash.bin-------->0x00000" 308 | $(ESPTOOL) -p $(ESPPORT) -b 256000 write_flash $(flashimageoptions) 0x00000 $(FW_BASE)/eagle.app.flash.bin 309 | 310 | flashboot: all flashinit 311 | ifeq ($(boot), new) 312 | $(vecho) "Flash boot_v1.3 and +" 313 | $(ESPTOOL) -p $(ESPPORT) -b 256000 write_flash $(flashimageoptions) 0x00000 $(SDK_BASE)/bin/boot_v1.3\(b3\).bin 314 | endif 315 | ifeq ($(boot), old) 316 | $(vecho) "Flash boot_v1.1 and +" 317 | $(ESPTOOL) -p $(ESPPORT) -b 256000 write_flash $(flashimageoptions) 0x00000 $(SDK_BASE)/bin/boot_v1.1.bin 318 | endif 319 | ifeq ($(boot), none) 320 | $(vecho) "No boot needed." 321 | endif 322 | 323 | flash: all 324 | ifeq ($(app), 0) 325 | $(ESPTOOL) -p $(ESPPORT) -b 256000 write_flash $(flashimageoptions) 0x00000 $(FW_BASE)/eagle.flash.bin 0x40000 $(FW_BASE)/eagle.irom0text.bin 326 | else 327 | ifeq ($(boot), none) 328 | $(ESPTOOL) -p $(ESPPORT) -b 256000 write_flash $(flashimageoptions) 0x00000 $(FW_BASE)/eagle.flash.bin 0x40000 $(FW_BASE)/eagle.irom0text.bin 329 | else 330 | $(ESPTOOL) -p $(ESPPORT) -b 256000 write_flash $(flashimageoptions) $(addr) $(FW_BASE)/upgrade/$(BIN_NAME).bin 331 | endif 332 | endif 333 | 334 | flashinit: 335 | $(vecho) "Flash init data:" 336 | $(vecho) "Clear old settings (EEP area):" 337 | $(vecho) "clear_eep.bin-------->0x79000" 338 | $(vecho) "Default config (Clear SDK settings):" 339 | $(vecho) "blank.bin-------->0x7E000" 340 | $(vecho) "esp_init_data_default.bin-------->0x7C000" 341 | $(ESPTOOL) -p $(ESPPORT) write_flash $(flashimageoptions) 0x79000 $(SDK_BASE)/bin/clear_eep.bin 0x7c000 $(SDK_BASE)/bin/esp_init_data_default.bin 0x7e000 $(SDK_BASE)/bin/blank.bin 342 | 343 | rebuild: clean all 344 | 345 | clean: 346 | $(Q) rm -f $(APP_AR) 347 | $(Q) rm -f $(TARGET_OUT) 348 | $(Q) rm -rf $(BUILD_DIR) 349 | $(Q) rm -rf $(BUILD_BASE) 350 | 351 | $(Q) rm -f $(FW_FILE_1) 352 | $(Q) rm -f $(FW_FILE_2) 353 | $(Q) rm -rf $(FW_BASE) 354 | 355 | $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) 356 | -------------------------------------------------------------------------------- /IR_RemoteC/build/app.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/app.out -------------------------------------------------------------------------------- /IR_RemoteC/build/app_app.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/app_app.a -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/EspIRremote.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/EspIRremote.o -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/dht22.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/dht22.o -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/ds18b20.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/ds18b20.o -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/gpio16.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/gpio16.o -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/i2c.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/i2c.o -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/i2c_bmp180.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/i2c_bmp180.o -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/i2c_master.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/i2c_master.o -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/key.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/key.o -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/pwm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/pwm.o -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/spi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/spi.o -------------------------------------------------------------------------------- /IR_RemoteC/build/driver/uart.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/driver/uart.o -------------------------------------------------------------------------------- /IR_RemoteC/build/user/user_devicefind.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/user/user_devicefind.o -------------------------------------------------------------------------------- /IR_RemoteC/build/user/user_esp_platform.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/user/user_esp_platform.o -------------------------------------------------------------------------------- /IR_RemoteC/build/user/user_esp_platform_timer.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/user/user_esp_platform_timer.o -------------------------------------------------------------------------------- /IR_RemoteC/build/user/user_json.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/user/user_json.o -------------------------------------------------------------------------------- /IR_RemoteC/build/user/user_light.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/user/user_light.o -------------------------------------------------------------------------------- /IR_RemoteC/build/user/user_main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/user/user_main.o -------------------------------------------------------------------------------- /IR_RemoteC/build/user/user_plug.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/user/user_plug.o -------------------------------------------------------------------------------- /IR_RemoteC/build/user/user_sensor.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/user/user_sensor.o -------------------------------------------------------------------------------- /IR_RemoteC/build/user/user_webserver.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/build/user/user_webserver.o -------------------------------------------------------------------------------- /IR_RemoteC/driver/dht22.c: -------------------------------------------------------------------------------- 1 | /* 2 | Driver for the temperature and humidity sensor DHT11 and DHT22 3 | Official repository: https://github.com/CHERTS/esp8266-dht11_22 4 | 5 | Copyright (C) 2014 Mikhail Grigorev (CHERTS) 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License along 18 | with this program; if not, write to the Free Software Foundation, Inc., 19 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | #include "ets_sys.h" 23 | #include "osapi.h" 24 | #include "c_types.h" 25 | #include "user_interface.h" 26 | #include "gpio.h" 27 | #include "driver/dht22.h" 28 | #include "driver/gpio16.h" 29 | 30 | #ifdef DHT_DEBUG 31 | #undef DHT_DEBUG 32 | #define DHT_DEBUG(...) os_printf(__VA_ARGS__); 33 | #else 34 | #define DHT_DEBUG(...) 35 | #endif 36 | 37 | #define sleepms(x) os_delay_us(x*1000); 38 | extern uint8_t pin_num[GPIO_PIN_NUM]; 39 | 40 | static inline float scale_humidity(DHTType sensor_type, int *data) 41 | { 42 | if(sensor_type == DHT11) { 43 | return (float) data[0]; 44 | } else { 45 | float humidity = data[0] * 256 + data[1]; 46 | return humidity /= 10; 47 | } 48 | } 49 | 50 | static inline float scale_temperature(DHTType sensor_type, int *data) 51 | { 52 | if(sensor_type == DHT11) { 53 | return (float) data[2]; 54 | } else { 55 | float temperature = data[2] & 0x7f; 56 | temperature *= 256; 57 | temperature += data[3]; 58 | temperature /= 10; 59 | if (data[2] & 0x80) 60 | temperature *= -1; 61 | return temperature; 62 | } 63 | } 64 | 65 | char* ICACHE_FLASH_ATTR DHTFloat2String(char* buffer, float value) 66 | { 67 | os_sprintf(buffer, "%d.%d", (int)(value),(int)((value - (int)value)*100)); 68 | return buffer; 69 | } 70 | 71 | bool ICACHE_FLASH_ATTR DHTRead(DHT_Sensor *sensor, DHT_Sensor_Data* output) 72 | { 73 | int counter = 0; 74 | int laststate = 1; 75 | int i = 0; 76 | int j = 0; 77 | int checksum = 0; 78 | int data[100]; 79 | data[0] = data[1] = data[2] = data[3] = data[4] = 0; 80 | uint8_t pin = pin_num[sensor->pin]; 81 | 82 | // Wake up device, 250ms of high 83 | GPIO_OUTPUT_SET(pin, 1); 84 | sleepms(250); 85 | // Hold low for 20ms 86 | GPIO_OUTPUT_SET(pin, 0); 87 | sleepms(20); 88 | // High for 40ns 89 | GPIO_OUTPUT_SET(pin, 1); 90 | os_delay_us(40); 91 | // Set DHT_PIN pin as an input 92 | GPIO_DIS_OUTPUT(pin); 93 | 94 | // wait for pin to drop? 95 | while (GPIO_INPUT_GET(pin) == 1 && i < DHT_MAXCOUNT) { 96 | os_delay_us(1); 97 | i++; 98 | } 99 | 100 | if(i == DHT_MAXCOUNT) 101 | { 102 | DHT_DEBUG("DHT: Failed to get reading from GPIO%d, dying\r\n", pin); 103 | return false; 104 | } 105 | 106 | // read data 107 | for (i = 0; i < DHT_MAXTIMINGS; i++) 108 | { 109 | // Count high time (in approx us) 110 | counter = 0; 111 | while (GPIO_INPUT_GET(pin) == laststate) 112 | { 113 | counter++; 114 | os_delay_us(1); 115 | if (counter == 1000) 116 | break; 117 | } 118 | laststate = GPIO_INPUT_GET(pin); 119 | if (counter == 1000) 120 | break; 121 | // store data after 3 reads 122 | if ((i>3) && (i%2 == 0)) { 123 | // shove each bit into the storage bytes 124 | data[j/8] <<= 1; 125 | if (counter > DHT_BREAKTIME) 126 | data[j/8] |= 1; 127 | j++; 128 | } 129 | } 130 | 131 | if (j >= 39) { 132 | checksum = (data[0] + data[1] + data[2] + data[3]) & 0xFF; 133 | DHT_DEBUG("DHT%s: %02x %02x %02x %02x [%02x] CS: %02x (GPIO%d)\r\n", 134 | sensor->type==DHT11?"11":"22", 135 | data[0], data[1], data[2], data[3], data[4], checksum, pin); 136 | if (data[4] == checksum) { 137 | // checksum is valid 138 | output->temperature = scale_temperature(sensor->type, data); 139 | output->humidity = scale_humidity(sensor->type, data); 140 | //DHT_DEBUG("DHT: Temperature = %d *C, Humidity = %d %%\r\n", (int)(reading.temperature * 100), (int)(reading.humidity * 100)); 141 | DHT_DEBUG("DHT: Temperature*100 = %d *C, Humidity*100 = %d %% (GPIO%d)\n", 142 | (int) (output->temperature * 100), (int) (output->humidity * 100), pin); 143 | } else { 144 | //DHT_DEBUG("Checksum was incorrect after %d bits. Expected %d but got %d\r\n", j, data[4], checksum); 145 | DHT_DEBUG("DHT: Checksum was incorrect after %d bits. Expected %d but got %d (GPIO%d)\r\n", 146 | j, data[4], checksum, pin); 147 | return false; 148 | } 149 | } else { 150 | //DHT_DEBUG("Got too few bits: %d should be at least 40\r\n", j); 151 | DHT_DEBUG("DHT: Got too few bits: %d should be at least 40 (GPIO%d)\r\n", j, pin); 152 | return false; 153 | } 154 | return true; 155 | } 156 | 157 | 158 | bool ICACHE_FLASH_ATTR DHTInit(DHT_Sensor *sensor) 159 | { 160 | if (set_gpio_mode(sensor->pin, GPIO_PULLUP, GPIO_INPUT)) { 161 | DHT_DEBUG("DHT: Setup for type %s connected to GPIO%d\n", sensor->type==DHT11?"DHT11":"DHT22", pin_num[sensor->pin]); 162 | return true; 163 | } else { 164 | DHT_DEBUG("DHT: Error in function set_gpio_mode for type %s connected to GPIO%d\n", sensor->type==DHT11?"DHT11":"DHT22", pin_num[sensor->pin]); 165 | return false; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /IR_RemoteC/driver/ds18b20.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Adaptation of Paul Stoffregen's One wire library to the ESP8266 and 3 | * 4 | * Fixed Mikhail Grigorev 5 | * 6 | * Paul's original library site: 7 | * http://www.pjrc.com/teensy/td_libs_OneWire.html 8 | * 9 | * See also http://playground.arduino.cc/Learning/OneWire 10 | * 11 | */ 12 | 13 | #include "ets_sys.h" 14 | #include "os_type.h" 15 | #include "mem.h" 16 | #include "osapi.h" 17 | #include "user_interface.h" 18 | 19 | #include "espconn.h" 20 | #include "gpio.h" 21 | #include "driver/ds18b20.h" 22 | 23 | // global search state 24 | static unsigned char address[8]; 25 | static uint8_t LastDiscrepancy; 26 | static uint8_t LastFamilyDiscrepancy; 27 | static uint8_t LastDeviceFlag; 28 | 29 | void ICACHE_FLASH_ATTR ds_init() 30 | { 31 | // Set DS18B20_PIN as gpio pin 32 | PIN_FUNC_SELECT(DS18B20_MUX, DS18B20_FUNC); 33 | // Disable pull-down 34 | //PIN_PULLDWN_DIS(DS18B20_MUX); 35 | // Enable pull-up 36 | PIN_PULLUP_EN(DS18B20_MUX); 37 | // Set DS18B20_PIN pin as an input 38 | GPIO_DIS_OUTPUT(DS18B20_PIN); 39 | reset_search(); 40 | } 41 | 42 | /* pass array of 8 bytes in */ 43 | int ICACHE_FLASH_ATTR ds_search(uint8_t *newAddr) 44 | { 45 | uint8_t id_bit_number; 46 | uint8_t last_zero, rom_byte_number; 47 | uint8_t id_bit, cmp_id_bit; 48 | int search_result; 49 | int i; 50 | 51 | unsigned char rom_byte_mask, search_direction; 52 | 53 | // initialize for search 54 | id_bit_number = 1; 55 | last_zero = 0; 56 | rom_byte_number = 0; 57 | rom_byte_mask = 1; 58 | search_result = 0; 59 | 60 | // if the last call was not the last one 61 | if (!LastDeviceFlag) 62 | { 63 | // 1-Wire reset 64 | if (!ds_reset()) 65 | { 66 | // reset the search 67 | LastDiscrepancy = 0; 68 | LastDeviceFlag = FALSE; 69 | LastFamilyDiscrepancy = 0; 70 | return FALSE; 71 | } 72 | 73 | // issue the search command 74 | ds_write(DS1820_SEARCHROM, 0); 75 | 76 | // loop to do the search 77 | do 78 | { 79 | // read a bit and its complement 80 | id_bit = read_bit(); 81 | cmp_id_bit = read_bit(); 82 | 83 | // check for no devices on 1-wire 84 | if ((id_bit == 1) && (cmp_id_bit == 1)) 85 | break; 86 | else 87 | { 88 | // all devices coupled have 0 or 1 89 | if (id_bit != cmp_id_bit) 90 | search_direction = id_bit; // bit write value for search 91 | else 92 | { 93 | // if this discrepancy if before the Last Discrepancy 94 | // on a previous next then pick the same as last time 95 | if (id_bit_number < LastDiscrepancy) 96 | search_direction = ((address[rom_byte_number] & rom_byte_mask) > 0); 97 | else 98 | // if equal to last pick 1, if not then pick 0 99 | search_direction = (id_bit_number == LastDiscrepancy); 100 | 101 | // if 0 was picked then record its position in LastZero 102 | if (search_direction == 0) 103 | { 104 | last_zero = id_bit_number; 105 | 106 | // check for Last discrepancy in family 107 | if (last_zero < 9) 108 | LastFamilyDiscrepancy = last_zero; 109 | } 110 | } 111 | 112 | // set or clear the bit in the ROM byte rom_byte_number 113 | // with mask rom_byte_mask 114 | if (search_direction == 1) 115 | address[rom_byte_number] |= rom_byte_mask; 116 | else 117 | address[rom_byte_number] &= ~rom_byte_mask; 118 | 119 | // serial number search direction write bit 120 | write_bit(search_direction); 121 | 122 | // increment the byte counter id_bit_number 123 | // and shift the mask rom_byte_mask 124 | id_bit_number++; 125 | rom_byte_mask <<= 1; 126 | 127 | // if the mask is 0 then go to new SerialNum byte rom_byte_number and reset mask 128 | if (rom_byte_mask == 0) 129 | { 130 | rom_byte_number++; 131 | rom_byte_mask = 1; 132 | } 133 | } 134 | } 135 | while(rom_byte_number < 8); // loop until through all ROM bytes 0-7 136 | 137 | // if the search was successful then 138 | if (!(id_bit_number < 65)) 139 | { 140 | // search successful so set LastDiscrepancy,LastDeviceFlag,search_result 141 | LastDiscrepancy = last_zero; 142 | 143 | // check for last device 144 | if (LastDiscrepancy == 0) 145 | LastDeviceFlag = TRUE; 146 | 147 | search_result = TRUE; 148 | } 149 | } 150 | 151 | // if no device found then reset counters so next 'search' will be like a first 152 | if (!search_result || !address[0]) 153 | { 154 | LastDiscrepancy = 0; 155 | LastDeviceFlag = FALSE; 156 | LastFamilyDiscrepancy = 0; 157 | search_result = FALSE; 158 | } 159 | for (i = 0; i < 8; i++) newAddr[i] = address[i]; 160 | return search_result; 161 | } 162 | 163 | // 164 | // Do a ROM select 165 | // 166 | void ICACHE_FLASH_ATTR select(const uint8_t *rom) 167 | { 168 | uint8_t i; 169 | ds_write(DS1820_MATCHROM, 0); // Choose ROM 170 | for (i = 0; i < 8; i++) ds_write(rom[i], 0); 171 | } 172 | 173 | // 174 | // Do a ROM skip 175 | // 176 | void ICACHE_FLASH_ATTR skip() 177 | { 178 | ds_write(DS1820_SKIP_ROM,0); // Skip ROM 179 | } 180 | 181 | void ICACHE_FLASH_ATTR reset_search() 182 | { 183 | int i; 184 | // reset the search state 185 | LastDiscrepancy = 0; 186 | LastDeviceFlag = FALSE; 187 | LastFamilyDiscrepancy = 0; 188 | for(i = 7; ; i--) { 189 | address[i] = 0; 190 | if ( i == 0) break; 191 | } 192 | } 193 | 194 | // Perform the onewire reset function. We will wait up to 250uS for 195 | // the bus to come high, if it doesn't then it is broken or shorted 196 | // and we return a 0; 197 | // Returns 1 if a device asserted a presence pulse, 0 otherwise. 198 | uint8_t ICACHE_FLASH_ATTR ds_reset(void) 199 | { 200 | int r; 201 | uint8_t retries = 125; 202 | GPIO_DIS_OUTPUT(DS18B20_PIN); 203 | do { 204 | if (--retries == 0) return 0; 205 | os_delay_us(2); 206 | } while ( !GPIO_INPUT_GET(DS18B20_PIN)); 207 | GPIO_OUTPUT_SET(DS18B20_PIN, 0); 208 | os_delay_us(500); 209 | GPIO_DIS_OUTPUT(DS18B20_PIN); 210 | os_delay_us(65); 211 | r = !GPIO_INPUT_GET(DS18B20_PIN); 212 | os_delay_us(490); 213 | return r; 214 | } 215 | 216 | // 217 | // Write a byte. The writing code uses the active drivers to raise the 218 | // pin high, if you need power after the write (e.g. DS18S20 in 219 | // parasite power mode) then set 'power' to 1, otherwise the pin will 220 | // go tri-state at the end of the write to avoid heating in a short or 221 | // other mishap. 222 | // 223 | void ICACHE_FLASH_ATTR ds_write(uint8_t v, int power) 224 | { 225 | uint8_t bitMask; 226 | for (bitMask = 0x01; bitMask; bitMask <<= 1) { 227 | write_bit((bitMask & v)?1:0); 228 | } 229 | if (!power) { 230 | GPIO_DIS_OUTPUT(DS18B20_PIN); 231 | GPIO_OUTPUT_SET(DS18B20_PIN, 0); 232 | } 233 | } 234 | 235 | // 236 | // Write a bit. Port and bit is used to cut lookup time and provide 237 | // more certain timing. 238 | // 239 | void ICACHE_FLASH_ATTR write_bit(int v) 240 | { 241 | GPIO_OUTPUT_SET(DS18B20_PIN, 0); 242 | if(v) { 243 | os_delay_us(10); 244 | GPIO_OUTPUT_SET(DS18B20_PIN, 1); 245 | os_delay_us(55); 246 | } else { 247 | os_delay_us(65); 248 | GPIO_OUTPUT_SET(DS18B20_PIN, 1); 249 | os_delay_us(5); 250 | } 251 | } 252 | 253 | // 254 | // Read a byte 255 | // 256 | uint8_t ICACHE_FLASH_ATTR ds_read() 257 | { 258 | uint8_t bitMask; 259 | uint8_t r = 0; 260 | for (bitMask = 0x01; bitMask; bitMask <<= 1) { 261 | if ( read_bit()) r |= bitMask; 262 | } 263 | return r; 264 | } 265 | 266 | // 267 | // Read a bit. Port and bit is used to cut lookup time and provide 268 | // more certain timing. 269 | // 270 | int ICACHE_FLASH_ATTR read_bit(void) 271 | { 272 | int r; 273 | GPIO_OUTPUT_SET(DS18B20_PIN, 0); 274 | os_delay_us(3); 275 | GPIO_DIS_OUTPUT(DS18B20_PIN); 276 | os_delay_us(10); 277 | r = GPIO_INPUT_GET(DS18B20_PIN); 278 | os_delay_us(53); 279 | return r; 280 | } 281 | 282 | // 283 | // Compute a Dallas Semiconductor 8 bit CRC directly. 284 | // this is much slower, but much smaller, than the lookup table. 285 | // 286 | uint8_t ICACHE_FLASH_ATTR crc8(const uint8_t *addr, uint8_t len) 287 | { 288 | uint8_t crc = 0; 289 | uint8_t i; 290 | while (len--) { 291 | uint8_t inbyte = *addr++; 292 | for (i = 8; i; i--) { 293 | uint8_t mix = (crc ^ inbyte) & 0x01; 294 | crc >>= 1; 295 | if (mix) crc ^= 0x8C; 296 | inbyte >>= 1; 297 | } 298 | } 299 | return crc; 300 | } 301 | 302 | // 303 | // Compute a Dallas Semiconductor 16 bit CRC. I have never seen one of 304 | // these, but here it is. 305 | // 306 | uint16_t ICACHE_FLASH_ATTR crc16(const uint16_t *data, const uint16_t len) 307 | { 308 | uint16_t i; 309 | uint16_t crc = 0; 310 | for ( i = 0; i < len; i++) { 311 | uint16_t cdata = data[len]; 312 | cdata = (cdata ^ (crc & 0xff)) & 0xff; 313 | crc >>= 8; 314 | if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4]) 315 | crc ^= 0xc001; 316 | cdata <<= 6; 317 | crc ^= cdata; 318 | cdata <<= 1; 319 | crc ^= cdata; 320 | } 321 | return crc; 322 | } 323 | -------------------------------------------------------------------------------- /IR_RemoteC/driver/gpio16.c: -------------------------------------------------------------------------------- 1 | /* 2 | Driver for GPIO 3 | Official repository: https://github.com/CHERTS/esp8266-gpio16 4 | 5 | Copyright (C) 2015 Mikhail Grigorev (CHERTS) 6 | 7 | Pin number: 8 | ----------- 9 | Pin 0 = GPIO16 10 | Pin 1 = GPIO5 11 | Pin 2 = GPIO4 12 | Pin 3 = GPIO0 13 | Pin 4 = GPIO2 14 | Pin 5 = GPIO14 15 | Pin 6 = GPIO12 16 | Pin 7 = GPIO13 17 | Pin 8 = GPIO15 18 | Pin 9 = GPIO3 19 | Pin 10 = GPIO1 20 | Pin 11 = GPIO9 21 | Pin 12 = GPIO10 22 | 23 | This program is free software; you can redistribute it and/or modify 24 | it under the terms of the GNU General Public License as published by 25 | the Free Software Foundation; either version 2 of the License, or 26 | (at your option) any later version. 27 | 28 | This program is distributed in the hope that it will be useful, 29 | but WITHOUT ANY WARRANTY; without even the implied warranty of 30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 31 | GNU General Public License for more details. 32 | 33 | You should have received a copy of the GNU General Public License along 34 | with this program; if not, write to the Free Software Foundation, Inc., 35 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 36 | */ 37 | 38 | #include "ets_sys.h" 39 | #include "osapi.h" 40 | #include "driver/gpio16.h" 41 | 42 | uint8_t pin_num[GPIO_PIN_NUM]; 43 | uint8_t pin_func[GPIO_PIN_NUM]; 44 | uint32_t pin_mux[GPIO_PIN_NUM]; 45 | uint32_t pin_mux[GPIO_PIN_NUM] = {PAD_XPD_DCDC_CONF, PERIPHS_IO_MUX_GPIO5_U, PERIPHS_IO_MUX_GPIO4_U, PERIPHS_IO_MUX_GPIO0_U, 46 | PERIPHS_IO_MUX_GPIO2_U, PERIPHS_IO_MUX_MTMS_U, PERIPHS_IO_MUX_MTDI_U, PERIPHS_IO_MUX_MTCK_U, 47 | PERIPHS_IO_MUX_MTDO_U, PERIPHS_IO_MUX_U0RXD_U, PERIPHS_IO_MUX_U0TXD_U, PERIPHS_IO_MUX_SD_DATA2_U, 48 | PERIPHS_IO_MUX_SD_DATA3_U }; 49 | uint8_t pin_num[GPIO_PIN_NUM] = {16, 5, 4, 0, 50 | 2, 14, 12, 13, 51 | 15, 3, 1, 9, 52 | 10}; 53 | uint8_t pin_func[GPIO_PIN_NUM] = {0, FUNC_GPIO5, FUNC_GPIO4, FUNC_GPIO0, 54 | FUNC_GPIO2, FUNC_GPIO14, FUNC_GPIO12, FUNC_GPIO13, 55 | FUNC_GPIO15, FUNC_GPIO3, FUNC_GPIO1, FUNC_GPIO9, 56 | FUNC_GPIO10}; 57 | #ifdef GPIO_INTERRUPT_ENABLE 58 | GPIO_INT_TYPE pin_int_type[GPIO_PIN_NUM] = { 59 | GPIO_PIN_INTR_DISABLE, GPIO_PIN_INTR_DISABLE, GPIO_PIN_INTR_DISABLE, GPIO_PIN_INTR_DISABLE, 60 | GPIO_PIN_INTR_DISABLE, GPIO_PIN_INTR_DISABLE, GPIO_PIN_INTR_DISABLE, GPIO_PIN_INTR_DISABLE, 61 | GPIO_PIN_INTR_DISABLE, GPIO_PIN_INTR_DISABLE, GPIO_PIN_INTR_DISABLE, GPIO_PIN_INTR_DISABLE, 62 | GPIO_PIN_INTR_DISABLE}; 63 | #endif 64 | 65 | void ICACHE_FLASH_ATTR gpio16_output_conf(void) 66 | { 67 | WRITE_PERI_REG(PAD_XPD_DCDC_CONF, 68 | (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC to output rtc_gpio0 69 | 70 | WRITE_PERI_REG(RTC_GPIO_CONF, 71 | (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable 72 | 73 | WRITE_PERI_REG(RTC_GPIO_ENABLE, 74 | (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); //out enable 75 | } 76 | 77 | void ICACHE_FLASH_ATTR gpio16_output_set(uint8 value) 78 | { 79 | WRITE_PERI_REG(RTC_GPIO_OUT, 80 | (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(value & 1)); 81 | } 82 | 83 | void ICACHE_FLASH_ATTR gpio16_input_conf(void) 84 | { 85 | WRITE_PERI_REG(PAD_XPD_DCDC_CONF, 86 | (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC and rtc_gpio0 connection 87 | 88 | WRITE_PERI_REG(RTC_GPIO_CONF, 89 | (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable 90 | 91 | WRITE_PERI_REG(RTC_GPIO_ENABLE, 92 | READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); //out disable 93 | } 94 | 95 | uint8 ICACHE_FLASH_ATTR gpio16_input_get(void) 96 | { 97 | return (uint8)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1); 98 | } 99 | 100 | int ICACHE_FLASH_ATTR set_gpio_mode(unsigned pin, unsigned mode, unsigned pull) 101 | { 102 | if (pin >= GPIO_PIN_NUM) 103 | return -1; 104 | if(pin == 0) { 105 | if(mode == GPIO_INPUT) 106 | gpio16_input_conf(); 107 | else 108 | gpio16_output_conf(); 109 | return 1; 110 | } 111 | 112 | switch(pull) { 113 | case GPIO_PULLUP: 114 | //PIN_PULLDWN_DIS(pin_mux[pin]); 115 | PIN_PULLUP_EN(pin_mux[pin]); 116 | break; 117 | case GPIO_PULLDOWN: 118 | PIN_PULLUP_DIS(pin_mux[pin]); 119 | //PIN_PULLDWN_EN(pin_mux[pin]); 120 | break; 121 | case GPIO_FLOAT: 122 | PIN_PULLUP_DIS(pin_mux[pin]); 123 | //PIN_PULLDWN_DIS(pin_mux[pin]); 124 | break; 125 | default: 126 | PIN_PULLUP_DIS(pin_mux[pin]); 127 | //PIN_PULLDWN_DIS(pin_mux[pin]); 128 | break; 129 | } 130 | 131 | switch(mode) { 132 | case GPIO_INPUT: 133 | GPIO_DIS_OUTPUT(pin_num[pin]); 134 | break; 135 | case GPIO_OUTPUT: 136 | ETS_GPIO_INTR_DISABLE(); 137 | #ifdef GPIO_INTERRUPT_ENABLE 138 | pin_int_type[pin] = GPIO_PIN_INTR_DISABLE; 139 | #endif 140 | PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]); 141 | //disable interrupt 142 | gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[pin]), GPIO_PIN_INTR_DISABLE); 143 | //clear interrupt status 144 | GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin_num[pin])); 145 | GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin])), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin]))) & (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))); //disable open drain; 146 | ETS_GPIO_INTR_ENABLE(); 147 | break; 148 | #ifdef GPIO_INTERRUPT_ENABLE 149 | case GPIO_INT: 150 | ETS_GPIO_INTR_DISABLE(); 151 | PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]); 152 | GPIO_DIS_OUTPUT(pin_num[pin]); 153 | gpio_register_set(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin])), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE) 154 | | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE) 155 | | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE)); 156 | ETS_GPIO_INTR_ENABLE(); 157 | break; 158 | #endif 159 | default: 160 | break; 161 | } 162 | return 1; 163 | } 164 | 165 | int ICACHE_FLASH_ATTR gpio_write(unsigned pin, unsigned level) 166 | { 167 | if (pin >= GPIO_PIN_NUM) 168 | return -1; 169 | if(pin == 0){ 170 | gpio16_output_conf(); 171 | gpio16_output_set(level); 172 | return 1; 173 | } 174 | GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), level); 175 | } 176 | 177 | int ICACHE_FLASH_ATTR gpio_read(unsigned pin) 178 | { 179 | if (pin >= GPIO_PIN_NUM) 180 | return -1; 181 | if(pin == 0){ 182 | // gpio16_input_conf(); 183 | return 0x1 & gpio16_input_get(); 184 | } 185 | // GPIO_DIS_OUTPUT(pin_num[pin]); 186 | return 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[pin])); 187 | } 188 | 189 | #ifdef GPIO_INTERRUPT_ENABLE 190 | void ICACHE_FLASH_ATTR gpio_intr_dispatcher(gpio_intr_handler cb) 191 | { 192 | uint8 i, level; 193 | uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); 194 | for (i = 0; i < GPIO_PIN_NUM; i++) { 195 | if (pin_int_type[i] && (gpio_status & BIT(pin_num[i])) ) { 196 | //disable global interrupt 197 | ETS_GPIO_INTR_DISABLE(); 198 | //disable interrupt 199 | gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[i]), GPIO_PIN_INTR_DISABLE); 200 | //clear interrupt status 201 | GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(pin_num[i])); 202 | level = 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[i])); 203 | if(cb){ 204 | cb(i, level); 205 | } 206 | //enable interrupt 207 | gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[i]), pin_int_type[i]); 208 | //enable global interrupt 209 | ETS_GPIO_INTR_ENABLE(); 210 | } 211 | } 212 | } 213 | 214 | void ICACHE_FLASH_ATTR gpio_intr_attach(gpio_intr_handler cb) 215 | { 216 | ETS_GPIO_INTR_ATTACH(gpio_intr_dispatcher, cb); 217 | } 218 | 219 | int ICACHE_FLASH_ATTR gpio_intr_deattach(unsigned pin) 220 | { 221 | if (pin >= GPIO_PIN_NUM) 222 | return -1; 223 | //disable global interrupt 224 | ETS_GPIO_INTR_DISABLE(); 225 | //clear interrupt status 226 | GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin_num[pin])); 227 | pin_int_type[pin] = GPIO_PIN_INTR_DISABLE; 228 | //disable interrupt 229 | gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[pin]), pin_int_type[pin]); 230 | //enable global interrupt 231 | ETS_GPIO_INTR_ENABLE(); 232 | return 1; 233 | } 234 | 235 | int ICACHE_FLASH_ATTR gpio_intr_init(unsigned pin, GPIO_INT_TYPE type) 236 | { 237 | if (pin >= GPIO_PIN_NUM) 238 | return -1; 239 | //disable global interrupt 240 | ETS_GPIO_INTR_DISABLE(); 241 | //clear interrupt status 242 | GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin_num[pin])); 243 | pin_int_type[pin] = type; 244 | //enable interrupt 245 | gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[pin]), type); 246 | //enable global interrupt 247 | ETS_GPIO_INTR_ENABLE(); 248 | return 1; 249 | } 250 | #endif 251 | -------------------------------------------------------------------------------- /IR_RemoteC/driver/i2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | I2C driver for the ESP8266 3 | Copyright (C) 2014 Rudy Hardeman (zarya) 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program; if not, write to the Free Software Foundation, Inc., 17 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | #include "ets_sys.h" 21 | #include "osapi.h" 22 | #include "gpio.h" 23 | #include "driver/i2c.h" 24 | 25 | /** 26 | * Set SDA to state 27 | */ 28 | LOCAL void ICACHE_FLASH_ATTR 29 | i2c_sda(uint8 state) 30 | { 31 | state &= 0x01; 32 | //Set SDA line to state 33 | if (state) 34 | gpio_output_set(1 << I2C_SDA_PIN, 0, 1 << I2C_SDA_PIN, 0); 35 | else 36 | gpio_output_set(0, 1 << I2C_SDA_PIN, 1 << I2C_SDA_PIN, 0); 37 | } 38 | 39 | /** 40 | * Set SCK to state 41 | */ 42 | LOCAL void ICACHE_FLASH_ATTR 43 | i2c_sck(uint8 state) 44 | { 45 | //Set SCK line to state 46 | if (state) 47 | gpio_output_set(1 << I2C_SCK_PIN, 0, 1 << I2C_SCK_PIN, 0); 48 | else 49 | gpio_output_set(0, 1 << I2C_SCK_PIN, 1 << I2C_SCK_PIN, 0); 50 | } 51 | 52 | /** 53 | * I2C init function 54 | * This sets up the GPIO io 55 | */ 56 | void ICACHE_FLASH_ATTR 57 | i2c_init(void) 58 | { 59 | //Disable interrupts 60 | ETS_GPIO_INTR_DISABLE(); 61 | 62 | //Set pin functions 63 | PIN_FUNC_SELECT(I2C_SDA_MUX, I2C_SDA_FUNC); 64 | PIN_FUNC_SELECT(I2C_SCK_MUX, I2C_SCK_FUNC); 65 | 66 | //Set SDA as open drain 67 | GPIO_REG_WRITE( 68 | GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_SDA_PIN)), 69 | GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_SDA_PIN))) | 70 | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE) 71 | ); 72 | 73 | GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_SDA_PIN)); 74 | 75 | //Set SCK as open drain 76 | GPIO_REG_WRITE( 77 | GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_SCK_PIN)), 78 | GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_SCK_PIN))) | 79 | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE) 80 | ); 81 | 82 | GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_SCK_PIN)); 83 | 84 | //Turn interrupt back on 85 | ETS_GPIO_INTR_ENABLE(); 86 | 87 | i2c_sda(1); 88 | i2c_sck(1); 89 | return; 90 | } 91 | 92 | /** 93 | * I2C Start signal 94 | */ 95 | void ICACHE_FLASH_ATTR 96 | i2c_start(void) 97 | { 98 | i2c_sda(1); 99 | i2c_sck(1); 100 | os_delay_us(I2C_SLEEP_TIME); 101 | i2c_sda(0); 102 | os_delay_us(I2C_SLEEP_TIME); 103 | i2c_sck(0); 104 | os_delay_us(I2C_SLEEP_TIME); 105 | } 106 | 107 | /** 108 | * I2C Stop signal 109 | */ 110 | void ICACHE_FLASH_ATTR 111 | i2c_stop(void) 112 | { 113 | os_delay_us(I2C_SLEEP_TIME); 114 | i2c_sck(1); 115 | os_delay_us(I2C_SLEEP_TIME); 116 | i2c_sda(1); 117 | os_delay_us(I2C_SLEEP_TIME); 118 | } 119 | 120 | /** 121 | * Send I2C ACK to the bus 122 | * uint8 state 1 or 0 123 | * 1 for ACK 124 | * 0 for NACK 125 | */ 126 | void ICACHE_FLASH_ATTR 127 | i2c_send_ack(uint8 state) 128 | { 129 | i2c_sck(0); 130 | os_delay_us(I2C_SLEEP_TIME); 131 | //Set SDA 132 | // HIGH for NACK 133 | // LOW for ACK 134 | i2c_sda((state?0:1)); 135 | 136 | //Pulse the SCK 137 | i2c_sck(0); 138 | os_delay_us(I2C_SLEEP_TIME); 139 | i2c_sck(1); 140 | os_delay_us(I2C_SLEEP_TIME); 141 | i2c_sck(0); 142 | os_delay_us(I2C_SLEEP_TIME); 143 | 144 | i2c_sda(1); 145 | os_delay_us(I2C_SLEEP_TIME); 146 | } 147 | 148 | /** 149 | * Receive I2C ACK from the bus 150 | * returns 1 or 0 151 | * 1 for ACK 152 | * 0 for NACK 153 | */ 154 | uint8 ICACHE_FLASH_ATTR 155 | i2c_check_ack(void) 156 | { 157 | uint8 ack; 158 | i2c_sda(1); 159 | os_delay_us(I2C_SLEEP_TIME); 160 | i2c_sck(0); 161 | os_delay_us(I2C_SLEEP_TIME); 162 | i2c_sck(1); 163 | os_delay_us(I2C_SLEEP_TIME); 164 | 165 | //Get SDA pin status 166 | ack = i2c_read(); 167 | 168 | os_delay_us(I2C_SLEEP_TIME); 169 | i2c_sck(0); 170 | os_delay_us(I2C_SLEEP_TIME); 171 | i2c_sda(0); 172 | os_delay_us(I2C_SLEEP_TIME); 173 | 174 | return (ack?0:1); 175 | } 176 | 177 | /** 178 | * Receive byte from the I2C bus 179 | * returns the byte 180 | */ 181 | uint8 ICACHE_FLASH_ATTR 182 | i2c_readByte(void) 183 | { 184 | uint8 data = 0; 185 | uint8 data_bit; 186 | uint8 i; 187 | 188 | i2c_sda(1); 189 | 190 | for (i = 0; i < 8; i++) 191 | { 192 | os_delay_us(I2C_SLEEP_TIME); 193 | i2c_sck(0); 194 | os_delay_us(I2C_SLEEP_TIME); 195 | 196 | i2c_sck(1); 197 | os_delay_us(I2C_SLEEP_TIME); 198 | 199 | data_bit = i2c_read(); 200 | os_delay_us(I2C_SLEEP_TIME); 201 | 202 | data_bit <<= (7 - i); 203 | data |= data_bit; 204 | } 205 | i2c_sck(0); 206 | os_delay_us(I2C_SLEEP_TIME); 207 | 208 | return data; 209 | } 210 | 211 | /** 212 | * Write byte to I2C bus 213 | * uint8 data: to byte to be writen 214 | */ 215 | void ICACHE_FLASH_ATTR 216 | i2c_writeByte(uint8 data) 217 | { 218 | uint8 data_bit; 219 | sint8 i; 220 | 221 | os_delay_us(I2C_SLEEP_TIME); 222 | 223 | for (i = 7; i >= 0; i--) { 224 | data_bit = data >> i; 225 | i2c_sda(data_bit); 226 | os_delay_us(I2C_SLEEP_TIME); 227 | i2c_sck(1); 228 | os_delay_us(I2C_SLEEP_TIME); 229 | i2c_sck(0); 230 | os_delay_us(I2C_SLEEP_TIME); 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /IR_RemoteC/driver/i2c_bmp180.c: -------------------------------------------------------------------------------- 1 | /* 2 | The driver for the temperature sensor and pressure BMP180 3 | Official repository: https://github.com/CHERTS/esp8266-i2c_bmp180 4 | Base on https://github.com/reaper7/esp8266_i2c_bmp180 5 | This driver depends on the I2C driver https://github.com/zarya/esp8266_i2c_driver/ 6 | 7 | Copyright (C) 2014 reaper7 8 | Copyright (C) 2014 Mikhail Grigorev (CHERTS) 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License along 21 | with this program; if not, write to the Free Software Foundation, Inc., 22 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | 25 | #include 26 | #include "driver/i2c.h" 27 | #include "driver/i2c_bmp180.h" 28 | 29 | int16_t ac1, ac2, ac3; 30 | uint16_t ac4, ac5, ac6; 31 | int16_t b1, b2; 32 | int16_t mb, mc, md; 33 | 34 | int16_t ICACHE_FLASH_ATTR BMP180_readRegister16(uint8_t reg) 35 | { 36 | i2c_start(); 37 | i2c_writeByte(BMP180_W); 38 | if(!i2c_check_ack()){ 39 | #ifdef BMP180_DEBUG 40 | //os_printf("slave not ack..\n return \n"); 41 | ets_uart_printf("BMP180_readRegister16: i2c_writeByte(0xEE) slave not ack..\r\nreturn\r\n"); 42 | #endif 43 | i2c_stop(); 44 | return(0); 45 | } 46 | i2c_writeByte(reg); 47 | if(!i2c_check_ack()){ 48 | #ifdef BMP180_DEBUG 49 | //os_printf("slave not ack..\n return \n"); 50 | ets_uart_printf("BMP180_readRegister16: i2c_writeByte(reg) slave not ack..\r\nreturn\r\n"); 51 | #endif 52 | i2c_stop(); 53 | return(0); 54 | } 55 | i2c_start(); 56 | i2c_writeByte(BMP180_R); 57 | if(!i2c_check_ack()){ 58 | #ifdef BMP180_DEBUG 59 | //os_printf("slave not ack..\n return \n"); 60 | ets_uart_printf("BMP180_readRegister16: i2c_writeByte(0xEF) slave not ack..\r\nreturn\r\n"); 61 | #endif 62 | i2c_stop(); 63 | return(0); 64 | } 65 | uint8_t msb = i2c_readByte(); 66 | i2c_send_ack(1); 67 | uint8_t lsb = i2c_readByte(); 68 | i2c_send_ack(0); 69 | i2c_stop(); 70 | int16_t res = (msb << 8) + lsb; 71 | return res; 72 | } 73 | 74 | int16_t ICACHE_FLASH_ATTR BMP180_readExRegister16(uint8_t reg, enum PRESSURE_RESOLUTION resolution) 75 | { 76 | i2c_start(); 77 | i2c_writeByte(BMP180_W); 78 | if(!i2c_check_ack()){ 79 | #ifdef BMP180_DEBUG 80 | //os_printf("slave not ack..\n return \n"); 81 | ets_uart_printf("BMP180_readExRegister16: i2c_writeByte(0xEE) slave not ack..\r\nreturn\r\n"); 82 | #endif 83 | i2c_stop(); 84 | return(0); 85 | } 86 | i2c_writeByte(reg); 87 | if(!i2c_check_ack()){ 88 | #ifdef BMP180_DEBUG 89 | //os_printf("slave not ack..\n return \n"); 90 | ets_uart_printf("BMP180_readExRegister16: i2c_writeByte(reg) slave not ack..\r\nreturn\r\n"); 91 | #endif 92 | i2c_stop(); 93 | return(0); 94 | } 95 | i2c_start(); 96 | i2c_writeByte(BMP180_R); 97 | if(!i2c_check_ack()){ 98 | #ifdef BMP180_DEBUG 99 | //os_printf("slave not ack..\n return \n"); 100 | ets_uart_printf("BMP180_readExRegister16: i2c_writeByte(0xEF) slave not ack..\r\nreturn\r\n"); 101 | #endif 102 | i2c_stop(); 103 | return(0); 104 | } 105 | uint8_t msb = i2c_readByte(); 106 | i2c_send_ack(1); 107 | uint8_t lsb = i2c_readByte(); 108 | i2c_send_ack(0); 109 | uint8_t xlsb = i2c_readByte(); 110 | i2c_send_ack(0); 111 | i2c_stop(); 112 | int32_t res = ((msb << 16) + (lsb << 8) + xlsb) >> (8-resolution); 113 | return res; 114 | } 115 | 116 | int16_t ICACHE_FLASH_ATTR BMP180_readRawValue(uint8_t cmd) 117 | { 118 | i2c_start(); 119 | i2c_writeByte(BMP180_W); 120 | if(!i2c_check_ack()){ 121 | #ifdef BMP180_DEBUG 122 | //os_printf("slave not ack..\n return \n"); 123 | ets_uart_printf("BMP180_readRawValue: i2c_writeByte(0xEE) slave not ack..\r\nreturn\r\n"); 124 | #endif 125 | i2c_stop(); 126 | return(0); 127 | } 128 | i2c_writeByte(BMP180_CTRL_REG); 129 | if(!i2c_check_ack()){ 130 | #ifdef BMP180_DEBUG 131 | //os_printf("slave not ack..\n return \n"); 132 | ets_uart_printf("BMP180_readRawValue: i2c_writeByte(0xF4) slave not ack..\r\nreturn\r\n"); 133 | #endif 134 | i2c_stop(); 135 | return(0); 136 | } 137 | i2c_writeByte(cmd); 138 | if(!i2c_check_ack()){ 139 | #ifdef BMP180_DEBUG 140 | //os_printf("slave not ack..\n return \n"); 141 | ets_uart_printf("BMP180_readRawValue: i2c_writeByte(cmd) slave not ack..\r\nreturn\r\n"); 142 | #endif 143 | i2c_stop(); 144 | return(0); 145 | } 146 | i2c_stop(); 147 | os_delay_us(CONVERSION_TIME*900); // max time is 4.5ms 148 | int16_t res = BMP180_readRegister16(BMP180_DATA_REG); 149 | return res; 150 | } 151 | 152 | int16_t ICACHE_FLASH_ATTR BMP180_readExRawValue(uint8_t cmd, enum PRESSURE_RESOLUTION resolution) 153 | { 154 | i2c_start(); 155 | i2c_writeByte(BMP180_W); 156 | if(!i2c_check_ack()){ 157 | #ifdef BMP180_DEBUG 158 | //os_printf("slave not ack..\n return \n"); 159 | ets_uart_printf("BMP180_readExRawValue: i2c_writeByte(0xEE) slave not ack..\r\nreturn\r\n"); 160 | #endif 161 | i2c_stop(); 162 | return(0); 163 | } 164 | i2c_writeByte(BMP180_CTRL_REG); 165 | if(!i2c_check_ack()){ 166 | #ifdef BMP180_DEBUG 167 | //os_printf("slave not ack..\n return \n"); 168 | ets_uart_printf("BMP180_readExRawValue: i2c_writeByte(0xF4) slave not ack..\r\nreturn\r\n"); 169 | #endif 170 | i2c_stop(); 171 | return(0); 172 | } 173 | i2c_writeByte(cmd); 174 | if(!i2c_check_ack()){ 175 | #ifdef BMP180_DEBUG 176 | //os_printf("slave not ack..\n return \n"); 177 | ets_uart_printf("BMP180_readExRawValue: i2c_writeByte(cmd) slave not ack..\r\nreturn\r\n"); 178 | #endif 179 | i2c_stop(); 180 | return(0); 181 | } 182 | i2c_stop(); 183 | switch(resolution) 184 | { 185 | case OSS_0: 186 | os_delay_us(CONVERSION_TIME*900); 187 | break; 188 | case OSS_1: 189 | os_delay_us(CONVERSION_TIME*1500); 190 | break; 191 | case OSS_2: 192 | os_delay_us(CONVERSION_TIME*2700); 193 | break; 194 | case OSS_3: 195 | os_delay_us(CONVERSION_TIME*5100); 196 | break; 197 | default: 198 | os_delay_us(CONVERSION_TIME*900); 199 | } 200 | int16_t res = BMP180_readExRegister16(BMP180_DATA_REG, resolution); 201 | return res; 202 | } 203 | 204 | bool ICACHE_FLASH_ATTR BMP180_Init() 205 | { 206 | i2c_init(); 207 | int16_t version = BMP180_readRegister16(BMP180_CHIP_ID_REG)>>8; 208 | if (version != BMP180_CHIP_ID) { 209 | #ifdef BMP180_DEBUG 210 | char temp[80]; 211 | os_sprintf(temp, "BMP180: wanted chip id 0x%X, found chip id 0x%X\r\n", 212 | BMP180_CHIP_ID, version); 213 | ets_uart_printf(temp); 214 | #endif 215 | return 0; 216 | } 217 | 218 | if (!BMP180_readRegister16(BMP180_VERSION_REG)) 219 | return 0; 220 | 221 | #ifdef BMP180_DEBUG 222 | //os_printf("BMP180 read calibration data...\r\n"); 223 | ets_uart_printf("BMP180 read calibration data...\r\n"); 224 | #endif 225 | ac1 = BMP180_readRegister16(0xAA); 226 | ac2 = BMP180_readRegister16(0xAC); 227 | ac3 = BMP180_readRegister16(0xAE); 228 | ac4 = BMP180_readRegister16(0xB0); 229 | ac5 = BMP180_readRegister16(0xB2); 230 | ac6 = BMP180_readRegister16(0xB4); 231 | b1 = BMP180_readRegister16(0xB6); 232 | b2 = BMP180_readRegister16(0xB8); 233 | mb = BMP180_readRegister16(0xBA); 234 | mc = BMP180_readRegister16(0xBC); 235 | md = BMP180_readRegister16(0xBE); 236 | 237 | #ifdef BMP180_DEBUG 238 | ets_uart_printf("BMP180_Calibration:\r\n"); 239 | char temp[128]; 240 | os_sprintf(temp, "AC1: %ld, AC2: %ld, AC3: %ld, AC4: %ld, AC5: %ld, AC6: %ld, B1: %ld, B2: %ld, MB: %ld, MC: %ld, MD: %ld\r\n", 241 | ac1, ac2, ac3, ac4, ac5, ac6, b1, b2, mb, mc, md); 242 | ets_uart_printf(temp); 243 | #endif 244 | return 1; 245 | } 246 | 247 | int32_t BMP180_GetTemperature() 248 | { 249 | int32_t UT; 250 | int32_t B5, X1, X2, T, F; 251 | UT = BMP180_readRawValue(BMP_CMD_MEASURE_TEMP); 252 | X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15; 253 | X2 = ((int32_t)mc << 11) / (X1 + (int32_t)md); 254 | B5 = X1 + X2; 255 | T = (B5+8) >> 4; //C X10 256 | F = ((T*18)/100) + 32; 257 | return (T); 258 | } 259 | 260 | int32_t BMP180_GetPressure(enum PRESSURE_RESOLUTION resolution) 261 | { 262 | int32_t UT; 263 | uint16_t UP; 264 | int32_t B3, B5, B6; 265 | uint32_t B4, B7; 266 | int32_t X1, X2, X3; 267 | int32_t P; 268 | UT = BMP180_readRawValue(BMP_CMD_MEASURE_TEMP); 269 | UP = BMP180_readExRawValue(BMP_CMD_MEASURE_PRESSURE_0+(resolution<<6), resolution); 270 | // Calculate temperature 271 | X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15; 272 | X2 = ((int32_t)mc << 11) / (X1 + (int32_t)md); 273 | B5 = X1 + X2; 274 | // Calculate pressure 275 | B6 = B5 - 4000; 276 | X1 = ((int32_t)b2 * ((B6 * B6) >> 12)) >> 11; 277 | X2 = ((int32_t)ac2 * B6) >> 11; 278 | X3 = X1 + X2; 279 | B3 = (((((int32_t) ac1) * 4 + X3)<> 2; 280 | X1 = ((int32_t)ac3 * B6) >> 13; 281 | X2 = ((int32_t)b1 * ((B6 * B6) >> 12)) >> 16; 282 | X3 = ((X1 + X2) + 2) >> 2; 283 | B4 = ((uint32_t)ac4 * (uint32_t)(X3 + 32768)) >> 15; 284 | B7 = ((uint32_t) (UP - B3) * (50000 >> resolution)); 285 | if (B7 < 0x80000000) { 286 | P = (B7 * 2) / B4; 287 | } else { 288 | P = (B7 / B4) * 2; 289 | } 290 | X1 = (P >> 8) * (P >> 8); 291 | X1 = (X1 * 3038) >> 16; 292 | X2 = (-7357 * P) >> 16; 293 | P = P + ((X1 + X2 + (int32_t)3791) >> 4); 294 | return P; 295 | } 296 | 297 | int32_t BMP180_CalcAltitude(int32_t pressure) 298 | { 299 | return (int32_t)(pow(((float)MYALTITUDE/44330)+1,5.255F)*pressure); 300 | } 301 | -------------------------------------------------------------------------------- /IR_RemoteC/driver/i2c_master.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: i2c_master.c 5 | * 6 | * Description: i2c master API 7 | * 8 | * Modification history: 9 | * 2014/3/12, v1.0 create this file. 10 | *******************************************************************************/ 11 | #include "ets_sys.h" 12 | #include "osapi.h" 13 | #include "gpio.h" 14 | 15 | #include "driver/i2c_master.h" 16 | 17 | LOCAL uint8 m_nLastSDA; 18 | LOCAL uint8 m_nLastSCL; 19 | 20 | /****************************************************************************** 21 | * FunctionName : i2c_master_setDC 22 | * Description : Internal used function - 23 | * set i2c SDA and SCL bit value for half clk cycle 24 | * Parameters : uint8 SDA 25 | * uint8 SCL 26 | * Returns : NONE 27 | *******************************************************************************/ 28 | LOCAL void ICACHE_FLASH_ATTR 29 | i2c_master_setDC(uint8 SDA, uint8 SCL) 30 | { 31 | SDA &= 0x01; 32 | SCL &= 0x01; 33 | m_nLastSDA = SDA; 34 | m_nLastSCL = SCL; 35 | 36 | if ((0 == SDA) && (0 == SCL)) { 37 | I2C_MASTER_SDA_LOW_SCL_LOW(); 38 | } else if ((0 == SDA) && (1 == SCL)) { 39 | I2C_MASTER_SDA_LOW_SCL_HIGH(); 40 | } else if ((1 == SDA) && (0 == SCL)) { 41 | I2C_MASTER_SDA_HIGH_SCL_LOW(); 42 | } else { 43 | I2C_MASTER_SDA_HIGH_SCL_HIGH(); 44 | } 45 | } 46 | 47 | /****************************************************************************** 48 | * FunctionName : i2c_master_getDC 49 | * Description : Internal used function - 50 | * get i2c SDA bit value 51 | * Parameters : NONE 52 | * Returns : uint8 - SDA bit value 53 | *******************************************************************************/ 54 | LOCAL uint8 ICACHE_FLASH_ATTR 55 | i2c_master_getDC(void) 56 | { 57 | uint8 sda_out; 58 | sda_out = GPIO_INPUT_GET(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)); 59 | return sda_out; 60 | } 61 | 62 | /****************************************************************************** 63 | * FunctionName : i2c_master_init 64 | * Description : initilize I2C bus to enable i2c operations 65 | * Parameters : NONE 66 | * Returns : NONE 67 | *******************************************************************************/ 68 | void ICACHE_FLASH_ATTR 69 | i2c_master_init(void) 70 | { 71 | uint8 i; 72 | 73 | i2c_master_setDC(1, 0); 74 | i2c_master_wait(5); 75 | 76 | // when SCL = 0, toggle SDA to clear up 77 | i2c_master_setDC(0, 0) ; 78 | i2c_master_wait(5); 79 | i2c_master_setDC(1, 0) ; 80 | i2c_master_wait(5); 81 | 82 | // set data_cnt to max value 83 | for (i = 0; i < 28; i++) { 84 | i2c_master_setDC(1, 0); 85 | i2c_master_wait(5); // sda 1, scl 0 86 | i2c_master_setDC(1, 1); 87 | i2c_master_wait(5); // sda 1, scl 1 88 | } 89 | 90 | // reset all 91 | i2c_master_stop(); 92 | return; 93 | } 94 | 95 | /****************************************************************************** 96 | * FunctionName : i2c_master_gpio_init 97 | * Description : config SDA and SCL gpio to open-drain output mode, 98 | * mux and gpio num defined in i2c_master.h 99 | * Parameters : NONE 100 | * Returns : NONE 101 | *******************************************************************************/ 102 | void ICACHE_FLASH_ATTR 103 | i2c_master_gpio_init(void) 104 | { 105 | ETS_GPIO_INTR_DISABLE() ; 106 | // ETS_INTR_LOCK(); 107 | 108 | PIN_FUNC_SELECT(I2C_MASTER_SDA_MUX, I2C_MASTER_SDA_FUNC); 109 | PIN_FUNC_SELECT(I2C_MASTER_SCL_MUX, I2C_MASTER_SCL_FUNC); 110 | 111 | GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain; 112 | GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SDA_GPIO)); 113 | GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain; 114 | GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SCL_GPIO)); 115 | 116 | I2C_MASTER_SDA_HIGH_SCL_HIGH(); 117 | 118 | ETS_GPIO_INTR_ENABLE() ; 119 | // ETS_INTR_UNLOCK(); 120 | 121 | i2c_master_init(); 122 | } 123 | 124 | /****************************************************************************** 125 | * FunctionName : i2c_master_start 126 | * Description : set i2c to send state 127 | * Parameters : NONE 128 | * Returns : NONE 129 | *******************************************************************************/ 130 | void ICACHE_FLASH_ATTR 131 | i2c_master_start(void) 132 | { 133 | i2c_master_setDC(1, m_nLastSCL); 134 | i2c_master_wait(5); 135 | i2c_master_setDC(1, 1); 136 | i2c_master_wait(5); // sda 1, scl 1 137 | i2c_master_setDC(0, 1); 138 | i2c_master_wait(5); // sda 0, scl 1 139 | } 140 | 141 | /****************************************************************************** 142 | * FunctionName : i2c_master_stop 143 | * Description : set i2c to stop sending state 144 | * Parameters : NONE 145 | * Returns : NONE 146 | *******************************************************************************/ 147 | void ICACHE_FLASH_ATTR 148 | i2c_master_stop(void) 149 | { 150 | i2c_master_wait(5); 151 | 152 | i2c_master_setDC(0, m_nLastSCL); 153 | i2c_master_wait(5); // sda 0 154 | i2c_master_setDC(0, 1); 155 | i2c_master_wait(5); // sda 0, scl 1 156 | i2c_master_setDC(1, 1); 157 | i2c_master_wait(5); // sda 1, scl 1 158 | } 159 | 160 | /****************************************************************************** 161 | * FunctionName : i2c_master_setAck 162 | * Description : set ack to i2c bus as level value 163 | * Parameters : uint8 level - 0 or 1 164 | * Returns : NONE 165 | *******************************************************************************/ 166 | void ICACHE_FLASH_ATTR 167 | i2c_master_setAck(uint8 level) 168 | { 169 | i2c_master_setDC(m_nLastSDA, 0); 170 | i2c_master_wait(5); 171 | i2c_master_setDC(level, 0); 172 | i2c_master_wait(5); // sda level, scl 0 173 | i2c_master_setDC(level, 1); 174 | i2c_master_wait(8); // sda level, scl 1 175 | i2c_master_setDC(level, 0); 176 | i2c_master_wait(5); // sda level, scl 0 177 | i2c_master_setDC(1, 0); 178 | i2c_master_wait(5); 179 | } 180 | 181 | /****************************************************************************** 182 | * FunctionName : i2c_master_getAck 183 | * Description : confirm if peer send ack 184 | * Parameters : NONE 185 | * Returns : uint8 - ack value, 0 or 1 186 | *******************************************************************************/ 187 | uint8 ICACHE_FLASH_ATTR 188 | i2c_master_getAck(void) 189 | { 190 | uint8 retVal; 191 | i2c_master_setDC(m_nLastSDA, 0); 192 | i2c_master_wait(5); 193 | i2c_master_setDC(1, 0); 194 | i2c_master_wait(5); 195 | i2c_master_setDC(1, 1); 196 | i2c_master_wait(5); 197 | 198 | retVal = i2c_master_getDC(); 199 | i2c_master_wait(5); 200 | i2c_master_setDC(1, 0); 201 | i2c_master_wait(5); 202 | 203 | return retVal; 204 | } 205 | 206 | /****************************************************************************** 207 | * FunctionName : i2c_master_checkAck 208 | * Description : get dev response 209 | * Parameters : NONE 210 | * Returns : true : get ack ; false : get nack 211 | *******************************************************************************/ 212 | bool ICACHE_FLASH_ATTR 213 | i2c_master_checkAck(void) 214 | { 215 | if(i2c_master_getAck()){ 216 | return FALSE; 217 | }else{ 218 | return TRUE; 219 | } 220 | } 221 | 222 | /****************************************************************************** 223 | * FunctionName : i2c_master_send_ack 224 | * Description : response ack 225 | * Parameters : NONE 226 | * Returns : NONE 227 | *******************************************************************************/ 228 | void ICACHE_FLASH_ATTR 229 | i2c_master_send_ack(void) 230 | { 231 | i2c_master_setAck(0x0); 232 | } 233 | /****************************************************************************** 234 | * FunctionName : i2c_master_send_nack 235 | * Description : response nack 236 | * Parameters : NONE 237 | * Returns : NONE 238 | *******************************************************************************/ 239 | void ICACHE_FLASH_ATTR 240 | i2c_master_send_nack(void) 241 | { 242 | i2c_master_setAck(0x1); 243 | } 244 | 245 | /****************************************************************************** 246 | * FunctionName : i2c_master_readByte 247 | * Description : read Byte from i2c bus 248 | * Parameters : NONE 249 | * Returns : uint8 - readed value 250 | *******************************************************************************/ 251 | uint8 ICACHE_FLASH_ATTR 252 | i2c_master_readByte(void) 253 | { 254 | uint8 retVal = 0; 255 | uint8 k, i; 256 | 257 | i2c_master_wait(5); 258 | i2c_master_setDC(m_nLastSDA, 0); 259 | i2c_master_wait(5); // sda 1, scl 0 260 | 261 | for (i = 0; i < 8; i++) { 262 | i2c_master_wait(5); 263 | i2c_master_setDC(1, 0); 264 | i2c_master_wait(5); // sda 1, scl 0 265 | i2c_master_setDC(1, 1); 266 | i2c_master_wait(5); // sda 1, scl 1 267 | 268 | k = i2c_master_getDC(); 269 | i2c_master_wait(5); 270 | 271 | if (i == 7) { 272 | i2c_master_wait(3); //// 273 | } 274 | 275 | k <<= (7 - i); 276 | retVal |= k; 277 | } 278 | 279 | i2c_master_setDC(1, 0); 280 | i2c_master_wait(5); // sda 1, scl 0 281 | 282 | return retVal; 283 | } 284 | 285 | /****************************************************************************** 286 | * FunctionName : i2c_master_writeByte 287 | * Description : write wrdata value(one byte) into i2c 288 | * Parameters : uint8 wrdata - write value 289 | * Returns : NONE 290 | *******************************************************************************/ 291 | void ICACHE_FLASH_ATTR 292 | i2c_master_writeByte(uint8 wrdata) 293 | { 294 | uint8 dat; 295 | sint8 i; 296 | 297 | i2c_master_wait(5); 298 | 299 | i2c_master_setDC(m_nLastSDA, 0); 300 | i2c_master_wait(5); 301 | 302 | for (i = 7; i >= 0; i--) { 303 | dat = wrdata >> i; 304 | i2c_master_setDC(dat, 0); 305 | i2c_master_wait(5); 306 | i2c_master_setDC(dat, 1); 307 | i2c_master_wait(5); 308 | 309 | if (i == 0) { 310 | i2c_master_wait(3); //// 311 | } 312 | 313 | i2c_master_setDC(dat, 0); 314 | i2c_master_wait(5); 315 | } 316 | } 317 | -------------------------------------------------------------------------------- /IR_RemoteC/driver/key.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: key.c 5 | * 6 | * Description: key driver, now can use different gpio and install different function 7 | * 8 | * Modification history: 9 | * 2014/5/1, v1.0 create this file. 10 | *******************************************************************************/ 11 | #include "ets_sys.h" 12 | #include "os_type.h" 13 | #include "osapi.h" 14 | #include "mem.h" 15 | #include "gpio.h" 16 | #include "user_interface.h" 17 | 18 | #include "driver/key.h" 19 | 20 | LOCAL void key_intr_handler(struct keys_param *keys); 21 | 22 | /****************************************************************************** 23 | * FunctionName : key_init_single 24 | * Description : init single key's gpio and register function 25 | * Parameters : uint8 gpio_id - which gpio to use 26 | * uint32 gpio_name - gpio mux name 27 | * uint32 gpio_func - gpio function 28 | * key_function long_press - long press function, needed to install 29 | * key_function short_press - short press function, needed to install 30 | * Returns : single_key_param - single key parameter, needed by key init 31 | *******************************************************************************/ 32 | struct single_key_param *ICACHE_FLASH_ATTR 33 | key_init_single(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func, key_function long_press, key_function short_press) 34 | { 35 | struct single_key_param *single_key = (struct single_key_param *)os_zalloc(sizeof(struct single_key_param)); 36 | 37 | single_key->gpio_id = gpio_id; 38 | single_key->gpio_name = gpio_name; 39 | single_key->gpio_func = gpio_func; 40 | single_key->long_press = long_press; 41 | single_key->short_press = short_press; 42 | 43 | return single_key; 44 | } 45 | 46 | /****************************************************************************** 47 | * FunctionName : key_init 48 | * Description : init keys 49 | * Parameters : key_param *keys - keys parameter, which inited by key_init_single 50 | * Returns : none 51 | *******************************************************************************/ 52 | void ICACHE_FLASH_ATTR 53 | key_init(struct keys_param *keys) 54 | { 55 | uint8 i; 56 | 57 | ETS_GPIO_INTR_ATTACH(key_intr_handler, keys); 58 | 59 | ETS_GPIO_INTR_DISABLE(); 60 | 61 | for (i = 0; i < keys->key_num; i++) { 62 | keys->single_key[i]->key_level = 1; 63 | 64 | PIN_FUNC_SELECT(keys->single_key[i]->gpio_name, keys->single_key[i]->gpio_func); 65 | 66 | gpio_output_set(0, 0, 0, GPIO_ID_PIN(keys->single_key[i]->gpio_id)); 67 | 68 | gpio_register_set(GPIO_PIN_ADDR(keys->single_key[i]->gpio_id), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE) 69 | | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE) 70 | | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE)); 71 | 72 | //clear gpio14 status 73 | GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(keys->single_key[i]->gpio_id)); 74 | 75 | //enable interrupt 76 | gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_NEGEDGE); 77 | } 78 | 79 | ETS_GPIO_INTR_ENABLE(); 80 | } 81 | 82 | /****************************************************************************** 83 | * FunctionName : key_5s_cb 84 | * Description : long press 5s timer callback 85 | * Parameters : single_key_param *single_key - single key parameter 86 | * Returns : none 87 | *******************************************************************************/ 88 | LOCAL void ICACHE_FLASH_ATTR 89 | key_5s_cb(struct single_key_param *single_key) 90 | { 91 | os_timer_disarm(&single_key->key_5s); 92 | 93 | // low, then restart 94 | if (0 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { 95 | if (single_key->long_press) { 96 | single_key->long_press(); 97 | } 98 | } 99 | } 100 | 101 | /****************************************************************************** 102 | * FunctionName : key_50ms_cb 103 | * Description : 50ms timer callback to check it's a real key push 104 | * Parameters : single_key_param *single_key - single key parameter 105 | * Returns : none 106 | *******************************************************************************/ 107 | LOCAL void ICACHE_FLASH_ATTR 108 | key_50ms_cb(struct single_key_param *single_key) 109 | { 110 | os_timer_disarm(&single_key->key_50ms); 111 | 112 | // high, then key is up 113 | if (1 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { 114 | os_timer_disarm(&single_key->key_5s); 115 | single_key->key_level = 1; 116 | gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_NEGEDGE); 117 | 118 | if (single_key->short_press) { 119 | single_key->short_press(); 120 | } 121 | } else { 122 | gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_POSEDGE); 123 | } 124 | } 125 | 126 | /****************************************************************************** 127 | * FunctionName : key_intr_handler 128 | * Description : key interrupt handler 129 | * Parameters : key_param *keys - keys parameter, which inited by key_init_single 130 | * Returns : none 131 | *******************************************************************************/ 132 | LOCAL void 133 | key_intr_handler(struct keys_param *keys) 134 | { 135 | uint8 i; 136 | uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); 137 | 138 | for (i = 0; i < keys->key_num; i++) { 139 | if (gpio_status & BIT(keys->single_key[i]->gpio_id)) { 140 | //disable interrupt 141 | gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_DISABLE); 142 | 143 | //clear interrupt status 144 | GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(keys->single_key[i]->gpio_id)); 145 | 146 | if (keys->single_key[i]->key_level == 1) { 147 | // 5s, restart & enter softap mode 148 | os_timer_disarm(&keys->single_key[i]->key_5s); 149 | os_timer_setfn(&keys->single_key[i]->key_5s, (os_timer_func_t *)key_5s_cb, keys->single_key[i]); 150 | os_timer_arm(&keys->single_key[i]->key_5s, 5000, 0); 151 | keys->single_key[i]->key_level = 0; 152 | gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_POSEDGE); 153 | } else { 154 | // 50ms, check if this is a real key up 155 | os_timer_disarm(&keys->single_key[i]->key_50ms); 156 | os_timer_setfn(&keys->single_key[i]->key_50ms, (os_timer_func_t *)key_50ms_cb, keys->single_key[i]); 157 | os_timer_arm(&keys->single_key[i]->key_50ms, 50, 0); 158 | } 159 | } 160 | } 161 | } 162 | 163 | -------------------------------------------------------------------------------- /IR_RemoteC/driver/pwm.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: pwm.c 5 | * 6 | * Description: pwm driver 7 | * 8 | * Modification history: 9 | * 2014/5/1, v1.0 create this file. 10 | *******************************************************************************/ 11 | #include "ets_sys.h" 12 | #include "os_type.h" 13 | #include "osapi.h" 14 | 15 | #include "user_interface.h" 16 | #include "driver/pwm.h" 17 | 18 | LOCAL struct pwm_param pwm; 19 | 20 | LOCAL bool rdy_flg = 0; //calc finished flag 21 | LOCAL bool update_flg = 0; //update finished flag 22 | LOCAL bool init_flg = 0; //first update flag 23 | 24 | //define local struct array 25 | LOCAL struct pwm_single_param local_single[PWM_CHANNEL + 1]; //local_single param 26 | LOCAL uint8 local_channel = 0; //local_channel value 27 | 28 | LOCAL struct pwm_single_param pwm_single[PWM_CHANNEL + 1]; //pwm_single param 29 | LOCAL uint8 pwm_channel = 0; //pwm_channel value 30 | 31 | LOCAL struct pwm_single_param saved_single[PWM_CHANNEL + 1]; //saved_single param 32 | LOCAL uint8 saved_channel = 0; //saved_channel value 33 | 34 | LOCAL uint8 pwm_out_io_num[PWM_CHANNEL] = {PWM_0_OUT_IO_NUM, 35 | PWM_1_OUT_IO_NUM, PWM_2_OUT_IO_NUM 36 | }; //each channel gpio number 37 | LOCAL uint8 pwm_current_channel = 0; //current pwm channel in pwm_tim1_intr_handler 38 | LOCAL uint16 pwm_gpio = 0; //all pwm gpio bits 39 | 40 | //XXX: 0xffffffff/(80000000/16)=35A 41 | #define US_TO_RTC_TIMER_TICKS(t) \ 42 | ((t) ? \ 43 | (((t) > 0x35A) ? \ 44 | (((t)>>2) * ((APB_CLK_FREQ>>4)/250000) + ((t)&0x3) * ((APB_CLK_FREQ>>4)/1000000)) : \ 45 | (((t) *(APB_CLK_FREQ>>4)) / 1000000)) : \ 46 | 0) 47 | 48 | #define FRC1_ENABLE_TIMER BIT7 49 | 50 | //TIMER PREDIVED MODE 51 | typedef enum { 52 | DIVDED_BY_1 = 0, //timer clock 53 | DIVDED_BY_16 = 4, //divided by 16 54 | DIVDED_BY_256 = 8, //divided by 256 55 | } TIMER_PREDIVED_MODE; 56 | 57 | typedef enum { //timer interrupt mode 58 | TM_LEVEL_INT = 1, // level interrupt 59 | TM_EDGE_INT = 0, //edge interrupt 60 | } TIMER_INT_MODE; 61 | 62 | // sort all channels' h_time,small to big 63 | LOCAL void ICACHE_FLASH_ATTR 64 | pwm_insert_sort(struct pwm_single_param pwm[], uint8 n) 65 | { 66 | uint8 i; 67 | 68 | for (i = 1; i < n; i++) { 69 | if (pwm[i].h_time < pwm[i - 1].h_time) { 70 | int8 j = i - 1; 71 | struct pwm_single_param tmp; 72 | 73 | os_memcpy(&tmp, &pwm[i], sizeof(struct pwm_single_param)); 74 | os_memcpy(&pwm[i], &pwm[i - 1], sizeof(struct pwm_single_param)); 75 | 76 | while (tmp.h_time < pwm[j].h_time) { 77 | os_memcpy(&pwm[j + 1], &pwm[j], sizeof(struct pwm_single_param)); 78 | j--; 79 | 80 | if (j < 0) { 81 | break; 82 | } 83 | } 84 | 85 | os_memcpy(&pwm[j + 1], &tmp, sizeof(struct pwm_single_param)); 86 | } 87 | } 88 | } 89 | 90 | void ICACHE_FLASH_ATTR 91 | pwm_start(void) 92 | { 93 | uint8 i, j; 94 | 95 | // if not first update,save local param to saved param,local_channel to saved_channel 96 | if (init_flg == 1) { 97 | for (i = 0; i < local_channel; i++) { 98 | os_memcpy(&saved_single[i], &local_single[i], sizeof(struct pwm_single_param)); 99 | } 100 | 101 | saved_channel = local_channel; 102 | } 103 | 104 | rdy_flg = 0; //clear rdy_flg before calcing local struct param 105 | 106 | // step 1: init PWM_CHANNEL+1 channels param 107 | for (i = 0; i < PWM_CHANNEL; i++) { 108 | uint32 us = pwm.period * pwm.duty[i] / PWM_DEPTH; //calc single channel us time 109 | local_single[i].h_time = US_TO_RTC_TIMER_TICKS(us); //calc h_time to write FRC1_LOAD_ADDRESS 110 | local_single[i].gpio_set = 0; //don't set gpio 111 | local_single[i].gpio_clear = 1 << pwm_out_io_num[i]; //clear single channel gpio 112 | } 113 | 114 | local_single[PWM_CHANNEL].h_time = US_TO_RTC_TIMER_TICKS(pwm.period); //calc pwm.period channel us time 115 | local_single[PWM_CHANNEL].gpio_set = pwm_gpio; //set all channels' gpio 116 | local_single[PWM_CHANNEL].gpio_clear = 0; //don't clear gpio 117 | 118 | // step 2: sort, small to big 119 | pwm_insert_sort(local_single, PWM_CHANNEL + 1); //time sort small to big, 120 | local_channel = PWM_CHANNEL + 1; //local channel number is PWM_CHANNEL+1 121 | 122 | // step 3: combine same duty channels 123 | for (i = PWM_CHANNEL; i > 0; i--) { 124 | if (local_single[i].h_time == local_single[i - 1].h_time) { 125 | local_single[i - 1].gpio_set |= local_single[i].gpio_set; 126 | local_single[i - 1].gpio_clear |= local_single[i].gpio_clear; 127 | 128 | //copy channel j param to channel j-1 param 129 | for (j = i + 1; j < local_channel; j++) { 130 | os_memcpy(&local_single[j - 1], &local_single[j], sizeof(struct pwm_single_param)); 131 | } 132 | 133 | local_channel--; 134 | } 135 | } 136 | 137 | // step 4: calc delt time 138 | for (i = local_channel - 1; i > 0; i--) { 139 | local_single[i].h_time -= local_single[i - 1].h_time; 140 | } 141 | 142 | // step 5: last channel needs to clean 143 | local_single[local_channel - 1].gpio_clear = 0; 144 | 145 | // step 6: if first channel duty is 0, remove it 146 | if (local_single[0].h_time == 0) { 147 | 148 | local_single[local_channel - 1].gpio_set &= ~local_single[0].gpio_clear; 149 | local_single[local_channel - 1].gpio_clear |= local_single[0].gpio_clear; 150 | 151 | //copy channel i param to channel i-1 param 152 | for (i = 1; i < local_channel; i++) { 153 | os_memcpy(&local_single[i - 1], &local_single[i], sizeof(struct pwm_single_param)); 154 | } 155 | 156 | local_channel--; 157 | } 158 | 159 | // if the first update,copy local param to pwm param and copy local_channel to pwm_channel 160 | if (init_flg == 0) { 161 | for (i = 0; i < local_channel; i++) { 162 | os_memcpy(&pwm_single[i], &local_single[i], sizeof(struct pwm_single_param)); 163 | } 164 | 165 | pwm_channel = local_channel; 166 | init_flg = 1; //first update finished 167 | RTC_REG_WRITE(FRC1_LOAD_ADDRESS, US_TO_RTC_TIMER_TICKS(pwm.period)); //first update finished,start 168 | } 169 | 170 | update_flg = 1; //update finished 171 | rdy_flg = 1; //calc ready 172 | 173 | } 174 | 175 | 176 | /****************************************************************************** 177 | * FunctionName : pwm_set_duty 178 | * Description : set each channel's duty param 179 | * Parameters : uint8 duty : 0 ~ PWM_DEPTH 180 | * uint8 channel : channel index 181 | * Returns : NONE 182 | *******************************************************************************/ 183 | void ICACHE_FLASH_ATTR 184 | pwm_set_duty(uint8 duty, uint8 channel) 185 | { 186 | if (duty < 1) { 187 | pwm.duty[channel] = 0; 188 | } else if (duty >= PWM_DEPTH) { 189 | pwm.duty[channel] = PWM_DEPTH; 190 | } else { 191 | pwm.duty[channel] = duty; 192 | } 193 | } 194 | 195 | /****************************************************************************** 196 | * FunctionName : pwm_set_freq 197 | * Description : set pwm frequency 198 | * Parameters : uint16 freq : 100hz typically 199 | * Returns : NONE 200 | *******************************************************************************/ 201 | void ICACHE_FLASH_ATTR 202 | pwm_set_freq(uint16 freq) 203 | { 204 | if (freq > 500) { 205 | pwm.freq = 500; 206 | } else if (freq < 1) { 207 | pwm.freq = 1; 208 | } else { 209 | pwm.freq = freq; 210 | } 211 | 212 | pwm.period = PWM_1S / pwm.freq; 213 | } 214 | 215 | /****************************************************************************** 216 | * FunctionName : pwm_set_freq_duty 217 | * Description : set pwm frequency and each channel's duty 218 | * Parameters : uint16 freq : 100hz typically 219 | * uint8 *duty : each channel's duty 220 | * Returns : NONE 221 | *******************************************************************************/ 222 | LOCAL void ICACHE_FLASH_ATTR 223 | pwm_set_freq_duty(uint16 freq, uint8 *duty) 224 | { 225 | uint8 i; 226 | 227 | pwm_set_freq(freq); 228 | 229 | for (i = 0; i < PWM_CHANNEL; i++) { 230 | pwm_set_duty(duty[i], i); 231 | } 232 | } 233 | 234 | /****************************************************************************** 235 | * FunctionName : pwm_get_duty 236 | * Description : get duty of each channel 237 | * Parameters : uint8 channel : channel index 238 | * Returns : NONE 239 | *******************************************************************************/ 240 | uint8 ICACHE_FLASH_ATTR 241 | pwm_get_duty(uint8 channel) 242 | { 243 | return pwm.duty[channel]; 244 | } 245 | 246 | /****************************************************************************** 247 | * FunctionName : pwm_get_freq 248 | * Description : get pwm frequency 249 | * Parameters : NONE 250 | * Returns : uint16 : pwm frequency 251 | *******************************************************************************/ 252 | uint16 ICACHE_FLASH_ATTR 253 | pwm_get_freq(void) 254 | { 255 | return pwm.freq; 256 | } 257 | 258 | /****************************************************************************** 259 | * FunctionName : pwm_period_timer 260 | * Description : pwm period timer function, output high level, 261 | * start each channel's high level timer 262 | * Parameters : NONE 263 | * Returns : NONE 264 | *******************************************************************************/ 265 | void pwm_tim1_intr_handler(void) 266 | { 267 | uint8 i = 0; 268 | RTC_CLR_REG_MASK(FRC1_INT_ADDRESS, FRC1_INT_CLR_MASK); 269 | 270 | if (pwm_current_channel == (pwm_channel - 1)) { 271 | 272 | // if update is not finished,don't copy param,otherwise copy 273 | if (update_flg == 1) { 274 | // if calc ready,copy local param, otherwise copy saved param 275 | if (rdy_flg == 1) { 276 | for (i = 0; i < local_channel; i++) { 277 | os_memcpy(&pwm_single[i], &local_single[i], sizeof(struct pwm_single_param)); 278 | } 279 | 280 | pwm_channel = local_channel; 281 | } else { 282 | for (i = 0; i < saved_channel; i++) { 283 | os_memcpy(&pwm_single[i], &saved_single[i], sizeof(struct pwm_single_param)); 284 | } 285 | 286 | pwm_channel = saved_channel; 287 | } 288 | } 289 | 290 | update_flg = 0; //clear update flag 291 | pwm_current_channel = 0; 292 | 293 | gpio_output_set(pwm_single[pwm_channel - 1].gpio_set, 294 | pwm_single[pwm_channel - 1].gpio_clear, 295 | pwm_gpio, 296 | 0); 297 | 298 | //if all channels' duty is 0 or 255,set intr period as pwm.period 299 | if (pwm_channel != 1) { 300 | RTC_REG_WRITE(FRC1_LOAD_ADDRESS, pwm_single[pwm_current_channel].h_time); 301 | } else { 302 | RTC_REG_WRITE(FRC1_LOAD_ADDRESS, US_TO_RTC_TIMER_TICKS(pwm.period)); 303 | } 304 | } else { 305 | gpio_output_set(pwm_single[pwm_current_channel].gpio_set, 306 | pwm_single[pwm_current_channel].gpio_clear, 307 | pwm_gpio, 0); 308 | pwm_current_channel++; 309 | RTC_REG_WRITE(FRC1_LOAD_ADDRESS, pwm_single[pwm_current_channel].h_time); 310 | } 311 | } 312 | 313 | /****************************************************************************** 314 | * FunctionName : pwm_init 315 | * Description : pwm gpio, param and timer initialization 316 | * Parameters : uint16 freq : pwm freq param 317 | * uint8 *duty : each channel's duty 318 | * Returns : NONE 319 | *******************************************************************************/ 320 | void ICACHE_FLASH_ATTR 321 | pwm_init(uint16 freq, uint8 *duty) 322 | { 323 | uint8 i; 324 | 325 | RTC_REG_WRITE(FRC1_CTRL_ADDRESS, 326 | DIVDED_BY_16 327 | | FRC1_ENABLE_TIMER 328 | | TM_EDGE_INT); 329 | //RTC_REG_WRITE(FRC1_LOAD_ADDRESS, 0); 330 | 331 | PIN_FUNC_SELECT(PWM_0_OUT_IO_MUX, PWM_0_OUT_IO_FUNC); 332 | PIN_FUNC_SELECT(PWM_1_OUT_IO_MUX, PWM_1_OUT_IO_FUNC); 333 | PIN_FUNC_SELECT(PWM_2_OUT_IO_MUX, PWM_2_OUT_IO_FUNC); 334 | 335 | for (i = 0; i < PWM_CHANNEL; i++) { 336 | pwm_gpio |= (1 << pwm_out_io_num[i]); 337 | } 338 | 339 | pwm_set_freq_duty(freq, duty); 340 | 341 | pwm_start(); 342 | 343 | ETS_FRC_TIMER1_INTR_ATTACH(pwm_tim1_intr_handler, NULL); 344 | TM1_EDGE_INT_ENABLE(); 345 | ETS_FRC1_INTR_ENABLE(); 346 | } 347 | 348 | -------------------------------------------------------------------------------- /IR_RemoteC/driver/uart.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: uart.c 5 | * 6 | * Description: Two UART mode configration and interrupt handler. 7 | * Check your hardware connection while use this mode. 8 | * 9 | * Modification history: 10 | * 2014/3/12, v1.0 create this file. 11 | *******************************************************************************/ 12 | #include "ets_sys.h" 13 | #include "osapi.h" 14 | #include "driver/uart.h" 15 | 16 | #define UART0 0 17 | #define UART1 1 18 | 19 | // UartDev is defined and initialized in rom code. 20 | extern UartDevice UartDev; 21 | 22 | LOCAL void uart0_rx_intr_handler(void *para); 23 | 24 | /****************************************************************************** 25 | * FunctionName : uart_config 26 | * Description : Internal used function 27 | * UART0 used for data TX/RX, RX buffer size is 0x100, interrupt enabled 28 | * UART1 just used for debug output 29 | * Parameters : uart_no, use UART0 or UART1 defined ahead 30 | * Returns : NONE 31 | *******************************************************************************/ 32 | LOCAL void ICACHE_FLASH_ATTR 33 | uart_config(uint8 uart_no) 34 | { 35 | if (uart_no == UART1) { 36 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK); 37 | } else { 38 | /* rcv_buff size if 0x100 */ 39 | ETS_UART_INTR_ATTACH(uart0_rx_intr_handler, &(UartDev.rcv_buff)); 40 | PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U); 41 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); 42 | } 43 | 44 | uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate)); 45 | 46 | WRITE_PERI_REG(UART_CONF0(uart_no), UartDev.exist_parity 47 | | UartDev.parity 48 | | (UartDev.stop_bits << UART_STOP_BIT_NUM_S) 49 | | (UartDev.data_bits << UART_BIT_NUM_S)); 50 | 51 | 52 | //clear rx and tx fifo,not ready 53 | SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST); 54 | CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST); 55 | 56 | //set rx fifo trigger 57 | WRITE_PERI_REG(UART_CONF1(uart_no), (UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S); 58 | 59 | //clear all interrupt 60 | WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff); 61 | //enable rx_interrupt 62 | SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA); 63 | } 64 | 65 | /****************************************************************************** 66 | * FunctionName : uart1_tx_one_char 67 | * Description : Internal used function 68 | * Use uart1 interface to transfer one char 69 | * Parameters : uint8 TxChar - character to tx 70 | * Returns : OK 71 | *******************************************************************************/ 72 | LOCAL STATUS ICACHE_FLASH_ATTR 73 | uart1_tx_one_char(uint8 TxChar) 74 | { 75 | while (true) 76 | { 77 | uint32 fifo_cnt = READ_PERI_REG(UART_STATUS(UART1)) & (UART_TXFIFO_CNT<> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126) { 79 | break; 80 | } 81 | } 82 | 83 | WRITE_PERI_REG(UART_FIFO(UART1) , TxChar); 84 | return OK; 85 | } 86 | 87 | /****************************************************************************** 88 | * FunctionName : uart1_write_char 89 | * Description : Internal used function 90 | * Do some special deal while tx char is '\r' or '\n' 91 | * Parameters : char c - character to tx 92 | * Returns : NONE 93 | *******************************************************************************/ 94 | LOCAL void ICACHE_FLASH_ATTR 95 | uart1_write_char(char c) 96 | { 97 | if (c == '\n') { 98 | uart1_tx_one_char('\r'); 99 | uart1_tx_one_char('\n'); 100 | } else if (c == '\r') { 101 | } else { 102 | uart1_tx_one_char(c); 103 | } 104 | } 105 | 106 | /****************************************************************************** 107 | * FunctionName : uart0_rx_intr_handler 108 | * Description : Internal used function 109 | * UART0 interrupt handler, add self handle code inside 110 | * Parameters : void *para - point to ETS_UART_INTR_ATTACH's arg 111 | * Returns : NONE 112 | *******************************************************************************/ 113 | LOCAL void 114 | uart0_rx_intr_handler(void *para) 115 | { 116 | /* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents 117 | * uart1 and uart0 respectively 118 | */ 119 | RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para; 120 | uint8 RcvChar; 121 | 122 | if (UART_RXFIFO_FULL_INT_ST != (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST)) { 123 | return; 124 | } 125 | 126 | WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR); 127 | 128 | while (READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) { 129 | RcvChar = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF; 130 | 131 | /* you can add your handle code below.*/ 132 | 133 | *(pRxBuff->pWritePos) = RcvChar; 134 | 135 | // insert here for get one command line from uart 136 | if (RcvChar == '\r') { 137 | pRxBuff->BuffState = WRITE_OVER; 138 | } 139 | 140 | pRxBuff->pWritePos++; 141 | 142 | if (pRxBuff->pWritePos == (pRxBuff->pRcvMsgBuff + RX_BUFF_SIZE)) { 143 | // overflow ...we may need more error handle here. 144 | pRxBuff->pWritePos = pRxBuff->pRcvMsgBuff ; 145 | } 146 | } 147 | } 148 | 149 | 150 | /****************************************************************************** 151 | * FunctionName : uart0_tx_buffer 152 | * Description : use uart0 to transfer buffer 153 | * Parameters : uint8 *buf - point to send buffer 154 | * uint16 len - buffer len 155 | * Returns : 156 | *******************************************************************************/ 157 | void ICACHE_FLASH_ATTR 158 | uart0_tx_buffer(uint8 *buf, uint16 len) 159 | { 160 | uint16 i; 161 | 162 | for (i = 0; i < len; i++) { 163 | uart_tx_one_char(buf[i]); 164 | } 165 | } 166 | 167 | /****************************************************************************** 168 | * FunctionName : uart_init 169 | * Description : user interface for init uart 170 | * Parameters : UartBautRate uart0_br - uart0 bautrate 171 | * UartBautRate uart1_br - uart1 bautrate 172 | * Returns : NONE 173 | *******************************************************************************/ 174 | void ICACHE_FLASH_ATTR 175 | uart_init(UartBautRate uart0_br, UartBautRate uart1_br) 176 | { 177 | // rom use 74880 baut_rate, here reinitialize 178 | UartDev.baut_rate = uart0_br; 179 | uart_config(UART0); 180 | UartDev.baut_rate = uart1_br; 181 | uart_config(UART1); 182 | ETS_UART_INTR_ENABLE(); 183 | 184 | // install uart1 putc callback 185 | os_install_putc1((void *)uart1_write_char); 186 | } 187 | 188 | -------------------------------------------------------------------------------- /IR_RemoteC/firmware/eagle.flash.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/firmware/eagle.flash.bin -------------------------------------------------------------------------------- /IR_RemoteC/firmware/eagle.irom0text.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/internetofhomethings/ESP8266-IR-Remote-Test-Code/04089ff5c19f26fc1585dc7c7aba1195f9c6e124/IR_RemoteC/firmware/eagle.irom0text.bin -------------------------------------------------------------------------------- /IR_RemoteC/gen_misc.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Please follow below steps(1-5) to generate specific bin(s): 4 | echo STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none) 5 | set input=default 6 | set /p input=enter(0/1/2, default 2): 7 | 8 | if %input% equ 0 ( 9 | set boot=old 10 | ) else ( 11 | if %input% equ 1 ( 12 | set boot=new 13 | ) else ( 14 | set boot=none 15 | ) 16 | ) 17 | 18 | echo boot mode: %boot% 19 | echo. 20 | 21 | echo STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin) 22 | set input=default 23 | set /p input=enter (0/1/2, default 0): 24 | 25 | if %input% equ 1 ( 26 | if %boot% equ none ( 27 | set app=0 28 | echo choose no boot before 29 | echo generate bin: eagle.flash.bin+eagle.irom0text.bin 30 | ) else ( 31 | set app=1 32 | echo generate bin: user1.bin 33 | ) 34 | ) else ( 35 | if %input% equ 2 ( 36 | if %boot% equ none ( 37 | set app=0 38 | echo choose no boot before 39 | echo generate bin: eagle.flash.bin+eagle.irom0text.bin 40 | ) else ( 41 | set app=2 42 | echo generate bin: user2.bin 43 | ) 44 | ) else ( 45 | if %boot% neq none ( 46 | set boot=none 47 | echo ignore boot 48 | ) 49 | set app=0 50 | echo generate bin: eagle.flash.bin+eagle.irom0text.bin 51 | )) 52 | 53 | echo. 54 | 55 | echo STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz) 56 | set input=default 57 | set /p input=enter (0/1/2/3, default 2): 58 | 59 | if %input% equ 0 ( 60 | set spi_speed=20 61 | ) else ( 62 | if %input% equ 1 ( 63 | set spi_speed=26.7 64 | ) else ( 65 | if %input% equ 3 ( 66 | set spi_speed=80 67 | ) else ( 68 | set spi_speed=40 69 | ))) 70 | 71 | echo spi speed: %spi_speed% MHz 72 | echo. 73 | 74 | echo STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT) 75 | set input=default 76 | set /p input=enter (0/1/2/3, default 0): 77 | 78 | if %input% equ 1 ( 79 | set spi_mode=QOUT 80 | ) else ( 81 | if %input% equ 2 ( 82 | set spi_mode=DIO 83 | ) else ( 84 | if %input% equ 3 ( 85 | set spi_mode=DOUT 86 | ) else ( 87 | set spi_mode=QIO 88 | ))) 89 | 90 | echo spi mode: %spi_mode% 91 | echo. 92 | 93 | echo STEP 5: choose spi size(0=256KB, 1=512KB, 2=1024KB, 3=2048KB, 4=4096KB) 94 | set input=default 95 | set /p input=enter (0/1/2/3/4, default 1): 96 | 97 | if %input% equ 0 ( 98 | set spi_size=256 99 | ) else ( 100 | if %input% equ 2 ( 101 | set spi_size=1024 102 | ) else ( 103 | if %input% equ 3 ( 104 | set spi_size=2048 105 | ) else ( 106 | if %input% equ 4 ( 107 | set spi_size=4096 108 | ) else ( 109 | set spi_size=512 110 | )))) 111 | 112 | echo spi size: %spi_size% KB 113 | 114 | touch user/user_main.c 115 | 116 | echo. 117 | echo start... 118 | echo. 119 | 120 | make BOOT=%boot% APP=%app% SPI_SPEED=%spi_speed% SPI_MODE=%spi_mode% SPI_SIZE=%spi_size% 121 | 122 | -------------------------------------------------------------------------------- /IR_RemoteC/gen_misc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Please follow below steps(1-5) to generate specific bin(s):" 4 | echo "STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none)" 5 | echo "enter(0/1/2, default 2):" 6 | read input 7 | 8 | if [ -z "$input" ]; then 9 | boot=none 10 | elif [ $input == 0 ]; then 11 | boot=old 12 | elif [ $input == 1 ]; then 13 | boot=new 14 | else 15 | boot=none 16 | fi 17 | 18 | echo "boot mode: $boot" 19 | echo "" 20 | 21 | echo "STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin)" 22 | echo "enter (0/1/2, default 0):" 23 | read input 24 | 25 | if [ -z "$input" ]; then 26 | if [ $boot != none ]; then 27 | boot=none 28 | echo "ignore boot" 29 | fi 30 | app=0 31 | echo "generate bin: eagle.flash.bin+eagle.irom0text.bin" 32 | elif [ $input == 1 ]; then 33 | if [ $boot == none ]; then 34 | app=0 35 | echo "choose no boot before" 36 | echo "generate bin: eagle.flash.bin+eagle.irom0text.bin" 37 | else 38 | app=1 39 | echo "generate bin: user1.bin" 40 | fi 41 | elif [ $input == 2 ]; then 42 | if [ $boot == none ]; then 43 | app=0 44 | echo "choose no boot before" 45 | echo "generate bin: eagle.flash.bin+eagle.irom0text.bin" 46 | else 47 | app=2 48 | echo "generate bin: user2.bin" 49 | fi 50 | else 51 | if [ $boot != none ]; then 52 | boot=none 53 | echo "ignore boot" 54 | fi 55 | app=0 56 | echo "generate bin: eagle.flash.bin+eagle.irom0text.bin" 57 | fi 58 | 59 | echo "" 60 | 61 | echo "STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz)" 62 | echo "enter (0/1/2/3, default 2):" 63 | read input 64 | 65 | if [ -z "$input" ]; then 66 | spi_speed=40 67 | elif [ $input == 0 ]; then 68 | spi_speed=20 69 | elif [ $input == 1 ]; then 70 | spi_speed=26.7 71 | elif [ $input == 3 ]; then 72 | spi_speed=80 73 | else 74 | spi_speed=40 75 | fi 76 | 77 | echo "spi speed: $spi_speed MHz" 78 | echo "" 79 | 80 | echo "STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT)" 81 | echo "enter (0/1/2/3, default 0):" 82 | read input 83 | 84 | if [ -z "$input" ]; then 85 | spi_mode=QIO 86 | elif [ $input == 1 ]; then 87 | spi_mode=QOUT 88 | elif [ $input == 2 ]; then 89 | spi_mode=DIO 90 | elif [ $input == 3 ]; then 91 | spi_mode=DOUT 92 | else 93 | spi_mode=QIO 94 | fi 95 | 96 | echo "spi mode: $spi_mode" 97 | echo "" 98 | 99 | echo "STEP 5: choose spi size(0=256KB, 1=512KB, 2=1024KB, 3=2048KB, 4=4096KB)" 100 | echo "enter (0/1/2/3/4, default 1):" 101 | read input 102 | 103 | if [ -z "$input" ]; then 104 | spi_size=512 105 | elif [ $input == 0 ]; then 106 | spi_size=256 107 | elif [ $input == 2 ]; then 108 | spi_size=1024 109 | elif [ $input == 3 ]; then 110 | spi_size=2048 111 | elif [ $input == 4 ]; then 112 | spi_size=4096 113 | else 114 | spi_size=512 115 | fi 116 | 117 | echo "spi size: $spi_size KB" 118 | echo "" 119 | 120 | touch user/user_main.c 121 | 122 | echo "" 123 | echo "start..." 124 | echo "" 125 | 126 | make COMPILE=gcc BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE=$spi_size 127 | -------------------------------------------------------------------------------- /IR_RemoteC/include/driver/EspIRremote.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote 3 | * Version 0.1 July, 2009 4 | * Copyright 2009 Ken Shirriff 5 | * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com 6 | * Edited by Mitra to add new controller SANYO 7 | * 8 | * Interrupt code based on NECIRrcv by Joe Knapp 9 | * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 10 | * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ 11 | * 12 | * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) 13 | * Ported to ESP8266 Espressif SDK Platform by Dave St. Aubin (internetofhomethings.com) 14 | */ 15 | 16 | #ifndef IRremote_h 17 | #define IRremote_h 18 | #include "ets_sys.h" 19 | #include "osapi.h" 20 | #include 21 | #include "c_types.h" 22 | 23 | /*Definition of GPIO PIN params, for GPIO initialization*/ 24 | #define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_MTDI_U 25 | #define PWM_0_OUT_IO_NUM 12 26 | #define PWM_0_OUT_IO_FUNC FUNC_GPIO12 27 | 28 | 29 | // The following are compile-time library options. 30 | // If you change them, recompile the library. 31 | // If DEBUG is defined, a lot of debugging output will be printed during decoding. 32 | // TEST must be defined for the IRtest unittests to work. It will make some 33 | // methods virtual, which will be slightly slower, which is why it is optional. 34 | // #define DEBUG 35 | // #define TEST 36 | 37 | // class decode_results types 38 | typedef struct decode_results_ { 39 | int decode_type; // NEC, SONY, RC5, UNKNOWN 40 | unsigned int panasonicAddress; // This is only used for decoding Panasonic data 41 | unsigned long value; // Decoded value 42 | int bits; // Number of bits in decoded value 43 | volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks 44 | int rawlen; // Number of records in rawbuf. 45 | } decode_results; 46 | 47 | // class decode_results variables 48 | int decode_type; // NEC, SONY, RC5, UNKNOWN 49 | unsigned int panasonicAddress; // This is only used for decoding Panasonic data 50 | unsigned long value; // Decoded value 51 | int bits; // Number of bits in decoded value 52 | volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks 53 | int rawlen; // Number of records in rawbuf. 54 | 55 | // main class for receiving IR class IRrecv variables & functions 56 | os_timer_t ir_timer; 57 | void ICACHE_FLASH_ATTR IRrecv(int recvpin); 58 | void ICACHE_FLASH_ATTR blink16(int blinkflag); 59 | int ICACHE_FLASH_ATTR decode(decode_results *results); 60 | void ICACHE_FLASH_ATTR enableIRIn(void); 61 | void ICACHE_FLASH_ATTR resume(void); 62 | // These are called by decode 63 | int ICACHE_FLASH_ATTR getRClevel(decode_results *results, int *offset, int *used, int t1); 64 | long ICACHE_FLASH_ATTR decodeNEC(decode_results *results); 65 | //long decodeSony(decode_results *results); 66 | long ICACHE_FLASH_ATTR decodeSanyo(decode_results *results); 67 | //long decodeMitsubishi(decode_results *results); 68 | //long decodeRC5(decode_results *results); 69 | //long decodeRC6(decode_results *results); 70 | //long decodePanasonic(decode_results *results); 71 | //long decodeJVC(decode_results *results); 72 | long decodeHash(decode_results *results); 73 | int compare(unsigned int oldval, unsigned int newval); 74 | 75 | // class Values for decode_type 76 | #define NEC 1 77 | #define SONY 2 78 | #define RC5 3 79 | #define RC6 4 80 | #define DISH 5 81 | #define SHARP 6 82 | #define PANASONIC 7 83 | #define JVC 8 84 | #define SANYO 9 85 | #define MITSUBISHI 10 86 | #define UNKNOWN -1 87 | 88 | // Decoded value for NEC when a repeat code is received 89 | #define REPEAT 0xffffffff 90 | 91 | 92 | 93 | // Only used for testing; can remove virtual for shorter code 94 | #ifdef TEST 95 | #define VIRTUAL virtual 96 | #else 97 | #define VIRTUAL 98 | #endif 99 | // Some useful constants 100 | 101 | #define USECPERTICK 50 // microseconds per clock interrupt tick 102 | #define RAWBUF 100 // Length of raw duration buffer 103 | 104 | // Marks tend to be 100us too long, and spaces 100us too short 105 | // when received due to sensor lag. 106 | #define MARK_EXCESS 100 107 | 108 | #endif 109 | 110 | //class IRsend 111 | void ICACHE_FLASH_ATTR IRsend(void); 112 | void ICACHE_FLASH_ATTR sendNEC(unsigned long data, int nbits); 113 | void ICACHE_FLASH_ATTR sendSony(unsigned long data, int nbits); 114 | void ICACHE_FLASH_ATTR sendRaw(unsigned int buf[], int len, int hz); 115 | void ICACHE_FLASH_ATTR sendRC5(unsigned long data, int nbits); 116 | void ICACHE_FLASH_ATTR sendRC6(unsigned long data, int nbits); 117 | // private: 118 | void ICACHE_FLASH_ATTR enableIROut(int khz); 119 | void ICACHE_FLASH_ATTR mark(int usec); 120 | void ICACHE_FLASH_ATTR space(int usec); 121 | 122 | 123 | void ICACHE_FLASH_ATTR ir_cb(void *arg); 124 | -------------------------------------------------------------------------------- /IR_RemoteC/include/driver/EspIRremoteTools.h: -------------------------------------------------------------------------------- 1 | #ifndef IRREMOTETOOLS_H 2 | #define IRREMOTETOOLS_H 3 | 4 | extern void beginIRremote(); 5 | 6 | extern bool IRrecived(); 7 | 8 | extern void resumeIRremote(); 9 | 10 | extern unsigned long getIRresult(); 11 | 12 | #endif -------------------------------------------------------------------------------- /IR_RemoteC/include/driver/dht22.h: -------------------------------------------------------------------------------- 1 | /* 2 | Driver for the temperature and humidity sensor DHT11 and DHT22 3 | Official repository: https://github.com/CHERTS/esp8266-dht11_22 4 | 5 | Copyright (C) 2014 Mikhail Grigorev (CHERTS) 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License along 18 | with this program; if not, write to the Free Software Foundation, Inc., 19 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | #ifndef __DHT22_H__ 23 | #define __DHT22_H__ 24 | 25 | #include "ets_sys.h" 26 | #include "osapi.h" 27 | 28 | typedef enum { 29 | DHT11, 30 | DHT22 31 | } DHTType; 32 | 33 | typedef struct { 34 | float temperature; 35 | float humidity; 36 | } DHT_Sensor_Data; 37 | 38 | typedef struct { 39 | uint8_t pin; 40 | DHTType type; 41 | } DHT_Sensor; 42 | 43 | #define DHT_MAXTIMINGS 10000 44 | #define DHT_BREAKTIME 20 45 | #define DHT_MAXCOUNT 32000 46 | //#define DHT_DEBUG true 47 | 48 | bool ICACHE_FLASH_ATTR DHTInit(DHT_Sensor *sensor); 49 | bool ICACHE_FLASH_ATTR DHTRead(DHT_Sensor *sensor, DHT_Sensor_Data* output); 50 | char* ICACHE_FLASH_ATTR DHTFloat2String(char* buffer, float value); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /IR_RemoteC/include/driver/ds18b20.h: -------------------------------------------------------------------------------- 1 | #ifndef __DS18B20_H__ 2 | #define __DS18B20_H__ 3 | 4 | #include "ets_sys.h" 5 | #include "osapi.h" 6 | #include "gpio.h" 7 | 8 | #define DS18B20_MUX PERIPHS_IO_MUX_GPIO4_U 9 | #define DS18B20_FUNC FUNC_GPIO4 10 | #define DS18B20_PIN 4 11 | 12 | #define DS1820_WRITE_SCRATCHPAD 0x4E 13 | #define DS1820_READ_SCRATCHPAD 0xBE 14 | #define DS1820_COPY_SCRATCHPAD 0x48 15 | #define DS1820_READ_EEPROM 0xB8 16 | #define DS1820_READ_PWRSUPPLY 0xB4 17 | #define DS1820_SEARCHROM 0xF0 18 | #define DS1820_SKIP_ROM 0xCC 19 | #define DS1820_READROM 0x33 20 | #define DS1820_MATCHROM 0x55 21 | #define DS1820_ALARMSEARCH 0xEC 22 | #define DS1820_CONVERT_T 0x44 23 | 24 | static uint16_t oddparity[16] = {0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0}; 25 | 26 | void ds_init(); 27 | int ds_search(uint8_t *addr); 28 | void select(const uint8_t rom[8]); 29 | void skip(); 30 | void reset_search(); 31 | uint8_t ds_reset(void); 32 | void ds_write(uint8_t v, int power); 33 | void write_bit(int v); 34 | uint8_t ds_read(); 35 | int read_bit(void); 36 | uint8_t crc8(const uint8_t *addr, uint8_t len); 37 | uint16_t crc16(const uint16_t *data, const uint16_t len); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /IR_RemoteC/include/driver/gpio16.h: -------------------------------------------------------------------------------- 1 | /* 2 | Driver for GPIO 3 | Official repository: https://github.com/CHERTS/esp8266-gpio16 4 | 5 | Copyright (C) 2015 Mikhail Grigorev (CHERTS) 6 | 7 | Pin number: 8 | ----------- 9 | Pin 0 = GPIO16 10 | Pin 1 = GPIO5 11 | Pin 2 = GPIO4 12 | Pin 3 = GPIO0 13 | Pin 4 = GPIO2 14 | Pin 5 = GPIO14 15 | Pin 6 = GPIO12 16 | Pin 7 = GPIO13 17 | Pin 8 = GPIO15 18 | Pin 9 = GPIO3 19 | Pin 10 = GPIO1 20 | Pin 11 = GPIO9 21 | Pin 12 = GPIO10 22 | 23 | This program is free software; you can redistribute it and/or modify 24 | it under the terms of the GNU General Public License as published by 25 | the Free Software Foundation; either version 2 of the License, or 26 | (at your option) any later version. 27 | 28 | This program is distributed in the hope that it will be useful, 29 | but WITHOUT ANY WARRANTY; without even the implied warranty of 30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 31 | GNU General Public License for more details. 32 | 33 | You should have received a copy of the GNU General Public License along 34 | with this program; if not, write to the Free Software Foundation, Inc., 35 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 36 | */ 37 | 38 | #ifndef __GPIO16_H__ 39 | #define __GPIO16_H__ 40 | 41 | #include "gpio.h" 42 | 43 | #define GPIO_PIN_NUM 13 44 | #define GPIO_INTERRUPT_ENABLE 1 45 | 46 | #define GPIO_FLOAT 0 47 | #define GPIO_PULLUP 1 48 | #define GPIO_PULLDOWN 2 49 | 50 | #define GPIO_INPUT 0 51 | #define GPIO_OUTPUT 1 52 | #define GPIO_INT 2 53 | 54 | /* GPIO interrupt handler */ 55 | #ifdef GPIO_INTERRUPT_ENABLE 56 | typedef void (* gpio_intr_handler)(unsigned pin, unsigned level); 57 | #endif 58 | 59 | void gpio16_output_conf(void); 60 | void gpio16_output_set(uint8 value); 61 | void gpio16_input_conf(void); 62 | uint8 gpio16_input_get(void); 63 | int set_gpio_mode(unsigned pin, unsigned mode, unsigned pull); 64 | int gpio_write(unsigned pin, unsigned level); 65 | int gpio_read(unsigned pin); 66 | #ifdef GPIO_INTERRUPT_ENABLE 67 | void gpio_intr_attach(gpio_intr_handler cb); 68 | int gpio_intr_deattach(unsigned pin); 69 | int gpio_intr_init(unsigned pin, GPIO_INT_TYPE type); 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /IR_RemoteC/include/driver/i2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | I2C driver for the ESP8266 3 | Copyright (C) 2014 Rudy Hardeman (zarya) 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program; if not, write to the Free Software Foundation, Inc., 17 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | #ifndef __I2C_H__ 21 | #define __I2C_H__ 22 | 23 | #include "ets_sys.h" 24 | #include "osapi.h" 25 | #include "gpio.h" 26 | 27 | #define I2C_SLEEP_TIME 10 28 | 29 | // SDA on GPIO13 30 | #define I2C_SDA_MUX PERIPHS_IO_MUX_MTCK_U 31 | #define I2C_SDA_FUNC FUNC_GPIO13 32 | #define I2C_SDA_PIN 13 33 | 34 | // SCK on GPIO14 35 | //#define I2C_SCK_MUX PERIPHS_IO_MUX_MTMS_U 36 | //#define I2C_SCK_FUNC FUNC_GPIO14 37 | //#define I2C_SCK_PIN 14 38 | 39 | //SCK on GPIO12 (untested) 40 | #define I2C_SCK_MUX PERIPHS_IO_MUX_MTDI_U 41 | #define I2C_SCK_PIN 12 42 | #define I2C_SCK_FUNC FUNC_GPIO12 43 | 44 | #define i2c_read() GPIO_INPUT_GET(GPIO_ID_PIN(I2C_SDA_PIN)); 45 | 46 | void i2c_init(void); 47 | void i2c_start(void); 48 | void i2c_stop(void); 49 | void i2c_send_ack(uint8 state); 50 | uint8 i2c_check_ack(void); 51 | uint8 i2c_readByte(void); 52 | void i2c_writeByte(uint8 data); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /IR_RemoteC/include/driver/i2c_bmp180.h: -------------------------------------------------------------------------------- 1 | /* 2 | The driver for the temperature sensor and pressure BMP180 3 | Official repository: https://github.com/CHERTS/esp8266-i2c_bmp180 4 | Base on https://github.com/reaper7/esp8266_i2c_bmp180 5 | This driver depends on the I2C driver https://github.com/zarya/esp8266_i2c_driver/ 6 | 7 | Copyright (C) 2014 reaper7 8 | Copyright (C) 2014 Mikhail Grigorev (CHERTS) 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License along 21 | with this program; if not, write to the Free Software Foundation, Inc., 22 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | 25 | #ifndef __I2C_BMP180_H 26 | #define __I2C_BMP180_H 27 | 28 | #include "c_types.h" 29 | #include "ets_sys.h" 30 | #include "osapi.h" 31 | 32 | #define CONVERSION_TIME 5 33 | #define BMP180_W 0xEE 34 | #define BMP180_R 0xEF 35 | #define BMP180_CHIP_ID 0x55 36 | #define BMP180_VERSION_REG 0xD1 37 | #define BMP180_CHIP_ID_REG 0xD0 38 | #define BMP180_CTRL_REG 0xF4 39 | #define BMP180_DATA_REG 0xF6 40 | #define BMP_CMD_MEASURE_TEMP 0x2E // Max conversion time 4.5ms 41 | #define BMP_CMD_MEASURE_PRESSURE_0 0x34 // Max conversion time 4.5ms (OSS = 0) 42 | //#define BMP_CMD_MEASURE_PRESSURE_1 0x74 // Max conversion time 7.5ms (OSS = 1) 43 | //#define BMP_CMD_MEASURE_PRESSURE_2 0xB4 // Max conversion time 13.5ms (OSS = 2) 44 | //#define BMP_CMD_MEASURE_PRESSURE_3 0xF4 // Max conversion time 25.5ms (OSS = 3) 45 | #define MYALTITUDE 167.6 46 | 47 | #define BMP180_DEBUG 1 48 | 49 | enum PRESSURE_RESOLUTION { 50 | OSS_0 = 0, 51 | OSS_1, 52 | OSS_2, 53 | OSS_3 54 | }; 55 | 56 | bool BMP180_Init(void); 57 | int32_t BMP180_GetTemperature(); 58 | int32_t BMP180_GetPressure(enum PRESSURE_RESOLUTION resolution); 59 | int32_t BMP180_CalcAltitude(int32_t pressure); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /IR_RemoteC/include/driver/i2c_master.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_MASTER_H__ 2 | #define __I2C_MASTER_H__ 3 | 4 | #define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO2_U 5 | #define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_MTMS_U 6 | #define I2C_MASTER_SDA_GPIO 2 7 | #define I2C_MASTER_SCL_GPIO 14 8 | #define I2C_MASTER_SDA_FUNC FUNC_GPIO2 9 | #define I2C_MASTER_SCL_FUNC FUNC_GPIO14 10 | 11 | //#define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO2_U 12 | //#define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_GPIO0_U 13 | //#define I2C_MASTER_SDA_GPIO 2 14 | //#define I2C_MASTER_SCL_GPIO 0 15 | //#define I2C_MASTER_SDA_FUNC FUNC_GPIO2 16 | //#define I2C_MASTER_SCL_FUNC FUNC_GPIO0 17 | 18 | #if 0 19 | #define I2C_MASTER_GPIO_SET(pin) \ 20 | gpio_output_set(1< 5 | //#include 6 | /* 7 | //Missing function prototypes in include folders. Gcc will warn on these if we don't define 'em anywhere. 8 | //MOST OF THESE ARE GUESSED! but they seem to swork and shut up the compiler. 9 | typedef struct espconn espconn; 10 | 11 | int atoi(const char *nptr); 12 | void ets_install_putc1(void *routine); 13 | void ets_isr_attach(int intr, void *handler, void *arg); 14 | void ets_isr_mask(unsigned intr); 15 | void ets_isr_unmask(unsigned intr); 16 | int ets_memcmp(const void *s1, const void *s2, size_t n); 17 | void *ets_memcpy(void *dest, const void *src, size_t n); 18 | void *ets_memset(void *s, int c, size_t n); 19 | int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3))); 20 | int ets_str2macaddr(void *, void *); 21 | int ets_strcmp(const char *s1, const char *s2); 22 | char *ets_strcpy(char *dest, const char *src); 23 | size_t ets_strlen(const char *s); 24 | int ets_strncmp(const char *s1, const char *s2, int len); 25 | char *ets_strncpy(char *dest, const char *src, size_t n); 26 | char *ets_strstr(const char *haystack, const char *needle); 27 | */ 28 | void ets_timer_arm_new(ETSTimer *a, int b, int c, int isMstimer); 29 | void ets_timer_disarm(ETSTimer *a); 30 | void ets_timer_setfn(ETSTimer *t, ETSTimerFunc *fn, void *parg); 31 | void os_timer_arm_us (ETSTimer *ptimer,uint32_t microseconds,bool repeat_flag); 32 | 33 | /* 34 | void ets_update_cpu_frequency(int freqmhz); 35 | int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 36 | int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4))); 37 | int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 38 | void pvPortFree(void *ptr); 39 | void *pvPortMalloc(size_t xWantedSize); 40 | void *pvPortZalloc(size_t); 41 | void uart_div_modify(int no, unsigned int freq); 42 | void vPortFree(void *ptr); 43 | void *vPortMalloc(size_t xWantedSize); 44 | uint8 wifi_get_opmode(void); 45 | uint32 system_get_time(); 46 | int os_random(); 47 | int rand(void); 48 | void ets_bzero(void *s, size_t n); 49 | void ets_delay_us(int ms); 50 | */ 51 | #endif 52 | -------------------------------------------------------------------------------- /IR_RemoteC/include/ssl/cert.h: -------------------------------------------------------------------------------- 1 | unsigned char default_certificate[] = { 2 | 0x30, 0x82, 0x01, 0x82, 0x30, 0x81, 0xec, 0x02, 0x09, 0x00, 0x88, 0xf2, 3 | 0x5f, 0x46, 0x12, 0x2e, 0x3d, 0x3a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 4 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x1c, 0x31, 5 | 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x11, 0x77, 0x77, 6 | 0x77, 0x2e, 0x65, 0x73, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x66, 0x2e, 7 | 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x36, 0x32, 8 | 0x34, 0x31, 0x30, 0x32, 0x32, 0x33, 0x33, 0x5a, 0x17, 0x0d, 0x32, 0x38, 9 | 0x30, 0x33, 0x30, 0x32, 0x31, 0x30, 0x32, 0x32, 0x33, 0x33, 0x5a, 0x30, 10 | 0x34, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x09, 11 | 0x65, 0x73, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x66, 0x31, 0x1e, 0x30, 12 | 0x1c, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x15, 0x65, 0x73, 0x70, 0x72, 13 | 0x65, 0x73, 0x73, 0x69, 0x66, 0x20, 0x49, 0x6f, 0x54, 0x20, 0x70, 0x72, 14 | 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 15 | 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 16 | 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, 0xb9, 0x83, 0x30, 0xca, 0xfb, 0xec, 17 | 0x11, 0x9e, 0x94, 0xb7, 0x89, 0xf2, 0x84, 0x2c, 0xda, 0xe1, 0x9a, 0x53, 18 | 0x3a, 0x1b, 0x6e, 0xc9, 0x85, 0x81, 0xf9, 0xa3, 0x41, 0xdb, 0xe2, 0x82, 19 | 0x3b, 0xfa, 0x80, 0x22, 0x3b, 0x81, 0x6d, 0x25, 0x73, 0x7e, 0xf6, 0x49, 20 | 0xcc, 0x69, 0x3c, 0x6c, 0xd8, 0x05, 0xfb, 0x92, 0x02, 0xcf, 0x19, 0x2a, 21 | 0x10, 0x7d, 0x69, 0x7a, 0xd8, 0x9d, 0xd3, 0xcf, 0x6c, 0xef, 0x02, 0x03, 22 | 0x01, 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 23 | 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0x2d, 0x63, 24 | 0x58, 0x21, 0xe3, 0x8b, 0x37, 0x0d, 0x28, 0x68, 0x11, 0x0e, 0x4d, 0xdd, 25 | 0xf3, 0xea, 0xdb, 0xec, 0xd7, 0x09, 0x47, 0x2c, 0xa1, 0xd8, 0xd1, 0x71, 26 | 0x83, 0x11, 0xb4, 0x17, 0xbc, 0x83, 0xea, 0x5a, 0xd6, 0x73, 0x02, 0x25, 27 | 0x87, 0x01, 0x76, 0xfc, 0x59, 0x1a, 0xcf, 0xd9, 0x49, 0xc9, 0xf9, 0x1f, 28 | 0x5c, 0x3b, 0x24, 0x6a, 0x5c, 0xa5, 0xca, 0xe6, 0x5d, 0x34, 0x5b, 0x5f, 29 | 0xcf, 0x56, 0x9c, 0x71, 0xd2, 0x6b, 0xdd, 0x1f, 0x15, 0xae, 0x4d, 0xf1, 30 | 0xca, 0x35, 0xc8, 0xdd, 0x93, 0x1b, 0x58, 0x1e, 0x94, 0x08, 0xcf, 0xa0, 31 | 0x20, 0xb9, 0x75, 0xa5, 0x4c, 0x77, 0xf5, 0x7f, 0xed, 0xd5, 0xcd, 0x53, 32 | 0xaa, 0x87, 0xa6, 0x3c, 0xf5, 0x72, 0xd8, 0xd2, 0xb0, 0xf7, 0x11, 0xb0, 33 | 0x0e, 0xe9, 0x41, 0xd6, 0x8e, 0xd9, 0x07, 0xf8, 0xed, 0xf8, 0x67, 0x7f, 34 | 0x28, 0x18, 0xf0, 0x1b, 0x29, 0x11 35 | }; 36 | unsigned int default_certificate_len = 390; 37 | -------------------------------------------------------------------------------- /IR_RemoteC/include/ssl/private_key.h: -------------------------------------------------------------------------------- 1 | unsigned char default_private_key[] = { 2 | 0x30, 0x82, 0x01, 0x3a, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xb9, 0x83, 3 | 0x30, 0xca, 0xfb, 0xec, 0x11, 0x9e, 0x94, 0xb7, 0x89, 0xf2, 0x84, 0x2c, 4 | 0xda, 0xe1, 0x9a, 0x53, 0x3a, 0x1b, 0x6e, 0xc9, 0x85, 0x81, 0xf9, 0xa3, 5 | 0x41, 0xdb, 0xe2, 0x82, 0x3b, 0xfa, 0x80, 0x22, 0x3b, 0x81, 0x6d, 0x25, 6 | 0x73, 0x7e, 0xf6, 0x49, 0xcc, 0x69, 0x3c, 0x6c, 0xd8, 0x05, 0xfb, 0x92, 7 | 0x02, 0xcf, 0x19, 0x2a, 0x10, 0x7d, 0x69, 0x7a, 0xd8, 0x9d, 0xd3, 0xcf, 8 | 0x6c, 0xef, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x1d, 0x13, 0x92, 9 | 0xf2, 0x3d, 0xca, 0x22, 0x78, 0xd8, 0x96, 0x6b, 0xe8, 0xb7, 0x0e, 0xd0, 10 | 0xbf, 0xcb, 0x90, 0x7f, 0xeb, 0x0c, 0xd2, 0x49, 0x3a, 0xb6, 0x06, 0x00, 11 | 0xac, 0x96, 0x34, 0x13, 0x72, 0x4b, 0x8c, 0xd2, 0xb9, 0x35, 0xf5, 0x64, 12 | 0x18, 0xb2, 0x47, 0x5b, 0x9f, 0xbb, 0xf2, 0x5b, 0x2f, 0x66, 0x78, 0x2d, 13 | 0x0a, 0x76, 0x44, 0xc5, 0x4f, 0xdb, 0x7d, 0x13, 0xcf, 0xa5, 0x08, 0xdc, 14 | 0x01, 0x02, 0x21, 0x00, 0xdf, 0x9a, 0x89, 0xd0, 0xef, 0x23, 0xcf, 0x12, 15 | 0xac, 0x8a, 0x63, 0x1a, 0x8c, 0xc0, 0x3f, 0xf4, 0x38, 0x52, 0x3c, 0x9f, 16 | 0x19, 0x0a, 0x37, 0xd2, 0xcb, 0x5d, 0xeb, 0xb6, 0x2a, 0x33, 0xb0, 0x91, 17 | 0x02, 0x21, 0x00, 0xd4, 0x63, 0xd9, 0x6a, 0x18, 0x5b, 0xe8, 0xa8, 0x57, 18 | 0x4d, 0xd1, 0x9a, 0xa8, 0xd7, 0xe1, 0x65, 0x75, 0xb3, 0xb9, 0x5c, 0x94, 19 | 0x14, 0xca, 0x98, 0x41, 0x47, 0x9c, 0x0a, 0x22, 0x38, 0x05, 0x7f, 0x02, 20 | 0x20, 0x6a, 0xce, 0xfd, 0xef, 0xe0, 0x9b, 0x61, 0x49, 0x91, 0x43, 0x95, 21 | 0x6d, 0x54, 0x38, 0x6d, 0x14, 0x32, 0x67, 0x0d, 0xf0, 0x0d, 0x5c, 0xf5, 22 | 0x27, 0x6a, 0xdf, 0x55, 0x3d, 0xb1, 0xd0, 0xf9, 0x11, 0x02, 0x21, 0x00, 23 | 0xba, 0x94, 0xa0, 0xf9, 0xb0, 0x3e, 0x85, 0x8b, 0xe5, 0x6e, 0x4a, 0x95, 24 | 0x88, 0x80, 0x65, 0xd5, 0x00, 0xea, 0x8b, 0x0b, 0x46, 0x57, 0x61, 0x87, 25 | 0x11, 0xc9, 0xfb, 0xcd, 0x77, 0x34, 0x29, 0xb7, 0x02, 0x20, 0x06, 0x8d, 26 | 0x41, 0x11, 0x47, 0x93, 0xcb, 0xad, 0xda, 0x5d, 0xe1, 0x9d, 0x49, 0x8d, 27 | 0xe0, 0xab, 0x48, 0xe6, 0x18, 0x28, 0x4a, 0x94, 0xae, 0xf9, 0xad, 0xc5, 28 | 0x5b, 0x0b, 0x15, 0xc6, 0x73, 0x17 29 | }; 30 | unsigned int default_private_key_len = 318; 31 | -------------------------------------------------------------------------------- /IR_RemoteC/include/user_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_CONFIG_H__ 2 | #define __USER_CONFIG_H__ 3 | 4 | #define USE_WIFI_MODE STATION_MODE 5 | #define WIFI_CLIENTSSID "YOURSSID" 6 | #define WIFI_CLIENTPASSWORD "YOURPW" 7 | #define WIFI_AP_NAME "ESP8266N4" 8 | #define WIFI_AP_PASSWORD "00000000" 9 | #define TCPSERVERIP "192.168.0.106" 10 | #define TCPSERVERPORT 9703 11 | #define PLATFORM_DEBUG true 12 | #define DNS_SVR "YourDNS" 13 | #define DNS_SVR_NAME "iot" 14 | #define DNS_TXTDATA "version = now" 15 | 16 | #define BLINKLED 5 17 | //#define LWIP_DEBUG true 18 | 19 | #define USE_OPTIMIZE_PRINTF 20 | 21 | 22 | #define ESP_PLATFORM 1 23 | #define LEWEI_PLATFORM 0 24 | 25 | #define USE_OPTIMIZE_PRINTF 26 | 27 | #if ESP_PLATFORM 28 | #define PLUG_DEVICE 0 29 | #define LIGHT_DEVICE 0 30 | #define SENSOR_DEVICE 1 31 | 32 | #if SENSOR_DEVICE 33 | #define HUMITURE_SUB_DEVICE 1 34 | #define FLAMMABLE_GAS_SUB_DEVICE 0 35 | #endif 36 | 37 | //#define SERVER_SSL_ENABLE 38 | //#define CLIENT_SSL_ENABLE 39 | //#define UPGRADE_SSL_ENABLE 40 | 41 | #define USE_DNS 42 | 43 | #ifdef USE_DNS 44 | #define ESP_DOMAIN "iot.espressif.cn" 45 | //#define ESP_DOMAIN "google-public-dns-a.google.com" 46 | //#define ESP_DOMAIN "google-public-dns-b.google.com" 47 | #endif 48 | 49 | #define SOFTAP_ENCRYPT 50 | 51 | #ifdef SOFTAP_ENCRYPT 52 | #define PASSWORD "v*%W>L<@i&Nxe!" 53 | #endif 54 | 55 | #if SENSOR_DEVICE 56 | #define SENSOR_DEEP_SLEEP 57 | 58 | #if HUMITURE_SUB_DEVICE 59 | #define SENSOR_DEEP_SLEEP_TIME 30000000 60 | #elif FLAMMABLE_GAS_SUB_DEVICE 61 | #define SENSOR_DEEP_SLEEP_TIME 60000000 62 | #endif 63 | #endif 64 | 65 | #if LIGHT_DEVICE 66 | #define USE_US_TIMER 67 | #endif 68 | 69 | #if PLUG_DEVICE || LIGHT_DEVICE 70 | #define BEACON_TIMEOUT 150000000 71 | #define BEACON_TIME 50000 72 | #endif 73 | 74 | #define AP_CACHE 1 75 | 76 | #if AP_CACHE 77 | #define AP_CACHE_NUMBER 5 78 | #endif 79 | 80 | #elif LEWEI_PLATFORM 81 | #endif 82 | 83 | #endif 84 | 85 | -------------------------------------------------------------------------------- /IR_RemoteC/include/user_devicefind.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_DEVICEFIND_H__ 2 | #define __USER_DEVICEFIND_H__ 3 | 4 | void user_devicefind_init(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /IR_RemoteC/include/user_esp_platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_DEVICE_H__ 2 | #define __USER_DEVICE_H__ 3 | 4 | /* NOTICE---this is for 512KB spi flash. 5 | * you can change to other sector if you use other size spi flash. */ 6 | #define ESP_PARAM_START_SEC 0x3C 7 | 8 | #define ESP_PARAM_SAVE_0 1 9 | #define ESP_PARAM_SAVE_1 2 10 | #define ESP_PARAM_FLAG 3 11 | 12 | #define packet_size (2 * 1024) 13 | 14 | #define token_size 41 15 | 16 | struct esp_platform_saved_param { 17 | uint8 devkey[40]; 18 | uint8 token[40]; 19 | uint8 activeflag; 20 | uint8 pad[3]; 21 | }; 22 | 23 | struct esp_platform_sec_flag_param { 24 | uint8 flag; 25 | uint8 pad[3]; 26 | }; 27 | 28 | enum { 29 | DEVICE_CONNECTING = 40, 30 | DEVICE_ACTIVE_DONE, 31 | DEVICE_ACTIVE_FAIL, 32 | DEVICE_CONNECT_SERVER_FAIL 33 | }; 34 | struct dhcp_client_info { 35 | ip_addr_t ip_addr; 36 | ip_addr_t netmask; 37 | ip_addr_t gw; 38 | uint8 flag; 39 | uint8 pad[3]; 40 | }; 41 | #endif 42 | -------------------------------------------------------------------------------- /IR_RemoteC/include/user_esp_platform_timer.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_DEVICEFIND_H__ 2 | #define __USER_DEVICEFIND_H__ 3 | 4 | void user_platform_timer_start(char* pbuffer, struct espconn *pespconn); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /IR_RemoteC/include/user_iot_version.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_IOT_VERSION_H__ 2 | #define __USER_IOT_VERSION_H__ 3 | 4 | #include "user_config.h" 5 | 6 | #define IOT_VERSION_MAJOR 1U 7 | #define IOT_VERSION_MINOR 0U 8 | #define IOT_VERSION_REVISION 2U 9 | 10 | #define VERSION_NUM (IOT_VERSION_MAJOR * 1000 + IOT_VERSION_MINOR * 100 + IOT_VERSION_REVISION) 11 | 12 | //#define VERSION_TYPE "b" 13 | #define VERSION_TYPE "v" 14 | 15 | #if LIGHT_DEVICE 16 | #define device_type 45772 17 | #elif PLUG_DEVICE 18 | #define device_type 23701 19 | #elif SENSOR_DEVICE 20 | #define device_type 12335 21 | #endif 22 | 23 | 24 | #define ONLINE_UPGRADE 0 25 | #define LOCAL_UPGRADE 0 26 | #define ALL_UPGRADE 1 27 | #define NONE_UPGRADE 0 28 | 29 | #if ONLINE_UPGRADE 30 | #define UPGRADE_FALG "O" 31 | #elif LOCAL_UPGRADE 32 | #define UPGRADE_FALG "l" 33 | #elif ALL_UPGRADE 34 | #define UPGRADE_FALG "a" 35 | #elif NONE_UPGRADE 36 | #define UPGRADE_FALG "n" 37 | #endif 38 | 39 | #define IOT_VERSION 40 | 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /IR_RemoteC/include/user_json.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_JSON_H__ 2 | #define __USER_JSON_H__ 3 | 4 | #include "json/jsonparse.h" 5 | #include "json/jsontree.h" 6 | 7 | #define jsonSize 2*1024 8 | 9 | void json_parse(struct jsontree_context *json, char *ptrJSONMessage); 10 | 11 | void json_ws_send(struct jsontree_value *tree, const char *path, char *pbuf); 12 | 13 | int json_putchar(int c); 14 | 15 | struct jsontree_value *find_json_path(struct jsontree_context *json, const char *path); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /IR_RemoteC/include/user_light.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_LIGHT_H__ 2 | #define __USER_LIGHT_H__ 3 | 4 | #include "driver/pwm.h" 5 | 6 | /* NOTICE---this is for 512KB spi flash. 7 | * you can change to other sector if you use other size spi flash. */ 8 | #define PRIV_PARAM_START_SEC 0x3C 9 | 10 | #define PRIV_PARAM_SAVE 0 11 | 12 | #define LIGHT_RED 0 13 | #define LIGHT_GREEN 1 14 | #define LIGHT_BLUE 2 15 | #define LIGHE_LEVEL 3 16 | 17 | struct light_saved_param { 18 | uint16 pwm_freq; 19 | uint8 pwm_duty[PWM_CHANNEL]; 20 | uint8 pad[6-PWM_CHANNEL]; 21 | }; 22 | 23 | void user_light_init(void); 24 | uint8 user_light_get_duty(uint8 channel); 25 | void user_light_set_duty(uint8 duty, uint8 channel); 26 | uint16 user_light_get_freq(void); 27 | void user_light_set_freq(uint16 freq); 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /IR_RemoteC/include/user_plug.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_ESPSWITCH_H__ 2 | #define __USER_ESPSWITCH_H__ 3 | 4 | #include "driver/key.h" 5 | 6 | /* NOTICE---this is for 512KB spi flash. 7 | * you can change to other sector if you use other size spi flash. */ 8 | #define PRIV_PARAM_START_SEC 0x3C 9 | 10 | #define PRIV_PARAM_SAVE 0 11 | 12 | #define PLUG_KEY_NUM 1 13 | 14 | #define PLUG_KEY_0_IO_MUX PERIPHS_IO_MUX_MTCK_U 15 | #define PLUG_KEY_0_IO_NUM 13 16 | #define PLUG_KEY_0_IO_FUNC FUNC_GPIO13 17 | 18 | #define PLUG_WIFI_LED_IO_MUX PERIPHS_IO_MUX_GPIO0_U 19 | #define PLUG_WIFI_LED_IO_NUM 0 20 | #define PLUG_WIFI_LED_IO_FUNC FUNC_GPIO0 21 | 22 | #define PLUG_LINK_LED_IO_MUX PERIPHS_IO_MUX_MTDI_U 23 | #define PLUG_LINK_LED_IO_NUM 12 24 | #define PLUG_LINK_LED_IO_FUNC FUNC_GPIO12 25 | 26 | #define PLUG_RELAY_LED_IO_MUX PERIPHS_IO_MUX_MTDO_U 27 | #define PLUG_RELAY_LED_IO_NUM 15 28 | #define PLUG_RELAY_LED_IO_FUNC FUNC_GPIO15 29 | 30 | #define PLUG_STATUS_OUTPUT(pin, on) GPIO_OUTPUT_SET(pin, on) 31 | 32 | struct plug_saved_param { 33 | uint8_t status; 34 | uint8_t pad[3]; 35 | }; 36 | 37 | void user_plug_init(void); 38 | uint8 user_plug_get_status(void); 39 | void user_plug_set_status(bool status); 40 | 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /IR_RemoteC/include/user_sensor.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_SENSOR_H__ 2 | #define __USER_SENSOR_H__ 3 | 4 | #include "user_config.h" 5 | #include "driver/key.h" 6 | 7 | #define SENSOR_KEY_NUM 1 8 | 9 | #define SENSOR_KEY_IO_MUX PERIPHS_IO_MUX_MTCK_U 10 | #define SENSOR_KEY_IO_NUM 13 11 | #define SENSOR_KEY_IO_FUNC FUNC_GPIO13 12 | 13 | #define SENSOR_WIFI_LED_IO_MUX PERIPHS_IO_MUX_GPIO0_U 14 | #define SENSOR_WIFI_LED_IO_NUM 0 15 | #define SENSOR_WIFI_LED_IO_FUNC FUNC_GPIO0 16 | 17 | #define SENSOR_LINK_LED_IO_MUX PERIPHS_IO_MUX_MTDI_U 18 | #define SENSOR_LINK_LED_IO_NUM 12 19 | #define SENSOR_LINK_LED_IO_FUNC FUNC_GPIO12 20 | 21 | #define SENSOR_UNUSED_LED_IO_MUX PERIPHS_IO_MUX_MTDO_U 22 | #define SENSOR_UNUSED_LED_IO_NUM 15 23 | #define SENSOR_UNUSED_LED_IO_FUNC FUNC_GPIO15 24 | 25 | #if HUMITURE_SUB_DEVICE 26 | bool user_mvh3004_read_th(uint8 *data); 27 | void user_mvh3004_init(void); 28 | #endif 29 | 30 | void user_sensor_init(uint8 active); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /IR_RemoteC/include/user_webserver.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_WEBSERVER_H__ 2 | #define __USER_WEBSERVER_H__ 3 | 4 | #define SERVER_PORT 9703 5 | #define SERVER_SSL_PORT 443 6 | 7 | #define URLSize 10 8 | #define DATASize 10 9 | 10 | typedef enum Result_Resp { 11 | RespFail = 0, 12 | RespSuc, 13 | } Result_Resp; 14 | 15 | typedef enum ProtocolType { 16 | GET = 0, 17 | POST, 18 | GET_FAVICON 19 | } ProtocolType; 20 | 21 | typedef enum _ParmType { 22 | SWITCH_STATUS = 0, 23 | INFOMATION, 24 | WIFI, 25 | SCAN, 26 | REBOOT, 27 | DEEP_SLEEP, 28 | LIGHT_STATUS, 29 | CONNECT_STATUS, 30 | USER_BIN, 31 | GET_SENSORS 32 | } ParmType; 33 | 34 | typedef struct DATA_Sensors { 35 | char tDht11[DATASize]; 36 | char hDht11[DATASize]; 37 | char tBmp085[DATASize]; 38 | char pBmp085[DATASize]; 39 | char aBmp085[DATASize]; 40 | char t1Ds18b20[DATASize]; 41 | char t2Ds18b20[DATASize]; 42 | } DATA_Sensors; 43 | 44 | typedef struct DATA_System { 45 | char freeheap[DATASize]; 46 | char systime[DATASize]; 47 | char loopcnt[DATASize]; 48 | char wifimode[DATASize]; 49 | char wifistatus[DATASize]; 50 | char wifireconnects[DATASize]; 51 | } DATA_System; 52 | 53 | typedef struct URL_Frame { 54 | enum ProtocolType Type; 55 | char pSelect[URLSize]; 56 | char pCommand[URLSize]; 57 | char pFilename[URLSize]; 58 | } URL_Frame; 59 | 60 | typedef struct URL_Param { 61 | enum ProtocolType Type; 62 | char pParam[URLSize][URLSize]; 63 | char pParVal[URLSize][URLSize]; 64 | int nPar; 65 | } URL_Param; 66 | 67 | typedef struct _rst_parm { 68 | ParmType parmtype; 69 | struct espconn *pespconn; 70 | } rst_parm; 71 | 72 | void user_webserver_init(uint32 port); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /IR_RemoteC/readme.txt: -------------------------------------------------------------------------------- 1 | IOT_Demo - a full IOT_Demo of the SDK, all one to one. 2 | -------------------------------------------------------------------------------- /IR_RemoteC/user/user_devicefind.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: user_devicefind.c 5 | * 6 | * Description: Find your hardware's information while working any mode. 7 | * 8 | * Modification history: 9 | * 2014/3/12, v1.0 create this file. 10 | *******************************************************************************/ 11 | #include "ets_sys.h" 12 | #include "os_type.h" 13 | #include "osapi.h" 14 | #include "mem.h" 15 | #include "user_interface.h" 16 | 17 | #include "espconn.h" 18 | #include "user_json.h" 19 | #include "user_devicefind.h" 20 | #include "user_config.h" 21 | 22 | const char *device_find_request = "Are You Espressif IOT Smart Device?"; 23 | #if PLUG_DEVICE 24 | const char *device_find_response_ok = "I'm Plug."; 25 | #elif LIGHT_DEVICE 26 | const char *device_find_response_ok = "I'm Light."; 27 | #elif SENSOR_DEVICE 28 | #if HUMITURE_SUB_DEVICE 29 | const char *device_find_response_ok = "I'm Humiture."; 30 | #elif FLAMMABLE_GAS_SUB_DEVICE 31 | const char *device_find_response_ok = "I'm Flammable Gas."; 32 | #endif 33 | #endif 34 | 35 | /*---------------------------------------------------------------------------*/ 36 | LOCAL struct espconn ptrespconn; 37 | 38 | /****************************************************************************** 39 | * FunctionName : user_devicefind_recv 40 | * Description : Processing the received data from the host 41 | * Parameters : arg -- Additional argument to pass to the callback function 42 | * pusrdata -- The received data (or NULL when the connection has been closed!) 43 | * length -- The length of received data 44 | * Returns : none 45 | *******************************************************************************/ 46 | LOCAL void ICACHE_FLASH_ATTR 47 | user_devicefind_recv(void *arg, char *pusrdata, unsigned short length) 48 | { 49 | char DeviceBuffer[40] = {0}; 50 | char Device_mac_buffer[60] = {0}; 51 | char hwaddr[6]; 52 | 53 | struct ip_info ipconfig; 54 | 55 | if (wifi_get_opmode() != STATION_MODE) { 56 | wifi_get_ip_info(SOFTAP_IF, &ipconfig); 57 | wifi_get_macaddr(SOFTAP_IF, hwaddr); 58 | 59 | if (!ip_addr_netcmp((struct ip_addr *)ptrespconn.proto.udp->remote_ip, &ipconfig.ip, &ipconfig.netmask)) { 60 | wifi_get_ip_info(STATION_IF, &ipconfig); 61 | wifi_get_macaddr(STATION_IF, hwaddr); 62 | } 63 | } else { 64 | wifi_get_ip_info(STATION_IF, &ipconfig); 65 | wifi_get_macaddr(STATION_IF, hwaddr); 66 | } 67 | 68 | if (pusrdata == NULL) { 69 | return; 70 | } 71 | 72 | if (length == os_strlen(device_find_request) && 73 | os_strncmp(pusrdata, device_find_request, os_strlen(device_find_request)) == 0) { 74 | os_sprintf(DeviceBuffer, "%s" MACSTR " " IPSTR, device_find_response_ok, 75 | MAC2STR(hwaddr), IP2STR(&ipconfig.ip)); 76 | 77 | os_printf("%s\n", DeviceBuffer); 78 | length = os_strlen(DeviceBuffer); 79 | espconn_sent(&ptrespconn, DeviceBuffer, length); 80 | } else if (length == (os_strlen(device_find_request) + 18)) { 81 | os_sprintf(Device_mac_buffer, "%s " MACSTR , device_find_request, MAC2STR(hwaddr)); 82 | os_printf("%s", Device_mac_buffer); 83 | 84 | if (os_strncmp(Device_mac_buffer, pusrdata, os_strlen(device_find_request) + 18) == 0) { 85 | //os_printf("%s\n", Device_mac_buffer); 86 | length = os_strlen(DeviceBuffer); 87 | os_sprintf(DeviceBuffer, "%s" MACSTR " " IPSTR, device_find_response_ok, 88 | MAC2STR(hwaddr), IP2STR(&ipconfig.ip)); 89 | 90 | os_printf("%s\n", DeviceBuffer); 91 | length = os_strlen(DeviceBuffer); 92 | espconn_sent(&ptrespconn, DeviceBuffer, length); 93 | } else { 94 | return; 95 | } 96 | } 97 | } 98 | 99 | /****************************************************************************** 100 | * FunctionName : user_devicefind_init 101 | * Description : the espconn struct parame init 102 | * Parameters : none 103 | * Returns : none 104 | *******************************************************************************/ 105 | void ICACHE_FLASH_ATTR 106 | user_devicefind_init(void) 107 | { 108 | ptrespconn.type = ESPCONN_UDP; 109 | ptrespconn.proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp)); 110 | ptrespconn.proto.udp->local_port = 1025; 111 | espconn_regist_recvcb(&ptrespconn, user_devicefind_recv); 112 | espconn_create(&ptrespconn); 113 | } 114 | -------------------------------------------------------------------------------- /IR_RemoteC/user/user_esp_platform_timer.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: esp_platform_user_timer.c 5 | * 6 | * Description: 7 | * 8 | * Modification history: 9 | * 2014/5/09, v1.0 create this file. 10 | *******************************************************************************/ 11 | #include "ets_sys.h" 12 | #include "os_type.h" 13 | #include "mem.h" 14 | #include "osapi.h" 15 | #include "user_interface.h" 16 | 17 | #include "espconn.h" 18 | #include "user_esp_platform.h" 19 | 20 | #define ESP_DEBUG 21 | 22 | #ifdef ESP_DEBUG 23 | #define ESP_DBG os_printf 24 | #else 25 | #define ESP_DBG 26 | #endif 27 | 28 | LOCAL os_timer_t device_timer; 29 | uint32 min_wait_second; 30 | char timestamp_str[11]; 31 | int timestamp = 0; 32 | char *timer_splits[20] = {NULL}; 33 | 34 | struct esp_platform_wait_timer_param { 35 | uint8 wait_time_param[11]; 36 | uint8 wait_action[15]; 37 | int wait_time_second; 38 | }; 39 | 40 | struct wait_param { 41 | uint8 action[20][15]; 42 | uint16 action_number; 43 | uint16 count; 44 | uint32 min_time_backup; 45 | }; 46 | 47 | void esp_platform_timer_action(struct esp_platform_wait_timer_param *timer_wait_param, uint16 count); 48 | 49 | /****************************************************************************** 50 | * FunctionName : split 51 | * Description : split string p1 according to sting p2 and save the splits 52 | * Parameters : p1 , p2 ,splits[] 53 | * Returns : the number of splits 54 | *******************************************************************************/ 55 | uint16 ICACHE_FLASH_ATTR 56 | split(char *p1, char *p2, char *splits[]) 57 | { 58 | int i = 0; 59 | int j = 0; 60 | 61 | while (i != -1) { 62 | int start = i; 63 | int end = indexof(p1, p2, start); 64 | 65 | if (end == -1) { 66 | end = os_strlen(p1); 67 | } 68 | 69 | char *p = (char *) os_zalloc(100); 70 | os_memcpy(p, p1 + start, end - start); 71 | p[end - start] = '\0'; 72 | splits[j] = p; 73 | j++; 74 | i = end + 1; 75 | 76 | if (i > os_strlen(p1)) { 77 | break; 78 | } 79 | } 80 | 81 | return j; 82 | } 83 | 84 | /****************************************************************************** 85 | * FunctionName : indexof 86 | * Description : calculate the offset of p2 relate to start of p1 87 | * Parameters : p1,p1,start 88 | * Returns : the offset of p2 relate to the start 89 | *******************************************************************************/ 90 | int ICACHE_FLASH_ATTR 91 | indexof(char *p1, char *p2, int start) 92 | { 93 | char *find = (char *)os_strstr(p1 + start, p2); 94 | 95 | if (find != NULL) { 96 | return (find - p1); 97 | } 98 | 99 | return -1; 100 | } 101 | 102 | /****************************************************************************** 103 | * FunctionName : esp_platform_find_min_time 104 | * Description : find the minimum wait second in timer list 105 | * Parameters : timer_wait_param -- param of timer action and wait time param 106 | * count -- The number of timers given by server 107 | * Returns : none 108 | *******************************************************************************/ 109 | void ICACHE_FLASH_ATTR 110 | esp_platform_find_min_time(struct esp_platform_wait_timer_param *timer_wait_param , uint16 count) 111 | { 112 | uint16 i = 0; 113 | min_wait_second = 0xFFFFFFF; 114 | 115 | for (i = 0; i < count ; i++) { 116 | if (timer_wait_param[i].wait_time_second < min_wait_second && timer_wait_param[i].wait_time_second >= 0) { 117 | min_wait_second = timer_wait_param[i].wait_time_second; 118 | } 119 | } 120 | } 121 | 122 | /****************************************************************************** 123 | * FunctionName : user_platform_timer_first_start 124 | * Description : calculate the wait time of each timer 125 | * Parameters : count -- The number of timers given by server 126 | * Returns : none 127 | *******************************************************************************/ 128 | void ICACHE_FLASH_ATTR 129 | user_platform_timer_first_start(uint16 count) 130 | { 131 | int i = 0; 132 | struct esp_platform_wait_timer_param timer_wait_param[100] = {0}; 133 | 134 | ESP_DBG("current timestamp= %ds\n", timestamp); 135 | 136 | timestamp = timestamp + min_wait_second; 137 | 138 | for (i = 0 ; i < count ; i++) { 139 | char *str = timer_splits[i]; 140 | 141 | if (indexof(str, "f", 0) == 0) { 142 | char *fixed_wait[2]; 143 | 144 | ESP_DBG("timer is fixed mode\n"); 145 | 146 | split(str, "=", fixed_wait); 147 | os_memcpy(timer_wait_param[i].wait_time_param, fixed_wait[0] + 1, os_strlen(fixed_wait[0]) - 1); 148 | os_memcpy(timer_wait_param[i].wait_action, fixed_wait[1], os_strlen(fixed_wait[1])); 149 | timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - timestamp; 150 | os_free(fixed_wait[0]); 151 | os_free(fixed_wait[1]); 152 | } 153 | 154 | else if (indexof(str, "l", 0) == 0) { 155 | char *loop_wait[2]; 156 | 157 | ESP_DBG("timer is loop mode\n"); 158 | 159 | split(str, "=", loop_wait); 160 | os_memcpy(timer_wait_param[i].wait_time_param, loop_wait[0] + 1, os_strlen(loop_wait[0]) - 1); 161 | os_memcpy(timer_wait_param[i].wait_action, loop_wait[1], os_strlen(loop_wait[1])); 162 | timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - (timestamp % atoi(timer_wait_param[i].wait_time_param)); 163 | os_free(loop_wait[0]); 164 | os_free(loop_wait[1]); 165 | } else if (indexof(str, "w", 0) == 0) { 166 | char *week_wait[2]; 167 | int monday_wait_time = 0; 168 | 169 | ESP_DBG("timer is weekend mode\n"); 170 | 171 | split(str, "=", week_wait); 172 | os_memcpy(timer_wait_param[i].wait_time_param, week_wait[0] + 1, os_strlen(week_wait[0]) - 1); 173 | os_memcpy(timer_wait_param[i].wait_action, week_wait[1], os_strlen(week_wait[1])); 174 | monday_wait_time = (timestamp - 1388937600) % (7 * 24 * 3600); 175 | 176 | ESP_DBG("monday_wait_time == %d", monday_wait_time); 177 | 178 | if (atoi(timer_wait_param[i].wait_time_param) > monday_wait_time) { 179 | timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - monday_wait_time; 180 | } else { 181 | timer_wait_param[i].wait_time_second = 7 * 24 * 3600 - monday_wait_time + atoi(timer_wait_param[i].wait_time_param); 182 | } 183 | 184 | os_free(week_wait[0]); 185 | os_free(week_wait[1]); 186 | } 187 | } 188 | 189 | esp_platform_find_min_time(timer_wait_param, count); 190 | if(min_wait_second == 0) { 191 | return; 192 | } 193 | 194 | esp_platform_timer_action(timer_wait_param, count); 195 | } 196 | 197 | /****************************************************************************** 198 | * FunctionName : user_esp_platform_device_action 199 | * Description : Execute the actions of minimum wait time 200 | * Parameters : pwait_action -- point the list of actions which need execute 201 | * 202 | * Returns : none 203 | *******************************************************************************/ 204 | void ICACHE_FLASH_ATTR 205 | user_esp_platform_device_action(struct wait_param *pwait_action) 206 | { 207 | uint8 i = 0; 208 | uint16 count = pwait_action->count; 209 | uint16 action_number = pwait_action->action_number; 210 | 211 | ESP_DBG("there is %d action at the same time\n", pwait_action->action_number); 212 | 213 | #if PLUG_DEVICE 214 | for (i = 0; i < action_number && pwait_action->action[i][0] != '0'; i++) { 215 | ESP_DBG("%s\n",pwait_action->action[i]); 216 | 217 | if (os_strcmp(pwait_action->action[i], "on_switch", 9) == 0) { 218 | user_plug_set_status(0x01); 219 | } else if (os_strcmp(pwait_action->action[i], "off_switch", 10) == 0) { 220 | user_plug_set_status(0x00); 221 | } else if (os_strcmp(pwait_action->action[i], "on_off_switch", 13) == 0) { 222 | if (user_plug_get_status() == 0) { 223 | user_plug_set_status(0x01); 224 | } else { 225 | user_plug_set_status(0x00); 226 | } 227 | } else { 228 | return; 229 | } 230 | } 231 | user_platform_timer_first_start(count); 232 | #endif 233 | } 234 | 235 | /****************************************************************************** 236 | * FunctionName : user_platform_timer_start 237 | * Description : Processing the message about timer from the server 238 | * Parameters : timer_wait_param -- The received data from the server 239 | * count -- the espconn used to connetion with the host 240 | * Returns : none 241 | *******************************************************************************/ 242 | void ICACHE_FLASH_ATTR 243 | user_esp_platform_wait_time_overflow_check(struct wait_param *pwait_action) 244 | { 245 | ESP_DBG("min_wait_second = %d", min_wait_second); 246 | 247 | if (pwait_action->min_time_backup >= 3600) { 248 | os_timer_disarm(&device_timer); 249 | os_timer_setfn(&device_timer, (os_timer_func_t *)user_esp_platform_wait_time_overflow_check, pwait_action); 250 | os_timer_arm(&device_timer, 3600000, 0); 251 | ESP_DBG("min_wait_second is extended\n"); 252 | } else { 253 | os_timer_disarm(&device_timer); 254 | os_timer_setfn(&device_timer, (os_timer_func_t *)user_esp_platform_device_action, pwait_action); 255 | os_timer_arm(&device_timer, pwait_action->min_time_backup * 1000, 0); 256 | ESP_DBG("min_wait_second is = %dms\n", pwait_action->min_time_backup * 1000); 257 | } 258 | 259 | pwait_action->min_time_backup -= 3600; 260 | } 261 | 262 | /****************************************************************************** 263 | * FunctionName : user_platform_timer_start 264 | * Description : Processing the message about timer from the server 265 | * Parameters : timer_wait_param -- The received data from the server 266 | * count -- the espconn used to connetion with the host 267 | * Returns : none 268 | *******************************************************************************/ 269 | void ICACHE_FLASH_ATTR 270 | esp_platform_timer_action(struct esp_platform_wait_timer_param *timer_wait_param, uint16 count) 271 | { 272 | uint16 i = 0; 273 | uint16 action_number; 274 | struct wait_param pwait_action = {0}; 275 | 276 | pwait_action.count = count; 277 | action_number = 0; 278 | 279 | for (i = 0; i < count ; i++) { 280 | if (timer_wait_param[i].wait_time_second == min_wait_second) { 281 | os_memcpy(pwait_action.action[action_number], timer_wait_param[i].wait_action, os_strlen(timer_wait_param[i].wait_action)); 282 | ESP_DBG("*****%s*****\n", timer_wait_param[i].wait_action); 283 | action_number++; 284 | } 285 | } 286 | 287 | pwait_action.action_number = action_number; 288 | pwait_action.min_time_backup = min_wait_second; 289 | user_esp_platform_wait_time_overflow_check(&pwait_action); 290 | } 291 | 292 | /****************************************************************************** 293 | * FunctionName : user_platform_timer_start 294 | * Description : Processing the message about timer from the server 295 | * Parameters : pbuffer -- The received data from the server 296 | 297 | * Returns : none 298 | *******************************************************************************/ 299 | void ICACHE_FLASH_ATTR 300 | user_platform_timer_start(char *pbuffer) 301 | { 302 | int str_begin = 0; 303 | int str_end = 0; 304 | uint8 i = 0; 305 | char *pstr_start = NULL; 306 | char *pstr_end = NULL; 307 | struct esp_platform_wait_timer_param timer_wait_param[20]; 308 | char *pstr = NULL; 309 | 310 | min_wait_second = 0; 311 | 312 | if ((pstr = (char *)os_strstr(pbuffer, "\"timestamp\":")) != NULL) { 313 | pstr_start = pstr + 13; 314 | pstr_end = (char *)os_strstr(pstr_start, ","); 315 | 316 | if (pstr != NULL) { 317 | os_memcpy(timestamp_str, pstr_start, pstr_end - pstr_start); 318 | timestamp = atoi(timestamp_str); 319 | } 320 | } 321 | 322 | for (i = 0 ; i < 20 ; i++) { 323 | if (timer_splits[i] != NULL) { 324 | os_free(timer_splits[i]); 325 | timer_splits[i] = NULL; 326 | } 327 | } 328 | 329 | if ((pstr_start = (char *)os_strstr(pbuffer, "\"timers\": \"")) != NULL) { 330 | str_begin = 11; 331 | str_end = indexof(pstr_start, "\"", str_begin); 332 | 333 | if (str_begin == str_end) { 334 | os_timer_disarm(&device_timer); 335 | return; 336 | } 337 | 338 | char *split_buffer = (char *)os_zalloc(str_end - str_begin + 1); 339 | os_memcpy(split_buffer, pstr_start + str_begin, str_end - str_begin); 340 | uint16 count = split(split_buffer , ";" , timer_splits); 341 | os_free(split_buffer); 342 | user_platform_timer_first_start(count); 343 | } 344 | } 345 | -------------------------------------------------------------------------------- /IR_RemoteC/user/user_json.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: user_json.c 5 | * 6 | * Description: JSON format set up and parse. 7 | * Check your hardware transmation while use this data format. 8 | * 9 | * Modification history: 10 | * 2014/5/09, v1.0 create this file. 11 | *******************************************************************************/ 12 | #include "ets_sys.h" 13 | #include "osapi.h" 14 | #include "os_type.h" 15 | #include "mem.h" 16 | 17 | #include "user_json.h" 18 | 19 | LOCAL char *json_buf; 20 | LOCAL int pos; 21 | LOCAL int size; 22 | 23 | /****************************************************************************** 24 | * FunctionName : find_json_path 25 | * Description : find the JSON format tree's path 26 | * Parameters : json -- A pointer to a JSON set up 27 | * path -- A pointer to the JSON format tree's path 28 | * Returns : A pointer to the JSON format tree 29 | *******************************************************************************/ 30 | struct jsontree_value *ICACHE_FLASH_ATTR 31 | find_json_path(struct jsontree_context *json, const char *path) 32 | { 33 | struct jsontree_value *v; 34 | const char *start; 35 | const char *end; 36 | int len; 37 | 38 | v = json->values[0]; 39 | start = path; 40 | 41 | do { 42 | end = (const char *)os_strstr(start, "/"); 43 | 44 | if (end == start) { 45 | break; 46 | } 47 | 48 | if (end != NULL) { 49 | len = end - start; 50 | end++; 51 | } else { 52 | len = os_strlen(start); 53 | } 54 | 55 | if (v->type != JSON_TYPE_OBJECT) { 56 | v = NULL; 57 | } else { 58 | struct jsontree_object *o; 59 | int i; 60 | 61 | o = (struct jsontree_object *)v; 62 | v = NULL; 63 | 64 | for (i = 0; i < o->count; i++) { 65 | if (os_strncmp(start, o->pairs[i].name, len) == 0) { 66 | v = o->pairs[i].value; 67 | json->index[json->depth] = i; 68 | json->depth++; 69 | json->values[json->depth] = v; 70 | json->index[json->depth] = 0; 71 | break; 72 | } 73 | } 74 | } 75 | 76 | start = end; 77 | } while (end != NULL && *end != '\0' && v != NULL); 78 | 79 | json->callback_state = 0; 80 | return v; 81 | } 82 | 83 | /****************************************************************************** 84 | * FunctionName : json_putchar 85 | * Description : write the value to the JSON format tree 86 | * Parameters : c -- the value which write the JSON format tree 87 | * Returns : result 88 | *******************************************************************************/ 89 | int ICACHE_FLASH_ATTR 90 | json_putchar(int c) 91 | { 92 | if (json_buf != NULL && pos <= size) { 93 | json_buf[pos++] = c; 94 | return c; 95 | } 96 | 97 | return 0; 98 | } 99 | 100 | /****************************************************************************** 101 | * FunctionName : json_ws_send 102 | * Description : set up the JSON format tree for string 103 | * Parameters : tree -- A pointer to the JSON format tree 104 | * path -- A pointer to the JSON format tree's path 105 | * pbuf -- A pointer for the data sent 106 | * Returns : none 107 | *******************************************************************************/ 108 | void ICACHE_FLASH_ATTR 109 | json_ws_send(struct jsontree_value *tree, const char *path, char *pbuf) 110 | { 111 | struct jsontree_context json; 112 | /* maxsize = 128 bytes */ 113 | json_buf = (char *)os_malloc(jsonSize); 114 | 115 | /* reset state and set max-size */ 116 | /* NOTE: packet will be truncated at 512 bytes */ 117 | pos = 0; 118 | size = jsonSize; 119 | 120 | json.values[0] = (struct jsontree_value *)tree; 121 | jsontree_reset(&json); 122 | find_json_path(&json, path); 123 | json.path = json.depth; 124 | json.putchar = json_putchar; 125 | 126 | while (jsontree_print_next(&json) && json.path <= json.depth); 127 | 128 | json_buf[pos] = 0; 129 | os_memcpy(pbuf, json_buf, pos); 130 | os_free(json_buf); 131 | } 132 | 133 | /****************************************************************************** 134 | * FunctionName : json_parse 135 | * Description : parse the data as a JSON format 136 | * Parameters : js_ctx -- A pointer to a JSON set up 137 | * ptrJSONMessage -- A pointer to the data 138 | * Returns : none 139 | *******************************************************************************/ 140 | void ICACHE_FLASH_ATTR 141 | json_parse(struct jsontree_context *json, char *ptrJSONMessage) 142 | { 143 | /* Set value */ 144 | struct jsontree_value *v; 145 | struct jsontree_callback *c; 146 | struct jsontree_callback *c_bak = NULL; 147 | 148 | while ((v = jsontree_find_next(json, JSON_TYPE_CALLBACK)) != NULL) { 149 | c = (struct jsontree_callback *)v; 150 | 151 | if (c == c_bak) { 152 | continue; 153 | } 154 | 155 | c_bak = c; 156 | 157 | if (c->set != NULL) { 158 | struct jsonparse_state js; 159 | 160 | jsonparse_setup(&js, ptrJSONMessage, os_strlen(ptrJSONMessage)); 161 | c->set(json, &js); 162 | } 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /IR_RemoteC/user/user_light.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: user_light.c 5 | * 6 | * Description: light demo's function realization 7 | * 8 | * Modification history: 9 | * 2014/5/1, v1.0 create this file. 10 | *******************************************************************************/ 11 | #include "ets_sys.h" 12 | #include "osapi.h" 13 | #include "os_type.h" 14 | #include "mem.h" 15 | #include "user_interface.h" 16 | 17 | #include "user_light.h" 18 | 19 | #if LIGHT_DEVICE 20 | 21 | LOCAL struct light_saved_param light_param; 22 | 23 | /****************************************************************************** 24 | * FunctionName : user_light_get_duty 25 | * Description : get duty of each channel 26 | * Parameters : uint8 channel : LIGHT_RED/LIGHT_GREEN/LIGHT_BLUE 27 | * Returns : NONE 28 | *******************************************************************************/ 29 | uint8 ICACHE_FLASH_ATTR 30 | user_light_get_duty(uint8 channel) 31 | { 32 | return light_param.pwm_duty[channel]; 33 | } 34 | 35 | /****************************************************************************** 36 | * FunctionName : user_light_set_duty 37 | * Description : set each channel's duty params 38 | * Parameters : uint8 duty : 0 ~ PWM_DEPTH 39 | * uint8 channel : LIGHT_RED/LIGHT_GREEN/LIGHT_BLUE 40 | * Returns : NONE 41 | *******************************************************************************/ 42 | void ICACHE_FLASH_ATTR 43 | user_light_set_duty(uint8 duty, uint8 channel) 44 | { 45 | if (duty != light_param.pwm_duty[channel]) { 46 | pwm_set_duty(duty, channel); 47 | 48 | light_param.pwm_duty[channel] = pwm_get_duty(channel); 49 | } 50 | } 51 | 52 | /****************************************************************************** 53 | * FunctionName : user_light_get_freq 54 | * Description : get pwm frequency 55 | * Parameters : NONE 56 | * Returns : uint16 : pwm frequency 57 | *******************************************************************************/ 58 | uint16 ICACHE_FLASH_ATTR 59 | user_light_get_freq(void) 60 | { 61 | return light_param.pwm_freq; 62 | } 63 | 64 | /****************************************************************************** 65 | * FunctionName : user_light_set_duty 66 | * Description : set pwm frequency 67 | * Parameters : uint16 freq : 100hz typically 68 | * Returns : NONE 69 | *******************************************************************************/ 70 | void ICACHE_FLASH_ATTR 71 | user_light_set_freq(uint16 freq) 72 | { 73 | if (freq != light_param.pwm_freq) { 74 | pwm_set_freq(freq); 75 | 76 | light_param.pwm_freq = pwm_get_freq(); 77 | } 78 | } 79 | 80 | void ICACHE_FLASH_ATTR 81 | user_light_restart(void) 82 | { 83 | spi_flash_erase_sector(PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE); 84 | spi_flash_write((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE, 85 | (uint32 *)&light_param, sizeof(struct light_saved_param)); 86 | 87 | pwm_start(); 88 | } 89 | 90 | /****************************************************************************** 91 | * FunctionName : user_light_init 92 | * Description : light demo init, mainy init pwm 93 | * Parameters : none 94 | * Returns : none 95 | *******************************************************************************/ 96 | void ICACHE_FLASH_ATTR 97 | user_light_init(void) 98 | { 99 | spi_flash_read((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE, 100 | (uint32 *)&light_param, sizeof(struct light_saved_param)); 101 | 102 | pwm_init(light_param.pwm_freq, light_param.pwm_duty); 103 | } 104 | #endif 105 | 106 | -------------------------------------------------------------------------------- /IR_RemoteC/user/user_plug.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: user_plug.c 5 | * 6 | * Description: plug demo's function realization 7 | * 8 | * Modification history: 9 | * 2014/5/1, v1.0 create this file. 10 | *******************************************************************************/ 11 | #include "ets_sys.h" 12 | #include "osapi.h" 13 | #include "os_type.h" 14 | #include "mem.h" 15 | #include "user_interface.h" 16 | 17 | #include "user_plug.h" 18 | 19 | #if PLUG_DEVICE 20 | 21 | LOCAL struct plug_saved_param plug_param; 22 | LOCAL struct keys_param keys; 23 | LOCAL struct single_key_param *single_key[PLUG_KEY_NUM]; 24 | LOCAL os_timer_t link_led_timer; 25 | LOCAL uint8 link_led_level = 0; 26 | 27 | /****************************************************************************** 28 | * FunctionName : user_plug_get_status 29 | * Description : get plug's status, 0x00 or 0x01 30 | * Parameters : none 31 | * Returns : uint8 - plug's status 32 | *******************************************************************************/ 33 | uint8 ICACHE_FLASH_ATTR 34 | user_plug_get_status(void) 35 | { 36 | return plug_param.status; 37 | } 38 | 39 | /****************************************************************************** 40 | * FunctionName : user_plug_set_status 41 | * Description : set plug's status, 0x00 or 0x01 42 | * Parameters : uint8 - status 43 | * Returns : none 44 | *******************************************************************************/ 45 | void ICACHE_FLASH_ATTR 46 | user_plug_set_status(bool status) 47 | { 48 | if (status != plug_param.status) { 49 | if (status > 1) { 50 | os_printf("error status input!\n"); 51 | return; 52 | } 53 | 54 | plug_param.status = status; 55 | PLUG_STATUS_OUTPUT(PLUG_RELAY_LED_IO_NUM, status); 56 | } 57 | } 58 | 59 | /****************************************************************************** 60 | * FunctionName : user_plug_short_press 61 | * Description : key's short press function, needed to be installed 62 | * Parameters : none 63 | * Returns : none 64 | *******************************************************************************/ 65 | LOCAL void ICACHE_FLASH_ATTR 66 | user_plug_short_press(void) 67 | { 68 | user_plug_set_status((~plug_param.status) & 0x01); 69 | 70 | spi_flash_erase_sector(PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE); 71 | spi_flash_write((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE, 72 | (uint32 *)&plug_param, sizeof(struct plug_saved_param)); 73 | } 74 | 75 | /****************************************************************************** 76 | * FunctionName : user_plug_long_press 77 | * Description : key's long press function, needed to be installed 78 | * Parameters : none 79 | * Returns : none 80 | *******************************************************************************/ 81 | LOCAL void ICACHE_FLASH_ATTR 82 | user_plug_long_press(void) 83 | { 84 | user_esp_platform_set_active(0); 85 | system_restore(); 86 | system_restart(); 87 | } 88 | 89 | LOCAL void ICACHE_FLASH_ATTR 90 | user_link_led_init(void) 91 | { 92 | PIN_FUNC_SELECT(PLUG_LINK_LED_IO_MUX, PLUG_LINK_LED_IO_FUNC); 93 | } 94 | 95 | void ICACHE_FLASH_ATTR 96 | user_link_led_output(uint8 level) 97 | { 98 | GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), level); 99 | } 100 | 101 | LOCAL void ICACHE_FLASH_ATTR 102 | user_link_led_timer_cb(void) 103 | { 104 | link_led_level = (~link_led_level) & 0x01; 105 | GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), link_led_level); 106 | } 107 | 108 | void ICACHE_FLASH_ATTR 109 | user_link_led_timer_init(void) 110 | { 111 | os_timer_disarm(&link_led_timer); 112 | os_timer_setfn(&link_led_timer, (os_timer_func_t *)user_link_led_timer_cb, NULL); 113 | os_timer_arm(&link_led_timer, 50, 1); 114 | link_led_level = 0; 115 | GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), link_led_level); 116 | } 117 | 118 | void ICACHE_FLASH_ATTR 119 | user_link_led_timer_done(void) 120 | { 121 | os_timer_disarm(&link_led_timer); 122 | GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), 0); 123 | } 124 | 125 | /****************************************************************************** 126 | * FunctionName : user_plug_init 127 | * Description : init plug's key function and relay output 128 | * Parameters : none 129 | * Returns : none 130 | *******************************************************************************/ 131 | void ICACHE_FLASH_ATTR 132 | user_plug_init(void) 133 | { 134 | user_link_led_init(); 135 | 136 | wifi_status_led_install(PLUG_WIFI_LED_IO_NUM, PLUG_WIFI_LED_IO_MUX, PLUG_WIFI_LED_IO_FUNC); 137 | 138 | single_key[0] = key_init_single(PLUG_KEY_0_IO_NUM, PLUG_KEY_0_IO_MUX, PLUG_KEY_0_IO_FUNC, 139 | user_plug_long_press, user_plug_short_press); 140 | 141 | keys.key_num = PLUG_KEY_NUM; 142 | keys.single_key = single_key; 143 | 144 | key_init(&keys); 145 | 146 | spi_flash_read((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE, 147 | (uint32 *)&plug_param, sizeof(struct plug_saved_param)); 148 | 149 | PIN_FUNC_SELECT(PLUG_RELAY_LED_IO_MUX, PLUG_RELAY_LED_IO_FUNC); 150 | 151 | // no used SPI Flash 152 | if (plug_param.status == 0xff) { 153 | plug_param.status = 1; 154 | } 155 | 156 | PLUG_STATUS_OUTPUT(PLUG_RELAY_LED_IO_NUM, plug_param.status); 157 | } 158 | #endif 159 | 160 | -------------------------------------------------------------------------------- /IR_RemoteC/user/user_sensor.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: user_humiture.c 5 | * 6 | * Description: humiture demo's function realization 7 | * 8 | * Modification history: 9 | * 2014/5/1, v1.0 create this file. 10 | *******************************************************************************/ 11 | #include "ets_sys.h" 12 | #include "osapi.h" 13 | #include "os_type.h" 14 | #include "user_interface.h" 15 | 16 | #if SENSOR_DEVICE 17 | #include "user_sensor.h" 18 | 19 | LOCAL struct keys_param keys; 20 | LOCAL struct single_key_param *single_key[SENSOR_KEY_NUM]; 21 | LOCAL os_timer_t sensor_sleep_timer; 22 | LOCAL os_timer_t link_led_timer; 23 | LOCAL uint8 link_led_level = 0; 24 | LOCAL uint32 link_start_time; 25 | 26 | #if HUMITURE_SUB_DEVICE 27 | #include "driver/i2c_master.h" 28 | 29 | #define MVH3004_Addr 0x88 30 | 31 | LOCAL uint8 humiture_data[4]; 32 | 33 | /****************************************************************************** 34 | * FunctionName : user_mvh3004_burst_read 35 | * Description : burst read mvh3004's internal data 36 | * Parameters : uint8 addr - mvh3004's address 37 | * uint8 *pData - data point to put read data 38 | * uint16 len - read length 39 | * Returns : bool - true or false 40 | *******************************************************************************/ 41 | LOCAL bool ICACHE_FLASH_ATTR 42 | user_mvh3004_burst_read(uint8 addr, uint8 *pData, uint16 len) 43 | { 44 | uint8 ack; 45 | uint16 i; 46 | 47 | i2c_master_start(); 48 | i2c_master_writeByte(addr); 49 | ack = i2c_master_getAck(); 50 | 51 | if (ack) { 52 | os_printf("addr not ack when tx write cmd \n"); 53 | i2c_master_stop(); 54 | return false; 55 | } 56 | 57 | i2c_master_stop(); 58 | i2c_master_wait(40000); 59 | 60 | i2c_master_start(); 61 | i2c_master_writeByte(addr + 1); 62 | ack = i2c_master_getAck(); 63 | 64 | if (ack) { 65 | os_printf("addr not ack when tx write cmd \n"); 66 | i2c_master_stop(); 67 | return false; 68 | } 69 | 70 | for (i = 0; i < len; i++) { 71 | pData[i] = i2c_master_readByte(); 72 | 73 | i2c_master_setAck((i == (len - 1)) ? 1 : 0); 74 | } 75 | 76 | i2c_master_stop(); 77 | 78 | return true; 79 | } 80 | 81 | /****************************************************************************** 82 | * FunctionName : user_mvh3004_read_th 83 | * Description : read mvh3004's humiture data 84 | * Parameters : uint8 *data - where data to put 85 | * Returns : bool - ture or false 86 | *******************************************************************************/ 87 | bool ICACHE_FLASH_ATTR 88 | user_mvh3004_read_th(uint8 *data) 89 | { 90 | return user_mvh3004_burst_read(MVH3004_Addr, data, 4); 91 | } 92 | 93 | /****************************************************************************** 94 | * FunctionName : user_mvh3004_init 95 | * Description : init mvh3004, mainly i2c master gpio 96 | * Parameters : none 97 | * Returns : none 98 | *******************************************************************************/ 99 | void ICACHE_FLASH_ATTR 100 | user_mvh3004_init(void) 101 | { 102 | i2c_master_gpio_init(); 103 | } 104 | 105 | uint8 *ICACHE_FLASH_ATTR 106 | user_mvh3004_get_poweron_th(void) 107 | { 108 | return humiture_data; 109 | } 110 | #endif 111 | 112 | /****************************************************************************** 113 | * FunctionName : user_humiture_long_press 114 | * Description : humiture key's function, needed to be installed 115 | * Parameters : none 116 | * Returns : none 117 | *******************************************************************************/ 118 | LOCAL void ICACHE_FLASH_ATTR 119 | user_sensor_long_press(void) 120 | { 121 | user_esp_platform_set_active(0); 122 | system_restore(); 123 | system_restart(); 124 | } 125 | 126 | LOCAL void ICACHE_FLASH_ATTR 127 | user_link_led_init(void) 128 | { 129 | PIN_FUNC_SELECT(SENSOR_LINK_LED_IO_MUX, SENSOR_LINK_LED_IO_FUNC); 130 | PIN_FUNC_SELECT(SENSOR_UNUSED_LED_IO_MUX, SENSOR_UNUSED_LED_IO_FUNC); 131 | GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_UNUSED_LED_IO_NUM), 0); 132 | } 133 | 134 | void ICACHE_FLASH_ATTR 135 | user_link_led_output(uint8 level) 136 | { 137 | GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), level); 138 | } 139 | 140 | LOCAL void ICACHE_FLASH_ATTR 141 | user_link_led_timer_cb(void) 142 | { 143 | link_led_level = (~link_led_level) & 0x01; 144 | GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), link_led_level); 145 | } 146 | 147 | void ICACHE_FLASH_ATTR 148 | user_link_led_timer_init(void) 149 | { 150 | link_start_time = system_get_time(); 151 | 152 | os_timer_disarm(&link_led_timer); 153 | os_timer_setfn(&link_led_timer, (os_timer_func_t *)user_link_led_timer_cb, NULL); 154 | os_timer_arm(&link_led_timer, 50, 1); 155 | link_led_level = 0; 156 | GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), link_led_level); 157 | } 158 | 159 | void ICACHE_FLASH_ATTR 160 | user_link_led_timer_done(void) 161 | { 162 | os_timer_disarm(&link_led_timer); 163 | GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), 0); 164 | } 165 | 166 | void ICACHE_FLASH_ATTR 167 | user_sensor_deep_sleep_enter(void) 168 | { 169 | system_deep_sleep(SENSOR_DEEP_SLEEP_TIME > link_start_time \ 170 | ? SENSOR_DEEP_SLEEP_TIME - link_start_time : 30000000); 171 | } 172 | 173 | void ICACHE_FLASH_ATTR 174 | user_sensor_deep_sleep_disable(void) 175 | { 176 | os_timer_disarm(&sensor_sleep_timer); 177 | } 178 | 179 | void ICACHE_FLASH_ATTR 180 | user_sensor_deep_sleep_init(uint32 time) 181 | { 182 | os_timer_disarm(&sensor_sleep_timer); 183 | os_timer_setfn(&sensor_sleep_timer, (os_timer_func_t *)user_sensor_deep_sleep_enter, NULL); 184 | os_timer_arm(&sensor_sleep_timer, time, 0); 185 | } 186 | 187 | /****************************************************************************** 188 | * FunctionName : user_humiture_init 189 | * Description : init humiture function, include key and mvh3004 190 | * Parameters : none 191 | * Returns : none 192 | *******************************************************************************/ 193 | void ICACHE_FLASH_ATTR 194 | user_sensor_init(uint8 active) 195 | { 196 | user_link_led_init(); 197 | 198 | wifi_status_led_install(SENSOR_WIFI_LED_IO_NUM, SENSOR_WIFI_LED_IO_MUX, SENSOR_WIFI_LED_IO_FUNC); 199 | 200 | if (wifi_get_opmode() != SOFTAP_MODE) { 201 | single_key[0] = key_init_single(SENSOR_KEY_IO_NUM, SENSOR_KEY_IO_MUX, SENSOR_KEY_IO_FUNC, 202 | user_sensor_long_press, NULL); 203 | 204 | keys.key_num = SENSOR_KEY_NUM; 205 | keys.single_key = single_key; 206 | 207 | key_init(&keys); 208 | 209 | if (GPIO_INPUT_GET(GPIO_ID_PIN(SENSOR_KEY_IO_NUM)) == 0) { 210 | user_sensor_long_press(); 211 | } 212 | } 213 | 214 | #if HUMITURE_SUB_DEVICE 215 | user_mvh3004_init(); 216 | user_mvh3004_read_th(humiture_data); 217 | #endif 218 | 219 | #ifdef SENSOR_DEEP_SLEEP 220 | if (wifi_get_opmode() != STATIONAP_MODE) { 221 | if (active == 1) { 222 | user_sensor_deep_sleep_init(SENSOR_DEEP_SLEEP_TIME / 1000 ); 223 | } else { 224 | user_sensor_deep_sleep_init(SENSOR_DEEP_SLEEP_TIME / 1000 / 3 * 2); 225 | } 226 | } 227 | #endif 228 | } 229 | #endif 230 | 231 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

IR Remote for ESP8266 Development Software

2 | 3 | This project ports the IRremote library from Arduino to the ESP8266 EspressIf SDK platform. 4 | 5 | Setup: 6 | 7 | 1. Using the Eclipse Luna Platform setup for the EspressIf SDK, import the project in the 8 | IR_RemoteC folder to your choice of workspaces. 9 | 10 | 2. Open the user_config.h file and add your local WIFI credentials: 11 | 12 | #define WIFI_CLIENTSSID "YOURSSID" 13 | #define WIFI_CLIENTPASSWORD "YOURPW" 14 | 15 | 16 | Operation: 17 | 18 | The ESP8266 Application (user_main.c): 19 | 1. user_init() - sets up configuration of GPIO used. 20 | - Starts Wifi in station mode (Even though we do not use WiFi in this example) 21 | 22 | 2. loop_cb() - timer callback with 1000ms period 23 | - checks state of push button switch 24 | - if button pushed, last IR code received is transmitted every 500 ms until button is released 25 | - if button released, IR receiver checked every 50 us for new codes. if received, code is saved 26 | 27 | The current settings (change if needed in the sketch to match your configuration): 28 | 29 | ESP8266 Static IP: 192.168.0.177 30 | ESP8266 Server Port: 9703 31 | Router IP: 192.168.0.1 32 | 33 | Serial port baud: 115200 bps 34 | 35 | --------------------------------------------------------------------------------