kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Badger2040: Build assets from source + CMake builtin copy
rodzic
d1954f50b9
commit
ef72098949
|
@ -42,18 +42,8 @@ jobs:
|
|||
path: pimoroni-pico-${{ github.sha }}
|
||||
|
||||
# Copy Python module files
|
||||
- name: Copy modules & examples
|
||||
- name: HACK - Copy board config fixup
|
||||
run: |
|
||||
cp -r pimoroni-pico-${GITHUB_SHA}/micropython/badger2040_modules_py/* micropython/ports/rp2/modules/
|
||||
cp pimoroni-pico-${GITHUB_SHA}/micropython/examples/badger2040/launcher.py micropython/ports/rp2/modules/_launcher.py
|
||||
cp pimoroni-pico-${GITHUB_SHA}/micropython/examples/badger2040/clock.py micropython/ports/rp2/modules/_clock.py
|
||||
cp pimoroni-pico-${GITHUB_SHA}/micropython/examples/badger2040/fonts.py micropython/ports/rp2/modules/_fonts.py
|
||||
cp pimoroni-pico-${GITHUB_SHA}/micropython/examples/badger2040/e-reader.py micropython/ports/rp2/modules/_ebook.py
|
||||
cp pimoroni-pico-${GITHUB_SHA}/micropython/examples/badger2040/image.py micropython/ports/rp2/modules/_image.py
|
||||
cp pimoroni-pico-${GITHUB_SHA}/micropython/examples/badger2040/checklist.py micropython/ports/rp2/modules/_list.py
|
||||
cp pimoroni-pico-${GITHUB_SHA}/micropython/examples/badger2040/badge.py micropython/ports/rp2/modules/_badge.py
|
||||
cp pimoroni-pico-${GITHUB_SHA}/micropython/examples/badger2040/help.py micropython/ports/rp2/modules/_help.py
|
||||
cp pimoroni-pico-${GITHUB_SHA}/micropython/examples/badger2040/info.py micropython/ports/rp2/modules/_info.py
|
||||
cp pimoroni-pico-${GITHUB_SHA}/micropython/badger2040-mpconfigboard.h micropython/ports/rp2/boards/PICO/mpconfigboard.h
|
||||
|
||||
# Linux deps
|
||||
|
|
|
@ -5,14 +5,17 @@
|
|||
# and reducing to black and white with dither. the data is then output as an
|
||||
# array that can be embedded directly into your c++ code
|
||||
|
||||
import io
|
||||
import argparse
|
||||
import sys
|
||||
from PIL import Image, ImageEnhance
|
||||
from pathlib import Path
|
||||
import data_to_py
|
||||
|
||||
parser = argparse.ArgumentParser(description='Converts images into the format used by Badger2040.')
|
||||
parser.add_argument('file', nargs="+", help='input files to convert')
|
||||
parser.add_argument('--out_dir', type=Path, default=None, help='output directory')
|
||||
parser.add_argument('--binary', action="store_true", help='output binary file for MicroPython')
|
||||
parser.add_argument('--py', action="store_true", help='output .py file for MicroPython embedding')
|
||||
parser.add_argument('--resize', action="store_true", help='force images to 296x128 pixels')
|
||||
|
||||
options = parser.parse_args()
|
||||
|
@ -39,10 +42,21 @@ for input_filename in options.file:
|
|||
output_data = [~b & 0xff for b in list(img.tobytes())]
|
||||
|
||||
if options.binary:
|
||||
if options.out_dir is not None:
|
||||
output_filename = (options.out_dir / image_name).with_suffix(".bin")
|
||||
else:
|
||||
output_filename = Path(input_filename).with_suffix(".bin")
|
||||
print(f"Saving to {output_filename}, {w}x{h}")
|
||||
with open(output_filename, "wb") as out:
|
||||
out.write(bytearray(output_data))
|
||||
elif options.py:
|
||||
if options.out_dir is not None:
|
||||
output_filename = (options.out_dir / image_name).with_suffix(".py")
|
||||
else:
|
||||
output_filename = Path(input_filename).with_suffix(".py")
|
||||
print(f"Saving to {output_filename}, {w}x{h}")
|
||||
with open(output_filename, "w") as out:
|
||||
data_to_py.write_stream(io.BytesIO(bytes(output_data)), out)
|
||||
else:
|
||||
image_code = '''\
|
||||
static const uint8_t {image_name}[{count}] = {{
|
||||
|
|
|
@ -0,0 +1,153 @@
|
|||
#! /usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2016 Peter Hinch
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import os
|
||||
|
||||
# UTILITIES FOR WRITING PYTHON SOURCECODE TO A FILE
|
||||
|
||||
# ByteWriter takes as input a variable name and data values and writes
|
||||
# Python source to an output stream of the form
|
||||
# my_variable = b'\x01\x02\x03\x04\x05\x06\x07\x08'\
|
||||
|
||||
# Lines are broken with \ for readability.
|
||||
|
||||
|
||||
class ByteWriter(object):
|
||||
bytes_per_line = 16
|
||||
|
||||
def __init__(self, stream, varname):
|
||||
self.stream = stream
|
||||
self.stream.write('{} =\\\n'.format(varname))
|
||||
self.bytecount = 0 # For line breaks
|
||||
|
||||
def _eol(self):
|
||||
self.stream.write("'\\\n")
|
||||
|
||||
def _eot(self):
|
||||
self.stream.write("'\n")
|
||||
|
||||
def _bol(self):
|
||||
self.stream.write("b'")
|
||||
|
||||
# Output a single byte
|
||||
def obyte(self, data):
|
||||
if not self.bytecount:
|
||||
self._bol()
|
||||
self.stream.write('\\x{:02x}'.format(data))
|
||||
self.bytecount += 1
|
||||
self.bytecount %= self.bytes_per_line
|
||||
if not self.bytecount:
|
||||
self._eol()
|
||||
|
||||
# Output from a sequence
|
||||
def odata(self, bytelist):
|
||||
for byt in bytelist:
|
||||
self.obyte(byt)
|
||||
|
||||
# ensure a correct final line
|
||||
def eot(self): # User force EOL if one hasn't occurred
|
||||
if self.bytecount:
|
||||
self._eot()
|
||||
self.stream.write('\n')
|
||||
|
||||
|
||||
# PYTHON FILE WRITING
|
||||
|
||||
STR01 = """# Code generated by data_to_py.py.
|
||||
version = '0.1'
|
||||
"""
|
||||
|
||||
STR02 = """_mvdata = memoryview(_data)
|
||||
|
||||
def data():
|
||||
return _mvdata
|
||||
|
||||
"""
|
||||
|
||||
def write_func(stream, name, arg):
|
||||
stream.write('def {}():\n return {}\n\n'.format(name, arg))
|
||||
|
||||
|
||||
def write_data(op_path, ip_path):
|
||||
try:
|
||||
with open(ip_path, 'rb') as ip_stream:
|
||||
try:
|
||||
with open(op_path, 'w') as op_stream:
|
||||
write_stream(ip_stream, op_stream)
|
||||
except OSError:
|
||||
print("Can't open", op_path, 'for writing')
|
||||
return False
|
||||
except OSError:
|
||||
print("Can't open", ip_path)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def write_stream(ip_stream, op_stream):
|
||||
op_stream.write(STR01)
|
||||
op_stream.write('\n')
|
||||
data = ip_stream.read()
|
||||
bw_data = ByteWriter(op_stream, '_data')
|
||||
bw_data.odata(data)
|
||||
bw_data.eot()
|
||||
op_stream.write(STR02)
|
||||
|
||||
|
||||
# PARSE COMMAND LINE ARGUMENTS
|
||||
|
||||
def quit(msg):
|
||||
print(msg)
|
||||
sys.exit(1)
|
||||
|
||||
DESC = """data_to_py.py
|
||||
Utility to convert an arbitrary binary file to Python source.
|
||||
Sample usage:
|
||||
data_to_py.py image.jpg image.py
|
||||
|
||||
"""
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(__file__, description=DESC,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument('infile', type=str, help='Input file path')
|
||||
parser.add_argument('outfile', type=str,
|
||||
help='Path and name of output file. Must have .py extension.')
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if not os.path.isfile(args.infile):
|
||||
quit("Data filename does not exist")
|
||||
|
||||
if not os.path.splitext(args.outfile)[1].upper() == '.PY':
|
||||
quit('Output filename must have a .py extension.')
|
||||
|
||||
print('Writing Python file.')
|
||||
if not write_data(args.outfile, args.infile):
|
||||
sys.exit(1)
|
||||
|
||||
print(args.outfile, 'written successfully.')
|
|
@ -31,5 +31,6 @@ include(breakout_icp10125/micropython)
|
|||
include(breakout_scd41/micropython)
|
||||
|
||||
include(badger2040/micropython)
|
||||
include(badger2040/micropython-builtins)
|
||||
include(plasma/micropython)
|
||||
include(ulab/code/micropython)
|
Plik diff jest za duży
Load Diff
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 3.4 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 36 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 9.8 KiB |
|
@ -0,0 +1,53 @@
|
|||
function (convert_image TARGET IMAGE)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../modules/${IMAGE}.py
|
||||
|
||||
COMMAND
|
||||
cd ${CMAKE_CURRENT_LIST_DIR}/assets && python3 ../../../../examples/badger2040/image_converter/convert.py --out_dir ${CMAKE_CURRENT_BINARY_DIR}/../modules --py ${IMAGE}.png
|
||||
|
||||
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/assets/${IMAGE}.png
|
||||
)
|
||||
target_sources(${TARGET} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../modules/${IMAGE}.py)
|
||||
endfunction()
|
||||
|
||||
function (convert_raw TARGET SRC DST)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../modules/${DST}.py
|
||||
|
||||
COMMAND
|
||||
cd ${CMAKE_CURRENT_LIST_DIR}/assets && python3 ../../../../examples/badger2040/image_converter/data_to_py.py ${CMAKE_CURRENT_LIST_DIR}/assets/${SRC} ${CMAKE_CURRENT_BINARY_DIR}/../modules/${DST}.py
|
||||
|
||||
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/assets/${SRC}
|
||||
)
|
||||
target_sources(${TARGET} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../modules/${DST}.py)
|
||||
endfunction()
|
||||
|
||||
function (copy_module TARGET SRC DST)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../modules/${DST}.py
|
||||
|
||||
COMMAND
|
||||
cp ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/../modules/${DST}.py
|
||||
|
||||
DEPENDS ${src}
|
||||
)
|
||||
|
||||
target_sources(${TARGET} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../modules/${DST}.py)
|
||||
endfunction()
|
||||
|
||||
convert_image(usermod_badger2040 badge_image)
|
||||
convert_image(usermod_badger2040 badgerpunk)
|
||||
convert_image(usermod_badger2040 launchericons)
|
||||
|
||||
convert_raw(usermod_badger2040 289-0-wind-in-the-willows-abridged.txt witw)
|
||||
|
||||
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/../../badger2040_modules_py/boot.py boot)
|
||||
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/../../examples/badger2040/launcher.py _launcher)
|
||||
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/../../examples/badger2040/clock.py _clock)
|
||||
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/../../examples/badger2040/fonts.py _fonts)
|
||||
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/../../examples/badger2040/e-reader.py _ebook)
|
||||
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/../../examples/badger2040/image.py _image)
|
||||
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/../../examples/badger2040/checklist.py _list)
|
||||
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/../../examples/badger2040/badge.py _badge)
|
||||
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/../../examples/badger2040/help.py _help)
|
||||
copy_module(usermod_badger2040 ${CMAKE_CURRENT_LIST_DIR}/../../examples/badger2040/info.py _info)
|
Ładowanie…
Reference in New Issue