@@ -178,6 +178,8 @@ def get_espidf():
178178usb_jtag = False
179179optimize_size = False
180180ota = False
181+ components = []
182+ user_c_modules = []
181183
182184dual_core_threads = False
183185task_stack_size = 16 * 1024
@@ -197,6 +199,8 @@ def common_args(extra_args):
197199 global ota
198200 global dual_core_threads
199201 global task_stack_size
202+ global components
203+ global user_c_modules
200204
201205 if board == 'ARDUINO_NANO_ESP32' :
202206 raise RuntimeError ('Board is not currently supported' )
@@ -297,6 +301,25 @@ def common_args(extra_args):
297301 action = 'store'
298302 )
299303
304+ esp_argParser .add_argument (
305+ 'COMPONENT' ,
306+ dest = 'components' ,
307+ help = (
308+ 'Component you want to add from the esp component registry\n '
309+ 'the format needs to be as follows\n '
310+ 'COMPONENT="espressif/esp32-camera^2.0.15"'
311+ ),
312+ action = 'append' ,
313+ default = []
314+ )
315+
316+ esp_argParser .add_argument (
317+ 'USER_C_MODULE' ,
318+ dest = 'user_c_modules' ,
319+ action = 'append' ,
320+ default = []
321+ )
322+
300323 esp_args , extra_args = esp_argParser .parse_known_args (extra_args )
301324
302325 BAUD = esp_args .baud
@@ -311,6 +334,10 @@ def common_args(extra_args):
311334 ota = esp_args .ota
312335 dual_core_threads = esp_args .dual_core_threads
313336 task_stack_size = esp_args .task_stack_size
337+ task_stack_size = esp_args .task_stack_size
338+
339+ components = esp_args .components
340+ user_c_modules = esp_args .user_c_modules
314341
315342 return extra_args
316343
@@ -753,19 +780,76 @@ def setup_idf_environ():
753780 return env , cmds
754781
755782
756- def add_components ():
757- # port_path = f'{SCRIPT_DIR}/lib/micropython/ports/esp32'
758- # for pth in ('esp32', 'esp32c3', 'esp32s2', 'esp32s3'):
759- # pth = os.path.join(port_path, f'main_{pth}', 'idf_component.yml')
760- # with open(pth, 'rb') as f:
761- # data = f.read().decode('utf-8')
783+ def user_c_module ():
784+ 'include(${CMAKE_CURRENT_LIST_DIR}/lcd_bus/micropython.cmake)'
785+
786+ with open ('ext_mod/esp32_components.cmake' , 'r' ) as f :
787+ data = f .read ().split ('\n ' )
788+
789+ for line in data [:]:
790+ if line .startswith ('include' ):
791+ data .remove (line )
792+
793+ data .append ('' )
794+
795+ if user_c_modules :
796+ for module in user_c_modules :
797+ data .append (f'include({ module } )' )
798+
799+ with open ('ext_mod/esp32_components.cmake' , 'w' ) as f :
800+ f .write ('\n ' .join (data ))
801+
802+
803+ def add_components (env , cmds ):
804+ # if a user adds a user_c_module they will be able to
805+ # add any includes needed for a component that was downloaded from the
806+ # component registry by using this code.
807+
808+ # set(USER_MOD_INCLUDES ${CMAKE_CURRENT_LIST_DIR})
809+ #
810+ # idf_component_get_property(ESP_COMP_INCLUDES comp_name INCLUDE_DIRS)
811+ # idf_component_get_property(ESP_COMP_PRIV_INCLUDES comp_name PRIV_INCLUDE_DIRS)
812+ # idf_component_get_property(ESP_COMP_DIR comp_name COMPONENT_DIR)
762813 #
763- # if 'espressif/esp_lcd_panel_io_additions: "~1.0.1"' not in data:
764- # data += '\n espressif/esp_io_expander: "~1.0.1"'
765- # data += '\n espressif/esp_lcd_panel_io_additions: "~1.0.1"\n'
766- # with open(pth, 'wb') as f:
767- # f.write(data.encode('utf-8'))
768- pass
814+ # if(ESP_COMP_INCLUDES)
815+ # list(TRANSFORM ESP_COMP_INCLUDES PREPEND ${ESP_COMP_DIR}/)
816+ # list(APPEND USER_MOD_INCLUDES ${ESP_COMP_INCLUDES})
817+ # endif()
818+ #
819+ # if(ESP_COMP_PRIV_INCLUDES)
820+ # list(TRANSFORM ESP_COMP_PRIV_INCLUDES PREPEND ${ESP_COMP_DIR}/)
821+ # list(APPEND USER_MOD_INCLUDES ${ESP_COMP_PRIV_INCLUDES})
822+ # endif()
823+
824+ comp_names = []
825+ comps = []
826+
827+ for component in components :
828+ comp_name = ''
829+ for char in component :
830+ if char == '"' :
831+ continue
832+ if char in '<>=`^|' :
833+ break
834+ comp_name += char
835+
836+ comp_names .append (comp_name .split ('/' )[- 1 ])
837+ comps .append ([f'idf.py add-dependency { component } ' ])
838+
839+ if comps :
840+ cmds .extend (comps )
841+ ret_code , output = spawn (cmds , env = env )
842+ if ret_code != 0 :
843+ sys .exit (ret_code )
844+
845+ with open ('ext_mod/esp32_components.cmake' , 'w' ) as f :
846+ f .write ('list(APPEND IDF_COMPONENTS\n ' )
847+ for item in comp_names :
848+ f .write (f' { item } \n ' )
849+ f .write (')\n ' )
850+ else :
851+ with open ('ext_mod/esp32_components.cmake' , 'w' ) as f :
852+ f .write ('' )
769853
770854
771855def submodules ():
@@ -1116,9 +1200,8 @@ def compile(*args): # NOQA
11161200 global PORT
11171201 global flash_size
11181202
1119- add_components ()
1120-
11211203 env , cmds = setup_idf_environ ()
1204+ add_components (env , cmds [:])
11221205
11231206 if ccache :
11241207 env ['IDF_CCACHE_ENABLE' ] = '1'
0 commit comments