rudimentary lcd implementation
This commit is contained in:
parent
a5aa57148f
commit
f8894e9529
142
Cargo.lock
generated
142
Cargo.lock
generated
@ -581,9 +581,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.4"
|
||||
version = "4.5.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
|
||||
checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@ -591,9 +591,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.2"
|
||||
version = "4.5.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4"
|
||||
checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@ -603,9 +603,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.4"
|
||||
version = "4.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64"
|
||||
checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6"
|
||||
dependencies = [
|
||||
"heck 0.5.0",
|
||||
"proc-macro2",
|
||||
@ -1246,19 +1246,20 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hyper-rustls"
|
||||
version = "0.26.0"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c"
|
||||
checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"http",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"rustls 0.22.4",
|
||||
"rustls 0.23.7",
|
||||
"rustls-pki-types",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-rustls 0.26.0",
|
||||
"tower-service",
|
||||
"webpki-roots 0.26.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1916,6 +1917,53 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quinn"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4ceeeeabace7857413798eb1ffa1e9c905a9946a57d81fb69b4b71c4d8eb3ad"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"pin-project-lite",
|
||||
"quinn-proto",
|
||||
"quinn-udp",
|
||||
"rustc-hash",
|
||||
"rustls 0.23.7",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quinn-proto"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddf517c03a109db8100448a4be38d498df8a210a99fe0e1b9eaf39e78c640efe"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"rand",
|
||||
"ring",
|
||||
"rustc-hash",
|
||||
"rustls 0.23.7",
|
||||
"slab",
|
||||
"thiserror",
|
||||
"tinyvec",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quinn-udp"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9096629c45860fc7fb143e125eb826b5e721e10be3263160c7d60ca832cf8c46"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"once_cell",
|
||||
"socket2 0.5.7",
|
||||
"tracing",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.36"
|
||||
@ -2034,9 +2082,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.12.4"
|
||||
version = "0.12.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10"
|
||||
checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37"
|
||||
dependencies = [
|
||||
"base64 0.22.0",
|
||||
"bytes",
|
||||
@ -2055,7 +2103,8 @@ dependencies = [
|
||||
"once_cell",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustls 0.22.4",
|
||||
"quinn",
|
||||
"rustls 0.23.7",
|
||||
"rustls-pemfile 2.1.2",
|
||||
"rustls-pki-types",
|
||||
"serde",
|
||||
@ -2063,7 +2112,7 @@ dependencies = [
|
||||
"serde_urlencoded",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-rustls 0.26.0",
|
||||
"tower-service",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
@ -2152,7 +2201,7 @@ dependencies = [
|
||||
"rustls-webpki 0.102.3",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-rustls 0.25.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2177,6 +2226,12 @@ version = "0.1.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.37.27"
|
||||
@ -2229,6 +2284,20 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.23.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebbbdb961df0ad3f2652da8f3fdc4b36122f568f968f45ad3316f26c025c677b"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"ring",
|
||||
"rustls-pki-types",
|
||||
"rustls-webpki 0.102.3",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-native-certs"
|
||||
version = "0.7.0"
|
||||
@ -2509,18 +2578,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.199"
|
||||
version = "1.0.203"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a"
|
||||
checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.199"
|
||||
version = "1.0.203"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc"
|
||||
checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -2529,9 +2598,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.116"
|
||||
version = "1.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813"
|
||||
checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
@ -2973,9 +3042,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sync_wrapper"
|
||||
version = "0.1.2"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
|
||||
checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394"
|
||||
|
||||
[[package]]
|
||||
name = "tap"
|
||||
@ -2997,18 +3066,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.59"
|
||||
version = "1.0.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
|
||||
checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.59"
|
||||
version = "1.0.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
|
||||
checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -3073,9 +3142,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.37.0"
|
||||
version = "1.38.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
|
||||
checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
@ -3092,9 +3161,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.2.0"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
||||
checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -3112,6 +3181,17 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.26.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4"
|
||||
dependencies = [
|
||||
"rustls 0.23.7",
|
||||
"rustls-pki-types",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-stream"
|
||||
version = "0.1.15"
|
||||
|
@ -5,8 +5,8 @@ members = [
|
||||
]
|
||||
|
||||
[workspace.dependencies]
|
||||
sea-orm = "0.12"
|
||||
serde = "1.0.199"
|
||||
sea-orm = "0.12.15"
|
||||
serde = "1.0.203"
|
||||
time = "0.3.36"
|
||||
|
||||
[workspace.package]
|
||||
|
@ -10,17 +10,17 @@ repository = { workspace = true }
|
||||
entity = { path = "../entity" }
|
||||
migration = { path = "../migration" }
|
||||
ciborium = "0.2.2"
|
||||
clap = { version = "4.5.4", features = ["derive"] }
|
||||
clap = { version = "4.5.7", features = ["derive"] }
|
||||
config = { version = "0.14.0", default-features = false, features = [ "toml" ] }
|
||||
futures = "0.3.30"
|
||||
itertools = "0.13.0"
|
||||
reqwest = { version = "0.12.4", features = ["json", "rustls-tls"], default-features = false }
|
||||
reqwest = { version = "0.12.5", features = ["json", "rustls-tls"], default-features = false }
|
||||
rumqttc = "0.24.0"
|
||||
sea-orm = { workspace = true, features = [ "with-time", "sqlx-sqlite", "sqlx-postgres", "sqlx-mysql", "runtime-tokio-rustls", "macros" ] }
|
||||
serde = { workspace = true }
|
||||
serde_json = "1.0.116"
|
||||
thiserror = "1.0.59"
|
||||
serde_json = "1.0.118"
|
||||
thiserror = "1.0.61"
|
||||
time = { workspace = true, features = ["macros", "serde", "formatting", "parsing" ] }
|
||||
tokio = { version = "1.37.0", features = ["full"] }
|
||||
tokio = { version = "1.38.0", features = ["full"] }
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||
|
32
display/Cargo.lock
generated
32
display/Cargo.lock
generated
@ -29,9 +29,12 @@ dependencies = [
|
||||
"cortex-m-rt",
|
||||
"defmt",
|
||||
"defmt-rtt",
|
||||
"ekv",
|
||||
"embassy-embedded-hal",
|
||||
"embassy-executor",
|
||||
"embassy-nrf",
|
||||
"embassy-time",
|
||||
"embedded-hal-async",
|
||||
"nrf-softdevice",
|
||||
"panic-probe",
|
||||
]
|
||||
@ -209,9 +212,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "defmt"
|
||||
version = "0.3.6"
|
||||
version = "0.3.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3939552907426de152b3c2c6f51ed53f98f448babd26f28694c95f5906194595"
|
||||
checksum = "a99dd22262668b887121d4672af5a64b238f026099f1a2a1b322066c9ecfe9e0"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"defmt-macros",
|
||||
@ -241,9 +244,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "defmt-rtt"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "609923761264dd99ed9c7d209718cda4631c5fe84668e0f0960124cbb844c49f"
|
||||
checksum = "bab697b3dbbc1750b7c8b821aa6f6e7f2480b47a99bc057a2ed7b170ebef0c51"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"defmt",
|
||||
@ -258,6 +261,15 @@ dependencies = [
|
||||
"litrs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ekv"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/embassy-rs/ekv.git?rev=571a9c8863e9644682ebd41343eaf0444ea4bf87#571a9c8863e9644682ebd41343eaf0444ea4bf87"
|
||||
dependencies = [
|
||||
"embassy-sync 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heapless",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embassy-embedded-hal"
|
||||
version = "0.1.0"
|
||||
@ -821,9 +833,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "panic-probe"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa6fa5645ef5a760cd340eaa92af9c1ce131c8c09e7f8926d8a24b59d26652b9"
|
||||
checksum = "4047d9235d1423d66cc97da7d07eddb54d4f154d6c13805c6d0793956f4f25b0"
|
||||
dependencies = [
|
||||
"cortex-m",
|
||||
"defmt",
|
||||
@ -978,18 +990,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.60"
|
||||
version = "1.0.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18"
|
||||
checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.60"
|
||||
version = "1.0.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524"
|
||||
checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -10,6 +10,11 @@ git = "https://github.com/embassy-rs/embassy.git"
|
||||
rev = "3c52ef60b19468a8700d612699c869f0bdcae339"
|
||||
features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"]
|
||||
|
||||
[dependencies.embassy-embedded-hal]
|
||||
version = "0.1.0"
|
||||
git = "https://github.com/embassy-rs/embassy.git"
|
||||
rev = "3c52ef60b19468a8700d612699c869f0bdcae339"
|
||||
|
||||
[dependencies.embassy-executor]
|
||||
version = "0.5.0"
|
||||
git = "https://github.com/embassy-rs/embassy.git"
|
||||
@ -29,10 +34,19 @@ rev = "3c53b8c454cc9331082053033485e713abcadbb5"
|
||||
features = ["defmt", "ble-peripheral", "ble-central", "critical-section-impl", "ble-gatt-server", "nrf52840", "s140"]
|
||||
|
||||
[dependencies]
|
||||
defmt = "0.3.6"
|
||||
defmt-rtt = "0.4.0"
|
||||
defmt = "0.3.8"
|
||||
defmt-rtt = "0.4.1"
|
||||
|
||||
panic-probe = { version = "0.3.1", features = ["print-defmt"] }
|
||||
panic-probe = { version = "0.3.2", features = ["print-defmt"] }
|
||||
|
||||
cortex-m = { version = "0.7.7", features = ["inline-asm"] }
|
||||
cortex-m-rt = "0.7.4"
|
||||
cortex-m-rt = "0.7.3"
|
||||
|
||||
embedded-hal-async = "1.0.0"
|
||||
|
||||
ekv = { version = "0.1.0", git = "https://github.com/embassy-rs/ekv.git", rev = "571a9c8863e9644682ebd41343eaf0444ea4bf87", features = [
|
||||
"crc",
|
||||
"page-size-4096",
|
||||
"align-4",
|
||||
"max-page-count-2048",
|
||||
]}
|
||||
|
169
display/src/lcd.rs
Normal file
169
display/src/lcd.rs
Normal file
@ -0,0 +1,169 @@
|
||||
use embassy_nrf::interrupt::Priority;
|
||||
use embassy_nrf::interrupt::{self, InterruptExt};
|
||||
use embassy_nrf::peripherals::{P0_03, P0_04, TWISPI0};
|
||||
use embassy_nrf::twim::{self, Twim};
|
||||
use embassy_nrf::{bind_interrupts, peripherals};
|
||||
use embassy_time::Delay;
|
||||
use embedded_hal_async::delay::DelayNs;
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0 => twim::InterruptHandler<peripherals::TWISPI0>;
|
||||
});
|
||||
|
||||
const LCD_2_LINE: u8 = 0x08;
|
||||
const LCD_4_BIT_MODE: u8 = 0x00;
|
||||
const LCD_5X8DOTS: u8 = 0x00;
|
||||
|
||||
const CLEAR_DISPLAY: u8 = 0x01;
|
||||
const DISPLAY_ON: u8 = 0x04;
|
||||
|
||||
const SCROLL_LEFT: u8 = 0x18;
|
||||
|
||||
const BLINK_ON: u8 = 0x01;
|
||||
const CURSOR_ON: u8 = 0x02;
|
||||
const BLINK_OFF: u8 = 0x00;
|
||||
const CURSOR_OFF: u8 = 0x00;
|
||||
|
||||
const FUNCTION_SET: u8 = 0x20;
|
||||
const DISPLAY_CONTROL: u8 = 0x08;
|
||||
|
||||
const BACKLIGHT: u8 = 0x08;
|
||||
|
||||
const RETURN_HOME: u8 = 0x02;
|
||||
const SET_DDRAM_ADDR: u8 = 0x80;
|
||||
|
||||
const EN: u8 = 0b000_00100;
|
||||
const RS: u8 = 0b000_00001;
|
||||
|
||||
const LINE_LENGTH: usize = 16;
|
||||
const LINE_OFFSETS: [u8; 2] = [0x00, 0x40];
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Lines {
|
||||
First,
|
||||
Second,
|
||||
}
|
||||
|
||||
pub struct Lcd<'a> {
|
||||
i2c: Twim<'a, TWISPI0>,
|
||||
lines: [&'a str; 2],
|
||||
address: u8,
|
||||
}
|
||||
|
||||
impl<'a> Lcd<'a> {
|
||||
async fn write_four_bits(&mut self, nibble: u8) -> Result<(), twim::Error> {
|
||||
self.i2c
|
||||
.write(self.address, &[nibble | EN | BACKLIGHT])
|
||||
.await?;
|
||||
self.i2c
|
||||
.write(self.address, &[(nibble & !EN) | BACKLIGHT])
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn cmd(&mut self, data: u8, mode: u8) -> Result<(), twim::Error> {
|
||||
self.write_four_bits(mode | (data & 0xF0)).await?;
|
||||
self.write_four_bits(mode | ((data << 4) & 0xF0)).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn init(&mut self) -> Result<(), twim::Error> {
|
||||
let mut delay = Delay {};
|
||||
|
||||
delay.delay_ms(100).await;
|
||||
|
||||
self.cmd(0x03, 0).await?;
|
||||
self.cmd(0x03, 0).await?;
|
||||
self.cmd(0x03, 0).await?;
|
||||
self.cmd(0x02, 0).await?;
|
||||
|
||||
self.cmd(FUNCTION_SET | LCD_2_LINE | LCD_5X8DOTS | LCD_4_BIT_MODE, 0)
|
||||
.await?;
|
||||
self.cmd(DISPLAY_CONTROL | DISPLAY_ON | CURSOR_OFF | BLINK_OFF, 0)
|
||||
.await?;
|
||||
self.cmd(FUNCTION_SET | LCD_2_LINE | LCD_5X8DOTS | LCD_4_BIT_MODE, 0)
|
||||
.await?;
|
||||
|
||||
self.cmd(RETURN_HOME, 0).await?;
|
||||
self.clear().await?;
|
||||
|
||||
self.i2c.write(self.address, &[BACKLIGHT]).await?;
|
||||
delay.delay_ms(10).await;
|
||||
|
||||
self.cmd(DISPLAY_CONTROL | DISPLAY_ON | CURSOR_ON | BLINK_ON, 0)
|
||||
.await?;
|
||||
|
||||
self.set_cursor(0, LINE_OFFSETS[Lines::First as usize])
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new(address: u8, spi0: TWISPI0, p03: P0_03, p04: P0_04) -> Self {
|
||||
interrupt::SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0.set_priority(Priority::P2);
|
||||
|
||||
let config = twim::Config::default();
|
||||
let i2c = Twim::new(spi0, Irqs, p03, p04, config);
|
||||
|
||||
Lcd {
|
||||
i2c,
|
||||
lines: ["", ""],
|
||||
address,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn scroll_buffer(&mut self) -> Result<(), twim::Error> {
|
||||
if self.lines[0].len() > LINE_LENGTH || self.lines[1].len() > LINE_LENGTH {
|
||||
self.cmd(SCROLL_LEFT, 0).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn write_buffer(&mut self) -> Result<(), twim::Error> {
|
||||
for line in 0..2 {
|
||||
let mut position = 0;
|
||||
|
||||
for c in self.lines[line].chars() {
|
||||
self.write_character(c, position, LINE_OFFSETS[line])
|
||||
.await?;
|
||||
position += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn clear(&mut self) -> Result<(), twim::Error> {
|
||||
self.cmd(CLEAR_DISPLAY, 0).await?;
|
||||
self.lines = ["", ""];
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_cursor(&mut self, position: u8, line_offset: u8) -> Result<(), twim::Error> {
|
||||
self.cmd(SET_DDRAM_ADDR | line_offset + position, 0).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn write_character(
|
||||
&mut self,
|
||||
character: char,
|
||||
position: u8,
|
||||
line_offset: u8,
|
||||
) -> Result<(), twim::Error> {
|
||||
self.set_cursor(position, line_offset).await?;
|
||||
self.cmd(character as u8, RS).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn write(&mut self, text: &'a str, line: Lines) -> Result<(), twim::Error> {
|
||||
self.lines[line as usize] = text;
|
||||
self.write_buffer().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use ble::gatt::Server;
|
||||
use defmt_rtt as _;
|
||||
use embassy_nrf as _;
|
||||
use nrf_softdevice::Softdevice;
|
||||
use embassy_time::Delay;
|
||||
use embedded_hal_async::delay::DelayNs;
|
||||
use panic_probe as _;
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use crate::lcd::Lcd;
|
||||
use defmt::{error, info, unwrap};
|
||||
use embassy_executor::Spawner;
|
||||
|
||||
pub mod ble {
|
||||
@ -17,6 +18,9 @@ pub mod ble {
|
||||
pub mod softdevice;
|
||||
}
|
||||
|
||||
pub mod lcd;
|
||||
pub mod peripherals;
|
||||
|
||||
const DEVICE_NAME: &str = "alert-me display";
|
||||
|
||||
#[embassy_executor::task]
|
||||
@ -30,7 +34,37 @@ async fn ble(spawner: Spawner) {
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn tick(mut lcd: lcd::Lcd<'static>, delay: u32) {
|
||||
let mut d = Delay {};
|
||||
loop {
|
||||
lcd.scroll_buffer()
|
||||
.await
|
||||
.unwrap_or_else(|e| error!("Failed to scroll lcd: {}", e));
|
||||
|
||||
d.delay_ms(delay).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let peripherals = peripherals::init();
|
||||
let mut lcd = Lcd::new(
|
||||
0x27,
|
||||
peripherals.TWISPI0,
|
||||
peripherals.P0_03,
|
||||
peripherals.P0_04,
|
||||
);
|
||||
lcd.init()
|
||||
.await
|
||||
.unwrap_or_else(|e| error!("Failed to initialize lcd: {}", e));
|
||||
lcd.write("Hello, horse :)", lcd::Lines::First)
|
||||
.await
|
||||
.unwrap();
|
||||
lcd.write("I am an electronic horse!", lcd::Lines::Second)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
unwrap!(spawner.spawn(ble(spawner)));
|
||||
unwrap!(spawner.spawn(tick(lcd, 300)));
|
||||
}
|
||||
|
9
display/src/peripherals.rs
Normal file
9
display/src/peripherals.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use embassy_nrf::interrupt::Priority;
|
||||
|
||||
pub fn init() -> embassy_nrf::Peripherals {
|
||||
let mut config = embassy_nrf::config::Config::default();
|
||||
config.gpiote_interrupt_priority = Priority::P2;
|
||||
config.time_interrupt_priority = Priority::P2;
|
||||
|
||||
embassy_nrf::init(config)
|
||||
}
|
@ -74,7 +74,7 @@
|
||||
with fenix.packages.${system};
|
||||
fromToolchainFile {
|
||||
file = ./rust-toolchain.toml;
|
||||
sha256 = "sha256-iUnN1Tn3SDUo5JvS1QZjjvA2adh7URLeQyXnQHYjCik=";
|
||||
sha256 = "sha256-yrQPCdDVYQlF7MSAZP+R4DKigWY3PSTs0Re42v7CDNs=";
|
||||
};
|
||||
in
|
||||
with pkgs;
|
||||
|
@ -1,5 +1,5 @@
|
||||
[toolchain]
|
||||
channel = "nightly"
|
||||
components = [ "rustfmt" ]
|
||||
components = [ "clippy", "rustfmt" ]
|
||||
targets = [ "thumbv7em-none-eabi", "thumbv7em-none-eabihf" ]
|
||||
profile = "minimal"
|
||||
|
Loading…
Reference in New Issue
Block a user