Try controlling dotstars through SPI and through bit-banging

This commit is contained in:
Savanni D'Gerinel 2023-11-09 22:24:37 -05:00
parent 7e3ee9a5b7
commit 168ba6eb40
5 changed files with 475 additions and 8 deletions

353
Cargo.lock generated
View File

@ -119,6 +119,12 @@ version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "arrayvec"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]]
name = "atoi"
version = "2.0.0"
@ -158,6 +164,15 @@ dependencies = [
"rustc-demangle",
]
[[package]]
name = "bare-metal"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
dependencies = [
"rustc_version 0.2.3",
]
[[package]]
name = "base64"
version = "0.9.3"
@ -201,6 +216,12 @@ version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
[[package]]
name = "bitfield"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
[[package]]
name = "bitflags"
version = "1.3.2"
@ -480,6 +501,38 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "cortex-m"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9"
dependencies = [
"bare-metal",
"bitfield",
"embedded-hal",
"volatile-register",
]
[[package]]
name = "cortex-m-rt"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee84e813d593101b1723e13ec38b6ab6abbdbaaa4546553f5395ed274079ddb1"
dependencies = [
"cortex-m-rt-macros",
]
[[package]]
name = "cortex-m-rt-macros"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0f6f3e36f203cfedbc78b357fb28730aa2c6dc1ab060ee5c2405e843988d3c7"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "cpufeatures"
version = "0.2.9"
@ -498,6 +551,15 @@ dependencies = [
"crc-catalog",
]
[[package]]
name = "crc-any"
version = "2.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "774646b687f63643eb0f4bf13dc263cb581c8c9e57973b6ddf78bda3994d88df"
dependencies = [
"debug-helper",
]
[[package]]
name = "crc-catalog"
version = "2.2.0"
@ -513,6 +575,12 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "critical-section"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216"
[[package]]
name = "crossbeam-deque"
version = "0.8.3"
@ -615,6 +683,12 @@ version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
[[package]]
name = "debug-helper"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f578e8e2c440e7297e008bb5486a3a8a194775224bbc23729b0dbdfaeebf162e"
[[package]]
name = "deflate"
version = "0.8.6"
@ -692,6 +766,25 @@ dependencies = [
"serde 1.0.188",
]
[[package]]
name = "embedded-dma"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "994f7e5b5cb23521c22304927195f236813053eb9c065dd2226a32ba64695446"
dependencies = [
"stable_deref_trait",
]
[[package]]
name = "embedded-hal"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff"
dependencies = [
"nb 0.1.3",
"void",
]
[[package]]
name = "emseries"
version = "0.6.0"
@ -811,7 +904,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f"
dependencies = [
"memoffset",
"rustc_version",
"rustc_version 0.4.0",
]
[[package]]
@ -956,12 +1049,60 @@ dependencies = [
"percent-encoding 2.3.0",
]
[[package]]
name = "frunk"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11a351b59e12f97b4176ee78497dff72e4276fb1ceb13e19056aca7fa0206287"
dependencies = [
"frunk_core",
"frunk_derives",
]
[[package]]
name = "frunk_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af2469fab0bd07e64ccf0ad57a1438f63160c69b2e57f04a439653d68eb558d6"
[[package]]
name = "frunk_derives"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fa992f1656e1707946bbba340ad244f0814009ef8c0118eb7b658395f19a2e"
dependencies = [
"frunk_proc_macro_helpers",
"quote",
"syn 2.0.37",
]
[[package]]
name = "frunk_proc_macro_helpers"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35b54add839292b743aeda6ebedbd8b11e93404f902c56223e51b9ec18a13d2c"
dependencies = [
"frunk_core",
"proc-macro2",
"quote",
"syn 2.0.37",
]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "fugit"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17186ad64927d5ac8f02c1e77ccefa08ccd9eaa314d5a4772278aa204a22f7e7"
dependencies = [
"gcd",
]
[[package]]
name = "futures"
version = "0.3.28"
@ -1062,6 +1203,12 @@ dependencies = [
"slab",
]
[[package]]
name = "gcd"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a"
[[package]]
name = "gdk-pixbuf"
version = "0.17.10"
@ -1923,6 +2070,15 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "itertools"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.11.0"
@ -2284,6 +2440,21 @@ dependencies = [
"tempfile",
]
[[package]]
name = "nb"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f"
dependencies = [
"nb 1.1.0",
]
[[package]]
name = "nb"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
[[package]]
name = "no-std-compat"
version = "0.4.1"
@ -2388,6 +2559,26 @@ dependencies = [
"libc",
]
[[package]]
name = "num_enum"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9"
dependencies = [
"num_enum_derive",
]
[[package]]
name = "num_enum_derive"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "object"
version = "0.32.1"
@ -2498,6 +2689,12 @@ dependencies = [
"system-deps",
]
[[package]]
name = "panic-halt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
[[package]]
name = "parking_lot"
version = "0.12.1"
@ -2634,6 +2831,18 @@ dependencies = [
"siphasher 0.3.11",
]
[[package]]
name = "pico-blink"
version = "0.1.0"
dependencies = [
"cortex-m",
"cortex-m-rt",
"embedded-hal",
"fugit",
"panic-halt",
"rp-pico",
]
[[package]]
name = "pin-project"
version = "1.1.3"
@ -2666,6 +2875,17 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pio"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76e09694b50f89f302ed531c1f2a7569f0be5867aee4ab4f8f729bbeec0078e3"
dependencies = [
"arrayvec",
"num_enum",
"paste",
]
[[package]]
name = "pkcs1"
version = "0.7.5"
@ -3119,6 +3339,76 @@ dependencies = [
"thiserror",
]
[[package]]
name = "rp-pico"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6341771e6f8e5d130b2b3cbc23435b7847761adf198af09f4b2a60407d43bd56"
dependencies = [
"cortex-m-rt",
"fugit",
"rp2040-boot2",
"rp2040-hal",
"usb-device",
]
[[package]]
name = "rp2040-boot2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c92f344f63f950ee36cf4080050e4dce850839b9175da38f9d2ffb69b4dbb21"
dependencies = [
"crc-any",
]
[[package]]
name = "rp2040-hal"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ec610f738b69100fbe75f3b835501b669d41c889ac9a62ef284f8e6d1f17385"
dependencies = [
"cortex-m",
"critical-section",
"embedded-dma",
"embedded-hal",
"frunk",
"fugit",
"itertools 0.10.5",
"nb 1.1.0",
"paste",
"pio",
"rand_core 0.6.4",
"rp2040-hal-macros",
"rp2040-pac",
"usb-device",
"vcell",
"void",
]
[[package]]
name = "rp2040-hal-macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86479063e497efe1ae81995ef9071f54fd1c7427e04d6c5b84cde545ff672a5e"
dependencies = [
"cortex-m-rt",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "rp2040-pac"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12d9d8375815f543f54835d01160d4e47f9e2cae75f17ff8f1ec19ce1da96e4c"
dependencies = [
"cortex-m",
"cortex-m-rt",
"critical-section",
"vcell",
]
[[package]]
name = "rsa"
version = "0.9.2"
@ -3153,13 +3443,22 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver 0.9.0",
]
[[package]]
name = "rustc_version"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
"semver 1.0.19",
]
[[package]]
@ -3271,12 +3570,27 @@ version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af"
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0"
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "0.9.15"
@ -3472,7 +3786,7 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b7b278788e7be4d0d29c0f39497a0eef3fba6bbc8e70d8bf7fde46edeaa9e85"
dependencies = [
"itertools",
"itertools 0.11.0",
"nom",
"unicode_categories",
]
@ -3671,6 +3985,12 @@ dependencies = [
"url 2.4.1",
]
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "stringprep"
version = "0.1.4"
@ -4247,6 +4567,12 @@ dependencies = [
"percent-encoding 2.3.0",
]
[[package]]
name = "usb-device"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508"
[[package]]
name = "utf-8"
version = "0.7.6"
@ -4288,6 +4614,12 @@ dependencies = [
"getrandom",
]
[[package]]
name = "vcell"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002"
[[package]]
name = "vcpkg"
version = "0.2.15"
@ -4312,6 +4644,21 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "volatile-register"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de437e2a6208b014ab52972a27e59b33fa2920d3e00fe05026167a1c509d19cc"
dependencies = [
"vcell",
]
[[package]]
name = "wait-timeout"
version = "0.2.0"

View File

@ -17,6 +17,7 @@ members = [
"kifu/gtk",
"memorycache",
"nom-training",
"pico-blink",
"result-extended",
"screenplay",
"sgf",

View File

@ -9,5 +9,6 @@ edition = "2021"
cortex-m = "0.7.7"
cortex-m-rt = "0.7.3"
embedded-hal = "0.2.7"
fugit = "0.3.7"
panic-halt = "0.2.0"
rp-pico = "0.8.0"

View File

@ -1,10 +1,95 @@
#![no_main]
#![no_std]
use rp_pico::entry;
use panic_halt as _;
use embedded_hal::blocking::spi::Write;
use embedded_hal::digital::v2::OutputPin;
use rp_pico::{hal, hal::{clocks, pac, watchdog::Watchdog, clocks::{Clock, init_clocks_and_plls}}};
use fugit::RateExtU32;
use panic_halt as _;
use rp_pico::entry;
use rp_pico::hal::gpio::{FunctionSio, PinId, PullType, SioOutput};
use rp_pico::{
hal,
hal::prelude::*,
hal::{
clocks::{init_clocks_and_plls, Clock},
gpio::Pin,
pac,
spi::Spi,
watchdog::Watchdog,
},
};
fn send_byte<I, J, P>(
data: &mut Pin<I, FunctionSio<SioOutput>, P>,
clock: &mut Pin<J, FunctionSio<SioOutput>, P>,
delay: &mut cortex_m::delay::Delay,
byte: u8,
) where
I: PinId,
J: PinId,
P: PullType,
{
(0..7).for_each(|bit| {
if byte & (1 << (7 - bit)) > 0 {
data.set_high();
} else {
data.set_low();
}
clock.set_high();
delay.delay_us(100);
clock.set_low();
delay.delay_us(100);
});
clock.set_low();
}
fn send_start<I, J, P>(
data: &mut Pin<I, FunctionSio<SioOutput>, P>,
clock: &mut Pin<J, FunctionSio<SioOutput>, P>,
delay: &mut cortex_m::delay::Delay,
) where
I: PinId,
J: PinId,
P: PullType,
{
send_byte(data, clock, delay, 0);
send_byte(data, clock, delay, 0);
send_byte(data, clock, delay, 0);
send_byte(data, clock, delay, 0);
}
fn send_term<I, J, P>(
data: &mut Pin<I, FunctionSio<SioOutput>, P>,
clock: &mut Pin<J, FunctionSio<SioOutput>, P>,
delay: &mut cortex_m::delay::Delay,
) where
I: PinId,
J: PinId,
P: PullType,
{
send_byte(data, clock, delay, 0xff);
send_byte(data, clock, delay, 0xff);
send_byte(data, clock, delay, 0xff);
send_byte(data, clock, delay, 0xff);
}
fn send<I, J, P>(
data: &mut Pin<I, FunctionSio<SioOutput>, P>,
clock: &mut Pin<J, FunctionSio<SioOutput>, P>,
delay: &mut cortex_m::delay::Delay,
values: &[u8],
) where
I: PinId,
J: PinId,
P: PullType,
{
send_start(data, clock, delay);
for val in values {
send_byte(data, clock, delay, *val);
}
send_term(data, clock, delay);
clock.set_low();
}
#[entry]
fn main() -> ! {
@ -29,14 +114,47 @@ fn main() -> ! {
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
).ok().unwrap();
)
.ok()
.unwrap();
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
let mut spi_clk = pins.gpio10.into_push_pull_output();
let mut spi_sdo = pins.gpio11.into_push_pull_output();
/*
let spi = Spi::<_, _, _, 8>::new(pac.SPI1, (spi_sdo, spi_clk));
let mut spi = spi.init(
&mut pac.RESETS,
clocks.peripheral_clock.freq(),
1.MHz(),
embedded_hal::spi::MODE_0,
);
*/
let mut led_pin = pins.led.into_push_pull_output();
let mut blue_pin = pins.gpio3.into_push_pull_output();
led_pin.set_high().unwrap();
spi_clk.set_low();
spi_sdo.set_low();
loop {
send(
&mut spi_sdo,
&mut spi_clk,
&mut delay,
&[
0, 0, 0, 0, 0xf0, 0x80, 0x0, 0x0, 0xe1, 0x0, 0x80, 0x0, 0xe1, 0x0, 0x0, 0x80, 0xff,
0xff, 0xff, 0xff,
],
);
/*
spi.write(&[
0, 0, 0, 0, 0xf0, 0x80, 0x0, 0x0, 0xe1, 0x0, 0x80, 0x0, 0xe1, 0x0, 0x0, 0x80, 0xff,
0xff, 0xff, 0xff,
]);
*/
led_pin.set_high().unwrap();
blue_pin.set_low().unwrap();
delay.delay_ms(500);