Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ae9e26

Browse files
committed
some code cleanup
1 parentc7ce0d0 commit6ae9e26

File tree

8 files changed

+158
-181
lines changed

8 files changed

+158
-181
lines changed

‎builder/__init__.py‎

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,20 @@ def update_mphalport(target):
6666
data=f.read().decode('utf-8')
6767

6868
if'#ifndef _MPHALPORT_H_'notindata:
69-
data=f'#ifndef _MPHALPORT_H_\n#define _MPHALPORT_H_\n{data}\n#endif /* _MPHALPORT_H_ */\n'
69+
data= (
70+
f'#ifndef _MPHALPORT_H_\n'
71+
f'#define _MPHALPORT_H_\n'
72+
f'{data}\n'
73+
f'#endif /* _MPHALPORT_H_ */\n'
74+
)
7075
withopen(mphalport_path,'wb')asf:
7176
f.write(data.encode('utf-8'))
7277

7378

74-
defgenerate_manifest(script_dir,lvgl_api,manifest_path,displays,indevs,frozen_manifest,*addl_manifest_files):
79+
defgenerate_manifest(
80+
script_dir,lvgl_api,manifest_path,displays,
81+
indevs,frozen_manifest,*addl_manifest_files
82+
):
7583
ifnotos.path.exists('build'):
7684
os.mkdir('build')
7785

@@ -98,8 +106,14 @@ def generate_manifest(script_dir, lvgl_api, manifest_path, displays, indevs, fro
98106
f'{api_path}/frozen/indev/pointer_framework.py',
99107
f'{api_path}/fs_driver.py',
100108
f'{script_dir}/api_drivers/common_api_drivers/frozen/other/i2c.py',
101-
f'{script_dir}/api_drivers/common_api_drivers/frozen/other/io_expander_framework.py',
102-
f'{script_dir}/api_drivers/common_api_drivers/frozen/other/task_handler.py'
109+
(
110+
f'{script_dir}/api_drivers/common_api_drivers/'
111+
f'frozen/other/io_expander_framework.py'
112+
),
113+
(
114+
f'{script_dir}/api_drivers/common_api_drivers/'
115+
f'frozen/other/task_handler.py'
116+
)
103117
]
104118

105119
forfileinfrozen_manifest_files:
@@ -122,7 +136,9 @@ def generate_manifest(script_dir, lvgl_api, manifest_path, displays, indevs, fro
122136

123137
forfileinindevs:
124138
ifnotos.path.exists(file):
125-
tmp_file=f'{script_dir}/api_drivers/common_api_drivers/indev/{file}.py'
139+
tmp_file= (
140+
f'{script_dir}/api_drivers/common_api_drivers/indev/{file}.py'
141+
)
126142

127143
ifnotos.path.exists(tmp_file):
128144
raiseRuntimeError(f'File not found "{file}"')
@@ -144,7 +160,9 @@ def generate_manifest(script_dir, lvgl_api, manifest_path, displays, indevs, fro
144160

145161
forfileindisplays:
146162
ifnotos.path.exists(file):
147-
tmp_file=f'{script_dir}/api_drivers/common_api_drivers/display/{file}.py'
163+
tmp_file= (
164+
f'{script_dir}/api_drivers/common_api_drivers/display/{file}.py'
165+
)
148166

149167
ifnotos.path.exists(tmp_file):
150168
raiseRuntimeError(f'File not found "{file}"')
@@ -440,7 +458,9 @@ def mpy_cross():
440458
sys.exit(return_code)
441459

442460

443-
defbuild_manifest(target,script_dir,lvgl_api,displays,indevs,frozen_manifest):
461+
defbuild_manifest(
462+
target,script_dir,lvgl_api,displays,indevs,frozen_manifest
463+
):
444464
update_mphalport(target)
445465
iftarget=='teensy':
446466
manifest_path=f'lib/micropython/ports/{target}/manifest.py'
@@ -449,7 +469,10 @@ def build_manifest(target, script_dir, lvgl_api, displays, indevs, frozen_manife
449469
ifnotos.path.exists(manifest_path):
450470
raiseRuntimeError(f'Unable to locate manifest file "{manifest_path}"')
451471

452-
generate_manifest(script_dir,lvgl_api,manifest_path,displays,indevs,frozen_manifest)
472+
generate_manifest(
473+
script_dir,lvgl_api,manifest_path,
474+
displays,indevs,frozen_manifest
475+
)
453476

454477

455478
defparse_args(extra_args,lv_cflags,board):

‎builder/esp32.py‎

Lines changed: 62 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,11 @@
11
importos
22
importsys
33
fromargparseimportArgumentParser
4-
from .importspawnas_spawn
4+
from .importspawn
55
from .importgenerate_manifest
66
from .importupdate_mphalport
77

88

9-
spawn=_spawn
10-
11-
12-
install_ps_script='''\
13-
build\\esp-idf-tools-setup-offline-5.0.4.exe /VERYSILENT /SUPPRESSMSGBOXES /SP- /NOCANCEL /IDFVERSION=5.0.4 /IDFDIR=C:\\esp-idf
14-
$InstallerProcess = Get-Process esp-idf-tools-setup
15-
Wait-Process -Id $InstallerProcess.id
16-
'''
17-
18-
idf_env_bat_script='''
19-
@echo off
20-
21-
set "IDF_PATH=C:\\esp-idf\\frameworks\\esp-idf-v5.0.4"
22-
set "IDF_TOOLS_PATH=C:\\esp-idf\\frameworks\\esp-idf-v5.0.4\\tools"
23-
set "PATH=%IDF_TOOLS_PATH%;%PATH%"
24-
idf-env config get --property python --idf-path %IDF_PATH%\\ > build\\idf-python-path.txt
25-
set /P "IDF_PYTHON=< build\\idf-python-path.txt"
26-
idf-env config get --property gitPath > build\\idf-git-path.txt
27-
set /P "IDF_GIT=< build\\idf-git-path.txt"
28-
set "PREFIX=%IDF_PYTHON% %IDF_PATH%"
29-
DOSKEY idf.py=%PREFIX%\\tools\\idf.py $*
30-
DOSKEY esptool.py=%PREFIX%\\components\\esptool_py\\esptool\\esptool.py $*
31-
DOSKEY espefuse.py=%PREFIX%\\components\\esptool_py\\esptool\\espefuse.py $*
32-
DOSKEY espsecure.py=%PREFIX%\\components\\esptool_py\\esptool\\espsecure.py $*
33-
DOSKEY otatool.py=%PREFIX%\\components\\app_update\\otatool.py $*
34-
DOSKEY parttool.py=%PREFIX%\\components\\partition_table\\parttool.py $*
35-
set PYTHONPATH=
36-
set PYTHONHOME=
37-
set PYTHONNOUSERSITE=True
38-
set "IDF_PYTHON_DIR=%IDF_PYTHON%"
39-
set "IDF_GIT_DIR=%IDF_GIT%"
40-
set "PATH=%IDF_PYTHON_DIR%;%IDF_GIT_DIR%;%PATH%"'
41-
%IDF_PATH%\\export.bat'
42-
'''
43-
44-
45-
defget_idf_build_environment():
46-
globalspawn
47-
48-
ifsys.platform.startswith('win'):
49-
50-
ifnotos.path.exists('build'):
51-
os.mkdir('build')
52-
53-
importrequests
54-
55-
print('downloading esp-idf toolkit for windows')
56-
57-
url='https://dl.espressif.com/dl/idf-installer/esp-idf-tools-setup-offline-5.0.4.exe'
58-
59-
response=requests.get(url,stream=True)
60-
withopen("build/esp-idf-tools-setup-offline-5.0.4.exe",mode="wb")asfile:
61-
forchunkinresponse.iter_content(chunk_size=10*1024):
62-
file.write(chunk)
63-
64-
withopen('build/install_esp-idf.ps1','w')asfile:
65-
file.write(install_ps_script)
66-
67-
withopen('build/setup_environment.bat','w')asfile:
68-
file.write(idf_env_bat_script)
69-
70-
cmd_= ['C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -ExecutionPolicy Bypass -NonInteractive -File "build\\install_esp-idf.ps1"']
71-
result,_=spawn(cmd_)
72-
ifresult!=0:
73-
sys.exit(result)
74-
75-
old_spawn=spawn
76-
77-
def_new_spawn(cmds,*args,**kwargs):
78-
framework_cmds= [
79-
['build\\setup_environment.bat']
80-
]
81-
82-
ifisinstance(cmds[0],str):
83-
cmds= [cmds[:]]
84-
85-
framework_cmds.extend(cmds)
86-
87-
returnold_spawn(framework_cmds,*args,**kwargs)
88-
89-
spawn=_new_spawn
90-
91-
929
defget_partition_file_name(otp):
9310
if'Running cmake in directory 'inotp:
9411
build_path=otp.split('Running cmake in directory ',1)[-1]
@@ -351,13 +268,18 @@ def build_commands(_, extra_args, __, lv_cflags, ___):
351268

352269
defget_idf_version():
353270
if'ESP_IDF_VERSION'inos.environ:
354-
exit_code,data=spawn(['python3','idf.py','--version'],out_to_screen=False)
271+
exit_code,data=spawn(
272+
['python3','idf.py','--version'],
273+
out_to_screen=False
274+
)
355275
version=data.split('v')[-1].split('-')[0]
356276
ifversion:
357277
returnversion
358278

359279

360-
defbuild_manifest(target,script_dir,lvgl_api,displays,indevs,frozen_manifest):
280+
defbuild_manifest(
281+
target,script_dir,lvgl_api,displays,indevs,frozen_manifest
282+
):
361283
update_mphalport(target)
362284

363285
withopen(f'lib/micropython/ports/esp32/boards/sdkconfig.base','r')asf:
@@ -374,7 +296,10 @@ def build_manifest(target, script_dir, lvgl_api, displays, indevs, frozen_manife
374296

375297
manifest_path='lib/micropython/ports/esp32/boards/manifest.py'
376298

377-
generate_manifest(script_dir,lvgl_api,manifest_path,displays,indevs,frozen_manifest)
299+
generate_manifest(
300+
script_dir,lvgl_api,manifest_path,
301+
displays,indevs,frozen_manifest
302+
)
378303

379304

380305
defclean():
@@ -400,13 +325,19 @@ def setup_idf_environ():
400325

401326
ifos.path.exists(os.path.join(idf_path,'export.sh')):
402327

403-
# this removes any IDF environment variable that may exist if the user
404-
# has the ESP-IDF installed
405-
env= {k:vfork,vinos.environ.items()ifnotk.startswith('IDF')}
328+
# this removes any IDF environment variable that may
329+
# exist if the user has the ESP-IDF installed
330+
env= {
331+
k:vfork,vinos.environ.items()ifnotk.startswith('IDF')
332+
}
406333
py_path=os.path.split(sys.executable)[0]
407334
idf_path=os.path.abspath(idf_path)
408335
idf_tools_path=os.path.join(idf_path,'tools')
409-
env['PATH']=py_path+os.pathsep+os.pathsep+idf_tools_path+os.pathsep+env.get('PATH','')
336+
env['PATH']= (
337+
py_path+os.pathsep+
338+
os.pathsep+idf_tools_path+
339+
os.pathsep+env.get('PATH','')
340+
)
410341
env['IDF_PATH']=idf_path
411342

412343
cmds= [
@@ -419,12 +350,15 @@ def setup_idf_environ():
419350
if'GITHUB_RUN_ID'inenv:
420351
ifsys.platform.startswith('win'):
421352
env_cmds= [
422-
['echo',f"{py_path}",'|','Out-File','-Append',
423-
'-FilePath','$env:GITHUB_PATH','-Encoding','utf8'],
424-
['echo',f"{idf_path}",'|','Out-File','-Append',
425-
'-FilePath','$env:GITHUB_PATH','-Encoding','utf8'],
426-
['echo',f"{idf_tools_path}",'|','Out-File','-Append',
427-
'-FilePath','$env:GITHUB_PATH','-Encoding','utf8']
353+
['echo',f"{py_path}",'|','Out-File',
354+
'-Append','-FilePath','$env:GITHUB_PATH',
355+
'-Encoding','utf8'],
356+
['echo',f"{idf_path}",'|','Out-File',
357+
'-Append','-FilePath','$env:GITHUB_PATH',
358+
'-Encoding','utf8'],
359+
['echo',f"{idf_tools_path}",'|','Out-File',
360+
'-Append','-FilePath','$env:GITHUB_PATH',
361+
'-Encoding','utf8']
428362
]
429363
else:
430364
env_cmds= [
@@ -485,21 +419,24 @@ def submodules():
485419
cmds= [
486420
[f'export "IDF_PATH={os.path.abspath(idf_path)}"'],
487421
['cd',idf_path],
488-
['git','submodule','update','--init',
489-
'components/bt/host/nimble/nimble',
490-
'components/esp_wifi',
491-
'components/esptool_py/esptool',
492-
'components/lwip/lwip',
493-
'components/mbedtls/mbedtls',
494-
'components/bt/controller/lib_esp32',
495-
'components/bt/controller/lib_esp32c3_family'
496-
], ['./install.sh','all']]
422+
[
423+
'git','submodule','update','--init',
424+
'components/bt/host/nimble/nimble',
425+
'components/esp_wifi',
426+
'components/esptool_py/esptool',
427+
'components/lwip/lwip',
428+
'components/mbedtls/mbedtls',
429+
'components/bt/controller/lib_esp32',
430+
'components/bt/controller/lib_esp32c3_family'
431+
], ['./install.sh','all']]
497432

498433
print('setting up ESP-IDF v5.0.4')
499434
print('this might take a bit...')
500435
print()
501436

502-
env= {k:vfork,vinos.environ.items()ifnotk.startswith('IDF')}
437+
env= {
438+
k:vfork,vinos.environ.items()ifnotk.startswith('IDF')
439+
}
503440
env['IDF_PATH']=os.path.abspath(idf_path)
504441

505442
result,_=spawn(cmds,env=env)
@@ -519,9 +456,7 @@ def submodules():
519456
submodules_cmd
520457
]
521458
else:
522-
get_idf_build_environment()
523-
cmds=submodules_cmd
524-
env=None
459+
raiseRuntimeError('compiling on windows is not supported at this time')
525460

526461
return_code,_=spawn(cmds,env=env)
527462
ifreturn_code!=0:
@@ -587,7 +522,11 @@ def compile(): # NOQA
587522

588523
base_config='\n'.join(base_config)
589524

590-
withopen('lib/micropython/ports/esp32/boards/ESP32_GENERIC_S3/sdkconfig.board','w')asf:
525+
sdkconfig_board_path= (
526+
'lib/micropython/ports/esp32/'
527+
'boards/ESP32_GENERIC_S3/sdkconfig.board'
528+
)
529+
withopen(sdkconfig_board_path,'w')asf:
591530
f.write(base_config+'\n')
592531

593532
ifboardin ('ESP32_GENERIC_S2','ESP32_GENERIC_S3'):
@@ -597,7 +536,10 @@ def compile(): # NOQA
597536
withopen(mphalport_path,'rb')asf:
598537
data=f.read().decode('utf-8')
599538

600-
data=data.replace('#elif CONFIG_USB_OTG_SUPPORTED','#elif MP_USB_OTG')
539+
data=data.replace(
540+
'#elif CONFIG_USB_OTG_SUPPORTED',
541+
'#elif MP_USB_OTG'
542+
)
601543

602544
withopen(mphalport_path,'wb')asf:
603545
f.write(data.encode('utf-8'))
@@ -615,7 +557,10 @@ def compile(): # NOQA
615557
withopen(main_path,'wb')asf:
616558
f.write(data.encode('utf-8'))
617559

618-
mpconfigboard_path=f'lib/micropython/ports/esp32/boards/{board}/mpconfigboard.h'
560+
mpconfigboard_path= (
561+
f'lib/micropython/ports/esp32/boards/{board}/mpconfigboard.h'
562+
)
563+
619564
withopen(mpconfigboard_path,'rb')asf:
620565
data=f.read().decode('utf-8')
621566

@@ -768,7 +713,10 @@ def compile(): # NOQA
768713

769714
esp_tool_path,output=output.split('esptool.py ',1)
770715
esp_tool_path+='esptool.py'
771-
esp_tool_path=esp_tool_path.replace('../../../',os.getcwd()+'/lib/')
716+
esp_tool_path=esp_tool_path.replace(
717+
'../../../',
718+
os.getcwd()+'/lib/'
719+
)
772720

773721
out_cmd= []
774722

@@ -830,9 +778,6 @@ def compile(): # NOQA
830778
print(
831779
python_path,esp_tool_path,'-p (PORT) -b 460800 erase_flash'
832780
)
833-
# print()
834-
# print(python_path, esp_tool_path, out_cmd.replace('-b 460800', '-b 921600'))
835-
# print()
836781

837782
cmd=f'{python_path}{esp_tool_path}{out_cmd}'
838783
cmd=cmd.split('write_flash',1)[0]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp