Merge branch 'main' of github.com:ZennDev1337/Rust-for-Arduboy
This commit is contained in:
commit
4fd55e8642
9 changed files with 155 additions and 4 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -31,6 +31,13 @@ version = "1.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cracker"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"arduboy-rust",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "critical-section"
|
name = "critical-section"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
|
|
|
@ -15,5 +15,6 @@ members = [
|
||||||
"Examples/rustacean",
|
"Examples/rustacean",
|
||||||
"Examples/snake",
|
"Examples/snake",
|
||||||
"Project/game",
|
"Project/game",
|
||||||
|
"Project/cracker",
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
74
README.md
74
README.md
|
@ -183,6 +183,80 @@ Windows:
|
||||||
.\run.bat tone
|
.\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]
|
## 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)
|
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)
|
||||||
|
|
|
@ -192,4 +192,12 @@ extern "C"
|
||||||
{
|
{
|
||||||
arduboy.digitalWriteRGB(red, green, blue);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -501,6 +501,35 @@ impl Arduboy2 {
|
||||||
pub fn digital_write_rgb(&self, red: u8, green: u8, blue: u8) {
|
pub fn digital_write_rgb(&self, red: u8, green: u8, blue: u8) {
|
||||||
unsafe { digital_write_rgb(red, green, blue) }
|
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.
|
///Indicate if the specified number of frames has elapsed.
|
||||||
///
|
///
|
||||||
///Parameters
|
///Parameters
|
||||||
|
@ -753,4 +782,10 @@ extern "C" {
|
||||||
|
|
||||||
#[link_name = "arduboy_digital_write_rgb"]
|
#[link_name = "arduboy_digital_write_rgb"]
|
||||||
fn digital_write_rgb(red: c_uchar, green: c_uchar, blue: c_uchar);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,3 +138,28 @@ impl EEPROMBYTE {
|
||||||
unsafe { arduboy_eeprom_write_raw(self.idx, val) }
|
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) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub use crate::library::arduboy_tone::{self, ArduboyTones};
|
||||||
pub use crate::library::arduino::*;
|
pub use crate::library::arduino::*;
|
||||||
pub use crate::library::ardvoice::*;
|
pub use crate::library::ardvoice::*;
|
||||||
pub use crate::library::c::*;
|
pub use crate::library::c::*;
|
||||||
pub use crate::library::eeprom::{EEPROM, EEPROMBYTE};
|
pub use crate::library::eeprom::{EEPROM, EEPROMBYTE, EEPROMBYTECHECKLESS};
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use crate::library::progmem::Pstring;
|
pub use crate::library::progmem::Pstring;
|
||||||
pub use crate::library::sprites;
|
pub use crate::library::sprites;
|
||||||
|
|
5
run
5
run
|
@ -52,6 +52,7 @@ elif [ "$option" = "demo7" ]
|
||||||
then
|
then
|
||||||
upload
|
upload
|
||||||
else
|
else
|
||||||
echo Usage: for uploading your game \|./run.sh
|
upload
|
||||||
echo Usage: for uploading an example game \| ./run.sh \<Example Game\>
|
# echo Usage: for uploading your game \|./run.sh
|
||||||
|
# echo Usage: for uploading an example game \| ./run.sh \<Example Game\>
|
||||||
fi
|
fi
|
||||||
|
|
2
run.bat
2
run.bat
|
@ -40,7 +40,7 @@ goto :eof
|
||||||
) else if %option%==demo7 (
|
) else if %option%==demo7 (
|
||||||
goto :run
|
goto :run
|
||||||
) else (
|
) else (
|
||||||
goto :help
|
goto :run
|
||||||
)
|
)
|
||||||
|
|
||||||
:run
|
:run
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue