added new demo for progmem and implemented new features for the usage of progmem.
This commit is contained in:
parent
5fdfcf88c4
commit
d9cb232cef
14 changed files with 148 additions and 117 deletions
|
@ -5,12 +5,14 @@ target-dir = "./target"
|
|||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = "fat"
|
||||
strip = true
|
||||
opt-level = "z"
|
||||
panic = "abort"
|
||||
|
||||
[profile.dev]
|
||||
codegen-units = 1
|
||||
lto = "fat"
|
||||
strip = true
|
||||
opt-level = "z"
|
||||
panic = "abort"
|
||||
|
||||
|
|
99
Cargo.lock
generated
99
Cargo.lock
generated
|
@ -6,27 +6,9 @@ version = 3
|
|||
name = "arduboy-rust"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"avr-progmem",
|
||||
"panic-halt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avr-progmem"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4026b5cfd2368953bed46ffaa1acc7e4ea398bb7a610743d11895a5187498076"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"derivative",
|
||||
"ufmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "demo2"
|
||||
version = "0.1.0"
|
||||
|
@ -62,17 +44,6 @@ dependencies = [
|
|||
"arduboy-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derivative"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "eeprom-demo"
|
||||
version = "0.1.0"
|
||||
|
@ -85,7 +56,6 @@ name = "game"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arduboy-rust",
|
||||
"avr-progmem",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -102,27 +72,10 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.20+deprecated"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||
name = "progmem"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"arduboy-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -139,55 +92,9 @@ dependencies = [
|
|||
"arduboy-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tone"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arduboy-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31d3c0c63312dfc9d8e5c71114d617018a19f6058674003c0da29ee8d8036cdd"
|
||||
dependencies = [
|
||||
"proc-macro-hack",
|
||||
"ufmt-macros",
|
||||
"ufmt-write",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt-macros"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4ab6c92f30c996394a8bd525aef9f03ce01d0d7ac82d81902968057e37dd7d9"
|
||||
dependencies = [
|
||||
"proc-macro-hack",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ufmt-write"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
members = [
|
||||
"arduboy-rust",
|
||||
"Examples/Arduboy-Tutorials/eeprom",
|
||||
"Examples/Arduboy-Tutorials/progmem",
|
||||
"Examples/Arduboy-Tutorials/tone",
|
||||
"Examples/Arduboy-Tutorials/demo2",
|
||||
"Examples/Arduboy-Tutorials/demo3",
|
||||
|
|
10
Examples/Arduboy-Tutorials/progmem/Cargo.toml
Normal file
10
Examples/Arduboy-Tutorials/progmem/Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "progmem"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = { path = "../../../arduboy-rust" }
|
114
Examples/Arduboy-Tutorials/progmem/src/lib.rs
Normal file
114
Examples/Arduboy-Tutorials/progmem/src/lib.rs
Normal file
|
@ -0,0 +1,114 @@
|
|||
#![no_std]
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
//Include the Arduboy Library
|
||||
//Initialize the arduboy object
|
||||
use arduboy_rust::arduboy_tone_pitch::*;
|
||||
#[allow(unused_imports)]
|
||||
use arduboy_rust::prelude::*;
|
||||
|
||||
// Progmem data
|
||||
#[link_section = ".progmem.data"]
|
||||
static lol1: [u8; 19] = *b"I'm a PROGMEM Text\0";
|
||||
#[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 tones: [u16; 43] = [
|
||||
NOTE_E4,
|
||||
400,
|
||||
NOTE_D4,
|
||||
200,
|
||||
NOTE_C4,
|
||||
400,
|
||||
NOTE_REST,
|
||||
200,
|
||||
NOTE_D4,
|
||||
200,
|
||||
NOTE_C4,
|
||||
300,
|
||||
NOTE_REST,
|
||||
100,
|
||||
NOTE_C4,
|
||||
300,
|
||||
NOTE_REST,
|
||||
100,
|
||||
NOTE_E4,
|
||||
300,
|
||||
NOTE_REST,
|
||||
100,
|
||||
NOTE_G4,
|
||||
300,
|
||||
NOTE_REST,
|
||||
100,
|
||||
NOTE_F4,
|
||||
300,
|
||||
NOTE_REST,
|
||||
100,
|
||||
NOTE_A4,
|
||||
300,
|
||||
NOTE_REST,
|
||||
100,
|
||||
NOTE_D5H,
|
||||
200,
|
||||
NOTE_REST,
|
||||
200,
|
||||
NOTE_D5H,
|
||||
200,
|
||||
NOTE_REST,
|
||||
1500,
|
||||
TONES_REPEAT,
|
||||
];
|
||||
|
||||
// dynamic ram variables
|
||||
static mut playerx: c_int = 5;
|
||||
static mut playery: c_int = 10;
|
||||
|
||||
// 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:
|
||||
arduboy.begin();
|
||||
arduboy.clear();
|
||||
arduboy.set_frame_rate(60);
|
||||
// load sound sequence from progmem
|
||||
sound.tones(get_tones_addr!(tones));
|
||||
}
|
||||
// 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:
|
||||
if !arduboy.next_frame() {
|
||||
return;
|
||||
}
|
||||
arduboy.poll_buttons();
|
||||
if arduboy.pressed(LEFT) {
|
||||
playerx -= 1;
|
||||
}
|
||||
if arduboy.pressed(RIGHT) {
|
||||
playerx += 1;
|
||||
}
|
||||
if arduboy.pressed(UP) {
|
||||
playery -= 1;
|
||||
}
|
||||
if arduboy.pressed(DOWN) {
|
||||
playery += 1;
|
||||
}
|
||||
if arduboy.just_pressed(A) {
|
||||
if arduboy.audio_enabled() {
|
||||
arduboy.audio_off()
|
||||
} else {
|
||||
arduboy.audio_on()
|
||||
}
|
||||
}
|
||||
arduboy.clear();
|
||||
arduboy.set_cursor((WIDTH as i16 / 2) - (lol1.len() as i16 * FONT_SIZE as i16 / 2), 10);
|
||||
arduboy.print(get_string_addr!(lol1));
|
||||
sprites::draw_override(playerx, playery, get_sprite_addr!(player_sprite1), 0);
|
||||
arduboy.display();
|
||||
}
|
|
@ -7,5 +7,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
avr-progmem = "0.3.3"
|
||||
arduboy-rust = { path = "../../arduboy-rust" }
|
||||
|
|
|
@ -1,30 +1,21 @@
|
|||
#![no_std]
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![feature(const_trait_impl)]
|
||||
use core::cell::LazyCell;
|
||||
|
||||
//Include the Arduboy Library
|
||||
//Initialize the arduboy object
|
||||
#[allow(unused_imports)]
|
||||
use arduboy_rust::prelude::*;
|
||||
|
||||
#[link_section = ".progmem.data"]
|
||||
static lol2: [u8; 29] = [
|
||||
0x54, 0x68, 0x61, 0x6E, 0x6B, 0x73, 0x20, 0x61, 0x20, 0x6C, 0x6F, 0x74, 0x0A, 0x79, 0x6F, 0x75,
|
||||
0x20, 0x61, 0x72, 0x65, 0x20, 0x61, 0x20, 0x0A, 0x48, 0x65, 0x72, 0x6F, 0x00,
|
||||
];
|
||||
#[link_section = ".progmem.data"]
|
||||
static lol1: [u8; 10] = LazyCell::new(|| "hallowelt\0".as_bytes().try_into().unwrap());
|
||||
// Progmem data
|
||||
//#[link_section = ".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:
|
||||
arduboy.begin();
|
||||
arduboy.clear();
|
||||
arduboy.print(get_string_addr!(lol1));
|
||||
arduboy.display();
|
||||
}
|
||||
|
||||
// The loop() function repeats forever after setup() is done
|
||||
#[no_mangle]
|
||||
#[export_name = "loop"]
|
||||
|
|
|
@ -140,6 +140,7 @@ Windows:
|
|||
- not done [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)
|
||||
- not done [demo8] [Make Your Own Arduboy Game: Part 8 - Starting DinoSmasher](https://community.arduboy.com/t/make-your-own-arduboy-game-part-8-starting-dinosmasher/7932)
|
||||
- [eeprom] [Help, I’m 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)
|
||||
|
||||
To upload a demo to the Arduboy use:
|
||||
|
@ -153,6 +154,7 @@ Linux:
|
|||
./run demo5
|
||||
./run demo6
|
||||
./run eeprom
|
||||
./run progmem
|
||||
./run tone
|
||||
```
|
||||
|
||||
|
@ -165,6 +167,7 @@ Windows:
|
|||
.\run.bat demo5
|
||||
.\run.bat demo6
|
||||
.\run.bat eeprom
|
||||
.\run.bat progmem
|
||||
.\run.bat tone
|
||||
```
|
||||
|
||||
|
|
|
@ -13,5 +13,4 @@ categories = ["game-engines", "games", "api-bindings"]
|
|||
|
||||
|
||||
[dependencies]
|
||||
avr-progmem = "0.3.3"
|
||||
panic-halt = "0.2.0"
|
||||
|
|
|
@ -6,7 +6,7 @@ mod hardware;
|
|||
mod library;
|
||||
pub mod prelude;
|
||||
mod print;
|
||||
pub use crate::library::arduboy::{Arduboy, Color, Pstring, FONT_SIZE, HEIGHT, WIDTH};
|
||||
pub use crate::library::arduboy::{Arduboy, Color, FONT_SIZE, HEIGHT, WIDTH};
|
||||
pub use crate::library::arduboy_tone::Sound;
|
||||
pub use crate::library::eeprom::EEPROM;
|
||||
pub use crate::library::{arduboy_tone_pitch, c, sprites};
|
||||
|
|
|
@ -20,7 +20,7 @@ pub const WIDTH: u8 = 128;
|
|||
///
|
||||
/// this is to calculate with it.
|
||||
pub const HEIGHT: u8 = 64;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Pstring {
|
||||
pub pointer: *const i8,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::prelude::Pstring;
|
||||
use core::ffi::c_int;
|
||||
|
||||
///Create a `const` raw pointer to a \[u8;_] that saves text, without creating an intermediate reference.
|
||||
#[macro_export]
|
||||
macro_rules! get_string_addr {
|
||||
( $s:expr ) => {
|
||||
|
@ -11,8 +12,6 @@ macro_rules! get_string_addr {
|
|||
#[allow(unused_imports)]
|
||||
pub(super) use get_string_addr;
|
||||
|
||||
use crate::Pstring;
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub enum Base {
|
||||
Bin = 2,
|
||||
|
|
3
run
3
run
|
@ -20,6 +20,9 @@ then
|
|||
elif [ "$option" = "eeprom" ]
|
||||
then
|
||||
cargo build -p eeprom-demo --release && cp ./target/arduboy/release/libeeprom_demo.a ./Wrapper-Project/lib/libgame.a && cd Wrapper-Project/ && pio run -v -t upload && cp ./.pio/build/arduboy/firmware.hex ./.pio/build/eeprom.hex && pio run -t clean && rm lib/libgame.a && cd ..
|
||||
elif [ "$option" = "progmem" ]
|
||||
then
|
||||
cargo build -p progmem --release && cp ./target/arduboy/release/libprogmem.a ./Wrapper-Project/lib/libgame.a && cd Wrapper-Project/ && pio run -v -t upload && cp ./.pio/build/arduboy/firmware.hex ./.pio/build/progmem.hex && pio run -t clean && rm lib/libgame.a && cd ..
|
||||
elif [ "$option" = "demo2" ]
|
||||
then
|
||||
cargo build -p demo2 --release && cp ./target/arduboy/release/libdemo2.a ./Wrapper-Project/lib/libgame.a && cd Wrapper-Project/ && pio run -v -t upload && cp ./.pio/build/arduboy/firmware.hex ./.pio/build/demo2.hex && pio run -t clean && rm lib/libgame.a && cd ..
|
||||
|
|
3
run.bat
3
run.bat
|
@ -22,6 +22,9 @@ if %option%==snake (
|
|||
) else if %option%==eeprom (
|
||||
powershell -Command "cargo build -p eeprom-demo --release; cp ./target/arduboy/release/libeeprom_demo.a ./Wrapper-Project/lib/libgame.a; cd Wrapper-Project/; pio run -v -t upload; cp ./.pio/build/arduboy/firmware.hex ./.pio/build/eeprom.hex; pio run -t clean; rm lib/libgame.a; cd .."
|
||||
goto :eof
|
||||
) else if %option%==progmem (
|
||||
powershell -Command "cargo build -p progmem --release; cp ./target/arduboy/release/libprogmem.a ./Wrapper-Project/lib/libgame.a; cd Wrapper-Project/; pio run -v -t upload; cp ./.pio/build/arduboy/firmware.hex ./.pio/build/progmem.hex; pio run -t clean; rm lib/libgame.a; cd .."
|
||||
goto :eof
|
||||
) else if %option%==demo2 (
|
||||
powershell -Command "cargo build -p demo2 --release; cp ./target/arduboy/release/libdemo2.a ./Wrapper-Project/lib/libgame.a; cd Wrapper-Project/; pio run -v -t upload; cp ./.pio/build/arduboy/firmware.hex ./.pio/build/demo2.hex; pio run -t clean; rm lib/libgame.a; cd .."
|
||||
goto :eof
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue