No description
Find a file
2023-09-18 16:24:18 +02:00
.cargo added new demo for progmem and implemented new features for the usage of progmem. 2023-08-07 18:17:52 +02:00
arduboy-rust fixed ArdVoice import 2023-09-13 12:38:22 +02:00
docs updated docs 2023-09-12 22:20:06 +02:00
Examples added get_ardvoice macro to the crate 2023-09-12 19:20:12 +02:00
Project/game reset the game lib 2023-09-18 16:24:18 +02:00
.gitignore adding drboy 2023-08-19 18:21:14 +02:00
arduboy.json first commit 2023-08-06 18:14:49 +02:00
Cargo.lock added ArdVoice example and cleanup the project game 2023-09-12 19:06:18 +02:00
Cargo.toml added ArdVoice example and cleanup the project game 2023-09-12 19:06:18 +02:00
import_config.h added docs and change the lib structure 2023-09-12 22:01:54 +02:00
LICENSE-APACHE first commit 2023-08-06 18:14:49 +02:00
LICENSE-MIT first commit 2023-08-06 18:14:49 +02:00
README.md added support to create new projects 2023-09-11 09:24:37 +02:00
run added ArdVoice example and cleanup the project game 2023-09-12 19:06:18 +02:00
run.bat added ArdVoice example and cleanup the project game 2023-09-12 19:06:18 +02:00
rust-toolchain.toml first commit 2023-08-06 18:14:49 +02:00
rustfmt.toml first commit 2023-08-06 18:14:49 +02:00

Rust for Arduboy

Running Rust on the Arduboy miniature game system.

The most important first. I didn't create this project from scratch, @Seeker14491 the legend has already done a lot in his old project ArduboyRust

I just updated and completed the project.

What do i mean by completed?

I provided all the important functions from the Arduboy2 library in a safe Rust API.

Most of the Arduboy2 funktions can be called the same way like in C.

How to use this Project

First clone the repo

git clone https://github.com/ZennDev1337/Rust-for-Arduboy

Install PlatformIO Core on your system. I recommend the pip install if you don't want to configure a new path variable for pio. Otherwise you will know how to do that.

The rust-analyzer will complain about a missing test crate to fix this add the following rule to the lsp settings :

{
    "rust-analyzer.checkOnSave.allTargets": false
}

If your using Visual Studio Code: Create a folder named .vscode and a file named settings.json inside. Past the setting above in the new file. (I have excluded my .vscode folder because I have many different settings there that you don't need)

Your game is located in the Project/game folder. This is also the folder you are working in

Inside the game folder you will find a lib.rs file which contains the setup and loop function as you know it from a normal Arduboy C project.

You can find the Docs here:

or you can use the following command to open the arduboy-rust Crate docs locally

cargo doc -p arduboy-rust --open

Most of the time you will use the prelude. There is listed witch funktionality you will have.

And last but not least there are multiple examples inside of the Examples folder which shows you how to use the functions. I will from time to time also upload my projects to the Example folder so you have as much ressurces as possible.

Usage of the run tool

Both run scripts (only works if you use the given folder structure)

requirements:

  • PlatformIO Core must be installed
  • The Arduboy must be plugged in
  • You are in the root directory of this project

All builded .hex files are saved inside of arduboy-rust/Wrapper-Project/build/<GAMENAME>.hex after you uploaded them to the Arduboy.

To upload your own game to the Arduboy use:

Linux:

./run

Windows:

.\run.bat

Play ZennDev1337 Games

Dr. Boy

To upload snake to the Arduboy use:

Linux:

./run drboy

Windows:

.\run.bat drboy

Snake

To upload snake to the Arduboy use:

Linux:

./run snake

Windows:

.\run.bat snake

Play Rust Games

I'm now a Rustacean <3

To upload rustacean to the Arduboy use:

Linux:

./run rustacean

Windows:

.\run.bat rustacean

Play Demo Games

The demo games / tutorials from the official Arduboy forum [Rewritten in Rust]

To upload a demo to the Arduboy use:

Linux:

./run demo2
./run demo3
./run demo4
./run demo5
./run demo6
./run demo7
./run eeprom
./run eeprom-byte
./run progmem
./run tone

Windows:

.\run.bat demo2
.\run.bat demo3
.\run.bat demo4
.\run.bat demo5
.\run.bat demo6
.\run.bat demo7
.\run.bat eeprom
.\run.bat eeprom-byte
.\run.bat progmem
.\run.bat tone

Create a new project

In the root of the repo use the command:

(Don't use "-" in the name because of a cargo feature that takes the "-" and mixes sometimes with a "_". You will have some weird behavior with the run tool.)

cargo new --lib ./Project/newproject

Then open the Cargo.toml in your new project and add the following dependencies and settings:

[lib]
crate-type = ["staticlib"]

[dependencies]

arduboy-rust = { path = "../../arduboy-rust" }

Next jump in your lib.rs file and add the following:

#![no_std]
#![allow(non_upper_case_globals)]

//Include the Arduboy Library
#[allow(unused_imports)]
use arduboy_rust::prelude::*;
#[allow(dead_code)]
const arduboy: Arduboy2 = Arduboy2::new();

// Progmem data

// dynamic ram variables

// The setup() function runs once when you turn your Arduboy on
#[no_mangle]
pub unsafe extern "C" fn setup() {
    // put your setup code here, to run once:
}

// The loop() function repeats forever after setup() is done
#[no_mangle]
#[export_name = "loop"]
pub unsafe extern "C" fn loop_() {
    // put your main code here, to run repeatedly:
}

Now the last step. Go in the Cargo.toml in the root directory and add your project:

[workspace]
members = [
    {All other Projects...}
    "Project/newproject",
]
resolver = "2"

To run and upload your game use the run tool

# Linux
./run newproject
# Windows
.\run.bat newproject

Creating and building an Arduboy crate [Outdated]

You can find instructions on how all build steps work in detail here ArduboyRust creating and building an arduboy crate

Linking the static library to the Arduino C++ project [Outdated]

Instructions on how to link all the static libraries in the Arduino C++ project can be found here ArduboyRust linking the static library to the arduino c++ project

Credits

Thanks to @Seeker14491 who wrote ArduboyRust, the starting point for me to create my own project based on this project. (you are a hero <3)

Thanks to @simon-i1-h who wrote arduboy-hello-rs, the proof of concept that inspired me to try Rust on the Arduboy.

License

You can license it under either one of those licenses:

Whichever you may prefer.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.