From f42b62fa400a42242f54093b0f39c5714f2177e1 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 20 Sep 2016 16:58:47 +0200 Subject: [PATCH] use mock config for stmhal, setup hid in boot --- src/boot.py | 6 ++++ src/trezor/config.py | 70 +++++++++++++++++---------------------- src/trezor/config.py.real | 10 ++++++ 3 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 src/trezor/config.py.real diff --git a/src/boot.py b/src/boot.py index e69de29bb2..ac87751639 100644 --- a/src/boot.py +++ b/src/boot.py @@ -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')) diff --git a/src/trezor/config.py b/src/trezor/config.py index 8eee439661..40d707bf6d 100644 --- a/src/trezor/config.py +++ b/src/trezor/config.py @@ -1,50 +1,40 @@ 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(): - try: - with open(_file, 'rb') as f: - while True: - d = f.read(4) - if len(d) != 4: - break - k, l = ustruct.unpack('