From 1b34a7f20403fd713c0aff2bbe8df64711036c37 Mon Sep 17 00:00:00 2001 From: James Munns Date: Tue, 26 May 2020 23:18:32 +0200 Subject: [PATCH 1/8] Not exactly initial commit --- .gitmodules | 6 + ili9341-rs | 1 + keywing/.cargo/config | 9 + keywing/.gitignore | 2 + keywing/Cargo.lock | 371 ++++++++++++++++++++++++++++++++ keywing/Cargo.toml | 46 ++++ keywing/Embed.toml | 46 ++++ keywing/debug.gdb | 6 + keywing/memory.x | 10 + keywing/src/buffer.rs | 62 ++++++ keywing/src/main.rs | 483 ++++++++++++++++++++++++++++++++++++++++++ nrf-hal | 1 + 12 files changed, 1043 insertions(+) create mode 100644 .gitmodules create mode 160000 ili9341-rs create mode 100644 keywing/.cargo/config create mode 100644 keywing/.gitignore create mode 100644 keywing/Cargo.lock create mode 100644 keywing/Cargo.toml create mode 100644 keywing/Embed.toml create mode 100644 keywing/debug.gdb create mode 100644 keywing/memory.x create mode 100644 keywing/src/buffer.rs create mode 100644 keywing/src/main.rs create mode 160000 nrf-hal diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ef75d6c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "ili9341-rs"] + path = ili9341-rs + url = git@github.com:jamesmunns/ili9341-rs.git +[submodule "nrf-hal"] + path = nrf-hal + url = git@github.com:jamesmunns/nrf-hal.git diff --git a/ili9341-rs b/ili9341-rs new file mode 160000 index 0000000..c732509 --- /dev/null +++ b/ili9341-rs @@ -0,0 +1 @@ +Subproject commit c7325094ebbc60640c4842e038c8de27beae48ad diff --git a/keywing/.cargo/config b/keywing/.cargo/config new file mode 100644 index 0000000..5673fa9 --- /dev/null +++ b/keywing/.cargo/config @@ -0,0 +1,9 @@ +[build] +target = "thumbv7em-none-eabihf" + +[target.thumbv7em-none-eabihf] +# runner = 'gdbgui -g arm-none-eabi-gdb --gdb-args="-command=debug.gdb"' +runner = "arm-none-eabi-gdb -tui -q -x debug.gdb" +rustflags = [ + "-C", "link-arg=-Tlink.x", +] diff --git a/keywing/.gitignore b/keywing/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/keywing/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/keywing/Cargo.lock b/keywing/Cargo.lock new file mode 100644 index 0000000..7b27e81 --- /dev/null +++ b/keywing/Cargo.lock @@ -0,0 +1,371 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aligned" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "as-slice" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", + "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bare-metal" +version = "0.2.5" +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 = "byteorder" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cast" +version = "0.2.3" +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 = "cortex-m" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aligned 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cortex-m-rt" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cortex-m-rt-macros 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cortex-m-rt-macros" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "embedded-graphics" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (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 = "fpa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "generic-array" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "generic-array" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hash32" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "heapless" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hash32 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ili9341" +version = "0.3.0" +dependencies = [ + "embedded-graphics 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "nb" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "nrf-hal-common" +version = "0.10.0" +dependencies = [ + "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fpa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "nrf52840-pac 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "nrf52840-hal" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "nrf-hal-common 0.10.0", + "nrf52840-pac 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "nrf52840-pac" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "panic-persist" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro2" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (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.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rtt-target" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ufmt-write 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "vcell 0.1.2 (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 = "stable_deref_trait" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "syn" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tiny-nrf52" +version = "0.1.0" +dependencies = [ + "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-graphics 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "heapless 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ili9341 0.3.0", + "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "nrf52840-hal 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "panic-persist 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rtt-target 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "typenum" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "ufmt-write" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "vcell" +version = "0.1.2" +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" + +[[package]] +name = "volatile-register" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum aligned 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a316c7ea8e1e9ece54862c992def5a7ac14de9f5832b69d71760680efeeefa" +"checksum as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "293dac66b274fab06f95e7efb05ec439a6b70136081ea522d270bc351ae5bb27" +"checksum bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" +"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +"checksum cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" +"checksum cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2954942fbbdd49996704e6f048ce57567c3e1a4e2dc59b41ae9fde06a01fc763" +"checksum cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "17805910e3ecf029bdbfcc42b7384d9e3d9e5626153fa810002c1ef9839338ac" +"checksum cortex-m-rt-macros 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2a6dc359ebb215c4924bffacfe46a8f02ef80fe2071bba1635a2ded42b40f936" +"checksum embedded-graphics 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "40a69991ceb896bd4810a0cf2bcc46fc94b7860573c71f965d8e5b3d66942fed" +"checksum embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b" +"checksum fpa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f074479d683e5a8fd0bf1251d0a5d91b0d9178b867b44962191ed0eaaf8d4009" +"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +"checksum generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd" +"checksum hash32 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d4041af86e63ac4298ce40e5cca669066e75b6f1aa3390fe2561ffa5e1d9f4cc" +"checksum heapless 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f339aa7d51777fc0af6aa7cbeb277dfc6e6c029cbdeda48d0fbb92c2337f0e69" +"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc" +"checksum nrf52840-hal 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6aab4c41abc02fcefbdbedfa773d213302bc00c57a0b2237c6b5bf0456da10d3" +"checksum nrf52840-pac 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1b780a5afd2621774652f28c82837f6aa6d19cf0ad71c734fc1fe53298a2d73" +"checksum panic-persist 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dd2e692a5954e3eb0c16f5dbaa75c4332a78d85851521f138c04ad95d6f5ee42" +"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" +"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +"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.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" +"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +"checksum rtt-target 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "58b1f36984bbcf227044b3b7af1de14a6ebe51b9d21cd856a3d5ba41c70ec191" +"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 stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" +"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92" +"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +"checksum ufmt-write 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69" +"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +"checksum vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "876e32dcadfe563a4289e994f7cb391197f362b6315dc45e8ba4aa6f564a4b3c" +"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +"checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286" diff --git a/keywing/Cargo.toml b/keywing/Cargo.toml new file mode 100644 index 0000000..85b93b8 --- /dev/null +++ b/keywing/Cargo.toml @@ -0,0 +1,46 @@ +[package] +name = "tiny-nrf52" +version = "0.1.0" +authors = ["James Munns "] +edition = "2018" + +[dependencies] +cortex-m-rt = "0.6.10" +cortex-m = "0.6.1" +nb = "0.1.2" +heapless = "0.5.1" +embedded-hal = "0.2" +rtt-target = {version = "0.2.0", features = ["cortex-m"] } +embedded-graphics = "0.6.2" + +[dependencies.ili9341] +version = "0.3.0" +path = "../ili9341-rs" + +[dependencies.nrf52840-hal] +version = "0.10.0" +features = ["rt"] + +[dependencies.panic-persist] +version = "0.2.1" +default-features = false +features = ["utf8"] + +[profile.dev] +lto = true +panic = "abort" +debug = true +incremental = false +codegen-units = 1 +opt-level = 0 + +[profile.release] +lto = true +panic = "abort" +debug = true +incremental = false +codegen-units = 1 +opt-level = 's' + +[patch.crates-io] +nrf-hal-common = { path = "../nrf-hal/nrf-hal-common" } diff --git a/keywing/Embed.toml b/keywing/Embed.toml new file mode 100644 index 0000000..918f48c --- /dev/null +++ b/keywing/Embed.toml @@ -0,0 +1,46 @@ +[probe] +# The index of the probe in the connected probe list. +probe_index = 0 +# The protocol to be used for communicating with the target. +protocol = "Swd" +# The speed in kHz of the data link to the target. +# speed = 1337 + +[flashing] +# Whether or not the target should be flashed. +enabled = true +# Whether or not the target should be halted after flashing. +halt_afterwards = false +# Whether or not bytes erased but not rewritten with data from the ELF +# should be restored with their contents before erasing. +restore_unwritten_bytes = false +# The path where an SVG of the assembled flash layout should be written to. +# flash_layout_output_path = "out.svg" + +[general] +# The chip name of the chip to be debugged. +chip = "nRF52840_xxAA" +# A list of chip descriptions to be loaded during runtime. +chip_descriptions = [] +# The default log level to be used. +log_level = "Warn" + +[rtt] +# Whether or not an RTTUI should be opened after flashing. +# This is exclusive and cannot be used with GDB at the moment. +enabled = true +# A list of channel associations to be displayed. If left empty, all channels are displayed. +channels = [ + # { up = 0, down = 0, name = "name" } +] +# The duration in ms for which the logger should retry to attach to RTT. +timeout = 3000 +# Whether timestamps in the RTTUI are enabled +show_timestamps = true + +[gdb] +# Whether or not a GDB server should be opened after flashing. +# This is exclusive and cannot be used with RTT at the moment. +enabled = false +# The connection string in host:port format wher the GDB server will open a socket. +# gdb_connection_string diff --git a/keywing/debug.gdb b/keywing/debug.gdb new file mode 100644 index 0000000..3696a91 --- /dev/null +++ b/keywing/debug.gdb @@ -0,0 +1,6 @@ +target remote :2331 +set backtrace limit 32 +load +monitor reset +break main +continue diff --git a/keywing/memory.x b/keywing/memory.x new file mode 100644 index 0000000..46f1278 --- /dev/null +++ b/keywing/memory.x @@ -0,0 +1,10 @@ +MEMORY +{ + /* NOTE K = KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x00000000, LENGTH = 1M + RAM : ORIGIN = 0x20000000, LENGTH = 255K + PANDUMP: ORIGIN = 0x2003FC00, LENGTH = 1K +} + +_panic_dump_start = ORIGIN(PANDUMP); +_panic_dump_end = ORIGIN(PANDUMP) + LENGTH(PANDUMP); diff --git a/keywing/src/buffer.rs b/keywing/src/buffer.rs new file mode 100644 index 0000000..da912ad --- /dev/null +++ b/keywing/src/buffer.rs @@ -0,0 +1,62 @@ +use embedded_graphics::{ + drawable::Pixel, + geometry::{Point, Size}, + pixelcolor::{ + raw::{RawData, RawU16}, + Rgb565, + }, + primitives::Rectangle, + style::{PrimitiveStyle, Styled}, + DrawTarget, +}; + +pub struct FrameBuffer<'a> { + buf: &'a mut [[u16; 320]; 240], +} + +impl<'a> FrameBuffer<'a> { + pub fn new(raw: &'a mut [[u16; 320]; 240]) -> Self { + Self { + buf: raw + } + } + + pub fn inner(&self) -> &[u16] { + unsafe { + core::slice::from_raw_parts(self.buf.as_ptr().cast::(), (self.width() * self.height()) as usize) + } + } + + fn width(&self) -> u32 { + self.buf.len() as u32 + } + + fn height(&self) -> u32 { + self.buf[0].len() as u32 + } +} + +impl<'a> DrawTarget for FrameBuffer<'a> +{ + type Error = (); + + fn size(&self) -> Size { + Size::new(self.width(), self.height()) + } + + fn draw_pixel(&mut self, pixel: Pixel) -> Result<(), Self::Error> { + let Pixel(pos, color) = pixel; + + if pos.x < 0 || pos.y < 0 || pos.x >= self.width() as i32 || pos.y >= self.height() as i32 { + return Ok(()); + } + + self.buf[pos.y as usize][pos.x as usize] = swap(RawU16::from(color).into_inner()); + Ok(()) + } +} + +const fn swap(inp: u16) -> u16 { + (inp & 0x00FF) << 8 | + (inp & 0xFF00) >> 8 +} diff --git a/keywing/src/main.rs b/keywing/src/main.rs new file mode 100644 index 0000000..fd71350 --- /dev/null +++ b/keywing/src/main.rs @@ -0,0 +1,483 @@ +#![no_std] +#![no_main] + +// Panic provider crate +use panic_persist; +use cortex_m; + +// Used to set the program entry point +use cortex_m_rt::entry; + +// Provides definitions for our development board +use nrf52840_hal::{ + prelude::*, + target::{Peripherals, CorePeripherals}, + Timer, + Rng, + Spim, + spim::{ + Pins as SpimPins, + Frequency as SpimFrequency, + MODE_0, + }, + gpio::{ + p0::Parts as P0Parts, + p1::Parts as P1Parts, + Level, + }, + Clocks, +}; + +use rtt_target::{ + rprint, rprintln, + rtt_init_print, +}; + +use embedded_graphics::{ + fonts::{Font8x16, Text}, + pixelcolor::Rgb565, + prelude::*, + style::{TextStyle, TextStyleBuilder}, +}; + +mod buffer; + +use ili9341::{Ili9341, Orientation}; + +const TEXT_SAMPLE: &[&str] = &[ + "for x in 0..10 {", + " for y in 0..10 {", + " let rand: u16 = rng.random_u16();", + " buffy.iter_mut().for_each(|px| {", + " *px = swap(rand)", + " });", + " lcd.draw_raw(", + " 32 * x,", + " 24 * y,", + " (32 * (x + 1)) - 1,", + " (24 * (y + 1)) - 1,", + " &buffy,", + " ).unwrap();", + " }", + "}", +]; + +const TEXT_SAMPLE2: &[&[(i32, Rgb565, &str)]] = &[ + // "for x in 0..10 {", + &[(0, Rgb565::RED, "for "), (4, Rgb565::WHITE, "x "), (6, Rgb565::RED, "in "), (9, Rgb565::MAGENTA, "0"), (10, Rgb565::RED, ".."), (12, Rgb565::MAGENTA, "10"), (14, Rgb565::WHITE, " {")], + // " for y in 0..10 {", + &[(2, Rgb565::RED, "for "), (6, Rgb565::WHITE, "y "), (8, Rgb565::RED, "in "), (11, Rgb565::MAGENTA, "0"), (12, Rgb565::RED, ".."), (14, Rgb565::MAGENTA, "10"), (16, Rgb565::WHITE, " {")], + // " let rand: u16 = rng.random_u16();", + &[(4, Rgb565::CYAN, "let "), (8, Rgb565::WHITE, "rand: "), (14, Rgb565::CYAN, "u16 "), (18, Rgb565::RED, "= "), (20, Rgb565::WHITE, "rng."), (24, Rgb565::CYAN, "random_u16"), (34, Rgb565::WHITE, "();")], + // " buffy.iter_mut().for_each(|px| {", + &[(4, Rgb565::WHITE, "buffy."), (10, Rgb565::CYAN, "iter_mut"), (18, Rgb565::WHITE, "()."), (21, Rgb565::CYAN, "for_each"), (29, Rgb565::WHITE, "(|"), (31, Rgb565::YELLOW, "px"), (33, Rgb565::WHITE, "| {")], + // " *px = swap(rand)", + &[(6, Rgb565::RED, "*"), (7, Rgb565::WHITE, "px "), (10, Rgb565::RED, "= "), (12, Rgb565::CYAN, "swap"), (16, Rgb565::WHITE, "(rand)")], + // " });", + &[(4, Rgb565::WHITE, "});")], + // " lcd.draw_raw(", + &[(4, Rgb565::WHITE, "lcd."), (8, Rgb565::CYAN, "draw_raw"), (16, Rgb565::WHITE, "(")], + // " 32 * x,", + &[(6, Rgb565::MAGENTA, "32 "), (9, Rgb565::RED, "* "), (11, Rgb565::WHITE, "x,")], + // " 24 * y,", + &[(6, Rgb565::MAGENTA, "24 "), (9, Rgb565::RED, "* "), (11, Rgb565::WHITE, "y,")], + // " (32 * (x + 1)) - 1,", + &[(6, Rgb565::WHITE, "("), (7, Rgb565::MAGENTA,"32 "), (10, Rgb565::RED, "* "), (12, Rgb565::WHITE, "(x "), (15, Rgb565::RED, "+ "), (17, Rgb565::MAGENTA, "1"), (18, Rgb565::WHITE, ")) "), (21, Rgb565::RED, "- "), (23, Rgb565::MAGENTA, "1"), (24, Rgb565::WHITE, ",")], + // " (24 * (y + 1)) - 1,", + &[(6, Rgb565::WHITE, "("), (7, Rgb565::MAGENTA,"24 "), (10, Rgb565::RED, "* "), (12, Rgb565::WHITE, "(y "), (15, Rgb565::RED, "+ "), (17, Rgb565::MAGENTA, "1"), (18, Rgb565::WHITE, ")) "), (21, Rgb565::RED, "- "), (23, Rgb565::MAGENTA, "1"), (24, Rgb565::WHITE, ",")], + // " &buffy,", + &[(6, Rgb565::RED, "&"), (7, Rgb565::WHITE, "buffy,")], + // " ).unwrap();", + &[(4, Rgb565::WHITE, ")."), (6, Rgb565::CYAN, "unwrap"), (12, Rgb565::WHITE, "();")], + // " }", + &[(2, Rgb565::WHITE, "}")], + // "}", + &[(0, Rgb565::WHITE, "}")], +]; + +#[entry] +fn main() -> ! { + match inner_main() { + Ok(()) => cortex_m::peripheral::SCB::sys_reset(), + Err(e) => panic!(e), + } +} + +fn inner_main() -> Result<(), &'static str> { + let mut board = Peripherals::take().ok_or("Error getting board!")?; + let mut corep = CorePeripherals::take().ok_or("Error")?; + let mut timer = Timer::new(board.TIMER0); + let mut delay = Timer::new(board.TIMER1); + let mut rng = Rng::new(board.RNG); + let mut toggle = false; + let _clocks = Clocks::new(board.CLOCK).enable_ext_hfosc(); + + // use ChannelMode::NoBlockS + rtt_init_print!(NoBlockSkip, 4096); + + if let Some(msg) = panic_persist::get_panic_message_utf8() { + rprintln!("{}", msg); + } else { + rprintln!("Clean boot!"); + } + + + let p0 = P0Parts::new(board.P0); + let p1 = P1Parts::new(board.P1); + + let kbd_lcd_reset = p1.p1_08; // GPIO5, D5 + let stm_cs = p0.p0_07; // GPIO6, D6, + let lcd_cs = p0.p0_26; // GPIO9, D9, + let lcd_dc = p0.p0_27; // GPIO10, D10 + + // Pull the neopixel line low so noise doesn't make it turn on spuriously + let keywing_neopixel = p0.p0_06.into_push_pull_output(Level::Low); // GPIO11, D11 + + let spim = Spim::new( + board.SPIM3, + SpimPins { + sck: p0.p0_14.into_push_pull_output(Level::Low).degrade(), + miso: Some(p0.p0_15.into_floating_input().degrade()), + mosi: Some(p0.p0_13.into_push_pull_output(Level::Low).degrade()), + }, + SpimFrequency::M32, + MODE_0, + 0x00, + ); + + let mut lcd = Ili9341::new_spi( + spim, + lcd_cs.into_push_pull_output(Level::High), + lcd_dc.into_push_pull_output(Level::High), + kbd_lcd_reset.into_push_pull_output(Level::High), + &mut delay, + ).unwrap(); + + lcd.set_orientation(Orientation::Landscape).unwrap(); + + let mut buffy = [0u16; 24 * 32]; + let mut buffy2 = [[0u16; 320]; 240]; + + let mut fbuffy = buffer::FrameBuffer::new(&mut buffy2); + + // // rrrrr gggggg bbbbb + // buffy.iter_mut().for_each(|px| *px = 0b11111_000000_00000); + + let style = TextStyleBuilder::new(Font8x16) + .text_color(Rgb565::WHITE) + .background_color(Rgb565::BLACK) + .build(); + + loop { + + rprintln!("Start colors raw"); + + for x in 0..10 { + for y in 0..10 { + let rand: u16 = rng.random_u16(); + buffy.iter_mut().for_each(|px| { + *px = swap(rand) + }); + + lcd.draw_raw( + 32 * x, + 24 * y, + (32 * (x + 1)) - 1, + (24 * (y + 1)) - 1, + &buffy, + ).unwrap(); + } + } + + rprintln!("Done.\n"); + + timer.delay_ms(1000u16); + + rprintln!("Start colors raw"); + + for x in 0..10 { + for y in 0..10 { + let rand: u16 = 0; + buffy.iter_mut().for_each(|px| { + *px = swap(rand) + }); + + lcd.draw_raw( + 32 * x, + 24 * y, + (32 * (x + 1)) - 1, + (24 * (y + 1)) - 1, + &buffy, + ).unwrap(); + } + } + + rprintln!("Done.\n"); + + + timer.delay_ms(1000u16); + + // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_00000)); + // rprintln!("Start black"); + // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); + // rprintln!("Done.\n"); + + rprintln!("text start"); + + for row in 0..15 { + Text::new( + TEXT_SAMPLE[row as usize], + Point::new(0, row * 16) + ).into_styled(style) + .draw(&mut lcd) + .unwrap(); + } + + rprintln!("text done"); + + timer.delay_ms(3000u16); + + rprintln!("Start colors raw"); + + for x in 0..10 { + for y in 0..10 { + let rand: u16 = 0; + buffy.iter_mut().for_each(|px| { + *px = swap(rand) + }); + + lcd.draw_raw( + 32 * x, + 24 * y, + (32 * (x + 1)) - 1, + (24 * (y + 1)) - 1, + &buffy, + ).unwrap(); + } + } + + rprintln!("Done.\n"); + + + timer.delay_ms(1000u16); + + // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_00000)); + // rprintln!("Start black"); + // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); + // rprintln!("Done.\n"); + + rprintln!("text2 start"); + + for (i, row) in TEXT_SAMPLE2.iter().enumerate() { + for (offset, color, text) in row.iter() { + let styled = TextStyleBuilder::new(Font8x16) + .text_color(*color) + .background_color(Rgb565::BLACK) + .build(); + + Text::new( + text, + Point::new(*offset * 8, i as i32 * 16) + ).into_styled(styled) + .draw(&mut lcd) + .unwrap(); + } + } + + rprintln!("text2 done"); + + timer.delay_ms(3000u16); + + rprintln!("Start colors raw"); + + for x in 0..10 { + for y in 0..10 { + let rand: u16 = 0; + buffy.iter_mut().for_each(|px| { + *px = swap(rand) + }); + + lcd.draw_raw( + 32 * x, + 24 * y, + (32 * (x + 1)) - 1, + (24 * (y + 1)) - 1, + &buffy, + ).unwrap(); + } + } + + rprintln!("Done.\n"); + + timer.delay_ms(1000u16); + + // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_00000)); + // rprintln!("Start black"); + // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); + // rprintln!("Done.\n"); + + timer.start(1_000_000u32); + + let start: u32 = timer.read(); + + for row in 0..15 { + Text::new( + TEXT_SAMPLE[row as usize], + Point::new(0, row * 16) + ).into_styled(style) + .draw(&mut fbuffy) + .unwrap(); + } + + let middle: u32 = timer.read(); + + lcd.draw_raw(0, 0, 319, 239, fbuffy.inner()).unwrap(); + + let end: u32 = timer.read(); + + rprintln!("text buffered done"); + rprintln!("start: 0x{:08X}, middle: 0x{:08X}, end: 0x{:08X}", start, middle, end); + rprintln!("render: {} cycs", middle - start); + rprintln!("draw: {} cycs", end - middle); + + + + + + timer.delay_ms(3000u16); + + rprintln!("Start colors raw"); + + for x in 0..10 { + for y in 0..10 { + let rand: u16 = 0; + buffy.iter_mut().for_each(|px| { + *px = swap(rand) + }); + + lcd.draw_raw( + 32 * x, + 24 * y, + (32 * (x + 1)) - 1, + (24 * (y + 1)) - 1, + &buffy, + ).unwrap(); + } + } + + rprintln!("Done.\n"); + + + timer.delay_ms(1000u16); + + rprintln!("text2 buffered middle"); + + for (i, row) in TEXT_SAMPLE2.iter().enumerate() { + for (offset, color, text) in row.iter() { + let styled = TextStyleBuilder::new(Font8x16) + .text_color(*color) + .background_color(Rgb565::BLACK) + .build(); + + Text::new( + text, + Point::new(*offset * 8, i as i32 * 16) + ).into_styled(styled) + .draw(&mut fbuffy) + .unwrap(); + } + } + + rprintln!("text2 buffered middle"); + + lcd.draw_raw(0, 0, 319, 239, fbuffy.inner()).unwrap(); + + rprintln!("text2 buffered done"); + + timer.delay_ms(3000u16); + + continue; + + + // // SHOULD BE + // // rrrrr gggggg bbbbb + // buffy2.iter_mut().for_each(|px| *px = swap(0b11111_000000_00000)); + // rprintln!("Start red"); + // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); + // rprintln!("Done.\n"); + + // timer.delay_ms(250u16); + + // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_111111_00000)); + // rprintln!("Start green"); + // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); + // rprintln!("Done.\n"); + + // timer.delay_ms(250u16); + + // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_11111)); + // rprintln!("Start blue"); + // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); + // rprintln!("Done.\n"); + + // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_00000)); + // rprintln!("Start black"); + // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); + // rprintln!("Done.\n"); + + // 240 / 16: 15 + // 320 / 8: 40 + + let text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + + let mut textiter = text.chars().cycle(); + + for row in 0..15 { + for col in 0..40 { + let mut buf = [0u8; 4]; + let txt = textiter.next().unwrap().encode_utf8(&mut buf); + Text::new( + txt, + Point::new(col * 8, row * 16) + ).into_styled(style) + .draw(&mut lcd) + .unwrap(); + } + timer.delay_ms(500u16); + } + + timer.delay_ms(1000u16); + + + // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_00000)); + // rprintln!("Start black"); + // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); + // rprintln!("Done.\n"); + + rprintln!("Starting Text Fill..."); + + let mut text = Text::new( + "1234567890123456789012345678901234567890", + Point::new(0, 0) + ).into_styled(style); + + for _y in 0..15 { + text.draw(&mut lcd).unwrap(); + text = text.translate(Point::new(0, 16)); + } + + rprintln!("Finished Text Fill."); + + + timer.delay_ms(1000u16); + + + } + + Ok(()) +} + +const fn swap(inp: u16) -> u16 { + (inp & 0x00FF) << 8 | + (inp & 0xFF00) >> 8 +} diff --git a/nrf-hal b/nrf-hal new file mode 160000 index 0000000..f98fe76 --- /dev/null +++ b/nrf-hal @@ -0,0 +1 @@ +Subproject commit f98fe76b4b0d43a8a542c0002ce6b2568d9f4070 -- 2.42.0 From f0c087b3c6464eab7d19a3a7b8c8835aff3cc6c1 Mon Sep 17 00:00:00 2001 From: James Munns Date: Tue, 26 May 2020 23:22:58 +0200 Subject: [PATCH 2/8] Add a readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea9aa38 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Keyboard Featherwing in Rust + +This is a playground for working with @arturo182's Keyboard Featherwing in Rust. + +For now, I am using the adafruit nrf52840 express as the main MCU. + -- 2.42.0 From fdaa0cd104dcde008b93d7dadb830508084c45c3 Mon Sep 17 00:00:00 2001 From: James Munns Date: Wed, 27 May 2020 01:15:17 +0200 Subject: [PATCH 3/8] Working little text editor --- .gitmodules | 3 + bbq10kbd | 1 + keywing/Cargo.lock | 8 + keywing/Cargo.toml | 4 + keywing/src/buffer.rs | 31 ++- keywing/src/main.rs | 597 ++++++++++++++++++++---------------------- 6 files changed, 316 insertions(+), 328 deletions(-) create mode 160000 bbq10kbd diff --git a/.gitmodules b/.gitmodules index ef75d6c..8971b25 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "nrf-hal"] path = nrf-hal url = git@github.com:jamesmunns/nrf-hal.git +[submodule "bbq10kbd"] + path = bbq10kbd + url = https://github.com/jamesmunns/bbq10kbd diff --git a/bbq10kbd b/bbq10kbd new file mode 160000 index 0000000..5900ad8 --- /dev/null +++ b/bbq10kbd @@ -0,0 +1 @@ +Subproject commit 5900ad89a6221e93702278a5fadc8dd2b65f0479 diff --git a/keywing/Cargo.lock b/keywing/Cargo.lock index 7b27e81..56bb412 100644 --- a/keywing/Cargo.lock +++ b/keywing/Cargo.lock @@ -25,6 +25,13 @@ dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "bbq10kbd" +version = "0.1.0" +dependencies = [ + "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "byteorder" version = "1.3.2" @@ -285,6 +292,7 @@ dependencies = [ name = "tiny-nrf52" version = "0.1.0" dependencies = [ + "bbq10kbd 0.1.0", "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-graphics 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/keywing/Cargo.toml b/keywing/Cargo.toml index 85b93b8..e1f5723 100644 --- a/keywing/Cargo.toml +++ b/keywing/Cargo.toml @@ -17,6 +17,10 @@ embedded-graphics = "0.6.2" version = "0.3.0" path = "../ili9341-rs" +[dependencies.bbq10kbd] +version = "0.1.0" +path = "../bbq10kbd" + [dependencies.nrf52840-hal] version = "0.10.0" features = ["rt"] diff --git a/keywing/src/buffer.rs b/keywing/src/buffer.rs index da912ad..f334eb4 100644 --- a/keywing/src/buffer.rs +++ b/keywing/src/buffer.rs @@ -12,32 +12,38 @@ use embedded_graphics::{ pub struct FrameBuffer<'a> { buf: &'a mut [[u16; 320]; 240], + dirty: bool, } impl<'a> FrameBuffer<'a> { pub fn new(raw: &'a mut [[u16; 320]; 240]) -> Self { - Self { - buf: raw - } + Self { buf: raw, dirty: false } } - pub fn inner(&self) -> &[u16] { - unsafe { - core::slice::from_raw_parts(self.buf.as_ptr().cast::(), (self.width() * self.height()) as usize) + pub fn inner(&mut self) -> Option<&[u16]> { + if self.dirty { + self.dirty = false; + Some(unsafe { + core::slice::from_raw_parts( + self.buf.as_ptr().cast::(), + (self.width() * self.height()) as usize, + ) + }) + } else { + None } } fn width(&self) -> u32 { - self.buf.len() as u32 + self.buf[0].len() as u32 } fn height(&self) -> u32 { - self.buf[0].len() as u32 + self.buf.len() as u32 } } -impl<'a> DrawTarget for FrameBuffer<'a> -{ +impl<'a> DrawTarget for FrameBuffer<'a> { type Error = (); fn size(&self) -> Size { @@ -50,13 +56,12 @@ impl<'a> DrawTarget for FrameBuffer<'a> if pos.x < 0 || pos.y < 0 || pos.x >= self.width() as i32 || pos.y >= self.height() as i32 { return Ok(()); } - + self.dirty = true; self.buf[pos.y as usize][pos.x as usize] = swap(RawU16::from(color).into_inner()); Ok(()) } } const fn swap(inp: u16) -> u16 { - (inp & 0x00FF) << 8 | - (inp & 0xFF00) >> 8 + (inp & 0x00FF) << 8 | (inp & 0xFF00) >> 8 } diff --git a/keywing/src/main.rs b/keywing/src/main.rs index fd71350..15df83b 100644 --- a/keywing/src/main.rs +++ b/keywing/src/main.rs @@ -2,36 +2,23 @@ #![no_main] // Panic provider crate -use panic_persist; use cortex_m; +use panic_persist; // Used to set the program entry point use cortex_m_rt::entry; // Provides definitions for our development board use nrf52840_hal::{ + gpio::{p0::Parts as P0Parts, p1::Parts as P1Parts, Level}, prelude::*, - target::{Peripherals, CorePeripherals}, - Timer, - Rng, - Spim, - spim::{ - Pins as SpimPins, - Frequency as SpimFrequency, - MODE_0, - }, - gpio::{ - p0::Parts as P0Parts, - p1::Parts as P1Parts, - Level, - }, - Clocks, + spim::{Frequency as SpimFrequency, Pins as SpimPins, MODE_0}, + target::{CorePeripherals, Peripherals}, + twim::{Frequency as TwimFrequency, Pins as TwimPins}, + Clocks, Rng, Spim, Timer, Twim, }; -use rtt_target::{ - rprint, rprintln, - rtt_init_print, -}; +use rtt_target::{rprint, rprintln, rtt_init_print}; use embedded_graphics::{ fonts::{Font8x16, Text}, @@ -40,6 +27,8 @@ use embedded_graphics::{ style::{TextStyle, TextStyleBuilder}, }; +use bbq10kbd::{Bbq10Kbd, KeyRaw}; + mod buffer; use ili9341::{Ili9341, Orientation}; @@ -64,31 +53,107 @@ const TEXT_SAMPLE: &[&str] = &[ const TEXT_SAMPLE2: &[&[(i32, Rgb565, &str)]] = &[ // "for x in 0..10 {", - &[(0, Rgb565::RED, "for "), (4, Rgb565::WHITE, "x "), (6, Rgb565::RED, "in "), (9, Rgb565::MAGENTA, "0"), (10, Rgb565::RED, ".."), (12, Rgb565::MAGENTA, "10"), (14, Rgb565::WHITE, " {")], + &[ + (0, Rgb565::RED, "for "), + (4, Rgb565::WHITE, "x "), + (6, Rgb565::RED, "in "), + (9, Rgb565::MAGENTA, "0"), + (10, Rgb565::RED, ".."), + (12, Rgb565::MAGENTA, "10"), + (14, Rgb565::WHITE, " {"), + ], // " for y in 0..10 {", - &[(2, Rgb565::RED, "for "), (6, Rgb565::WHITE, "y "), (8, Rgb565::RED, "in "), (11, Rgb565::MAGENTA, "0"), (12, Rgb565::RED, ".."), (14, Rgb565::MAGENTA, "10"), (16, Rgb565::WHITE, " {")], + &[ + (2, Rgb565::RED, "for "), + (6, Rgb565::WHITE, "y "), + (8, Rgb565::RED, "in "), + (11, Rgb565::MAGENTA, "0"), + (12, Rgb565::RED, ".."), + (14, Rgb565::MAGENTA, "10"), + (16, Rgb565::WHITE, " {"), + ], // " let rand: u16 = rng.random_u16();", - &[(4, Rgb565::CYAN, "let "), (8, Rgb565::WHITE, "rand: "), (14, Rgb565::CYAN, "u16 "), (18, Rgb565::RED, "= "), (20, Rgb565::WHITE, "rng."), (24, Rgb565::CYAN, "random_u16"), (34, Rgb565::WHITE, "();")], + &[ + (4, Rgb565::CYAN, "let "), + (8, Rgb565::WHITE, "rand: "), + (14, Rgb565::CYAN, "u16 "), + (18, Rgb565::RED, "= "), + (20, Rgb565::WHITE, "rng."), + (24, Rgb565::CYAN, "random_u16"), + (34, Rgb565::WHITE, "();"), + ], // " buffy.iter_mut().for_each(|px| {", - &[(4, Rgb565::WHITE, "buffy."), (10, Rgb565::CYAN, "iter_mut"), (18, Rgb565::WHITE, "()."), (21, Rgb565::CYAN, "for_each"), (29, Rgb565::WHITE, "(|"), (31, Rgb565::YELLOW, "px"), (33, Rgb565::WHITE, "| {")], + &[ + (4, Rgb565::WHITE, "buffy."), + (10, Rgb565::CYAN, "iter_mut"), + (18, Rgb565::WHITE, "()."), + (21, Rgb565::CYAN, "for_each"), + (29, Rgb565::WHITE, "(|"), + (31, Rgb565::YELLOW, "px"), + (33, Rgb565::WHITE, "| {"), + ], // " *px = swap(rand)", - &[(6, Rgb565::RED, "*"), (7, Rgb565::WHITE, "px "), (10, Rgb565::RED, "= "), (12, Rgb565::CYAN, "swap"), (16, Rgb565::WHITE, "(rand)")], + &[ + (6, Rgb565::RED, "*"), + (7, Rgb565::WHITE, "px "), + (10, Rgb565::RED, "= "), + (12, Rgb565::CYAN, "swap"), + (16, Rgb565::WHITE, "(rand)"), + ], // " });", &[(4, Rgb565::WHITE, "});")], // " lcd.draw_raw(", - &[(4, Rgb565::WHITE, "lcd."), (8, Rgb565::CYAN, "draw_raw"), (16, Rgb565::WHITE, "(")], + &[ + (4, Rgb565::WHITE, "lcd."), + (8, Rgb565::CYAN, "draw_raw"), + (16, Rgb565::WHITE, "("), + ], // " 32 * x,", - &[(6, Rgb565::MAGENTA, "32 "), (9, Rgb565::RED, "* "), (11, Rgb565::WHITE, "x,")], + &[ + (6, Rgb565::MAGENTA, "32 "), + (9, Rgb565::RED, "* "), + (11, Rgb565::WHITE, "x,"), + ], // " 24 * y,", - &[(6, Rgb565::MAGENTA, "24 "), (9, Rgb565::RED, "* "), (11, Rgb565::WHITE, "y,")], + &[ + (6, Rgb565::MAGENTA, "24 "), + (9, Rgb565::RED, "* "), + (11, Rgb565::WHITE, "y,"), + ], // " (32 * (x + 1)) - 1,", - &[(6, Rgb565::WHITE, "("), (7, Rgb565::MAGENTA,"32 "), (10, Rgb565::RED, "* "), (12, Rgb565::WHITE, "(x "), (15, Rgb565::RED, "+ "), (17, Rgb565::MAGENTA, "1"), (18, Rgb565::WHITE, ")) "), (21, Rgb565::RED, "- "), (23, Rgb565::MAGENTA, "1"), (24, Rgb565::WHITE, ",")], + &[ + (6, Rgb565::WHITE, "("), + (7, Rgb565::MAGENTA, "32 "), + (10, Rgb565::RED, "* "), + (12, Rgb565::WHITE, "(x "), + (15, Rgb565::RED, "+ "), + (17, Rgb565::MAGENTA, "1"), + (18, Rgb565::WHITE, ")) "), + (21, Rgb565::RED, "- "), + (23, Rgb565::MAGENTA, "1"), + (24, Rgb565::WHITE, ","), + ], // " (24 * (y + 1)) - 1,", - &[(6, Rgb565::WHITE, "("), (7, Rgb565::MAGENTA,"24 "), (10, Rgb565::RED, "* "), (12, Rgb565::WHITE, "(y "), (15, Rgb565::RED, "+ "), (17, Rgb565::MAGENTA, "1"), (18, Rgb565::WHITE, ")) "), (21, Rgb565::RED, "- "), (23, Rgb565::MAGENTA, "1"), (24, Rgb565::WHITE, ",")], + &[ + (6, Rgb565::WHITE, "("), + (7, Rgb565::MAGENTA, "24 "), + (10, Rgb565::RED, "* "), + (12, Rgb565::WHITE, "(y "), + (15, Rgb565::RED, "+ "), + (17, Rgb565::MAGENTA, "1"), + (18, Rgb565::WHITE, ")) "), + (21, Rgb565::RED, "- "), + (23, Rgb565::MAGENTA, "1"), + (24, Rgb565::WHITE, ","), + ], // " &buffy,", &[(6, Rgb565::RED, "&"), (7, Rgb565::WHITE, "buffy,")], // " ).unwrap();", - &[(4, Rgb565::WHITE, ")."), (6, Rgb565::CYAN, "unwrap"), (12, Rgb565::WHITE, "();")], + &[ + (4, Rgb565::WHITE, ")."), + (6, Rgb565::CYAN, "unwrap"), + (12, Rgb565::WHITE, "();"), + ], // " }", &[(2, Rgb565::WHITE, "}")], // "}", @@ -121,7 +186,6 @@ fn inner_main() -> Result<(), &'static str> { rprintln!("Clean boot!"); } - let p0 = P0Parts::new(board.P0); let p1 = P1Parts::new(board.P1); @@ -130,8 +194,23 @@ fn inner_main() -> Result<(), &'static str> { let lcd_cs = p0.p0_26; // GPIO9, D9, let lcd_dc = p0.p0_27; // GPIO10, D10 - // Pull the neopixel line low so noise doesn't make it turn on spuriously + let kbd_sda = p0.p0_12.into_floating_input().degrade(); + let kbd_scl = p0.p0_11.into_floating_input().degrade(); + + let kbd_i2c = Twim::new( + board.TWIM0, + TwimPins { + sda: kbd_sda, + scl: kbd_scl, + }, + TwimFrequency::K100, + ); + + let mut kbd = Bbq10Kbd::new(kbd_i2c); + + // Pull the neopixel lines low so noise doesn't make it turn on spuriously let keywing_neopixel = p0.p0_06.into_push_pull_output(Level::Low); // GPIO11, D11 + let feather_neopixel = p0.p0_16.into_push_pull_output(Level::Low); let spim = Spim::new( board.SPIM3, @@ -151,11 +230,12 @@ fn inner_main() -> Result<(), &'static str> { lcd_dc.into_push_pull_output(Level::High), kbd_lcd_reset.into_push_pull_output(Level::High), &mut delay, - ).unwrap(); + ) + .unwrap(); lcd.set_orientation(Orientation::Landscape).unwrap(); - let mut buffy = [0u16; 24 * 32]; + let mut _buffy = [0u16; 24 * 32]; let mut buffy2 = [[0u16; 320]; 240]; let mut fbuffy = buffer::FrameBuffer::new(&mut buffy2); @@ -163,321 +243,208 @@ fn inner_main() -> Result<(), &'static str> { // // rrrrr gggggg bbbbb // buffy.iter_mut().for_each(|px| *px = 0b11111_000000_00000); - let style = TextStyleBuilder::new(Font8x16) + let mut style = TextStyleBuilder::new(Font8x16) .text_color(Rgb565::WHITE) .background_color(Rgb565::BLACK) .build(); - loop { + let mut ctr: u8 = 0; + kbd.set_backlight(ctr).unwrap(); - rprintln!("Start colors raw"); - - for x in 0..10 { - for y in 0..10 { - let rand: u16 = rng.random_u16(); - buffy.iter_mut().for_each(|px| { - *px = swap(rand) - }); - - lcd.draw_raw( - 32 * x, - 24 * y, - (32 * (x + 1)) - 1, - (24 * (y + 1)) - 1, - &buffy, - ).unwrap(); - } - } + let vers = kbd.get_version().unwrap(); - rprintln!("Done.\n"); + rprintln!("Vers: {:?}", vers); - timer.delay_ms(1000u16); + kbd.sw_reset().unwrap(); + timer.delay_ms(10u8); - rprintln!("Start colors raw"); + let vers = kbd.get_version().unwrap(); - for x in 0..10 { - for y in 0..10 { - let rand: u16 = 0; - buffy.iter_mut().for_each(|px| { - *px = swap(rand) - }); + rprintln!("Vers: {:?}", vers); - lcd.draw_raw( - 32 * x, - 24 * y, - (32 * (x + 1)) - 1, - (24 * (y + 1)) - 1, - &buffy, - ).unwrap(); - } - } - - rprintln!("Done.\n"); - - - timer.delay_ms(1000u16); - - // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_00000)); - // rprintln!("Start black"); - // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); - // rprintln!("Done.\n"); - - rprintln!("text start"); - - for row in 0..15 { - Text::new( - TEXT_SAMPLE[row as usize], - Point::new(0, row * 16) - ).into_styled(style) - .draw(&mut lcd) - .unwrap(); - } - - rprintln!("text done"); - - timer.delay_ms(3000u16); - - rprintln!("Start colors raw"); + let mut cursor_y = 0; + let mut cursor_x = 0; - for x in 0..10 { - for y in 0..10 { - let rand: u16 = 0; - buffy.iter_mut().for_each(|px| { - *px = swap(rand) - }); - - lcd.draw_raw( - 32 * x, - 24 * y, - (32 * (x + 1)) - 1, - (24 * (y + 1)) - 1, - &buffy, - ).unwrap(); - } - } + let mut cursor = Cursor { x: 0, y: 0 }; - rprintln!("Done.\n"); + lcd.clear(Rgb565::BLACK).map_err(|_| "Fade to error")?; + fbuffy.clear(Rgb565::BLACK).map_err(|_| "Fade to error")?; + loop { + let key = kbd.get_fifo_key_raw().map_err(|_| "bad fifo")?; - timer.delay_ms(1000u16); - - // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_00000)); - // rprintln!("Start black"); - // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); - // rprintln!("Done.\n"); - - rprintln!("text2 start"); - - for (i, row) in TEXT_SAMPLE2.iter().enumerate() { - for (offset, color, text) in row.iter() { - let styled = TextStyleBuilder::new(Font8x16) - .text_color(*color) + match key { + // LL + KeyRaw::Pressed(6) => { + style = TextStyleBuilder::new(Font8x16) + .text_color(Rgb565::WHITE) .background_color(Rgb565::BLACK) .build(); - - Text::new( - text, - Point::new(*offset * 8, i as i32 * 16) - ).into_styled(styled) - .draw(&mut lcd) - .unwrap(); } - } - - rprintln!("text2 done"); - - timer.delay_ms(3000u16); - - rprintln!("Start colors raw"); - - for x in 0..10 { - for y in 0..10 { - let rand: u16 = 0; - buffy.iter_mut().for_each(|px| { - *px = swap(rand) - }); - - lcd.draw_raw( - 32 * x, - 24 * y, - (32 * (x + 1)) - 1, - (24 * (y + 1)) - 1, - &buffy, - ).unwrap(); + // LR + KeyRaw::Pressed(17) => { + style = TextStyleBuilder::new(Font8x16) + .text_color(Rgb565::RED) + .background_color(Rgb565::BLACK) + .build(); } - } - - rprintln!("Done.\n"); - - timer.delay_ms(1000u16); - - // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_00000)); - // rprintln!("Start black"); - // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); - // rprintln!("Done.\n"); - - timer.start(1_000_000u32); - - let start: u32 = timer.read(); - - for row in 0..15 { - Text::new( - TEXT_SAMPLE[row as usize], - Point::new(0, row * 16) - ).into_styled(style) - .draw(&mut fbuffy) - .unwrap(); - } - - let middle: u32 = timer.read(); - - lcd.draw_raw(0, 0, 319, 239, fbuffy.inner()).unwrap(); - - let end: u32 = timer.read(); - - rprintln!("text buffered done"); - rprintln!("start: 0x{:08X}, middle: 0x{:08X}, end: 0x{:08X}", start, middle, end); - rprintln!("render: {} cycs", middle - start); - rprintln!("draw: {} cycs", end - middle); - - - - - - timer.delay_ms(3000u16); - - rprintln!("Start colors raw"); - - for x in 0..10 { - for y in 0..10 { - let rand: u16 = 0; - buffy.iter_mut().for_each(|px| { - *px = swap(rand) - }); - - lcd.draw_raw( - 32 * x, - 24 * y, - (32 * (x + 1)) - 1, - (24 * (y + 1)) - 1, - &buffy, - ).unwrap(); + // RL + KeyRaw::Pressed(7) => { + style = TextStyleBuilder::new(Font8x16) + .text_color(Rgb565::GREEN) + .background_color(Rgb565::BLACK) + .build(); } - } - - rprintln!("Done.\n"); - - - timer.delay_ms(1000u16); - - rprintln!("text2 buffered middle"); - - for (i, row) in TEXT_SAMPLE2.iter().enumerate() { - for (offset, color, text) in row.iter() { - let styled = TextStyleBuilder::new(Font8x16) - .text_color(*color) + // RR + KeyRaw::Pressed(18) => { + style = TextStyleBuilder::new(Font8x16) + .text_color(Rgb565::BLUE) .background_color(Rgb565::BLACK) .build(); + } + // Up + KeyRaw::Pressed(1) => { + cursor.up(); + } + // Down + KeyRaw::Pressed(2) => { + cursor.down(); + } + // Left + KeyRaw::Pressed(3) => { + cursor.left(); + } + // Right + KeyRaw::Pressed(4) => { + cursor.right(); + } + // Center + KeyRaw::Pressed(5) => { + kbd.sw_reset().unwrap(); + cursor = Cursor { x: 0, y: 0 }; + fbuffy.clear(Rgb565::BLACK).map_err(|_| "Fade to error")?; + } + // Backspace + KeyRaw::Pressed(8) => { + cursor.left(); + Text::new(" ", cursor.pos()) + .into_styled(style) + .draw(&mut fbuffy) + .map_err(|_| "bad lcd")?; + } + // Enter + KeyRaw::Pressed(10) => { + cursor.enter(); + } + KeyRaw::Pressed(k) => { + rprintln!("Got key {}", k); + if let Ok(s) = core::str::from_utf8(&[k]) { + Text::new(s, cursor.pos()) + .into_styled(style) + .draw(&mut fbuffy) + .map_err(|_| "bad lcd")?; + + cursor.right(); + } + } + KeyRaw::Invalid => { + if let Some(buf) = fbuffy.inner() { + timer.start(1_000_000u32); + lcd.draw_raw( + 0, 0, + 319, 239, + buf + ).map_err(|_| "bad buffy")?; + let done = timer.read(); + rprintln!("Drew in {}ms.", done / 1000); + } else { + timer.delay_ms(38u8); + } - Text::new( - text, - Point::new(*offset * 8, i as i32 * 16) - ).into_styled(styled) - .draw(&mut fbuffy) - .unwrap(); } + _ => {} } + } - rprintln!("text2 buffered middle"); - - lcd.draw_raw(0, 0, 319, 239, fbuffy.inner()).unwrap(); - - rprintln!("text2 buffered done"); - - timer.delay_ms(3000u16); - - continue; - - - // // SHOULD BE - // // rrrrr gggggg bbbbb - // buffy2.iter_mut().for_each(|px| *px = swap(0b11111_000000_00000)); - // rprintln!("Start red"); - // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); - // rprintln!("Done.\n"); - - // timer.delay_ms(250u16); - - // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_111111_00000)); - // rprintln!("Start green"); - // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); - // rprintln!("Done.\n"); - - // timer.delay_ms(250u16); - - // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_11111)); - // rprintln!("Start blue"); - // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); - // rprintln!("Done.\n"); - - // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_00000)); - // rprintln!("Start black"); - // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); - // rprintln!("Done.\n"); + Ok(()) +} - // 240 / 16: 15 - // 320 / 8: 40 +struct Cursor { + x: i32, + y: i32, +} - let text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; +impl Cursor { + fn up(&mut self) { + self.y -= 1; + if self.y < 0 { + self.y = 0; + } + } - let mut textiter = text.chars().cycle(); + fn down(&mut self) { + self.y += 1; + if self.y >= 15 { + self.y = 14; + } + } - for row in 0..15 { - for col in 0..40 { - let mut buf = [0u8; 4]; - let txt = textiter.next().unwrap().encode_utf8(&mut buf); - Text::new( - txt, - Point::new(col * 8, row * 16) - ).into_styled(style) - .draw(&mut lcd) - .unwrap(); + fn left(&mut self) { + self.x -= 1; + if self.x < 0 { + if self.y != 0 { + self.x = 39; + self.up(); + } else { + self.x = 0; } - timer.delay_ms(500u16); } + } - timer.delay_ms(1000u16); - - - // buffy2.iter_mut().for_each(|px| *px = swap(0b00000_000000_00000)); - // rprintln!("Start black"); - // lcd.draw_raw(0, 0, 319, 239, &buffy2).unwrap(); - // rprintln!("Done.\n"); - - rprintln!("Starting Text Fill..."); - - let mut text = Text::new( - "1234567890123456789012345678901234567890", - Point::new(0, 0) - ).into_styled(style); - - for _y in 0..15 { - text.draw(&mut lcd).unwrap(); - text = text.translate(Point::new(0, 16)); + fn right(&mut self) { + self.x += 1; + if self.x >= 40 { + self.x = 0; + self.down(); } + } - rprintln!("Finished Text Fill."); - - - timer.delay_ms(1000u16); - - + fn enter(&mut self) { + if self.y != 14 { + self.x = 0; + self.down(); + } } - Ok(()) + fn pos(&self) -> Point { + Point::new(self.x * 8, self.y * 16) + } } -const fn swap(inp: u16) -> u16 { - (inp & 0x00FF) << 8 | - (inp & 0xFF00) >> 8 -} +// let key_raw = kbd.get_fifo_key_raw().unwrap(); + +// match key_raw { +// KeyRaw::Invalid => { +// timer.delay_ms(1000u16); +// let state = kbd.get_key_status().unwrap(); +// rprintln!("Key Status: {:?}", state); +// } +// key @ _ => { +// ctr = ctr.wrapping_add(5); +// rprintln!("Key: {:?} - {}", key, ctr); +// kbd.set_backlight(ctr).unwrap(); +// assert_eq!(kbd.get_backlight().unwrap(), ctr); +// } +// } + +// Special keys +// LL: 6 +// LR: 17 +// RL: 7 +// RR: 18 +// +// D-L: 3 +// D-U: 1 +// D-R: 4 +// D-D: 2 +// D-C: 5 -- 2.42.0 From 563efa0d02de05a2f3a35ea2a9d689df4c8cd55b Mon Sep 17 00:00:00 2001 From: James Munns Date: Wed, 27 May 2020 02:03:27 +0200 Subject: [PATCH 4/8] Remove dead code --- keywing/src/buffer.rs | 9 +- keywing/src/main.rs | 191 +++--------------------------------------- 2 files changed, 16 insertions(+), 184 deletions(-) diff --git a/keywing/src/buffer.rs b/keywing/src/buffer.rs index f334eb4..6898b68 100644 --- a/keywing/src/buffer.rs +++ b/keywing/src/buffer.rs @@ -1,12 +1,10 @@ use embedded_graphics::{ drawable::Pixel, - geometry::{Point, Size}, + geometry::Size, pixelcolor::{ raw::{RawData, RawU16}, Rgb565, }, - primitives::Rectangle, - style::{PrimitiveStyle, Styled}, DrawTarget, }; @@ -17,7 +15,10 @@ pub struct FrameBuffer<'a> { impl<'a> FrameBuffer<'a> { pub fn new(raw: &'a mut [[u16; 320]; 240]) -> Self { - Self { buf: raw, dirty: false } + Self { + buf: raw, + dirty: false, + } } pub fn inner(&mut self) -> Option<&[u16]> { diff --git a/keywing/src/main.rs b/keywing/src/main.rs index 15df83b..2397fa8 100644 --- a/keywing/src/main.rs +++ b/keywing/src/main.rs @@ -2,8 +2,7 @@ #![no_main] // Panic provider crate -use cortex_m; -use panic_persist; +use panic_persist as _; // Used to set the program entry point use cortex_m_rt::entry; @@ -13,18 +12,18 @@ use nrf52840_hal::{ gpio::{p0::Parts as P0Parts, p1::Parts as P1Parts, Level}, prelude::*, spim::{Frequency as SpimFrequency, Pins as SpimPins, MODE_0}, - target::{CorePeripherals, Peripherals}, + target::Peripherals, twim::{Frequency as TwimFrequency, Pins as TwimPins}, Clocks, Rng, Spim, Timer, Twim, }; -use rtt_target::{rprint, rprintln, rtt_init_print}; +use rtt_target::{rprintln, rtt_init_print}; use embedded_graphics::{ fonts::{Font8x16, Text}, pixelcolor::Rgb565, prelude::*, - style::{TextStyle, TextStyleBuilder}, + style::TextStyleBuilder, }; use bbq10kbd::{Bbq10Kbd, KeyRaw}; @@ -33,133 +32,6 @@ mod buffer; use ili9341::{Ili9341, Orientation}; -const TEXT_SAMPLE: &[&str] = &[ - "for x in 0..10 {", - " for y in 0..10 {", - " let rand: u16 = rng.random_u16();", - " buffy.iter_mut().for_each(|px| {", - " *px = swap(rand)", - " });", - " lcd.draw_raw(", - " 32 * x,", - " 24 * y,", - " (32 * (x + 1)) - 1,", - " (24 * (y + 1)) - 1,", - " &buffy,", - " ).unwrap();", - " }", - "}", -]; - -const TEXT_SAMPLE2: &[&[(i32, Rgb565, &str)]] = &[ - // "for x in 0..10 {", - &[ - (0, Rgb565::RED, "for "), - (4, Rgb565::WHITE, "x "), - (6, Rgb565::RED, "in "), - (9, Rgb565::MAGENTA, "0"), - (10, Rgb565::RED, ".."), - (12, Rgb565::MAGENTA, "10"), - (14, Rgb565::WHITE, " {"), - ], - // " for y in 0..10 {", - &[ - (2, Rgb565::RED, "for "), - (6, Rgb565::WHITE, "y "), - (8, Rgb565::RED, "in "), - (11, Rgb565::MAGENTA, "0"), - (12, Rgb565::RED, ".."), - (14, Rgb565::MAGENTA, "10"), - (16, Rgb565::WHITE, " {"), - ], - // " let rand: u16 = rng.random_u16();", - &[ - (4, Rgb565::CYAN, "let "), - (8, Rgb565::WHITE, "rand: "), - (14, Rgb565::CYAN, "u16 "), - (18, Rgb565::RED, "= "), - (20, Rgb565::WHITE, "rng."), - (24, Rgb565::CYAN, "random_u16"), - (34, Rgb565::WHITE, "();"), - ], - // " buffy.iter_mut().for_each(|px| {", - &[ - (4, Rgb565::WHITE, "buffy."), - (10, Rgb565::CYAN, "iter_mut"), - (18, Rgb565::WHITE, "()."), - (21, Rgb565::CYAN, "for_each"), - (29, Rgb565::WHITE, "(|"), - (31, Rgb565::YELLOW, "px"), - (33, Rgb565::WHITE, "| {"), - ], - // " *px = swap(rand)", - &[ - (6, Rgb565::RED, "*"), - (7, Rgb565::WHITE, "px "), - (10, Rgb565::RED, "= "), - (12, Rgb565::CYAN, "swap"), - (16, Rgb565::WHITE, "(rand)"), - ], - // " });", - &[(4, Rgb565::WHITE, "});")], - // " lcd.draw_raw(", - &[ - (4, Rgb565::WHITE, "lcd."), - (8, Rgb565::CYAN, "draw_raw"), - (16, Rgb565::WHITE, "("), - ], - // " 32 * x,", - &[ - (6, Rgb565::MAGENTA, "32 "), - (9, Rgb565::RED, "* "), - (11, Rgb565::WHITE, "x,"), - ], - // " 24 * y,", - &[ - (6, Rgb565::MAGENTA, "24 "), - (9, Rgb565::RED, "* "), - (11, Rgb565::WHITE, "y,"), - ], - // " (32 * (x + 1)) - 1,", - &[ - (6, Rgb565::WHITE, "("), - (7, Rgb565::MAGENTA, "32 "), - (10, Rgb565::RED, "* "), - (12, Rgb565::WHITE, "(x "), - (15, Rgb565::RED, "+ "), - (17, Rgb565::MAGENTA, "1"), - (18, Rgb565::WHITE, ")) "), - (21, Rgb565::RED, "- "), - (23, Rgb565::MAGENTA, "1"), - (24, Rgb565::WHITE, ","), - ], - // " (24 * (y + 1)) - 1,", - &[ - (6, Rgb565::WHITE, "("), - (7, Rgb565::MAGENTA, "24 "), - (10, Rgb565::RED, "* "), - (12, Rgb565::WHITE, "(y "), - (15, Rgb565::RED, "+ "), - (17, Rgb565::MAGENTA, "1"), - (18, Rgb565::WHITE, ")) "), - (21, Rgb565::RED, "- "), - (23, Rgb565::MAGENTA, "1"), - (24, Rgb565::WHITE, ","), - ], - // " &buffy,", - &[(6, Rgb565::RED, "&"), (7, Rgb565::WHITE, "buffy,")], - // " ).unwrap();", - &[ - (4, Rgb565::WHITE, ")."), - (6, Rgb565::CYAN, "unwrap"), - (12, Rgb565::WHITE, "();"), - ], - // " }", - &[(2, Rgb565::WHITE, "}")], - // "}", - &[(0, Rgb565::WHITE, "}")], -]; - #[entry] fn main() -> ! { match inner_main() { @@ -169,12 +41,10 @@ fn main() -> ! { } fn inner_main() -> Result<(), &'static str> { - let mut board = Peripherals::take().ok_or("Error getting board!")?; - let mut corep = CorePeripherals::take().ok_or("Error")?; + let board = Peripherals::take().ok_or("Error getting board!")?; let mut timer = Timer::new(board.TIMER0); let mut delay = Timer::new(board.TIMER1); - let mut rng = Rng::new(board.RNG); - let mut toggle = false; + let mut _rng = Rng::new(board.RNG); let _clocks = Clocks::new(board.CLOCK).enable_ext_hfosc(); // use ChannelMode::NoBlockS @@ -190,7 +60,7 @@ fn inner_main() -> Result<(), &'static str> { let p1 = P1Parts::new(board.P1); let kbd_lcd_reset = p1.p1_08; // GPIO5, D5 - let stm_cs = p0.p0_07; // GPIO6, D6, + let _stm_cs = p0.p0_07; // GPIO6, D6, let lcd_cs = p0.p0_26; // GPIO9, D9, let lcd_dc = p0.p0_27; // GPIO10, D10 @@ -209,8 +79,8 @@ fn inner_main() -> Result<(), &'static str> { let mut kbd = Bbq10Kbd::new(kbd_i2c); // Pull the neopixel lines low so noise doesn't make it turn on spuriously - let keywing_neopixel = p0.p0_06.into_push_pull_output(Level::Low); // GPIO11, D11 - let feather_neopixel = p0.p0_16.into_push_pull_output(Level::Low); + let _keywing_neopixel = p0.p0_06.into_push_pull_output(Level::Low); // GPIO11, D11 + let _feather_neopixel = p0.p0_16.into_push_pull_output(Level::Low); let spim = Spim::new( board.SPIM3, @@ -248,8 +118,7 @@ fn inner_main() -> Result<(), &'static str> { .background_color(Rgb565::BLACK) .build(); - let mut ctr: u8 = 0; - kbd.set_backlight(ctr).unwrap(); + kbd.set_backlight(255).unwrap(); let vers = kbd.get_version().unwrap(); @@ -262,9 +131,6 @@ fn inner_main() -> Result<(), &'static str> { rprintln!("Vers: {:?}", vers); - let mut cursor_y = 0; - let mut cursor_x = 0; - let mut cursor = Cursor { x: 0, y: 0 }; lcd.clear(Rgb565::BLACK).map_err(|_| "Fade to error")?; @@ -350,23 +216,16 @@ fn inner_main() -> Result<(), &'static str> { KeyRaw::Invalid => { if let Some(buf) = fbuffy.inner() { timer.start(1_000_000u32); - lcd.draw_raw( - 0, 0, - 319, 239, - buf - ).map_err(|_| "bad buffy")?; + lcd.draw_raw(0, 0, 319, 239, buf).map_err(|_| "bad buffy")?; let done = timer.read(); rprintln!("Drew in {}ms.", done / 1000); } else { timer.delay_ms(38u8); } - } _ => {} } } - - Ok(()) } struct Cursor { @@ -420,31 +279,3 @@ impl Cursor { Point::new(self.x * 8, self.y * 16) } } - -// let key_raw = kbd.get_fifo_key_raw().unwrap(); - -// match key_raw { -// KeyRaw::Invalid => { -// timer.delay_ms(1000u16); -// let state = kbd.get_key_status().unwrap(); -// rprintln!("Key Status: {:?}", state); -// } -// key @ _ => { -// ctr = ctr.wrapping_add(5); -// rprintln!("Key: {:?} - {}", key, ctr); -// kbd.set_backlight(ctr).unwrap(); -// assert_eq!(kbd.get_backlight().unwrap(), ctr); -// } -// } - -// Special keys -// LL: 6 -// LR: 17 -// RL: 7 -// RR: 18 -// -// D-L: 3 -// D-U: 1 -// D-R: 4 -// D-D: 2 -// D-C: 5 -- 2.42.0 From ae7e9009c24193d06daa77bdfcde9caeb37053e4 Mon Sep 17 00:00:00 2001 From: Patrick O'Doherty Date: Fri, 4 Sep 2020 16:13:51 -0700 Subject: [PATCH 5/8] Add nix & direnv rust environment configuration --- .envrc | 1 + shell.nix | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .envrc create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..051d09d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +eval "$(lorri direnv)" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..19b7c15 --- /dev/null +++ b/shell.nix @@ -0,0 +1,38 @@ +let + rust-version = "1.46.0"; + + nixpkgs = fetchGit { + url = "https://github.com/patrickod/nixpkgs.git"; + rev = "8bb6ca5f0a93bb0b9264b50a8c56431c7c7cc591"; + ref = "personal"; + }; + + mozilla-overlay = + import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz); + + pkgs = import nixpkgs { + overlays = [ mozilla-overlay ]; + }; + + targets = [ + "x86_64-unknown-linux-gnu" + "thumbv7em-none-eabihf" + ]; + +in + pkgs.mkShell { + name = "rust-dev"; + nativeBuildInputs = with pkgs; [ + (rustChannels.stable.rust.override { + targets = targets; + extensions = [ + "rust-src" + "rust-analysis" + "rls-preview" + ]; + }) + gcc-arm-embedded + cargo-hf2 + rustup + ]; + } -- 2.42.0 From 2c5a6ce701efb11787525a42b6ced9957e32e6ca Mon Sep 17 00:00:00 2001 From: Patrick O'Doherty Date: Sun, 20 Sep 2020 10:51:31 -0700 Subject: [PATCH 6/8] Initial port to Feather M4 Changes: * Update the SPI and i2c bus initialization to use the handy feather_m4 hal helper methods. * Hack out some timer code in the invalid key handler due to differences in timer/delay API to return to later. * update memory.x referencing the atsamd feather_m4 board definition & reserving 1KB for panic dumping --- .gitmodules | 3 - keywing/.cargo/config | 10 +- keywing/Cargo.lock | 265 +++++++++++++++++++++--------------------- keywing/Cargo.toml | 23 ++-- keywing/Embed.toml | 46 -------- keywing/memory.x | 13 ++- keywing/src/main.rs | 116 +++++++++--------- nrf-hal | 1 - shell.nix | 5 +- 9 files changed, 213 insertions(+), 269 deletions(-) delete mode 100644 keywing/Embed.toml delete mode 160000 nrf-hal diff --git a/.gitmodules b/.gitmodules index 8971b25..415292f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "ili9341-rs"] path = ili9341-rs url = git@github.com:jamesmunns/ili9341-rs.git -[submodule "nrf-hal"] - path = nrf-hal - url = git@github.com:jamesmunns/nrf-hal.git [submodule "bbq10kbd"] path = bbq10kbd url = https://github.com/jamesmunns/bbq10kbd diff --git a/keywing/.cargo/config b/keywing/.cargo/config index 5673fa9..fd7ff15 100644 --- a/keywing/.cargo/config +++ b/keywing/.cargo/config @@ -1,9 +1,9 @@ +# vim:ft=toml: +[target.thumbv7em-none-eabihf] +runner = 'arm-none-eabi-gdb' + [build] target = "thumbv7em-none-eabihf" - -[target.thumbv7em-none-eabihf] -# runner = 'gdbgui -g arm-none-eabi-gdb --gdb-args="-command=debug.gdb"' -runner = "arm-none-eabi-gdb -tui -q -x debug.gdb" rustflags = [ - "-C", "link-arg=-Tlink.x", + "-C", "link-arg=-Tlink.x", ] diff --git a/keywing/Cargo.lock b/keywing/Cargo.lock index 56bb412..7761169 100644 --- a/keywing/Cargo.lock +++ b/keywing/Cargo.lock @@ -2,19 +2,47 @@ # It is not intended for manual editing. [[package]] name = "aligned" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "as-slice" -version = "0.1.0" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", - "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "stable_deref_trait 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "atsamd-hal" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atsamd51j19a 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitfield 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "nb 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "paste 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "vcell 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 = "atsamd51j19a" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m-rt 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -29,50 +57,47 @@ dependencies = [ name = "bbq10kbd" version = "0.1.0" dependencies = [ - "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "byteorder" -version = "1.3.2" +name = "bitfield" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "cast" -version = "0.2.3" +name = "byteorder" +version = "1.3.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 = "cortex-m" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "aligned 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "aligned 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "bitfield 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cortex-m-rt" -version = "0.6.10" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cortex-m-rt-macros 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m-rt-macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cortex-m-rt-macros" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -80,25 +105,28 @@ name = "embedded-graphics" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "embedded-hal" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "nb 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "fpa" -version = "0.1.0" +name = "feather_m4" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "atsamd-hal 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m-rt 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "nb 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -106,7 +134,7 @@ name = "generic-array" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -114,7 +142,7 @@ name = "generic-array" version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -122,17 +150,18 @@ name = "hash32" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "heapless" -version = "0.5.1" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "hash32 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "stable_deref_trait 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -140,101 +169,88 @@ name = "ili9341" version = "0.3.0" dependencies = [ "embedded-graphics 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "nb" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "nrf-hal-common" -version = "0.10.0" +name = "keywing" +version = "0.1.0" dependencies = [ - "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fpa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "nrf52840-pac 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bbq10kbd 0.1.0", + "cortex-m 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m-rt 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-graphics 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "feather_m4 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "heapless 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "ili9341 0.3.0", + "nb 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "panic-persist 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rtt-target 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "nrf52840-hal" -version = "0.10.0" +name = "nb" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "nrf-hal-common 0.10.0", - "nrf52840-pac 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "nb 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "nrf52840-pac" -version = "0.9.0" +name = "nb" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "panic-persist" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "proc-macro2" -version = "1.0.6" +name = "paste" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "paste-impl 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "quote" -version = "1.0.2" +name = "paste-impl" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "r0" -version = "0.2.2" +name = "proc-macro-hack" +version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "rand" -version = "0.5.6" +name = "proc-macro2" +version = "1.0.21" 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)", + "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "rand_core" -version = "0.3.1" +name = "quote" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "rand_core" -version = "0.4.2" +name = "r0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -244,12 +260,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rtt-target" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "ufmt-write 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -275,39 +290,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "stable_deref_trait" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "1.0.8" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tiny-nrf52" -version = "0.1.0" -dependencies = [ - "bbq10kbd 0.1.0", - "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-graphics 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "heapless 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ili9341 0.3.0", - "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "nrf52840-hal 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "panic-persist 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rtt-target 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "typenum" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -317,7 +315,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -339,41 +337,42 @@ dependencies = [ ] [metadata] -"checksum aligned 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a316c7ea8e1e9ece54862c992def5a7ac14de9f5832b69d71760680efeeefa" -"checksum as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "293dac66b274fab06f95e7efb05ec439a6b70136081ea522d270bc351ae5bb27" +"checksum aligned 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c19796bd8d477f1a9d4ac2465b464a8b1359474f06a96bb3cda650b4fca309bf" +"checksum as-slice 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "37dfb65bc03b2bc85ee827004f14a6817e04160e3b1a28931986a666a9290e70" +"checksum atsamd-hal 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a845093b449700f878b8a91323e10307577e28f29f37c859645eaba2e655a60f" +"checksum atsamd51j19a 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f3710f797630bb6fd7ab101e057e9a9f43342e86727867b03c76dfd42c20a05b" "checksum bare-metal 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" -"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" -"checksum cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" -"checksum cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2954942fbbdd49996704e6f048ce57567c3e1a4e2dc59b41ae9fde06a01fc763" -"checksum cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "17805910e3ecf029bdbfcc42b7384d9e3d9e5626153fa810002c1ef9839338ac" -"checksum cortex-m-rt-macros 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2a6dc359ebb215c4924bffacfe46a8f02ef80fe2071bba1635a2ded42b40f936" +"checksum bitfield 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" +"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +"checksum cortex-m 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2be99930c99669a74d986f7fd2162085498b322e6daae8ef63a97cc9ac1dc73c" +"checksum cortex-m-rt 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "980c9d0233a909f355ed297ef122f257942de5e0a2cb1c39f60684b65bcb90fb" +"checksum cortex-m-rt-macros 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4717562afbba06e760d34451919f5c3bf3ac15c7bb897e8b04862a7428378647" "checksum embedded-graphics 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "40a69991ceb896bd4810a0cf2bcc46fc94b7860573c71f965d8e5b3d66942fed" -"checksum embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee4908a155094da7723c2d60d617b820061e3b4efcc3d9e293d206a5a76c170b" -"checksum fpa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f074479d683e5a8fd0bf1251d0a5d91b0d9178b867b44962191ed0eaaf8d4009" +"checksum embedded-hal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "fa998ce59ec9765d15216393af37a58961ddcefb14c753b4816ba2191d865fcb" +"checksum feather_m4 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96671f623dfdb988a95695a70ac1d02cfbbc6e6552a3c5fdf2791e8855100e2c" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum generic-array 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd" "checksum hash32 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d4041af86e63ac4298ce40e5cca669066e75b6f1aa3390fe2561ffa5e1d9f4cc" -"checksum heapless 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f339aa7d51777fc0af6aa7cbeb277dfc6e6c029cbdeda48d0fbb92c2337f0e69" -"checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc" -"checksum nrf52840-hal 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6aab4c41abc02fcefbdbedfa773d213302bc00c57a0b2237c6b5bf0456da10d3" -"checksum nrf52840-pac 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1b780a5afd2621774652f28c82837f6aa6d19cf0ad71c734fc1fe53298a2d73" +"checksum heapless 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "73a8a2391a3bc70b31f60e7a90daa5755a360559c0b6b9c5cfc0fee482362dc0" +"checksum nb 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +"checksum nb 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" "checksum panic-persist 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dd2e692a5954e3eb0c16f5dbaa75c4332a78d85851521f138c04ad95d6f5ee42" -"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +"checksum paste 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" +"checksum paste-impl 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" +"checksum proc-macro-hack 0.5.18 (registry+https://github.com/rust-lang/crates.io-index)" = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" +"checksum proc-macro2 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c" +"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" "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.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" "checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -"checksum rtt-target 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "58b1f36984bbcf227044b3b7af1de14a6ebe51b9d21cd856a3d5ba41c70ec191" +"checksum rtt-target 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0869b4c5b6a6d8c5583fc473f9eb3423a170f77626b8c8a7fb18eddcda5770e2" "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 stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" -"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92" -"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +"checksum stable_deref_trait 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +"checksum syn 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b" +"checksum typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" "checksum ufmt-write 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +"checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" "checksum vcell 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "876e32dcadfe563a4289e994f7cb391197f362b6315dc45e8ba4aa6f564a4b3c" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286" diff --git a/keywing/Cargo.toml b/keywing/Cargo.toml index e1f5723..b5fdcac 100644 --- a/keywing/Cargo.toml +++ b/keywing/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "tiny-nrf52" +name = "keywing" version = "0.1.0" -authors = ["James Munns "] +authors = ["Patrick O'Doherty "] edition = "2018" [dependencies] @@ -21,15 +21,14 @@ path = "../ili9341-rs" version = "0.1.0" path = "../bbq10kbd" -[dependencies.nrf52840-hal] -version = "0.10.0" -features = ["rt"] - [dependencies.panic-persist] version = "0.2.1" default-features = false features = ["utf8"] +[dependencies.feather_m4] +version = "0.5.0" + [profile.dev] lto = true panic = "abort" @@ -39,12 +38,6 @@ codegen-units = 1 opt-level = 0 [profile.release] -lto = true -panic = "abort" -debug = true -incremental = false -codegen-units = 1 -opt-level = 's' - -[patch.crates-io] -nrf-hal-common = { path = "../nrf-hal/nrf-hal-common" } +debug = true +lto = true +opt-level = "s" \ No newline at end of file diff --git a/keywing/Embed.toml b/keywing/Embed.toml deleted file mode 100644 index 918f48c..0000000 --- a/keywing/Embed.toml +++ /dev/null @@ -1,46 +0,0 @@ -[probe] -# The index of the probe in the connected probe list. -probe_index = 0 -# The protocol to be used for communicating with the target. -protocol = "Swd" -# The speed in kHz of the data link to the target. -# speed = 1337 - -[flashing] -# Whether or not the target should be flashed. -enabled = true -# Whether or not the target should be halted after flashing. -halt_afterwards = false -# Whether or not bytes erased but not rewritten with data from the ELF -# should be restored with their contents before erasing. -restore_unwritten_bytes = false -# The path where an SVG of the assembled flash layout should be written to. -# flash_layout_output_path = "out.svg" - -[general] -# The chip name of the chip to be debugged. -chip = "nRF52840_xxAA" -# A list of chip descriptions to be loaded during runtime. -chip_descriptions = [] -# The default log level to be used. -log_level = "Warn" - -[rtt] -# Whether or not an RTTUI should be opened after flashing. -# This is exclusive and cannot be used with GDB at the moment. -enabled = true -# A list of channel associations to be displayed. If left empty, all channels are displayed. -channels = [ - # { up = 0, down = 0, name = "name" } -] -# The duration in ms for which the logger should retry to attach to RTT. -timeout = 3000 -# Whether timestamps in the RTTUI are enabled -show_timestamps = true - -[gdb] -# Whether or not a GDB server should be opened after flashing. -# This is exclusive and cannot be used with RTT at the moment. -enabled = false -# The connection string in host:port format wher the GDB server will open a socket. -# gdb_connection_string diff --git a/keywing/memory.x b/keywing/memory.x index 46f1278..bbbe065 100644 --- a/keywing/memory.x +++ b/keywing/memory.x @@ -1,10 +1,13 @@ MEMORY { - /* NOTE K = KiBi = 1024 bytes */ - FLASH : ORIGIN = 0x00000000, LENGTH = 1M - RAM : ORIGIN = 0x20000000, LENGTH = 255K - PANDUMP: ORIGIN = 0x2003FC00, LENGTH = 1K + /* Leave 16k for the default bootloader on the Feather M4 */ + FLASH (rx) : ORIGIN = 0x00000000 + 16K, LENGTH = 512K - 16K + /* Usually 192K RAM. Reserve 1K at the end for storing panic dumps */ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 191K + PANDUMP (rw) : ORIGIN = 0x20000000 + 191K, LENGTH = 1K } +_stack_start = ORIGIN(RAM) + LENGTH(RAM); _panic_dump_start = ORIGIN(PANDUMP); -_panic_dump_end = ORIGIN(PANDUMP) + LENGTH(PANDUMP); +_panic_dump_end = ORIGIN(PANDUMP) + LENGTH(PANDUMP); + diff --git a/keywing/src/main.rs b/keywing/src/main.rs index 2397fa8..28841c1 100644 --- a/keywing/src/main.rs +++ b/keywing/src/main.rs @@ -7,15 +7,16 @@ use panic_persist as _; // Used to set the program entry point use cortex_m_rt::entry; -// Provides definitions for our development board -use nrf52840_hal::{ - gpio::{p0::Parts as P0Parts, p1::Parts as P1Parts, Level}, - prelude::*, - spim::{Frequency as SpimFrequency, Pins as SpimPins, MODE_0}, - target::Peripherals, - twim::{Frequency as TwimFrequency, Pins as TwimPins}, - Clocks, Rng, Spim, Timer, Twim, -}; +extern crate feather_m4 as hal; + +use hal::prelude::*; +use hal::clock::GenericClockController; +use hal::pac::{CorePeripherals,Peripherals}; +use hal::trng::Trng; +use hal::delay::Delay; +use hal::Pins; +use hal::{i2c_master,spi_master}; +use hal::time::U32Ext; use rtt_target::{rprintln, rtt_init_print}; @@ -41,11 +42,19 @@ fn main() -> ! { } fn inner_main() -> Result<(), &'static str> { - let board = Peripherals::take().ok_or("Error getting board!")?; - let mut timer = Timer::new(board.TIMER0); - let mut delay = Timer::new(board.TIMER1); - let mut _rng = Rng::new(board.RNG); - let _clocks = Clocks::new(board.CLOCK).enable_ext_hfosc(); + let mut peripherals = Peripherals::take().ok_or("Error getting board!")?; + let mut _pins = Pins::new(peripherals.PORT); + let _core = CorePeripherals::take().unwrap(); + + let mut _rng: Trng = Trng::new(&mut peripherals.MCLK, peripherals.TRNG); + let mut _clocks = GenericClockController::with_external_32kosc( + peripherals.GCLK, + &mut peripherals.MCLK, + &mut peripherals.OSC32KCTRL, + &mut peripherals.OSCCTRL, + &mut peripherals.NVMCTRL, + ); + let mut delay = Delay::new(_core.SYST, &mut _clocks); // use ChannelMode::NoBlockS rtt_init_print!(NoBlockSkip, 4096); @@ -56,52 +65,45 @@ fn inner_main() -> Result<(), &'static str> { rprintln!("Clean boot!"); } - let p0 = P0Parts::new(board.P0); - let p1 = P1Parts::new(board.P1); - - let kbd_lcd_reset = p1.p1_08; // GPIO5, D5 - let _stm_cs = p0.p0_07; // GPIO6, D6, - let lcd_cs = p0.p0_26; // GPIO9, D9, - let lcd_dc = p0.p0_27; // GPIO10, D10 - - let kbd_sda = p0.p0_12.into_floating_input().degrade(); - let kbd_scl = p0.p0_11.into_floating_input().degrade(); - - let kbd_i2c = Twim::new( - board.TWIM0, - TwimPins { - sda: kbd_sda, - scl: kbd_scl, - }, - TwimFrequency::K100, + let kbd_lcd_reset = _pins.d5; + let _stm_cs = _pins.d6; + let lcd_cs = _pins.d9; + let lcd_dc = _pins.d10; + + // i2c keyboard interface + // kbd SDA = D12 + // kbd SCL = D11 + // FREQ 100KHZ + let kbd_i2c = i2c_master( + &mut _clocks, + 100u32.khz(), + peripherals.SERCOM2, + &mut peripherals.MCLK, + _pins.sda, + _pins.scl, + &mut _pins.port ); let mut kbd = Bbq10Kbd::new(kbd_i2c); - // Pull the neopixel lines low so noise doesn't make it turn on spuriously - let _keywing_neopixel = p0.p0_06.into_push_pull_output(Level::Low); // GPIO11, D11 - let _feather_neopixel = p0.p0_16.into_push_pull_output(Level::Low); - - let spim = Spim::new( - board.SPIM3, - SpimPins { - sck: p0.p0_14.into_push_pull_output(Level::Low).degrade(), - miso: Some(p0.p0_15.into_floating_input().degrade()), - mosi: Some(p0.p0_13.into_push_pull_output(Level::Low).degrade()), - }, - SpimFrequency::M32, - MODE_0, - 0x00, + let lcd_spi = spi_master( + &mut _clocks, + 32u32.mhz(), + peripherals.SERCOM1, + &mut peripherals.MCLK, + _pins.sck, + _pins.mosi, + _pins.miso, + &mut _pins.port ); let mut lcd = Ili9341::new_spi( - spim, - lcd_cs.into_push_pull_output(Level::High), - lcd_dc.into_push_pull_output(Level::High), - kbd_lcd_reset.into_push_pull_output(Level::High), + lcd_spi, + lcd_cs.into_push_pull_output(&mut _pins.port), + lcd_dc.into_push_pull_output(&mut _pins.port), + kbd_lcd_reset.into_push_pull_output(&mut _pins.port), &mut delay, - ) - .unwrap(); + ).unwrap(); lcd.set_orientation(Orientation::Landscape).unwrap(); @@ -125,7 +127,7 @@ fn inner_main() -> Result<(), &'static str> { rprintln!("Vers: {:?}", vers); kbd.sw_reset().unwrap(); - timer.delay_ms(10u8); + delay.delay_ms(10u8); let vers = kbd.get_version().unwrap(); @@ -215,12 +217,12 @@ fn inner_main() -> Result<(), &'static str> { } KeyRaw::Invalid => { if let Some(buf) = fbuffy.inner() { - timer.start(1_000_000u32); + // timer.start(1_000_000u32); lcd.draw_raw(0, 0, 319, 239, buf).map_err(|_| "bad buffy")?; - let done = timer.read(); - rprintln!("Drew in {}ms.", done / 1000); + // let done = timer.read(); + // rprintln!("Drew in {}ms.", done / 1000); } else { - timer.delay_ms(38u8); + delay.delay_ms(38u8); } } _ => {} diff --git a/nrf-hal b/nrf-hal deleted file mode 160000 index f98fe76..0000000 --- a/nrf-hal +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f98fe76b4b0d43a8a542c0002ce6b2568d9f4070 diff --git a/shell.nix b/shell.nix index 19b7c15..1c5dc56 100644 --- a/shell.nix +++ b/shell.nix @@ -1,6 +1,4 @@ let - rust-version = "1.46.0"; - nixpkgs = fetchGit { url = "https://github.com/patrickod/nixpkgs.git"; rev = "8bb6ca5f0a93bb0b9264b50a8c56431c7c7cc591"; @@ -21,8 +19,7 @@ let in pkgs.mkShell { - name = "rust-dev"; - nativeBuildInputs = with pkgs; [ + buildInputs = with pkgs; [ (rustChannels.stable.rust.override { targets = targets; extensions = [ -- 2.42.0 From c4653c0bb99d718ffc296f20ba5c9e5dca0b284a Mon Sep 17 00:00:00 2001 From: Patrick O'Doherty Date: Sun, 20 Sep 2020 16:19:07 -0700 Subject: [PATCH 7/8] Updated README with links to original source & boards --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index ea9aa38..20ccdad 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Keyboard Featherwing in Rust -This is a playground for working with @arturo182's Keyboard Featherwing in Rust. +This is a playground for working with @arturo182's Keyboard Featherwing in Rust using the [Adafruit Feather M4 Express](https://www.adafruit.com/product/3857). It is ported from [@jamesmunns's original work](https://github.com/jamesmunns/keywing-rs) targeting the [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062). -For now, I am using the adafruit nrf52840 express as the main MCU. -- 2.42.0 From 7b363ff299aa4caf985392e76033df6a36606410 Mon Sep 17 00:00:00 2001 From: Patrick O'Doherty Date: Sat, 10 Jul 2021 15:08:35 -0700 Subject: [PATCH 8/8] 2021 nix flake updates & some minor cleanup --- .envrc | 2 +- .gitignore | 1 + flake.lock | 88 +++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 39 ++++++++++++++++++++ keywing/src/main.rs | 10 +++--- 5 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc index 051d09d..3550a30 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -eval "$(lorri direnv)" +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92b2793 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a28f98d --- /dev/null +++ b/flake.lock @@ -0,0 +1,88 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1623875721, + "narHash": "sha256-A8BU7bjS5GirpAUv4QA+QnJ4CceLHkcXdRp4xITDB0s=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f7e004a55b120c02ecb6219596820fcd32ca8772", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1614513358, + "narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5466c5bbece17adaab2d82fae80b46e807611bf3", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "narHash": "sha256-CM4XxuzS4VaTH3WYwUUmPBUSc2BNVLhv8JEahERWUWY=", + "path": "/home/patrickod/code/nixpkgs", + "type": "path" + }, + "original": { + "path": "/home/patrickod/code/nixpkgs", + "type": "path" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1617325113, + "narHash": "sha256-GksR0nvGxfZ79T91UUtWjjccxazv6Yh/MvEJ82v1Xmw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "54c1e44240d8a527a8f4892608c4bce5440c3ecb", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1625796896, + "narHash": "sha256-yAFp4hslYKZcZwAXSiKnFezSFY/kdoh4l5qqioTtHFM=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "76732f3ddba766b1fe772fca80aafbc9cccd78dd", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..20b8f1a --- /dev/null +++ b/flake.nix @@ -0,0 +1,39 @@ +{ + description = "rust ARM M-0 development"; + inputs = { + nixpkgs.url = "path:/home/patrickod/code/nixpkgs"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + rust = pkgs.rust-bin.nightly.latest.default.override { + extensions = [ + "clippy-preview" + "rust-src" + "rustfmt-preview" + ]; + targets = [ + "thumbv7em-none-eabihf" + ]; + }; + in + { + devShell = pkgs.mkShell { + buildInputs = [ + pkgs.gcc-arm-embedded + pkgs.probe-run + pkgs.flip-link + pkgs.cargo-hf2 + rust + ]; + }; + } + ); +} diff --git a/keywing/src/main.rs b/keywing/src/main.rs index 28841c1..aaa1d48 100644 --- a/keywing/src/main.rs +++ b/keywing/src/main.rs @@ -56,6 +56,12 @@ fn inner_main() -> Result<(), &'static str> { ); let mut delay = Delay::new(_core.SYST, &mut _clocks); + // set pins low to prevent floating values read as data by the pixels + let mut front_neopixel_pin = _pins.d11.into_push_pull_output(&mut _pins.port); + let mut rear_neopixel_pin = _pins.neopixel.into_push_pull_output(&mut _pins.port); + front_neopixel_pin.set_low().unwrap(); + rear_neopixel_pin.set_high().unwrap(); + // use ChannelMode::NoBlockS rtt_init_print!(NoBlockSkip, 4096); @@ -107,14 +113,10 @@ fn inner_main() -> Result<(), &'static str> { lcd.set_orientation(Orientation::Landscape).unwrap(); - let mut _buffy = [0u16; 24 * 32]; let mut buffy2 = [[0u16; 320]; 240]; let mut fbuffy = buffer::FrameBuffer::new(&mut buffy2); - // // rrrrr gggggg bbbbb - // buffy.iter_mut().for_each(|px| *px = 0b11111_000000_00000); - let mut style = TextStyleBuilder::new(Font8x16) .text_color(Rgb565::WHITE) .background_color(Rgb565::BLACK) -- 2.42.0