From 32498c500a45bfaf89bcec4f405aebaa68ac16d8 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Tue, 7 Dec 2021 16:39:22 +0000 Subject: [PATCH 1/5] Remove examples/go Uses the old DFU tool... on things that aren't DFU-able and the removed flash tool. --- examples/go | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 examples/go diff --git a/examples/go b/examples/go deleted file mode 100644 index b3bc62d9b..000000000 --- a/examples/go +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -PROJECT=$(echo $1 | sed 's:/*$::') - -echo "32blit: Build and flash project $PROJECT" - -if [ -d "${PROJECT}" ] -then - - cd $PROJECT - - mkdir -p build.stm32 - - cd build.stm32 - - echo " - preparing" - - cmake .. -DCMAKE_TOOLCHAIN_FILE=../../../32blit.toolchain # > /dev/null - - echo " - building" - - make -j8 # > /dev/null - - ../../../tools/dfu build --force --out $PROJECT.dfu $PROJECT.bin - - echo " - flashing to device (make sure it's in DFU mode!)" - - ../../../../32Blit.exe SAVE COM4 $PROJECT.bin -# ../../../tools/wsl-flash $PROJECT.dfu # > /dev/null - - cd .. - cd .. - - echo "..done! Reset your 32blit and happy hacking! :-)" -fi - -if [ ! -d "${PROJECT}" ] -then - echo "ERROR: Cannot find project $PROJECT. :-(" - exit 1 -fi - -exit 0 From 9e046705fa9cb7ab5836bbe6695b1b9605181a81 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Tue, 7 Dec 2021 16:43:03 +0000 Subject: [PATCH 2/5] Remove tools/dfu Replaced with 32blit-tools --- tools/dfu | 223 ------------------------------------------------------ 1 file changed, 223 deletions(-) delete mode 100755 tools/dfu diff --git a/tools/dfu b/tools/dfu deleted file mode 100755 index 651f52eec..000000000 --- a/tools/dfu +++ /dev/null @@ -1,223 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import sys -import pathlib -import zlib - -missing_modules = [] - -try: - from bitstring import BitArray -except ImportError: - missing_modules.append("bitstring") - -try: - import construct - from construct import this, len_, Struct, Padded, CString, Rebuild, Computed, RawCopy, Checksum, Hex, Bytes, Int8ul, Int16ul, Int32ul, Const, Flag, Padding, Array, Prefixed, GreedyBytes, GreedyRange, PaddedString -except ImportError: - missing_modules.append("construct") - -if len(missing_modules) > 0: - error_text = "" - if 'build' in sys.argv: - error_text += """ -Warning: no dfu file has been generated (missing python3 dependencies) -""" - error_text += f""" -dfu requires the following python module(s): {', '.join(missing_modules)} -install with: python3 -m pip install {' '.join(missing_modules)} -""" - # Soft fail to avoid cmake error - print(error_text) - sys.exit(0) - - -DFU_SIGNATURE = b'DfuSe' -DFU_size = Rebuild(Int32ul, 0) - - -def DFU_file_length(ctx): - '''Compute the entire file size + 4 bytes for CRC - - The total DFU file length is ostensibly the actual - length in bytes of the resulting file. - - However DFU File Manager does not seem to agree, - since it's output size is 16 bytes short. - - Since this is suspiciously the same as the suffix - length in bytes, we omit that number to match - DFU File Manager's output. - - ''' - size = 11 # DFU Header Length - # size += 16 # DFU Suffix Length - for target in ctx.targets: - # Each target has a 274 byte header consisting - # of the following fields: - size += Const(DFU_SIGNATURE).sizeof() # szSignature ('Target' in bytes) - size += Int8ul.sizeof() # bAlternateSetting - size += Int8ul.sizeof() # bTargetNamed - size += Padding(3).sizeof() # Padding - size += Padded(255, CString('utf8')).sizeof() # szTargetName - size += Int32ul.sizeof() # dwTargetSize - size += Int32ul.sizeof() # dwNbElements - size += DFU_target_size(target) - - return size - - -def DFU_target_size(ctx): - '''Returns the size of the target binary data, plus the - dwElementAddress header, and dwElementSize byte count. - ''' - size = 0 - - try: - images = ctx.images - except AttributeError: - images = ctx['images'] - - size += sum([DFU_image_size(image) for image in images]) - return size - - -def DFU_image_size(image): - return len(image['data']) + Int32ul.sizeof() + Int32ul.sizeof() - - -DFU_image = Struct( - 'dwElementAddress' / Hex(Int32ul), # Data offset address for image - 'data' / Prefixed(Int32ul, GreedyBytes) -) - -DFU_target = Struct( - 'szSignature' / Const(b'Target'), # DFU target identifier - 'bAlternateSetting' / Int8ul, # Gives device alternate setting for which this image can be used - 'bTargetNamed' / Flag, # Boolean determining if the target is named - Padding(3), # Mystery bytes! - 'szTargetName' / Padded(255, CString('utf8')), # Target name - # DFU File Manager does not initialise this - # memory, so our file will not exactly match - # its output. - 'dwTargetSize' / Rebuild(Int32ul, DFU_target_size), # Total size of target images - 'dwNbElements' / Rebuild(Int32ul, len_(this.images)), # Count the number of target images - 'images' / GreedyRange(DFU_image) -) - -DFU_body = Struct( - 'szSignature' / Const(DFU_SIGNATURE), # DFU format identifier (changes on major revisions) - 'bVersion' / Const(1, Int8ul), # DFU format revision (changes on minor revisions) - 'DFUImageSize' / Rebuild(Int32ul, DFU_file_length), # Total DFU file length in bytes - 'bTargets' / Rebuild(Int8ul, len_(this.targets)), # Number of targets in the file - - 'targets' / GreedyRange(DFU_target), - - 'bcdDevice' / Int16ul, # Firmware version, or 0xffff if ignored - 'idProduct' / Hex(Int16ul), # USB product ID or 0xffff to ignore - 'idVendor' / Hex(Int16ul), # USB vendor ID or 0xffff to ignore - 'bcdDFU' / Const(0x011A, Int16ul), # DFU specification number - 'ucDfuSignature' / Const(b'UFD'), # 0x44, 0x46 and 0x55 ie 'DFU' but reversed - 'bLength' / Const(16, Int8ul) # Length of the DFU suffix in bytes -) - -DFU = Struct( - 'fields' / RawCopy(DFU_body), - 'dwCRC' / Checksum(Int32ul, # CRC calculated over the whole file, except for itself - lambda data: 0xffffffff ^ zlib.crc32(data), - this.fields.data) -) - - -def display_dfu_info(parsed): - print(f''' -Device: {parsed.fields.value.bcdDevice} -Target: {parsed.fields.value.idProduct:04x}:{parsed.fields.value.idVendor:04x} -Size: {parsed.fields.value.DFUImageSize:,} bytes -Targets: {parsed.fields.value.bTargets}''') - for target in parsed.fields.value.targets: - print(f''' - Name: {target.szTargetName} - Alternate Setting: {target.bAlternateSetting} - Size: {target.dwTargetSize:,} bytes - Images: {target.dwNbElements}''') - for image in target.images: - print(f''' - Offset: {image.dwElementAddress} - Size: {len(image.data):,} bytes -''') - - -if __name__ == '__main__': - parser = argparse.ArgumentParser() - subparsers = parser.add_subparsers(help='Commands', dest='command') - parser_build = subparsers.add_parser('build', help='Build a DFU image') - parser_read = subparsers.add_parser('read', help='Read a DFU image') - parser_dump = subparsers.add_parser('dump', help='Dump binary from DFU image') - parser_dump.add_argument('--force', action='store_true') - parser_build.add_argument('--out', type=pathlib.Path, help='Output file', default=None) - parser_build.add_argument('--address', type=int, default=0x08000000) - parser_build.add_argument('--force', action='store_true') - parser.add_argument('file', type=pathlib.Path, help='Input file') - parser.add_argument('--verbose', action='store_true') - - args = parser.parse_args() - - if not args.file.is_file(): - raise parser.error(f'Invalid input file "{args.file}"') - - if args.command == 'build': - if not args.out.parent.is_dir(): - raise parser.error(f'Output directory "{args.out.parent}" does not exist!') - elif args.out.is_file() and not args.force: - raise parser.error(f'Existing output file "{args.out}", use --force to overwrite!') - - if not args.file.suffix == ".bin": - raise parser.error(f'Input file "{args.file}", is not a .bin file?') - - output = DFU.build({'fields': {'value': { - 'targets': [{ - 'bAlternateSetting': 0, - 'bTargetNamed': True, - 'szTargetName': 'ST...', - 'images': [{ - 'dwElementAddress': args.address, - 'data': open(args.file, 'rb').read() - }] - }], - 'bcdDevice': 0, - 'idProduct': 0x0000, - 'idVendor': 0x0483 - }}}) - - if args.verbose: - print(f'''Packing "{args.file}" into "{args.out}"''') - display_dfu_info(DFU.parse(output)) - - open(args.out, 'wb').write(output) - - if args.command == 'read' or args.command == 'dump': - try: - parsed = DFU.parse(open(args.file, 'rb').read()) - except construct.core.ConstructError as error: - parser.error(f'Invalid dfu file {args.file} ({error})') - - display_dfu_info(parsed) - - if args.command == 'dump': - - for target in parsed.fields.value.targets: - target_id = target.bAlternateSetting - for image in target.images: - address = image.dwElementAddress - data = image.data - dest = str(args.file).replace('.dfu', '') - filename = f"{dest}-{target_id}-{address}.bin" - - if pathlib.Path(filename).is_file() and not args.force: - raise parser.error(f'Existing output file "{filename}", use --force to overwrite!') - - print(f"Dumping image at {address} to {filename} ({len(data)} bytes)") - - open(filename, 'wb').write(data) From 3335e3db0a8c0228580a4c213d32a6848693fec5 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Tue, 7 Dec 2021 16:44:16 +0000 Subject: [PATCH 3/5] Remove 32blit/README.md Not very helpful --- 32blit/README.md | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 32blit/README.md diff --git a/32blit/README.md b/32blit/README.md deleted file mode 100644 index d9200a16c..000000000 --- a/32blit/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# x-software -Software for X project From b96f3bf307c2ab5d7b4057fb4136848a6545a01d Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Tue, 7 Dec 2021 16:45:15 +0000 Subject: [PATCH 4/5] Remove 32blit/helpers.hpp Entirely commented out and not included from anywhere --- 32blit/helpers.hpp | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 32blit/helpers.hpp diff --git a/32blit/helpers.hpp b/32blit/helpers.hpp deleted file mode 100644 index 9dfea3267..000000000 --- a/32blit/helpers.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -/* -#undef min -#undef max - -template -const T& clamp(const T &value, const T &min, const T &max) { - return value < min ? min : (value > max ? max : value); -} - -template -const T& min(const T &v1, const T &v2) { - return v1 < v2 ? v1 : v2; -} - -template -const T& max(const T &v1, const T &v2) { - return v1 > v2 ? v1 : v2; -} - -template -const T& min(const T &v1, const T &v2, const T &v3) { - return min(v1, min(v2, v3)); -} - -template -const T& max(const T &v1, const T &v2, const T &v3) { - return max(v1, max(v2, v3)); -}*/ \ No newline at end of file From 4625a113d44f46e8a7b872779ff673bb7c08ffcc Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Tue, 7 Dec 2021 16:52:03 +0000 Subject: [PATCH 5/5] Remove old palette-cycle files --- examples/palette-cycle/palette-cycle-old.hpp | 41 ---- examples/palette-cycle/palette-cycle-old.xcpp | 216 ------------------ 2 files changed, 257 deletions(-) delete mode 100644 examples/palette-cycle/palette-cycle-old.hpp delete mode 100644 examples/palette-cycle/palette-cycle-old.xcpp diff --git a/examples/palette-cycle/palette-cycle-old.hpp b/examples/palette-cycle/palette-cycle-old.hpp deleted file mode 100644 index c736a89cf..000000000 --- a/examples/palette-cycle/palette-cycle-old.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "32blit.hpp" - -const uint8_t torch[] = { - 0x53, 0x50, 0x52, 0x49, 0x54, 0x45, 0x00, 0x00, // type: sprite - 0xd4, 0x00, // payload size (212) - - 0x10, 0x00, // width (16) - 0x10, 0x00, // height (16) - 0x00, 0x00, // cols (0) - 0x00, 0x00, // rows (0) - - 0x02, // format - - 0x10, // number of palette colours -// r g b a - 0x51, 0x35, 0x11, 0xff, - 0x6d, 0x4e, 0x1c, 0xff, - 0xf3, 0xb5, 0x41, 0xff, - 0xfd, 0xca, 0x0b, 0xff, - 0xfc, 0xde, 0x4f, 0xff, - 0xdc, 0xe5, 0xe3, 0xff, - 0x00, 0x00, 0x00, 0xff, - 0x24, 0x24, 0x24, 0xff, - 0x33, 0x34, 0x34, 0xff, - 0x45, 0x45, 0x46, 0xff, - 0x58, 0x58, 0x58, 0xff, - 0x6b, 0x6b, 0x6b, 0xff, - 0x93, 0x94, 0x93, 0xff, - 0xa7, 0xa7, 0xa7, 0xff, - 0xcb, 0xcc, 0xcc, 0xff, - 0xf6, 0xf6, 0xf5, 0xff, - - 0x67, 0x66, 0x66, 0x76, 0x66, 0x6e, 0x66, 0x96, 0x66, 0x68, 0x66, 0x96, 0x66, 0x66, 0x66, 0x66, - 0x66, 0x69, 0x66, 0xa6, 0x66, 0xf6, 0x66, 0x66, 0x66, 0x66, 0x96, 0x6a, 0x67, 0x76, 0x6c, 0x66, - 0x66, 0x66, 0xaa, 0xbb, 0x68, 0x86, 0x66, 0x66, 0x66, 0x66, 0xbb, 0xcc, 0x99, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x6e, 0xed, 0xda, 0x66, 0xf6, 0x66, 0x66, 0x66, 0xff, 0xee, 0xbb, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x69, 0x9f, 0xfc, 0x76, 0x66, 0x66, 0x66, 0x66, 0x66, 0x54, 0x43, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x22, 0x22, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x60, 0x16, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x60, 0x11, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x63, 0x01, 0x36, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x62, 0x00, 0x26, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x22, 0x66, 0x66, 0x66 -}; \ No newline at end of file diff --git a/examples/palette-cycle/palette-cycle-old.xcpp b/examples/palette-cycle/palette-cycle-old.xcpp deleted file mode 100644 index 2f50fc0ca..000000000 --- a/examples/palette-cycle/palette-cycle-old.xcpp +++ /dev/null @@ -1,216 +0,0 @@ -#include "palette-cycle.hpp" - -using namespace engine; -using namespace graphics; - -// define storage for the spritesheet -uint8_t __ss_cycle[16 * 16] __attribute__((section(".ss"))); -surface ss_cycle((uint8_t *)__ss_cycle, size(16, 16), pixel_format::P); -spritesheet s_cycle(ss_cycle, 16, 16); - -bool is_cycling = true; -bool blend_cycle = true; -uint32_t debounce = 0; -int tick_count = 0; -int fire_offset = 0; -uint32_t last_cycle = 0; - -#define FIRE_TYPES 4 -#define FIRE_COLOURS 9 - -//const rgba* grey = (rgba *)&torch2[47]; - -const std::string fire_names[FIRE_TYPES] = { - "Grey", - "Green", - "Blue", - "Red" -}; - -rgba fire[FIRE_TYPES * 9] = { - // Grey Motion Indicator - rgba(0x24, 0x24, 0x24), - rgba(0x33, 0x34, 0x34), - rgba(0x45, 0x45, 0x46), - rgba(0x58, 0x58, 0x58), - rgba(0x6b, 0x6b, 0x6b), - rgba(0x93, 0x94, 0x93), - rgba(0xa7, 0xa7, 0xa7), - rgba(0xcb, 0xcc, 0xcc), - rgba(0xf6, 0xf6, 0xf5), - - // Green Fire - rgba(0, 0, 0), - rgba(20, 20, 20), - rgba(12, 62, 12), - rgba(8, 192, 8), - rgba(73, 192, 8), - rgba(99, 192, 8), - rgba(125, 192, 8), - rgba(159, 192, 8), - rgba(180, 216, 10), - //rgba(222, 195, 14) - - // Blue Fire - rgba(0, 0, 0), - rgba(20, 20, 20), - rgba(12, 12, 62), - rgba(8, 8, 192), - rgba(73, 8, 192), - rgba(99, 8, 192), - rgba(125, 8, 192), - rgba(159, 8, 192), - rgba(180, 10, 216), - //rgba(222, 195, 14) - - // Red Fire - rgba(0, 0, 0), - rgba(20, 20, 20), - rgba(62, 12, 12), - rgba(192, 8, 8), - rgba(192, 73, 8), - rgba(192, 99, 8), - rgba(192, 125, 8), - rgba(192, 159, 8), - rgba(216, 180, 10), - //rgba(222, 195, 14) -}; - -rgba fadeColour(rgba a, rgba b, float f) { - rgba t(0, 0, 0, 255); - t.r = std::min(255, std::max(0, int(a.r + (float(b.r - a.r) * f)))); - t.g = std::min(255, std::max(0, int(a.g + (float(b.g - a.g) * f)))); - t.b = std::min(255, std::max(0, int(a.b + (float(b.b - a.b) * f)))); - return t; -} - -void init() { - set_screen_mode(screen_mode::hires); - s_cycle.s.load_from_packed(torch); -} - -void render(uint32_t time) { - fb.pen(s_cycle.s.palette[6]); - fb.clear(); - - fb.alpha = 255; - fb.mask = nullptr; - fb.pen(rgba(255, 255, 255)); - fb.rectangle(rect(0, 0, 320, 14)); - fb.pen(rgba(0, 0, 0)); - fb.text("Palette cycle demo", minimal_font, point(5, 4)); - - uint32_t ms_start = now(); - - fb.stretch_blit(&ss_cycle, rect(0, 0, 16, 16), rect((fb.bounds.w - 128) / 2, (fb.bounds.h - 128) / 2, 128, 128)); - - if (is_cycling) { - int offset = fire_offset * FIRE_COLOURS; - float t = ms_start / 50.0f; - float phase = (t - floor(t)); - for (int p = 7; p < 16; p++) { - int index = p - 7 + t; - index %= FIRE_COLOURS; - int blend_to = index + 1; - if (blend_to > (FIRE_COLOURS - 1)) { blend_to = 0; } - if (blend_cycle) { - // Blended Cycle - s_cycle.s.palette[p] = fadeColour(fire[offset + index], fire[offset + blend_to], std::max(0.0f, std::min(1.0f, phase))); - } - else - { - // Regular Cycle - s_cycle.s.palette[p] = fire[offset + index]; - } - } - } - - for (int x = 0; x < 16; x++) { - rgba r = s_cycle.s.palette[x]; - fb.pen(r); - fb.rectangle(rect(20 * x, 220, 20, 20)); - //std::stringstream no; - //no << x; - //fb.pen(rgba(128, 128, 128)); - //fb.text(no.str(), minimal_font, rect(10 * x, 100, 10, 10)); - } - - for (int i = 0; i < FIRE_TYPES; i++) { - fb.pen(fire_offset == i ? rgba(200, 200, 200) : rgba(100, 100, 100) ); - fb.text(fire_names[i], minimal_font, rect(4, i * 10 + 18, 100, 10)); - } -/* - fb.pen(blend_cycle ? rgba(200, 200, 200) : rgba(100, 100, 100)); - fb.text("PRESS B", minimal_font, rect(4, 62, 100, 10)); - fb.text("TO BLEND", minimal_font, rect(4, 70, 100, 10)); - - fb.pen(is_cycling ? rgba(200, 200, 200) : rgba(100, 100, 100)); - fb.text("PRESS A", minimal_font, rect(4, 82, 100, 10)); - fb.text(is_cycling ? "TO PAUSE" : "TO PLAY", minimal_font, rect(4, 90, 100, 10)); -*/ - uint32_t ms_end = now(); - - fb.watermark(); - - // draw FPS meter - /*fb.alpha = 200; - fb.pen(rgba(255, 255, 255, 100)); - fb.rectangle(rect(1, 240 - 10, 12, 9)); - fb.pen(rgba(255, 255, 255, 200)); - std::string fms = std::to_string(ms_end - ms_start); - fb.text(fms, minimal_font, rect(3, 120 - 9, 10, 16)); - - int block_size = 4; - for (int i = 0; i < (ms_end - ms_start); i++) { - fb.pen(rgba(i * 5, 255 - (i * 5), 0)); - fb.rectangle(rect(i * (block_size + 1) + 1 + 13, fb.bounds.h - block_size - 1, block_size, block_size)); - }*/ -} - -void update(uint32_t time) { - if (input::buttons & input::A) { - if (!(debounce & input::A)) { - is_cycling = !is_cycling; - debounce |= input::A; - } - } - else { - debounce &= ~input::A; - } - - if (input::buttons & input::B) { - if (!(debounce & input::B)) { - blend_cycle = !blend_cycle; - debounce |= input::B; - } - } - else { - debounce &= ~input::B; - } - - if (input::buttons & input::DPAD_DOWN) { - if (!(debounce & input::DPAD_DOWN)) { - fire_offset += 1; - if (fire_offset > FIRE_TYPES - 1) { - fire_offset = 0; - } - debounce |= input::DPAD_DOWN; - } - } - else { - debounce &= ~input::DPAD_DOWN; - } - - if (input::buttons & input::DPAD_UP) { - if (!(debounce & input::DPAD_UP)) { - fire_offset -= 1; - if (fire_offset < 0) { - fire_offset = FIRE_TYPES - 1; - } - debounce |= input::DPAD_UP; - } - } - else { - debounce &= ~input::DPAD_UP; - } -}