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..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,4 +192,12 @@ 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); + } } \ No newline at end of file diff --git a/arduboy-rust/src/library/arduboy2.rs b/arduboy-rust/src/library/arduboy2.rs index 0a72b9f..e9dde88 100644 --- a/arduboy-rust/src/library/arduboy2.rs +++ b/arduboy-rust/src/library/arduboy2.rs @@ -501,6 +501,35 @@ 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) } + } ///Indicate if the specified number of frames has elapsed. /// ///Parameters @@ -753,4 +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); } diff --git a/arduboy-rust/src/library/eeprom.rs b/arduboy-rust/src/library/eeprom.rs index 85bb969..6c2d644 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) } } } + +///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, +} +impl EEPROMBYTECHECKLESS { + pub const fn new(mut idx: i16) -> EEPROMBYTECHECKLESS { + if idx > 1010 { + idx = 0 + } + EEPROMBYTECHECKLESS { + idx: EEPROM_STORAGE_SPACE_START + idx, + } + } + 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;