1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 03:18:09 +00:00

use mock config for stmhal, setup hid in boot

This commit is contained in:
Pavol Rusnak 2016-09-20 16:58:47 +02:00
parent 7aa8593941
commit f42b62fa40
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 46 additions and 40 deletions

View File

@ -0,0 +1,6 @@
import sys
if sys.platform in ['trezor', 'pyboard']: # stmhal
import pyb
# hid=(subclass, protocol, max_packet_len, polling_interval, report_desc)
pyb.usb_mode('CDC+HID', vid=0x1209, pid=0x53C1, hid=(0, 0, 64, 1, b'\x06\x00\xff\x09\x01\xa1\x01\x09\x20\x15\x00\x26\xff\x00\x75\x08\x95\x40\x81\x02\x09\x21\x15\x00\x26\xff\x00\x75\x08\x95\x40\x91\x02\xc0'))

View File

@ -1,26 +1,16 @@
import sys
import ustruct
if sys.platform == 'trezor': # stmhal - use binary module (not working atm)
# mock implementation using binary file
from TrezorConfig import Config
_mock = {}
_config = Config()
def get(app, key, default=None):
v = _config.get(app, key)
return v if v else default
def set(app, key, value):
return _config.set(app, key, value)
else: # emulator (mock implementation using binary file)
import ustruct
_mock = {}
if sys.platform in ['trezor', 'pyboard']: # stmhal
_file = '/flash/trezor.config'
else:
_file = '/var/tmp/trezor.config'
def _load():
def _load():
try:
with open(_file, 'rb') as f:
while True:
@ -33,18 +23,18 @@ else: # emulator (mock implementation using binary file)
except OSError:
pass
def _save():
def _save():
with open(_file, 'wb') as f:
for k, v in _mock.items():
f.write(ustruct.pack('<HH', k, len(v)))
f.write(v)
_load()
_load()
def get(app, key, default=None):
def get(app, key, default=None):
return _mock.get((app << 8) | key, default)
def set(app, key, value):
def set(app, key, value):
_mock[(app << 8) | key] = value
_save()
return True

10
src/trezor/config.py.real Normal file
View File

@ -0,0 +1,10 @@
from TrezorConfig import Config
_config = Config()
def get(app, key, default=None):
v = _config.get(app, key)
return v if v else default
def set(app, key, value):
return _config.set(app, key, value)