added a new macro progmem!() at the inside you can add new progmem data.

This commit is contained in:
Zenn 2023-08-07 19:18:34 +02:00
parent d9cb232cef
commit 28cbec07f8
8 changed files with 427 additions and 337 deletions

View file

@ -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"]

View file

@ -4,4 +4,5 @@ pub mod arduboy_tone_pitch;
pub mod arduino;
pub mod c;
pub mod eeprom;
pub mod progmem;
pub mod sprites;

View 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;

View file

@ -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"]