Skip to content
Snippets Groups Projects
Select Git revision
  • 71be1ddeb128e6068d2f1df605ec9c8c10f67091
  • master default protected
  • schneider/ir
  • rahix/user-space-ctx
  • schneider/iaq-python
  • schneider/ble-mini-demo
  • schneider/ble-ecg-stream-visu
  • schneider/mp-exception-print
  • schneider/sleep-display
  • schneider/deepsleep4
  • schneider/deepsleep2
  • schneider/deepsleep
  • schneider/ble-central
  • rahix/bluetooth-app-favorite
  • schneider/v1.17-changelog
  • schneider/ancs
  • schneider/png
  • schneider/freertos-list-debug
  • schneider/212-reset-hardware-when-entering-repl
  • schneider/bonding-fail-if-full
  • schneider/ble-fixes-2020-3
  • v1.18
  • v1.17
  • v1.16
  • v1.15
  • v1.14
  • v1.13
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
41 results

group__SPI17Y__DMA.html

Blame
  • make-frozen.py 1.34 KiB
    #!/usr/bin/env python
    #
    # Create frozen modules structure for MicroPython.
    #
    # Usage:
    #
    # Have a directory with modules to be frozen (only modules, not packages
    # supported so far):
    #
    # frozen/foo.py
    # frozen/bar.py
    #
    # Run script, passing path to the directory above:
    #
    # ./make-frozen.py frozen > frozen.c
    #
    # Include frozen.c in your build, having defined MICROPY_MODULE_FROZEN_STR in
    # config.
    #
    from __future__ import print_function
    import sys
    import os
    
    
    def module_name(f):
        return f[:-len(".py")]
    
    modules = []
    
    root = sys.argv[1].rstrip("/")
    root_len = len(root)
    
    for dirpath, dirnames, filenames in os.walk(root):
        for f in filenames:
            fullpath = dirpath + "/" + f
            st = os.stat(fullpath)
            modules.append((fullpath[root_len + 1:], st))
    
    print("#include <stdint.h>")
    print("const char mp_frozen_str_names[] = {")
    for f, st in modules:
        m = module_name(f)
        print('"%s\\0"' % m)
    print('"\\0"};')
    
    print("const uint32_t mp_frozen_str_sizes[] = {")
    
    for f, st in modules:
        print("%d," % st.st_size)
    
    print("};")
    
    print("const char mp_frozen_str_content[] = {")
    for f, st in modules:
        data = open(sys.argv[1] + "/" + f, "rb").read()
        # Python2 vs Python3 tricks
        data = repr(data)
        if data[0] == "b":
            data = data[1:]
        data = data[1:-1]
        data = data.replace('"', '\\"')
        print('"%s\\0"' % data)
    print("};")