From 7da07df0f780166f8426f35ff9467b53a6eed17d Mon Sep 17 00:00:00 2001 From: PrimmR Date: Sat, 9 Sep 2023 18:04:08 +0100 Subject: [PATCH 1/5] EEPROMBYTECHECKLESS --- arduboy-rust/src/library/eeprom.rs | 25 +++++++++++++++++++++++++ arduboy-rust/src/prelude.rs | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arduboy-rust/src/library/eeprom.rs b/arduboy-rust/src/library/eeprom.rs index 85bb969..ae0d8e6 100644 --- a/arduboy-rust/src/library/eeprom.rs +++ b/arduboy-rust/src/library/eeprom.rs @@ -138,3 +138,28 @@ impl EEPROMBYTE { unsafe { arduboy_eeprom_write_raw(self.idx, val) } } } + +pub struct EEPROMBYTECHECKLESS { + idx: i16, +} +impl EEPROMBYTECHECKLESS { + pub const fn new(mut idx: i16) -> EEPROMBYTECHECKLESS { + if idx > 1010 { + idx = 0 + } + EEPROMBYTECHECKLESS { + idx: EEPROM_STORAGE_SPACE_START + idx, + } + } + pub fn init(&self) { + } + pub fn read(&self) -> u8 { + unsafe { arduboy_eeprom_read_raw(self.idx) } + } + pub fn update(&self, val: u8) { + unsafe { arduboy_eeprom_update_raw(self.idx, val) } + } + pub fn write(&self, val: u8) { + unsafe { arduboy_eeprom_write_raw(self.idx, val) } + } +} diff --git a/arduboy-rust/src/prelude.rs b/arduboy-rust/src/prelude.rs index cbefac7..c57da9a 100644 --- a/arduboy-rust/src/prelude.rs +++ b/arduboy-rust/src/prelude.rs @@ -13,7 +13,7 @@ pub use crate::library::arduboy2::{self, *}; pub use crate::library::arduboy_tone::{self, ArduboyTones}; pub use crate::library::arduino::*; pub use crate::library::c::*; -pub use crate::library::eeprom::{EEPROM, EEPROMBYTE}; +pub use crate::library::eeprom::{EEPROM, EEPROMBYTE, EEPROMBYTECHECKLESS}; #[doc(hidden)] pub use crate::library::progmem::Pstring; pub use crate::library::sprites; From 360f7a79a1a35461ccb899847a034eeacab3c9a1 Mon Sep 17 00:00:00 2001 From: PrimmR Date: Sat, 9 Sep 2023 18:08:01 +0100 Subject: [PATCH 2/5] arduboy_set_rgb_led --- .../Wrapper-Project/src/library/arduboy/arduboy_export.h | 4 ++++ arduboy-rust/src/library/arduboy2.rs | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/arduboy-rust/Wrapper-Project/src/library/arduboy/arduboy_export.h b/arduboy-rust/Wrapper-Project/src/library/arduboy/arduboy_export.h index d558b9d..263ba5d 100644 --- a/arduboy-rust/Wrapper-Project/src/library/arduboy/arduboy_export.h +++ b/arduboy-rust/Wrapper-Project/src/library/arduboy/arduboy_export.h @@ -192,4 +192,8 @@ extern "C" { arduboy.digitalWriteRGB(red, green, blue); } + void arduboy_set_rgb_led(uint8_t red, uint8_t green, uint8_t blue) + { + arduboy.setRGBled(red, green, blue); + } } \ No newline at end of file diff --git a/arduboy-rust/src/library/arduboy2.rs b/arduboy-rust/src/library/arduboy2.rs index 0a72b9f..6c57423 100644 --- a/arduboy-rust/src/library/arduboy2.rs +++ b/arduboy-rust/src/library/arduboy2.rs @@ -501,6 +501,10 @@ impl Arduboy2 { pub fn digital_write_rgb(&self, red: u8, green: u8, blue: u8) { unsafe { digital_write_rgb(red, green, blue) } } + + pub fn set_rgb_led(&self, red: u8, green: u8, blue: u8) { + unsafe { set_rgb_led(red, green, blue) } + } ///Indicate if the specified number of frames has elapsed. /// ///Parameters @@ -753,4 +757,7 @@ extern "C" { #[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"] + fn set_rgb_led(red: c_uchar, green: c_uchar, blue: c_uchar); } From afa19a67dca0055396a18fd8e77acbe1cf67b2e7 Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 11 Sep 2023 09:24:37 +0200 Subject: [PATCH 3/5] added support to create new projects --- Cargo.lock | 7 ++++++ Cargo.toml | 1 + README.md | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ run | 5 ++-- run.bat | 2 +- 5 files changed, 86 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e93f88..2b0b7d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,6 +31,13 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "cracker" +version = "0.1.0" +dependencies = [ + "arduboy-rust", +] + [[package]] name = "critical-section" version = "1.1.2" diff --git a/Cargo.toml b/Cargo.toml index 535e69e..5154ab3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,6 @@ members = [ "Examples/rustacean", "Examples/snake", "Project/game", + "Project/cracker", ] resolver = "2" diff --git a/README.md b/README.md index 0467f15..a92b745 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,80 @@ Windows: .\run.bat tone ``` +# Create a new project + +In the root of the repo use the command: + +(Don't use "-" in the name because of a cargo feature that takes the "-" and mixes sometimes with a "\_". You will have some weird behavior with the run tool.) + +```bash +cargo new --lib ./Project/newproject +``` + +Then open the Cargo.toml in your new project and add the following dependencies and settings: + +```toml +[lib] +crate-type = ["staticlib"] + +[dependencies] + +arduboy-rust = { path = "../../arduboy-rust" } +``` + +Next jump in your lib.rs file and add the following: + +```rust +#![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: +} +``` + +Now the last step. Go in the Cargo.toml in the root directory and add your project: + +```toml +[workspace] +members = [ + {All other Projects...} + "Project/newproject", +] +resolver = "2" +``` + +To run and upload your game use the run tool + +```bash +# Linux +./run newproject +``` + +```ps1 +# Windows +.\run.bat newproject +``` + ## Creating and building an Arduboy crate [Outdated] You can find instructions on how all build steps work in detail here [ArduboyRust creating and building an arduboy crate](https://github.com/Seeker14491/ArduboyRust#creating-and-building-an-arduboy-crate) diff --git a/run b/run index ed6bf41..40fadac 100755 --- a/run +++ b/run @@ -52,6 +52,7 @@ elif [ "$option" = "demo7" ] then upload else - echo Usage: for uploading your game \|./run.sh - echo Usage: for uploading an example game \| ./run.sh \ + upload + # echo Usage: for uploading your game \|./run.sh + # echo Usage: for uploading an example game \| ./run.sh \ fi diff --git a/run.bat b/run.bat index d035a50..3ee0417 100644 --- a/run.bat +++ b/run.bat @@ -40,7 +40,7 @@ goto :eof ) else if %option%==demo7 ( goto :run ) else ( - goto :help + goto :run ) :run From c3acb2455a04ab11110c999f52ddd5d826bf93fe Mon Sep 17 00:00:00 2001 From: PrimmR Date: Tue, 12 Sep 2023 17:25:17 +0100 Subject: [PATCH 4/5] Add set_rgb_led_single --- .../src/library/arduboy/arduboy_export.h | 4 +++ arduboy-rust/src/library/arduboy2.rs | 32 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/arduboy-rust/Wrapper-Project/src/library/arduboy/arduboy_export.h b/arduboy-rust/Wrapper-Project/src/library/arduboy/arduboy_export.h index 263ba5d..4d6598c 100644 --- a/arduboy-rust/Wrapper-Project/src/library/arduboy/arduboy_export.h +++ b/arduboy-rust/Wrapper-Project/src/library/arduboy/arduboy_export.h @@ -192,6 +192,10 @@ extern "C" { arduboy.digitalWriteRGB(red, green, blue); } + void arduboy_set_rgb_led_single(uint8_t color, uint8_t val) + { + arduboy.setRGBled(color, val); + } void arduboy_set_rgb_led(uint8_t red, uint8_t green, uint8_t blue) { arduboy.setRGBled(red, green, blue); diff --git a/arduboy-rust/src/library/arduboy2.rs b/arduboy-rust/src/library/arduboy2.rs index 6c57423..e9dde88 100644 --- a/arduboy-rust/src/library/arduboy2.rs +++ b/arduboy-rust/src/library/arduboy2.rs @@ -501,7 +501,32 @@ impl Arduboy2 { pub fn digital_write_rgb(&self, red: u8, green: u8, blue: u8) { unsafe { digital_write_rgb(red, green, blue) } } - + ///Set the brightness of one of the RGB LEDs without affecting the others. + /// + ///Parameters + ///- color The name of the LED to set. The value given should be one of RED_LED, GREEN_LED or BLUE_LED. + ///- val The brightness value for the LED, from 0 to 255. + /// + ///**Note** + ///> In order to use this function, the 3 parameter version must first be called at least once, in order to initialize the hardware. + /// + ///This 2 parameter version of the function will set the brightness of a single LED within the RGB LED without affecting the current brightness of the other two. See the description of the 3 parameter version of this function for more details on the RGB LED. + pub fn set_rgb_led_single(&self, color: u8, val: u8) { + unsafe { set_rgb_led_single(color, val) } + } + /// Set the light output of the RGB LED. + /// + ///Parameters + ///- red,green,blue The brightness value for each LED. + /// + /// The RGB LED is actually individual red, green and blue LEDs placed very close together in a single package. By setting the brightness of each LED, the RGB LED can show various colors and intensities. The brightness of each LED can be set to a value from 0 (fully off) to 255 (fully on). + /// + ///**Note** + ///> Certain libraries that take control of the hardware timers may interfere with the ability of this function to properly control the RGB LED. ArduboyPlaytune is one such library known to do this. The `digital_write_rgb()` function will still work properly in this case. + /// + /// + ///**Note** + ///> Many of the Kickstarter Arduboys were accidentally shipped with the RGB LED installed incorrectly. For these units, the green LED cannot be lit. As long as the green led is set to off, setting the red LED will actually control the blue LED and setting the blue LED will actually control the red LED. If the green LED is turned fully on, none of the LEDs will light. pub fn set_rgb_led(&self, red: u8, green: u8, blue: u8) { unsafe { set_rgb_led(red, green, blue) } } @@ -757,7 +782,10 @@ extern "C" { #[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); } From 4a85696f19437bbffaccd8fcdd185f02e1f57420 Mon Sep 17 00:00:00 2001 From: PrimmR Date: Tue, 12 Sep 2023 17:37:45 +0100 Subject: [PATCH 5/5] Updated EEPROMBYTECHECKLESS documentation --- arduboy-rust/src/library/eeprom.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arduboy-rust/src/library/eeprom.rs b/arduboy-rust/src/library/eeprom.rs index ae0d8e6..6c2d644 100644 --- a/arduboy-rust/src/library/eeprom.rs +++ b/arduboy-rust/src/library/eeprom.rs @@ -139,6 +139,8 @@ impl EEPROMBYTE { } } +///Use this struct to store and read single bytes to/from eeprom memory without using a check digit. +///Unlike the other eeprom structs, this does not need to be initialised. pub struct EEPROMBYTECHECKLESS { idx: i16, } @@ -151,8 +153,6 @@ impl EEPROMBYTECHECKLESS { idx: EEPROM_STORAGE_SPACE_START + idx, } } - pub fn init(&self) { - } pub fn read(&self) -> u8 { unsafe { arduboy_eeprom_read_raw(self.idx) } }