added a new macro progmem!() at the inside you can add new progmem data.
This commit is contained in:
parent
d9cb232cef
commit
28cbec07f8
8 changed files with 427 additions and 337 deletions
|
@ -9,16 +9,14 @@ use arduboy_rust::arduboy_tone_pitch::*;
|
|||
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] = [
|
||||
progmem!(
|
||||
static lol1: [u8; _] = *b"I'm a PROGMEM Text\0";
|
||||
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,
|
||||
];
|
||||
#[link_section = ".progmem.data"]
|
||||
static tones: [u16; 43] = [
|
||||
0x01, 0xfe, 0x7f, 0x80, 0x9c, 0xbc, 0xb0, 0xb0, 0xb2, 0xb2, 0xb3, 0xb0, 0xb0, 0xb0, 0xbc,
|
||||
0x9c, 0x80, 0x7f,
|
||||
];
|
||||
static tones: [u16; _] = [
|
||||
NOTE_E4,
|
||||
400,
|
||||
NOTE_D4,
|
||||
|
@ -62,7 +60,60 @@ static tones: [u16; 43] = [
|
|||
NOTE_REST,
|
||||
1500,
|
||||
TONES_REPEAT,
|
||||
];
|
||||
];
|
||||
);
|
||||
//#[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;
|
||||
|
|
|
@ -6,8 +6,8 @@ use arduboy_rust::arduboy_tone_pitch::*;
|
|||
#[allow(unused_imports)]
|
||||
use arduboy_rust::prelude::*;
|
||||
|
||||
#[link_section = ".progmem.data"]
|
||||
static allNotes: [u16; 241] = [
|
||||
progmem!(
|
||||
static allNotes: [u16; _] = [
|
||||
NOTE_C0H,
|
||||
NDUR,
|
||||
NOTE_CS0,
|
||||
|
@ -249,16 +249,18 @@ static allNotes: [u16; 241] = [
|
|||
NOTE_B9,
|
||||
NDUR,
|
||||
TONES_REPEAT,
|
||||
];
|
||||
#[link_section = ".progmem.data"]
|
||||
static sound1: [u16; 73] = [
|
||||
NOTE_C1, 500, NOTE_C1H, 500, NOTE_G1, 500, NOTE_G1H, 500, NOTE_C2, 500, NOTE_C2H, 500, NOTE_G2,
|
||||
500, NOTE_G2H, 500, NOTE_C3, 500, NOTE_C3H, 500, NOTE_G3, 500, NOTE_G3H, 500, NOTE_C4, 500,
|
||||
NOTE_C4H, 500, NOTE_G4, 500, NOTE_G4H, 500, NOTE_C5, 500, NOTE_C5H, 500, NOTE_G5, 500,
|
||||
NOTE_G5H, 500, NOTE_C6, 500, NOTE_C6H, 500, NOTE_G6, 500, NOTE_G6H, 500, NOTE_C7, 500,
|
||||
NOTE_C7H, 500, NOTE_G7, 500, NOTE_G7H, 500, NOTE_C8, 500, NOTE_C8H, 500, NOTE_G8, 500,
|
||||
NOTE_G8H, 500, NOTE_C9, 500, NOTE_C9H, 500, NOTE_G9, 500, NOTE_G9H, 500, TONES_END,
|
||||
];
|
||||
];
|
||||
|
||||
static sound1: [u16; _] = [
|
||||
NOTE_C1, 500, NOTE_C1H, 500, NOTE_G1, 500, NOTE_G1H, 500, NOTE_C2, 500, NOTE_C2H, 500,
|
||||
NOTE_G2, 500, NOTE_G2H, 500, NOTE_C3, 500, NOTE_C3H, 500, NOTE_G3, 500, NOTE_G3H, 500,
|
||||
NOTE_C4, 500, NOTE_C4H, 500, NOTE_G4, 500, NOTE_G4H, 500, NOTE_C5, 500, NOTE_C5H, 500,
|
||||
NOTE_G5, 500, NOTE_G5H, 500, NOTE_C6, 500, NOTE_C6H, 500, NOTE_G6, 500, NOTE_G6H, 500,
|
||||
NOTE_C7, 500, NOTE_C7H, 500, NOTE_G7, 500, NOTE_G7H, 500, NOTE_C8, 500, NOTE_C8H, 500,
|
||||
NOTE_G8, 500, NOTE_G8H, 500, NOTE_C9, 500, NOTE_C9H, 500, NOTE_G9, 500, NOTE_G9H, 500,
|
||||
TONES_END,
|
||||
];
|
||||
);
|
||||
|
||||
static mut circle_pos: i16 = 7;
|
||||
const BUTTON_DELAY: u32 = 200;
|
||||
|
|
|
@ -1,14 +1,5 @@
|
|||
//pub use crate::library::arduboy_tone_pitch::*;
|
||||
use core::ffi::{c_uchar, c_uint, c_ulong};
|
||||
///Create a `const` raw pointer to a sprite as u16, without creating an intermediate reference.
|
||||
#[macro_export]
|
||||
macro_rules! get_tones_addr {
|
||||
( $s:expr ) => {
|
||||
addr_of!($s) as *const u16
|
||||
};
|
||||
}
|
||||
#[allow(unused_imports)]
|
||||
pub(super) use get_tones_addr;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "sound_tone"]
|
||||
|
|
|
@ -4,4 +4,5 @@ pub mod arduboy_tone_pitch;
|
|||
pub mod arduino;
|
||||
pub mod c;
|
||||
pub mod eeprom;
|
||||
pub mod progmem;
|
||||
pub mod sprites;
|
||||
|
|
65
arduboy-rust/src/library/progmem.rs
Normal file
65
arduboy-rust/src/library/progmem.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
#![allow(unused_imports)]
|
||||
/// Create a space for Progrem variable
|
||||
/// ## Example
|
||||
/// ```
|
||||
/// //for text
|
||||
/// progmem!(
|
||||
/// static text: [u8; _] = *b"I'm a PROGMEM Text\0";
|
||||
/// );
|
||||
/// //for tone sequence
|
||||
/// progmem!(
|
||||
/// static tone: [u16; 43] = [
|
||||
/// NOTE_E4, 400, NOTE_D4, 200, NOTE_C4, 400, NOTE_D4, 200, NOTE_C4, 300, NOTE_REST,
|
||||
/// ];
|
||||
/// );
|
||||
/// //for for bitmap
|
||||
/// progmem!(
|
||||
/// static image: [u8; _] = [8, 8, 0x81, 0x00, 0x12, 0x40, 0x04, 0x11, 0x00, 0x04];
|
||||
/// );
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! progmem {
|
||||
(
|
||||
$( #[$attr:meta] )*
|
||||
$v:vis $id:ident $name:ident: [$ty:ty; _] = $value:expr;
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
$( #[$attr] )*
|
||||
#[link_section = ".progmem.data"]
|
||||
$v $id $name: [$ty; $value.len()] = $value;
|
||||
$crate::progmem!{
|
||||
$($rest)*
|
||||
}
|
||||
};
|
||||
() => ()
|
||||
}
|
||||
|
||||
pub(super) use progmem;
|
||||
///Create a `const` raw pointer to a sprite as u8, without creating an intermediate reference.
|
||||
#[macro_export]
|
||||
macro_rules! get_sprite_addr {
|
||||
( $s:expr ) => {
|
||||
addr_of!($s) as *const u8
|
||||
};
|
||||
}
|
||||
pub(super) use get_sprite_addr;
|
||||
|
||||
///Create a `const` raw pointer to a sprite as u16, without creating an intermediate reference.
|
||||
#[macro_export]
|
||||
macro_rules! get_tones_addr {
|
||||
( $s:expr ) => {
|
||||
addr_of!($s) as *const u16
|
||||
};
|
||||
}
|
||||
pub(super) use get_tones_addr;
|
||||
|
||||
///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 ) => {
|
||||
Pstring {
|
||||
pointer: addr_of!($s) as *const i8,
|
||||
}
|
||||
};
|
||||
}
|
||||
pub(super) use get_string_addr;
|
|
@ -1,14 +1,5 @@
|
|||
//!This is the module to interact in a save way with the Sprites C++ library.
|
||||
use core::ffi::{c_int, c_uchar};
|
||||
///Create a `const` raw pointer to a sprite as u8, without creating an intermediate reference.
|
||||
#[macro_export]
|
||||
macro_rules! get_sprite_addr {
|
||||
( $s:expr ) => {
|
||||
addr_of!($s) as *const u8
|
||||
};
|
||||
}
|
||||
#[allow(unused_imports)]
|
||||
pub(super) use get_sprite_addr;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "arduino_draw_override"]
|
||||
|
|
|
@ -19,7 +19,7 @@ pub use crate::library::c::*;
|
|||
pub use crate::library::eeprom::EEPROM;
|
||||
pub use crate::library::sprites;
|
||||
pub use crate::print::*;
|
||||
pub use crate::{get_sprite_addr, get_string_addr, get_tones_addr};
|
||||
pub use crate::{get_sprite_addr, get_string_addr, get_tones_addr, progmem};
|
||||
use core::cmp;
|
||||
|
||||
pub fn constrain<T: Ord>(x: T, a: T, b: T) -> T {
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
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 ) => {
|
||||
Pstring {
|
||||
pointer: addr_of!($s) as *const i8,
|
||||
}
|
||||
};
|
||||
}
|
||||
#[allow(unused_imports)]
|
||||
pub(super) use get_string_addr;
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub enum Base {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue