mirror of
https://github.com/laanwj/k210-sdk-stuff.git
synced 2024-11-22 01:16:20 +04:00
rust: Add accelerometer
This commit is contained in:
parent
d24e79f7b9
commit
a7f437c8ce
@ -91,6 +91,13 @@ secp256k1\_{tests,bench}
|
||||
|
||||
Run tests and benchmarks for the secp256k1 elliptic curve cryptographic library on this RISC-V CPU.
|
||||
|
||||
rust/accelerometer
|
||||
-----------------
|
||||
|
||||
Read measurements from MSA300 accelerometer. Doesn't do anything interesting with them yet.
|
||||
|
||||
[README](rust/accelerometer/README.md)
|
||||
|
||||
rust/k210-console
|
||||
-----------------
|
||||
|
||||
|
@ -3,6 +3,7 @@ members = [
|
||||
"k210-console",
|
||||
"mandelbrot",
|
||||
"game-of-life",
|
||||
"accelerometer",
|
||||
]
|
||||
|
||||
[patch.crates-io]
|
||||
|
9
rust/accelerometer/.cargo/config
Normal file
9
rust/accelerometer/.cargo/config
Normal file
@ -0,0 +1,9 @@
|
||||
[target.riscv64gc-unknown-none-elf]
|
||||
runner = "riscv64-unknown-elf-gdb -x gdb_init"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tmemory.x",
|
||||
"-C", "link-arg=-Tlink.x",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "riscv64gc-unknown-none-elf"
|
2
rust/accelerometer/.gitignore
vendored
Normal file
2
rust/accelerometer/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
**/*.rs.bk
|
37
rust/accelerometer/CODE_OF_CONDUCT.md
Normal file
37
rust/accelerometer/CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,37 @@
|
||||
# The Rust Code of Conduct
|
||||
|
||||
## Conduct
|
||||
|
||||
**Contact**: [RISC-V team](https://github.com/rust-embedded/wg#the-riscv-team)
|
||||
|
||||
* We are committed to providing a friendly, safe and welcoming environment for all, regardless of level of experience, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, nationality, or other similar characteristic.
|
||||
* On IRC, please avoid using overtly sexual nicknames or other nicknames that might detract from a friendly, safe and welcoming environment for all.
|
||||
* Please be kind and courteous. There's no need to be mean or rude.
|
||||
* Respect that people have differences of opinion and that every design or implementation choice carries a trade-off and numerous costs. There is seldom a right answer.
|
||||
* Please keep unstructured critique to a minimum. If you have solid ideas you want to experiment with, make a fork and see how it works.
|
||||
* We will exclude you from interaction if you insult, demean or harass anyone. That is not welcome behavior. We interpret the term "harassment" as including the definition in the [Citizen Code of Conduct](http://citizencodeofconduct.org/); if you have any lack of clarity about what might be included in that concept, please read their definition. In particular, we don't tolerate behavior that excludes people in socially marginalized groups.
|
||||
* Private harassment is also unacceptable. No matter who you are, if you feel you have been or are being harassed or made uncomfortable by a community member, please contact one of the channel ops or any of the [RISC-V team][team] immediately. Whether you're a regular contributor or a newcomer, we care about making this community a safe place for you and we've got your back.
|
||||
* Likewise any spamming, trolling, flaming, baiting or other attention-stealing behavior is not welcome.
|
||||
|
||||
## Moderation
|
||||
|
||||
These are the policies for upholding our community's standards of conduct.
|
||||
|
||||
1. Remarks that violate the Rust standards of conduct, including hateful, hurtful, oppressive, or exclusionary remarks, are not allowed. (Cursing is allowed, but never targeting another user, and never in a hateful manner.)
|
||||
2. Remarks that moderators find inappropriate, whether listed in the code of conduct or not, are also not allowed.
|
||||
3. Moderators will first respond to such remarks with a warning.
|
||||
4. If the warning is unheeded, the user will be "kicked," i.e., kicked out of the communication channel to cool off.
|
||||
5. If the user comes back and continues to make trouble, they will be banned, i.e., indefinitely excluded.
|
||||
6. Moderators may choose at their discretion to un-ban the user if it was a first offense and they offer the offended party a genuine apology.
|
||||
7. If a moderator bans someone and you think it was unjustified, please take it up with that moderator, or with a different moderator, **in private**. Complaints about bans in-channel are not allowed.
|
||||
8. Moderators are held to a higher standard than other community members. If a moderator creates an inappropriate situation, they should expect less leeway than others.
|
||||
|
||||
In the Rust community we strive to go the extra step to look out for each other. Don't just aim to be technically unimpeachable, try to be your best self. In particular, avoid flirting with offensive or sensitive issues, particularly if they're off-topic; this all too often leads to unnecessary fights, hurt feelings, and damaged trust; worse, it can drive people away from the community entirely.
|
||||
|
||||
And if someone takes issue with something you said or did, resist the urge to be defensive. Just stop doing what it was they complained about and apologize. Even if you feel you were misinterpreted or unfairly accused, chances are good there was something you could've communicated better — remember that it's your responsibility to make your fellow Rustaceans comfortable. Everyone wants to get along and we are all here first and foremost because we want to talk about cool technology. You will find that people will be eager to assume good intent and forgive as long as you earn their trust.
|
||||
|
||||
The enforcement policies listed above apply to all official embedded WG venues; including official IRC channels (#rust-embedded); GitHub repositories under rust-embedded; and all forums under rust-embedded.org (forum.rust-embedded.org).
|
||||
|
||||
*Adapted from the [Node.js Policy on Trolling](http://blog.izs.me/post/30036893703/policy-on-trolling) as well as the [Contributor Covenant v1.3.0](https://www.contributor-covenant.org/version/1/3/0/).*
|
||||
|
||||
[team]: https://github.com/rust-embedded/wg#the-riscv-team
|
13
rust/accelerometer/Cargo.toml
Normal file
13
rust/accelerometer/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "accelerometer"
|
||||
version = "0.1.0"
|
||||
authors = ["W.J. van der Laan <laanwj@protonmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
panic-halt = "0.2.0"
|
||||
riscv-rt = "0.5.0"
|
||||
k210-hal = "0.1.0"
|
||||
riscv = "0.5"
|
||||
libm = "0.1"
|
||||
k210-shared = { path = "../k210-shared" }
|
38
rust/accelerometer/README.md
Normal file
38
rust/accelerometer/README.md
Normal file
@ -0,0 +1,38 @@
|
||||
# `accelerometer`
|
||||
|
||||
Read measurements from MSA300 accelerometer.
|
||||
|
||||
## Getting started
|
||||
|
||||
Start openocd:
|
||||
|
||||
openocd -f dp_busblaster.cfg -f openocd.cfg
|
||||
|
||||
Run the example:
|
||||
|
||||
cargo run --release
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2019 W. J. van der Laan
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
Contribution to this crate is organized under the terms of the [Rust Code of
|
||||
Conduct][CoC], the maintainer of this crate, the [RISC-V team][team], promises
|
||||
to intervene to uphold that code of conduct.
|
||||
|
||||
[CoC]: CODE_OF_CONDUCT.md
|
||||
[team]: https://github.com/rust-embedded/wg#the-riscv-team
|
3
rust/accelerometer/gdb_init
Normal file
3
rust/accelerometer/gdb_init
Normal file
@ -0,0 +1,3 @@
|
||||
target remote :3333
|
||||
load
|
||||
c
|
11
rust/accelerometer/openocd.cfg
Normal file
11
rust/accelerometer/openocd.cfg
Normal file
@ -0,0 +1,11 @@
|
||||
transport select jtag
|
||||
adapter_khz 1000
|
||||
|
||||
set _CHIPNAME riscv
|
||||
jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x04e4796b
|
||||
|
||||
set _TARGETNAME $_CHIPNAME.cpu
|
||||
target create $_TARGETNAME riscv -chain-position $_TARGETNAME
|
||||
|
||||
init
|
||||
halt
|
90
rust/accelerometer/src/main.rs
Normal file
90
rust/accelerometer/src/main.rs
Normal file
@ -0,0 +1,90 @@
|
||||
#![allow(dead_code)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use k210_hal::pac;
|
||||
use k210_hal::prelude::*;
|
||||
use k210_hal::stdout::Stdout;
|
||||
use k210_shared::board::def::{io,DISP_WIDTH,DISP_HEIGHT,MSA300_SLV_ADDR,MSA300_ADDR_BITS,MSA300_CLK};
|
||||
use k210_shared::board::lcd;
|
||||
use k210_shared::board::lcd_colors;
|
||||
use k210_shared::board::msa300;
|
||||
use k210_shared::soc::fpioa;
|
||||
use k210_shared::soc::i2c;
|
||||
use k210_shared::soc::sleep::usleep;
|
||||
use k210_shared::soc::sysctl;
|
||||
use libm::F32Ext;
|
||||
use riscv_rt::entry;
|
||||
|
||||
pub const BLK_SIZE: usize = 8;
|
||||
pub const GRID_WIDTH: usize = DISP_WIDTH / BLK_SIZE;
|
||||
pub const GRID_HEIGHT: usize = DISP_HEIGHT / BLK_SIZE;
|
||||
|
||||
/** Array for representing an image of the entire screen.
|
||||
* This is an array of DISP_WIDTH / 2 × DISP_HEIGHT, each two horizontally consecutive
|
||||
* pixels are encoded in a u32 with `(a << 16)|b`.
|
||||
*/
|
||||
pub type ScreenImage = [u32; DISP_WIDTH * DISP_HEIGHT / 2];
|
||||
|
||||
/** Connect pins to internal functions */
|
||||
fn io_mux_init() {
|
||||
/* Init SPI IO map and function settings */
|
||||
fpioa::set_function(io::LCD_RST.into(), fpioa::function::gpiohs(lcd::RST_GPIONUM));
|
||||
fpioa::set_io_pull(io::LCD_RST.into(), fpioa::pull::DOWN); // outputs must be pull-down
|
||||
fpioa::set_function(io::LCD_DC.into(), fpioa::function::gpiohs(lcd::DCX_GPIONUM));
|
||||
fpioa::set_io_pull(io::LCD_DC.into(), fpioa::pull::DOWN);
|
||||
fpioa::set_function(io::LCD_CS.into(), fpioa::function::SPI0_SS3);
|
||||
fpioa::set_function(io::LCD_WR.into(), fpioa::function::SPI0_SCLK);
|
||||
|
||||
/* I2C0 for touch-screen */
|
||||
fpioa::set_function(io::I2C1_SCL.into(), fpioa::function::I2C0_SCLK);
|
||||
fpioa::set_function(io::I2C1_SDA.into(), fpioa::function::I2C0_SDA);
|
||||
|
||||
sysctl::set_spi0_dvp_data(true);
|
||||
}
|
||||
|
||||
/** Set correct voltage for pins */
|
||||
fn io_set_power() {
|
||||
/* Set dvp and spi pin to 1.8V */
|
||||
sysctl::set_power_mode(sysctl::power_bank::BANK6, sysctl::io_power_mode::V18);
|
||||
sysctl::set_power_mode(sysctl::power_bank::BANK7, sysctl::io_power_mode::V18);
|
||||
}
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let p = pac::Peripherals::take().unwrap();
|
||||
|
||||
let clocks = k210_hal::clock::Clocks::new();
|
||||
|
||||
usleep(200000);
|
||||
|
||||
// Configure UART
|
||||
let serial = p.UARTHS.constrain(115_200.bps(), &clocks);
|
||||
let (mut tx, _) = serial.split();
|
||||
|
||||
let mut stdout = Stdout(&mut tx);
|
||||
|
||||
io_mux_init();
|
||||
io_set_power();
|
||||
|
||||
lcd::init();
|
||||
lcd::set_direction(lcd::direction::YX_LRUD);
|
||||
lcd::clear(lcd_colors::PURPLE);
|
||||
|
||||
let mut image: ScreenImage = [0; DISP_WIDTH * DISP_HEIGHT / 2];
|
||||
|
||||
writeln!(stdout, "MSA300 init").unwrap();
|
||||
i2c::init(MSA300_SLV_ADDR, MSA300_ADDR_BITS, MSA300_CLK);
|
||||
msa300::init();
|
||||
|
||||
loop {
|
||||
let (x, y, z) = msa300::measure().unwrap();
|
||||
let mag = (x*x+y*y+z*z).sqrt();
|
||||
writeln!(stdout, "m/s^2 x={} y={} z={} (size={})", x, y, z, mag).unwrap();
|
||||
usleep(100000);
|
||||
}
|
||||
}
|
218
rust/game-of-life/Cargo.lock
generated
218
rust/game-of-life/Cargo.lock
generated
@ -1,218 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "bare-metal"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit_field"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "k210-hal"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7#725418b922d9bb6d8593ba4087b5d90f49e1b8e7"
|
||||
dependencies = [
|
||||
"embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"k210-pac 0.1.0 (git+https://github.com/riscv-rust/k210-pac.git?rev=c24d654f5ad39eecf9758b852d0f54a88cefad3f)",
|
||||
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "k210-pac"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/riscv-rust/k210-pac.git?rev=c24d654f5ad39eecf9758b852d0f54a88cefad3f#c24d654f5ad39eecf9758b852d0f54a88cefad3f"
|
||||
dependencies = [
|
||||
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
"vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "k210-shared"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"k210-hal 0.1.0 (git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mandelbrot"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"k210-hal 0.1.0 (git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7)",
|
||||
"k210-shared 0.1.0",
|
||||
"panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "panic-halt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.6.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r0"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "riscv"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "riscv-rt"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888#ecc1344ffc9af1c88b3dd76b83ad56284672f888"
|
||||
dependencies = [
|
||||
"r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt-macros 0.1.5 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "riscv-rt-macros"
|
||||
version = "0.1.5"
|
||||
source = "git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888#ecc1344ffc9af1c88b3dd76b83ad56284672f888"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "vcell"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3caf393d93b2d453e80638d0674597020cef3382ada454faacd43d1a55a735a"
|
||||
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
|
||||
"checksum embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b"
|
||||
"checksum k210-hal 0.1.0 (git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7)" = "<none>"
|
||||
"checksum k210-pac 0.1.0 (git+https://github.com/riscv-rust/k210-pac.git?rev=c24d654f5ad39eecf9758b852d0f54a88cefad3f)" = "<none>"
|
||||
"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
|
||||
"checksum panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
|
||||
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
|
||||
"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db"
|
||||
"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
|
||||
"checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9"
|
||||
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0"
|
||||
"checksum riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "00f3ec73803f144a6474819070dfcf0b0d1662e1bd8845956850ee8f8cfbc69b"
|
||||
"checksum riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)" = "<none>"
|
||||
"checksum riscv-rt-macros 0.1.5 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)" = "<none>"
|
||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
"checksum vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45c297f0afb6928cd08ab1ff9d95e99392595ea25ae1b5ecf822ff8764e57a0d"
|
||||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
218
rust/k210-console/Cargo.lock
generated
218
rust/k210-console/Cargo.lock
generated
@ -1,218 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "bare-metal"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit_field"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "k210-console"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"k210-hal 0.1.0 (git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7)",
|
||||
"k210-shared 0.1.0",
|
||||
"panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "k210-hal"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7#725418b922d9bb6d8593ba4087b5d90f49e1b8e7"
|
||||
dependencies = [
|
||||
"embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"k210-pac 0.1.0 (git+https://github.com/riscv-rust/k210-pac.git?rev=c24d654f5ad39eecf9758b852d0f54a88cefad3f)",
|
||||
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "k210-pac"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/riscv-rust/k210-pac.git?rev=c24d654f5ad39eecf9758b852d0f54a88cefad3f#c24d654f5ad39eecf9758b852d0f54a88cefad3f"
|
||||
dependencies = [
|
||||
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
"vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "k210-shared"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"k210-hal 0.1.0 (git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "panic-halt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.6.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r0"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "riscv"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "riscv-rt"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888#ecc1344ffc9af1c88b3dd76b83ad56284672f888"
|
||||
dependencies = [
|
||||
"r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt-macros 0.1.5 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "riscv-rt-macros"
|
||||
version = "0.1.5"
|
||||
source = "git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888#ecc1344ffc9af1c88b3dd76b83ad56284672f888"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "vcell"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3caf393d93b2d453e80638d0674597020cef3382ada454faacd43d1a55a735a"
|
||||
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
|
||||
"checksum embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b"
|
||||
"checksum k210-hal 0.1.0 (git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7)" = "<none>"
|
||||
"checksum k210-pac 0.1.0 (git+https://github.com/riscv-rust/k210-pac.git?rev=c24d654f5ad39eecf9758b852d0f54a88cefad3f)" = "<none>"
|
||||
"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
|
||||
"checksum panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
|
||||
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
|
||||
"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db"
|
||||
"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
|
||||
"checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9"
|
||||
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0"
|
||||
"checksum riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "00f3ec73803f144a6474819070dfcf0b0d1662e1bd8845956850ee8f8cfbc69b"
|
||||
"checksum riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)" = "<none>"
|
||||
"checksum riscv-rt-macros 0.1.5 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)" = "<none>"
|
||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
"checksum vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45c297f0afb6928cd08ab1ff9d95e99392595ea25ae1b5ecf822ff8764e57a0d"
|
||||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
@ -1,4 +1,5 @@
|
||||
pub mod def;
|
||||
pub mod lcd;
|
||||
pub mod lcd_colors;
|
||||
pub mod msa300;
|
||||
pub mod ns2009;
|
||||
|
@ -20,6 +20,12 @@ pub const NS2009_CAL: [i32; 7] = [65, 5853, -1083592, -4292, -15, 16450115, 6553
|
||||
/** I2C address of MSA300 (accelerometer) */
|
||||
pub const MSA300_SLV_ADDR: u16 = 0x26;
|
||||
|
||||
/** I2C address bits for NS2009 */
|
||||
pub const MSA300_ADDR_BITS: u32 = 7;
|
||||
|
||||
/** I2C clock speed for MSA300 */
|
||||
pub const MSA300_CLK: u32 = 500000;
|
||||
|
||||
/** I/O pins for FPIOA */
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(u32)]
|
||||
|
114
rust/k210-shared/src/board/msa300.rs
Normal file
114
rust/k210-shared/src/board/msa300.rs
Normal file
@ -0,0 +1,114 @@
|
||||
/** Support for MSA300 accelerometer */
|
||||
/* MSA300 code based on 'accelerometer' demo by j.m.voogd@gmail.com */
|
||||
use crate::soc::i2c;
|
||||
|
||||
/** MSA300 Registers */
|
||||
enum reg {
|
||||
/** Part ID (R) */
|
||||
PARTID = 0x01,
|
||||
/** X-acceleration LSB (R) */
|
||||
ACC_X_LSB = 0x02,
|
||||
/** X-acceleration MSB (R) */
|
||||
ACC_X_MSB = 0x03,
|
||||
/** Y-acceleration LSB (R) */
|
||||
ACC_Y_LSB = 0x04,
|
||||
/** Y-acceleration MSB (R) */
|
||||
ACC_Y_MSB = 0x05,
|
||||
/** Z-acceleration LSB (R) */
|
||||
ACC_Z_LSB = 0x06,
|
||||
/** Z-acceleration MSB (R) */
|
||||
ACC_Z_MSB = 0x07,
|
||||
/** Resolution/Range (R/W) */
|
||||
RES_RANGE = 0x0F,
|
||||
/** Output Data Rate (R/W) */
|
||||
ODR = 0x10,
|
||||
/** Power Mode/Bandwidth (R/W) */
|
||||
PWR_MODE_BW = 0x11,
|
||||
/** Interrupt Set 0 (R/W) */
|
||||
INT_SET_0 = 0x16,
|
||||
/** Interrupt Set 1 (R/W) */
|
||||
INT_SET_1 = 0x17,
|
||||
/** Interrupt Latch (R/W) */
|
||||
INT_LATCH = 0x21,
|
||||
}
|
||||
|
||||
/** 0.488mg per lsb */
|
||||
const MG2G_MULTIPLIER_4_G: f32 = 0.000488;
|
||||
|
||||
/** 500Hz Bandwidth, not available in low power mode */
|
||||
const DATARATE_1000_HZ: u8 = 0x0F;
|
||||
|
||||
/** Gravity constant (Earth surface) */
|
||||
const GRAVITY: f32 = 9.80665;
|
||||
|
||||
/** Read a register of the MSA300 via I2C */
|
||||
fn read_register(reg: reg) -> Result<u8, ()> {
|
||||
let mut reg_val = [0u8; 2];
|
||||
if i2c::recv_data(&[reg as u8], &mut reg_val).is_ok() {
|
||||
Ok(reg_val[0])
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
/** Set a register of the MSA300 via I2C */
|
||||
fn set_register(reg: reg, val: u8) -> Result<(), ()> {
|
||||
i2c::send_data(&[reg as u8, val])
|
||||
}
|
||||
|
||||
/** Initialize chip */
|
||||
pub fn init() -> Result<(), ()> {
|
||||
let correct_id = 0x13;
|
||||
if let Ok(part_id) = read_register(reg::PARTID) {
|
||||
if part_id != correct_id {
|
||||
//writeln!(stdout, "MSA device not found (ID should be {:02x} but is {:02x})", correct_id, part_id).unwrap();
|
||||
return Err(());
|
||||
}
|
||||
} else {
|
||||
//writeln!(stdout, "Could not read MSA device ID").unwrap();
|
||||
return Err(());
|
||||
}
|
||||
|
||||
// set (and check) the power mode to 0x1A: normal power mode + 500Hz bandwidth
|
||||
let desired_mode = 0x1A;
|
||||
if set_register(reg::PWR_MODE_BW, desired_mode).is_err() {
|
||||
//writeln!(stdout, "Problem: setting power mode went wrong").unwrap();
|
||||
return Err(());
|
||||
}
|
||||
|
||||
let pwr_mode = read_register(reg::PWR_MODE_BW).unwrap();
|
||||
if pwr_mode != desired_mode {
|
||||
//writeln!(stdout, "Power mode should be {:02x} but is {:02x}", desired_mode, pwr_mode).unwrap();
|
||||
return Err(());
|
||||
}
|
||||
|
||||
// Enable x, y and z + set output data rate to 500 Hz
|
||||
set_register(reg::ODR, 0x09)?;
|
||||
// resolution 14 bits (MSB=8 bits, LSB=6 bits + 2 zero bits), range +- 4G
|
||||
set_register(reg::RES_RANGE, 0x01)?;
|
||||
// no interrupts
|
||||
set_register(reg::INT_SET_0, 0x00)?;
|
||||
set_register(reg::INT_SET_1, 0x00)?;
|
||||
// reset all latched interrupts, temporary latched 250ms
|
||||
set_register(reg::INT_LATCH, 0x81)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/** Return measurement in m/s^2 for x, y, z */
|
||||
pub fn measure() -> Result<(f32, f32, f32), ()> {
|
||||
// for x, y, and z: read the LSB (6 bits + 2 zero bits) and the MSB (8 bits)
|
||||
// shift the MSB left 8 bits, add the LSB, and multiply this with a calibration constant
|
||||
let tx = (read_register(reg::ACC_X_LSB)? as i32) +
|
||||
((read_register(reg::ACC_X_MSB)? as i8) as i32)*256;
|
||||
let x = 0.25f32 * MG2G_MULTIPLIER_4_G * GRAVITY * (tx as f32);
|
||||
let ty = (read_register(reg::ACC_Y_LSB)? as i32) +
|
||||
((read_register(reg::ACC_Y_MSB)? as i8) as i32)*256;
|
||||
let y = 0.25f32 * MG2G_MULTIPLIER_4_G * GRAVITY * (ty as f32);
|
||||
// looks like Z has a large bias - don't know if this is general or just on my board
|
||||
let tz = (read_register(reg::ACC_Z_LSB)? as i32) +
|
||||
((read_register(reg::ACC_Z_MSB)? as i8) as i32)*256 + 3386;
|
||||
let z = 0.25f32 * MG2G_MULTIPLIER_4_G * GRAVITY * (tz as f32);
|
||||
|
||||
Ok((x, y, z))
|
||||
}
|
@ -89,3 +89,40 @@ pub fn recv_data(send_buf: &[u8], receive_buf: &mut [u8]) -> Result<(), ()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn send_data(send_buf: &[u8]) -> Result<(), ()>
|
||||
{
|
||||
unsafe {
|
||||
let ptr = pac::I2C0::ptr();
|
||||
let mut txi = 0;
|
||||
let mut tx_left = send_buf.len();
|
||||
|
||||
// Clear TX abort by reading from clear register
|
||||
// Hopefully this is not optimized out
|
||||
(*ptr).clr_tx_abrt.read().bits();
|
||||
|
||||
// Send all data that is left, handle errors that occur
|
||||
while tx_left != 0 {
|
||||
let fifo_len = 8 - ((*ptr).txflr.read().bits() as usize);
|
||||
let fifo_len = cmp::min(tx_left, fifo_len);
|
||||
for _ in 0..fifo_len {
|
||||
(*ptr).data_cmd.write(|w| w.data().bits(send_buf[txi]));
|
||||
txi += 1;
|
||||
}
|
||||
if (*ptr).tx_abrt_source.read().bits() != 0 {
|
||||
return Err(());
|
||||
}
|
||||
tx_left -= fifo_len;
|
||||
}
|
||||
|
||||
// Wait for TX succeed
|
||||
while (*ptr).status.read().activity().bit() || !(*ptr).status.read().tfe().bit() {
|
||||
// NOP
|
||||
}
|
||||
|
||||
// Check for errors one last time
|
||||
if (*ptr).tx_abrt_source.read().bits() != 0 {
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
218
rust/mandelbrot/Cargo.lock
generated
218
rust/mandelbrot/Cargo.lock
generated
@ -1,218 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "bare-metal"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit_field"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "k210-hal"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7#725418b922d9bb6d8593ba4087b5d90f49e1b8e7"
|
||||
dependencies = [
|
||||
"embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"k210-pac 0.1.0 (git+https://github.com/riscv-rust/k210-pac.git?rev=c24d654f5ad39eecf9758b852d0f54a88cefad3f)",
|
||||
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "k210-pac"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/riscv-rust/k210-pac.git?rev=c24d654f5ad39eecf9758b852d0f54a88cefad3f#c24d654f5ad39eecf9758b852d0f54a88cefad3f"
|
||||
dependencies = [
|
||||
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
"vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "k210-shared"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"k210-hal 0.1.0 (git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mandelbrot"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"k210-hal 0.1.0 (git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7)",
|
||||
"k210-shared 0.1.0",
|
||||
"panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "panic-halt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.6.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r0"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "riscv"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "riscv-rt"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888#ecc1344ffc9af1c88b3dd76b83ad56284672f888"
|
||||
dependencies = [
|
||||
"r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"riscv-rt-macros 0.1.5 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "riscv-rt-macros"
|
||||
version = "0.1.5"
|
||||
source = "git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888#ecc1344ffc9af1c88b3dd76b83ad56284672f888"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "vcell"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3caf393d93b2d453e80638d0674597020cef3382ada454faacd43d1a55a735a"
|
||||
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
|
||||
"checksum embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b"
|
||||
"checksum k210-hal 0.1.0 (git+https://github.com/riscv-rust/k210-hal.git?rev=725418b922d9bb6d8593ba4087b5d90f49e1b8e7)" = "<none>"
|
||||
"checksum k210-pac 0.1.0 (git+https://github.com/riscv-rust/k210-pac.git?rev=c24d654f5ad39eecf9758b852d0f54a88cefad3f)" = "<none>"
|
||||
"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
|
||||
"checksum panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
|
||||
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
|
||||
"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db"
|
||||
"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
|
||||
"checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9"
|
||||
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0"
|
||||
"checksum riscv 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "00f3ec73803f144a6474819070dfcf0b0d1662e1bd8845956850ee8f8cfbc69b"
|
||||
"checksum riscv-rt 0.5.0 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)" = "<none>"
|
||||
"checksum riscv-rt-macros 0.1.5 (git+https://github.com/rust-embedded/riscv-rt.git?rev=ecc1344ffc9af1c88b3dd76b83ad56284672f888)" = "<none>"
|
||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
"checksum vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45c297f0afb6928cd08ab1ff9d95e99392595ea25ae1b5ecf822ff8764e57a0d"
|
||||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
Loading…
Reference in New Issue
Block a user