├── .gitignore ├── 8k.amr ├── LICENSE ├── Makefile ├── README.md ├── baidu_reset_api.py ├── components ├── bsp │ ├── component.mk │ ├── include │ │ └── wm8978.h │ └── wm8978.c ├── espressif │ ├── .tags │ ├── .tags_sorted_by_file │ ├── component.mk │ ├── eth.c │ ├── event.c │ ├── include │ │ ├── eth.h │ │ ├── event.h │ │ └── wifi.h │ └── wifi.c ├── hal │ ├── component.mk │ ├── hal_eth.c │ ├── hal_i2c.c │ ├── hal_i2s.c │ └── include │ │ ├── hal_eth.h │ │ ├── hal_i2c.h │ │ └── hal_i2s.h ├── http │ ├── component.mk │ ├── http.c │ ├── include │ │ ├── http.h │ │ └── url_parser.h │ └── url_parser.c └── rest │ ├── baidu_rest.c │ ├── component.mk │ └── include │ └── baidu_rest.h ├── main ├── component.mk └── main.c └── sdkconfig /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | sdkconfig.old 3 | -------------------------------------------------------------------------------- /8k.amr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liqin123/esp32_baidu_rest/d91c10cbd3a3f722ec1855b16bc5bce629a95c87/8k.amr -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := we_esp32 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esp32 2 | esp32_iot_platform 3 | baidu rest api 4 | -------------------------------------------------------------------------------- /baidu_reset_api.py: -------------------------------------------------------------------------------- 1 | import json 2 | import httplib 3 | import base64 4 | f=open('8k.amr','rb') 5 | data=f.read(6340) 6 | access_token="24.44810154581d4b7e8cc3554c90b949f0.2592000.1505980562.282335-10037482" 7 | speech=base64.b64encode(data) 8 | length=6340 9 | params={'format':"amr","rate":8000,"channel":1,"cuid":"eps32_frankie","token":access_token,"speech":speech,"len":length} 10 | a=json.dumps(params) 11 | print a 12 | conn = httplib.HTTPConnection("vop.baidu.com",80) 13 | conn.request("GET","/server_api",a) 14 | response=conn.getresponse() 15 | print response.status,response.reason 16 | print response.read() -------------------------------------------------------------------------------- /components/bsp/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | -------------------------------------------------------------------------------- /components/bsp/include/wm8978.h: -------------------------------------------------------------------------------- 1 | #ifndef __WM8978_H 2 | #define __WM8978_H 3 | 4 | #include "hal_i2c.h" 5 | ////////////////////////////////////////////////////////////////////////////////// 6 | //±¾³ÌÐòÖ»¹©Ñ§Ï°Ê¹Óã¬Î´¾­×÷ÕßÐí¿É£¬²»µÃÓÃÓÚÆäËüÈκÎÓÃ; 7 | //ALIENTEK STM32F407¿ª·¢°å 8 | //WM8978 Çý¶¯´úÂë 9 | //ÕýµãÔ­×Ó@ALIENTEK 10 | //¼¼ÊõÂÛ̳:www.openedv.com 11 | //´´½¨ÈÕÆÚ:2014/5/24 12 | //°æ±¾£ºV1.0 13 | //°æÈ¨ËùÓУ¬µÁ°æ±Ø¾¿¡£ 14 | //Copyright(C) ¹ãÖÝÊÐÐÇÒíµç×ӿƼ¼ÓÐÏÞ¹«Ë¾ 2014-2024 15 | //All rights reserved 16 | ////////////////////////////////////////////////////////////////////////////////// 17 | 18 | 19 | //Èç¹ûAD0½Å(4½Å)½ÓµØ,IICµØÖ·Îª0X4A(²»°üº¬×îµÍλ). 20 | //Èç¹û½ÓV3.3,ÔòIICµØÖ·Îª0X4B(²»°üº¬×îµÍλ). 21 | #define WM8978_ADDR 0X1A //WM8978µÄÆ÷¼þµØÖ·,¹Ì¶¨Îª0X1A 22 | 23 | #define EQ1_80Hz 0X00 24 | #define EQ1_105Hz 0X01 25 | #define EQ1_135Hz 0X02 26 | #define EQ1_175Hz 0X03 27 | 28 | #define EQ2_230Hz 0X00 29 | #define EQ2_300Hz 0X01 30 | #define EQ2_385Hz 0X02 31 | #define EQ2_500Hz 0X03 32 | 33 | #define EQ3_650Hz 0X00 34 | #define EQ3_850Hz 0X01 35 | #define EQ3_1100Hz 0X02 36 | #define EQ3_14000Hz 0X03 37 | 38 | #define EQ4_1800Hz 0X00 39 | #define EQ4_2400Hz 0X01 40 | #define EQ4_3200Hz 0X02 41 | #define EQ4_4100Hz 0X03 42 | 43 | #define EQ5_5300Hz 0X00 44 | #define EQ5_6900Hz 0X01 45 | #define EQ5_9000Hz 0X02 46 | #define EQ5_11700Hz 0X03 47 | 48 | 49 | #define WM8978_RESET 0x00 50 | 51 | #define WM8978_POWER_MANAGEMENT_1 0x01 52 | 53 | #define WM8978_POWER_MANAGEMENT_2 0x02 54 | 55 | #define WM8978_POWER_MANAGEMENT_3 0x03 56 | 57 | #define WM8978_AUDIO_INTERFACE 0x04 58 | 59 | #define WM8978_COMPANDING_CONTROL 0x05 60 | 61 | #define WM8978_CLOCKING 0x06 62 | 63 | #define WM8978_ADDITIONAL_CONTROL 0x07 64 | 65 | #define WM8978_GPIO_CONTROL 0x08 66 | 67 | #define WM8978_JACK_DETECT_CONTROL_1 0x09 68 | 69 | #define WM8978_DAC_CONTROL 0x0A 70 | 71 | #define WM8978_LEFT_DAC_DIGITAL_VOLUME 0x0B 72 | 73 | #define WM8978_RIGHT_DAC_DIGITAL_VOLUME 0x0C 74 | 75 | #define WM8978_JACK_DETECT_CONTROL_2 0x0D 76 | 77 | #define WM8978_ADC_CONTROL 0x0E 78 | 79 | #define WM8978_LEFT_ADC_DIGITAL_VOLUME 0x0F 80 | 81 | #define WM8978_RIGHT_ADC_DIGITAL_VOLUME 0x10 82 | 83 | #define WM8978_EQ1 0x12 84 | 85 | #define WM8978_EQ2 0x13 86 | 87 | #define WM8978_EQ3 0x14 88 | 89 | #define WM8978_EQ4 0x15 90 | 91 | #define WM8978_EQ5 0x16 92 | 93 | #define WM8978_DAC_LIMITER_1 0x18 94 | 95 | #define WM8978_DAC_LIMITER_2 0x19 96 | 97 | #define WM8978_NOTCH_FILTER_1 0x1b 98 | 99 | #define WM8978_NOTCH_FILTER_2 0x1c 100 | 101 | #define WM8978_NOTCH_FILTER_3 0x1d 102 | 103 | #define WM8978_NOTCH_FILTER_4 0x1e 104 | 105 | #define WM8978_ALC_CONTROL_1 0x20 106 | 107 | #define WM8978_ALC_CONTROL_2 0x21 108 | 109 | #define WM8978_ALC_CONTROL_3 0x22 110 | 111 | #define WM8978_NOISE_GATE 0x23 112 | 113 | #define WM8978_PLL_N 0x24 114 | 115 | #define WM8978_PLL_K1 0x25 116 | 117 | #define WM8978_PLL_K2 0x26 118 | 119 | #define WM8978_PLL_K3 0x27 120 | 121 | #define WM8978_3D_CONTROL 0x29 122 | 123 | #define WM8978_BEEP_CONTROL 0x2b 124 | 125 | #define WM8978_INPUT_CONTROL 0x2c 126 | 127 | #define WM8978_LEFT_INP_PGA_CONTROL 0x2d 128 | 129 | #define WM8978_RIGHT_INP_PGA_CONTROL 0x2e 130 | 131 | #define WM8978_LEFT_ADC_BOOST_CONTROL 0x2f 132 | 133 | #define WM8978_RIGHT_ADC_BOOST_CONTROL 0x30 134 | 135 | #define WM8978_OUTPUT_CONTROL 0x31 136 | 137 | #define WM8978_LEFT_MIXER_CONTROL 0x32 138 | 139 | #define WM8978_RIGHT_MIXER_CONTROL 0x33 140 | 141 | #define WM8978_LOUT1_HP_CONTROL 0x34 142 | 143 | #define WM8978_ROUT1_HP_CONTROL 0x35 144 | 145 | #define WM8978_LOUT2_SPK_CONTROL 0x36 146 | 147 | #define WM8978_ROUT2_SPK_CONTROL 0x37 148 | 149 | #define WM8978_OUT3_MIXER_CONTROL 0x38 150 | 151 | #define WM8978_OUT4_MIXER_CONTROL 0x39 152 | 153 | typedef struct 154 | { 155 | char rld[4]; //riff 标志符号 156 | int rLen; // 157 | char wld[4]; //格式类型(wave) 158 | char fld[4]; //"fmt" 159 | 160 | int fLen; //sizeof(wave format matex) 161 | 162 | short wFormatTag; //编码格式 163 | short wChannels; //声道数 164 | int nSamplesPersec; //采样频率 165 | int nAvgBitsPerSample;//WAVE文件采样大小 166 | short wBlockAlign; //块对齐 167 | short wBitsPerSample; //WAVE文件采样大小 168 | 169 | char dld[4]; //”data“ 170 | int wSampleLength; //音频数据的大小 171 | }WAV_HEADER; 172 | 173 | 174 | uint8_t WM8978_Init(void); 175 | void WM8978_ADDA_Cfg(uint8_t dacen,uint8_t adcen); 176 | void WM8978_Input_Cfg(uint8_t micen,uint8_t lineinen,uint8_t auxen); 177 | void WM8978_Output_Cfg(uint8_t dacen,uint8_t bpsen); 178 | void WM8978_MIC_Gain(uint8_t gain); 179 | void WM8978_LINEIN_Gain(uint8_t gain); 180 | void WM8978_AUX_Gain(uint8_t gain); 181 | uint8_t WM8978_Write_Reg(uint8_t reg,uint16_t val); 182 | uint16_t WM8978_Read_Reg(uint8_t reg); 183 | void WM8978_HPvol_Set(uint8_t voll,uint8_t volr); 184 | void WM8978_SPKvol_Set(uint8_t volx); 185 | void WM8978_I2S_Cfg(uint8_t fmt,uint8_t len); 186 | void WM8978_3D_Set(uint8_t depth); 187 | void WM8978_EQ_3D_Dir(uint8_t dir); 188 | void WM8978_EQ1_Set(uint8_t cfreq,uint8_t gain); 189 | void WM8978_EQ2_Set(uint8_t cfreq,uint8_t gain); 190 | void WM8978_EQ3_Set(uint8_t cfreq,uint8_t gain); 191 | void WM8978_EQ4_Set(uint8_t cfreq,uint8_t gain); 192 | void WM8978_EQ5_Set(uint8_t cfreq,uint8_t gain); 193 | void aplay(char* filename); 194 | 195 | #endif 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | -------------------------------------------------------------------------------- /components/bsp/wm8978.c: -------------------------------------------------------------------------------- 1 | #include "wm8978.h" 2 | #include "hal_i2c.h" 3 | #include 4 | #include 5 | #include 6 | #include "hal_i2s.h" 7 | 8 | 9 | #define bit0 0x001 10 | 11 | #define bit1 0x002 12 | 13 | #define bit2 0x004 14 | 15 | #define bit3 0x008 16 | 17 | #define bit4 0x010 18 | 19 | #define bit5 0x020 20 | 21 | #define bit6 0x040 22 | 23 | #define bit7 0x080 24 | 25 | #define bit8 0x100 26 | ////////////////////////////////////////////////////////////////////////////////// 27 | //????????ѧϰʹ???δ??????ɣ?????????????? 28 | //ALIENTEK STM32F407?????? 29 | //WM8978 ?????? 30 | //?????@ALIENTEK 31 | //????̳:www.openedv.com 32 | //??????:2014/5/24 33 | //?汾??V1.0 34 | //??????????????? 35 | //Copyright(C) ???????ӿƼ?????˾ 2014-2024 36 | //All rights reserved 37 | ////////////////////////////////////////////////////////////////////////////////// 38 | 39 | 40 | //WM8978?Ĵ??ֵ?????(???58???Ĵ??,0~57),ռ?116???ڴ? 41 | //?ΪWM8978??IC?????֧?ֶ????,??????ر??????Ĵ??ֵ 42 | //дWM8978?Ĵ??ʱ,ͬ??????????ؼĴ??ֵ,???Ĵ??ʱ,ֱ?ӷ??ر??ر????Ĵ??ֵ. 43 | //ע?:WM8978?ļĴ??ֵ?9λ????Ҫ?uint16_t???洢. 44 | static uint16_t WM8978_REGVAL_TBL[58]= 45 | { 46 | 0X0000,0X0000,0X0000,0X0000,0X0050,0X0000,0X0140,0X0000, 47 | 0X0000,0X0000,0X0000,0X00FF,0X00FF,0X0000,0X0100,0X00FF, 48 | 0X00FF,0X0000,0X012C,0X002C,0X002C,0X002C,0X002C,0X0000, 49 | 0X0032,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000, 50 | 0X0038,0X000B,0X0032,0X0000,0X0008,0X000C,0X0093,0X00E9, 51 | 0X0000,0X0000,0X0000,0X0000,0X0003,0X0010,0X0010,0X0100, 52 | 0X0100,0X0002,0X0001,0X0001,0X0039,0X0039,0X0039,0X0039, 53 | 0X0001,0X0001 54 | }; 55 | 56 | static void wm8979_interface() 57 | { 58 | 59 | //WM8978_REGVAL_TBL[WM8978_AUDIO_INTERFACE]|=bit0;//mono left phase 60 | WM8978_REGVAL_TBL[WM8978_AUDIO_INTERFACE] &=~(bit6|bit5);//16bit 61 | //WM8978_REGVAL_TBL[WM8978_AUDIO_INTERFACE]|=(bit6|bit5);//32bit 62 | WM8978_Write_Reg(WM8978_AUDIO_INTERFACE,WM8978_REGVAL_TBL[WM8978_AUDIO_INTERFACE]); 63 | WM8978_REGVAL_TBL[WM8978_CLOCKING]|=bit0; //the codec ic is master mode 64 | WM8978_REGVAL_TBL[WM8978_CLOCKING]|=bit3|bit2;// 100 256/16=16; 16 bit 65 | WM8978_REGVAL_TBL[WM8978_CLOCKING]&=~(bit7|bit6|bit5); 66 | WM8978_REGVAL_TBL[WM8978_CLOCKING]|=(bit7|bit5|bit6);// 101 48/6=8 67 | WM8978_REGVAL_TBL[WM8978_CLOCKING]|=bit8; 68 | WM8978_Write_Reg(WM8978_CLOCKING,WM8978_REGVAL_TBL[WM8978_CLOCKING]); 69 | //WM8978_REGVAL_TBL[WM8978_CLOCKING]&=~bit8;//mclk is the clk source 70 | } 71 | static void wm8979_pll(uint32_t k,uint8_t n) 72 | { 73 | WM8978_REGVAL_TBL[WM8978_ADDITIONAL_CONTROL]&=~(bit3|bit2|bit1); 74 | WM8978_REGVAL_TBL[WM8978_ADDITIONAL_CONTROL]|=(bit3|bit1); 75 | WM8978_Write_Reg(WM8978_ADDITIONAL_CONTROL,WM8978_REGVAL_TBL[WM8978_ADDITIONAL_CONTROL]);//sr 8K 76 | 77 | WM8978_REGVAL_TBL[WM8978_POWER_MANAGEMENT_1]|=bit5;//enable pll 78 | WM8978_Write_Reg(WM8978_POWER_MANAGEMENT_1,WM8978_REGVAL_TBL[WM8978_POWER_MANAGEMENT_1]); 79 | WM8978_REGVAL_TBL[WM8978_PLL_N]|=bit4;//prescale enable /2 80 | WM8978_REGVAL_TBL[WM8978_PLL_N]&=0x1f0; 81 | WM8978_REGVAL_TBL[WM8978_PLL_N]|=n;//7 82 | WM8978_Write_Reg(WM8978_PLL_N,WM8978_REGVAL_TBL[WM8978_PLL_N]); 83 | //k=EE009F 84 | WM8978_REGVAL_TBL[WM8978_PLL_K1]=(k>>18); 85 | WM8978_Write_Reg(WM8978_PLL_K1,WM8978_REGVAL_TBL[WM8978_PLL_K1]); 86 | WM8978_REGVAL_TBL[WM8978_PLL_K2]=(k>>9); 87 | WM8978_Write_Reg(WM8978_PLL_K2,WM8978_REGVAL_TBL[WM8978_PLL_K2]); 88 | WM8978_REGVAL_TBL[WM8978_PLL_K3]=k; 89 | WM8978_Write_Reg(WM8978_PLL_K3,WM8978_REGVAL_TBL[WM8978_PLL_K3]); 90 | } 91 | static void wm8979_loopback() 92 | { 93 | 94 | WM8978_REGVAL_TBL[WM8978_COMPANDING_CONTROL]|=bit0; //start loopback 95 | WM8978_Write_Reg(WM8978_COMPANDING_CONTROL,WM8978_REGVAL_TBL[WM8978_COMPANDING_CONTROL]); 96 | 97 | } 98 | //WM8978 init 99 | //返回值:0,初始化正常 100 | // 其他,错误代码 101 | uint8_t WM8978_Init(void) 102 | { 103 | //??Ϊͨ??? 104 | wm8979_pll(0X3126E9,0x08); 105 | wm8979_interface(); 106 | WM8978_Write_Reg(1,0X3B); //R1,MICEN??Ϊ1(MICʹ?),BIASEN??Ϊ1(ģ?????),VMIDSEL[1:0]??Ϊ:11(5K) 107 | WM8978_Write_Reg(2,0X1B0); //R2,ROUT1,LOUT1???ʹ?(??????Թ??),BOOSTENR,BOOSTENLʹ? 108 | WM8978_Write_Reg(3,0X6C); //R3,LOUT2,ROUT2???ʹ?(???ȹ??),RMIX,LMIXʹ? //0x6c 109 | //WM8978_Write_Reg(6,0); //R6,MCLK??????? 110 | WM8978_Write_Reg(43,1<<4); //R43,INVROUT2???,??????? 111 | WM8978_Write_Reg(47,1<<8); //R47??,PGABOOSTL,?ͨ??MIC??20???? 112 | WM8978_Write_Reg(48,1<<8); //R48??,PGABOOSTR,?ͨ??MIC??20???? 113 | WM8978_Write_Reg(49,1<<1); //R49,TSDEN,?????????? 114 | WM8978_Write_Reg(10,1<<3); //R10,SOFTMUTE?ر?128x???,???NR 115 | WM8978_Write_Reg(14,1<<3); //R14,ADC 128x???? 116 | //wm8979_loopback(); 117 | return 0; 118 | } 119 | //WM8978写寄存器 120 | //reg:寄存器地址 121 | //val:要写入寄存器的值 122 | //返回值:0,成功; 123 | //其他,错误代码 124 | uint8_t WM8978_Write_Reg(uint8_t reg,uint16_t val) 125 | { 126 | uint8_t buf[2]; 127 | buf[0]=((val&0x0100)>>8)|(reg<<1); 128 | buf[1]=(uint8_t)(val&0xff); 129 | hal_i2c_master_mem_write(0,WM8978_ADDR,buf[0],buf+1,1); 130 | WM8978_REGVAL_TBL[reg]=val; 131 | return 0; 132 | } 133 | 134 | // WM8978 read register 135 | // Reads the value of the local register buffer zone 136 | // reg: Register Address 137 | // Return Value: Register value 138 | uint16_t WM8978_Read_Reg(uint8_t reg) 139 | { 140 | return WM8978_REGVAL_TBL[reg]; 141 | } 142 | //WM8978 DAC/ADC配置 143 | //adcen:adc使能(1)/关闭(0) 144 | //dacen:dac使能(1)/关闭(0) 145 | 146 | void WM8978_ADDA_Cfg(uint8_t dacen,uint8_t adcen) 147 | { 148 | uint16_t regval; 149 | regval=WM8978_Read_Reg(3); //??ȡR3 150 | if(dacen)regval|=3<<0; //R3?????λ??Ϊ1,???DACR&DACL 151 | else regval&=~(3<<0); //R3?????λ????ر?ACR&DACL. 152 | WM8978_Write_Reg(3,regval); //??R3 153 | regval=WM8978_Read_Reg(2); //??ȡR2 154 | if(adcen)regval|=3<<0; //R2?????λ??Ϊ1,???ADCR&ADCL 155 | else regval&=~(3<<0); //R2?????λ????ر?DCR&ADCL. 156 | WM8978_Write_Reg(2,regval); //??R2 157 | } 158 | //WM8978 输入通道配置 159 | //micen:MIC开启(1)/关闭(0) 160 | //lineinen:Line In开启(1)/关闭(0) 161 | //auxen:aux开启(1)/关闭(0) 162 | void WM8978_Input_Cfg(uint8_t micen,uint8_t lineinen,uint8_t auxen) 163 | { 164 | uint16_t regval; 165 | regval=WM8978_Read_Reg(2); //??ȡR2 166 | if(micen)regval|=3<<2; //???INPPGAENR,INPPGAENL(MIC??GA?Ŵ? 167 | else regval&=~(3<<2); //?ر?NPPGAENR,INPPGAENL. 168 | WM8978_Write_Reg(2,regval); //??R2 169 | 170 | regval=WM8978_Read_Reg(44); //??ȡR44 171 | if(micen)regval|=3<<4|3<<0; //???LIN2INPPGA,LIP2INPGA,RIN2INPPGA,RIP2INPGA. 172 | else regval&=~(3<<4|3<<0); //?ر?IN2INPPGA,LIP2INPGA,RIN2INPPGA,RIP2INPGA. 173 | WM8978_Write_Reg(44,regval);//??R44 174 | 175 | if(lineinen)WM8978_LINEIN_Gain(5);//LINE IN 0dB?? 176 | else WM8978_LINEIN_Gain(0); //?ر?INE IN 177 | if(auxen)WM8978_AUX_Gain(7);//AUX 6dB?? 178 | else WM8978_AUX_Gain(0); //?ر?UX?? 179 | } 180 | //WM8978 输出配置 181 | //dacen:DAC输出(放音)开启(1)/关闭(0) 182 | //bpsen:Bypass输出(录音,包括MIC,LINE IN,AUX等)开启(1)/关闭(0) 183 | void WM8978_Output_Cfg(uint8_t dacen,uint8_t bpsen) 184 | { 185 | uint16_t regval=0; 186 | if(dacen)regval|=1<<0; //DAC???ʹ? 187 | if(bpsen) 188 | { 189 | regval|=1<<1; //BYPASSʹ? 190 | regval|=5<<2; //0dB?? 191 | } 192 | WM8978_Write_Reg(50,regval);//R50?? 193 | WM8978_Write_Reg(51,regval);//R51?? 194 | } 195 | //WM8978 MIC增益设置(不包括BOOST的20dB,MIC-->ADC输入部分的增益) 196 | //gain:0~63,对应-12dB~35.25dB,0.75dB/Step 197 | void WM8978_MIC_Gain(uint8_t gain) 198 | { 199 | gain&=0X3F; 200 | WM8978_Write_Reg(45,gain); //R45,?ͨ??PGA?? 201 | WM8978_Write_Reg(46,gain|1<<8); //R46,?ͨ??PGA?? 202 | } 203 | //WM8978 L2/R2(也就是Line In)增益设置(L2/R2-->ADC输入部分的增益) 204 | //gain:0~7,0表示通道禁止,1~7,对应-12dB~6dB,3dB/Step 205 | void WM8978_LINEIN_Gain(uint8_t gain) 206 | { 207 | uint16_t regval; 208 | gain&=0X07; 209 | regval=WM8978_Read_Reg(47); //??ȡR47 210 | regval&=~(7<<4); //???ԭ?????? 211 | WM8978_Write_Reg(47,regval|gain<<4);//??R47 212 | regval=WM8978_Read_Reg(48); //??ȡR48 213 | regval&=~(7<<4); //???ԭ?????? 214 | WM8978_Write_Reg(48,regval|gain<<4);//??R48 215 | } 216 | 217 | void aplay(char* filename){ 218 | //"/sdcard/test.wav" 219 | WAV_HEADER wav_head; 220 | FILE* f = fopen(filename, "r"); 221 | if (f == NULL) { 222 | printf("Failed to open file for writing"); 223 | return; 224 | } 225 | //fprintf(f, "Hello %s!\n", card->cid.name); 226 | int rlen=fread(&wav_head,1,sizeof(wav_head),f); 227 | if(rlen!=sizeof(wav_head)){ 228 | printf("%s\n","read faliled"); 229 | return; 230 | } 231 | int channels = wav_head.wChannels; 232 | int frequency = wav_head.nSamplesPersec; 233 | int bit = wav_head.wBitsPerSample; 234 | int datalen= wav_head.wSampleLength; 235 | printf("channels:%d,frequency:%d,bit:%d\n",channels,frequency,bit); 236 | char* samples_data = malloc(1024); 237 | 238 | while(datalen){ 239 | rlen=fread(samples_data,1,1024,f); 240 | datalen-=rlen; 241 | hal_i2s_write(0,samples_data,rlen,5000); 242 | } 243 | fclose(f); 244 | free(samples_data); 245 | } 246 | //WM8978 AUXR,AUXL(PWM音频部分)增益设置(AUXR/L-->ADC输入部分的增益) 247 | //gain:0~7,0表示通道禁止,1~7,对应-12dB~6dB,3dB/Step 248 | void WM8978_AUX_Gain(uint8_t gain) 249 | { 250 | uint16_t regval; 251 | gain&=0X07; 252 | regval=WM8978_Read_Reg(47); //??ȡR47 253 | regval&=~(7<<0); //???ԭ?????? 254 | WM8978_Write_Reg(47,regval|gain<<0);//??R47 255 | regval=WM8978_Read_Reg(48); //??ȡR48 256 | regval&=~(7<<0); //???ԭ?????? 257 | WM8978_Write_Reg(48,regval|gain<<0);//??R48 258 | } 259 | //设置I2S工作模式 260 | //fmt:0,LSB(右对齐);1,MSB(左对齐);2,飞利浦标准I2S;3,PCM/DSP; 261 | //len:0,16位;1,20位;2,24位;3,32位; 262 | void WM8978_I2S_Cfg(uint8_t fmt,uint8_t len) 263 | { 264 | fmt&=0X03; 265 | len&=0X03;//?????Χ 266 | WM8978_Write_Reg(4,(fmt<<3)|(len<<5)); //R4,WM8978???ģʽ?? 267 | } 268 | 269 | //设置耳机左右声道音量 270 | //voll:左声道音量(0~63) 271 | //volr:右声道音量(0~63) 272 | void WM8978_HPvol_Set(uint8_t voll,uint8_t volr) 273 | { 274 | voll&=0X3F; 275 | volr&=0X3F;//?????Χ 276 | if(voll==0)voll|=1<<6;//???Ϊ0ʱ,ֱ??ute 277 | if(volr==0)volr|=1<<6;//???Ϊ0ʱ,ֱ??ute 278 | WM8978_Write_Reg(52,voll); //R52,????????????? 279 | WM8978_Write_Reg(53,volr|(1<<8)); //R53,?????????????,ͬ?????(HPVU=1) 280 | } 281 | //设置喇叭音量 282 | //voll:左声道音量(0~63) 283 | void WM8978_SPKvol_Set(uint8_t volx) 284 | { 285 | volx&=0X3F;//?????Χ 286 | if(volx==0)volx|=1<<6;//???Ϊ0ʱ,ֱ??ute 287 | WM8978_Write_Reg(54,volx); //R54,????????????? 288 | WM8978_Write_Reg(55,volx|(1<<8)); //R55,?????????????,ͬ?????(SPKVU=1) 289 | } 290 | //设置3D环绕声 291 | //depth:0~15(3D强度,0最弱,15最强) 292 | void WM8978_3D_Set(uint8_t depth) 293 | { 294 | depth&=0XF;//?????Χ 295 | WM8978_Write_Reg(41,depth); //R41,3D????? 296 | } 297 | //设置EQ/3D作用方向 298 | //dir:0,在ADC起作用 299 | // 1,在DAC起作用(默认) 300 | void WM8978_EQ_3D_Dir(uint8_t dir) 301 | { 302 | uint16_t regval; 303 | regval=WM8978_Read_Reg(0X12); 304 | if(dir)regval|=1<<8; 305 | else regval&=~(1<<8); 306 | WM8978_Write_Reg(18,regval);//R18,EQ1?ĵ?λ???Q/3D??? 307 | } 308 | 309 | //设置EQ1 310 | //cfreq:截止频率,0~3,分别对应:80/105/135/175Hz 311 | //gain:增益,0~24,对应-12~+12dB 312 | void WM8978_EQ1_Set(uint8_t cfreq,uint8_t gain) 313 | { 314 | uint16_t regval; 315 | cfreq&=0X3;//?????Χ 316 | if(gain>24)gain=24; 317 | gain=24-gain; 318 | regval=WM8978_Read_Reg(18); 319 | regval&=0X100; 320 | regval|=cfreq<<5; //?????Ƶ? 321 | regval|=gain; //???? 322 | WM8978_Write_Reg(18,regval);//R18,EQ1?? 323 | } 324 | //设置EQ2 325 | //cfreq:中心频率,0~3,分别对应:230/300/385/500Hz 326 | //gain:增益,0~24,对应-12~+12dB 327 | void WM8978_EQ2_Set(uint8_t cfreq,uint8_t gain) 328 | { 329 | uint16_t regval=0; 330 | cfreq&=0X3;//?????Χ 331 | if(gain>24)gain=24; 332 | gain=24-gain; 333 | regval|=cfreq<<5; //?????Ƶ? 334 | regval|=gain; //???? 335 | WM8978_Write_Reg(19,regval);//R19,EQ2?? 336 | } 337 | //设置EQ3 338 | //cfreq:中心频率,0~3,分别对应:650/850/1100/1400Hz 339 | //gain:增益,0~24,对应-12~+12dB 340 | void WM8978_EQ3_Set(uint8_t cfreq,uint8_t gain) 341 | { 342 | uint16_t regval=0; 343 | cfreq&=0X3;//?????Χ 344 | if(gain>24)gain=24; 345 | gain=24-gain; 346 | regval|=cfreq<<5; //?????Ƶ? 347 | regval|=gain; //???? 348 | WM8978_Write_Reg(20,regval);//R20,EQ3?? 349 | } 350 | //设置EQ4 351 | //cfreq:中心频率,0~3,分别对应:1800/2400/3200/4100Hz 352 | //gain:增益,0~24,对应-12~+12dB 353 | void WM8978_EQ4_Set(uint8_t cfreq,uint8_t gain) 354 | { 355 | uint16_t regval=0; 356 | cfreq&=0X3;//?????Χ 357 | if(gain>24)gain=24; 358 | gain=24-gain; 359 | regval|=cfreq<<5; //?????Ƶ? 360 | regval|=gain; //???? 361 | WM8978_Write_Reg(21,regval);//R21,EQ4?? 362 | } 363 | //设置EQ5 364 | //cfreq:中心频率,0~3,分别对应:5300/6900/9000/11700Hz 365 | //gain:增益,0~24,对应-12~+12dB 366 | void WM8978_EQ5_Set(uint8_t cfreq,uint8_t gain) 367 | { 368 | uint16_t regval=0; 369 | cfreq&=0X3;//?????Χ 370 | if(gain>24)gain=24; 371 | gain=24-gain; 372 | regval|=cfreq<<5; //?????Ƶ? 373 | regval|=gain; //???? 374 | WM8978_Write_Reg(22,regval);//R22,EQ5?? 375 | } 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | -------------------------------------------------------------------------------- /components/espressif/.tags: -------------------------------------------------------------------------------- 1 | !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 2 | !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 3 | !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ 4 | !_TAG_PROGRAM_NAME Exuberant Ctags // 5 | !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 6 | !_TAG_PROGRAM_VERSION 5.9~svn20110310 // 7 | DEFAULT_ETHERNET_PHY_CONFIG eth.c 25;" d file: 8 | ETH_CONNECTED_BIT include/event.h 12;" d 9 | ETH_GOTIP_BIT include/event.h 13;" d 10 | EXAMPLE_DEFAULT_PWD wifi.c 17;" d file: 11 | EXAMPLE_DEFAULT_SSID wifi.c 16;" d file: 12 | EXAMPLE_MAX_STA_CONN wifi.c 19;" d file: 13 | PIN_SMI_MDC eth.c 27;" d file: 14 | PIN_SMI_MDIO eth.c 28;" d file: 15 | STA_CONNECTED_BIT include/event.h 9;" d 16 | STA_GOTIP_BIT include/event.h 10;" d 17 | _ETH_H include/eth.h 2;" d 18 | _EVENT_H include/event.h 2;" d 19 | _WIFI_H include/wifi.h 2;" d 20 | ap_event_group event.c /^EventGroupHandle_t ap_event_group;\/\/24bit$/;" v 21 | eth_event_group event.c /^EventGroupHandle_t eth_event_group;\/\/24bit$/;" v 22 | eth_gpio_config_rmii eth.c /^static void eth_gpio_config_rmii(void)$/;" f file: 23 | eth_init eth.c /^void eth_init(){$/;" f 24 | event_engine_init event.c /^void event_engine_init(){$/;" f 25 | event_handler event.c /^static esp_err_t event_handler(void *ctx, system_event_t *event)$/;" f file: 26 | station_event_group event.c /^EventGroupHandle_t station_event_group;\/\/24bit$/;" v 27 | wifi_init_softap wifi.c /^void wifi_init_softap()$/;" f 28 | wifi_init_sta wifi.c /^void wifi_init_sta()$/;" f 29 | -------------------------------------------------------------------------------- /components/espressif/.tags_sorted_by_file: -------------------------------------------------------------------------------- 1 | !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 2 | !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 3 | !_TAG_PROGRAM_VERSION 5.9~svn20110310 // 4 | !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ 5 | !_TAG_PROGRAM_NAME Exuberant Ctags // 6 | DEFAULT_ETHERNET_PHY_CONFIG eth.c 25;" d file: 7 | PIN_SMI_MDC eth.c 27;" d file: 8 | PIN_SMI_MDIO eth.c 28;" d file: 9 | eth_gpio_config_rmii eth.c /^static void eth_gpio_config_rmii(void)$/;" f file: 10 | eth_init eth.c /^void eth_init(){$/;" f 11 | ap_event_group event.c /^EventGroupHandle_t ap_event_group;\/\/24bit$/;" v 12 | eth_event_group event.c /^EventGroupHandle_t eth_event_group;\/\/24bit$/;" v 13 | event_engine_init event.c /^void event_engine_init(){$/;" f 14 | event_handler event.c /^static esp_err_t event_handler(void *ctx, system_event_t *event)$/;" f file: 15 | station_event_group event.c /^EventGroupHandle_t station_event_group;\/\/24bit$/;" v 16 | !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 17 | _ETH_H include/eth.h 2;" d 18 | ETH_CONNECTED_BIT include/event.h 12;" d 19 | ETH_GOTIP_BIT include/event.h 13;" d 20 | STA_CONNECTED_BIT include/event.h 9;" d 21 | STA_GOTIP_BIT include/event.h 10;" d 22 | _EVENT_H include/event.h 2;" d 23 | _WIFI_H include/wifi.h 2;" d 24 | EXAMPLE_DEFAULT_PWD wifi.c 17;" d file: 25 | EXAMPLE_DEFAULT_SSID wifi.c 16;" d file: 26 | EXAMPLE_MAX_STA_CONN wifi.c 19;" d file: 27 | wifi_init_softap wifi.c /^void wifi_init_softap()$/;" f 28 | wifi_init_sta wifi.c /^void wifi_init_sta()$/;" f 29 | -------------------------------------------------------------------------------- /components/espressif/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | -------------------------------------------------------------------------------- /components/espressif/eth.c: -------------------------------------------------------------------------------- 1 | 2 | #include "esp_system.h" 3 | #include "esp_err.h" 4 | #include "esp_event_loop.h" 5 | #include "esp_event.h" 6 | #include "esp_attr.h" 7 | #include "esp_log.h" 8 | #include "esp_eth.h" 9 | 10 | #include "rom/ets_sys.h" 11 | #include "rom/gpio.h" 12 | 13 | #include "soc/dport_reg.h" 14 | #include "soc/io_mux_reg.h" 15 | #include "soc/rtc_cntl_reg.h" 16 | #include "soc/gpio_reg.h" 17 | #include "soc/gpio_sig_map.h" 18 | 19 | #include "nvs_flash.h" 20 | #include "driver/gpio.h" 21 | 22 | #include "eth_phy/phy_lan8720.h" 23 | #include "eth.h" 24 | #include "event.h" 25 | 26 | 27 | 28 | 29 | #define DEFAULT_ETHERNET_PHY_CONFIG phy_lan8720_default_ethernet_config 30 | 31 | #define PIN_SMI_MDC GPIO_NUM_23 32 | #define PIN_SMI_MDIO GPIO_NUM_18 33 | 34 | static void eth_gpio_config_rmii(void) 35 | { 36 | // RMII data pins are fixed: 37 | // TXD0 = GPIO19 38 | // TXD1 = GPIO22 39 | // TX_EN = GPIO21 40 | // RXD0 = GPIO25 41 | // RXD1 = GPIO26 42 | // CLK == GPIO0 43 | phy_rmii_configure_data_interface_pins(); 44 | // MDC is GPIO 23, MDIO is GPIO 18 45 | phy_rmii_smi_configure_pins(PIN_SMI_MDC, PIN_SMI_MDIO); 46 | } 47 | void eth_init(){ 48 | eth_event_group = xEventGroupCreate(); 49 | esp_err_t ret = ESP_OK; 50 | //tcpip_adapter_init(); 51 | //esp_event_loop_init(NULL, NULL); 52 | 53 | eth_config_t config = DEFAULT_ETHERNET_PHY_CONFIG; 54 | /* Set the PHY address in the example configuration */ 55 | config.phy_addr = 0; 56 | config.gpio_config = eth_gpio_config_rmii; 57 | config.tcpip_input = tcpip_adapter_eth_input; 58 | 59 | ret = esp_eth_init(&config); 60 | 61 | if(ret == ESP_OK) { 62 | esp_eth_enable(); 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /components/espressif/event.c: -------------------------------------------------------------------------------- 1 | //event engine 2 | #include "event.h" 3 | #include "esp_system.h" 4 | #include "esp_event_loop.h" 5 | #include "esp_log.h" 6 | #include "esp_wifi.h" 7 | 8 | 9 | 10 | #define TAG "event:" 11 | 12 | EventGroupHandle_t station_event_group;//24bit 13 | EventGroupHandle_t ap_event_group;//24bit 14 | EventGroupHandle_t eth_event_group;//24bit 15 | 16 | static esp_err_t event_handler(void *ctx, system_event_t *event) 17 | { 18 | switch(event->event_id) { 19 | case SYSTEM_EVENT_STA_START:// station start 20 | esp_wifi_connect(); 21 | break; 22 | case SYSTEM_EVENT_STA_DISCONNECTED: //station disconnect from ap 23 | esp_wifi_connect(); 24 | xEventGroupClearBits(station_event_group, STA_CONNECTED_BIT); 25 | xEventGroupClearBits(station_event_group, STA_GOTIP_BIT); 26 | break; 27 | case SYSTEM_EVENT_STA_CONNECTED: //station connect to ap 28 | xEventGroupSetBits(station_event_group, STA_CONNECTED_BIT); 29 | break; 30 | case SYSTEM_EVENT_STA_GOT_IP: //station get ip 31 | ESP_LOGI(TAG, "got ip:%s\n", 32 | ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip)); 33 | xEventGroupSetBits(station_event_group, STA_GOTIP_BIT); 34 | break; 35 | case SYSTEM_EVENT_AP_STACONNECTED:// a station connect to ap 36 | ESP_LOGI(TAG, "station:"MACSTR" join,AID=%d\n", 37 | MAC2STR(event->event_info.sta_connected.mac), 38 | event->event_info.sta_connected.aid); 39 | //xEventGroupSetBits(tcp_event_group, WIFI_CONNECTED_BIT); 40 | break; 41 | case SYSTEM_EVENT_AP_STADISCONNECTED://a station disconnect from ap 42 | ESP_LOGI(TAG, "station:"MACSTR"leave,AID=%d\n", 43 | MAC2STR(event->event_info.sta_disconnected.mac), 44 | event->event_info.sta_disconnected.aid); 45 | //xEventGroupClearBits(tcp_event_group, WIFI_CONNECTED_BIT); 46 | break; 47 | case SYSTEM_EVENT_ETH_CONNECTED: 48 | xEventGroupSetBits(eth_event_group, ETH_CONNECTED_BIT); 49 | break; 50 | case SYSTEM_EVENT_ETH_DISCONNECTED: 51 | //xEventGroupClearBits(eth_event_group, ETH_CONNECTED_BIT); 52 | //xEventGroupClearBits(eth_event_group, ETH_GOTIP_BIT); 53 | xEventGroupSetBits(eth_event_group, ETH_DISCONNECTED_BIT); 54 | case SYSTEM_EVENT_ETH_GOT_IP: 55 | xEventGroupSetBits(eth_event_group, ETH_GOTIP_BIT); 56 | default: 57 | break; 58 | } 59 | return ESP_OK; 60 | } 61 | 62 | 63 | void event_engine_init(){ 64 | esp_event_loop_init(event_handler,NULL); 65 | } 66 | 67 | 68 | -------------------------------------------------------------------------------- /components/espressif/include/eth.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETH_H 2 | #define _ETH_H 3 | 4 | void eth_init(); 5 | 6 | #endif -------------------------------------------------------------------------------- /components/espressif/include/event.h: -------------------------------------------------------------------------------- 1 | #ifndef _EVENT_H 2 | #define _EVENT_H 3 | 4 | 5 | #include "freertos/FreeRTOS.h" 6 | #include "freertos/task.h" 7 | #include "freertos/event_groups.h" 8 | 9 | #define STA_CONNECTED_BIT BIT0 10 | #define STA_GOTIP_BIT BIT1 11 | 12 | #define ETH_CONNECTED_BIT BIT0 13 | #define ETH_GOTIP_BIT BIT1 14 | #define ETH_DISCONNECTED_BIT BIT2 15 | 16 | extern EventGroupHandle_t station_event_group;//24bit 17 | extern EventGroupHandle_t ap_event_group;//24bit 18 | extern EventGroupHandle_t eth_event_group;//24bit 19 | 20 | 21 | void event_engine_init(); 22 | #endif -------------------------------------------------------------------------------- /components/espressif/include/wifi.h: -------------------------------------------------------------------------------- 1 | #ifndef _WIFI_H 2 | #define _WIFI_H 3 | 4 | void wifi_init_softap(); 5 | void wifi_init_sta(); 6 | 7 | #endif -------------------------------------------------------------------------------- /components/espressif/wifi.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include "freertos/FreeRTOS.h" 6 | #include "freertos/task.h" 7 | #include "freertos/event_groups.h" 8 | #include "esp_wifi.h" 9 | #include "esp_event_loop.h" 10 | #include "esp_log.h" 11 | 12 | #include "wifi.h" 13 | #include "event.h" 14 | 15 | 16 | #define EXAMPLE_DEFAULT_SSID "Frankie" 17 | #define EXAMPLE_DEFAULT_PWD "yp6sfnff" 18 | 19 | #define EXAMPLE_MAX_STA_CONN 1 20 | 21 | #define TAG "wifi:" 22 | 23 | 24 | void wifi_init_sta() 25 | { 26 | station_event_group = xEventGroupCreate(); 27 | 28 | //tcpip_adapter_init(); 29 | 30 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); 31 | ESP_ERROR_CHECK(esp_wifi_init(&cfg)); 32 | ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_FLASH)); 33 | wifi_config_t wifi_config = { 34 | .sta = { 35 | .ssid = EXAMPLE_DEFAULT_SSID, 36 | .password = EXAMPLE_DEFAULT_PWD 37 | }, 38 | }; 39 | 40 | ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); 41 | ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) ); 42 | ESP_ERROR_CHECK(esp_wifi_start() ); 43 | 44 | ESP_LOGI(TAG, "wifi_init_sta finished."); 45 | ESP_LOGI(TAG, "connect to ap SSID:%s password:%s \n", 46 | EXAMPLE_DEFAULT_SSID,EXAMPLE_DEFAULT_PWD); 47 | } 48 | void wifi_init_softap() 49 | { 50 | ap_event_group = xEventGroupCreate(); 51 | 52 | //tcpip_adapter_init(); 53 | 54 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); 55 | ESP_ERROR_CHECK(esp_wifi_init(&cfg)); 56 | wifi_config_t wifi_config = { 57 | .ap = { 58 | .ssid = EXAMPLE_DEFAULT_SSID, 59 | .ssid_len = 0, 60 | .max_connection=EXAMPLE_MAX_STA_CONN, 61 | .password = EXAMPLE_DEFAULT_PWD, 62 | .authmode = WIFI_AUTH_WPA_WPA2_PSK 63 | }, 64 | }; 65 | if (strlen(EXAMPLE_DEFAULT_PWD) ==0) { 66 | wifi_config.ap.authmode = WIFI_AUTH_OPEN; 67 | } 68 | 69 | ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP)); 70 | ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config)); 71 | ESP_ERROR_CHECK(esp_wifi_start()); 72 | 73 | ESP_LOGI(TAG, "wifi_init_softap finished.SSID:%s password:%s \n", 74 | EXAMPLE_DEFAULT_SSID, EXAMPLE_DEFAULT_PWD); 75 | } -------------------------------------------------------------------------------- /components/hal/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | -------------------------------------------------------------------------------- /components/hal/hal_eth.c: -------------------------------------------------------------------------------- 1 | //#include "esp_eth.h" 2 | #include "hal_eth.h" 3 | #include "soc/io_mux_reg.h" 4 | #include "eth_phy/phy_lan8720.h" 5 | #include "tcpip_adapter.h" 6 | #include "driver/gpio.h" 7 | #include "esp_system.h" 8 | #include "soc/emac_ex_reg.h" 9 | 10 | #define PIN_SMI_MDC GPIO_NUM_23 11 | #define PIN_SMI_MDIO GPIO_NUM_18 12 | 13 | extern void rtc_plla_ena(bool ena, uint32_t sdm0, uint32_t sdm1, uint32_t sdm2, uint32_t o_div); 14 | 15 | static void eth_gpio_config_rmii() 16 | { 17 | // RMII data pins are fixed: 18 | // TXD0 = GPIO19 19 | // TXD1 = GPIO22 20 | // TX_EN = GPIO21 21 | // RXD0 = GPIO25 22 | // RXD1 = GPIO26 23 | // CLK == GPIO0 24 | //phy_rmii_configure_data_interface_pins(); 25 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO27_U, FUNC_GPIO27_EMAC_RX_DV); 26 | 27 | // TXD0 to GPIO19 28 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U, FUNC_GPIO19_EMAC_TXD0); 29 | // TX_EN to GPIO21 30 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO21_U, FUNC_GPIO21_EMAC_TX_EN); 31 | // TXD1 to GPIO22 32 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO22_U, FUNC_GPIO22_EMAC_TXD1); 33 | //clk out to GPIO17 34 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO16_U, FUNC_GPIO16_EMAC_CLK_OUT); 35 | // for rev0 chip: f_out = f_xtal * (sdm2 + 4) / (2 * (o_div + 2)) 36 | // so for 40MHz XTAL, sdm2 = 1 and o_div = 1 will give 50MHz //output 37 | 38 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO16_U, FUNC_GPIO16_EMAC_CLK_OUT); 39 | // REG_SET_FIELD(EMAC_EX_CLKOUT_CONF_REG, EMAC_EX_CLK_OUT_H_DIV_NUM, 0); 40 | // REG_SET_FIELD(EMAC_EX_CLKOUT_CONF_REG, EMAC_EX_CLK_OUT_DIV_NUM, 0); 41 | // REG_CLR_BIT(EMAC_EX_CLK_CTRL_REG, EMAC_EX_EXT_OSC_EN); 42 | // REG_SET_BIT(EMAC_EX_CLK_CTRL_REG, EMAC_EX_INT_OSC_EN); 43 | // rtc_plla_ena(1, 0, 0, 1, 0); 44 | printf("ok!!!!!"); 45 | // RXD0 to GPIO25 46 | gpio_set_direction(25, GPIO_MODE_INPUT); 47 | // RXD1 to GPIO26 48 | gpio_set_direction(26, GPIO_MODE_INPUT); 49 | phy_rmii_smi_configure_pins(PIN_SMI_MDC, PIN_SMI_MDIO); 50 | } 51 | // static void tcpip_adapter_init(void) 52 | // { 53 | // static bool tcpip_inited = false; 54 | // int ret; 55 | 56 | // if (tcpip_inited == false) { 57 | // tcpip_inited = true; 58 | 59 | // tcpip_init(NULL, NULL); 60 | 61 | // IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].ip, 192, 168 , 31, 100); 62 | // IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].gw, 192, 168 , 31, 1); 63 | // IP4_ADDR(&esp_ip[TCPIP_ADAPTER_IF_AP].netmask, 255, 255 , 255, 0); 64 | // ret = sys_sem_new(&api_sync_sem, 0); 65 | // if (ERR_OK != ret) { 66 | // ESP_LOGD( "tcpip adatper api sync sem init fail"); 67 | // } 68 | // } 69 | // } 70 | esp_err_t hal_eht_init() 71 | { 72 | esp_err_t ret = ESP_OK; 73 | tcpip_adapter_init(); 74 | 75 | eth_config_t config = phy_lan8720_default_ethernet_config; 76 | //config.mac_mode=ETH_MODE_RMII_INT_50MHZ_CLK; 77 | config.gpio_config = eth_gpio_config_rmii; 78 | config.tcpip_input = tcpip_adapter_eth_input; 79 | 80 | ret = esp_eth_init(&config); 81 | return ret; 82 | } 83 | -------------------------------------------------------------------------------- /components/hal/hal_i2c.c: -------------------------------------------------------------------------------- 1 | #include "hal_i2c.h" 2 | #include "driver/i2c.h" 3 | 4 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/ 5 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */ 6 | #define ACK_VAL 0x0 /*!< I2C ack value */ 7 | #define NACK_VAL 0x1 /*!< I2C nack value */ 8 | 9 | #define I2C_EXAMPLE_MASTER_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ 10 | #define I2C_EXAMPLE_MASTER_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ 11 | 12 | 13 | void hal_i2c_init(uint8_t port ,uint8_t sda,uint8_t scl) 14 | { 15 | int i2c_master_port = (i2c_port_t)port; 16 | i2c_config_t conf; 17 | conf.mode = I2C_MODE_MASTER; 18 | conf.sda_io_num = sda; 19 | conf.sda_pullup_en = GPIO_PULLDOWN_DISABLE; 20 | conf.scl_io_num = scl; 21 | conf.scl_pullup_en = GPIO_PULLDOWN_DISABLE; 22 | conf.master.clk_speed = 100000; 23 | i2c_param_config(i2c_master_port, &conf); 24 | i2c_driver_install(i2c_master_port, conf.mode, 25 | I2C_EXAMPLE_MASTER_RX_BUF_DISABLE, 26 | I2C_EXAMPLE_MASTER_TX_BUF_DISABLE, 0); 27 | } 28 | esp_err_t hal_i2c_master_mem_write(i2c_port_t i2c_num, uint8_t DevAddr,uint8_t MemAddr,uint8_t* data_wr, size_t size) 29 | { 30 | if (size == 0) { 31 | return ESP_OK; 32 | } 33 | i2c_cmd_handle_t cmd = i2c_cmd_link_create();//a cmd list 34 | i2c_master_start(cmd); 35 | i2c_master_write_byte(cmd, ( DevAddr << 1 ) | I2C_MASTER_WRITE, ACK_CHECK_EN); 36 | i2c_master_write_byte(cmd, MemAddr, ACK_CHECK_EN); 37 | i2c_master_write(cmd, data_wr, size, ACK_CHECK_EN); 38 | i2c_master_stop(cmd); 39 | esp_err_t ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS); 40 | i2c_cmd_link_delete(cmd); 41 | return ret; 42 | } 43 | esp_err_t hal_i2c_master_mem_read(i2c_port_t i2c_num, uint8_t DevAddr,uint8_t MemAddr,uint8_t* data_rd, size_t size) 44 | { 45 | if (size == 0) { 46 | return ESP_OK; 47 | } 48 | i2c_cmd_handle_t cmd = i2c_cmd_link_create();//a cmd list 49 | i2c_master_start(cmd); 50 | i2c_master_write_byte(cmd, ( DevAddr << 1 ) | I2C_MASTER_WRITE, ACK_CHECK_EN); 51 | i2c_master_start(cmd); 52 | i2c_master_write_byte(cmd, ( DevAddr << 1 ) | I2C_MASTER_READ, ACK_CHECK_EN); 53 | if (size > 1) { 54 | i2c_master_read(cmd, data_rd, size - 1, ACK_VAL); 55 | } 56 | i2c_master_read_byte(cmd, data_rd + size - 1, NACK_VAL); 57 | i2c_master_stop(cmd); 58 | esp_err_t ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS); 59 | i2c_cmd_link_delete(cmd); 60 | return ret; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /components/hal/hal_i2s.c: -------------------------------------------------------------------------------- 1 | #include "freertos/FreeRTOS.h" 2 | #include "driver/i2s.h" 3 | #include "hal_i2s.h" 4 | #include "soc/io_mux_reg.h" 5 | #include "soc/soc.h" 6 | 7 | void hal_i2s_init(uint8_t i2s_num,uint32_t rate,uint8_t bits,uint8_t ch) 8 | { 9 | 10 | i2s_channel_fmt_t chanel; 11 | if(ch==2) 12 | chanel=I2S_CHANNEL_FMT_RIGHT_LEFT; 13 | else 14 | chanel=I2S_CHANNEL_FMT_ONLY_LEFT; 15 | 16 | i2s_config_t i2s_config = { 17 | .mode = I2S_MODE_SLAVE | I2S_MODE_TX|I2S_MODE_RX, 18 | .sample_rate = rate, 19 | .bits_per_sample = bits, 20 | .channel_format = chanel, //2-channels 21 | .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB, 22 | .dma_buf_count = 4, 23 | .dma_buf_len = 256, // 24 | .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 //Interrupt level 1 25 | }; 26 | i2s_pin_config_t pin_config = { 27 | .bck_io_num = 34, 28 | .ws_io_num = 35, 29 | .data_out_num = 32, 30 | .data_in_num = 33 //Not used 31 | }; 32 | i2s_driver_install(i2s_num, &i2s_config, 0, NULL); 33 | i2s_set_pin(i2s_num, &pin_config); 34 | //clk out 35 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); 36 | //REG_SET_FIELD(PIN_CTRL,CLK_OUT1, 0); 37 | //i2s_set_clk(i2s_num, rate, bits, ch); 38 | } 39 | int hal_i2s_read(uint8_t i2s_num,char* dest,size_t size,TickType_t timeout) 40 | { 41 | return i2s_read_bytes(i2s_num, dest, size, timeout); 42 | } 43 | int hal_i2s_write(uint8_t i2s_num,char* dest,size_t size,TickType_t timeout) 44 | { 45 | return i2s_write_bytes(i2s_num, dest, size, timeout); 46 | } 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /components/hal/include/hal_eth.h: -------------------------------------------------------------------------------- 1 | #ifndef HAL_ETH_H 2 | #define HAL_ETH_H 3 | 4 | #include "esp_eth.h" 5 | esp_err_t hal_eht_init(); 6 | 7 | #endif -------------------------------------------------------------------------------- /components/hal/include/hal_i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef _HAL_I2C_H 2 | #define _HAL_I2C_H 3 | 4 | #include "driver/i2c.h" 5 | esp_err_t hal_i2c_master_mem_read(i2c_port_t i2c_num, uint8_t DevAddr,uint8_t MemAddr,uint8_t* data_rd, size_t size); 6 | esp_err_t hal_i2c_master_mem_write(i2c_port_t i2c_num, uint8_t DevAddr,uint8_t MemAddr,uint8_t* data_wr, size_t size); 7 | void hal_i2c_init(uint8_t port ,uint8_t sda,uint8_t scl); 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /components/hal/include/hal_i2s.h: -------------------------------------------------------------------------------- 1 | #ifndef HAL_I2S_H 2 | #define HAL_I2S_H 3 | 4 | 5 | #include "driver/i2s.h" 6 | 7 | void hal_i2s_init(uint8_t i2s_num,uint32_t rate,uint8_t bits,uint8_t ch); 8 | int hal_i2s_read(uint8_t i2s_num,char* dest,size_t size,TickType_t timeout); 9 | int hal_i2s_write(uint8_t i2s_num,char* dest,size_t size,TickType_t timeout); 10 | #endif 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /components/http/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | -------------------------------------------------------------------------------- /components/http/http.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "freertos/event_groups.h" 5 | #include "esp_system.h" 6 | #include "esp_wifi.h" 7 | #include "esp_event_loop.h" 8 | #include "esp_log.h" 9 | #include "nvs_flash.h" 10 | #include "errno.h" 11 | 12 | #include "lwip/err.h" 13 | #include "lwip/sockets.h" 14 | #include "lwip/sys.h" 15 | #include "lwip/netdb.h" 16 | #include "lwip/dns.h" 17 | 18 | #include "url_parser.h" 19 | #include "http.h" 20 | 21 | 22 | #define TAG "http_client" 23 | 24 | int http_client_post(char *uri, http_parser_settings *callbacks, void *user_data,char* post_data) 25 | { 26 | url_t *url = url_parse(uri); 27 | 28 | const struct addrinfo hints = { 29 | .ai_family = AF_INET, 30 | .ai_socktype = SOCK_STREAM, 31 | }; 32 | struct addrinfo *res; 33 | struct in_addr *addr; 34 | char port_str[6]; // stack allocated 35 | snprintf(port_str, 6, "%d", url->port); 36 | 37 | int err = getaddrinfo(url->host, port_str, &hints, &res); 38 | if(err != ESP_OK || res == NULL) { 39 | ESP_LOGE(TAG, "DNS lookup failed err=%d res=%p", err, res); 40 | return err; 41 | } 42 | 43 | // print resolved IP 44 | addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr; 45 | ESP_LOGI(TAG, "DNS lookup succeeded. IP=%s", inet_ntoa(*addr)); 46 | 47 | // allocate socket 48 | int sock = socket(res->ai_family, res->ai_socktype, 0); 49 | if(sock < 0) { 50 | ESP_LOGE(TAG, "... Failed to allocate socket."); 51 | freeaddrinfo(res); 52 | } 53 | ESP_LOGI(TAG, "... allocated socket"); 54 | 55 | 56 | // connect, retrying a few times 57 | char retries = 0; 58 | while(connect(sock, res->ai_addr, res->ai_addrlen) != 0) { 59 | retries++; 60 | ESP_LOGE(TAG, "... socket connect attempt %d failed, errno=%d", retries, errno); 61 | 62 | if(retries > 5) { 63 | ESP_LOGE(TAG, "giving up"); 64 | close(sock); 65 | freeaddrinfo(res); 66 | return ESP_FAIL; 67 | } 68 | } 69 | 70 | ESP_LOGI(TAG, "... connected"); 71 | freeaddrinfo(res); 72 | 73 | // write http request 74 | char *request; 75 | if(asprintf(&request, "POST %s HTTP/1.0\r\nHost: %s:%d\r\nContent-Length: %d\r\nUser-Agent: ESP32\r\nAccept: */*\r\n\r\n%s\r\n\r\n", url->path, url->host, url->port,strlen(post_data),post_data) < 0) 76 | { 77 | return ESP_FAIL; 78 | } 79 | 80 | ESP_LOGI(TAG, "requesting %s", request); 81 | 82 | if (write(sock, request, strlen(request)) < 0) { 83 | ESP_LOGE(TAG, "... socket send failed"); 84 | close(sock); 85 | } 86 | 87 | free(request); 88 | ESP_LOGI(TAG, "... socket send success"); 89 | 90 | 91 | /* Read HTTP response */ 92 | char recv_buf[64]; 93 | bzero(recv_buf, sizeof(recv_buf)); 94 | ssize_t recved; 95 | 96 | /* intercept on_headers_complete() */ 97 | 98 | /* parse response */ 99 | http_parser parser; 100 | http_parser_init(&parser, HTTP_RESPONSE); 101 | parser.data = user_data; 102 | 103 | esp_err_t nparsed = 0; 104 | do { 105 | recved = read(sock, recv_buf, sizeof(recv_buf)-1); 106 | 107 | // using http parser causes stack overflow somtimes - disable for now 108 | nparsed = http_parser_execute(&parser, callbacks, recv_buf, recved); 109 | 110 | // invoke on_body cb directly 111 | // nparsed = callbacks->on_body(&parser, recv_buf, recved); 112 | } while(recved > 0 && nparsed >= 0); 113 | 114 | free(url); 115 | 116 | ESP_LOGI(TAG, "... done reading from socket. Last read return=%d errno=%d", recved, errno); 117 | close(sock); 118 | ESP_LOGI(TAG, "socket closed"); 119 | 120 | return 0; 121 | } 122 | /** 123 | * @brief Application specified event callback function 124 | * 125 | * @param char *recv_buf : buffer 126 | * @param ssize_t bytes_read : bytes read 127 | * 128 | * @return ESP_OK : succeed 129 | * @return others : fail 130 | */ 131 | typedef esp_err_t (*stream_reader_cb)(char *recv_buf, ssize_t bytes_read, void *user_data); 132 | 133 | /** 134 | * @brief simple http_get 135 | * see https://github.com/nodejs/http-parser for callback usage 136 | */ 137 | int http_client_get(char *uri, http_parser_settings *callbacks, void *user_data) 138 | { 139 | url_t *url = url_parse(uri); 140 | 141 | const struct addrinfo hints = { 142 | .ai_family = AF_INET, 143 | .ai_socktype = SOCK_STREAM, 144 | }; 145 | struct addrinfo *res; 146 | struct in_addr *addr; 147 | char port_str[6]; // stack allocated 148 | snprintf(port_str, 6, "%d", url->port); 149 | 150 | int err = getaddrinfo(url->host, port_str, &hints, &res); 151 | if(err != ESP_OK || res == NULL) { 152 | ESP_LOGE(TAG, "DNS lookup failed err=%d res=%p", err, res); 153 | return err; 154 | } 155 | 156 | // print resolved IP 157 | addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr; 158 | ESP_LOGI(TAG, "DNS lookup succeeded. IP=%s", inet_ntoa(*addr)); 159 | 160 | // allocate socket 161 | int sock = socket(res->ai_family, res->ai_socktype, 0); 162 | if(sock < 0) { 163 | ESP_LOGE(TAG, "... Failed to allocate socket."); 164 | freeaddrinfo(res); 165 | } 166 | ESP_LOGI(TAG, "... allocated socket"); 167 | 168 | 169 | // connect, retrying a few times 170 | char retries = 0; 171 | while(connect(sock, res->ai_addr, res->ai_addrlen) != 0) { 172 | retries++; 173 | ESP_LOGE(TAG, "... socket connect attempt %d failed, errno=%d", retries, errno); 174 | 175 | if(retries > 5) { 176 | ESP_LOGE(TAG, "giving up"); 177 | close(sock); 178 | freeaddrinfo(res); 179 | return ESP_FAIL; 180 | } 181 | } 182 | 183 | ESP_LOGI(TAG, "... connected"); 184 | freeaddrinfo(res); 185 | 186 | // write http request 187 | char *request; 188 | if(asprintf(&request, "POST %s HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: ESP32\r\nAccept: */*\r\n\r\n", url->path, url->host, url->port) < 0) 189 | { 190 | return ESP_FAIL; 191 | } 192 | 193 | ESP_LOGI(TAG, "requesting %s", request); 194 | 195 | if (write(sock, request, strlen(request)) < 0) { 196 | ESP_LOGE(TAG, "... socket send failed"); 197 | close(sock); 198 | } 199 | 200 | free(request); 201 | ESP_LOGI(TAG, "... socket send success"); 202 | 203 | 204 | /* Read HTTP response */ 205 | char recv_buf[64]; 206 | bzero(recv_buf, sizeof(recv_buf)); 207 | ssize_t recved; 208 | 209 | /* intercept on_headers_complete() */ 210 | 211 | /* parse response */ 212 | http_parser parser; 213 | http_parser_init(&parser, HTTP_RESPONSE); 214 | parser.data = user_data; 215 | 216 | esp_err_t nparsed = 0; 217 | do { 218 | recved = read(sock, recv_buf, sizeof(recv_buf)-1); 219 | 220 | // using http parser causes stack overflow somtimes - disable for now 221 | nparsed = http_parser_execute(&parser, callbacks, recv_buf, recved); 222 | 223 | // invoke on_body cb directly 224 | // nparsed = callbacks->on_body(&parser, recv_buf, recved); 225 | } while(recved > 0 && nparsed >= 0); 226 | 227 | free(url); 228 | 229 | ESP_LOGI(TAG, "... done reading from socket. Last read return=%d errno=%d", recved, errno); 230 | close(sock); 231 | ESP_LOGI(TAG, "socket closed"); 232 | 233 | return 0; 234 | } -------------------------------------------------------------------------------- /components/http/include/http.h: -------------------------------------------------------------------------------- 1 | #ifndef _HTTP_H_ 2 | #define _HTTP_H_ 3 | 4 | #include "http_parser.h" 5 | 6 | 7 | 8 | int http_client_get(char *uri, http_parser_settings *callbacks, void *user_data); 9 | int http_client_post(char *uri, http_parser_settings *callbacks, void *user_data,char* post_data); 10 | 11 | #endif -------------------------------------------------------------------------------- /components/http/include/url_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * url_parser.h 3 | * 4 | * Created on: 29.03.2017 5 | * Author: michaelboeckling 6 | */ 7 | 8 | #ifndef _URL_PARSER_H_ 9 | #define _URL_PARSER_H_ 10 | 11 | 12 | typedef struct 13 | { 14 | /* The host portion of the |uri|, NULL-terminated */ 15 | char *host; 16 | 17 | /* The schema portion of the |uri|, NULL-terminated */ 18 | char *scheme; 19 | 20 | /* The port portion of the |uri|, or the schema's default port */ 21 | uint16_t port; 22 | 23 | /* The authority portion of the |uri|, NULL-terminated */ 24 | char *authority; 25 | 26 | /* The path portion of the |uri|, including query, NULL-terminated */ 27 | char *path; 28 | 29 | } url_t; 30 | 31 | 32 | url_t *url_parse(char *uri); 33 | 34 | void url_free(url_t *url); 35 | 36 | 37 | #endif /* _URL_PARSER_H_ */ -------------------------------------------------------------------------------- /components/http/url_parser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * url_parser.c 3 | * 4 | * This is a wrapper around http_parser_url to simplify usage. 5 | * 6 | * Created on: 29.03.2017 7 | * Author: michaelboeckling 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "esp_log.h" 16 | 17 | #include "http_parser.h" 18 | #include "url_parser.h" 19 | 20 | #define TAG "url_parser" 21 | 22 | 23 | static char* url_get_scheme(struct http_parser_url *url, char *uri) 24 | { 25 | return strndup(&uri[url->field_data[UF_SCHEMA].off], url->field_data[UF_SCHEMA].len); 26 | } 27 | 28 | static char* url_get_host(struct http_parser_url *url, char *uri) 29 | { 30 | return strndup(&uri[url->field_data[UF_HOST].off], url->field_data[UF_HOST].len); 31 | } 32 | 33 | static uint16_t url_get_port(struct http_parser_url *url) 34 | { 35 | uint16_t port; 36 | 37 | if (url->field_set & (1 << UF_PORT)) { 38 | port = url->port; 39 | } else { 40 | // assume: 4 = http, 5 = https 41 | port = (url->field_data[UF_SCHEMA].len == 5) ? 443 : 80; 42 | } 43 | 44 | return port; 45 | } 46 | 47 | static char* url_get_authority(struct http_parser_url *url, char *uri) 48 | { 49 | char *authority; 50 | 51 | /* MAX 5 digits (max 65535) + 1 ':' + 1 NULL (because of snprintf) */ 52 | size_t extra = 7; 53 | 54 | uint16_t authoritylen = url->field_data[UF_HOST].len; 55 | authority = calloc(authoritylen + extra, sizeof(char)); 56 | memcpy(authority, 57 | &uri[url->field_data[UF_HOST].off], 58 | url->field_data[UF_HOST].len); 59 | /* maybe add port */ 60 | if (url->field_set & (1 << UF_PORT)) { 61 | authoritylen += (size_t) snprintf(authority + authoritylen, 62 | extra, ":%u", url->port); 63 | } 64 | authority[authoritylen] = '\0'; 65 | 66 | return authority; 67 | } 68 | 69 | static char* url_get_path(struct http_parser_url *url, char *uri) 70 | { 71 | /* path */ 72 | char *path; 73 | 74 | /* If we don't have path in URI, we use "/" as path. */ 75 | uint16_t pathlen = 1; 76 | if (url->field_set & (1 << UF_PATH)) { 77 | pathlen = url->field_data[UF_PATH].len; 78 | } 79 | if (url->field_set & (1 << UF_QUERY)) { 80 | /* +1 for '?' character */ 81 | pathlen += (size_t) (url->field_data[UF_QUERY].len + 1); 82 | } 83 | 84 | /* +1 for \0 */ 85 | path = malloc(pathlen + 1); 86 | if (url->field_set & (1 << UF_PATH)) { 87 | memcpy(path, &uri[url->field_data[UF_PATH].off], 88 | url->field_data[UF_PATH].len); 89 | } else { 90 | path[0] = '/'; 91 | } 92 | 93 | if (url->field_set & (1 << UF_QUERY)) { 94 | path[pathlen - url->field_data[UF_QUERY].len - 1] = '?'; 95 | memcpy( 96 | path + pathlen - url->field_data[UF_QUERY].len, 97 | &uri[url->field_data[UF_QUERY].off], url->field_data[UF_QUERY].len); 98 | } 99 | path[pathlen] = '\0'; 100 | 101 | return path; 102 | } 103 | 104 | 105 | url_t *url_parse(char *uri) 106 | { 107 | struct http_parser_url *url_parser = calloc(1, sizeof(struct http_parser_url)); 108 | if(url_parser == NULL) { 109 | ESP_LOGE(TAG, "could not allocate http_parser_url"); 110 | return NULL; 111 | } 112 | 113 | int ret = http_parser_parse_url(uri, strlen(uri), 0, url_parser); 114 | if (ret != 0) { 115 | ESP_LOGE(TAG, "Could not parse URI %s", uri); 116 | return NULL; 117 | } 118 | 119 | url_t *url = calloc(1, sizeof(url_t)); 120 | if(url_parser == NULL) { 121 | ESP_LOGE(TAG, "could not allocate url_t"); 122 | return NULL; 123 | } 124 | 125 | url->scheme = url_get_scheme(url_parser, uri); 126 | url->host = url_get_host(url_parser, uri); 127 | url->port = url_get_port(url_parser); 128 | url->authority = url_get_authority(url_parser, uri); 129 | url->path = url_get_path(url_parser, uri); 130 | 131 | free(url_parser); 132 | 133 | return url; 134 | } 135 | 136 | void url_free(url_t *url) 137 | { 138 | if(url->scheme != NULL) free(url->scheme); 139 | if(url->host != NULL) free(url->host); 140 | if(url->authority != NULL) free(url->authority); 141 | if(url->path != NULL) free(url->path); 142 | 143 | free(url); 144 | } -------------------------------------------------------------------------------- /components/rest/baidu_rest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "freertos/FreeRTOS.h" 5 | #include "freertos/task.h" 6 | #include "freertos/queue.h" 7 | #include "freertos/event_groups.h" 8 | #include "esp_log.h" 9 | #include "lwip/err.h" 10 | #include "lwip/sockets.h" 11 | #include "lwip/sys.h" 12 | #include "lwip/netdb.h" 13 | #include "lwip/dns.h" 14 | #include "baidu_rest.h" 15 | #include "http.h" 16 | #include "driver/gpio.h" 17 | #include "cJSON.h" 18 | #include "hal_i2s.h" 19 | #include "wm8978.h" 20 | #include "http_parser.h" 21 | #include "url_parser.h" 22 | #include "mbedtls/base64.h" 23 | 24 | #define TAG "REST:" 25 | 26 | static uint8_t vad_check(int16_t* data,uint32_t lenght); 27 | 28 | #define GPIO_OUTPUT_IO_0 16 29 | #define GPIO_OUTPUT_PIN_SEL ((1<status_code); 38 | // cJSON *root; 39 | // root= cJSON_Parse(http_body); 40 | // char* err_msg; 41 | // err_msg=cJSON_GetObjectItem(root,"err_msg")->valuestring; 42 | // ESP_LOGI(TAG,"err_msg:%s",err_msg); 43 | // char* sn; 44 | // err_msg=cJSON_GetObjectItem(root,"sn")->valuestring; 45 | // ESP_LOGI(TAG,"sn:%s",err_msg); 46 | // int err_no; 47 | // err_no=cJSON_GetObjectItem(root,"err_no")->valueint; 48 | // ESP_LOGI(TAG,"err_msg:%d",err_no); 49 | // cJSON_Delete(root); 50 | //printf("recv data:%s\n", http_body); 51 | //ESP_LOGI(TAG,"received body:%s",http_body); 52 | return 0; 53 | } 54 | static int body_done_callback (http_parser* a){ 55 | http_body=realloc(http_body,http_body_length+1); 56 | http_body[http_body_length]='\0'; 57 | // ESP_LOGI(TAG,"return code:%d",a->status_code); 58 | // ESP_LOGI(TAG,"request method:%d",a->method); 59 | // ESP_LOGI(TAG,"data:%s",http_body); 60 | cJSON *root; 61 | root= cJSON_Parse(http_body); 62 | char* err_msg; 63 | err_msg=cJSON_GetObjectItem(root,"err_msg")->valuestring; 64 | ESP_LOGI(TAG,"err_msg:%s",err_msg); 65 | char* sn; 66 | err_msg=cJSON_GetObjectItem(root,"sn")->valuestring; 67 | ESP_LOGI(TAG,"sn:%s",err_msg); 68 | int err_no; 69 | err_no=cJSON_GetObjectItem(root,"err_no")->valueint; 70 | ESP_LOGI(TAG,"err_msg:%d",err_no); 71 | cJSON_Delete(root); 72 | ESP_LOGI(TAG,"received body:%s",http_body); 73 | free(http_body); 74 | return 0; 75 | } 76 | 77 | static http_parser_settings settings_null = 78 | { .on_message_begin = 0 79 | ,.on_header_field = 0 80 | ,.on_header_value = 0 81 | ,.on_url = 0 82 | ,.on_status = 0 83 | ,.on_body = body_callback 84 | ,.on_headers_complete = 0 85 | ,.on_message_complete = body_done_callback 86 | ,.on_chunk_header = 0 87 | ,.on_chunk_complete = 0 88 | }; 89 | 90 | #define MAX_LENGTH 8*1000*16*10 //base64 8k 16bits 40s 91 | const char* stream_head="{\"format\":\"wav\",\"cuid\":\"esp32_whyengineer\",\"token\":\"24.44810154581d4b7e8cc3554c90b949f0.2592000.1505980562.282335-10037482\",\"rate\":8000,\"channel\":1,\"speech\":\"";//","len":0,}" 92 | const char* stream_len="\",\"len\":"; 93 | const char* stream_tail="}"; 94 | static int baid_http_post(http_parser_settings *callbacks, void *user_data) 95 | { 96 | url_t *url = url_parse("http://vop.baidu.com/server_api"); 97 | FILE* f = fopen("/sdcard/record.wav", "r"); 98 | fseek(f,sizeof(WAV_HEADER),SEEK_SET); 99 | if (f == NULL) { 100 | ESP_LOGE(TAG,"Failed to open file for writing"); 101 | return ESP_FAIL; 102 | } 103 | const struct addrinfo hints = { 104 | .ai_family = AF_INET, 105 | .ai_socktype = SOCK_STREAM, 106 | }; 107 | struct addrinfo *res; 108 | struct in_addr *addr; 109 | char port_str[6]; // stack allocated 110 | snprintf(port_str, 6, "%d", url->port); 111 | 112 | int err = getaddrinfo(url->host, port_str, &hints, &res); 113 | if(err != ESP_OK || res == NULL) { 114 | ESP_LOGE(TAG, "DNS lookup failed err=%d res=%p", err, res); 115 | return err; 116 | } 117 | 118 | // print resolved IP 119 | addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr; 120 | ESP_LOGI(TAG, "DNS lookup succeeded. IP=%s", inet_ntoa(*addr)); 121 | 122 | // allocate socket 123 | int sock = socket(res->ai_family, res->ai_socktype, 0); 124 | if(sock < 0) { 125 | ESP_LOGE(TAG, "... Failed to allocate socket."); 126 | freeaddrinfo(res); 127 | } 128 | ESP_LOGI(TAG, "... allocated socket"); 129 | 130 | 131 | // connect, retrying a few times 132 | char retries = 0; 133 | while(connect(sock, res->ai_addr, res->ai_addrlen) != 0) { 134 | retries++; 135 | ESP_LOGE(TAG, "... socket connect attempt %d failed, errno=%d", retries, errno); 136 | 137 | if(retries > 5) { 138 | ESP_LOGE(TAG, "giving up"); 139 | close(sock); 140 | freeaddrinfo(res); 141 | return ESP_FAIL; 142 | } 143 | } 144 | 145 | ESP_LOGI(TAG, "... connected"); 146 | freeaddrinfo(res); 147 | uint32_t length=MAX_LENGTH; 148 | // write http request 149 | char *request; 150 | if(asprintf(&request, "POST %s HTTP/1.0\r\nHost: %s:%d\r\nContent-Length: %d\r\nUser-Agent: ESP32\r\nAccept: */*\r\n\r\n", url->path, url->host, url->port,length) < 0) 151 | { 152 | return ESP_FAIL; 153 | } 154 | 155 | ESP_LOGI(TAG, "requesting %s", request); 156 | 157 | if (write(sock, request, strlen(request)) < 0) { 158 | ESP_LOGE(TAG, "... socket send failed"); 159 | close(sock); 160 | } 161 | 162 | free(request); 163 | ESP_LOGI(TAG, "... socket send success"); 164 | uint32_t w,r; 165 | //stream head 166 | printf("%s",stream_head ); 167 | w=write(sock, stream_head, strlen(stream_head)); 168 | if(w==strlen(stream_head)){ 169 | length-=w; 170 | ESP_LOGI(TAG, "#head success"); 171 | } 172 | //loop write 173 | uint32_t wav_len=0; 174 | uint32_t olen=0; 175 | uint8_t *read_buf=malloc(1026); //1026/3=342 176 | if(read_buf==NULL){ 177 | ESP_LOGE(TAG,"read_buf malloc failed!"); 178 | return ESP_FAIL; 179 | } 180 | uint8_t *dst_buf=malloc(1369); 181 | if(dst_buf==NULL){ 182 | ESP_LOGE(TAG,"read_buf malloc failed!"); 183 | return ESP_FAIL; 184 | } 185 | do{ 186 | r=fread(read_buf,1,1026,f); 187 | wav_len+=r; 188 | if(mbedtls_base64_encode(dst_buf,1369,&olen,read_buf,r)){ 189 | ESP_LOGE(TAG,"base64 encode failed!"); 190 | ESP_LOGE(TAG,"olen:%d",olen); 191 | } 192 | printf("%s",dst_buf); 193 | w=write(sock, dst_buf, olen); 194 | if(w==olen){ 195 | length-=w; 196 | } 197 | }while(r>0); 198 | ESP_LOGI(TAG, "#loop success"); 199 | fclose(f); 200 | free(read_buf); 201 | free(dst_buf); 202 | //steaem len 203 | printf("%s",stream_len); 204 | w=write(sock, stream_len, strlen(stream_len)); 205 | if(w==strlen(stream_len)){ 206 | length-=w; 207 | ESP_LOGI(TAG, "#len success"); 208 | } 209 | //wav len 210 | char *p_wav_len; 211 | if(asprintf(&p_wav_len, "%d",wav_len) < 0) 212 | { 213 | return ESP_FAIL; 214 | } 215 | printf("%s",p_wav_len); 216 | w=write(sock, p_wav_len, strlen(p_wav_len)); 217 | if(w==strlen(p_wav_len)){ 218 | length-=w; 219 | ESP_LOGI(TAG, "#wav_len success"); 220 | } 221 | free(p_wav_len); 222 | //stream tail 223 | printf("%s",stream_tail); 224 | w=write(sock, stream_tail, strlen(stream_tail)); 225 | if(w==strlen(stream_tail)){ 226 | length-=w; 227 | ESP_LOGI(TAG, "#tail success"); 228 | } 229 | //complete the length 230 | uint8_t *temp=malloc(1024); //1026/3=342 231 | memset(temp,0,1024); 232 | for(int i=(length-1024);i>0;i=i-1024){ 233 | write(sock,temp,1024); 234 | length-=1024; 235 | } 236 | ESP_LOGI(TAG, "##length%d",length); 237 | write(sock,temp,length); 238 | ESP_LOGI(TAG, "#http end"); 239 | free(temp); 240 | /* Read HTTP response */ 241 | char recv_buf[64]; 242 | bzero(recv_buf, sizeof(recv_buf)); 243 | ssize_t recved; 244 | 245 | /* intercept on_headers_complete() */ 246 | 247 | /* parse response */ 248 | http_parser parser; 249 | http_parser_init(&parser, HTTP_RESPONSE); 250 | parser.data = user_data; 251 | 252 | esp_err_t nparsed = 0; 253 | do { 254 | recved = read(sock, recv_buf, sizeof(recv_buf)-1); 255 | 256 | // using http parser causes stack overflow somtimes - disable for now 257 | nparsed = http_parser_execute(&parser, callbacks, recv_buf, recved); 258 | 259 | // invoke on_body cb directly 260 | // nparsed = callbacks->on_body(&parser, recv_buf, recved); 261 | } while(recved > 0 && nparsed >= 0); 262 | 263 | free(url); 264 | 265 | ESP_LOGI(TAG, "... done reading from socket. Last read return=%d errno=%d", recved, errno); 266 | close(sock); 267 | ESP_LOGI(TAG, "socket closed"); 268 | 269 | return 0; 270 | } 271 | 272 | int start_record_audio(){ 273 | WAV_HEADER wav_header; 274 | memcpy(wav_header.rld,"RIFF",4); 275 | memcpy(wav_header.wld,"WAVE",4); 276 | memcpy(wav_header.fld,"fmt ",4); 277 | wav_header.fLen=0x00000010; 278 | wav_header.wFormatTag=0x0001; 279 | wav_header.wChannels=0x0001; 280 | wav_header.nSamplesPersec=8000; 281 | wav_header.nAvgBitsPerSample=8000*1*2; 282 | wav_header.wBlockAlign=1*16/8; 283 | wav_header.wBitsPerSample=16; 284 | memcpy(wav_header.dld,"data",4); 285 | 286 | int w; 287 | FILE* f = fopen("/sdcard/record.wav", "wb"); 288 | w=fwrite(&wav_header,1,sizeof(wav_header),f); 289 | if(w!=sizeof(wav_header)){ 290 | ESP_LOGE(TAG,"write wav_header failed!"); 291 | return 1; 292 | } 293 | char* data=malloc(1024); 294 | uint8_t vad_cnt=0; 295 | int16_t* value=(int16_t*)data; 296 | gpio_set_level(GPIO_OUTPUT_IO_0,1); 297 | while(1){ 298 | hal_i2s_read(0,data,1024,portMAX_DELAY); 299 | if(vad_check(value,512)==0) 300 | vad_cnt++; 301 | else 302 | vad_cnt=0; 303 | if(vad_cnt>10) 304 | break; 305 | w=fwrite(data,1,1024,f); 306 | } 307 | gpio_set_level(GPIO_OUTPUT_IO_0,0); 308 | int n=ftell(f); 309 | ESP_LOGI(TAG,"flle lenght:%d",n); 310 | fseek(f, 0, SEEK_SET); 311 | wav_header.wSampleLength=n-sizeof(wav_header); 312 | wav_header.rLen=n-8; 313 | w = fwrite(&wav_header, 1, sizeof(wav_header), f); 314 | fclose(f); 315 | return 0; 316 | } 317 | /** 318 | 319 | not enough ram,giveup this way. 320 | 321 | 322 | **/ 323 | // static char* baidu_rest_input(char* speech,uint32_t len){ 324 | // cJSON* root=NULL; 325 | // root=cJSON_CreateObject(); 326 | // if(root==NULL){ 327 | // ESP_LOGI(TAG,"cjson root create failed\n"); 328 | // return NULL; 329 | // } 330 | // cJSON_AddStringToObject(root,"format","pcm"); 331 | // cJSON_AddStringToObject(root,"cuid","esp32_whyengineer"); 332 | // cJSON_AddStringToObject(root,"token",access_token); 333 | // cJSON_AddNumberToObject(root, "rate", 8000); 334 | // cJSON_AddNumberToObject(root, "channel", 1); 335 | 336 | // cJSON_AddNumberToObject(root, "len", len); 337 | // cJSON_AddStringToObject(root,"speech",speech); 338 | 339 | // // if(!strncmp(item,"vbus",4)){ 340 | // // CALIB_DEBUG("%s\n",info); 341 | // // cJSON_AddStringToObject(root,"content",info); 342 | // // } 343 | 344 | // char* out = cJSON_PrintUnformatted(root); 345 | // //send(client,out,strlen(out),MSG_WAITALL); 346 | // //printf("handle_return: %s\n", out); 347 | // cJSON_Delete(root); 348 | // return out; 349 | // } 350 | static int32_t sign(int32_t a){ 351 | if(a>0) 352 | return 1; 353 | else 354 | return 0; 355 | } 356 | static uint8_t vad_check(int16_t* data,uint32_t lenght){ 357 | int sum=0; 358 | int delta_sum=0; 359 | for(int i=0;i150000&&delta_sum<150){ 370 | //gpio_set_level(GPIO_OUTPUT_IO_0,1); 371 | return 1; 372 | } 373 | else{ 374 | //gpio_set_level(GPIO_OUTPUT_IO_0,0); 375 | return 0; 376 | } 377 | 378 | } 379 | void baidu_rest_task(void *pvParameters) 380 | { 381 | hal_i2c_init(0,5,17); 382 | hal_i2s_init(0,8000,16,1); //8k 16bit 1 channel 383 | WM8978_Init(); 384 | WM8978_ADDA_Cfg(1,1); 385 | WM8978_Input_Cfg(1,0,0); 386 | WM8978_Output_Cfg(1,0); 387 | WM8978_MIC_Gain(35); 388 | WM8978_AUX_Gain(0); 389 | WM8978_LINEIN_Gain(0); 390 | WM8978_SPKvol_Set(0); 391 | WM8978_HPvol_Set(20,20); 392 | WM8978_EQ_3D_Dir(1); 393 | WM8978_EQ1_Set(0,24); 394 | WM8978_EQ2_Set(0,24); 395 | WM8978_EQ3_Set(0,24); 396 | WM8978_EQ4_Set(0,24); 397 | WM8978_EQ5_Set(0,0); 398 | 399 | 400 | gpio_config_t io_conf; 401 | io_conf.intr_type = GPIO_PIN_INTR_DISABLE; 402 | io_conf.mode = GPIO_MODE_OUTPUT; 403 | io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL; 404 | io_conf.pull_down_en = 0; 405 | io_conf.pull_up_en = 0; 406 | gpio_config(&io_conf); 407 | //gpio_set_level(GPIO_OUTPUT_IO_0,1); 408 | ESP_LOGI(TAG, "baidu_rest task start"); 409 | //char* json=baidu_rest_input("",0); 410 | //printf("%s\n", json); 411 | char *sample_data=malloc(1024); 412 | int16_t* value=(int16_t*)sample_data; 413 | 414 | if(sample_data==NULL){ 415 | ESP_LOGE(TAG, "sample_data malloc failed"); 416 | vTaskSuspend(NULL); 417 | } 418 | // 419 | uint8_t vad_cnt=0; 420 | for(;;){ 421 | hal_i2s_read(0,sample_data,1024,portMAX_DELAY); 422 | if(vad_check(value,512)==1) 423 | vad_cnt++; 424 | else 425 | vad_cnt=0; 426 | if(vad_cnt==4){ 427 | start_record_audio(); 428 | break; 429 | } 430 | 431 | } 432 | 433 | //http_client_post("http://vop.baidu.com/server_api",&settings_null,NULL,json); 434 | //free(json); 435 | //vTaskSuspend(NULL); 436 | // uint32_t io_num; 437 | 438 | 439 | // hal_i2s_read(0,sample_data,1024,portMAX_DELAY); 440 | // for(int i=0;i<1024;i++){ 441 | // printf("%d:%d\n",i,sample_data[i]); 442 | // } 443 | baid_http_post(&settings_null,NULL); 444 | 445 | 446 | for(;;) { 447 | hal_i2s_read(0,sample_data,1024,portMAX_DELAY); 448 | vad_check(value,512); 449 | hal_i2s_write(0,sample_data,1024,portMAX_DELAY); 450 | //printf("cnt:%d\n",cnt++ ); 451 | } 452 | } -------------------------------------------------------------------------------- /components/rest/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | -------------------------------------------------------------------------------- /components/rest/include/baidu_rest.h: -------------------------------------------------------------------------------- 1 | #ifndef _BAIDU_REST_H 2 | #define _BAIDU_REST_H 3 | 4 | 5 | 6 | 7 | 8 | 9 | void baidu_rest_task(); 10 | 11 | 12 | 13 | #endif -------------------------------------------------------------------------------- /main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | -------------------------------------------------------------------------------- /main/main.c: -------------------------------------------------------------------------------- 1 | /* GPIO Example 2 | 3 | This example code is in the Public Domain (or CC0 licensed, at your option.) 4 | 5 | Unless required by applicable law or agreed to in writing, this 6 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 | CONDITIONS OF ANY KIND, either express or implied. 8 | */ 9 | #include 10 | #include 11 | #include 12 | #include "freertos/FreeRTOS.h" 13 | #include "freertos/task.h" 14 | #include "freertos/queue.h" 15 | #include "freertos/event_groups.h" 16 | #include "wm8978.h" 17 | #include "esp_vfs_fat.h" 18 | #include "driver/sdmmc_host.h" 19 | #include "driver/sdmmc_defs.h" 20 | #include "sdmmc_cmd.h" 21 | #include "esp_event_loop.h" 22 | #include "esp_log.h" 23 | #include 24 | #include "nvs.h" 25 | #include "nvs_flash.h" 26 | #include "eth.h" 27 | #include "event.h" 28 | #include "wifi.h" 29 | #include "hal_i2c.h" 30 | #include "hal_i2s.h" 31 | #include "wm8978.h" 32 | #include "baidu_rest.h" 33 | #include "http.h" 34 | #include "cJSON.h" 35 | 36 | 37 | #define TAG "main:" 38 | // typedef int (*http_data_cb) (http_parser*, const char *at, size_t length); 39 | // typedef int (*http_cb) (http_parser*); 40 | 41 | 42 | //char* http_body; 43 | 44 | 45 | void app_main() 46 | { 47 | esp_err_t err; 48 | event_engine_init(); 49 | nvs_flash_init(); 50 | tcpip_adapter_init(); 51 | wifi_init_sta(); 52 | sdmmc_host_t host = SDMMC_HOST_DEFAULT(); 53 | sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); 54 | esp_vfs_fat_sdmmc_mount_config_t mount_config = { 55 | .format_if_mount_failed = true, 56 | .max_files = 5 57 | }; 58 | sdmmc_card_t* card; 59 | err = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card); 60 | if (err != ESP_OK) { 61 | if (err == ESP_FAIL) { 62 | printf("Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true."); 63 | } else { 64 | printf("Failed to initialize the card (%d). Make sure SD card lines have pull-up resistors in place.", err); 65 | } 66 | return; 67 | } 68 | sdmmc_card_print_info(stdout, card); 69 | // /*eth_init(); 70 | //do{ 71 | //gpio_set_level(GPIO_OUTPUT_IO_0, 0); 72 | xEventGroupWaitBits(station_event_group,STA_GOTIP_BIT,pdTRUE,pdTRUE,portMAX_DELAY); 73 | //ESP_LOGI(TAG,"got ip address"); 74 | //xEventGroupWaitBits(eth_event_group,ETH_GOTIP_BIT,pdTRUE,pdTRUE,portMAX_DELAY); 75 | //esp_err_t tcpip_adapter_get_ip_printf(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_printf_t *ip_printf); 76 | //gpio_set_level(GPIO_OUTPUT_IO_0, 1); 77 | tcpip_adapter_ip_info_t ip; 78 | memset(&ip, 0, sizeof(tcpip_adapter_ip_info_t)); 79 | if (tcpip_adapter_get_ip_info(ESP_IF_WIFI_STA, &ip) == 0) { 80 | ESP_LOGI(TAG, "~~~~~~~~~~~"); 81 | ESP_LOGI(TAG, "ETHIP:"IPSTR, IP2STR(&ip.ip)); 82 | ESP_LOGI(TAG, "ETHPMASK:"IPSTR, IP2STR(&ip.netmask)); 83 | ESP_LOGI(TAG, "ETHPGW:"IPSTR, IP2STR(&ip.gw)); 84 | ESP_LOGI(TAG, "~~~~~~~~~~~"); 85 | } 86 | 87 | xTaskCreate(baidu_rest_task, "asr_task", 4096, NULL, 5, NULL); 88 | //xEventGroupWaitBits(eth_event_group,ETH_DISCONNECTED_BIT,pdTRUE,pdTRUE,portMAX_DELAY); 89 | //}while(1); 90 | //if(create_tcp_server(8080)!=ESP_OK){ 91 | // return; 92 | //} 93 | //mqtt_start(&settings); 94 | //xTaskCreate(vTelnetTask, "telnet_task", 2048, NULL, (tskIDLE_PRIORITY + 10), NULL); 95 | //char databuff[100]={0}; 96 | //int len=0; 97 | //xTaskCreatePinnedToCore 98 | //char samples_data[64]; 99 | //memset(samples_data,0,1024); 100 | //http_client_get("http://vop.baidu.com/server_api",&settings_null,NULL); 101 | uint8_t cnt=0; 102 | while(1){ 103 | //gpio_set_level(GPIO_OUTPUT_IO_0, cnt%2); 104 | //memset(samples_data,0,1024); 105 | vTaskDelay(5000 / portTICK_PERIOD_MS); 106 | //ESP_LOGI(TAG, "%s/n",samples_data); 107 | //aplay("/sdcard/test.wav"); 108 | //hal_i2s_read(0,samples_data,256,portMAX_DELAY); 109 | //hal_i2s_write(0,samples_data,256,0); 110 | //vTaskDelay(5000 / portTICK_PERIOD_MS); 111 | cnt++; 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /sdkconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Automatically generated file; DO NOT EDIT. 3 | # Espressif IoT Development Framework Configuration 4 | # 5 | 6 | # 7 | # SDK tool configuration 8 | # 9 | CONFIG_TOOLPREFIX="xtensa-esp32-elf-" 10 | CONFIG_PYTHON="python" 11 | 12 | # 13 | # Bootloader config 14 | # 15 | # CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set 16 | # CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set 17 | CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y 18 | # CONFIG_LOG_BOOTLOADER_LEVEL_INFO is not set 19 | # CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set 20 | # CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set 21 | CONFIG_LOG_BOOTLOADER_LEVEL=2 22 | 23 | # 24 | # Security features 25 | # 26 | # CONFIG_SECURE_BOOT_ENABLED is not set 27 | # CONFIG_FLASH_ENCRYPTION_ENABLED is not set 28 | 29 | # 30 | # Serial flasher config 31 | # 32 | CONFIG_ESPTOOLPY_PORT="/dev/ttyUSB0" 33 | CONFIG_ESPTOOLPY_BAUD_115200B=y 34 | # CONFIG_ESPTOOLPY_BAUD_230400B is not set 35 | # CONFIG_ESPTOOLPY_BAUD_921600B is not set 36 | # CONFIG_ESPTOOLPY_BAUD_2MB is not set 37 | # CONFIG_ESPTOOLPY_BAUD_OTHER is not set 38 | CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200 39 | CONFIG_ESPTOOLPY_BAUD=115200 40 | CONFIG_ESPTOOLPY_COMPRESSED=y 41 | # CONFIG_FLASHMODE_QIO is not set 42 | # CONFIG_FLASHMODE_QOUT is not set 43 | CONFIG_FLASHMODE_DIO=y 44 | # CONFIG_FLASHMODE_DOUT is not set 45 | CONFIG_ESPTOOLPY_FLASHMODE="dio" 46 | CONFIG_ESPTOOLPY_FLASHFREQ_80M=y 47 | # CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set 48 | # CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set 49 | # CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set 50 | CONFIG_ESPTOOLPY_FLASHFREQ="80m" 51 | # CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set 52 | # CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set 53 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 54 | # CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set 55 | # CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set 56 | CONFIG_ESPTOOLPY_FLASHSIZE="4MB" 57 | CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y 58 | CONFIG_ESPTOOLPY_BEFORE_RESET=y 59 | # CONFIG_ESPTOOLPY_BEFORE_NORESET is not set 60 | CONFIG_ESPTOOLPY_BEFORE="default_reset" 61 | CONFIG_ESPTOOLPY_AFTER_RESET=y 62 | # CONFIG_ESPTOOLPY_AFTER_NORESET is not set 63 | CONFIG_ESPTOOLPY_AFTER="hard_reset" 64 | # CONFIG_MONITOR_BAUD_9600B is not set 65 | # CONFIG_MONITOR_BAUD_57600B is not set 66 | CONFIG_MONITOR_BAUD_115200B=y 67 | # CONFIG_MONITOR_BAUD_230400B is not set 68 | # CONFIG_MONITOR_BAUD_921600B is not set 69 | # CONFIG_MONITOR_BAUD_2MB is not set 70 | # CONFIG_MONITOR_BAUD_OTHER is not set 71 | CONFIG_MONITOR_BAUD_OTHER_VAL=115200 72 | CONFIG_MONITOR_BAUD=115200 73 | 74 | # 75 | # Partition Table 76 | # 77 | CONFIG_PARTITION_TABLE_SINGLE_APP=y 78 | # CONFIG_PARTITION_TABLE_TWO_OTA is not set 79 | # CONFIG_PARTITION_TABLE_CUSTOM is not set 80 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" 81 | CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 82 | CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv" 83 | CONFIG_APP_OFFSET=0x10000 84 | 85 | # 86 | # Compiler options 87 | # 88 | CONFIG_OPTIMIZATION_LEVEL_DEBUG=y 89 | # CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set 90 | CONFIG_OPTIMIZATION_ASSERTIONS=y 91 | 92 | # 93 | # Component config 94 | # 95 | 96 | # 97 | # Application Level Tracing 98 | # 99 | # CONFIG_ESP32_APPTRACE_DEST_TRAX is not set 100 | CONFIG_ESP32_APPTRACE_DEST_NONE=y 101 | # CONFIG_ESP32_APPTRACE_ENABLE is not set 102 | 103 | # 104 | # FreeRTOS SystemView Tracing 105 | # 106 | # CONFIG_AWS_IOT_SDK is not set 107 | CONFIG_BT_ENABLED=y 108 | CONFIG_BLUEDROID_ENABLED=y 109 | CONFIG_BTC_TASK_STACK_SIZE=3072 110 | # CONFIG_BLUEDROID_MEM_DEBUG is not set 111 | CONFIG_CLASSIC_BT_ENABLED=y 112 | CONFIG_GATTS_ENABLE=y 113 | CONFIG_GATTC_ENABLE=y 114 | CONFIG_BLE_SMP_ENABLE=y 115 | # CONFIG_BT_STACK_NO_LOG is not set 116 | CONFIG_BT_ACL_CONNECTIONS=4 117 | CONFIG_BTDM_CONTROLLER_RUN_CPU=0 118 | CONFIG_SMP_ENABLE=y 119 | CONFIG_BT_RESERVE_DRAM=0x10000 120 | 121 | # 122 | # ESP32-specific 123 | # 124 | # CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set 125 | # CONFIG_ESP32_DEFAULT_CPU_FREQ_160 is not set 126 | CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y 127 | CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 128 | CONFIG_MEMMAP_SMP=y 129 | # CONFIG_MEMMAP_TRACEMEM is not set 130 | # CONFIG_MEMMAP_TRACEMEM_TWOBANKS is not set 131 | # CONFIG_ESP32_TRAX is not set 132 | CONFIG_TRACEMEM_RESERVE_DRAM=0x0 133 | # CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set 134 | # CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set 135 | CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y 136 | # CONFIG_ESP32_ENABLE_COREDUMP is not set 137 | # CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set 138 | CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y 139 | CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4 140 | CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 141 | CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2048 142 | CONFIG_MAIN_TASK_STACK_SIZE=4096 143 | CONFIG_IPC_TASK_STACK_SIZE=1024 144 | CONFIG_NEWLIB_STDOUT_ADDCR=y 145 | # CONFIG_NEWLIB_NANO_FORMAT is not set 146 | CONFIG_CONSOLE_UART_DEFAULT=y 147 | # CONFIG_CONSOLE_UART_CUSTOM is not set 148 | # CONFIG_CONSOLE_UART_NONE is not set 149 | CONFIG_CONSOLE_UART_NUM=0 150 | CONFIG_CONSOLE_UART_BAUDRATE=115200 151 | # CONFIG_ULP_COPROC_ENABLED is not set 152 | CONFIG_ULP_COPROC_RESERVE_MEM=0 153 | # CONFIG_ESP32_PANIC_PRINT_HALT is not set 154 | CONFIG_ESP32_PANIC_PRINT_REBOOT=y 155 | # CONFIG_ESP32_PANIC_SILENT_REBOOT is not set 156 | # CONFIG_ESP32_PANIC_GDBSTUB is not set 157 | CONFIG_ESP32_DEBUG_OCDAWARE=y 158 | CONFIG_INT_WDT=y 159 | CONFIG_INT_WDT_TIMEOUT_MS=2000 160 | CONFIG_INT_WDT_CHECK_CPU1=y 161 | CONFIG_TASK_WDT=y 162 | # CONFIG_TASK_WDT_PANIC is not set 163 | CONFIG_TASK_WDT_TIMEOUT_S=5 164 | CONFIG_TASK_WDT_CHECK_IDLE_TASK=y 165 | CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1=y 166 | # CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set 167 | CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y 168 | # CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set 169 | # CONFIG_ESP32_TIME_SYSCALL_USE_NONE is not set 170 | CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y 171 | # CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set 172 | CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024 173 | CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=0 174 | # CONFIG_ESP32_XTAL_FREQ_40 is not set 175 | # CONFIG_ESP32_XTAL_FREQ_26 is not set 176 | CONFIG_ESP32_XTAL_FREQ_AUTO=y 177 | CONFIG_ESP32_XTAL_FREQ=0 178 | CONFIG_WIFI_ENABLED=y 179 | # CONFIG_SW_COEXIST_ENABLE is not set 180 | CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10 181 | CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32 182 | # CONFIG_ESP32_WIFI_STATIC_TX_BUFFER is not set 183 | CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y 184 | CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1 185 | CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32 186 | CONFIG_ESP32_WIFI_AMPDU_ENABLED=y 187 | CONFIG_ESP32_WIFI_NVS_ENABLED=y 188 | CONFIG_PHY_ENABLED=y 189 | 190 | # 191 | # PHY 192 | # 193 | CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y 194 | # CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set 195 | CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20 196 | CONFIG_ESP32_PHY_MAX_TX_POWER=20 197 | CONFIG_ETHERNET=y 198 | CONFIG_DMA_RX_BUF_NUM=10 199 | CONFIG_DMA_TX_BUF_NUM=10 200 | # CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE is not set 201 | CONFIG_EMAC_TASK_PRIORITY=20 202 | 203 | # 204 | # FAT Filesystem support 205 | # 206 | CONFIG_FATFS_CODEPAGE_ASCII=y 207 | # CONFIG_FATFS_CODEPAGE_437 is not set 208 | # CONFIG_FATFS_CODEPAGE_720 is not set 209 | # CONFIG_FATFS_CODEPAGE_737 is not set 210 | # CONFIG_FATFS_CODEPAGE_771 is not set 211 | # CONFIG_FATFS_CODEPAGE_775 is not set 212 | # CONFIG_FATFS_CODEPAGE_850 is not set 213 | # CONFIG_FATFS_CODEPAGE_852 is not set 214 | # CONFIG_FATFS_CODEPAGE_855 is not set 215 | # CONFIG_FATFS_CODEPAGE_857 is not set 216 | # CONFIG_FATFS_CODEPAGE_860 is not set 217 | # CONFIG_FATFS_CODEPAGE_861 is not set 218 | # CONFIG_FATFS_CODEPAGE_862 is not set 219 | # CONFIG_FATFS_CODEPAGE_863 is not set 220 | # CONFIG_FATFS_CODEPAGE_864 is not set 221 | # CONFIG_FATFS_CODEPAGE_865 is not set 222 | # CONFIG_FATFS_CODEPAGE_866 is not set 223 | # CONFIG_FATFS_CODEPAGE_869 is not set 224 | # CONFIG_FATFS_CODEPAGE_932 is not set 225 | # CONFIG_FATFS_CODEPAGE_936 is not set 226 | # CONFIG_FATFS_CODEPAGE_949 is not set 227 | # CONFIG_FATFS_CODEPAGE_950 is not set 228 | CONFIG_FATFS_CODEPAGE=1 229 | CONFIG_FATFS_MAX_LFN=255 230 | 231 | # 232 | # FreeRTOS 233 | # 234 | # CONFIG_FREERTOS_UNICORE is not set 235 | CONFIG_FREERTOS_CORETIMER_0=y 236 | # CONFIG_FREERTOS_CORETIMER_1 is not set 237 | CONFIG_FREERTOS_HZ=1000 238 | CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y 239 | # CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set 240 | CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL=y 241 | # CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY is not set 242 | # CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set 243 | CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=3 244 | # CONFIG_FREERTOS_ASSERT_FAIL_ABORT is not set 245 | CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE=y 246 | # CONFIG_FREERTOS_ASSERT_DISABLE is not set 247 | CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG=y 248 | # CONFIG_ENABLE_MEMORY_DEBUG is not set 249 | CONFIG_FREERTOS_ISR_STACKSIZE=1536 250 | # CONFIG_FREERTOS_LEGACY_HOOKS is not set 251 | CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16 252 | # CONFIG_SUPPORT_STATIC_ALLOCATION is not set 253 | CONFIG_TIMER_TASK_PRIORITY=1 254 | CONFIG_TIMER_TASK_STACK_DEPTH=2048 255 | CONFIG_TIMER_QUEUE_LENGTH=10 256 | # CONFIG_FREERTOS_DEBUG_INTERNALS is not set 257 | 258 | # 259 | # Log output 260 | # 261 | # CONFIG_LOG_DEFAULT_LEVEL_NONE is not set 262 | # CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set 263 | # CONFIG_LOG_DEFAULT_LEVEL_WARN is not set 264 | CONFIG_LOG_DEFAULT_LEVEL_INFO=y 265 | # CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set 266 | # CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set 267 | CONFIG_LOG_DEFAULT_LEVEL=3 268 | CONFIG_LOG_COLORS=y 269 | 270 | # 271 | # LWIP 272 | # 273 | # CONFIG_L2_TO_L3_COPY is not set 274 | CONFIG_LWIP_MAX_SOCKETS=4 275 | CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX=0 276 | # CONFIG_LWIP_SO_REUSE is not set 277 | # CONFIG_LWIP_SO_RCVBUF is not set 278 | CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1 279 | # CONFIG_LWIP_IP_FRAG is not set 280 | # CONFIG_LWIP_IP_REASSEMBLY is not set 281 | 282 | # 283 | # TCP 284 | # 285 | CONFIG_TCP_MAXRTX=12 286 | CONFIG_TCP_SYNMAXRTX=6 287 | CONFIG_TCP_MSS=1436 288 | CONFIG_TCP_SND_BUF_DEFAULT=5744 289 | CONFIG_TCP_WND_DEFAULT=5744 290 | CONFIG_TCP_QUEUE_OOSEQ=y 291 | CONFIG_TCP_OVERSIZE_MSS=y 292 | # CONFIG_TCP_OVERSIZE_QUARTER_MSS is not set 293 | # CONFIG_TCP_OVERSIZE_DISABLE is not set 294 | CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y 295 | CONFIG_TCPIP_TASK_STACK_SIZE=2560 296 | # CONFIG_PPP_SUPPORT is not set 297 | 298 | # 299 | # ICMP 300 | # 301 | # CONFIG_LWIP_MULTICAST_PING is not set 302 | # CONFIG_LWIP_BROADCAST_PING is not set 303 | 304 | # 305 | # mbedTLS 306 | # 307 | CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384 308 | # CONFIG_MBEDTLS_DEBUG is not set 309 | # CONFIG_MBEDTLS_UNSAFE_ACCELERATION is not set 310 | CONFIG_MBEDTLS_HAVE_TIME=y 311 | # CONFIG_MBEDTLS_HAVE_TIME_DATE is not set 312 | 313 | # 314 | # OpenSSL 315 | # 316 | # CONFIG_OPENSSL_DEBUG is not set 317 | CONFIG_OPENSSL_ASSERT_DO_NOTHING=y 318 | # CONFIG_OPENSSL_ASSERT_EXIT is not set 319 | 320 | # 321 | # SPI Flash driver 322 | # 323 | # CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set 324 | CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y 325 | --------------------------------------------------------------------------------