Big refactor and new run script

This commit is contained in:
ZennDev1337 2023-10-11 14:55:18 +02:00
parent 5796b78695
commit a54fa90edc
68 changed files with 769 additions and 336 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ localcommands.txt
arduboy-rust/Wrapper-Project/.pio
arduboy-rust/Wrapper-Project/lib/*.a
arduboy-rust/Wrapper-Project/build/*.hex
**/imports.h

View file

@ -9,7 +9,6 @@
<sourceFolder url="file://$MODULE_DIR$/Examples/Arduboy-Tutorials/demo6/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Examples/Arduboy-Tutorials/demo7/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Examples/Arduboy-Tutorials/demo9/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Examples/Arduboy-Tutorials/eeprom-byte/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Examples/Arduboy-Tutorials/eeprom/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Examples/Arduboy-Tutorials/progmem/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Examples/Arduboy-Tutorials/serial/src" isTestSource="false" />
@ -26,6 +25,7 @@
<sourceFolder url="file://$MODULE_DIR$/Examples/ArduboyFX/fxdrawframes/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Examples/ArduboyFX/fxhelloworld/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Examples/ArduboyFX/fxloadgamestate/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Examples/Arduboy-Tutorials/eeprom_byte/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />

2
Cargo.lock generated
View file

@ -108,7 +108,7 @@ dependencies = [
]
[[package]]
name = "eeprom-byte"
name = "eeprom_byte"
version = "0.1.0"
dependencies = [
"arduboy-rust",

View file

@ -1,8 +1,9 @@
[workspace]
members = [
"arduboy-rust",
"Examples/Arduboy-Tutorials/eeprom",
"Examples/Arduboy-Tutorials/eeprom-byte",
"Examples/Arduboy-Tutorials/eeprom_byte",
"Examples/Arduboy-Tutorials/progmem",
"Examples/Arduboy-Tutorials/tone",
"Examples/Arduboy-Tutorials/serial",

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -5,22 +5,19 @@
#[allow(unused_imports)]
use arduboy_rust::prelude::*;
const arduboy: Arduboy2 = Arduboy2::new();
#[link_section = ".progmem.data"]
static background_sprite: [u8; 10] = [8, 8, 0x81, 0x00, 0x12, 0x40, 0x04, 0x11, 0x00, 0x04];
#[link_section = ".progmem.data"]
static player_sprite1: [u8; 34] = [
16, 16, 0xfe, 0x01, 0x3d, 0x25, 0x25, 0x3d, 0x01, 0x01, 0xc1, 0x01, 0x3d, 0x25, 0x25, 0x3d,
0x01, 0xfe, 0x7f, 0x80, 0x9c, 0xbc, 0xb0, 0xb0, 0xb2, 0xb2, 0xb3, 0xb0, 0xb0, 0xb0, 0xbc, 0x9c,
0x80, 0x7f,
];
#[link_section = ".progmem.data"]
static player_sprite2: [u8; 34] = [
16, 16, 0xfc, 0x02, 0x19, 0x25, 0x25, 0x19, 0x01, 0x01, 0x01, 0x01, 0x19, 0x25, 0x25, 0x19,
0x02, 0xfc, 0x3f, 0x40, 0x80, 0x98, 0x8c, 0x86, 0x82, 0x82, 0x82, 0x82, 0x86, 0x8c, 0x98, 0x80,
0x40, 0x3f,
];
progmem!(
static background_sprite: [u8; _] = [8, 8, 0x81, 0x00, 0x12, 0x40, 0x04, 0x11, 0x00, 0x04];
static player_sprite1: [u8; _] = [
16, 16, 0xfe, 0x01, 0x3d, 0x25, 0x25, 0x3d, 0x01, 0x01, 0xc1, 0x01, 0x3d, 0x25, 0x25, 0x3d,
0x01, 0xfe, 0x7f, 0x80, 0x9c, 0xbc, 0xb0, 0xb0, 0xb2, 0xb2, 0xb3, 0xb0, 0xb0, 0xb0, 0xbc,
0x9c, 0x80, 0x7f,
];
static player_sprite2: [u8; _] = [
16, 16, 0xfc, 0x02, 0x19, 0x25, 0x25, 0x19, 0x01, 0x01, 0x01, 0x01, 0x19, 0x25, 0x25, 0x19,
0x02, 0xfc, 0x3f, 0x40, 0x80, 0x98, 0x8c, 0x86, 0x82, 0x82, 0x82, 0x82, 0x86, 0x8c, 0x98,
0x80, 0x40, 0x3f,
];
);
// Put your variables here
static mut playerx: c_int = 5;
static mut playery: c_int = 10;

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -24,7 +24,7 @@ static mut s: Scorebord = Scorebord {
pub unsafe extern "C" fn setup() {
// put your setup code here, to run once:
arduboy.begin();
arduboy.set_frame_rate(1);
arduboy.set_frame_rate(30);
arduboy.clear();
e.init(&mut s);
}
@ -54,11 +54,9 @@ pub unsafe extern "C" fn loop_() {
if s.player1 == 5 {
arduboy.print(f!(b"lolxd\0"));
s.text = "it works!!!\0";
e.put(&s)
} else {
arduboy.print(f!(b"nope\0"));
s.text = "lol\0";
e.put(&s)
}
//e.get(&mut s);

View file

@ -1,5 +1,5 @@
[package]
name = "eeprom-byte"
name = "eeprom_byte"
version = "0.1.0"
authors = ["ZennDev <zenndev@protonmail.com>"]
license = "MIT OR Apache-2.0"

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -11,7 +11,8 @@ const arduboy: Arduboy2 = Arduboy2::new();
// Setup eeprom memory
static mut eeprom: EEPROMBYTE = EEPROMBYTE::new(10);
static mut count: u8 = 0;
static mut count_in_ram: u8 = 0;
static mut count_in_eeprom: u8 = 0;
// The setup() function runs once when you turn your Arduboy on
#[no_mangle]
@ -33,24 +34,23 @@ pub unsafe extern "C" fn loop_() {
arduboy.clear();
arduboy.poll_buttons();
if arduboy.just_pressed(UP) {
count += 1;
count_in_ram += 1;
}
if arduboy.just_pressed(DOWN) {
count -= 1;
count_in_ram -= 1;
}
if arduboy.just_pressed(A) {
eeprom.update(count)
eeprom.update(count_in_ram);
count_in_eeprom = eeprom.read()
}
arduboy.set_cursor(0, 0);
arduboy.print(count as u16);
arduboy.set_cursor(0, 30);
arduboy.print(f!(b"Counter:\0"));
arduboy.print(count as u16);
arduboy.set_cursor(0, 40);
arduboy.print(f!(b"eeprom:\0"));
//arduboy.print(eeprom.read() as u16);
arduboy.print(f!(b"Up/Down: Edit InRam\n\nA: Save to EEPROM\0"));
arduboy.set_cursor(0, HEIGHT - FONT_HEIGHT);
arduboy.print(f!(b"InRam:\0"));
arduboy.print(count_in_ram as u16);
arduboy.set_cursor(10 * FONT_WIDTH, HEIGHT - FONT_HEIGHT);
arduboy.print(f!(b"EEPROM:\0"));
arduboy.print(count_in_eeprom as u16);
arduboy.display();
}

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -5,7 +5,7 @@
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
use arduboy_tones::tones_pitch::*;
use tones_pitch::*;
const arduboy: Arduboy2 = Arduboy2::new();
const sound: ArduboyTones = ArduboyTones::new();
// Progmem data
@ -106,7 +106,10 @@ pub unsafe extern "C" fn loop_() {
}
}
arduboy.clear();
arduboy.set_cursor((WIDTH as i16 / 2) - (text1.len() as i16 * FONT_SIZE as i16 / 2), 10);
arduboy.set_cursor(
(WIDTH as i16 / 2) - (text1.len() as i16 * FONT_WIDTH / 2),
10,
);
arduboy.print(get_string_addr!(text1));
sprites::draw_override(playerx, playery, get_sprite_addr!(player_sprite1), 0);
arduboy.display();

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
"Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
"ArduboyTones",
# "ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -4,7 +4,7 @@
//Initialize the arduboy object
#[allow(unused_imports)]
use arduboy_rust::prelude::*;
use arduboy_tones::tones_pitch::*;
use tones_pitch::*;
const arduboy: Arduboy2 = Arduboy2::new();
const sound: ArduboyTones = ArduboyTones::new();
const NDUR: u16 = 100;
@ -346,7 +346,9 @@ pub unsafe extern "C" fn loop_() {
sound.tone(1000, 0);
arduboy.clear();
arduboy.print(f!(b"tone(1000)\n\nB: no_tone()\n delay(1000)\n break\0"));
arduboy.print(f!(
b"tone(1000)\n\nB: no_tone()\n delay(1000)\n break\0"
));
while sound.playing() {
move_circle();
if arduboy.pressed(B_BUTTON) {
@ -381,7 +383,9 @@ pub unsafe extern "C" fn loop_() {
sound.tone3(NOTE_C7H, 500, NOTE_REST, 1000, NOTE_C6, 5000);
arduboy.clear();
arduboy.print(f!(b"tone(C7H,500,\n REST,1000,\n C6,6000)\n\nB: no_tone(), break\0"));
arduboy.print(f!(
b"tone(C7H,500,\n REST,1000,\n C6,6000)\n\nB: no_tone(), break\0"
));
while sound.playing() {
move_circle();
if arduboy.pressed(B_BUTTON) {
@ -393,7 +397,9 @@ pub unsafe extern "C" fn loop_() {
sound.tones(get_tones_addr!(allNotes));
arduboy.clear();
arduboy.print(f!(b"tones(allNotes)\n\nA: no_tone(), again\nUP: again\nB: break\0"));
arduboy.print(f!(
b"tones(allNotes)\n\nA: no_tone(), again\nUP: again\nB: break\0"
));
while sound.playing() {
move_circle();
if arduboy.pressed(A_BUTTON) {
@ -446,7 +452,9 @@ pub unsafe extern "C" fn loop_() {
sound.volume_mode(VOLUME_ALWAYS_NORMAL);
sound.tones(get_tones_addr!(sound1));
arduboy.clear();
arduboy.print(f!(b"volume_mode(NORMAL)\ntones(sound1)\n\nB: no_tone(), break\0"));
arduboy.print(f!(
b"volume_mode(NORMAL)\ntones(sound1)\n\nB: no_tone(), break\0"
));
while sound.playing() {
move_circle();
if arduboy.pressed(B) {

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
"ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
"ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -4,7 +4,7 @@
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
use arduboyfx::fx_consts::*;
use fx_consts::*;
const arduboy: Arduboy2 = Arduboy2::new();
// FX Data

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
"ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -1,10 +1,11 @@
#![no_std]
#![allow(non_upper_case_globals)]
use arduboy_rust::arduboyfx::fx_consts::{dbmMasked, dbmNormal};
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
use fx_consts::{dbmMasked, dbmNormal};
const arduboy: Arduboy2 = Arduboy2::new();
// FX Data

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
"ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
"ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -4,7 +4,7 @@
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
use arduboyfx::fx_consts::*;
use fx_consts::*;
const arduboy: Arduboy2 = Arduboy2::new();
//FX Data

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
"ArduboyFX",
# "ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
# "ArduboyTones",
# "ArduboyFX",
"ArdVoice",
# "Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
"ArduboyTones",
#"ArduboyFX",
#"ArdVoice",
#"Serial",
"EEPROM",
"Arduino",
]

View file

@ -4,7 +4,7 @@
//Include the Arduboy Library
#[allow(unused_imports)]
use arduboy_rust::prelude::*;
use arduboy_tones::tones_pitch::*;
use tones_pitch::*;
mod gameloop;
#[allow(dead_code)]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
"ArduboyTones",
#"ArduboyFX",
#"ArdVoice",
#"Serial",
"EEPROM",
"Arduino",
]

View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
"ArduboyTones",
#"ArduboyFX",
#"ArdVoice",
#"Serial",
"EEPROM",
"Arduino",
]

View file

@ -257,11 +257,8 @@ pub unsafe extern "C" fn loop_() {
State::Win => (),
State::Pause => {
let msg = "[ Break ]\0";
let l = msg.len() as u8 * FONT_SIZE / 2;
arduboy.set_cursor(
((WIDTH / 2) as u16 - l as u16).try_into().unwrap(),
((HEIGHT / 2) as u16).try_into().unwrap(),
);
let l = msg.len() as i16 * FONT_WIDTH / 2;
arduboy.set_cursor(WIDTH / 2 - l, HEIGHT / 2);
snake.render();
snake.boarder();
arduboy.print(msg);

9
Project/game/config.toml Normal file
View file

@ -0,0 +1,9 @@
Libraries = [
"Arduboy2",
"ArduboyTones",
#"ArduboyFX",
#"ArdVoice",
#"Serial",
"EEPROM",
"Arduino",
]

View file

@ -32,7 +32,7 @@ add the following rule to the lsp settings :
```json
{
"rust-analyzer.checkOnSave.allTargets": false
"rust-analyzer.checkOnSave.allTargets": false
}
```
@ -47,7 +47,7 @@ normal Arduboy C project.
You can find the Docs here:
- [arduboy-rust Crate Docs](https://zenndev1337.github.io/Rust-for-Arduboy/)
- [arduboy-rust Crate Docs](https://zenndev1337.github.io/Rust-for-Arduboy/)
or you can use the following command to open the arduboy-rust Crate docs locally
@ -68,9 +68,10 @@ I will from time to time also upload my projects to the Example folder so you ha
requirements:
- [PlatformIO Core](https://docs.platformio.org/en/latest/core/installation/methods/pypi.html) must be installed
- The Arduboy must be plugged in
- You are in the root directory of this project
- Python3.11 or higher
- [PlatformIO Core](https://docs.platformio.org/en/latest/core/installation/methods/pypi.html) 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.
@ -93,30 +94,30 @@ Windows:
### ZennDev1337 Games
- drboy
- drboy
### Rust Games
- snake
- rustacean
- snake
- rustacean
### The demo games / tutorials from the official Arduboy forum [Rewritten in Rust]
- [Make Your Own Arduboy Game: Part 1 - Setting Up Your Computer](https://community.arduboy.com/t/make-your-own-arduboy-game-part-1-setting-up-your-computer/7924/1)
- [demo2] [Make Your Own Arduboy Game: Part 2 - Printing Text](https://community.arduboy.com/t/make-your-own-arduboy-game-part-2-printing-text/7925)
- [demo3] [Make Your Own Arduboy Game: Part 3 - Storing Data & Loops](https://community.arduboy.com/t/make-your-own-arduboy-game-part-3-storing-data-loops/7926)
- [demo4] [Make Your Own Arduboy Game: Part 4 - Questions & Button Input](https://community.arduboy.com/t/make-your-own-arduboy-game-part-4-questions-button-input/7927)
- [demo5] [Make Your Own Arduboy Game: Part 5 - Your First Game!](https://community.arduboy.com/t/make-your-own-arduboy-game-part-5-your-first-game/7928)
- [demo6] [Make Your Own Arduboy Game: Part 6 - Graphics!](https://community.arduboy.com/t/make-your-own-arduboy-game-part-6-graphics/7929)
Link for the [ZennDev1337 Tile Converter](https://zenndev1337.github.io/Rust-for-Arduboy/tile-converter.html)
- [demo7] [Make Your Own Arduboy Game: Part 7 - Make Pong From Scratch!](https://community.arduboy.com/t/make-your-own-arduboy-game-part-7-make-pong-from-scratch/7930)
- Prepare for
demo9 [Make Your Own Arduboy Game: Part 8 - Starting DinoSmasher](https://community.arduboy.com/t/make-your-own-arduboy-game-part-8-starting-dinosmasher/7932)
- [demo9] [Make Your Own Arduboy Game: Part 9 - Mapping DinoSmasher](https://community.arduboy.com/t/make-your-own-arduboy-game-part-9-mapping-dinosmasher/7931)
- [eeprom] [Help, Im struggling with EEPROM!](https://community.arduboy.com/t/help-im-struggling-with-eeprom/7178)
- [eeprom-byte] [Help, Im struggling with EEPROM!](https://community.arduboy.com/t/help-im-struggling-with-eeprom/7178)
- [progmem] Usage of the big 28'000 Bytes flash memory for Bitmaps Sound sequeces and Text.
- [tone] [ArduboyTonesTest](https://github.com/MLXXXp/ArduboyTones/blob/master/examples/ArduboyTonesTest/ArduboyTonesTest.ino)
- [Make Your Own Arduboy Game: Part 1 - Setting Up Your Computer](https://community.arduboy.com/t/make-your-own-arduboy-game-part-1-setting-up-your-computer/7924/1)
- [demo2] [Make Your Own Arduboy Game: Part 2 - Printing Text](https://community.arduboy.com/t/make-your-own-arduboy-game-part-2-printing-text/7925)
- [demo3] [Make Your Own Arduboy Game: Part 3 - Storing Data & Loops](https://community.arduboy.com/t/make-your-own-arduboy-game-part-3-storing-data-loops/7926)
- [demo4] [Make Your Own Arduboy Game: Part 4 - Questions & Button Input](https://community.arduboy.com/t/make-your-own-arduboy-game-part-4-questions-button-input/7927)
- [demo5] [Make Your Own Arduboy Game: Part 5 - Your First Game!](https://community.arduboy.com/t/make-your-own-arduboy-game-part-5-your-first-game/7928)
- [demo6] [Make Your Own Arduboy Game: Part 6 - Graphics!](https://community.arduboy.com/t/make-your-own-arduboy-game-part-6-graphics/7929)
Link for the [ZennDev1337 Tile Converter](https://zenndev1337.github.io/Rust-for-Arduboy/tile-converter.html)
- [demo7] [Make Your Own Arduboy Game: Part 7 - Make Pong From Scratch!](https://community.arduboy.com/t/make-your-own-arduboy-game-part-7-make-pong-from-scratch/7930)
- Prepare for
demo9 [Make Your Own Arduboy Game: Part 8 - Starting DinoSmasher](https://community.arduboy.com/t/make-your-own-arduboy-game-part-8-starting-dinosmasher/7932)
- [demo9] [Make Your Own Arduboy Game: Part 9 - Mapping DinoSmasher](https://community.arduboy.com/t/make-your-own-arduboy-game-part-9-mapping-dinosmasher/7931)
- [eeprom] [Help, Im struggling with EEPROM!](https://community.arduboy.com/t/help-im-struggling-with-eeprom/7178)
- [eeprom-byte] [Help, Im struggling with EEPROM!](https://community.arduboy.com/t/help-im-struggling-with-eeprom/7178)
- [progmem] Usage of the big 28'000 Bytes flash memory for Bitmaps Sound sequeces and Text.
- [tone] [ArduboyTonesTest](https://github.com/MLXXXp/ArduboyTones/blob/master/examples/ArduboyTonesTest/ArduboyTonesTest.ino)
## Usage of the FX Chip
@ -146,13 +147,13 @@ See the examples in `Examples/ArduboyFX`.
More information:
- [Arduboy-Python-Utilities by MrBlinky](https://github.com/MrBlinky/Arduboy-Python-Utilities)
- [Arduboy-Python-Utilities by MrBlinky](https://github.com/MrBlinky/Arduboy-Python-Utilities)
run Commands:
- `fxbuild` is used to build the fxdata.dat file.
- `fxupload` is used to upload the fxdata.dat file.
- `fxall` is used to build and upload the fxdata.dat file and build and upload the game all in one step.
- `fxbuild` is used to build the fxdata.dat file.
- `fxupload` is used to upload the fxdata.dat file.
- `fxall` is used to build and upload the fxdata.dat file and build and upload the game all in one step.
Linux:
@ -272,10 +273,10 @@ that inspired me to try Rust on the Arduboy.
You can license it under either one of those licenses:
- Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
Whichever you may prefer.

View file

@ -1,6 +1,6 @@
#pragma once
#include "../../../import_config.h"
#include "imports.h"
#if defined(Arduboy2_Library)
#include <Arduboy2.h>

View file

@ -47,18 +47,18 @@ pub struct ButtonSet {
impl ButtonSet {
pub unsafe fn pressed(&self) -> bool {
crate::library::arduboy2::pressed(self.flag_set)
crate::libraries::arduboy2_library::binding::pressed(self.flag_set)
}
pub unsafe fn just_pressed(&self) -> bool {
crate::library::arduboy2::just_pressed(self.flag_set)
crate::libraries::arduboy2_library::binding::just_pressed(self.flag_set)
}
pub unsafe fn just_released(&self) -> bool {
crate::library::arduboy2::just_released(self.flag_set)
crate::libraries::arduboy2_library::binding::just_released(self.flag_set)
}
pub unsafe fn not_pressed(&self) -> bool {
crate::library::arduboy2::not_pressed(self.flag_set)
crate::libraries::arduboy2_library::binding::not_pressed(self.flag_set)
}
}

View file

@ -27,15 +27,11 @@
extern crate panic_halt;
pub mod hardware;
mod library;
mod libraries;
pub mod prelude;
mod print;
#[doc(inline)]
pub extern crate heapless;
pub use crate::library::arduboy2::{self, Arduboy2, Color, FONT_SIZE, HEIGHT, WIDTH};
pub use crate::library::arduboy_tones::{self, ArduboyTones};
pub use crate::library::ardvoice::{self, ArdVoice};
pub use crate::library::eeprom::{EEPROM, EEPROMBYTE};
pub use crate::library::{arduino, c, sprites};
pub use crate::library::arduboyfx::{self};
pub mod serial_print;
pub use crate::libraries::{
arduboy2_library, arduboy_tones_library, arduboyfx_library, arduino_system, ardvoice_library,
};

View file

@ -3,16 +3,17 @@
//! All of the functions are safe wrapped inside the [Arduboy2] struct.
#![allow(dead_code)]
use super::binding::*;
use super::print::Printable;
use crate::hardware::buttons::ButtonSet;
use crate::print::Printable;
use core::ffi::{c_char, c_int, c_long, c_size_t, c_uchar, c_uint, c_ulong};
use core::mem;
use core::ops::Not;
/// The standard font size of the arduboy
///
/// this is to calculate with it.
pub const FONT_SIZE: u8 = 6;
pub const FONT_WIDTH: i16 = 6;
pub const FONT_HEIGHT: i16 = 8;
/// The standard width of the arduboy
///
/// this is to calculate with it.
@ -650,7 +651,7 @@ impl Arduboy2 {
///The returned mask contains a bit for each button. For any pressed button, its bit will be 1. For released buttons their associated bits will be 0.
///
///The following defined mask values should be used for the buttons:
/// LEFT_BUTTON, RIGHT_BUTTON, UP_BUTTON, DOWN_BUTTON, A_BUTTON, B_BUTTON
/// LEFT_BUTTON, RIGHT_BUTTON, UP_BUTTON, DOWN_BUTTON, A_BUTTON, B_BUTTON
pub fn buttons_state(&self) -> u8 {
unsafe { arduboy_buttons_state() }
}
@ -658,175 +659,9 @@ impl Arduboy2 {
///
///The sketch will exit and the bootloader will be started in command mode. The effect will be similar to pressing the reset button.
///
///This function is intended to be used to allow uploading a new sketch, when the USB code has been removed to gain more code space. Ideally, the sketch would present a "New Sketch Upload" menu or prompt telling the user to "Press and hold the DOWN button when the procedure to upload a new sketch has been initiated".
///This function is intended to be used to allow uploading a new sketch, when the USB code has been removed to gain more code space. Ideally, the sketch would present a "New Sketch Upload" menu or prompt telling the user to "Press and hold the DOWN button when the procedure to upload a new sketch has been initiated".
///The sketch would then wait for the DOWN button to be pressed and then call this function.
pub fn exit_to_bootloader(&self) {
unsafe { arduboy_exit_to_bootloader() }
}
}
extern "C" {
#[link_name = "arduboy_begin"]
fn begin();
#[link_name = "arduboy_clear"]
fn clear();
#[link_name = "arduboy_display"]
fn display();
#[link_name = "arduboy_display_and_clear_buffer"]
fn display_and_clear_buffer();
#[link_name = "arduboy_draw_fast_hline"]
fn draw_fast_hline_raw(x: i16, y: i16, w: u8, color: u8);
#[link_name = "arduboy_draw_fast_vline"]
fn draw_fast_vline_raw(x: i16, y: i16, h: u8, color: u8);
#[link_name = "arduboy_draw_pixel"]
fn draw_pixel_raw(x: i16, y: i16, color: u8);
#[link_name = "arduboy_draw_circle"]
fn draw_circle_raw(x: i16, y: i16, r: u8, color: u8);
#[link_name = "arduboy_draw_rect"]
fn draw_rect_raw(x: i16, y: i16, w: u8, h: u8, color: u8);
#[link_name = "arduboy_fill_circle"]
fn fill_circle_raw(x: i16, y: i16, r: u8, color: u8);
#[link_name = "arduboy_fill_rect"]
fn fill_rect_raw(x: i16, y: i16, w: u8, h: u8, color: u8);
#[link_name = "arduboy_fill_round_rect"]
fn fill_round_rect(x: i16, y: i16, w: u8, h: u8, r: u8, color: u8);
#[link_name = "arduboy_draw_round_rect"]
fn draw_round_rect(x: i16, y: i16, w: u8, h: u8, r: u8, color: u8);
#[link_name = "arduboy_fill_triangle"]
fn fill_triangle(x0: i16, y0: i16, x1: i16, y1: i16, x2: i16, y2: i16, color: u8);
#[link_name = "arduboy_draw_triangle"]
fn draw_triangle(x0: i16, y0: i16, x1: i16, y1: i16, x2: i16, y2: i16, color: u8);
#[link_name = "arduboy_get_pixel"]
fn get_pixel_raw(x: u8, y: u8) -> u8;
#[doc(hidden)]
#[link_name = "arduboy_init_random_seed"]
fn init_random_seed();
#[doc(hidden)]
#[link_name = "arduboy_just_pressed"]
pub fn just_pressed(button: u8) -> bool;
#[doc(hidden)]
#[link_name = "arduboy_just_released"]
pub fn just_released(button: u8) -> bool;
#[doc(hidden)]
#[link_name = "arduboy_not_pressed"]
pub fn not_pressed(button: u8) -> bool;
#[link_name = "arduboy_next_frame"]
fn next_frame() -> bool;
#[link_name = "arduboy_poll_buttons"]
fn poll_buttons();
#[doc(hidden)]
#[link_name = "arduboy_pressed"]
pub fn pressed(buttons: u8) -> bool;
#[doc(hidden)]
#[link_name = "arduboy_print_chars"]
pub fn print_chars(cstr: *const c_char);
#[doc(hidden)]
#[link_name = "arduboy_print_chars_progmem"]
pub fn print_chars_progmem(pstring: *const c_char);
// #[link_name = "arduboy_print_char"]
// fn print_char(c: c_char) -> c_size_t;
#[doc(hidden)]
#[link_name = "arduboy_print_int"]
pub fn print_int(n: c_int, base: c_int) -> c_size_t;
#[doc(hidden)]
#[link_name = "arduboy_print_long"]
pub fn print_long(n: c_long, base: c_int) -> c_size_t;
#[doc(hidden)]
#[link_name = "arduboy_print_unsigned_char"]
pub fn print_unsigned_char(n: c_uchar, base: c_int) -> c_size_t;
#[doc(hidden)]
#[link_name = "arduboy_print_unsigned_int"]
pub fn print_unsigned_int(n: c_uint, base: c_int) -> c_size_t;
#[doc(hidden)]
#[link_name = "arduboy_print_unsigned_long"]
pub fn print_unsigned_long(n: c_ulong, base: c_int) -> c_size_t;
#[link_name = "arduboy_set_cursor"]
fn set_cursor(x: i16, y: i16);
#[link_name = "arduboy_set_frame_rate"]
fn set_frame_rate(rate: u8);
#[link_name = "arduboy_set_text_size"]
fn set_text_size(size: u8);
#[link_name = "arduboy_audio_on"]
fn arduboy_audio_on();
#[link_name = "arduboy_audio_off"]
fn arduboy_audio_off();
#[link_name = "arduboy_audio_save_on_off"]
fn arduboy_audio_save_on_off();
#[link_name = "arduboy_audio_toggle"]
fn arduboy_audio_toggle();
#[link_name = "arduboy_audio_enabled"]
fn arduboy_audio_enabled() -> bool;
#[link_name = "arduboy_invert"]
fn arduboy_invert(inverse: bool);
#[link_name = "arduboy_every_x_frames"]
fn every_x_frames(frames: u8) -> bool;
#[link_name = "arduboy_flip_horizontal"]
fn flip_horizontal(flipped: bool);
#[link_name = "arduboy_flip_vertical"]
fn flip_vertical(flipped: bool);
#[link_name = "arduboy_set_text_color"]
fn set_text_color(color: u8);
#[link_name = "arduboy_set_text_background_color"]
fn set_text_background_color(color: u8);
#[link_name = "arduboy_set_cursor_x"]
fn set_cursor_x(x: i16);
#[link_name = "arduboy_set_cursor_y"]
fn set_cursor_y(y: i16);
#[link_name = "arduboy_set_text_wrap"]
fn set_text_wrap(w: bool);
#[link_name = "arduboy_idle"]
fn idle();
#[link_name = "arduboy_digital_write_rgb_single"]
fn digital_write_rgb_single(color: c_uchar, val: c_uchar);
#[link_name = "arduboy_digital_write_rgb"]
fn digital_write_rgb(red: c_uchar, green: c_uchar, blue: c_uchar);
#[link_name = "arduboy_set_rgb_led_single"]
fn set_rgb_led_single(color: c_uchar, val: c_uchar);
#[link_name = "arduboy_set_rgb_led"]
fn set_rgb_led(red: c_uchar, green: c_uchar, blue: c_uchar);
#[link_name = "arduboy_buttons_state"]
fn arduboy_buttons_state() -> u8;
#[link_name = "arduboy_exit_to_bootloader"]
fn arduboy_exit_to_bootloader();
}

View file

@ -0,0 +1,168 @@
use core::ffi::{c_char, c_int, c_long, c_size_t, c_uchar, c_uint, c_ulong};
extern "C" {
#[link_name = "arduboy_begin"]
pub fn begin();
#[link_name = "arduboy_clear"]
pub fn clear();
#[link_name = "arduboy_display"]
pub fn display();
#[link_name = "arduboy_display_and_clear_buffer"]
pub fn display_and_clear_buffer();
#[link_name = "arduboy_draw_fast_hline"]
pub fn draw_fast_hline_raw(x: i16, y: i16, w: u8, color: u8);
#[link_name = "arduboy_draw_fast_vline"]
pub fn draw_fast_vline_raw(x: i16, y: i16, h: u8, color: u8);
#[link_name = "arduboy_draw_pixel"]
pub fn draw_pixel_raw(x: i16, y: i16, color: u8);
#[link_name = "arduboy_draw_circle"]
pub fn draw_circle_raw(x: i16, y: i16, r: u8, color: u8);
#[link_name = "arduboy_draw_rect"]
pub fn draw_rect_raw(x: i16, y: i16, w: u8, h: u8, color: u8);
#[link_name = "arduboy_fill_circle"]
pub fn fill_circle_raw(x: i16, y: i16, r: u8, color: u8);
#[link_name = "arduboy_fill_rect"]
pub fn fill_rect_raw(x: i16, y: i16, w: u8, h: u8, color: u8);
#[link_name = "arduboy_fill_round_rect"]
pub fn fill_round_rect(x: i16, y: i16, w: u8, h: u8, r: u8, color: u8);
#[link_name = "arduboy_draw_round_rect"]
pub fn draw_round_rect(x: i16, y: i16, w: u8, h: u8, r: u8, color: u8);
#[link_name = "arduboy_fill_triangle"]
pub fn fill_triangle(x0: i16, y0: i16, x1: i16, y1: i16, x2: i16, y2: i16, color: u8);
#[link_name = "arduboy_draw_triangle"]
pub fn draw_triangle(x0: i16, y0: i16, x1: i16, y1: i16, x2: i16, y2: i16, color: u8);
#[link_name = "arduboy_get_pixel"]
pub fn get_pixel_raw(x: u8, y: u8) -> u8;
#[link_name = "arduboy_init_random_seed"]
pub fn init_random_seed();
#[link_name = "arduboy_just_pressed"]
pub fn just_pressed(button: u8) -> bool;
#[link_name = "arduboy_just_released"]
pub fn just_released(button: u8) -> bool;
#[link_name = "arduboy_not_pressed"]
pub fn not_pressed(button: u8) -> bool;
#[link_name = "arduboy_next_frame"]
pub fn next_frame() -> bool;
#[link_name = "arduboy_poll_buttons"]
pub fn poll_buttons();
#[link_name = "arduboy_pressed"]
pub fn pressed(buttons: u8) -> bool;
#[link_name = "arduboy_print_chars"]
pub fn print_chars(cstr: *const c_char);
#[link_name = "arduboy_print_chars_progmem"]
pub fn print_chars_progmem(pstring: *const c_char);
// #[link_name = "arduboy_print_char"]
// fn print_char(c: c_char) -> c_size_t;
#[link_name = "arduboy_print_int"]
pub fn print_int(n: c_int, base: c_int) -> c_size_t;
#[link_name = "arduboy_print_long"]
pub fn print_long(n: c_long, base: c_int) -> c_size_t;
#[link_name = "arduboy_print_unsigned_char"]
pub fn print_unsigned_char(n: c_uchar, base: c_int) -> c_size_t;
#[link_name = "arduboy_print_unsigned_int"]
pub fn print_unsigned_int(n: c_uint, base: c_int) -> c_size_t;
#[link_name = "arduboy_print_unsigned_long"]
pub fn print_unsigned_long(n: c_ulong, base: c_int) -> c_size_t;
#[link_name = "arduboy_set_cursor"]
pub fn set_cursor(x: i16, y: i16);
#[link_name = "arduboy_set_frame_rate"]
pub fn set_frame_rate(rate: u8);
#[link_name = "arduboy_set_text_size"]
pub fn set_text_size(size: u8);
#[link_name = "arduboy_audio_on"]
pub fn arduboy_audio_on();
#[link_name = "arduboy_audio_off"]
pub fn arduboy_audio_off();
#[link_name = "arduboy_audio_save_on_off"]
pub fn arduboy_audio_save_on_off();
#[link_name = "arduboy_audio_toggle"]
pub fn arduboy_audio_toggle();
#[link_name = "arduboy_audio_enabled"]
pub fn arduboy_audio_enabled() -> bool;
#[link_name = "arduboy_invert"]
pub fn arduboy_invert(inverse: bool);
#[link_name = "arduboy_every_x_frames"]
pub fn every_x_frames(frames: u8) -> bool;
#[link_name = "arduboy_flip_horizontal"]
pub fn flip_horizontal(flipped: bool);
#[link_name = "arduboy_flip_vertical"]
pub fn flip_vertical(flipped: bool);
#[link_name = "arduboy_set_text_color"]
pub fn set_text_color(color: u8);
#[link_name = "arduboy_set_text_background_color"]
pub fn set_text_background_color(color: u8);
#[link_name = "arduboy_set_cursor_x"]
pub fn set_cursor_x(x: i16);
#[link_name = "arduboy_set_cursor_y"]
pub fn set_cursor_y(y: i16);
#[link_name = "arduboy_set_text_wrap"]
pub fn set_text_wrap(w: bool);
#[link_name = "arduboy_idle"]
pub fn idle();
#[link_name = "arduboy_digital_write_rgb_single"]
pub fn digital_write_rgb_single(color: c_uchar, val: c_uchar);
#[link_name = "arduboy_digital_write_rgb"]
pub fn digital_write_rgb(red: c_uchar, green: c_uchar, blue: c_uchar);
#[link_name = "arduboy_set_rgb_led_single"]
pub fn set_rgb_led_single(color: c_uchar, val: c_uchar);
#[link_name = "arduboy_set_rgb_led"]
pub fn set_rgb_led(red: c_uchar, green: c_uchar, blue: c_uchar);
#[link_name = "arduboy_buttons_state"]
pub fn arduboy_buttons_state() -> u8;
#[link_name = "arduboy_exit_to_bootloader"]
pub fn arduboy_exit_to_bootloader();
}

View file

@ -0,0 +1,12 @@
//! This is the Module to interact in a save way with the Arduboy2 C++ library.
//!
//! All of the functions are safe wrapped inside the [Arduboy2] struct.
#[doc(hidden)]
pub mod arduboy2;
#[doc(hidden)]
pub mod binding;
#[doc(hidden)]
pub mod print;
pub mod sprites;
pub use arduboy2::{Arduboy2, Color, Point, Rect, FONT_HEIGHT, FONT_WIDTH, HEIGHT, WIDTH};

View file

@ -1,4 +1,4 @@
use crate::prelude::Pstring;
use crate::arduino_system::progmem::Pstring;
use core::ffi::c_int;
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
@ -28,7 +28,7 @@ impl Printable for i16 {
fn print_2(self, params: Self::Parameters) {
unsafe {
crate::library::arduboy2::print_int(self, params as c_int);
super::binding::print_int(self, params as c_int);
}
}
@ -42,7 +42,7 @@ impl Printable for u16 {
fn print_2(self, params: Self::Parameters) {
unsafe {
crate::library::arduboy2::print_unsigned_int(self, params as c_int);
super::binding::print_unsigned_int(self, params as c_int);
}
}
@ -56,7 +56,7 @@ impl Printable for i32 {
fn print_2(self, params: Self::Parameters) {
unsafe {
crate::library::arduboy2::print_long(self, params as c_int);
super::binding::print_long(self, params as c_int);
}
}
@ -70,7 +70,7 @@ impl Printable for u32 {
fn print_2(self, params: Self::Parameters) {
unsafe {
crate::library::arduboy2::print_unsigned_long(self, params as c_int);
super::binding::print_unsigned_long(self, params as c_int);
}
}
@ -84,7 +84,7 @@ impl Printable for &[u8] {
fn print_2(self, _params: Self::Parameters) {
unsafe {
crate::library::arduboy2::print_chars(self as *const [u8] as *const i8);
super::binding::print_chars(self as *const [u8] as *const i8);
}
}
@ -96,7 +96,7 @@ impl Printable for &str {
fn print_2(self, _params: Self::Parameters) {
unsafe {
crate::library::arduboy2::print_chars(self.as_bytes() as *const [u8] as *const i8);
super::binding::print_chars(self.as_bytes() as *const [u8] as *const i8);
}
}
@ -107,7 +107,7 @@ impl<const N: usize> Printable for crate::heapless::String<N> {
fn print_2(self, _params: Self::Parameters) {
unsafe {
crate::library::arduboy2::print_chars(self.as_bytes() as *const [u8] as *const i8);
super::binding::print_chars(self.as_bytes() as *const [u8] as *const i8);
}
}
@ -119,7 +119,7 @@ impl Printable for Pstring {
fn print_2(self, _params: Self::Parameters) {
unsafe {
crate::library::arduboy2::print_chars_progmem(self.pointer);
super::binding::print_chars_progmem(self.pointer);
}
}

View file

@ -1,13 +1,9 @@
//!This is the Module to interact in a save way with the ArduboyTones C++ library.
//!
//! You will need to uncomment the ArduboyTones_Library in the import_config.h file.
pub mod tones_pitch;
use core::ffi::{c_uchar, c_uint, c_ulong};
///This is the struct to interact in a save way with the ArduboyTones C++ library.
///
/// You will need to uncomment the ArduboyTones_Library in the import_config.h file.
pub struct ArduboyTones {}
impl ArduboyTones {
///Get a new instance of [ArduboyTones]
@ -71,9 +67,9 @@ impl ArduboyTones {
/// Example:
/// ```
/// use arduboy_rust::prelude::*;
/// const sound:ArduboyTones=ArduboyTones::new();
/// const sound: ArduboyTones = ArduboyTones::new();
/// progmem!(
/// static sound1:[u8;_]=[220,1000, 0,250, 440,500, 880,2000,TONES_END];
/// static sound1: [u8; _] = [220, 1000, 0, 250, 440, 500, 880, 2000, TONES_END];
/// );
///
/// sound.tones(get_tones_addr!(sound1));

View file

@ -0,0 +1,8 @@
//!This is the Module to interact in a save way with the ArduboyTones C++ library.
//!
//! You will need to uncomment the ArduboyTones_Library in the import_config.h file.
#[doc(hidden)]
mod arduboy_tones;
pub mod tones_pitch;
pub use arduboy_tones::ArduboyTones;

View file

@ -1,5 +1,5 @@
use crate::libraries::arduino_system::progmem::Pstring;
use core::ffi::{c_char, c_uchar, c_ulong};
use crate::library::progmem::Pstring;
pub trait DrawableString
where

View file

@ -1,9 +1,11 @@
//! This is the Module to interact in a save way with the ArduboyFX C++ library.
//!
//! You will need to uncomment the ArduboyFX_Library in the import_config.h file.
pub mod fx_consts;
mod drawable_number;
pub mod fx_consts;
#[doc(hidden)]
pub use drawable_number::DrawableNumber;
mod drawable_string;
#[doc(hidden)]
pub use drawable_string::DrawableString;
pub mod fx;

View file

@ -1,3 +1,4 @@
//!This is the module to interact with the eeprom memory
use core::ffi::{c_int, c_uchar};
pub const EEPROM_STORAGE_SPACE_START: i16 = 16;

View file

@ -0,0 +1,7 @@
//!This module contains all the Arduino system functions to interact with the hardware.
pub mod arduino;
pub mod c;
pub mod eeprom;
pub mod progmem;
pub mod serial_print;

View file

@ -1,3 +1,4 @@
//!This is the module to interact with the progmem memory
#![allow(unused_imports)]
/// Create a space for Progmem variable
/// ## Example

View file

@ -1,10 +1,10 @@
//! This is the Module to interact in a save way with the Arduino Serial C++ library.
//!
//! You will need to uncomment the Arduino_Serial_Library in the import_config.h file.
use crate::prelude::Pstring;
use crate::arduino_system::progmem::Pstring;
use core::ffi::{c_char, c_int, c_long, c_size_t, c_uchar, c_uint, c_ulong};
use crate::print::Base;
use crate::libraries::arduboy2_library::print::Base;
extern "C" {
#[link_name = "arduino_serial_begin"]
fn serial_begin(serial: c_ulong);

View file

@ -0,0 +1,5 @@
//! This is the Module to interact in a save way with the ArdVoice C++ library.
//!
//! You will need to uncomment the ArdVoice_Library in the import_config.h file.
mod ardvoice;
pub use ardvoice::ArdVoice;

View file

@ -0,0 +1,5 @@
pub mod arduboy2_library;
pub mod arduboy_tones_library;
pub mod arduino_system;
pub mod arduboyfx_library;
pub mod ardvoice_library;

View file

@ -1,9 +0,0 @@
pub mod arduboy2;
pub mod arduboy_tones;
pub mod arduino;
pub mod ardvoice;
pub mod c;
pub mod eeprom;
pub mod progmem;
pub mod sprites;
pub mod arduboyfx;

View file

@ -5,23 +5,19 @@
//! use arduboy_rust::prelude::*;
//! ```
#[doc(inline)]
pub use crate::hardware::buttons::{self, *};
pub use crate::hardware::buttons::*;
#[doc(inline)]
pub use crate::hardware::led::{self, *};
pub use crate::hardware::led::*;
pub use crate::heapless::{LinearMap, String, Vec};
pub use crate::library::arduboy2::{self, *};
pub use crate::library::arduboy_tones::{self, ArduboyTones};
pub use crate::library::arduboyfx::{self, fx};
pub use crate::library::arduino::*;
pub use crate::library::ardvoice::{self, ArdVoice};
pub use crate::library::c::*;
pub use crate::library::eeprom::{EEPROM, EEPROMBYTE, EEPROMBYTECHECKLESS};
#[doc(hidden)]
pub use crate::library::progmem::Pstring;
pub use crate::library::sprites;
pub use crate::print::*;
#[doc(inline)]
pub use crate::serial_print as serial;
pub use crate::libraries::arduboy2_library::*;
pub use crate::libraries::arduboy_tones_library::*;
pub use crate::libraries::arduboyfx_library::*;
pub use crate::libraries::arduino_system::arduino::*;
pub use crate::libraries::arduino_system::c::*;
pub use crate::libraries::arduino_system::eeprom::*;
pub use crate::libraries::arduino_system::progmem::*;
pub use crate::libraries::arduino_system::serial_print as serial;
pub use crate::libraries::ardvoice_library::ArdVoice;
pub use crate::{
f, get_ardvoice_tone_addr, get_sprite_addr, get_string_addr, get_tones_addr, progmem,
};

View file

@ -1,24 +0,0 @@
#pragma once
// #################
// # WARNING #
// #################
//
// ## Read the docs before change here things!! ##
//
// https://zenndev1337.github.io/Rust-for-Arduboy/
//
// Comment out the libraries you dont need.
// This saves memory but be careful if the libraries are not defined
// it will not export the given functions for the rust project.
//
// to save a good amount you can comment out
// the ArduboyTones library if you don't need it.
#define Arduboy2_Library ;
// #define ArduboyTones_Library ;
// #define ArduboyFX_Library ;
// #define ArdVoice_Library ;
#define EEPROM_Library ;
#define Arduino_Library ;
// #define Arduino_Serial_Library ;

220
run.py Normal file
View file

@ -0,0 +1,220 @@
import sys
import os
import tomllib
import subprocess
import platform
# Global Params
param1 = ""
param2 = ""
fx_mode=False
project_list=[]
parameter_validation_check=False
project=[]
# Functions
def get_args():
global param1
global param2
global fx_mode
if len(sys.argv)==1:
help()
if len(sys.argv)>1:
param1 = sys.argv[1]
if len(sys.argv)>2:
param2 = sys.argv[2]
fx_mode=True
def help():
print("Usage build and upload Project:")
print(" run.py list Get a list of all Projects")
print(" run.py new <Project-Name> Create a new game in the Project folder")
print(" run.py <Project-Name> For uploading a game")
print("")
print("Usage FX-Data build and upload:")
print(" run.py fxbuild <Project-Name> Build your fxdata")
print(" run.py fxupload <Project-Name> Upload your fxdata")
print(" run.py fxall <Project-Name> Build and Upload your fxdata")
print(" and the game in one step")
sys.exit()
def get_projects():
global project_list
with open("Cargo.toml", "rb") as f:
data = tomllib.load(f)
path=data["workspace"]["members"]
for p in path:
name = p.split("/")[-1]
if name =="arduboy-rust":
continue
project=[name,p]
project_list.append(project)
def validate_args():
global parameter_validation_check
global project
if fx_mode:
for p in project_list:
if param2 in p:
parameter_validation_check=True
project = p
else:
for p in project_list:
if param1 in p:
parameter_validation_check=True
project = p
if not parameter_validation_check:
help()
def execute_options():
if param1=="list":
group=""
for p in project_list:
if not group==p[1].split("/")[-2]:
group=p[1].split("/")[-2]
print(f"\n{group}:")
print(f" {p[0]}")
print("")
exit()
if param1=="new":
create_new_project()
exit()
def _dumps_value(value):
if isinstance(value, bool):
return "true" if value else "false"
elif isinstance(value, (int, float)):
return str(value)
elif isinstance(value, str):
return f'"{value}"'
elif isinstance(value, list):
return f"[{', '.join(_dumps_value(v) for v in value)}]"
else:
raise TypeError(f"{type(value).__name__} {value!r} is not supported")
def dumps(toml_dict, table=""):
toml = []
for key, value in toml_dict.items():
if isinstance(value, dict):
table_key = f"{table}.{key}" if table else key
toml.append(f"\n[{table_key}]\n{dumps(value, table_key)}")
else:
toml.append(f"{key} = {_dumps_value(value)}")
return "\n".join(toml)
def create_new_project():
project_name = param2.replace("-","_")
for p in project_list:
if p[0]==project_name:
sys.exit()
error_code=os.system(f'cargo new --vcs=none --lib ./Project/{project_name}')
if error_code>0:
sys.exit()
# Edit main Cargo.toml
with open("Cargo.toml", "rb") as f:
data = tomllib.load(f)
data["workspace"]["members"].append(f"Project/{project_name}")
with open("Cargo.toml","w") as f:
f.write(dumps(data))
# Edit new project Cargo.toml
with open(f"Project/{project_name}/Cargo.toml", "rb") as f:
data = tomllib.load(f)
newdata={}
newdata["package"]=data["package"]
newdata["lib"]={'crate-type':["staticlib"]}
newdata["dependencies"]={"arduboy-rust":{"path":"../../arduboy-rust"}}
with open(f"Project/{project_name}/Cargo.toml","w") as f:
f.write(dumps(newdata))
# Edit lib.rs
with open(f"Project/{project_name}/src/lib.rs","w") as f:
f.write('''#![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:
}''')
def generate_import_h():
with open(f"{project[1]}/config.toml", "rb") as f:
data = tomllib.load(f)
strings=["#pragma once\n"]
for lib in data["Libraries"]:
strings.append(f"#define {lib}_Library ;\n")
f = open("arduboy-rust/Wrapper-Project/src/imports.h", "w")
f.writelines(strings)
f.close()
def upload_to_arduboy():
if not fx_mode:
game_name=param1
else:
game_name=param2
if platform.system()=="Linux":
cmd=f"cargo build -p {game_name} --release; cp ./target/arduboy/release/lib{game_name}.a ./arduboy-rust/Wrapper-Project/lib/libgame.a; cd arduboy-rust/Wrapper-Project/; pio run -v -t upload; cp ./.pio/build/arduboy/firmware.hex ./build/{game_name}.hex; pio run -t clean; rm ./lib/libgame.a; cd ../../"
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
elif platform.system()=="Windows":
cmd=f'cargo build -p {game_name} --release; cp ./target/arduboy/release/lib{game_name}.a ./arduboy-rust/Wrapper-Project/lib/libgame.a; cd arduboy-rust/Wrapper-Project/; pio run -v -t upload; cp ./.pio/build/arduboy/firmware.hex ./build/{game_name}.hex; pio run -t clean; rm lib/libgame.a; cd ../../'
process = subprocess.Popen(["powershell", "-Command", cmd], stdout=subprocess.PIPE)
else:
sys.exit()
for c in iter(lambda: process.stdout.read(1),b""):
sys.stdout.buffer.write(c)
if process.returncode != 0:
sys.exit()
def fx_build():
error_code=os.system(f'python ./Tools/Arduboy-Python-Utilities/fxdata-build.py ./{project[1]}/fxdata/fxdata.txt')
if error_code>0:
sys.exit()
def fx_upload():
error_code=os.system(f'python ./Tools/Arduboy-Python-Utilities/fxdata-upload.py ./{project[1]}/fxdata/fxdata.bin')
if error_code>0:
sys.exit()
def fx_commands():
print("")
if param1=="fxbuild":
fx_build()
elif param1=="fxupload":
fx_upload()
elif param1=="fxall":
fx_build()
fx_upload()
upload_to_arduboy()
# Execute Script
get_args()
get_projects()
execute_options()
validate_args()
generate_import_h()
if fx_mode:
fx_commands()
else:
upload_to_arduboy()