Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[target.thumbv7em-none-eabihf]
runner = 'npm exec --yes -- nwlink@0.0.19 install-nwa'
rustflags = ["-C", "link-arg=--relocatable", "-C", "link-arg=-no-gc-sections", "-C", "link-arg=-lstorage_c"]

[target.'cfg(target_os="macos")']
rustflags = [
"-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup", "-C", "link-arg=-lSystem"
Expand Down
25 changes: 0 additions & 25 deletions .github/workflows/build.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Full check
on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: carlosperate/arm-none-eabi-gcc-action@v1
- name: Install dependencies
run: bash ./setup.sh <<< y
- name: Build app
run: just check
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install just
uses: extractions/setup-just@v3
- name: Build app
run: just build
run: just build-epsilon
- run: mv target/thumbv7em-none-eabihf/release/Numcraft target/thumbv7em-none-eabihf/release/Numcraft.nwa
- uses: actions/upload-artifact@v4
with:
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
/node_modules
.DS_store
/epsilon_simulator
/.vscode
/.vscode
.venv
*.elf
*.icon
/icon.png
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ name = "Numcraft"
version = "0.1.5"
authors = ["Yannis300307"]
edition = "2024"
build="build/build.rs"

[[bin]]
name = "Numcraft"
Expand All @@ -21,8 +22,10 @@ doctest = false
bench = false

[features]

default = ["upsilon"]
debug_ui = []
upsilon = []
epsilon = []

[profile.dev]
panic="abort"
Expand Down
21 changes: 21 additions & 0 deletions build/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Damien Nicolet

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.
51 changes: 51 additions & 0 deletions build/archive
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

# MIT License

# Copyright (c) 2025 Damien Nicolet

# 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.

set -e

LD=arm-none-eabi-ld
OBJCOPY=arm-none-eabi-objcopy

echo "Building archive..."
echo " - ld: $LD"
echo " - objcopy: $OBJCOPY"
echo " - arguments: $@"

OUTPUT="$1"
rm -f "target/${OUTPUT}"
shift 1

POS=0

FILENAME="target/thumbv7em-none-eabihf/release/$1"
NAME="$1"
echo " - $FILENAME"
sed "s/\+ (0)/+ (${POS})/" build/external.ld > target/temp.ld
"${LD}" "$FILENAME" -o "target/${NAME}_linked.elf" -Ttarget/temp.ld
"${OBJCOPY}" -O binary "target/${NAME}_linked.elf" "target/${NAME}"
cd target
tar -rf "${OUTPUT}" "${NAME}"
cd ..
POS=$(( ${POS} + (($(stat --printf="%s" "target/${NAME}") + 1023)/512)*512 ))
rm -f target/temp.ld "target/${NAME}" "target/${NAME}_linked.elf"
13 changes: 11 additions & 2 deletions build.rs → build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn compile_c_libs() {
.expect("Invalid UTF-8 in nwlink flags");

let mut build = cc::Build::new();
build.file("src/eadk/storage/storage.c");
build.file("src/nadk/storage/storage.c");
build.flag("-std=c99");
build.flag("-Os");
build.flag("-Wall");
Expand Down Expand Up @@ -278,7 +278,16 @@ fn main() {

// Compile storage.c
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "none" {
compile_c_libs();
println!("cargo:rustc-link-arg=--relocatable");
println!("cargo:rustc-link-arg=-no-gc-sections");

if std::env::var("CARGO_FEATURE_UPSILON").is_ok() {
println!("cargo:rustc-link-arg=-Ltarget/upsilon_api");
println!("cargo:rustc-link-arg=-lapi");
} else {
compile_c_libs();
println!("cargo:rustc-link-arg=-lstorage_c");
}
} else {
patch_simulator();
}
Expand Down
53 changes: 53 additions & 0 deletions build/external.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
MEMORY {
SRAM (rw) : ORIGIN = 0x00000000, LENGTH = 16K
FLASH (rx) : ORIGIN = 0x90200200 + (0), LENGTH = 6M
}

SECTIONS {
.entrypoint ORIGIN(FLASH) : {
KEEP(*(.entrypoint))
} >FLASH

.init_array : {
. = ALIGN(4);
_init_array_start = .;
KEEP (*(.init_array*))
_init_array_end = .;
} >FLASH

.text : {
. = ALIGN(4);
*(.text)
*(.text.*)
} >FLASH

.rodata : {
. = ALIGN(4);
*(.rodata)
*(.rodata.*)
} >FLASH

.ARM.exidx : {
__exidx_start = .;
/* *(.ARM.exidx* .gnu.linkonce.armexidx.*) */
__exidx_end = .;
} >FLASH

.data : {
. = ALIGN(4);
_data_section_start_flash = LOADADDR(.data);
_data_section_start_ram = .;
*(.data)
*(.data.*)
_data_section_end_ram = .;
} >SRAM AT> FLASH

.bss : {
. = ALIGN(4);
_bss_section_start_ram = .;
*(.bss)
*(.bss.*)
*(COMMON)
_bss_section_end_ram = .;
} >SRAM
}
68 changes: 68 additions & 0 deletions build/png2icon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3

import sys
import argparse
import struct

def error_exit(message, code):
print(message, file=sys.stderr)
sys.exit(code)

try:
import png
except ImportError:
error_exit("You need pypng to run this script.\n Use `pip3 install pypng`", 1)

try:
import lz4.block
except ImportError:
error_exit("You need lz4 to run this script.\n Use `pip3 install lz4`", 1)


def main():
# Parse args.
parser = argparse.ArgumentParser()
parser.add_argument("input")
parser.add_argument("output")
args = parser.parse_args()

with open(args.input, 'rb') as input_file:
r = png.Reader(file=input_file)

width, height, rows, infos = r.asRGBA8()

if width != 55 or height != 56:
error_exit("Icon must be 55x56 !", 2)

output = bytearray(width * height * 2)
colors = list(rows)

for y in range(height):
for x in range(width):

red = colors[y][x * 4 + 0] / 255
green = colors[y][x * 4 + 1] / 255
blue = colors[y][x * 4 + 2] / 255
alpha = colors[y][x * 4 + 3] / 255

Bred = red * alpha + 1 * (1 - alpha)
Bgreen = green * alpha + 1 * (1 - alpha)
Bblue = blue * alpha + 1 * (1 - alpha)

Ired = int(Bred * 0xFF)
Igreen = int(Bgreen * 0xFF)
Iblue = int(Bblue * 0xFF)

rgb565value = (Ired >> 3) << 11 | (Igreen >> 2) << 5 | (Iblue >> 3)

i = (y * width + x) * 2
struct.pack_into("<H", output, i, rgb565value)

compressed = lz4.block.compress(output, mode="high_compression", store_size=False, return_bytearray=True)

with open(args.output, 'wb') as output_file:
output_file.write(compressed)

if __name__ == "__main__":
main()

21 changes: 21 additions & 0 deletions build/upsilon-api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy
AR=arm-none-eabi-ar
CFLAGS=-Os -mcpu=cortex-m7 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard -fno-common -fdata-sections -ffunction-sections -fno-exceptions

BUILD_DIR=target/upsilon_api
SRCS_DIR=build/upsilon-api
SRCS=$(SRCS_DIR)/extapp_api.c $(SRCS_DIR)/extapp_startup.c
OBJS=$(SRCS:$(SRCS_DIR)/%.c=$(BUILD_DIR)/%.o)
NAME=target/upsilon_api/libapi.a


$(NAME): $(OBJS)
$(AR) rcs $@ $^

$(OBJS): $(BUILD_DIR)/%.o: $(SRCS_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@

all: $(NAME)

.PHONY: all
Loading