2828import os
2929from os .path import join
3030import re
31+ import requests
3132import platform as sys_platform
3233
3334import click
@@ -194,12 +195,40 @@ def get_MD5_hash(phrase):
194195 import hashlib
195196 return hashlib .md5 ((phrase ).encode ('utf-8' )).hexdigest ()[:16 ]
196197
198+ def custom_sdkconfig_file (string ):
199+ if not config .has_option ("env:" + env ["PIOENV" ], "custom_sdkconfig" ):
200+ return ""
201+ sdkconfig_entrys = env .GetProjectOption ("custom_sdkconfig" ).splitlines ()
202+ for file in sdkconfig_entrys :
203+ if "http" in file and "://" in file :
204+ response = requests .get (file .split (" " )[0 ])
205+ if response .ok :
206+ target = str (response .content .decode ('utf-8' ))
207+ else :
208+ print ("Failed to download:" , file )
209+ return ""
210+ return target
211+ if "file://" in file :
212+ file_path = join (PROJECT_DIR ,file .lstrip ("file://" ).split (os .path .sep )[- 1 ])
213+ if os .path .exists (file_path ):
214+ with open (file_path , 'r' ) as file :
215+ target = file .read ()
216+ else :
217+ print ("File not found:" , file_path )
218+ return ""
219+ return target
220+ return ""
221+
222+
197223 custom_sdk_config_flags = ""
198224 board_idf_config_flags = ""
225+ sdkconfig_file_flags = ""
226+ custom_sdkconfig_file_str = ""
199227
200228 if config .has_option ("env:" + env ["PIOENV" ], "custom_sdkconfig" ):
201229 flag_custom_sdkonfig = True
202230 custom_sdk_config_flags = (env .GetProjectOption ("custom_sdkconfig" ).rstrip ("\n " )) + "\n "
231+ custom_sdkconfig_file_str = custom_sdkconfig_file (sdkconfig_file_flags )
203232
204233 if "espidf.custom_sdkconfig" in board :
205234 board_idf_config_flags = ('\n ' .join ([element for element in board .get ("espidf.custom_sdkconfig" , "" )])).rstrip ("\n " ) + "\n "
@@ -208,6 +237,9 @@ def get_MD5_hash(phrase):
208237 if flag_custom_sdkonfig == True : # TDOO duplicated
209238 print ("*** Add \" custom_sdkconfig\" settings to IDF sdkconfig.defaults ***" )
210239 idf_config_flags = custom_sdk_config_flags
240+ if custom_sdkconfig_file_str != "" :
241+ sdkconfig_file_flags = custom_sdkconfig_file_str + "\n "
242+ idf_config_flags = idf_config_flags + sdkconfig_file_flags
211243 idf_config_flags = idf_config_flags + board_idf_config_flags
212244 if flash_frequency != "80m" :
213245 idf_config_flags = idf_config_flags + "# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set\n "
@@ -224,7 +256,7 @@ def get_MD5_hash(phrase):
224256
225257 idf_config_flags = idf_config_flags .splitlines ()
226258 sdkconfig_src = join (ARDUINO_FRMWRK_LIB_DIR ,mcu ,"sdkconfig" )
227-
259+
228260 def get_flag (line ):
229261 if line .startswith ("#" ) and "is not set" in line :
230262 return line .split (" " )[1 ]
0 commit comments