added the dependency to the project to circumvent crates.io and updated all projects
This commit is contained in:
parent
c591b2c272
commit
50819abc50
31 changed files with 1422 additions and 14 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -5,8 +5,6 @@ version = 3
|
|||
[[package]]
|
||||
name = "arduboy-rust"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e80037f297e2a5db1e58804b7a3b1b10f448b104623422db1c94b185b45b1ea5"
|
||||
dependencies = [
|
||||
"panic-halt",
|
||||
]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"arduboy-rust",
|
||||
"Examples/Arduboy-Tutorials/eeprom",
|
||||
"Examples/Arduboy-Tutorials/tone",
|
||||
"Examples/Arduboy-Tutorials/demo2",
|
||||
|
|
|
@ -8,4 +8,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../../arduboy-rust" }
|
||||
|
|
|
@ -8,4 +8,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../../arduboy-rust" }
|
||||
|
|
|
@ -8,4 +8,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../../arduboy-rust" }
|
||||
|
|
|
@ -7,4 +7,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../../arduboy-rust" }
|
||||
|
|
|
@ -7,4 +7,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../../arduboy-rust" }
|
||||
|
|
|
@ -9,4 +9,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../../arduboy-rust" }
|
||||
|
|
|
@ -9,4 +9,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../../arduboy-rust" }
|
||||
|
|
|
@ -9,4 +9,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../arduboy-rust" }
|
||||
|
|
|
@ -7,4 +7,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../arduboy-rust" }
|
||||
|
|
|
@ -9,4 +9,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../arduboy-rust" }
|
||||
|
|
|
@ -7,4 +7,4 @@ edition = "2021"
|
|||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
arduboy-rust = "1.0.0"
|
||||
arduboy-rust = { path = "../../arduboy-rust" }
|
||||
|
|
|
@ -43,7 +43,7 @@ Inside the game folder you will find a lib.rs file which contains the setup and
|
|||
You can use the following command to open the Rust doc of the arduboy_rust crate
|
||||
|
||||
```bash
|
||||
cargo doc -p arduboy_rust --open
|
||||
cargo doc -p arduboy-rust --open
|
||||
```
|
||||
|
||||
Most of the time you will use the prelude.
|
||||
|
|
16
arduboy-rust/Cargo.toml
Normal file
16
arduboy-rust/Cargo.toml
Normal file
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "arduboy-rust"
|
||||
version = "1.0.0"
|
||||
authors = ["ZennDev <ZennDev@protonmail.com>"]
|
||||
description = "This is a library used in Rust for Arduboy to program Arduboy games in Rust."
|
||||
readme = "README.md"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2021"
|
||||
repository = "https://github.com/ZennDev1337/arduboy-rust.git"
|
||||
homepage = "https://github.com/ZennDev1337/arduboy-rust"
|
||||
keywords = ["arduboy", "game", "arduboy-tone", "atmega32u4"]
|
||||
categories = ["game-engines", "games", "api-bindings"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
panic-halt = "0.2.0"
|
199
arduboy-rust/LICENSE-APACHE
Normal file
199
arduboy-rust/LICENSE-APACHE
Normal file
|
@ -0,0 +1,199 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
19
arduboy-rust/LICENSE-MIT
Normal file
19
arduboy-rust/LICENSE-MIT
Normal file
|
@ -0,0 +1,19 @@
|
|||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
23
arduboy-rust/README.md
Normal file
23
arduboy-rust/README.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Arduboy2 library wrapper
|
||||
|
||||
This is a library used in [Rust for Arduboy](https://github.com/ZennDev1337/Rust-for-Arduboy) to program Arduboy games in Rust.
|
||||
|
||||
## More info for the usage:
|
||||
|
||||
[https://github.com/ZennDev1337/Rust-for-Arduboy](https://github.com/ZennDev1337/Rust-for-Arduboy)
|
||||
|
||||
## License
|
||||
|
||||
You can license it under either one of those licenses:
|
||||
|
||||
- Apache License, Version 2.0
|
||||
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
- MIT license
|
||||
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||
|
||||
Whichever you may prefer.
|
||||
|
||||
## Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
69
arduboy-rust/src/hardware/buttons.rs
Normal file
69
arduboy-rust/src/hardware/buttons.rs
Normal file
|
@ -0,0 +1,69 @@
|
|||
//! A list of all six buttons available on the Arduboy
|
||||
/// Just a `const` for the UP button
|
||||
pub const UP: ButtonSet = ButtonSet {
|
||||
flag_set: 0b10000000,
|
||||
};
|
||||
/// Just a `const` for the RIGHT button
|
||||
pub const RIGHT: ButtonSet = ButtonSet {
|
||||
flag_set: 0b01000000,
|
||||
};
|
||||
/// Just a `const` for the LEFT button
|
||||
pub const LEFT: ButtonSet = ButtonSet {
|
||||
flag_set: 0b00100000,
|
||||
};
|
||||
/// Just a `const` for the DOWN button
|
||||
pub const DOWN: ButtonSet = ButtonSet {
|
||||
flag_set: 0b00010000,
|
||||
};
|
||||
/// Just a `const` for the A button
|
||||
pub const A: ButtonSet = ButtonSet {
|
||||
flag_set: 0b00001000,
|
||||
};
|
||||
/// Just a `const` for the B button
|
||||
pub const B: ButtonSet = ButtonSet {
|
||||
flag_set: 0b00000100,
|
||||
};
|
||||
/// Just a `const` for the UP button
|
||||
pub const UP_BUTTON: ButtonSet = UP;
|
||||
/// Just a `const` for the RIGHT button
|
||||
pub const RIGHT_BUTTON: ButtonSet = RIGHT;
|
||||
/// Just a `const` for the DOWN button
|
||||
pub const DOWN_BUTTON: ButtonSet = DOWN;
|
||||
/// Just a `const` for the LEFT button
|
||||
pub const LEFT_BUTTON: ButtonSet = LEFT;
|
||||
/// Just a `const` for the A button
|
||||
pub const A_BUTTON: ButtonSet = A;
|
||||
/// Just a `const` for the B button
|
||||
pub const B_BUTTON: ButtonSet = B;
|
||||
///This struct gives the library a understanding what Buttons on the Arduboy are.
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub struct ButtonSet {
|
||||
pub flag_set: u8,
|
||||
}
|
||||
|
||||
impl ButtonSet {
|
||||
pub unsafe fn pressed(&self) -> bool {
|
||||
crate::library::arduboy::pressed(self.flag_set)
|
||||
}
|
||||
|
||||
pub unsafe fn just_pressed(&self) -> bool {
|
||||
crate::library::arduboy::just_pressed(self.flag_set)
|
||||
}
|
||||
|
||||
pub unsafe fn just_released(&self) -> bool {
|
||||
crate::library::arduboy::just_released(self.flag_set)
|
||||
}
|
||||
pub unsafe fn not_pressed(&self) -> bool {
|
||||
crate::library::arduboy::not_pressed(self.flag_set)
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::BitOr for ButtonSet {
|
||||
type Output = Self;
|
||||
|
||||
fn bitor(self, other: Self) -> Self {
|
||||
Self {
|
||||
flag_set: self.flag_set | other.flag_set,
|
||||
}
|
||||
}
|
||||
}
|
1
arduboy-rust/src/hardware/mod.rs
Normal file
1
arduboy-rust/src/hardware/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod buttons;
|
14
arduboy-rust/src/lib.rs
Normal file
14
arduboy-rust/src/lib.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
#![cfg(target_arch = "avr")]
|
||||
#![no_std]
|
||||
#![feature(c_size_t)]
|
||||
extern crate panic_halt;
|
||||
mod hardware;
|
||||
mod library;
|
||||
pub mod prelude;
|
||||
mod print;
|
||||
pub use crate::library::arduboy::{Arduboy, Color, FONT_SIZE, HEIGHT, WIDTH};
|
||||
pub use crate::library::arduboy_tone::Sound;
|
||||
pub use crate::library::eeprom::EEPROM;
|
||||
pub use crate::library::{arduboy_tone_pitch, c, sprites};
|
||||
|
||||
pub use hardware::buttons;
|
451
arduboy-rust/src/library/arduboy.rs
Normal file
451
arduboy-rust/src/library/arduboy.rs
Normal file
|
@ -0,0 +1,451 @@
|
|||
//! This is the Module to interact in a save way with the Arduboy2 C++ library.
|
||||
//!
|
||||
//! Ignore the functions here you only need to import the prelude here you will find all sorts of unsafe functions
|
||||
//! All of them are safe wrapped inside the struct.
|
||||
#![allow(dead_code)]
|
||||
use crate::prelude::ButtonSet;
|
||||
use crate::print::Printable;
|
||||
use core::ffi::{c_char, c_int, c_long, c_size_t, c_uchar, c_uint, c_ulong};
|
||||
use core::mem;
|
||||
use core::ops::Not;
|
||||
/// The standard font size of the arduboy
|
||||
///
|
||||
/// this is to calculate with it.
|
||||
pub const FONT_SIZE: u8 = 6;
|
||||
/// The standard width of the arduboy
|
||||
///
|
||||
/// this is to calculate with it.
|
||||
pub const WIDTH: u8 = 128;
|
||||
/// The standard height of the arduboy
|
||||
///
|
||||
/// this is to calculate with it.
|
||||
pub const HEIGHT: u8 = 64;
|
||||
/// This item is to chose between Black or White
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
||||
#[repr(u8)]
|
||||
pub enum Color {
|
||||
/// Led is off
|
||||
Black,
|
||||
/// Led is on
|
||||
White,
|
||||
}
|
||||
impl Not for Color {
|
||||
type Output = Self;
|
||||
|
||||
fn not(self) -> Self::Output {
|
||||
match self {
|
||||
Color::Black => Color::White,
|
||||
Color::White => Color::Black,
|
||||
}
|
||||
}
|
||||
}
|
||||
/// This is the struct to interact in a save way with the Arduboy2 C++ library.
|
||||
pub struct Arduboy {}
|
||||
impl Arduboy {
|
||||
pub fn new() -> Self {
|
||||
Arduboy {}
|
||||
}
|
||||
/// Initialize the hardware, display the boot logo, provide boot utilities, etc.
|
||||
/// This function should be called once near the start of the sketch, usually in setup(), before using any other functions in this class. It initializes the display, displays the boot logo, provides "flashlight" and system control features and initializes audio control.
|
||||
pub fn begin(&self) {
|
||||
unsafe { begin() }
|
||||
}
|
||||
/// Clear the display buffer and set the text cursor to location 0, 0.
|
||||
pub fn clear(&self) {
|
||||
unsafe { clear() }
|
||||
}
|
||||
/// Copy the contents of the display buffer to the display.
|
||||
/// The contents of the display buffer in RAM are copied to the display and will appear on the screen.
|
||||
pub fn display(&self) {
|
||||
unsafe { display() }
|
||||
}
|
||||
///Copy the contents of the display buffer to the display. The display buffer will be cleared to zero.
|
||||
///
|
||||
///Operation is the same as calling display() without parameters except additionally the display buffer will be cleared.
|
||||
pub fn display_and_clear_buffer(&self) {
|
||||
unsafe { display_and_clear_buffer() }
|
||||
}
|
||||
///Draw a horizontal line.
|
||||
///
|
||||
///### Parameters:
|
||||
///
|
||||
///x The X coordinate of the left start point.
|
||||
///
|
||||
///y The Y coordinate of the left start point.
|
||||
///
|
||||
///w The width of the line.
|
||||
///
|
||||
///color The color of the line (optional; defaults to WHITE).
|
||||
pub fn draw_fast_hline(&self, x: i16, y: i16, w: u8, color: Color) {
|
||||
unsafe { draw_fast_hline_raw(x, y, w, color as u8) }
|
||||
}
|
||||
///Draw a vertical line.
|
||||
///
|
||||
///### Parameters:
|
||||
///
|
||||
///x The X coordinate of the left start point.
|
||||
///
|
||||
///y The Y coordinate of the left start point.
|
||||
///
|
||||
///h The height of the line.
|
||||
///
|
||||
///color The color of the line (optional; defaults to WHITE).
|
||||
pub fn draw_fast_vline(&self, x: i16, y: i16, h: u8, color: Color) {
|
||||
unsafe { draw_fast_vline_raw(x, y, h, color as u8) }
|
||||
}
|
||||
///Set a single pixel in the display buffer to the specified color.
|
||||
///
|
||||
///### Parameters
|
||||
///
|
||||
///x The X coordinate of the pixel.
|
||||
///
|
||||
///y The Y coordinate of the pixel.
|
||||
///
|
||||
///color The color of the pixel (optional; defaults to WHITE).
|
||||
///
|
||||
///The single pixel specified location in the display buffer is set to the specified color. The values WHITE or BLACK can be used for the color. If the color parameter isn't included, the pixel will be set to WHITE.
|
||||
pub fn draw_pixel(&self, x: i16, y: i16, color: Color) {
|
||||
unsafe { draw_pixel_raw(x, y, color as u8) }
|
||||
}
|
||||
///Draw a filled-in rectangle of a specified width and height.
|
||||
///
|
||||
///### Parameters
|
||||
///
|
||||
///x The X coordinate of the upper left corner.
|
||||
///
|
||||
///y The Y coordinate of the upper left corner.
|
||||
///
|
||||
///w The width of the rectangle.
|
||||
///
|
||||
///h The height of the rectangle.
|
||||
///
|
||||
///color The color of the pixel (optional; defaults to WHITE).
|
||||
pub fn fill_rect(&self, x: i16, y: i16, w: u8, h: u8, color: Color) {
|
||||
unsafe { fill_rect_raw(x, y, w, h, color as u8) }
|
||||
}
|
||||
pub fn draw_circle(&self, x: i16, y: i16, r: u8, color: Color) {
|
||||
unsafe { draw_circle_raw(x, y, r, color as u8) }
|
||||
}
|
||||
///Draw a filled-in circle of a given radius.
|
||||
///
|
||||
///### Parameters
|
||||
///
|
||||
///x0 The X coordinate of the circle's center.
|
||||
///
|
||||
///y0 The Y coordinate of the circle's center.
|
||||
///
|
||||
///r The radius of the circle in pixels.
|
||||
///
|
||||
///color The circle's color (optional; defaults to WHITE).
|
||||
pub fn fill_circle(&self, x: i16, y: i16, r: u8, color: Color) {
|
||||
unsafe { fill_circle_raw(x, y, r, color as u8) }
|
||||
}
|
||||
///Returns the state of the given pixel in the screen buffer.
|
||||
///
|
||||
///### Parameters
|
||||
///x The X coordinate of the pixel.
|
||||
///
|
||||
///y The Y coordinate of the pixel.
|
||||
///
|
||||
///### Returns
|
||||
///WHITE if the pixel is on or BLACK if the pixel is off.
|
||||
pub fn get_pixel(&self, x: u8, y: u8) -> Color {
|
||||
unsafe { mem::transmute::<u8, Color>(get_pixel_raw(x, y)) }
|
||||
}
|
||||
/// Seed the random number generator with a random value.
|
||||
///
|
||||
/// The Arduino pseudorandom number generator is seeded with the random value returned from a call to generateRandomSeed().
|
||||
pub fn init_random_seed(&self) {
|
||||
unsafe { init_random_seed() }
|
||||
}
|
||||
///Check if a button has just been pressed.
|
||||
///
|
||||
///### Parameters
|
||||
///button The button to test for. Only one button should be specified.
|
||||
///
|
||||
///### Returns
|
||||
///true if the specified button has just been pressed.
|
||||
///
|
||||
///Return true if the given button was pressed between the latest call to pollButtons() and previous call to pollButtons(). If the button has been held down over multiple polls, this function will return false.
|
||||
///
|
||||
///There is no need to check for the release of the button since it must have been released for this function to return true when pressed again.
|
||||
///
|
||||
///This function should only be used to test a single button.
|
||||
pub fn just_pressed(&self, button: ButtonSet) -> bool {
|
||||
unsafe { just_pressed(button.flag_set) }
|
||||
}
|
||||
///Check if a button has just been released.
|
||||
///
|
||||
///### Parameters
|
||||
///button The button to test for. Only one button should be specified.
|
||||
///
|
||||
///### Returns
|
||||
///true if the specified button has just been released.
|
||||
///
|
||||
///Return true if the given button was released between the latest call to pollButtons() and previous call to pollButtons(). If the button has been held down over multiple polls, this function will return false.
|
||||
///
|
||||
///There is no need to check for the released of the button since it must have been pressed for this function to return true when pressed again.
|
||||
///
|
||||
///This function should only be used to test a single button.
|
||||
pub fn just_released(&self, button: ButtonSet) -> bool {
|
||||
unsafe { just_released(button.flag_set) }
|
||||
}
|
||||
///Test if the specified buttons are not pressed.
|
||||
///
|
||||
///### Parameters
|
||||
///
|
||||
///buttons A bit mask indicating which buttons to test. (Can be a single button)
|
||||
///
|
||||
///### Returns
|
||||
///
|
||||
/// True if all buttons in the provided mask are currently released.
|
||||
///
|
||||
///Read the state of the buttons and return true if all the buttons in the specified mask are currently released.
|
||||
pub fn not_pressed(&self, button: ButtonSet) -> bool {
|
||||
unsafe { not_pressed(button.flag_set) }
|
||||
}
|
||||
///Indicate that it's time to render the next frame.
|
||||
///
|
||||
///### Returns
|
||||
///true if it's time for the next frame.
|
||||
///
|
||||
///When this function returns true, the amount of time has elapsed to display the next frame, as specified by setFrameRate() or setFrameDuration().
|
||||
///
|
||||
///This function will normally be called at the start of the rendering loop which would wait for true to be returned before rendering and displaying the next frame.
|
||||
pub fn next_frame(&self) -> bool {
|
||||
unsafe { next_frame() }
|
||||
}
|
||||
///Poll the buttons and track their state over time.
|
||||
///
|
||||
///Read and save the current state of the buttons and also keep track of the button state when this function was previously called. These states are used by the justPressed() and justReleased() functions to determine if a button has changed state between now and the previous call to pollButtons().
|
||||
///
|
||||
///This function should be called once at the start of each new frame.
|
||||
///
|
||||
///The justPressed() and justReleased() functions rely on this function.
|
||||
pub fn poll_buttons(&self) {
|
||||
unsafe { poll_buttons() }
|
||||
}
|
||||
///Test if the all of the specified buttons are pressed.
|
||||
///
|
||||
///### Parameters
|
||||
/// buttons A bit mask indicating which buttons to test. (Can be a single button)
|
||||
///
|
||||
///### Returns
|
||||
/// true if all buttons in the provided mask are currently pressed.
|
||||
///
|
||||
///Read the state of the buttons and return true if all of the buttons in the specified mask are being pressed.
|
||||
pub fn pressed(&self, button: ButtonSet) -> bool {
|
||||
unsafe { pressed(button.flag_set) }
|
||||
}
|
||||
///The Arduino Print class is available for writing text to the screen buffer.
|
||||
///
|
||||
///For an Arduboy2 class object, functions provided by the Arduino Print class can be used to write text to the screen buffer, in the same manner as the Arduino Serial.print(), etc., functions.
|
||||
///
|
||||
///Print will use the write() function to actually draw each character in the screen buffer, using the library's font5x7 font. Two character values are handled specially:
|
||||
///
|
||||
///- ASCII newline/line feed (\n, 0x0A, inverse white circle). This will move the text cursor position to the start of the next line, based on the current text size.
|
||||
///- ASCII carriage return (\r, 0x0D, musical eighth note). This character will be ignored.
|
||||
///
|
||||
///
|
||||
///Example
|
||||
/// ```text
|
||||
/// let value:i16 = 42;
|
||||
///
|
||||
/// arduboy.println("Hello World\0"); // Prints "Hello World" and then sets the
|
||||
/// // text cursor to the start of the next line
|
||||
/// arduboy.print(value); // Prints "42"
|
||||
/// arduboy.print('\n\0'); // Sets the text cursor to the start of the next line
|
||||
/// arduboy.print(78, HEX); // Prints "4E" (78 in hexadecimal)
|
||||
/// arduboy.print("\x03\xEA"); // Prints a heart symbol and a Greek uppercase omega
|
||||
/// ```
|
||||
pub fn print(&self, x: impl Printable) {
|
||||
x.print()
|
||||
}
|
||||
///Set the location of the text cursor.
|
||||
///
|
||||
///### Parameters
|
||||
/// x The X (horizontal) coordinate, in pixels, for the new location of the text cursor.
|
||||
///
|
||||
/// y The Y (vertical) coordinate, in pixels, for the new location of the text cursor.
|
||||
///
|
||||
///The location of the text cursor is set the the specified coordinates. The coordinates are in pixels. Since the coordinates can specify any pixel location, the text does not have to be placed on specific rows. As with all drawing functions, location 0, 0 is the top left corner of the display. The cursor location represents the top left corner of the next character written.
|
||||
pub fn set_cursor(&self, x: i16, y: i16) {
|
||||
unsafe { set_cursor(x, y) }
|
||||
}
|
||||
///Set the frame rate used by the frame control functions.
|
||||
///
|
||||
///### Parameters
|
||||
/// rate The desired frame rate in frames per second.
|
||||
///
|
||||
///Normally, the frame rate would be set to the desired value once, at the start of the game, but it can be changed at any time to alter the frame update rate.
|
||||
pub fn set_frame_rate(&self, rate: u8) {
|
||||
unsafe { set_frame_rate(rate) }
|
||||
}
|
||||
///Set the text character size.
|
||||
///
|
||||
///### Parameters
|
||||
/// s The text size multiplier. Must be 1 or higher.
|
||||
///
|
||||
///Setting a text size of 1 will result in standard size characters with one pixel for each bit in the bitmap for a character. The value specified is a multiplier. A value of 2 will double the width and height. A value of 3 will triple the dimensions, etc.
|
||||
pub fn set_text_size(&self, size: u8) {
|
||||
unsafe { set_text_size(size) }
|
||||
}
|
||||
///Turn sound on.
|
||||
///
|
||||
///The system is configured to generate sound. This function sets the sound mode only until the unit is powered off.
|
||||
pub fn audio_on(&self) {
|
||||
unsafe { arduboy_audio_on() }
|
||||
}
|
||||
///Turn sound off (mute).
|
||||
///
|
||||
///The system is configured to not produce sound (mute). This function sets the sound mode only until the unit is powered off.
|
||||
pub fn audio_off(&self) {
|
||||
unsafe { arduboy_audio_off() }
|
||||
}
|
||||
///Get the current sound state.
|
||||
///
|
||||
///### Returns
|
||||
///true if sound is currently enabled (not muted).
|
||||
///
|
||||
///This function should be used by code that actually generates sound. If true is returned, sound can be produced. If false is returned, sound should be muted.
|
||||
pub fn audio_enabled(&self) -> bool {
|
||||
unsafe { arduboy_audio_enabled() }
|
||||
}
|
||||
///Invert the entire display or set it back to normal.
|
||||
///
|
||||
///### Parameters
|
||||
///inverse true will invert the display. false will set the display to no-inverted.
|
||||
///
|
||||
///Calling this function with a value of true will set the display to inverted mode. A pixel with a value of 0 will be on and a pixel set to 1 will be off.
|
||||
///
|
||||
///Once in inverted mode, the display will remain this way until it is set back to non-inverted mode by calling this function with false.
|
||||
pub fn invert(&self, inverse: bool) {
|
||||
unsafe { arduboy_invert(inverse) }
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "arduboy_begin"]
|
||||
pub fn begin();
|
||||
|
||||
#[link_name = "arduboy_clear"]
|
||||
pub fn clear();
|
||||
|
||||
#[link_name = "arduboy_display"]
|
||||
pub fn display();
|
||||
|
||||
#[link_name = "arduboy_display_and_clear_buffer"]
|
||||
pub fn display_and_clear_buffer();
|
||||
|
||||
#[link_name = "arduboy_draw_fast_hline"]
|
||||
fn draw_fast_hline_raw(x: i16, y: i16, w: u8, color: u8);
|
||||
|
||||
#[link_name = "arduboy_draw_fast_vline"]
|
||||
fn draw_fast_vline_raw(x: i16, y: i16, h: u8, color: u8);
|
||||
|
||||
#[link_name = "arduboy_draw_pixel"]
|
||||
fn draw_pixel_raw(x: i16, y: i16, color: u8);
|
||||
|
||||
#[link_name = "arduboy_draw_circle"]
|
||||
fn draw_circle_raw(x: i16, y: i16, r: u8, color: u8);
|
||||
|
||||
#[link_name = "arduboy_fill_circle"]
|
||||
fn fill_circle_raw(x: i16, y: i16, r: u8, color: u8);
|
||||
|
||||
#[link_name = "arduboy_fill_rect"]
|
||||
fn fill_rect_raw(x: i16, y: i16, w: u8, h: u8, color: u8);
|
||||
|
||||
#[link_name = "arduboy_get_pixel"]
|
||||
fn get_pixel_raw(x: u8, y: u8) -> u8;
|
||||
|
||||
#[link_name = "arduboy_init_random_seed"]
|
||||
pub fn init_random_seed();
|
||||
|
||||
#[link_name = "arduboy_just_pressed"]
|
||||
pub fn just_pressed(button: u8) -> bool;
|
||||
|
||||
#[link_name = "arduboy_just_released"]
|
||||
pub fn just_released(button: u8) -> bool;
|
||||
|
||||
#[link_name = "arduboy_not_pressed"]
|
||||
pub fn not_pressed(button: u8) -> bool;
|
||||
|
||||
#[link_name = "arduboy_next_frame"]
|
||||
pub fn next_frame() -> bool;
|
||||
|
||||
#[link_name = "arduboy_poll_buttons"]
|
||||
pub fn poll_buttons();
|
||||
|
||||
#[link_name = "arduboy_pressed"]
|
||||
pub fn pressed(buttons: u8) -> bool;
|
||||
|
||||
#[link_name = "arduboy_print_chars"]
|
||||
pub fn print_chars(cstr: *const c_char);
|
||||
|
||||
// #[link_name = "arduboy_print_char"]
|
||||
// fn print_char(c: c_char) -> c_size_t;
|
||||
|
||||
#[link_name = "arduboy_print_int"]
|
||||
pub fn print_int(n: c_int, base: c_int) -> c_size_t;
|
||||
|
||||
#[link_name = "arduboy_print_long"]
|
||||
pub fn print_long(n: c_long, base: c_int) -> c_size_t;
|
||||
|
||||
#[link_name = "arduboy_print_unsigned_char"]
|
||||
pub fn print_unsigned_char(n: c_uchar, base: c_int) -> c_size_t;
|
||||
|
||||
#[link_name = "arduboy_print_unsigned_int"]
|
||||
pub fn print_unsigned_int(n: c_uint, base: c_int) -> c_size_t;
|
||||
|
||||
#[link_name = "arduboy_print_unsigned_long"]
|
||||
pub fn print_unsigned_long(n: c_ulong, base: c_int) -> c_size_t;
|
||||
|
||||
#[link_name = "arduboy_set_cursor"]
|
||||
pub fn set_cursor(x: i16, y: i16);
|
||||
|
||||
#[link_name = "arduboy_set_frame_rate"]
|
||||
pub fn set_frame_rate(rate: u8);
|
||||
|
||||
#[link_name = "arduboy_set_text_size"]
|
||||
pub fn set_text_size(size: u8);
|
||||
|
||||
#[link_name = "arduboy_audio_on"]
|
||||
fn arduboy_audio_on();
|
||||
|
||||
#[link_name = "arduboy_audio_off"]
|
||||
fn arduboy_audio_off();
|
||||
|
||||
#[link_name = "arduboy_audio_enabled"]
|
||||
fn arduboy_audio_enabled() -> bool;
|
||||
|
||||
#[link_name = "arduboy_invert"]
|
||||
fn arduboy_invert(inverse: bool);
|
||||
}
|
||||
|
||||
pub unsafe fn print(x: impl Printable) {
|
||||
x.print();
|
||||
}
|
||||
|
||||
pub unsafe fn draw_fast_hline(x: i16, y: i16, w: u8, color: Color) {
|
||||
draw_fast_hline_raw(x, y, w, color as u8);
|
||||
}
|
||||
|
||||
pub unsafe fn draw_fast_vline(x: i16, y: i16, h: u8, color: Color) {
|
||||
draw_fast_vline_raw(x, y, h, color as u8);
|
||||
}
|
||||
|
||||
pub unsafe fn draw_pixel(x: i16, y: i16, color: Color) {
|
||||
draw_pixel_raw(x, y, color as u8);
|
||||
}
|
||||
|
||||
pub unsafe fn fill_rect(x: i16, y: i16, w: u8, h: u8, color: Color) {
|
||||
fill_rect_raw(x, y, w, h, color as u8);
|
||||
}
|
||||
|
||||
pub unsafe fn draw_circle(x: i16, y: i16, r: u8, color: Color) {
|
||||
draw_circle_raw(x, y, r, color as u8);
|
||||
}
|
||||
|
||||
pub unsafe fn get_pixel(x: u8, y: u8) -> Color {
|
||||
mem::transmute::<u8, Color>(get_pixel_raw(x, y))
|
||||
}
|
79
arduboy-rust/src/library/arduboy_tone.rs
Normal file
79
arduboy-rust/src/library/arduboy_tone.rs
Normal file
|
@ -0,0 +1,79 @@
|
|||
//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"]
|
||||
fn sound_tone(frequency: c_uint, duration: c_ulong);
|
||||
#[link_name = "sound_tone2"]
|
||||
fn sound_tone2(frequency1: c_uint, duration1: c_ulong, frequency2: c_uint, duration2: c_ulong);
|
||||
#[link_name = "sound_tone3"]
|
||||
fn sound_tone3(
|
||||
frequency1: c_uint,
|
||||
duration1: c_ulong,
|
||||
frequency2: c_uint,
|
||||
duration2: c_ulong,
|
||||
frequency3: c_uint,
|
||||
duration3: c_ulong,
|
||||
);
|
||||
|
||||
#[link_name = "sound_tones"]
|
||||
fn sound_tones(tones: *const c_uint);
|
||||
|
||||
#[link_name = "sound_no_tone"]
|
||||
fn sound_no_tone();
|
||||
|
||||
#[link_name = "sound_playing"]
|
||||
fn sound_playing() -> bool;
|
||||
|
||||
#[link_name = "sound_tones_in_ram"]
|
||||
fn sound_tones_in_ram(tones: *mut c_ulong);
|
||||
|
||||
#[link_name = "sound_volume_mode"]
|
||||
fn sound_volume_mode(mode: c_uchar);
|
||||
|
||||
}
|
||||
///This is the struct to interact in a save way with the Arduboy2Audio C++ library.
|
||||
pub struct Sound {}
|
||||
impl Sound {
|
||||
pub fn tone(&self, frequency: u16, duration: u32) {
|
||||
unsafe { sound_tone(frequency, duration) }
|
||||
}
|
||||
pub fn tone2(&self, frequency1: u16, duration1: u32, frequency2: u16, duration2: u32) {
|
||||
unsafe { sound_tone2(frequency1, duration1, frequency2, duration2) }
|
||||
}
|
||||
pub fn tone3(
|
||||
&self,
|
||||
frequency1: u16,
|
||||
duration1: u32,
|
||||
frequency2: u16,
|
||||
duration2: u32,
|
||||
frequency3: u16,
|
||||
duration3: u32,
|
||||
) {
|
||||
unsafe { sound_tone3(frequency1, duration1, frequency2, duration2, frequency3, duration3) }
|
||||
}
|
||||
pub fn tones(&self, tones: *const u16) {
|
||||
unsafe { sound_tones(tones) }
|
||||
}
|
||||
pub fn no_tone(&self) {
|
||||
unsafe { sound_no_tone() }
|
||||
}
|
||||
pub fn playing(&self) -> bool {
|
||||
unsafe { sound_playing() }
|
||||
}
|
||||
pub fn tones_in_ram(&self, tones: *mut u32) {
|
||||
unsafe { sound_tones_in_ram(tones) }
|
||||
}
|
||||
pub fn volume_mode(&self, mode: u8) {
|
||||
unsafe { sound_volume_mode(mode) }
|
||||
}
|
||||
}
|
252
arduboy-rust/src/library/arduboy_tone_pitch.rs
Normal file
252
arduboy-rust/src/library/arduboy_tone_pitch.rs
Normal file
|
@ -0,0 +1,252 @@
|
|||
//! A list of all tones available and used by the Sounds library Arduboy2Tones
|
||||
pub const NDUR: u16 = 100;
|
||||
|
||||
pub const TONES_END: u16 = 0x8000;
|
||||
pub const TONES_REPEAT: u16 = 0x8001;
|
||||
pub const TONE_HIGH_VOLUME: u16 = 0x8000;
|
||||
pub const VOLUME_IN_TONE: u8 = 0;
|
||||
pub const VOLUME_ALWAYS_NORMAL: u8 = 1;
|
||||
pub const VOLUME_ALWAYS_HIGH: u8 = 2;
|
||||
|
||||
pub const NOTE_REST: u16 = 0;
|
||||
pub const NOTE_C0: u16 = 16;
|
||||
pub const NOTE_CS0: u16 = 17;
|
||||
pub const NOTE_D0: u16 = 18;
|
||||
pub const NOTE_DS0: u16 = 19;
|
||||
pub const NOTE_E0: u16 = 21;
|
||||
pub const NOTE_F0: u16 = 22;
|
||||
pub const NOTE_FS0: u16 = 23;
|
||||
pub const NOTE_G0: u16 = 25;
|
||||
pub const NOTE_GS0: u16 = 26;
|
||||
pub const NOTE_A0: u16 = 28;
|
||||
pub const NOTE_AS0: u16 = 29;
|
||||
pub const NOTE_B0: u16 = 31;
|
||||
pub const NOTE_C1: u16 = 33;
|
||||
pub const NOTE_CS1: u16 = 35;
|
||||
pub const NOTE_D1: u16 = 37;
|
||||
pub const NOTE_DS1: u16 = 39;
|
||||
pub const NOTE_E1: u16 = 41;
|
||||
pub const NOTE_F1: u16 = 44;
|
||||
pub const NOTE_FS1: u16 = 46;
|
||||
pub const NOTE_G1: u16 = 49;
|
||||
pub const NOTE_GS1: u16 = 52;
|
||||
pub const NOTE_A1: u16 = 55;
|
||||
pub const NOTE_AS1: u16 = 58;
|
||||
pub const NOTE_B1: u16 = 62;
|
||||
pub const NOTE_C2: u16 = 65;
|
||||
pub const NOTE_CS2: u16 = 69;
|
||||
pub const NOTE_D2: u16 = 73;
|
||||
pub const NOTE_DS2: u16 = 78;
|
||||
pub const NOTE_E2: u16 = 82;
|
||||
pub const NOTE_F2: u16 = 87;
|
||||
pub const NOTE_FS2: u16 = 93;
|
||||
pub const NOTE_G2: u16 = 98;
|
||||
pub const NOTE_GS2: u16 = 104;
|
||||
pub const NOTE_A2: u16 = 110;
|
||||
pub const NOTE_AS2: u16 = 117;
|
||||
pub const NOTE_B2: u16 = 123;
|
||||
pub const NOTE_C3: u16 = 131;
|
||||
pub const NOTE_CS3: u16 = 139;
|
||||
pub const NOTE_D3: u16 = 147;
|
||||
pub const NOTE_DS3: u16 = 156;
|
||||
pub const NOTE_E3: u16 = 165;
|
||||
pub const NOTE_F3: u16 = 175;
|
||||
pub const NOTE_FS3: u16 = 185;
|
||||
pub const NOTE_G3: u16 = 196;
|
||||
pub const NOTE_GS3: u16 = 208;
|
||||
pub const NOTE_A3: u16 = 220;
|
||||
pub const NOTE_AS3: u16 = 233;
|
||||
pub const NOTE_B3: u16 = 247;
|
||||
pub const NOTE_C4: u16 = 262;
|
||||
pub const NOTE_CS4: u16 = 277;
|
||||
pub const NOTE_D4: u16 = 294;
|
||||
pub const NOTE_DS4: u16 = 311;
|
||||
pub const NOTE_E4: u16 = 330;
|
||||
pub const NOTE_F4: u16 = 349;
|
||||
pub const NOTE_FS4: u16 = 370;
|
||||
pub const NOTE_G4: u16 = 392;
|
||||
pub const NOTE_GS4: u16 = 415;
|
||||
pub const NOTE_A4: u16 = 440;
|
||||
pub const NOTE_AS4: u16 = 466;
|
||||
pub const NOTE_B4: u16 = 494;
|
||||
pub const NOTE_C5: u16 = 523;
|
||||
pub const NOTE_CS5: u16 = 554;
|
||||
pub const NOTE_D5: u16 = 587;
|
||||
pub const NOTE_DS5: u16 = 622;
|
||||
pub const NOTE_E5: u16 = 659;
|
||||
pub const NOTE_F5: u16 = 698;
|
||||
pub const NOTE_FS5: u16 = 740;
|
||||
pub const NOTE_G5: u16 = 784;
|
||||
pub const NOTE_GS5: u16 = 831;
|
||||
pub const NOTE_A5: u16 = 880;
|
||||
pub const NOTE_AS5: u16 = 932;
|
||||
pub const NOTE_B5: u16 = 988;
|
||||
pub const NOTE_C6: u16 = 1047;
|
||||
pub const NOTE_CS6: u16 = 1109;
|
||||
pub const NOTE_D6: u16 = 1175;
|
||||
pub const NOTE_DS6: u16 = 1245;
|
||||
pub const NOTE_E6: u16 = 1319;
|
||||
pub const NOTE_F6: u16 = 1397;
|
||||
pub const NOTE_FS6: u16 = 1480;
|
||||
pub const NOTE_G6: u16 = 1568;
|
||||
pub const NOTE_GS6: u16 = 1661;
|
||||
pub const NOTE_A6: u16 = 1760;
|
||||
pub const NOTE_AS6: u16 = 1865;
|
||||
pub const NOTE_B6: u16 = 1976;
|
||||
pub const NOTE_C7: u16 = 2093;
|
||||
pub const NOTE_CS7: u16 = 2218;
|
||||
pub const NOTE_D7: u16 = 2349;
|
||||
pub const NOTE_DS7: u16 = 2489;
|
||||
pub const NOTE_E7: u16 = 2637;
|
||||
pub const NOTE_F7: u16 = 2794;
|
||||
pub const NOTE_FS7: u16 = 2960;
|
||||
pub const NOTE_G7: u16 = 3136;
|
||||
pub const NOTE_GS7: u16 = 3322;
|
||||
pub const NOTE_A7: u16 = 3520;
|
||||
pub const NOTE_AS7: u16 = 3729;
|
||||
pub const NOTE_B7: u16 = 3951;
|
||||
pub const NOTE_C8: u16 = 4186;
|
||||
pub const NOTE_CS8: u16 = 4435;
|
||||
pub const NOTE_D8: u16 = 4699;
|
||||
pub const NOTE_DS8: u16 = 4978;
|
||||
pub const NOTE_E8: u16 = 5274;
|
||||
pub const NOTE_F8: u16 = 5588;
|
||||
pub const NOTE_FS8: u16 = 5920;
|
||||
pub const NOTE_G8: u16 = 6272;
|
||||
pub const NOTE_GS8: u16 = 6645;
|
||||
pub const NOTE_A8: u16 = 7040;
|
||||
pub const NOTE_AS8: u16 = 7459;
|
||||
pub const NOTE_B8: u16 = 7902;
|
||||
pub const NOTE_C9: u16 = 8372;
|
||||
pub const NOTE_CS9: u16 = 8870;
|
||||
pub const NOTE_D9: u16 = 9397;
|
||||
pub const NOTE_DS9: u16 = 9956;
|
||||
pub const NOTE_E9: u16 = 10548;
|
||||
pub const NOTE_F9: u16 = 11175;
|
||||
pub const NOTE_FS9: u16 = 11840;
|
||||
pub const NOTE_G9: u16 = 12544;
|
||||
pub const NOTE_GS9: u16 = 13290;
|
||||
pub const NOTE_A9: u16 = 14080;
|
||||
pub const NOTE_AS9: u16 = 14917;
|
||||
pub const NOTE_B9: u16 = 15804;
|
||||
|
||||
pub const NOTE_C0H: u16 = NOTE_C0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_CS0H: u16 = NOTE_CS0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_D0H: u16 = NOTE_D0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_DS0H: u16 = NOTE_DS0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_E0H: u16 = NOTE_E0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_F0H: u16 = NOTE_F0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_FS0H: u16 = NOTE_FS0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_G0H: u16 = NOTE_G0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_GS0H: u16 = NOTE_GS0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_A0H: u16 = NOTE_A0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_AS0H: u16 = NOTE_AS0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_B0H: u16 = NOTE_B0 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_C1H: u16 = NOTE_C1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_CS1H: u16 = NOTE_CS1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_D1H: u16 = NOTE_D1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_DS1H: u16 = NOTE_DS1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_E1H: u16 = NOTE_E1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_F1H: u16 = NOTE_F1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_FS1H: u16 = NOTE_FS1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_G1H: u16 = NOTE_G1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_GS1H: u16 = NOTE_GS1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_A1H: u16 = NOTE_A1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_AS1H: u16 = NOTE_AS1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_B1H: u16 = NOTE_B1 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_C2H: u16 = NOTE_C2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_CS2H: u16 = NOTE_CS2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_D2H: u16 = NOTE_D2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_DS2H: u16 = NOTE_DS2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_E2H: u16 = NOTE_E2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_F2H: u16 = NOTE_F2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_FS2H: u16 = NOTE_FS2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_G2H: u16 = NOTE_G2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_GS2H: u16 = NOTE_GS2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_A2H: u16 = NOTE_A2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_AS2H: u16 = NOTE_AS2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_B2H: u16 = NOTE_B2 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_C3H: u16 = NOTE_C3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_CS3H: u16 = NOTE_CS3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_D3H: u16 = NOTE_D3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_DS3H: u16 = NOTE_DS3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_E3H: u16 = NOTE_E3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_F3H: u16 = NOTE_F3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_FS3H: u16 = NOTE_F3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_G3H: u16 = NOTE_G3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_GS3H: u16 = NOTE_GS3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_A3H: u16 = NOTE_A3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_AS3H: u16 = NOTE_AS3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_B3H: u16 = NOTE_B3 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_C4H: u16 = NOTE_C4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_CS4H: u16 = NOTE_CS4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_D4H: u16 = NOTE_D4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_DS4H: u16 = NOTE_DS4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_E4H: u16 = NOTE_E4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_F4H: u16 = NOTE_F4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_FS4H: u16 = NOTE_FS4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_G4H: u16 = NOTE_G4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_GS4H: u16 = NOTE_GS4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_A4H: u16 = NOTE_A4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_AS4H: u16 = NOTE_AS4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_B4H: u16 = NOTE_B4 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_C5H: u16 = NOTE_C5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_CS5H: u16 = NOTE_CS5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_D5H: u16 = NOTE_D5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_DS5H: u16 = NOTE_DS5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_E5H: u16 = NOTE_E5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_F5H: u16 = NOTE_F5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_FS5H: u16 = NOTE_FS5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_G5H: u16 = NOTE_G5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_GS5H: u16 = NOTE_GS5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_A5H: u16 = NOTE_A5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_AS5H: u16 = NOTE_AS5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_B5H: u16 = NOTE_B5 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_C6H: u16 = NOTE_C6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_CS6H: u16 = NOTE_CS6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_D6H: u16 = NOTE_D6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_DS6H: u16 = NOTE_DS6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_E6H: u16 = NOTE_E6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_F6H: u16 = NOTE_F6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_FS6H: u16 = NOTE_FS6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_G6H: u16 = NOTE_G6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_GS6H: u16 = NOTE_GS6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_A6H: u16 = NOTE_A6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_AS6H: u16 = NOTE_AS6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_B6H: u16 = NOTE_B6 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_C7H: u16 = NOTE_C7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_CS7H: u16 = NOTE_CS7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_D7H: u16 = NOTE_D7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_DS7H: u16 = NOTE_DS7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_E7H: u16 = NOTE_E7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_F7H: u16 = NOTE_F7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_FS7H: u16 = NOTE_FS7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_G7H: u16 = NOTE_G7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_GS7H: u16 = NOTE_GS7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_A7H: u16 = NOTE_A7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_AS7H: u16 = NOTE_AS7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_B7H: u16 = NOTE_B7 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_C8H: u16 = NOTE_C8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_CS8H: u16 = NOTE_CS8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_D8H: u16 = NOTE_D8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_DS8H: u16 = NOTE_DS8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_E8H: u16 = NOTE_E8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_F8H: u16 = NOTE_F8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_FS8H: u16 = NOTE_FS8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_G8H: u16 = NOTE_G8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_GS8H: u16 = NOTE_GS8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_A8H: u16 = NOTE_A8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_AS8H: u16 = NOTE_AS8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_B8H: u16 = NOTE_B8 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_C9H: u16 = NOTE_C9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_CS9H: u16 = NOTE_CS9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_D9H: u16 = NOTE_D9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_DS9H: u16 = NOTE_DS9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_E9H: u16 = NOTE_E9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_F9H: u16 = NOTE_F9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_FS9H: u16 = NOTE_FS9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_G9H: u16 = NOTE_G9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_GS9H: u16 = NOTE_GS9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_A9H: u16 = NOTE_A9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_AS9H: u16 = NOTE_AS9 + TONE_HIGH_VOLUME;
|
||||
pub const NOTE_B9H: u16 = NOTE_B9 + TONE_HIGH_VOLUME;
|
26
arduboy-rust/src/library/arduino.rs
Normal file
26
arduboy-rust/src/library/arduino.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use core::ffi::{c_long, c_ulong};
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "arduino_random_between"]
|
||||
fn arduino_random_between_raw(min: c_long, max: c_long) -> c_long;
|
||||
|
||||
#[link_name = "arduino_random_less_than"]
|
||||
fn arduino_random_less_than_raw(max: c_long) -> c_long;
|
||||
|
||||
#[link_name = "arduino_delay"]
|
||||
fn arduino_delay(ms: c_ulong);
|
||||
}
|
||||
/// A Arduino function to get a random number between 2 numbers
|
||||
/// seed based
|
||||
pub fn random_between(min: i32, max: i32) -> i32 {
|
||||
unsafe { arduino_random_between_raw(min, max) }
|
||||
}
|
||||
/// A Arduino function to get a random number smaller than the number given
|
||||
/// seed based
|
||||
pub fn random_less_than(max: i32) -> i32 {
|
||||
unsafe { arduino_random_less_than_raw(max) }
|
||||
}
|
||||
/// A Arduino function to pause the cpu circles for a given amount of ms
|
||||
pub fn delay(ms: u32) {
|
||||
unsafe { arduino_delay(ms) }
|
||||
}
|
11
arduboy-rust/src/library/c.rs
Normal file
11
arduboy-rust/src/library/c.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
//! Clib functions you can use on the Arduboy
|
||||
use core::ffi::{c_char, c_size_t};
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "strlen"]
|
||||
fn c_strlen(cstr: *const c_char) -> c_size_t;
|
||||
}
|
||||
/// A C function to get the length of a string
|
||||
pub fn strlen(cstr: *const i8) -> usize {
|
||||
unsafe { c_strlen(cstr) }
|
||||
}
|
65
arduboy-rust/src/library/eeprom.rs
Normal file
65
arduboy-rust/src/library/eeprom.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
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(b'M');
|
||||
self.update(b'V');
|
||||
self.update(0);
|
||||
};
|
||||
}
|
||||
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) }
|
||||
}
|
||||
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) }
|
||||
}
|
||||
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) }
|
||||
}
|
||||
}
|
7
arduboy-rust/src/library/mod.rs
Normal file
7
arduboy-rust/src/library/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
pub mod arduboy;
|
||||
pub mod arduboy_tone;
|
||||
pub mod arduboy_tone_pitch;
|
||||
pub mod arduino;
|
||||
pub mod c;
|
||||
pub mod eeprom;
|
||||
pub mod sprites;
|
47
arduboy-rust/src/library/sprites.rs
Normal file
47
arduboy-rust/src/library/sprites.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
//!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"]
|
||||
fn arduino_draw_override_raw(x: c_int, y: c_int, bitmap: *const c_uchar, frame: c_uchar);
|
||||
}
|
||||
/// Draw a sprite by replacing the existing content completely.
|
||||
///
|
||||
/// ### Parameters
|
||||
///
|
||||
/// x,y The coordinates of the top left pixel location.
|
||||
///
|
||||
/// bitmap A pointer to the array containing the image frames.
|
||||
///
|
||||
/// frame The frame number of the image to draw.
|
||||
///
|
||||
/// A sprite is drawn by overwriting the pixels in the buffer with the data from the specified frame in the array. No masking is done. A bit set to 1 in the frame will set the pixel to 1 in the buffer, and a 0 in the array will set a 0 in the buffer.
|
||||
///```
|
||||
/// image before after (# = 1, - = 0)
|
||||
///
|
||||
/// ----- ----- -----
|
||||
/// --#-- ----- --#--
|
||||
/// ###-## ----- ##-##
|
||||
/// --#-- ----- --#--
|
||||
/// ----- ----- -----
|
||||
///
|
||||
/// image before after
|
||||
///
|
||||
/// ----- ##### -----
|
||||
/// --#-- ##### --#--
|
||||
/// ###-## ##### ##-##
|
||||
/// --#-- ##### --#--
|
||||
/// ----- ##### -----
|
||||
/// ```
|
||||
pub fn draw_override(x: i16, y: i16, bitmap: *const u8, frame: u8) {
|
||||
unsafe { arduino_draw_override_raw(x, y, bitmap, frame) }
|
||||
}
|
27
arduboy-rust/src/prelude.rs
Normal file
27
arduboy-rust/src/prelude.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
//! This is the imported one to use this library effective in your project
|
||||
pub use crate::library::arduboy::Arduboy;
|
||||
pub use core::ffi::{
|
||||
c_char, c_double, c_float, c_int, c_long, c_longlong, c_size_t, c_uchar, c_uint, c_ulong,
|
||||
c_ulonglong,
|
||||
};
|
||||
pub use core::ptr::addr_of;
|
||||
///The main [Arduboy] struct ready to use in your project
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const arduboy: Arduboy = Arduboy {};
|
||||
///The main [Sound] struct ready to use in your project
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const sound: Sound = Sound {};
|
||||
pub use crate::hardware::buttons::*;
|
||||
pub use crate::library::arduboy::{Color, 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::sprites;
|
||||
pub use crate::print::*;
|
||||
pub use crate::{get_sprite_addr, get_tones_addr};
|
||||
use core::cmp;
|
||||
|
||||
pub fn constrain<T: Ord>(x: T, a: T, b: T) -> T {
|
||||
cmp::max(cmp::min(x, b), a)
|
||||
}
|
103
arduboy-rust/src/print.rs
Normal file
103
arduboy-rust/src/print.rs
Normal file
|
@ -0,0 +1,103 @@
|
|||
use core::ffi::c_int;
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub enum Base {
|
||||
Bin = 2,
|
||||
Oct = 8,
|
||||
Dec = 10,
|
||||
Hex = 16,
|
||||
}
|
||||
|
||||
pub trait Printable
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
type Parameters;
|
||||
|
||||
fn print_2(self, params: Self::Parameters);
|
||||
fn default_parameters() -> Self::Parameters;
|
||||
|
||||
fn print(self) {
|
||||
self.print_2(Self::default_parameters());
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for i16 {
|
||||
type Parameters = Base;
|
||||
|
||||
fn print_2(self, params: Self::Parameters) {
|
||||
unsafe {
|
||||
crate::library::arduboy::print_int(self, params as c_int);
|
||||
}
|
||||
}
|
||||
|
||||
fn default_parameters() -> Self::Parameters {
|
||||
Base::Dec
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for u16 {
|
||||
type Parameters = Base;
|
||||
|
||||
fn print_2(self, params: Self::Parameters) {
|
||||
unsafe {
|
||||
crate::library::arduboy::print_unsigned_int(self, params as c_int);
|
||||
}
|
||||
}
|
||||
|
||||
fn default_parameters() -> Self::Parameters {
|
||||
Base::Dec
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for i32 {
|
||||
type Parameters = Base;
|
||||
|
||||
fn print_2(self, params: Self::Parameters) {
|
||||
unsafe {
|
||||
crate::library::arduboy::print_long(self, params as c_int);
|
||||
}
|
||||
}
|
||||
|
||||
fn default_parameters() -> Self::Parameters {
|
||||
Base::Dec
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for u32 {
|
||||
type Parameters = Base;
|
||||
|
||||
fn print_2(self, params: Self::Parameters) {
|
||||
unsafe {
|
||||
crate::library::arduboy::print_unsigned_long(self, params as c_int);
|
||||
}
|
||||
}
|
||||
|
||||
fn default_parameters() -> Self::Parameters {
|
||||
Base::Dec
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for &[u8] {
|
||||
type Parameters = ();
|
||||
|
||||
fn print_2(self, _params: Self::Parameters) {
|
||||
unsafe {
|
||||
crate::library::arduboy::print_chars(self as *const [u8] as *const i8);
|
||||
}
|
||||
}
|
||||
|
||||
fn default_parameters() -> Self::Parameters {}
|
||||
}
|
||||
|
||||
impl Printable for &str {
|
||||
type Parameters = ();
|
||||
|
||||
fn print_2(self, _params: Self::Parameters) {
|
||||
unsafe {
|
||||
crate::library::arduboy::print_chars(self.as_bytes() as *const [u8] as *const i8);
|
||||
}
|
||||
}
|
||||
|
||||
fn default_parameters() -> Self::Parameters {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue