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

Commite147c52

Browse files
committed
modifications
1 parent76958e5 commite147c52

File tree

50 files changed

+3032
-1283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3032
-1283
lines changed

‎builder/__init__.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ def generate_manifest(
256256
)
257257
]
258258

259+
toml_gen_driver=f'{script_dir}/build/display.py'
260+
ifos.path.exists(toml_gen_driver):
261+
print(toml_gen_driver)
262+
file_path,file_name=os.path.split(toml_gen_driver)
263+
entry=f"freeze('{file_path}', '{file_name}')"
264+
manifest_files.append(entry)
265+
259266
forfileinfrozen_manifest_files:
260267
ifnotos.path.exists(file):
261268
raiseRuntimeError(f'File not found "{file}"')

‎builder/toml_reader.py‎

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
importos
2+
3+
try:
4+
importtomlibastoml
5+
exceptImportError:
6+
try:
7+
importtoml
8+
exceptImportError:
9+
raiseRuntimeError(
10+
'A "toml" library is needed to read a .toml file\n'
11+
'One is included with Python 3.11+ or you can install\n'
12+
'into your current version of Python using the following command:\n'
13+
'\n'
14+
'pip3 install toml'
15+
)
16+
17+
18+
classTOMLMeta(type):
19+
20+
def__call__(cls,name,parent=None,**kwargs):
21+
children= {}
22+
forkey,valueinlist(kwargs.items()):
23+
ifisinstance(value,dict):
24+
children[key]=value
25+
delkwargs[key]
26+
27+
instance=super().__call__(name,parent=parent,**kwargs)
28+
29+
forchild_name,child_datainchildren.items():
30+
child=TOMLObject(child_name,parent=instance,**child_data)
31+
instance.add_child(child)
32+
33+
returninstance
34+
35+
36+
classTOMLObject(metaclass=TOMLMeta):
37+
38+
def__init__(self,name,parent=None,**kwargs):
39+
40+
ifparentisnotNoneandparent.name=='MCU':
41+
self.build_args=kwargs
42+
43+
self.name=name
44+
self.parent=parent
45+
self.__kwargs=kwargs
46+
self.__children= []
47+
self.imports= []
48+
self.mcu=None
49+
50+
defadd_child(self,child):
51+
ifself.name=='MCU':
52+
self.__dict__.update(child.__dict__)
53+
self.board=child.name
54+
self.name='MCU'
55+
elifself.parentisNoneandchild.name=='MCU':
56+
self.mcu=TOMLmcu(child)
57+
else:
58+
self.__children.append(child)
59+
60+
def__getattr__(self,item):
61+
ifiteminself.__dict__:
62+
returnself.__dict__[item]
63+
64+
ifiteminself.__kwargs:
65+
returnself.__kwargs[item]
66+
67+
raiseAttributeError(item)
68+
69+
@property
70+
deffqn(self):
71+
ifself.__kwargs:
72+
if'params'inself.__kwargsor'value'inself.__kwargs:
73+
returnself.parent.fqn+'.'+self.name
74+
75+
returnself.name+' = '+self.parent.fqn
76+
77+
ifself.name=='I2C':
78+
return'i2c.I2C'
79+
80+
ifself.name=='SPI':
81+
return'machine.SPI'
82+
83+
ifself.name=='SDCard':
84+
return'machine.SDCard'
85+
86+
ifself.name.lower()indisplay_drivers:
87+
returnself.name.lower()+'.'+self.name
88+
89+
ifself.name.lower()inindev_drivers:
90+
returnself.name.lower()+'.'+self.name
91+
92+
ifself.name.lower()inio_expanders:
93+
returnself.name.lower()+'.'+self.name
94+
95+
ifself.namein ('I80Bus','SPIBus','I2CBus','RGBBus'):
96+
return'lcd_bus.'+self.name
97+
98+
ifself.parentisNone:
99+
returnNone
100+
101+
ifself.parent.name:
102+
returnself.parent.fqn+'.'+self.name
103+
104+
returnself.name
105+
106+
@property
107+
defvar_names(self):
108+
ifself.__kwargs:
109+
fqn=self.fqn
110+
111+
if'='infqn:
112+
return [fqn.split('=')[0].strip()]
113+
114+
return []
115+
116+
var_names= []
117+
118+
forchildinself.__children:
119+
var_names.extend(child.var_names)
120+
121+
returnvar_names
122+
123+
@property
124+
defconstants(self):
125+
res= []
126+
127+
ifnotself.__children:
128+
forkey,valueinlist(self.__kwargs.items()):
129+
ifnotisinstance(value,int)orkey=='value':
130+
continue
131+
132+
name=self.name.upper()
133+
134+
key_upper=key.upper()
135+
ifnamenotinkey_upper:
136+
key_upper=name+'_'+key_upper
137+
138+
res.append(f'_{key_upper} = const({value})')
139+
self.__kwargs[key]=f'_{key_upper}'
140+
else:
141+
forchildinself.__children:
142+
res.extend(child.constants)
143+
144+
returnres
145+
146+
def__str__(self):
147+
ifself.parentisNone:
148+
var_names=self.var_names
149+
150+
output= []
151+
output.extend(self.constants)
152+
153+
forchildinself.__children:
154+
ifchild.namenotinvar_names:
155+
module=child.fqn.split('.')[0]
156+
ifmodulenotinself.imports:
157+
self.imports.append(module)
158+
output.extend(['',f'import{module}',''])
159+
160+
output.append(str(child))
161+
162+
ifoutput:
163+
output= [
164+
'from micropython import const',
165+
'import lvgl as lv',
166+
'',
167+
''
168+
]+output
169+
170+
return'\n'.join(output)
171+
172+
ifself.__childrenandnotself.__kwargs:
173+
output= [str(child)forchildinself.__children]
174+
return'\n'.join(output)
175+
176+
fqn=self.fqn
177+
178+
iflen(self.__kwargs)==1:
179+
key=list(self.__kwargs.keys())[0]
180+
ifkey=='params':
181+
params=', '.join(str(itm)foritminself.__kwargs[key])
182+
returnf'{fqn}({params})'
183+
elifkey=='value':
184+
returnf'{fqn} = '+str(self.__kwargs[key])
185+
else:
186+
returnf'{fqn}({key}={str(self.__kwargs[key])})'
187+
else:
188+
params=',\n'.join(f'{k}={str(v)}'fork,vinself.__kwargs.items()ifnotisinstance(v,dict))
189+
ifparams:
190+
output= [f'{fqn}(\n{params}\n)','']
191+
else:
192+
raiseRuntimeError
193+
194+
forchildinself.__children:
195+
output.append(self.name+'.'+str(child).split('.',2)[-1])
196+
197+
iflen(output)>2:
198+
output.append('')
199+
200+
return'\n'.join(output)
201+
202+
203+
classTOMLmcu:
204+
205+
def__init__(self,mcu):
206+
name=mcu.board
207+
build_args=mcu.build_args
208+
209+
command= [name]
210+
forarg,valueinbuild_args.items():
211+
ifarg.islower():
212+
build_arg='--'+arg.replace('_','-')
213+
ifisinstance(value,bool)andnotvalue:
214+
raiseSyntaxError(
215+
'optionless build commands must be set to "true"\n'
216+
f'if they are used in the toml file. ({arg} ={repr(value)})'
217+
)
218+
else:
219+
build_arg=arg
220+
221+
ifnotisinstance(value,bool):
222+
build_arg=f'{build_arg}={value}'
223+
224+
command.append(build_arg)
225+
226+
self.build_command=command
227+
228+
229+
base_path=os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))
230+
231+
display_driver_path=os.path.join(base_path,'api_drivers/common_api_drivers/display')
232+
indev_driver_path=os.path.join(base_path,'api_drivers/common_api_drivers/indev')
233+
io_expander_path=os.path.join(base_path,'api_drivers/common_api_drivers/io_expander')
234+
235+
236+
display_drivers= [fileforfileinos.listdir(display_driver_path)ifnotfile.endswith('.wip')andnotfile.endswith('.py')]
237+
indev_drivers= [file[:-3]forfileinos.listdir(indev_driver_path)iffile.endswith('.py')]
238+
io_expanders= [file[:-3]forfileinos.listdir(io_expander_path)iffile.endswith('.py')]
239+
240+
241+
defrun(toml_path,output_file):
242+
243+
ifnotos.path.exists(toml_path):
244+
raiseRuntimeError(f'inable to locate .toml ({toml_path})')
245+
246+
try:
247+
withopen(toml_path,'r')asf:
248+
toml_data=toml.load(f)
249+
250+
toml_obj=TOMLObject('',**toml_data)
251+
252+
t_data=str(toml_obj)
253+
254+
ift_data:
255+
withopen(output_file,'w')asf:
256+
f.write(t_data)
257+
258+
displays= [f'DISPLAY={item}'foritemintoml_obj.importsifitemindisplay_drivers]
259+
indevs= [f'INDEV={item}'foritemintoml_obj.importsifiteminindev_drivers]
260+
expanders= [f'EXPANDER={item}'foritemintoml_obj.importsifiteminio_expanders]
261+
262+
iftoml_obj.mcuisNone:
263+
build_command= []
264+
else:
265+
build_command=toml_obj.build_command
266+
267+
fordisplayindisplays[:]:
268+
ifdisplaynotinbuild_command:
269+
build_command.append(display)
270+
271+
forindevinindevs[:]:
272+
ifindevnotinbuild_command:
273+
build_command.append(indev)
274+
275+
forexpanderinexpanders[:]:
276+
ifexpandernotinbuild_command:
277+
build_command.append(expander)
278+
279+
returnbuild_command
280+
281+
exceptOSErroraserr:
282+
raiseRuntimeError(f'Unable to write data to{output_file}')fromerr
283+
exceptExceptionaserr:# NOQA
284+
raiseSyntaxError(f'Unable to parse .toml file ({toml_path})')fromerr
285+
286+

‎example_build_toml.toml‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
[MCU.esp32]
3+
BOARD ="ESP32_GENERIC_S3"
4+
BOARD_VARIANT ="SPIRAM_OCT"
5+
octal_flash =true
6+
flash_size =16
7+
enable_jtag_repl ='n'
8+
enable_cdc_repl ='n'
9+
enable_uart_repl ='y'
10+
uart_repl_bitrate =115200
11+
12+
13+
14+
[I80Bus.display_bus]
15+
data0 =9
16+
data1 =46
17+
data2 =3
18+
data3 =8
19+
data4 =18
20+
data5 =17
21+
data6 =16
22+
data7 =15
23+
dc =0
24+
wr =47
25+
cs =-1
26+
freq =20000000
27+
28+
29+
[I2C.Bus.i2c_bus]
30+
host =0
31+
scl =5
32+
sda =6
33+
freq =100000
34+
35+
36+
[I2C.Device.indev_device]
37+
bus ="i2c_bus"
38+
dev_id ="ft6x36.I2C_ADDR"
39+
reg_bits ="ft6x36.BITS"
40+
41+
42+
[ST7796.display]
43+
data_bus ="display_bus"
44+
display_width =320
45+
display_height =480
46+
backlight_pin =45
47+
color_byte_order ="st7789.BYTE_ORDER_BGR"
48+
color_space ="lv.COLOR_FORMAT.RGB565"
49+
rgb565_byte_swap =true
50+
51+
[ST7796.display.init]
52+
params = []
53+
54+
[FT6x36.indev]
55+
device ="indev_device"
56+
57+
[display.set_color_inversion]
58+
params = [true]
59+
60+
[display.set_rotation]
61+
params = ["lv.DISPLAY_ROTATION._90"]
62+
63+
[display.set_backlight]
64+
params = [100]
65+
66+
[task_handler.TaskHandler]
67+
params=[]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp