rust: Add mandelbrot

Add mandelbrot zoom demo, and move some things to shared crate.

Switch to most recent k210-pac revision to fix fp issue.
This commit is contained in:
Wladimir J. van der Laan 2019-05-11 17:54:48 +00:00
parent 819ad1665f
commit 667c051969
36 changed files with 609 additions and 24 deletions

View File

@ -58,6 +58,13 @@ in general.
[README](rust/k210-console/README.md)
rust/mandelbrot
---------------
Mandelbrot fractal zoom.
[README](rust/mandelbrot/README.md)
ROM re'ing
===========

2
rust/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

10
rust/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[workspace]
members = [
"k210-console",
"mandelbrot",
]
[patch.crates-io]
riscv-rt = { git = "https://github.com/rust-embedded/riscv-rt.git", rev = "ecc1344ffc9af1c88b3dd76b83ad56284672f888"}
k210-pac = { git = "https://github.com/riscv-rust/k210-pac.git", rev = "c24d654f5ad39eecf9758b852d0f54a88cefad3f"}
k210-hal = { git = "https://github.com/riscv-rust/k210-hal.git", rev = "725418b922d9bb6d8593ba4087b5d90f49e1b8e7" }

View File

@ -27,6 +27,7 @@ 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)",
@ -38,7 +39,7 @@ 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=eea80433bf6c0f91e1eeb89cd9f0b892b970149a)",
"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)",
]
@ -46,7 +47,7 @@ dependencies = [
[[package]]
name = "k210-pac"
version = "0.1.0"
source = "git+https://github.com/riscv-rust/k210-pac.git?rev=eea80433bf6c0f91e1eeb89cd9f0b892b970149a#eea80433bf6c0f91e1eeb89cd9f0b892b970149a"
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)",
@ -54,6 +55,15 @@ dependencies = [
"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"
@ -187,7 +197,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"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=eea80433bf6c0f91e1eeb89cd9f0b892b970149a)" = "<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"

View File

@ -9,8 +9,4 @@ panic-halt = "0.2.0"
riscv-rt = "0.5.0"
k210-hal = "0.1.0"
riscv = "0.5"
[patch.crates-io]
riscv-rt = { git = "https://github.com/rust-embedded/riscv-rt.git", rev = "ecc1344ffc9af1c88b3dd76b83ad56284672f888"}
k210-pac = { git = "https://github.com/riscv-rust/k210-pac.git", rev = "eea80433bf6c0f91e1eeb89cd9f0b892b970149a"}
k210-hal = { git = "https://github.com/riscv-rust/k210-hal.git", rev = "725418b922d9bb6d8593ba4087b5d90f49e1b8e7" }
k210-shared = { path = "../k210-shared" }

View File

@ -1,8 +0,0 @@
INCLUDE memory-k210.x
REGION_ALIAS("REGION_TEXT", SRAM_NOCACHE);
REGION_ALIAS("REGION_RODATA", SRAM_NOCACHE);
REGION_ALIAS("REGION_DATA", SRAM_NOCACHE);
REGION_ALIAS("REGION_BSS", SRAM_NOCACHE);
REGION_ALIAS("REGION_HEAP", SRAM_NOCACHE);
REGION_ALIAS("REGION_STACK", SRAM_NOCACHE);

View File

@ -1,4 +1,4 @@
use crate::board::lcd_colors::rgb565;
use k210_shared::board::lcd_colors::rgb565;
use crate::cp437;
use crate::cp437_8x8;

View File

@ -6,26 +6,24 @@
extern crate panic_halt;
mod board;
mod console;
mod cp437;
mod cp437_8x8;
mod lfsr;
mod palette_xterm256;
mod soc;
use k210_hal::pac;
use k210_hal::prelude::*;
use k210_hal::stdout::Stdout;
use k210_shared::board::lcd;
use k210_shared::board::lcd_colors;
use k210_shared::soc::fpioa;
use k210_shared::soc::sleep::usleep;
use k210_shared::soc::sysctl;
use riscv_rt::entry;
use crate::board::lcd;
use crate::board::lcd_colors;
use crate::console::{Color, Console, ScreenImage, DISP_HEIGHT, DISP_WIDTH};
use crate::palette_xterm256::PALETTE;
use crate::soc::fpioa;
use crate::soc::sleep::usleep;
use crate::soc::sysctl;
/** Connect pins to internal functions */
fn io_mux_init() {

2
rust/k210-shared/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

View 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

View File

@ -0,0 +1,10 @@
[package]
name = "k210-shared"
version = "0.1.0"
authors = ["W.J. van der Laan <laanwj@protonmail.com>"]
edition = "2018"
[dependencies]
riscv-rt = "0.5.0"
k210-hal = "0.1.0"
riscv = "0.5"

View File

@ -0,0 +1,41 @@
# `k210-console`
Console emulator written in rust for the Maix Go.
Barely functional at the moment. This is really a test for some functionality
like SPI and driving the display from Rust.
## 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

View File

@ -0,0 +1,8 @@
INCLUDE memory-k210.x
REGION_ALIAS("REGION_TEXT", SRAM);
REGION_ALIAS("REGION_RODATA", SRAM);
REGION_ALIAS("REGION_DATA", SRAM);
REGION_ALIAS("REGION_BSS", SRAM);
REGION_ALIAS("REGION_HEAP", SRAM);
REGION_ALIAS("REGION_STACK", SRAM);

View File

@ -0,0 +1,7 @@
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![no_std]
pub mod board;
pub mod soc;

View 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/mandelbrot/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

View 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

218
rust/mandelbrot/Cargo.lock generated Normal file
View File

@ -0,0 +1,218 @@
# 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"

View File

@ -0,0 +1,12 @@
[package]
name = "mandelbrot"
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"
k210-shared = { path = "../k210-shared" }

38
rust/mandelbrot/README.md Normal file
View File

@ -0,0 +1,38 @@
# `mandelbrot`
Obligatory Mandelbrot fractal zoom.
## 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/mandelbrot/gdb_init Normal file
View File

@ -0,0 +1,3 @@
target remote :3333
load
c

View 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

108
rust/mandelbrot/src/main.rs Normal file
View File

@ -0,0 +1,108 @@
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![no_std]
#![no_main]
extern crate panic_halt;
mod palette;
use k210_hal::pac;
use k210_hal::prelude::*;
use k210_hal::stdout::Stdout;
use k210_shared::board::lcd;
use k210_shared::board::lcd_colors;
use k210_shared::soc::fpioa;
use k210_shared::soc::sleep::usleep;
use k210_shared::soc::sysctl;
use riscv_rt::entry;
use crate::palette::PALETTE;
pub const DISP_WIDTH: usize = 320;
pub const DISP_HEIGHT: usize = 240;
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(37, fpioa::function::gpiohs(lcd::RST_GPIONUM));
fpioa::set_io_pull(37, fpioa::pull::DOWN); // outputs must be pull-down
fpioa::set_function(38, fpioa::function::gpiohs(lcd::DCX_GPIONUM));
fpioa::set_io_pull(38, fpioa::pull::DOWN);
fpioa::set_function(36, fpioa::function::SPI0_SS3);
fpioa::set_function(39, fpioa::function::SPI0_SCLK);
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);
}
fn mandelbrot(cx: f32, cy: f32, iterations: u32) -> u32 {
let mut z: (f32, f32) = (0.0, 0.0);
let mut i: u32 = 0;
while (z.0*z.0 + z.1*z.1) < 2.0*2.0 && i < iterations {
z = (z.0 * z.0 - z.1 * z.1 + cx, 2.0 * z.0 * z.1 + cy);
i += 1;
}
i
}
fn compute(x: u16, y: u16, zoom: f32) -> u16 {
let ofsx = 0.02997f32;
let ofsy = 0.80386f32;
let xx = 2.0 * (x as f32) / ((DISP_WIDTH-1) as f32) - 1.0;
let yy = 2.0 * (y as f32) / ((DISP_HEIGHT-1) as f32) - 1.0;
let i = mandelbrot(xx * zoom + ofsx, yy * zoom + ofsy, 20);
PALETTE[i as usize]
}
#[entry]
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();
// Configure clocks (TODO)
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_RLDU);
lcd::clear(lcd_colors::PURPLE);
let mut image: ScreenImage = [0; DISP_WIDTH * DISP_HEIGHT / 2];
writeln!(stdout, "First frame").unwrap();
let mut frame = 0;
let mut zoom = 5.0f32;
loop {
let mut ofs = 0;
for y in 0..DISP_HEIGHT as u16 {
for x in 0..(DISP_WIDTH/2) as u16 {
image[ofs] = ((compute(x*2+0, y, zoom) as u32)<<16) | (compute(x*2+1, y, zoom) as u32);
ofs += 1;
}
}
lcd::draw_picture(0, 0, DISP_WIDTH as u16, DISP_HEIGHT as u16, &image);
frame += 1;
zoom *= 0.98f32;
}
}

View File

@ -0,0 +1,27 @@
/// Xterm-256 palette, rgb565 format
/// First 16 colors are the VGA colors
pub const PALETTE: [u16; 256] = [
0x0000, 0xa800, 0x0540, 0xaaa0, 0x0015, 0xa815, 0x0555, 0xad55, 0x52aa, 0xfaaa, 0x57ea, 0xffea,
0x52bf, 0xfabf, 0x57ff, 0xffff, 0x0000, 0x000b, 0x0010, 0x0015, 0x001a, 0x001f, 0x02e0, 0x02eb,
0x02f0, 0x02f5, 0x02fa, 0x02ff, 0x0420, 0x042b, 0x0430, 0x0435, 0x043a, 0x043f, 0x0560, 0x056b,
0x0570, 0x0575, 0x057a, 0x057f, 0x06a0, 0x06ab, 0x06b0, 0x06b5, 0x06ba, 0x06bf, 0x07e0, 0x07eb,
0x07f0, 0x07f5, 0x07fa, 0x07ff, 0x5800, 0x580b, 0x5810, 0x5815, 0x581a, 0x581f, 0x5ae0, 0x5aeb,
0x5af0, 0x5af5, 0x5afa, 0x5aff, 0x5c20, 0x5c2b, 0x5c30, 0x5c35, 0x5c3a, 0x5c3f, 0x5d60, 0x5d6b,
0x5d70, 0x5d75, 0x5d7a, 0x5d7f, 0x5ea0, 0x5eab, 0x5eb0, 0x5eb5, 0x5eba, 0x5ebf, 0x5fe0, 0x5feb,
0x5ff0, 0x5ff5, 0x5ffa, 0x5fff, 0x8000, 0x800b, 0x8010, 0x8015, 0x801a, 0x801f, 0x82e0, 0x82eb,
0x82f0, 0x82f5, 0x82fa, 0x82ff, 0x8420, 0x842b, 0x8430, 0x8435, 0x843a, 0x843f, 0x8560, 0x856b,
0x8570, 0x8575, 0x857a, 0x857f, 0x86a0, 0x86ab, 0x86b0, 0x86b5, 0x86ba, 0x86bf, 0x87e0, 0x87eb,
0x87f0, 0x87f5, 0x87fa, 0x87ff, 0xa800, 0xa80b, 0xa810, 0xa815, 0xa81a, 0xa81f, 0xaae0, 0xaaeb,
0xaaf0, 0xaaf5, 0xaafa, 0xaaff, 0xac20, 0xac2b, 0xac30, 0xac35, 0xac3a, 0xac3f, 0xad60, 0xad6b,
0xad70, 0xad75, 0xad7a, 0xad7f, 0xaea0, 0xaeab, 0xaeb0, 0xaeb5, 0xaeba, 0xaebf, 0xafe0, 0xafeb,
0xaff0, 0xaff5, 0xaffa, 0xafff, 0xd000, 0xd00b, 0xd010, 0xd015, 0xd01a, 0xd01f, 0xd2e0, 0xd2eb,
0xd2f0, 0xd2f5, 0xd2fa, 0xd2ff, 0xd420, 0xd42b, 0xd430, 0xd435, 0xd43a, 0xd43f, 0xd560, 0xd56b,
0xd570, 0xd575, 0xd57a, 0xd57f, 0xd6a0, 0xd6ab, 0xd6b0, 0xd6b5, 0xd6ba, 0xd6bf, 0xd7e0, 0xd7eb,
0xd7f0, 0xd7f5, 0xd7fa, 0xd7ff, 0xf800, 0xf80b, 0xf810, 0xf815, 0xf81a, 0xf81f, 0xfae0, 0xfaeb,
0xfaf0, 0xfaf5, 0xfafa, 0xfaff, 0xfc20, 0xfc2b, 0xfc30, 0xfc35, 0xfc3a, 0xfc3f, 0xfd60, 0xfd6b,
0xfd70, 0xfd75, 0xfd7a, 0xfd7f, 0xfea0, 0xfeab, 0xfeb0, 0xfeb5, 0xfeba, 0xfebf, 0xffe0, 0xffeb,
0xfff0, 0xfff5, 0xfffa, 0xffff, 0x0841, 0x1082, 0x18e3, 0x2124, 0x3186, 0x39c7, 0x4228, 0x4a69,
0x5acb, 0x630c, 0x6b6d, 0x73ae, 0x8410, 0x8c51, 0x94b2, 0x9cf3, 0xad55, 0xb596, 0xbdf7, 0xc638,
0xd69a, 0xdedb, 0xe73c, 0xef7d,
];