rustkey 0.5.0

rusTkey — rust library for tillitis TKey application development
Documentation
// rusTkey, a rust crate/library that provides a development API for the tillitis TKey.
// Copyright (C) 2024  Danny van Heumen
// SPDX-License-Identifier: BSD-2-Clause

#![no_std]
#![no_main]
#![deny(unused_must_use)]
#![warn(clippy::pedantic)]

use core::{arch::global_asm, panic::PanicInfo};

use rustkey::{led, sleep};

#[no_mangle]
extern "C" fn main() -> ! {
    loop {
        rustkey::led::set(led::LED_RED);
        sleep(400_000);
        rustkey::led::set(led::LED_GREEN);
        sleep(400_000);
    }
    // Note: if main returns, behavior seems to be undefined, even varying with optimization levels.
}

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    rustkey::abort()
}

// Note: this assembly provides the initialization procedure that clears memory and finally calls
// `main` to start execution of the app-binary.
global_asm!(
    ".section \".text.init\"",
    ".global _start",
    "_start:",
    "li x1, 0",
    "li x2, 0",
    "li x3, 0",
    "li x4, 0",
    "li x5, 0",
    "li x6, 0",
    "li x7, 0",
    "li x8, 0",
    "li x9, 0",
    "li x10,0",
    "li x11,0",
    "li x12,0",
    "li x13,0",
    "li x14,0",
    "li x15,0",
    "li x16,0",
    "li x17,0",
    "li x18,0",
    "li x19,0",
    "li x20,0",
    "li x21,0",
    "li x22,0",
    "li x23,0",
    "li x24,0",
    "li x25,0",
    "li x26,0",
    "li x27,0",
    "li x28,0",
    "li x29,0",
    "li x30,0",
    "li x31,0",
    /* init stack below 0x40020000 (TK1_RAM_BASE+TK1_RAM_SIZE) */
    "la sp, _stack_start",
    /* zero-init bss section */
    "la a0, _sbss",
    "la a1, _ebss",
    "bge a0, a1, end_init_bss",
    "loop_init_bss:",
    "sw zero, 0(a0)",
    "addi a0, a0, 4",
    "blt a0, a1, loop_init_bss",
    "end_init_bss:",
    "call main",
    options(raw)
);