示例#1
0
async def dev_enable_vcp(*a):
    # Enable USB serial port emulation, for devs.
    #
    from usb import is_vcp_active

    if is_vcp_active():
        await ux_show_story(
            """The USB virtual serial port is already enabled.""")
        return

    was = pyb.usb_mode()
    pyb.usb_mode(None)
    if was and 'MSC' in was:
        pyb.usb_mode('VCP+MSC')
    else:
        pyb.usb_mode('VCP+HID')

    # allow REPL access
    ckcc.vcp_enabled(True)

    await ux_show_story("""\
The USB virtual serial port has now been enabled. Use a real computer to connect to it."""
                        )
示例#2
0
async def usb_keypad_emu():
    # Take keypresses on USB virtual serial port (when not in REPL mode)
    # and converts them into keypad events. Super handy for UX testing/dev.
    #
    # IMPORTANT: 
    # - code is **not** used in real product, but left here for devs to use
    # - this code isn't even called; unless you add code to do so, see ../stm32/my_lib_boot2.py
    #
    u = pyb.USB_VCP()

    while 1:
        await sleep_ms(100)

        while u.isconnected() and u.any():
            from main import numpad

            k = u.read(3).decode()

            remap = {  '\r': 'y',
                     '\x1b': 'x', 
                        'q': 'x', 
                   '\x1b[A': '5', 
                   '\x1b[B': '8', 
                   '\x1b[C': '9', 
                   '\x1b[D': '7' }

            if k in remap: k = remap[k]

            if k in '\x04':     # ^D
                # warm reset
                from machine import soft_reset
                soft_reset()

            if k == 'd':
                numpad.debug = (numpad.debug + 1) % 3
                continue

            if k == 'n':
                if numpad.disabled:
                    numpad.start()
                else:
                    numpad.stop()

                print("npdis = %d" % numpad.disabled)
                continue

            if k == 'r':
                numpad.trigger_baseline = True
                continue
            if k == 's':
                numpad.sensitivity = (numpad.sensitivity + 1) % 5
                print("sensi = %d" % numpad.sensitivity)
                continue

            if k == 'U':
                # enter DFU
                import callgate
                callgate.enter_dfu()
                # not reached

            if k == 't':
                ckcc.vcp_enabled(True)
                print("Repl enabled")
                continue

            if k == 'm':
                import gc
                print("Memory: %d" % gc.mem_free())
                continue

            if k in '0123456789xy':
                numpad.inject(k)
            else:
                print('? %r' % k)
示例#3
0
文件: main.py 项目: yahiheb/firmware
# main.py
#
# - main.loop is imported and "run forever" by boot.py, forced into place by COLDCARD/initfs code
# - cannot be changed by /flash/lib overrides, because already imported before that.
#

# see RAM_HEADER_BASE, and coldcardFirmwareHeader_t in sigheader.h
import pyb, sys, version, gc

# this makes the GC run when larger objects are free in an attempt to reduce fragmentation.
gc.threshold(4096)

if 0:
    # useful for debug: keep this stub!
    import ckcc
    ckcc.vcp_enabled(True)
    #pyb.usb_mode('VCP+MSC')            # handy but annoying disk issues
    pyb.usb_mode('VCP')
    raise SystemExit

# what firmware signing key did we boot with? are we in dev mode?
is_devmode = version.is_devmode()

if is_devmode:
    # For devs only: allow code in this directory to overide compiled-in stuff. Dangerous!
    # - using relative paths here so works better on simulator
    # - you must boot w/ non-production-signed firmware to get here
    sys.path.insert(0, 'flash/lib')

    # Give external devs a way to start stuff early
    try:
示例#4
0
文件: usb.py 项目: jimmysong/firmware
def is_vcp_active():
    # VCP = Virtual Comm Port
    en = ckcc.vcp_enabled(None)
    cur = pyb.usb_mode()

    return cur and ('VCP' in cur) and en
示例#5
0
async def usb_keypad_emu():
    # Take keypresses on USB virtual serial port (when not in REPL mode)
    # and converts them into keypad events. Super handy for UX testing/dev.
    #
    # IMPORTANT: 
    # - code is **not** used in real product, but left here for devs to use
    # - this code isn't even called; unless you add code to do so, see ../stm32/my_lib_boot2.py
    #
    from ux import the_ux
    from menu import MenuSystem
    from seed import WordNestMenu

    u = pyb.USB_VCP()

    remap = {  '\r': 'y',
             '\x1b': 'x', 
           '\x1b[A': '5', 
           '\x1b[B': '8', 
           '\x1b[C': '9', 
           '\x1b[D': '7' }

    while 1:
        await sleep_ms(100)

        while u.isconnected() and u.any():
            from main import numpad

            k = u.read(3).decode()

            if k in '\x04':     # ^D
                # warm reset
                from machine import soft_reset
                soft_reset()

            if 0:
                if k == 'd':
                    numpad.debug = (numpad.debug + 1) % 3
                    continue

                if k == 'n':
                    if numpad.disabled:
                        numpad.start()
                    else:
                        numpad.stop()

                    print("npdis = %d" % numpad.disabled)
                    continue

            if k == 'U':
                # enter DFU
                import callgate
                callgate.enter_dfu()
                # not reached

            if k == 'T':
                ckcc.vcp_enabled(True)
                print("Repl enabled")
                continue

            if k == 'M':
                import gc
                print("Memory: %d" % gc.mem_free())
                continue

            # word menus: shortcut for first letter
            top = the_ux.top_of_stack()
            if top and isinstance(top, WordNestMenu) and len(top.items) > 6:
                pos = min(len(i.label) for i in top.items)
                if pos >= 2:
                    for n, it in enumerate(top.items):
                        if it.label[pos-2] == k:
                            top.goto_idx(n)
                            top.show()
                            k = None
                            break

                    if k is None: continue

            if k in remap:
                k = remap[k]

            if k in '0123456789xy':
                numpad.inject(k)
                continue
            
            print('? %r' % k)
示例#6
0
def is_vcp_active():
    en = ckcc.vcp_enabled(None)
    cur = pyb.usb_mode()

    return cur and ('VCP' in cur) and en