From 21620b65c1247355a983f93337b48f5ef3378301 Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 10 May 2023 22:34:39 +0200 Subject: [PATCH] Add OLED implementation --- .cargo/config | 42 +++ .gitignore | 1 + Cargo.lock | 728 ++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 25 ++ LICENSE.md | 483 +++++++++++++++++++++++++++++++++ README.md | 5 + memory.x | 15 ++ src/main.rs | 130 +++++++++ 8 files changed, 1429 insertions(+) create mode 100644 .cargo/config create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 memory.x create mode 100644 src/main.rs diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..ed10a10 --- /dev/null +++ b/.cargo/config @@ -0,0 +1,42 @@ +# +# Cargo Configuration for the https://github.com/rp-rs/rp-hal.git repository. +# +# Copyright (c) The RP-RS Developers, 2021 +# +# You might want to make a similar file in your own repository if you are +# writing programs for Raspberry Silicon microcontrollers. +# +# This file is MIT or Apache-2.0 as per the repository README.md file +# + +[build] +# Set the default target to match the Cortex-M0+ in the RP2040 +target = "thumbv6m-none-eabi" + +# Target specific options +[target.thumbv6m-none-eabi] +# Pass some extra options to rustc, some of which get passed on to the linker. +# +# * linker argument --nmagic turns off page alignment of sections (which saves +# flash space) +# * linker argument -Tlink.x tells the linker to use link.x as the linker +# script. This is usually provided by the cortex-m-rt crate, and by default +# the version in that crate will include a file called `memory.x` which +# describes the particular memory layout for your specific chip. +# * inline-threshold=5 makes the compiler more aggressive and inlining functions +# * no-vectorize-loops turns off the loop vectorizer (seeing as the M0+ doesn't +# have SIMD) +rustflags = [ + "-C", "link-arg=--nmagic", + "-C", "link-arg=-Tlink.x", + "-C", "inline-threshold=5", + "-C", "no-vectorize-loops", +] + +# This runner will make a UF2 file and then copy it to a mounted RP2040 in USB +# Bootloader mode: +runner = "elf2uf2-rs -d" + +# This runner will find a supported SWD debug probe and flash your RP2040 over +# SWD: +# runner = "probe-run --chip RP2040" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..332fde7 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,728 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "atmo-sense" +version = "0.1.0" +dependencies = [ + "cortex-m", + "cortex-m-rt", + "cortex-m-rtic", + "embedded-graphics", + "embedded-hal", + "embedded-time", + "fugit", + "nb 1.0.0", + "numtoa", + "panic-halt", + "rp2040-boot2", + "rp2040-hal", + "rtic-monotonic", + "sparkfun-pro-micro-rp2040", + "ssd1306", + "systick-monotonic", +] + +[[package]] +name = "atomic-polyfill" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ff7eb3f316534d83a8a2c3d1674ace8a5a71198eba31e2e2b597833f699b28" +dependencies = [ + "critical-section", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "az" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" + +[[package]] +name = "bare-metal" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" +dependencies = [ + "rustc_version 0.2.3", +] + +[[package]] +name = "bare-metal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" + +[[package]] +name = "bitfield" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" + +[[package]] +name = "byte-slice-cast" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0a5e3906bcbf133e33c1d4d95afc664ad37fbdb9f6568d8043e7ea8c27d93d3" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cortex-m" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9" +dependencies = [ + "bare-metal 0.2.5", + "bitfield", + "embedded-hal", + "volatile-register", +] + +[[package]] +name = "cortex-m-rt" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6d3328b8b5534f0c90acd66b68950f2763b37e0173cac4d8b4937c4a80761f9" +dependencies = [ + "cortex-m-rt-macros", +] + +[[package]] +name = "cortex-m-rt-macros" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f6f3e36f203cfedbc78b357fb28730aa2c6dc1ab060ee5c2405e843988d3c7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "cortex-m-rtic" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6b82f1c39acd6c3a35c2013b6110c20f5bc534522791fabadeed49ccada2dce" +dependencies = [ + "bare-metal 1.0.0", + "cortex-m", + "cortex-m-rtic-macros", + "heapless", + "rtic-core", + "rtic-monotonic", + "version_check", +] + +[[package]] +name = "cortex-m-rtic-macros" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e8e9645ef54bec1cf70ac33e9bf9566e6507ab5b41ae6baf3735662194e8607" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "rtic-syntax", + "syn", +] + +[[package]] +name = "crc-any" +version = "2.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "774646b687f63643eb0f4bf13dc263cb581c8c9e57973b6ddf78bda3994d88df" +dependencies = [ + "debug-helper", +] + +[[package]] +name = "critical-section" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6548a0ad5d2549e111e1f6a11a6c2e2d00ce6a3dafe22948d67c2b443f775e52" + +[[package]] +name = "debug-helper" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f578e8e2c440e7297e008bb5486a3a8a194775224bbc23729b0dbdfaeebf162e" + +[[package]] +name = "display-interface" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7517c040926d7b02b111884aa089177db80878533127f7c1b480d852c5fb4112" + +[[package]] +name = "display-interface-i2c" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4895cd4e54e5536ef370d7f1eec787aad8275dd8ad15815aebfa71dd847b4ebf" +dependencies = [ + "display-interface", + "embedded-hal", +] + +[[package]] +name = "display-interface-spi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "489378ad054862146fbd1f09f51d585ccbe4bd1e2feadcda2a13ac33f840e1a5" +dependencies = [ + "byte-slice-cast", + "display-interface", + "embedded-hal", +] + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "embedded-graphics" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "750082c65094fbcc4baf9ba31583ce9a8bb7f52cadfb96f6164b1bc7f922f32b" +dependencies = [ + "az", + "byteorder", + "embedded-graphics-core", + "float-cmp", + "micromath", +] + +[[package]] +name = "embedded-graphics-core" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8b1239db5f3eeb7e33e35bd10bd014e7b2537b17e071f726a09351431337cfa" +dependencies = [ + "az", + "byteorder", +] + +[[package]] +name = "embedded-hal" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff" +dependencies = [ + "nb 0.1.3", + "void", +] + +[[package]] +name = "embedded-time" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a4b4d10ac48d08bfe3db7688c402baadb244721f30a77ce360bd24c3dffe58" +dependencies = [ + "num", +] + +[[package]] +name = "float-cmp" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4" +dependencies = [ + "num-traits", +] + +[[package]] +name = "fugit" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ab17bb279def6720d058cb6c052249938e7f99260ab534879281a95367a87e5" +dependencies = [ + "gcd", +] + +[[package]] +name = "gcd" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a" + +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heapless" +version = "0.7.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version 0.4.0", + "spin", + "stable_deref_trait", +] + +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "micromath" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc4010833aea396656c2f91ee704d51a6f1329ec2ab56ffd00bfd56f7481ea94" + +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.0.0", +] + +[[package]] +name = "nb" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" + +[[package]] +name = "num" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b7a8e9be5e039e2ff869df49155f1c06bd01ade2117ec783e56ab0932b67a8f" +dependencies = [ + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747d632c0c558b87dbabbe6a82f3b4ae03720d0646ac5b7b4dae89394be5f2c5" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_enum" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d829733185c1ca374f17e52b762f24f535ec625d2cc1f070e34c8a9068f341b" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2be1598bf1c313dcdd12092e3f1920f463462525a21b7b4e11b4168353d0123e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "numtoa" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f" + +[[package]] +name = "panic-halt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812" + +[[package]] +name = "paste" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" + +[[package]] +name = "pio" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76e09694b50f89f302ed531c1f2a7569f0be5867aee4ab4f8f729bbeec0078e3" +dependencies = [ + "arrayvec", + "num_enum", + "paste", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rp2040-boot2" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c773ec49b836077aa144b58dc7654a243e1eecdb6cf0d25361ae7c7600fabd8" +dependencies = [ + "crc-any", +] + +[[package]] +name = "rp2040-hal" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ecf1b975581f0cac465247c464e7d2b8d93c7a5fceb4eb13b7b8517f4f85f6d" +dependencies = [ + "cortex-m", + "critical-section", + "embedded-hal", + "fugit", + "itertools", + "nb 1.0.0", + "paste", + "pio", + "rand_core", + "rp2040-hal-macros", + "rp2040-pac", + "usb-device", + "vcell", + "void", +] + +[[package]] +name = "rp2040-hal-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86479063e497efe1ae81995ef9071f54fd1c7427e04d6c5b84cde545ff672a5e" +dependencies = [ + "cortex-m-rt", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "rp2040-pac" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9192cafbb40d717c9e0ddf767aaf9c69fee1b4e48d22ed853b57b11f6d9f3d7e" +dependencies = [ + "cortex-m", + "cortex-m-rt", + "vcell", +] + +[[package]] +name = "rtic-core" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9369355b04d06a3780ec0f51ea2d225624db777acbc60abd8ca4832da5c1a42" + +[[package]] +name = "rtic-monotonic" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb8b0b822d1a366470b9cea83a1d4e788392db763539dc4ba022bcc787fece82" + +[[package]] +name = "rtic-syntax" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad3ae243dd8d0a1b064615f664d4fa7e63929939074c564cbe5efdc4c503065" +dependencies = [ + "indexmap", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.16", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "sparkfun-pro-micro-rp2040" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a38e3e0ef1201e3e1fe3e40c2facd95fa1235dda391e002724544a0b885bbe07" +dependencies = [ + "cortex-m", + "cortex-m-rt", + "embedded-hal", + "rp2040-boot2", + "rp2040-hal", +] + +[[package]] +name = "spin" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dccf47db1b41fa1573ed27ccf5e08e3ca771cb994f776668c5ebda893b248fc" +dependencies = [ + "lock_api", +] + +[[package]] +name = "ssd1306" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f066d5458b0a27d938dd2b71a8b397d88c5776cb316b8a39f19ef49b6d290709" +dependencies = [ + "display-interface", + "display-interface-i2c", + "display-interface-spi", + "embedded-graphics-core", + "embedded-hal", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "systick-monotonic" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67fb822d5c615a0ae3a4795ee5b1d06381c7faf488d861c0a4fa8e6a88d5ff84" +dependencies = [ + "cortex-m", + "fugit", + "rtic-monotonic", +] + +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "usb-device" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508" + +[[package]] +name = "vcell" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "volatile-register" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee8f19f9d74293faf70901bc20ad067dc1ad390d2cbf1e3f75f721ffee908b6" +dependencies = [ + "vcell", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2708cfb --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "atmo-sense" +version = "0.1.0" +edition = "2021" +license = "CNPLv4+" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +cortex-m = "0.7.7" +cortex-m-rt = "0.7.2" +embedded-hal = { version = "0.2.7", features = ["unproven"] } +rp2040-boot2 = "0.2.1" +panic-halt = "0.2.0" +rp2040-hal = { version = "0.7.0", features = ["rt", "rom-func-cache", "critical-section-impl"] } +fugit = "0.3.6" +nb = "1.0.0" +cortex-m-rtic = "1.1.3" +rtic-monotonic = "1.0.0" +systick-monotonic = "1.0.1" +sparkfun-pro-micro-rp2040 = "0.5.0" +embedded-time = "0.12.1" +ssd1306 = "0.7.1" +embedded-graphics = "0.7.1" +numtoa = "0.2.4" diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..f76ea26 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,483 @@ +THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS +COOPERATIVE NON-VIOLENT PUBLIC LICENSE (\"LICENSE\"). THE WORK IS +PROTECTED BY COPYRIGHT AND ALL OTHER APPLICABLE LAWS. ANY USE OF THE +WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS +PROHIBITED. BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED IN THIS +LICENSE, YOU AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE +EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR +GRANTS YOU THE RIGHTS CONTAINED HERE IN AS CONSIDERATION FOR ACCEPTING +THE TERMS AND CONDITIONS OF THIS LICENSE AND FOR AGREEING TO BE BOUND BY +THE TERMS AND CONDITIONS OF THIS LICENSE. + +# Definitions + +An Act of War is any action of one country against any group either with +an intention to provoke a conflict or an action that occurs during a +declared war or during armed conflict between military forces of any +origin. This includes but is not limited to enforcing sanctions or +sieges, supplying armed forces, or profiting from the manufacture of +tools or weaponry used in military conflict. + +An Adaptation is a work based upon the Work, or upon the Work and other +pre-existing works, such as a translation, adaptation, derivative work, +arrangement of music or other alterations of a literary or artistic +work, or phonogram or performance and includes cinematographic +adaptations or any other form in which the Work may be recast, +transformed, or adapted including in any form recognizably derived from +the original, except that a work that constitutes a Collection will not +be considered an Adaptation for the purpose of this License. For the +avoidance of doubt, where the Work is a musical work, performance or +phonogram, the synchronization of the Work in timed-relation with a +moving image (\"synching\") will be considered an Adaptation for the +purpose of this License. In addition, where the Work is designed to +output a neural network the output of the neural network will be +considered an Adaptation for the purpose of this license. + +Bodily Harm is any physical hurt or injury to a person that interferes +with the health or comfort of the person and that is more than merely +transient or trifling in nature. + +Distribute is to make available to the public the original and copies of +the Work or Adaptation, as appropriate, through sale, gift or any other +transfer of possession or ownership. + +Incarceration is Confinement in a jail, prison, or any other place where +individuals of any kind are held against either their will or (if their +will cannot be determined) the will of their legal guardian or +guardians. In the case of a conflict between the will of the individual +and the will of their legal guardian or guardians, the will of the +individual will take precedence. + +Licensor is The individual, individuals, entity, or entities that +offer(s) the Work under the terms of this License + +Original Author is in the case of a literary or artistic work, the +individual, individuals, entity or entities who created the Work or if +no individual or entity can be identified, the publisher; and in +addition + +- in the case of a performance the actors, singers, musicians, + dancers, and other persons who act, sing, deliver, declaim, play in, + interpret or otherwise perform literary or artistic works or + expressions of folklore; + +- in the case of a phonogram the producer being the person or legal + entity who first fixes the sounds of a performance or other sounds; + and, + +- in the case of broadcasts, the organization that transmits the + broadcast. + +Work is the literary and/or artistic work offered under the terms of +this License including without limitation any production in the +literary, scientific and artistic domain, whatever may be the mode or +form of its expression including digital form, such as a book, pamphlet +and other writing; a lecture, address, sermon or other work of the same +nature; a dramatic or dramatico-musical work; a choreographic work or +entertainment in dumb show; a musical composition with or without words; +a cinematographic work to which are assimilated works expressed by a +process analogous to cinematography; a work of drawing, painting, +architecture, sculpture, engraving or lithography; a photographic work +to which are assimilated works expressed by a process analogous to +photography; a work of applied art; an illustration, map, plan, sketch +or three-dimensional work relative to geography, topography, +architecture or science; a performance; a broadcast; a phonogram; a +compilation of data to the extent it is protected as a copyrightable +work; or a work performed by a variety or circus performer to the extent +it is not otherwise considered a literary or artistic work. + +You means an individual or entity exercising rights under this License +who has not previously violated the terms of this License with respect +to the Work, or who has received express permission from the Licensor to +exercise rights under this License despite a previous violation. + +Publicly Perform means to perform public recitations of the Work and to +communicate to the public those public recitations, by any means or +process, including by wire or wireless means or public digital +performances; to make available to the public Works in such a way that +members of the public may access these Works from a place and at a place +individually chosen by them; to perform the Work to the public by any +means or process and the communication to the public of the performances +of the Work, including by public digital performance; to broadcast and +rebroadcast the Work by any means including signs, sounds or images. + +Reproduce is to make copies of the Work by any means including without +limitation by sound or visual recordings and the right of fixation and +reproducing fixations of the Work, including storage of a protected +performance or phonogram in digital form or other electronic medium. + +Software is any digital Work which, through use of a third-party piece +of Software or through the direct usage of itself on a computer system, +the memory of the computer is modified dynamically or semi-dynamically. +\"Software\", secondly, processes or interprets information. + +Source Code is Any digital Work which, through use of a third-party +piece of Software or through the direct usage of itself on a computer +system, the memory of the computer is modified dynamically or +semi-dynamically. \"Software\", secondly, processes or interprets +information. + +Surveilling is the use of the Work to either overtly or covertly observe +and record persons and or their activities. + +A Network Service is the use of a piece of Software to interpret or +modify information that is subsequently and directly served to users +over the Internet. + +To Discriminate is use of a work to differentiate between humans in a +such a way which prioritizes some above others on the basis of percieved +membership within certain groups. + +Hate Speech is Communication or any form of expression which is solely +for the purpose of expressing hatred for some group or advocating a form +of Discrimination between humans. + +Coercion is leveraging of the threat of force or use of force to +intimidate a person in order to gain compliance, or to offer large +incentives which aim to entice a person to act against their will. + +# Fair Dealing Rights + +Nothing in this License is intended to reduce, limit, or restrict any +uses free from copyright or rights arising from limitations or +exceptions that are provided for in connection with the copyright +protection under copyright law or other applicable laws. + +# License Grant + +Subject to the terms and conditions of this License, Licensor hereby +grants You a worldwide, royalty-free, non-exclusive, perpetual (for the +duration of the applicable copyright) license to exercise the rights in +the Work as stated below: + +To Reproduce the Work, to incorporate the Work into one or more +Collections, and to Reproduce the Work as incorporated in the +Collections + +To create and Reproduce Adaptations provided that any such Adaptation, +including any translation in any medium, takes reasonable steps to +clearly label, demarcate or otherwise identify that changes were made to +the original Work. For example, a translation could be marked \"The +original work was translated from English to Spanish,\" or a +modification could indicate \"The original work has been modified.\" + +To Distribute and Publicly Perform the Work including as incorporated in +Collections. + +To Distribute and Publicly Perform Adaptations. The above rights may be +exercised in all media and formats whether now known or hereafter +devised. The above rights include the right to make such modifications +as are technically necessary to exercise the rights in other media and +formats. This License constitutes the entire agreement between the +parties with respect to the Work licensed here. There are no +understandings, agreements or representations with respect to the Work +not specified here. Licensor shall not be bound by any additional +provisions that may appear in any communication from You. This License +may not be modified without the mutual written agreement of the Licensor +and You. All rights not expressly granted by Licensor are hereby +reserved, including but not limited to the rights set forth in +Non-waivable Compulsory License Schemes, Waivable Compulsory License +Schemes, and Voluntary License Schemes in the restrictions. + +# Restrictions + +The license granted in the license grant above is expressly made subject +to and limited by the following restrictions: + +You may Distribute or Publicly Perform the Work only under the terms of +this License. You must include a copy of, or the Uniform Resource +Identifier (URI) for, this License with every copy of the Work You +Distribute or Publicly Perform. You may not offer or impose any terms on +the Work that restrict the terms of this License or the ability of the +recipient of the Work to exercise the rights granted to that recipient +under the terms of the License. You may not sublicense the Work. You +must keep intact all notices that refer to this License and to the +disclaimer of warranties with every copy of the Work You Distribute or +Publicly Perform. When You Distribute or Publicly Perform the Work, You +may not impose any effective technological measures on the Work that +restrict the ability of a recipient of the Work from You to exercise the +rights granted to that recipient under the terms of the License. This +Section applies to the Work as incorporated in a Collection, but this +does not require the Collection apart from the Work itself to be made +subject to the terms of this License. If You create a Collection, upon +notice from any Licensor You must, to the extent practicable, remove +from the Collection any credit as requested. If You create an +Adaptation, upon notice from any Licensor You must, to the extent +practicable, remove from the Adaptation any credit as requested. + +## Commercial Restrictions + +You may not exercise any of the rights granted to You in the above +section in any manner that is primarily intended for or directed toward +commercial advantage or private monetary compensation unless you meet +the following requirements. + +i. You are a worker-owned business or worker-owned collective. + +ii. after tax, all financial gain, surplus, profits and benefits + produced by the business or collective are distributed among the + worker-owners unless a set amount is to be allocated towards + community projects as decided by a previously-established consensus + agreement between the worker-owners where all worker-owners agreed. + +iii. You are not using such rights on behalf of a business other than + those specified in (i) or (ii) above, nor are using such rights as + a proxy on behalf of a business with the intent to circumvent the + aforementioned restrictions on such a business. + +The exchange of the Work for other copyrighted works by means of digital +file-sharing or otherwise shall not be considered to be intended for or +directed toward commercial advantage or private monetary compensation, +provided there is no payment of any monetary compensation in connection +with the exchange of copyrighted works. + +If the Work meets the definition of Software, You may exercise the +rights granted in the license grant only if You provide a copy of the +corresponding Source Code from which the Work was derived in digital +form, or You provide a URI for the corresponding Source Code of the +Work, to any recipients upon request. + +If the Work is used as or for a Network Service, You may exercise the +rights granted in the license grant only if You provide a copy of the +corresponding Source Code from which the Work was derived in digital +form, or You provide a URI for the corresponding Source Code to the +Work, to any recipients of the data served or modified by the Web +Service. + +Any use by a business that is privately owned and managed, and that +seeks to generate profit from the labor of employees paid by salary or +other wages, is not permitted under this license. + +## + +You may exercise the rights granted in the license grant for any +purposes only if: + +i. You do not use the Work for the purpose of inflicting Bodily Harm on + human beings (subject to criminal prosecution or otherwise) outside + of providing medical aid or undergoing a voluntary procedure under + no form of Coercion. + +ii. You do not use the Work for the purpose of Surveilling or tracking + individuals for financial gain. + +iii. You do not use the Work in an Act of War. + +iv. You do not use the Work for the purpose of supporting or profiting + from an Act of War. + +v. You do not use the Work for the purpose of Incarceration. + +vi. You do not use the Work for the purpose of extracting, processing, + or refining, oil, gas, or coal. Or to in any other way to + deliberately pollute the environment as a byproduct of manufacturing + or irresponsible disposal of hazardous materials. + +vii. You do not use the Work for the purpose of expediting, + coordinating, or facilitating paid work undertaken by individuals + under the age of 12 years. + +viii. You do not use the Work to either Discriminate or spread Hate + Speech on the basis of sex, sexual orientation, gender identity, + race, age, disability, color, national origin, religion, caste, or + lower economic status. + +## + +If You Distribute, or Publicly Perform the Work or any Adaptations or +Collections, You must, unless a request has been made by any Licensor to +remove credit from a Collection or Adaptation, keep intact all copyright +notices for the Work and provide, reasonable to the medium or means You +are utilizing: + +i. the name of the Original Author (or pseudonym, if applicable) if + supplied, and/or if the Original Author and/or Licensor designate + another party or parties (e.g., a sponsor institute, publishing + entity, journal) for attribution (\"Attribution Parties\") in + Licensor\'s copyright notice, terms of service or by other + reasonable means, the name of such party or parties; + +ii. the title of the Work if supplied; + +iii. to the extent reasonably practicable, the URI, if any, that + Licensor to be associated with the Work, unless such URI does not + refer to the copyright notice or licensing information for the + Work; and, + +iv. in the case of an Adaptation, a credit identifying the use of the + Work in the Adaptation (e.g., \"French translation of the Work by + Original Author,\" or \"Screenplay based on original Work by + Original Author\"). + +If any Licensor has sent notice to request removing credit, You must, to +the extent practicable, remove any credit as requested. The credit +required by this Section may be implemented in any reasonable manner; +provided, however, that in the case of an Adaptation or Collection, at a +minimum such credit will appear, if a credit for all contributing +authors of the Adaptation or Collection appears, then as part of these +credits and in a manner at least as prominent as the credits for the +other contributing authors. For the avoidance of doubt, You may only use +the credit required by this Section for the purpose of attribution in +the manner set out above and, by exercising Your rights under this +License, You may not implicitly or explicitly assert or imply any +connection with, sponsorship or endorsement by the Original Author, +Licensor and/or Attribution Parties, as appropriate, of You or Your use +of the Work, without the separate, express prior written permission of +the Original Author, Licensor and/or Attribution Parties. + +Non-waivable Compulsory License Schemes. In those jurisdictions in which +the right to collect royalties through any statutory or compulsory +licensing scheme cannot be waived, the Licensor reserves the exclusive +right to collect such royalties for any exercise by You of the rights +granted under this License + +Waivable Compulsory License Schemes. In those jurisdictions in which the +right to collect royalties through any statutory or compulsory licensing +scheme can be waived, the Licensor reserves the exclusive right to +collect such royalties for any exercise by You of the rights granted +under this License if Your exercise of such rights is for a purpose or +use which is otherwise than noncommercial as permitted under Commercial +Restrictions and otherwise waives the right to collect royalties through +any statutory or compulsory licensing scheme. + +Voluntary License Schemes. The Licensor reserves the right to collect +royalties, whether individually or, in the event that the Licensor is a +member of a collecting society that administers voluntary licensing +schemes, via that society, from any exercise by You of the rights +granted under this License that is for a purpose or use which is +otherwise than noncommercial as permitted under the license grant. + +Except as otherwise agreed in writing by the Licensor or as may be +otherwise permitted by applicable law, if You Reproduce, Distribute or +Publicly Perform the Work either by itself or as part of any Adaptations +or Collections, You must not distort, mutilate, modify or take other +derogatory action in relation to the Work which would be prejudicial to +the Original Author\'s honor or reputation. Licensor agrees that in +those jurisdictions (e.g. Japan), in which any exercise of the right +granted in the license grant of this License (the right to make +Adaptations) would be deemed to be a distortion, mutilation, +modification or other derogatory action prejudicial to the Original +Author\'s honor and reputation, the Licensor will waive or not assert, +as appropriate, this Section, to the fullest extent permitted by the +applicable national law, to enable You to reasonably exercise Your right +under the license grant of this License (right to make Adaptations) but +not otherwise. + +Do not make any legal claim against anyone accusing the Work, with or +without changes, alone or with other works, of infringing any patent +claim. + +# Representations Warranties and Disclaimer + +UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR +OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY +KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, +INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, +FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF +LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, +WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE +EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU. + +# Limitation on Liability + +EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL +LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, +INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF +THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED +OF THE POSSIBILITY OF SUCH DAMAGES. + +# Termination + +This License and the rights granted hereunder will terminate +automatically upon any breach by You of the terms of this License. +Individuals or entities who have received Adaptations or Collections +from You under this License, however, will not have their licenses +terminated provided such individuals or entities remain in full +compliance with those licenses. The Sections on definitions, fair +dealing rights, representations, warranties, and disclaimer, limitation +on liability, termination, and revised license versions will survive any +termination of this License. + +Subject to the above terms and conditions, the license granted here is +perpetual (for the duration of the applicable copyright in the Work). +Notwithstanding the above, Licensor reserves the right to release the +Work under different license terms or to stop distributing the Work at +any time; provided, however that any such election will not serve to +withdraw this License (or any other license that has been, or is +required to be, granted under the terms of this License), and this +License will continue in full force and effect unless terminated as +stated above. + +# Revised License Versions + +This License may receive future revisions in the original spirit of the +license intended to strengthen This License. Each version of This +License has an incrementing version number. + +Unless otherwise specified like in the below subsection The Licensor has +only granted this current version of This License for The Work. In this +case future revisions do not apply. + +The Licensor may specify that the latest available revision of This +License be used for The Work by either explicitly writing so or by +suffixing the License URI with a \"+\" symbol. + +The Licensor may specify that The Work is also available under the terms +of This License\'s current revision as well as specific future +revisions. The Licensor may do this by writing it explicitly or +suffixing the License URI with any additional version numbers each +separated by a comma. + +# Miscellaneous + +Each time You Distribute or Publicly Perform the Work or a Collection, +the Licensor offers to the recipient a license to the Work on the same +terms and conditions as the license granted to You under this License. + +Each time You Distribute or Publicly Perform an Adaptation, Licensor +offers to the recipient a license to the original Work on the same terms +and conditions as the license granted to You under this License. + +If the Work is classified as Software, each time You Distribute or +Publicly Perform an Adaptation, Licensor offers to the recipient a copy +and/or URI of the corresponding Source Code on the same terms and +conditions as the license granted to You under this License. + +If the Work is used as a Network Service, each time You Distribute or +Publicly Perform an Adaptation, or serve data derived from the Software, +the Licensor offers to any recipients of the data a copy and/or URI of +the corresponding Source Code on the same terms and conditions as the +license granted to You under this License. + +If any provision of this License is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this License, and without further action +by the parties to this agreement, such provision shall be reformed to +the minimum extent necessary to make such provision valid and +enforceable. + +No term or provision of this License shall be deemed waived and no +breach consented to unless such waiver or consent shall be in writing +and signed by the party to be charged with such waiver or consent. + +This License constitutes the entire agreement between the parties with +respect to the Work licensed here. There are no understandings, +agreements or representations with respect to the Work not specified +here. Licensor shall not be bound by any additional provisions that may +appear in any communication from You. This License may not be modified +without the mutual written agreement of the Licensor and You. + +The rights granted under, and the subject matter referenced, in this +License were drafted utilizing the terminology of the Berne Convention +for the Protection of Literary and Artistic Works (as amended on +September 28, 1979), the Rome Convention of 1961, the WIPO Copyright +Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and +the Universal Copyright Convention (as revised on July 24, 1971). These +rights and subject matter take effect in the relevant jurisdiction in +which the License terms are sought to be enforced according to the +corresponding provisions of the implementation of those treaty +provisions in the applicable national law. If the standard suite of +rights granted under applicable copyright law includes additional rights +not granted under this License, such additional rights are deemed to be +included in the License; this License is not intended to restrict the +license of any rights under applicable law. diff --git a/README.md b/README.md new file mode 100644 index 0000000..bb67a41 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# atmo-sense + +This will be a small firmware for an rp2040 microcontroller +to read from a gas sensor and display the result on an +oled display. \ No newline at end of file diff --git a/memory.x b/memory.x new file mode 100644 index 0000000..070eac7 --- /dev/null +++ b/memory.x @@ -0,0 +1,15 @@ +MEMORY { + BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 + FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 + RAM : ORIGIN = 0x20000000, LENGTH = 256K +} + +EXTERN(BOOT2_FIRMWARE) + +SECTIONS { + /* ### Boot loader */ + .boot2 ORIGIN(BOOT2) : + { + KEEP(*(.boot2)); + } > BOOT2 +} INSERT BEFORE .text; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0f880d7 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,130 @@ +#![no_std] +#![no_main] + +use panic_halt as _; + +use fugit::RateExtU32; + +use hal::i2c; +pub use sparkfun_pro_micro_rp2040::hal; +use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; + +use embedded_graphics::text::Text; +use embedded_graphics::{ + mono_font::{ascii::FONT_10X20, MonoTextStyle}, + pixelcolor::BinaryColor, + prelude::*, + text::Alignment, +}; + +use fugit::MicrosDurationU32; +use hal::gpio::bank0::{Gpio14, Gpio15}; +use hal::gpio::Pin; +use hal::pac::I2C1; +use hal::timer::Alarm; +use hal::timer::Alarm0; + +#[rtic::app(device = sparkfun_pro_micro_rp2040::hal::pac, peripherals = true)] +mod app { + + const CHANGE_FREQUENCY_TICKS: u32 = 1000; + + use super::*; + type Display = Ssd1306< + I2CInterface< + hal::I2C< + I2C1, + ( + Pin>, + Pin>, + ), + >, + >, + DisplaySize128x64, + ssd1306::mode::BufferedGraphicsMode, + >; + + #[shared] + struct Shared { + alarm: Alarm0, + } + + #[local] + struct Local { + display: Display, + state: u8, + } + + #[init()] + fn init(c: init::Context) -> (Shared, Local, init::Monotonics) { + let mut resets = c.device.RESETS; + + let sio = hal::Sio::new(c.device.SIO); + let pins = rp2040_hal::gpio::Pins::new( + c.device.IO_BANK0, + c.device.PADS_BANK0, + sio.gpio_bank0, + &mut resets, + ); + let mut timer = hal::Timer::new(c.device.TIMER, &mut resets); + let mut alarm = timer.alarm_0().unwrap(); + let _ = alarm.schedule(MicrosDurationU32::from_ticks(CHANGE_FREQUENCY_TICKS)); + alarm.enable_interrupt(); + + let scl = pins.gpio15.into_mode(); + let sda = pins.gpio14.into_mode(); + let i2c = i2c::I2C::i2c1( + c.device.I2C1, + sda, + scl, + 100.kHz(), + &mut resets, + 125_000_000.Hz(), + ); + let interface = I2CDisplayInterface::new(i2c); + let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0) + .into_buffered_graphics_mode(); + display.init().unwrap(); + + display.flush().unwrap(); + + ( + Shared { alarm }, + Local { display, state: 0 }, + init::Monotonics(), + ) + } + + #[task(binds = TIMER_IRQ_0, priority = 1, shared = [alarm], local = [display, state])] + fn tick(mut c: tick::Context) { + use numtoa::NumToA; + let display = c.local.display; + display.clear(); + + let mut buf = [0u8; 20]; + let text = c.local.state.numtoa_str(10, &mut buf); + *c.local.state += 1; + + Text::with_alignment( + text, + display.bounding_box().center(), + MonoTextStyle::new(&FONT_10X20, BinaryColor::On), + Alignment::Center, + ) + .draw(display) + .unwrap(); + display.flush().unwrap(); + + c.shared.alarm.lock(|a| { + a.clear_interrupt(); + let _ = a.schedule(MicrosDurationU32::from_ticks(CHANGE_FREQUENCY_TICKS)); + }); + } + + #[idle] + fn idle(_cx: idle::Context) -> ! { + loop { + cortex_m::asm::nop(); + } + } +}