added support for structs inside of eeprom memory
This commit is contained in:
parent
d382da0300
commit
c21aa97915
27 changed files with 605 additions and 414 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -44,6 +44,13 @@ dependencies = [
|
|||
"arduboy-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "eeprom-byte-demo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arduboy-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "eeprom-demo"
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
members = [
|
||||
"arduboy-rust",
|
||||
"Examples/Arduboy-Tutorials/eeprom",
|
||||
"Examples/Arduboy-Tutorials/eeprom-byte",
|
||||
"Examples/Arduboy-Tutorials/progmem",
|
||||
"Examples/Arduboy-Tutorials/tone",
|
||||
"Examples/Arduboy-Tutorials/demo2",
|
||||
|
|
12
Examples/Arduboy-Tutorials/eeprom-byte/Cargo.toml
Normal file
12
Examples/Arduboy-Tutorials/eeprom-byte/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "eeprom-byte-demo"
|
||||
version = "0.1.0"
|
||||
authors = ["ZennDev <zenndev@protonmail.com>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = { path = "../../../arduboy-rust" }
|
55
Examples/Arduboy-Tutorials/eeprom-byte/src/lib.rs
Normal file
55
Examples/Arduboy-Tutorials/eeprom-byte/src/lib.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
#![no_std]
|
||||
#![allow(non_upper_case_globals)]
|
||||
//Include the Arduboy Library
|
||||
//Initialize the arduboy object
|
||||
#[allow(unused_imports)]
|
||||
use arduboy_rust::prelude::*;
|
||||
|
||||
// #[link_section = ".progmem.data"]
|
||||
|
||||
// Setup eeprom memory
|
||||
static mut eeprom: EEPROMBYTE = EEPROMBYTE::new(10);
|
||||
|
||||
static mut count: u8 = 0;
|
||||
|
||||
// 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();
|
||||
eeprom.init();
|
||||
arduboy.clear();
|
||||
arduboy.set_frame_rate(30);
|
||||
}
|
||||
// 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.clear();
|
||||
arduboy.poll_buttons();
|
||||
if arduboy.just_pressed(UP) {
|
||||
count += 1;
|
||||
}
|
||||
if arduboy.just_pressed(DOWN) {
|
||||
count -= 1;
|
||||
}
|
||||
if arduboy.just_pressed(A) {
|
||||
eeprom.update(count)
|
||||
}
|
||||
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.display();
|
||||
}
|
|
@ -1,27 +1,33 @@
|
|||
#![no_std]
|
||||
#![allow(non_upper_case_globals)]
|
||||
|
||||
//Include the Arduboy Library
|
||||
//Initialize the arduboy object
|
||||
#[allow(unused_imports)]
|
||||
use arduboy_rust::prelude::*;
|
||||
|
||||
// #[link_section = ".progmem.data"]
|
||||
// Progmem data
|
||||
|
||||
// Setup eeprom memory
|
||||
static mut eeprom: EEPROM = EEPROM::new(10);
|
||||
|
||||
static mut count: u8 = 0;
|
||||
static mut MEM: u8 = 0;
|
||||
// dynamic ram variables
|
||||
static e: EEPROM = EEPROM::new(10);
|
||||
struct Scorebord {
|
||||
player1: u16,
|
||||
text: &'static str,
|
||||
}
|
||||
static mut s: Scorebord = Scorebord {
|
||||
player1: 0,
|
||||
text: "lol\0",
|
||||
};
|
||||
|
||||
// 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();
|
||||
eeprom.init();
|
||||
arduboy.set_frame_rate(1);
|
||||
arduboy.clear();
|
||||
arduboy.set_frame_rate(30);
|
||||
e.init(&mut s);
|
||||
}
|
||||
|
||||
// The loop() function repeats forever after setup() is done
|
||||
#[no_mangle]
|
||||
#[export_name = "loop"]
|
||||
|
@ -30,30 +36,39 @@ pub unsafe extern "C" fn loop_() {
|
|||
if !arduboy.next_frame() {
|
||||
return;
|
||||
}
|
||||
arduboy.clear();
|
||||
arduboy.poll_buttons();
|
||||
if arduboy.just_pressed(UP) {
|
||||
count += 1;
|
||||
if arduboy.just_pressed(B) {
|
||||
s.player1 += 1;
|
||||
e.put(&s);
|
||||
}
|
||||
if arduboy.just_pressed(DOWN) {
|
||||
count -= 1;
|
||||
s.player1 -= 1;
|
||||
e.put(&s);
|
||||
}
|
||||
if arduboy.just_pressed(A) {
|
||||
unsafe { eeprom.put(count) }
|
||||
s.player1 += 1;
|
||||
e.get(&mut s);
|
||||
}
|
||||
if arduboy.just_pressed(B) {
|
||||
eeprom.get(&mut MEM)
|
||||
arduboy.clear();
|
||||
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)
|
||||
}
|
||||
arduboy.set_cursor(0, 0);
|
||||
arduboy.print(count as u16);
|
||||
|
||||
arduboy.set_cursor(0, 30);
|
||||
arduboy.print(f!(b"Memory:\0"));
|
||||
arduboy.print(MEM as u16);
|
||||
arduboy.set_cursor(0, 40);
|
||||
arduboy.print(f!(b"eeprom:\0"));
|
||||
|
||||
arduboy.print(eeprom.read() as u16);
|
||||
//e.get(&mut s);
|
||||
arduboy.print("\n\0");
|
||||
arduboy.print("eeprom save: \0");
|
||||
let ss: Scorebord = e.get_direct();
|
||||
arduboy.print(ss.player1);
|
||||
arduboy.print("\nscore save: \0");
|
||||
arduboy.print(s.player1);
|
||||
arduboy.print("\n \0");
|
||||
arduboy.print(s.text);
|
||||
|
||||
arduboy.display();
|
||||
}
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
#![no_std]
|
||||
#![allow(non_upper_case_globals)]
|
||||
use arduboy_rust::prelude::*;
|
||||
#[allow(dead_code)]
|
||||
#[repr(C)]
|
||||
struct Scorebord {
|
||||
places: [u16; 3],
|
||||
}
|
||||
impl Scorebord {
|
||||
fn check_score(&mut self, mut score: u16) -> bool {
|
||||
let res = self.places[2] < score;
|
||||
//todo
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
static mut MEM: u8 = 0;
|
||||
static SCORE: EEPROM = EEPROM::new(100);
|
||||
|
||||
static mut scoreboard: Scorebord = Scorebord { places: [0, 0, 0] };
|
||||
static eeprom: EEPROM = EEPROM::new(100);
|
||||
const WORLD_WIDTH: u8 = 32;
|
||||
const WORLD_HEIGHT: u8 = 16;
|
||||
const SCALE_FACTOR: u8 = 4;
|
||||
|
@ -13,6 +24,7 @@ enum State {
|
|||
Title,
|
||||
Game,
|
||||
Win,
|
||||
Scorebord,
|
||||
GameOver,
|
||||
Reset,
|
||||
Pause,
|
||||
|
@ -26,7 +38,7 @@ enum Direction {
|
|||
}
|
||||
struct Snake {
|
||||
game_state: State,
|
||||
points: u8,
|
||||
points: u16,
|
||||
len: u8,
|
||||
pos: [(u8, u8); 255 as usize],
|
||||
next_food: (u8, u8),
|
||||
|
@ -179,7 +191,7 @@ static mut snake: Snake = Snake {
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn setup() {
|
||||
arduboy.begin();
|
||||
SCORE.init();
|
||||
eeprom.init(&mut scoreboard);
|
||||
arduboy.init_random_seed();
|
||||
arduboy.set_frame_rate(60);
|
||||
arduboy.clear();
|
||||
|
@ -204,7 +216,8 @@ pub unsafe extern "C" fn loop_() {
|
|||
arduboy.set_text_size(2);
|
||||
arduboy.print(f!(b"RustySnake\n\0"));
|
||||
arduboy.set_text_size(1);
|
||||
arduboy.print(f!(b"\nControls: \nB for Pause\nA&B for reset\n\0"));
|
||||
arduboy.print(f!(b"\nControls: \nB for Pause\nA&B for reset\nScore: \0"));
|
||||
arduboy.print(f!(b"Press A for Scorebord\0"));
|
||||
arduboy.print(f!(b"\nZennDev 2023\n\0"));
|
||||
if A.just_pressed() {
|
||||
snake.game_state = State::Game;
|
||||
|
@ -240,28 +253,38 @@ pub unsafe extern "C" fn loop_() {
|
|||
}
|
||||
}
|
||||
State::GameOver => {
|
||||
SCORE.get(&mut MEM);
|
||||
if MEM == 255 {
|
||||
MEM = 0;
|
||||
}
|
||||
if snake.points > MEM {
|
||||
SCORE.put(snake.points);
|
||||
}
|
||||
|
||||
arduboy.set_cursor(0, 0);
|
||||
arduboy.print(f!(b"Game Over!\0"));
|
||||
arduboy.print(f!(b"\n\n\0"));
|
||||
arduboy.print(f!(b"Score: \0"));
|
||||
arduboy.print(snake.points as u16);
|
||||
if scoreboard.check_score(snake.points) {
|
||||
eeprom.put(&scoreboard);
|
||||
arduboy.print(f!(b"New Highscore!\0"));
|
||||
arduboy.print(f!(b"\n\n\0"));
|
||||
arduboy.print(f!(b"\nHigh Score: \0"));
|
||||
arduboy.print(scoreboard.places[0] as u16);
|
||||
arduboy.print(f!(b"\n\n\0"));
|
||||
arduboy.print(f!(b"Press A to Play Again\0"));
|
||||
} else {
|
||||
arduboy.print(f!(b"Game Over!\0"));
|
||||
arduboy.print(f!(b"\n\n\0"));
|
||||
arduboy.print(f!(b"Score: \0"));
|
||||
arduboy.print(snake.points as u16);
|
||||
}
|
||||
arduboy.print(f!(b"\nHigh Score: \0"));
|
||||
arduboy.print(MEM as u16);
|
||||
arduboy.print(scoreboard.places[0] as u16);
|
||||
arduboy.print(f!(b"\n\n\0"));
|
||||
arduboy.print(f!(b"Press A to Play Again\0"));
|
||||
|
||||
if A.just_pressed() {
|
||||
snake.game_state = State::Reset;
|
||||
}
|
||||
}
|
||||
State::Scorebord => {
|
||||
arduboy.set_cursor(0, 0);
|
||||
arduboy.print(f!(b"1 place: \0"));
|
||||
arduboy.print(scoreboard.places[0]);
|
||||
arduboy.print(f!(b"\n2 place: \0"));
|
||||
arduboy.print(scoreboard.places[1]);
|
||||
arduboy.print(f!(b"\n3 place: \0"));
|
||||
arduboy.print(scoreboard.places[2]);
|
||||
}
|
||||
}
|
||||
if (A | B).pressed() {
|
||||
snake.game_state = State::Reset;
|
||||
|
|
|
@ -1,131 +0,0 @@
|
|||
#include "arduboy.h"
|
||||
extern Arduboy2 arduboy;
|
||||
|
||||
void arduboy_begin(void)
|
||||
{
|
||||
arduboy.begin();
|
||||
}
|
||||
void arduboy_clear(void)
|
||||
{
|
||||
arduboy.clear();
|
||||
}
|
||||
void arduboy_display(void)
|
||||
{
|
||||
arduboy.display();
|
||||
}
|
||||
void arduboy_display_and_clear_buffer(void)
|
||||
{
|
||||
arduboy.display(CLEAR_BUFFER);
|
||||
}
|
||||
void arduboy_draw_fast_hline(int16_t x, int16_t y, uint8_t w, uint8_t color)
|
||||
{
|
||||
arduboy.drawFastHLine(x, y, w, color);
|
||||
}
|
||||
void arduboy_draw_fast_vline(int16_t x, int16_t y, uint8_t h, uint8_t color)
|
||||
{
|
||||
arduboy.drawFastVLine(x, y, h, color);
|
||||
}
|
||||
void arduboy_draw_pixel(int16_t x, int16_t y, uint8_t color)
|
||||
{
|
||||
arduboy.drawPixel(x, y, color);
|
||||
}
|
||||
void arduboy_draw_circle(int16_t x, int16_t y, uint8_t r, uint8_t color)
|
||||
{
|
||||
arduboy.drawCircle(x, y, r, color);
|
||||
}
|
||||
void arduboy_fill_circle(int16_t x, int16_t y, uint8_t r, uint8_t color)
|
||||
{
|
||||
arduboy.fillCircle(x, y, r, color);
|
||||
}
|
||||
void arduboy_fill_rect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color)
|
||||
{
|
||||
arduboy.fillRect(x, y, w, h, color);
|
||||
}
|
||||
void arduboy_draw_rect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color)
|
||||
{
|
||||
arduboy.drawRect(x, y, w, h, color);
|
||||
}
|
||||
unsigned long arduboy_generate_random_seed()
|
||||
{
|
||||
return arduboy.generateRandomSeed();
|
||||
}
|
||||
uint8_t arduboy_get_pixel(uint8_t x, uint8_t y)
|
||||
{
|
||||
return arduboy.getPixel(x, y);
|
||||
}
|
||||
void arduboy_init_random_seed(void)
|
||||
{
|
||||
arduboy.initRandomSeed();
|
||||
}
|
||||
bool arduboy_just_pressed(uint8_t button)
|
||||
{
|
||||
return arduboy.justPressed(button);
|
||||
}
|
||||
bool arduboy_just_released(uint8_t button)
|
||||
{
|
||||
return arduboy.justReleased(button);
|
||||
}
|
||||
bool arduboy_next_frame(void)
|
||||
{
|
||||
return arduboy.nextFrame();
|
||||
}
|
||||
void arduboy_poll_buttons()
|
||||
{
|
||||
arduboy.pollButtons();
|
||||
}
|
||||
bool arduboy_pressed(uint8_t buttons)
|
||||
{
|
||||
return arduboy.pressed(buttons);
|
||||
}
|
||||
void arduboy_print_chars(const char *cstr)
|
||||
{
|
||||
arduboy.print(cstr);
|
||||
}
|
||||
size_t arduboy_print_chars_progmem(const char *cstr)
|
||||
{
|
||||
return arduboy.print(reinterpret_cast<const __FlashStringHelper *>(cstr));
|
||||
}
|
||||
size_t arduboy_print_char(char c)
|
||||
{
|
||||
return arduboy.print(c);
|
||||
}
|
||||
size_t arduboy_print_int(int n, int base)
|
||||
{
|
||||
return arduboy.print(n, base);
|
||||
}
|
||||
size_t arduboy_print_long(long n, int base)
|
||||
{
|
||||
return arduboy.print(n, base);
|
||||
}
|
||||
size_t arduboy_print_unsigned_char(unsigned char n, int base)
|
||||
{
|
||||
return arduboy.print(n, base);
|
||||
}
|
||||
size_t arduboy_print_unsigned_int(unsigned int n, int base)
|
||||
{
|
||||
return arduboy.print(n, base);
|
||||
}
|
||||
size_t arduboy_print_unsigned_long(unsigned long n, int base)
|
||||
{
|
||||
return arduboy.print(n, base);
|
||||
}
|
||||
void arduboy_set_cursor(int16_t x, int16_t y)
|
||||
{
|
||||
arduboy.setCursor(x, y);
|
||||
}
|
||||
void arduboy_set_frame_rate(uint8_t rate)
|
||||
{
|
||||
arduboy.setFrameRate(rate);
|
||||
}
|
||||
bool arduboy_not_pressed(uint8_t button)
|
||||
{
|
||||
arduboy.notPressed(button);
|
||||
}
|
||||
void arduboy_set_text_size(uint8_t s)
|
||||
{
|
||||
arduboy.setTextSize(s);
|
||||
}
|
||||
void arduboy_invert(bool inverse)
|
||||
{
|
||||
arduboy.invert(inverse);
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
#pragma once
|
||||
#include <Arduboy2.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void arduboy_begin(void);
|
||||
void arduboy_clear(void);
|
||||
void arduboy_display(void);
|
||||
void arduboy_display_and_clear_buffer(void);
|
||||
void arduboy_draw_fast_hline(int16_t x, int16_t y, uint8_t w, uint8_t color);
|
||||
void arduboy_draw_fast_vline(int16_t x, int16_t y, uint8_t h, uint8_t color);
|
||||
void arduboy_draw_pixel(int16_t x, int16_t y, uint8_t color);
|
||||
void arduboy_draw_circle(int16_t x, int16_t y, uint8_t r, uint8_t color);
|
||||
void arduboy_fill_circle(int16_t x, int16_t y, uint8_t r, uint8_t color);
|
||||
void arduboy_draw_rect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color);
|
||||
void arduboy_fill_rect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color);
|
||||
unsigned long arduboy_generate_random_seed();
|
||||
uint8_t arduboy_get_pixel(uint8_t x, uint8_t y);
|
||||
void arduboy_init_random_seed(void);
|
||||
bool arduboy_just_pressed(uint8_t button);
|
||||
bool arduboy_just_released(uint8_t button);
|
||||
bool arduboy_next_frame(void);
|
||||
void arduboy_poll_buttons();
|
||||
bool arduboy_pressed(uint8_t buttons);
|
||||
void arduboy_print_chars(const char *cstr);
|
||||
size_t arduboy_print_char(char c);
|
||||
size_t arduboy_print_chars_progmem(const char *);
|
||||
size_t arduboy_print_int(int n, int base);
|
||||
size_t arduboy_print_long(long n, int base);
|
||||
size_t arduboy_print_unsigned_char(unsigned char n, int base);
|
||||
size_t arduboy_print_unsigned_int(unsigned int n, int base);
|
||||
size_t arduboy_print_unsigned_long(unsigned long n, int base);
|
||||
void arduboy_set_cursor(int16_t x, int16_t y);
|
||||
void arduboy_set_frame_rate(uint8_t rate);
|
||||
bool arduboy_not_pressed(uint8_t button);
|
||||
void arduboy_set_text_size(uint8_t s);
|
||||
void arduboy_invert(bool inverse);
|
||||
}
|
134
Wrapper-Project/src/library/arduboy/arduboy_export.h
Normal file
134
Wrapper-Project/src/library/arduboy/arduboy_export.h
Normal file
|
@ -0,0 +1,134 @@
|
|||
#pragma once
|
||||
#include <Arduboy2.h>
|
||||
extern Arduboy2 arduboy;
|
||||
extern "C"
|
||||
{
|
||||
void arduboy_begin(void)
|
||||
{
|
||||
arduboy.begin();
|
||||
}
|
||||
void arduboy_clear(void)
|
||||
{
|
||||
arduboy.clear();
|
||||
}
|
||||
void arduboy_display(void)
|
||||
{
|
||||
arduboy.display();
|
||||
}
|
||||
void arduboy_display_and_clear_buffer(void)
|
||||
{
|
||||
arduboy.display(CLEAR_BUFFER);
|
||||
}
|
||||
void arduboy_draw_fast_hline(int16_t x, int16_t y, uint8_t w, uint8_t color)
|
||||
{
|
||||
arduboy.drawFastHLine(x, y, w, color);
|
||||
}
|
||||
void arduboy_draw_fast_vline(int16_t x, int16_t y, uint8_t h, uint8_t color)
|
||||
{
|
||||
arduboy.drawFastVLine(x, y, h, color);
|
||||
}
|
||||
void arduboy_draw_pixel(int16_t x, int16_t y, uint8_t color)
|
||||
{
|
||||
arduboy.drawPixel(x, y, color);
|
||||
}
|
||||
void arduboy_draw_circle(int16_t x, int16_t y, uint8_t r, uint8_t color)
|
||||
{
|
||||
arduboy.drawCircle(x, y, r, color);
|
||||
}
|
||||
void arduboy_fill_circle(int16_t x, int16_t y, uint8_t r, uint8_t color)
|
||||
{
|
||||
arduboy.fillCircle(x, y, r, color);
|
||||
}
|
||||
void arduboy_fill_rect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color)
|
||||
{
|
||||
arduboy.fillRect(x, y, w, h, color);
|
||||
}
|
||||
void arduboy_draw_rect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color)
|
||||
{
|
||||
arduboy.drawRect(x, y, w, h, color);
|
||||
}
|
||||
unsigned long arduboy_generate_random_seed()
|
||||
{
|
||||
return arduboy.generateRandomSeed();
|
||||
}
|
||||
uint8_t arduboy_get_pixel(uint8_t x, uint8_t y)
|
||||
{
|
||||
return arduboy.getPixel(x, y);
|
||||
}
|
||||
void arduboy_init_random_seed(void)
|
||||
{
|
||||
arduboy.initRandomSeed();
|
||||
}
|
||||
bool arduboy_just_pressed(uint8_t button)
|
||||
{
|
||||
return arduboy.justPressed(button);
|
||||
}
|
||||
bool arduboy_just_released(uint8_t button)
|
||||
{
|
||||
return arduboy.justReleased(button);
|
||||
}
|
||||
bool arduboy_next_frame(void)
|
||||
{
|
||||
return arduboy.nextFrame();
|
||||
}
|
||||
void arduboy_poll_buttons()
|
||||
{
|
||||
arduboy.pollButtons();
|
||||
}
|
||||
bool arduboy_pressed(uint8_t buttons)
|
||||
{
|
||||
return arduboy.pressed(buttons);
|
||||
}
|
||||
void arduboy_print_chars(const char *cstr)
|
||||
{
|
||||
arduboy.print(cstr);
|
||||
}
|
||||
size_t arduboy_print_chars_progmem(const char *cstr)
|
||||
{
|
||||
return arduboy.print(reinterpret_cast<const __FlashStringHelper *>(cstr));
|
||||
}
|
||||
size_t arduboy_print_char(char c)
|
||||
{
|
||||
return arduboy.print(c);
|
||||
}
|
||||
size_t arduboy_print_int(int n, int base)
|
||||
{
|
||||
return arduboy.print(n, base);
|
||||
}
|
||||
size_t arduboy_print_long(long n, int base)
|
||||
{
|
||||
return arduboy.print(n, base);
|
||||
}
|
||||
size_t arduboy_print_unsigned_char(unsigned char n, int base)
|
||||
{
|
||||
return arduboy.print(n, base);
|
||||
}
|
||||
size_t arduboy_print_unsigned_int(unsigned int n, int base)
|
||||
{
|
||||
return arduboy.print(n, base);
|
||||
}
|
||||
size_t arduboy_print_unsigned_long(unsigned long n, int base)
|
||||
{
|
||||
return arduboy.print(n, base);
|
||||
}
|
||||
void arduboy_set_cursor(int16_t x, int16_t y)
|
||||
{
|
||||
arduboy.setCursor(x, y);
|
||||
}
|
||||
void arduboy_set_frame_rate(uint8_t rate)
|
||||
{
|
||||
arduboy.setFrameRate(rate);
|
||||
}
|
||||
bool arduboy_not_pressed(uint8_t button)
|
||||
{
|
||||
arduboy.notPressed(button);
|
||||
}
|
||||
void arduboy_set_text_size(uint8_t s)
|
||||
{
|
||||
arduboy.setTextSize(s);
|
||||
}
|
||||
void arduboy_invert(bool inverse)
|
||||
{
|
||||
arduboy.invert(inverse);
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
#include "arduboy_tones.h"
|
||||
|
||||
void arduboy_audio_on()
|
||||
{
|
||||
arduboy.audio.on();
|
||||
}
|
||||
void arduboy_audio_off()
|
||||
{
|
||||
arduboy.audio.off();
|
||||
}
|
||||
void arduboy_audio_toggle()
|
||||
{
|
||||
arduboy.audio.toggle();
|
||||
}
|
||||
void arduboy_audio_save_on_off()
|
||||
{
|
||||
arduboy.audio.saveOnOff();
|
||||
}
|
||||
bool arduboy_audio_enabled()
|
||||
{
|
||||
return arduboy.audio.enabled();
|
||||
}
|
||||
void sound_tone(unsigned int frequency, unsigned long duration)
|
||||
{
|
||||
sound.tone(frequency, duration);
|
||||
}
|
||||
void sound_tone2(unsigned int frequency1, unsigned long duration1, unsigned int frequency2, unsigned long duration2)
|
||||
{
|
||||
sound.tone(frequency1, duration1, frequency2, duration2);
|
||||
}
|
||||
void sound_tone3(unsigned int frequency1, unsigned long duration1, unsigned int frequency2, unsigned long duration2, unsigned int frequency3, unsigned long duration3)
|
||||
{
|
||||
sound.tone(frequency1, duration1, frequency2, duration2, frequency3, duration3);
|
||||
}
|
||||
void sound_tones(const uint16_t *tones)
|
||||
{
|
||||
sound.tones(tones);
|
||||
}
|
||||
void sound_no_tone()
|
||||
{
|
||||
sound.noTone();
|
||||
}
|
||||
bool sound_playing()
|
||||
{
|
||||
sound.playing();
|
||||
}
|
||||
void sound_tones_in_ram(uint16_t *tones)
|
||||
{
|
||||
sound.tonesInRAM(tones);
|
||||
}
|
||||
void sound_volume_mode(uint8_t mode)
|
||||
{
|
||||
sound.volumeMode(mode);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <ArduboyTones.h>
|
||||
#include <Arduboy2.h>
|
||||
extern ArduboyTones sound;
|
||||
extern Arduboy2 arduboy;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void arduboy_audio_on();
|
||||
void arduboy_audio_off();
|
||||
bool arduboy_audio_enabled();
|
||||
void arduboy_audio_toggle();
|
||||
void arduboy_audio_save_on_off();
|
||||
void sound_tone(unsigned int frequency, unsigned long duration);
|
||||
void sound_tone2(unsigned int frequency1, unsigned long duration1, unsigned int frequency2, unsigned long duration2);
|
||||
void sound_tone3(unsigned int frequency1, unsigned long duration1, unsigned int frequency2, unsigned long duration2, unsigned int frequency3, unsigned long duration3);
|
||||
void sound_tones(const uint16_t *tones);
|
||||
void sound_no_tone();
|
||||
bool sound_playing();
|
||||
void sound_tones_in_ram(uint16_t *tones);
|
||||
void sound_volume_mode(uint8_t mode);
|
||||
}
|
62
Wrapper-Project/src/library/arduboy/arduboy_tones_export.h
Normal file
62
Wrapper-Project/src/library/arduboy/arduboy_tones_export.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
#pragma once
|
||||
|
||||
#include <ArduboyTones.h>
|
||||
#include <Arduboy2.h>
|
||||
extern ArduboyTones sound;
|
||||
extern Arduboy2 arduboy;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void arduboy_audio_on()
|
||||
{
|
||||
arduboy.audio.on();
|
||||
}
|
||||
void arduboy_audio_off()
|
||||
{
|
||||
arduboy.audio.off();
|
||||
}
|
||||
void arduboy_audio_toggle()
|
||||
{
|
||||
arduboy.audio.toggle();
|
||||
}
|
||||
void arduboy_audio_save_on_off()
|
||||
{
|
||||
arduboy.audio.saveOnOff();
|
||||
}
|
||||
bool arduboy_audio_enabled()
|
||||
{
|
||||
return arduboy.audio.enabled();
|
||||
}
|
||||
void sound_tone(unsigned int frequency, unsigned long duration)
|
||||
{
|
||||
sound.tone(frequency, duration);
|
||||
}
|
||||
void sound_tone2(unsigned int frequency1, unsigned long duration1, unsigned int frequency2, unsigned long duration2)
|
||||
{
|
||||
sound.tone(frequency1, duration1, frequency2, duration2);
|
||||
}
|
||||
void sound_tone3(unsigned int frequency1, unsigned long duration1, unsigned int frequency2, unsigned long duration2, unsigned int frequency3, unsigned long duration3)
|
||||
{
|
||||
sound.tone(frequency1, duration1, frequency2, duration2, frequency3, duration3);
|
||||
}
|
||||
void sound_tones(const uint16_t *tones)
|
||||
{
|
||||
sound.tones(tones);
|
||||
}
|
||||
void sound_no_tone()
|
||||
{
|
||||
sound.noTone();
|
||||
}
|
||||
bool sound_playing()
|
||||
{
|
||||
sound.playing();
|
||||
}
|
||||
void sound_tones_in_ram(uint16_t *tones)
|
||||
{
|
||||
sound.tonesInRAM(tones);
|
||||
}
|
||||
void sound_volume_mode(uint8_t mode)
|
||||
{
|
||||
sound.volumeMode(mode);
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#include "sprites.h"
|
||||
|
||||
void arduino_draw_override(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame)
|
||||
{
|
||||
Sprites::drawOverwrite(x, y, bitmap, frame);
|
||||
}
|
||||
void arduino_draw_external_mask(int16_t x, int16_t y, const uint8_t *bitmap,
|
||||
const uint8_t *mask, uint8_t frame, uint8_t mask_frame)
|
||||
{
|
||||
Sprites::drawExternalMask(x, y, bitmap, mask, frame, mask_frame);
|
||||
}
|
||||
void arduino_draw_plus_mask(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame)
|
||||
{
|
||||
Sprites::drawPlusMask(x, y, bitmap, frame);
|
||||
}
|
||||
void arduino_draw_erase(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame)
|
||||
{
|
||||
Sprites::drawErase(x, y, bitmap, frame);
|
||||
}
|
||||
void arduino_draw_self_masked(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame)
|
||||
{
|
||||
Sprites::drawSelfMasked(x, y, bitmap, frame);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#pragma once
|
||||
#include <Sprites.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void arduino_draw_override(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame);
|
||||
void arduino_draw_external_mask(int16_t x, int16_t y, const uint8_t *bitmap,
|
||||
const uint8_t *mask, uint8_t frame, uint8_t mask_frame);
|
||||
void arduino_draw_plus_mask(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame);
|
||||
void arduino_draw_erase(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame);
|
||||
void arduino_draw_self_masked(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame);
|
||||
}
|
27
Wrapper-Project/src/library/arduboy/sprites_export.h
Normal file
27
Wrapper-Project/src/library/arduboy/sprites_export.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
#include <Sprites.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void arduino_draw_override(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame)
|
||||
{
|
||||
Sprites::drawOverwrite(x, y, bitmap, frame);
|
||||
}
|
||||
void arduino_draw_external_mask(int16_t x, int16_t y, const uint8_t *bitmap,
|
||||
const uint8_t *mask, uint8_t frame, uint8_t mask_frame)
|
||||
{
|
||||
Sprites::drawExternalMask(x, y, bitmap, mask, frame, mask_frame);
|
||||
}
|
||||
void arduino_draw_plus_mask(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame)
|
||||
{
|
||||
Sprites::drawPlusMask(x, y, bitmap, frame);
|
||||
}
|
||||
void arduino_draw_erase(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame)
|
||||
{
|
||||
Sprites::drawErase(x, y, bitmap, frame);
|
||||
}
|
||||
void arduino_draw_self_masked(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t frame)
|
||||
{
|
||||
Sprites::drawSelfMasked(x, y, bitmap, frame);
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
#include "arduino.h"
|
||||
|
||||
long arduino_random_between(long min, long max)
|
||||
{
|
||||
return random(min, max);
|
||||
}
|
||||
long arduino_random_less_than(long max)
|
||||
{
|
||||
return random(max);
|
||||
}
|
||||
void arduino_delay(unsigned long ms)
|
||||
{
|
||||
delay(ms);
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
#pragma once
|
||||
#include <Arduboy2.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
long arduino_random_between(long min, long max);
|
||||
long arduino_random_less_than(long max);
|
||||
void arduino_delay(unsigned long ms);
|
||||
}
|
18
Wrapper-Project/src/library/arduino/arduino_export.h
Normal file
18
Wrapper-Project/src/library/arduino/arduino_export.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
#include <Arduboy2.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
long arduino_random_between(long min, long max)
|
||||
{
|
||||
return random(min, max);
|
||||
}
|
||||
long arduino_random_less_than(long max)
|
||||
{
|
||||
return random(max);
|
||||
}
|
||||
void arduino_delay(unsigned long ms)
|
||||
{
|
||||
delay(ms);
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
#include "eeprom.h"
|
||||
|
||||
int eeprom;
|
||||
|
||||
uint8_t arduboy_eeprom_read(int idx)
|
||||
{
|
||||
eeprom = EEPROM.read(idx);
|
||||
return eeprom;
|
||||
}
|
||||
void arduboy_eeprom_update(int idx, uint8_t val)
|
||||
{
|
||||
EEPROM.update(idx, val);
|
||||
}
|
||||
void arduboy_eeprom_write(int idx, uint8_t val)
|
||||
{
|
||||
EEPROM.write(idx, val);
|
||||
}
|
||||
uint8_t arduboy_eeprom_get(int idx)
|
||||
{
|
||||
EEPROM.get(idx, eeprom);
|
||||
return eeprom;
|
||||
}
|
||||
void arduboy_eeprom_put(int idx, uint8_t val)
|
||||
{
|
||||
EEPROM.put(idx, val);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <EEPROM.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
uint8_t arduboy_eeprom_read(int idx);
|
||||
void arduboy_eeprom_update(int idx, uint8_t val);
|
||||
void arduboy_eeprom_write(int idx, uint8_t val);
|
||||
uint8_t arduboy_eeprom_get(int idx);
|
||||
void arduboy_eeprom_put(int idx, uint8_t val);
|
||||
}
|
26
Wrapper-Project/src/library/arduino/eeprom_export.h
Normal file
26
Wrapper-Project/src/library/arduino/eeprom_export.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
#include <avr/eeprom.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
uint8_t arduboy_eeprom_read(int idx)
|
||||
{
|
||||
return eeprom_read_byte(reinterpret_cast<const uint8_t *>(idx));
|
||||
}
|
||||
void arduboy_eeprom_update(int idx, uint8_t val)
|
||||
{
|
||||
eeprom_update_byte(reinterpret_cast<uint8_t *>(idx), val);
|
||||
}
|
||||
void arduboy_eeprom_write(int idx, uint8_t val)
|
||||
{
|
||||
eeprom_write_byte(reinterpret_cast<uint8_t *>(idx), val);
|
||||
}
|
||||
void arduboy_eeprom_get(uint16_t address, uint8_t *object, size_t size)
|
||||
{
|
||||
eeprom_read_block(object, reinterpret_cast<const uint8_t *>(address), size);
|
||||
}
|
||||
void arduboy_eeprom_put(uint16_t address, const uint8_t *object, size_t size)
|
||||
{
|
||||
eeprom_update_block(object, reinterpret_cast<uint8_t *>(address), size);
|
||||
}
|
||||
}
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include <Arduboy2.h>
|
||||
#include <ArduboyTones.h>
|
||||
#include "./library/arduboy/arduboy.h"
|
||||
#include "./library/arduboy/sprites.h"
|
||||
#include "./library/arduboy/arduboy_tones.h"
|
||||
#include "./library/arduino/arduino.h"
|
||||
#include "./library/arduino/eeprom.h"
|
||||
#include "./library/arduboy/arduboy_export.h"
|
||||
#include "./library/arduboy/sprites_export.h"
|
||||
#include "./library/arduboy/arduboy_tones_export.h"
|
||||
#include "./library/arduino/arduino_export.h"
|
||||
#include "./library/arduino/eeprom_export.h"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use core::ffi::{c_int, c_uchar};
|
||||
|
||||
pub const EEPROM_STORAGE_SPACE_START: c_int = 16;
|
||||
pub const EEPROM_STORAGE_SPACE_START: i16 = 16;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "arduboy_eeprom_read"]
|
||||
|
@ -10,15 +10,31 @@ extern "C" {
|
|||
#[link_name = "arduboy_eeprom_write"]
|
||||
fn arduboy_eeprom_write_raw(idx: c_int, val: c_uchar);
|
||||
#[link_name = "arduboy_eeprom_get"]
|
||||
fn arduboy_eeprom_get_raw(idx: c_int) -> c_uchar;
|
||||
fn arduboy_eeprom_get_raw(idx: c_int, object: *mut u8, size: usize);
|
||||
#[link_name = "arduboy_eeprom_put"]
|
||||
fn arduboy_eeprom_put_raw(idx: c_int, val: c_uchar);
|
||||
fn arduboy_eeprom_put_raw(idx: c_int, object: *const u8, size: usize);
|
||||
}
|
||||
///This is the struct to interact in a save way with the EEPROM C++ library.
|
||||
///This struct to store and read structs objects to eeprom memory.
|
||||
/// ## Example
|
||||
/// ```
|
||||
/// static e: EEPROM = EEPROM::new(10);
|
||||
/// struct Scorebord {
|
||||
/// player1: u16,
|
||||
/// text: &'static str,
|
||||
/// }
|
||||
/// static mut s: Scorebord = Scorebord {
|
||||
/// player1: 0,
|
||||
/// text: "lol\0",
|
||||
/// };
|
||||
///
|
||||
/// // init inside of the setup function
|
||||
/// e.init(&mut s);
|
||||
/// }
|
||||
/// ```
|
||||
pub struct EEPROM {
|
||||
start_c1: i16,
|
||||
start_c2: i16,
|
||||
pub idx: i16,
|
||||
idx: i16,
|
||||
}
|
||||
impl EEPROM {
|
||||
pub const fn new(mut idx: i16) -> EEPROM {
|
||||
|
@ -31,24 +47,90 @@ impl EEPROM {
|
|||
idx: EEPROM_STORAGE_SPACE_START + idx + 2,
|
||||
}
|
||||
}
|
||||
pub fn init(&self) {
|
||||
let c1 = self.read_start_c1();
|
||||
let c2 = self.read_start_c2();
|
||||
pub fn init<T>(&self, your_struct: &mut T) {
|
||||
let c1 = self.read(self.start_c1);
|
||||
let c2 = self.read(self.start_c2);
|
||||
|
||||
if c1 != b'Z' || c2 != b'D' {
|
||||
self.update(b'Z');
|
||||
self.update(b'D');
|
||||
self.update(self.start_c1, b'Z');
|
||||
self.update(self.start_c2, b'D');
|
||||
self.put(your_struct);
|
||||
};
|
||||
self.get(your_struct)
|
||||
}
|
||||
fn read(&self, idx: i16) -> u8 {
|
||||
unsafe { arduboy_eeprom_read_raw(idx) }
|
||||
}
|
||||
fn update(&self, idx: i16, val: u8) {
|
||||
unsafe { arduboy_eeprom_update_raw(idx, val) }
|
||||
}
|
||||
pub fn get<T>(&self, your_struct: &mut T) {
|
||||
let pointer = your_struct as *mut T;
|
||||
let object_pointer = pointer as *mut u8;
|
||||
let object_size = core::mem::size_of::<T>();
|
||||
|
||||
unsafe {
|
||||
arduboy_eeprom_get_raw(self.idx, object_pointer, object_size);
|
||||
};
|
||||
}
|
||||
pub fn get_direct<T>(&self) -> T {
|
||||
let mut buffer = core::mem::MaybeUninit::<T>::uninit();
|
||||
|
||||
let pointer = buffer.as_mut_ptr();
|
||||
let object_pointer = pointer as *mut u8;
|
||||
let object_size = core::mem::size_of::<T>();
|
||||
|
||||
unsafe {
|
||||
arduboy_eeprom_get_raw(self.idx, object_pointer, object_size);
|
||||
};
|
||||
|
||||
return unsafe { buffer.assume_init() };
|
||||
}
|
||||
pub fn put<T>(&self, your_struct: &T) {
|
||||
let pointer = your_struct as *const T;
|
||||
let object_pointer = pointer as *const u8;
|
||||
let object_size = core::mem::size_of::<T>();
|
||||
|
||||
unsafe {
|
||||
arduboy_eeprom_put_raw(self.idx, object_pointer, object_size);
|
||||
};
|
||||
}
|
||||
}
|
||||
///Use this struct to store and read single bytes to/from eeprom memory.
|
||||
pub struct EEPROMBYTE {
|
||||
start_c1: i16,
|
||||
start_c2: i16,
|
||||
idx: i16,
|
||||
}
|
||||
impl EEPROMBYTE {
|
||||
pub const fn new(mut idx: i16) -> EEPROMBYTE {
|
||||
if idx > 1010 {
|
||||
idx = 0
|
||||
}
|
||||
EEPROMBYTE {
|
||||
start_c1: EEPROM_STORAGE_SPACE_START + idx,
|
||||
start_c2: EEPROM_STORAGE_SPACE_START + idx + 1,
|
||||
idx: EEPROM_STORAGE_SPACE_START + idx + 2,
|
||||
}
|
||||
}
|
||||
pub fn init(&self) {
|
||||
let c1 = self.read_intern(self.start_c1);
|
||||
let c2 = self.read_intern(self.start_c2);
|
||||
|
||||
if c1 != b'Z' || c2 != b'D' {
|
||||
self.update_intern(self.start_c1, b'Z');
|
||||
self.update_intern(self.start_c2, b'D');
|
||||
self.update(0);
|
||||
};
|
||||
}
|
||||
fn read_intern(&self, idx: i16) -> u8 {
|
||||
unsafe { arduboy_eeprom_read_raw(idx) }
|
||||
}
|
||||
pub fn read(&self) -> u8 {
|
||||
unsafe { arduboy_eeprom_read_raw(self.idx) }
|
||||
}
|
||||
fn read_start_c1(&self) -> u8 {
|
||||
unsafe { arduboy_eeprom_read_raw(self.start_c1) }
|
||||
}
|
||||
fn read_start_c2(&self) -> u8 {
|
||||
unsafe { arduboy_eeprom_read_raw(self.start_c2) }
|
||||
fn update_intern(&self, idx: i16, val: u8) {
|
||||
unsafe { arduboy_eeprom_update_raw(idx, val) }
|
||||
}
|
||||
pub fn update(&self, val: u8) {
|
||||
unsafe { arduboy_eeprom_update_raw(self.idx, val) }
|
||||
|
@ -56,10 +138,4 @@ impl EEPROM {
|
|||
pub fn write(&self, val: u8) {
|
||||
unsafe { arduboy_eeprom_write_raw(self.idx, val) }
|
||||
}
|
||||
pub fn get(&self, buffer: &mut u8) {
|
||||
*buffer = unsafe { arduboy_eeprom_get_raw(self.idx) }
|
||||
}
|
||||
pub fn put(&self, val: u8) {
|
||||
unsafe { arduboy_eeprom_put_raw(self.idx, val) }
|
||||
}
|
||||
}
|
||||
|
|
71
arduboy-rust/src/library/eepromold.rs
Normal file
71
arduboy-rust/src/library/eepromold.rs
Normal file
|
@ -0,0 +1,71 @@
|
|||
use core::ffi::{c_int, c_uchar};
|
||||
|
||||
pub const EEPROM_STORAGE_SPACE_START: c_int = 16;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "arduboy_eeprom_read"]
|
||||
fn arduboy_eeprom_read_raw(idx: c_int) -> c_uchar;
|
||||
#[link_name = "arduboy_eeprom_update"]
|
||||
fn arduboy_eeprom_update_raw(idx: c_int, val: c_uchar);
|
||||
#[link_name = "arduboy_eeprom_write"]
|
||||
fn arduboy_eeprom_write_raw(idx: c_int, val: c_uchar);
|
||||
#[link_name = "arduboy_eeprom_get"]
|
||||
fn arduboy_eeprom_get_raw(idx: c_int) -> c_uchar;
|
||||
#[link_name = "arduboy_eeprom_put"]
|
||||
fn arduboy_eeprom_put_raw(idx: c_int, val: c_uchar);
|
||||
}
|
||||
///This is the struct to interact in a save way with the EEPROM C++ library.
|
||||
pub struct EEPROM {
|
||||
start_c1: i16,
|
||||
start_c2: i16,
|
||||
pub idx: i16,
|
||||
}
|
||||
impl EEPROM {
|
||||
pub const fn new(mut idx: i16) -> EEPROM {
|
||||
if idx > 950 {
|
||||
idx = 0
|
||||
}
|
||||
EEPROM {
|
||||
start_c1: EEPROM_STORAGE_SPACE_START + idx,
|
||||
start_c2: EEPROM_STORAGE_SPACE_START + idx + 1,
|
||||
idx: EEPROM_STORAGE_SPACE_START + idx + 2,
|
||||
}
|
||||
}
|
||||
pub fn init(&self) {
|
||||
let c1 = self.read_start_c1();
|
||||
let c2 = self.read_start_c2();
|
||||
|
||||
if c1 != b'Z' || c2 != b'D' {
|
||||
self.update_start_c1(b'Z');
|
||||
self.update_start_c2(b'D');
|
||||
self.update(0);
|
||||
};
|
||||
}
|
||||
pub fn read(&self) -> u8 {
|
||||
unsafe { arduboy_eeprom_read_raw(self.idx) }
|
||||
}
|
||||
pub fn read_start_c1(&self) -> u8 {
|
||||
unsafe { arduboy_eeprom_read_raw(self.start_c1) }
|
||||
}
|
||||
pub fn read_start_c2(&self) -> u8 {
|
||||
unsafe { arduboy_eeprom_read_raw(self.start_c2) }
|
||||
}
|
||||
pub fn update(&self, val: u8) {
|
||||
unsafe { arduboy_eeprom_update_raw(self.idx, val) }
|
||||
}
|
||||
pub fn update_start_c1(&self, val: u8) {
|
||||
unsafe { arduboy_eeprom_update_raw(self.start_c1, val) }
|
||||
}
|
||||
pub fn update_start_c2(&self, val: u8) {
|
||||
unsafe { arduboy_eeprom_update_raw(self.start_c2, val) }
|
||||
}
|
||||
pub fn write(&self, val: u8) {
|
||||
unsafe { arduboy_eeprom_write_raw(self.idx, val) }
|
||||
}
|
||||
pub fn get(&self, buffer: &mut u8) {
|
||||
*buffer = unsafe { arduboy_eeprom_get_raw(self.idx) }
|
||||
}
|
||||
pub fn put(&self, val: u8) {
|
||||
unsafe { arduboy_eeprom_put_raw(self.idx, val) }
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ pub use crate::library::arduboy::{Color, Point, Rect, FONT_SIZE, HEIGHT, WIDTH};
|
|||
pub use crate::library::arduboy_tone::*;
|
||||
pub use crate::library::arduino::*;
|
||||
pub use crate::library::c::*;
|
||||
pub use crate::library::eeprom::EEPROM;
|
||||
pub use crate::library::eeprom::{EEPROM, EEPROMBYTE};
|
||||
pub use crate::library::progmem::Pstring;
|
||||
pub use crate::library::sprites;
|
||||
pub use crate::print::*;
|
||||
|
|
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" = "eeprom-byte" ]
|
||||
then
|
||||
cargo build -p eeprom-byte-demo --release && cp ./target/arduboy/release/libeeprom_byte_demo.a ./Wrapper-Project/lib/libgame.a && cd Wrapper-Project/ && pio run -v -t upload && cp ./.pio/build/arduboy/firmware.hex ./.pio/build/eeprom-byte.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 ..
|
||||
|
|
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%==eeprom-byte (
|
||||
powershell -Command "cargo build -p eeprom-byte-demo --release; cp ./target/arduboy/release/libeeprom_byte_demo.a ./Wrapper-Project/lib/libgame.a; cd Wrapper-Project/; pio run -v -t upload; cp ./.pio/build/arduboy/firmware.hex ./.pio/build/eeprom-byte.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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue