From b23796fc7765b74fe0448b26b3e50b3a72595019 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 30 Nov 2025 03:04:45 -0600 Subject: [PATCH] Initial Commit --- .cargo/config.toml | 14 + .gitignore | 17 + .vscode/extensions.json | 7 + .vscode/settings.json | 13 + Cargo.lock | 1231 +++++++++++++++++++++++++++++++ Cargo.toml | 42 ++ build.rs | 40 + rust-toolchain.toml | 2 + src/bin/main.rs | 216 ++++++ src/bin/mini_ulp.s | 205 ++++++ src/bin/ulp_program.s | 1551 +++++++++++++++++++++++++++++++++++++++ src/display.rs | 447 +++++++++++ src/init.rs | 115 +++ src/lib.rs | 15 + src/setting_screen.rs | 492 +++++++++++++ src/state.rs | 387 ++++++++++ src/touch.rs | 406 ++++++++++ template.yaml | 149 ++++ 18 files changed, 5349 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 rust-toolchain.toml create mode 100644 src/bin/main.rs create mode 100644 src/bin/mini_ulp.s create mode 100644 src/bin/ulp_program.s create mode 100644 src/display.rs create mode 100644 src/init.rs create mode 100644 src/lib.rs create mode 100644 src/setting_screen.rs create mode 100644 src/state.rs create mode 100644 src/touch.rs create mode 100644 template.yaml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..0f5c9fa --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,14 @@ +[target.xtensa-esp32-none-elf] +runner = "espflash flash --monitor --chip esp32" + +[env] + +[build] +rustflags = [ + "-C", "link-arg=-nostartfiles", +] + +target = "xtensa-esp32-none-elf" + +[unstable] +build-std = ["alloc", "core"] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e771f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# RustRover +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..3b6f64e --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "rust-lang.rust-analyzer", + "tamasfe.even-better-toml", + "fill-labs.dependi" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e71dea6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "rust-analyzer.cargo.allTargets": false, + "rust-analyzer.cargo.target": "xtensa-esp32-none-elf", + "rust-analyzer.server.extraEnv": { + "RUSTUP_TOOLCHAIN": "stable" + }, + "rust-analyzer.check.extraEnv": { + "RUSTUP_TOOLCHAIN": "esp" + }, + "rust-analyzer.cargo.extraEnv": { + "RUSTUP_TOOLCHAIN": "esp" + }, +} diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..4e3def0 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1231 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anyhow" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "az" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" + +[[package]] +name = "basic-toml" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba62675e8242a4c4e806d12f11d136e626e6c8361d6b829310732241652a178a" +dependencies = [ + "serde", +] + +[[package]] +name = "bitfield" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db1bcd90f88eabbf0cadbfb87a45bceeaebcd3b4bc9e43da379cd2ef0162590d" +dependencies = [ + "bitfield-macros", +] + +[[package]] +name = "bitfield-macros" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3787a07661997bfc05dd3431e379c0188573f78857080cf682e1393ab8e4d64c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bitflags" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" + +[[package]] +name = "bytemuck" +version = "1.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" + +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "delegate" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9b6483c2bbed26f97861cf57651d4f2b731964a28cd2257f934a4b452480d21" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "crypto-common", +] + +[[package]] +name = "display-interface" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ba2aab1ef3793e6f7804162debb5ac5edb93b3d650fbcc5aeb72fcd0e6c03a0" + +[[package]] +name = "document-features" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d" +dependencies = [ + "litrs", +] + +[[package]] +name = "embassy-embedded-hal" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fea5ef5bed4d3468dfd44f5c9fa4cda8f54c86d4fb4ae683eacf9d39e2ea12" +dependencies = [ + "embassy-futures", + "embassy-sync", + "embassy-time", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "embedded-storage", + "embedded-storage-async", + "nb 1.1.0", +] + +[[package]] +name = "embassy-futures" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067" + +[[package]] +name = "embassy-sync" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d2c8cdff05a7a51ba0087489ea44b0b1d97a296ca6b1d6d1a33ea7423d34049" +dependencies = [ + "cfg-if", + "critical-section", + "embedded-io-async", + "futures-sink", + "futures-util", + "heapless", +] + +[[package]] +name = "embassy-time" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f820157f198ada183ad62e0a66f554c610cdcd1a9f27d4b316358103ced7a1f8" +dependencies = [ + "cfg-if", + "critical-section", + "document-features", + "embassy-time-driver", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "futures-util", +] + +[[package]] +name = "embassy-time-driver" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d45f5d833b6d98bd2aab0c2de70b18bfaa10faf661a1578fd8e5dfb15eb7eba" +dependencies = [ + "document-features", +] + +[[package]] +name = "embedded-can" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d2e857f87ac832df68fa498d18ddc679175cf3d2e4aa893988e5601baf9438" +dependencies = [ + "nb 1.1.0", +] + +[[package]] +name = "embedded-graphics" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0649998afacf6d575d126d83e68b78c0ab0e00ca2ac7e9b3db11b4cbe8274ef0" +dependencies = [ + "az", + "byteorder", + "embedded-graphics-core", + "float-cmp", + "micromath", +] + +[[package]] +name = "embedded-graphics-core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba9ecd261f991856250d2207f6d8376946cd9f412a2165d3b75bc87a0bc7a044" +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-hal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89" + +[[package]] +name = "embedded-hal-async" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4c685bbef7fe13c3c6dd4da26841ed3980ef33e841cddfa15ce8a8fb3f1884" +dependencies = [ + "embedded-hal 1.0.0", +] + +[[package]] +name = "embedded-hal-bus" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "513e0b3a8fb7d3013a8ae17a834283f170deaf7d0eeab0a7c1a36ad4dd356d22" +dependencies = [ + "critical-section", + "embedded-hal 1.0.0", +] + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + +[[package]] +name = "embedded-io-async" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff09972d4073aa8c299395be75161d582e7629cd663171d62af73c8d50dba3f" +dependencies = [ + "embedded-io", +] + +[[package]] +name = "embedded-storage" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21dea9854beb860f3062d10228ce9b976da520a73474aed3171ec276bc0c032" + +[[package]] +name = "embedded-storage-async" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1763775e2323b7d5f0aa6090657f5e21cfa02ede71f5dc40eead06d64dcd15cc" +dependencies = [ + "embedded-storage", +] + +[[package]] +name = "enum-as-inner" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "enumset" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11a6b7c3d347de0a9f7bfd2f853be43fe32fa6fac30c70f6d6d67a1e936b87ee" +dependencies = [ + "enumset_derive", +] + +[[package]] +name = "enumset_derive" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6da3ea9e1d1a3b1593e15781f930120e72aa7501610b2f82e5b6739c72e8eac5" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "esp-alloc" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a78132d362cbf62ce22a1466eb9e98424f6b2d1e476e7a3cb46ca9063c5833f7" +dependencies = [ + "cfg-if", + "critical-section", + "document-features", + "enumset", + "linked_list_allocator", +] + +[[package]] +name = "esp-backtrace" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4cd70abe47945c9116972781b5c05277ad855a5f5569fe2afd3e2e61a103cc0" +dependencies = [ + "esp-build 0.2.0", + "esp-println", + "semihosting", +] + +[[package]] +name = "esp-build" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aa1c8f9954c9506699cf1ca10a2adcc226ff10b6ae3cb9e875cf2c6a0b9a372" +dependencies = [ + "quote", + "syn", + "termcolor", +] + +[[package]] +name = "esp-build" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "837020ff95fbf4c15c206541dda7994f1bbe6e1505e36a6a5ecb51fdb61656d7" +dependencies = [ + "quote", + "syn", + "termcolor", +] + +[[package]] +name = "esp-config" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8c4c95d8d6243ddb39efe1fcf2524c9becd0f86bb3e24048ed30b4f553609f" +dependencies = [ + "document-features", + "serde", + "serde_json", +] + +[[package]] +name = "esp-hal" +version = "1.0.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d973697621cd3eef9c3f260fa8c1af77d8547cfc92734255d8e8ddf05c7d331" +dependencies = [ + "basic-toml", + "bitfield", + "bitflags", + "bytemuck", + "cfg-if", + "critical-section", + "delegate", + "digest", + "document-features", + "embassy-embedded-hal", + "embassy-futures", + "embassy-sync", + "embedded-can", + "embedded-hal 1.0.0", + "embedded-hal-async", + "embedded-io", + "embedded-io-async", + "enumset", + "esp-build 0.3.0", + "esp-config", + "esp-hal-procmacros", + "esp-metadata", + "esp-riscv-rt", + "esp32 0.37.0", + "fugit", + "instability", + "nb 1.1.0", + "paste", + "portable-atomic", + "rand_core 0.6.4", + "rand_core 0.9.3", + "riscv", + "serde", + "strum", + "ufmt-write", + "xtensa-lx", + "xtensa-lx-rt", +] + +[[package]] +name = "esp-hal-procmacros" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73164008cb2eada2ef85e6b0e459001d851f9b8e65e96e0d594bdfa8cf1b813b" +dependencies = [ + "darling", + "document-features", + "litrs", + "proc-macro-crate", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "esp-metadata" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0154d59933c2419ef25a01938517cc6969f47b6af53ebb34c279393aa20d9654" +dependencies = [ + "anyhow", + "basic-toml", + "serde", + "strum", +] + +[[package]] +name = "esp-println" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960703930f9f3c899ddedd122ea27a09d6a612c22323157e524af5b18876448e" +dependencies = [ + "critical-section", + "esp-build 0.2.0", + "log", + "portable-atomic", +] + +[[package]] +name = "esp-riscv-rt" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05c2badd16cbd6307d463090615332b77c17a6766b41ba5fe5bb783310e8af6" +dependencies = [ + "document-features", + "riscv", + "riscv-rt-macros", +] + +[[package]] +name = "esp32" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83ddfdb413ef0739d84bd3fce771e6e0feb6457ac1bcdd7a1dcd6326061e919d" +dependencies = [ + "critical-section", + "vcell", +] + +[[package]] +name = "esp32" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7680f79e3a4770e59c2dc25b17dcd852921ee57ffae9a4c4806c9ca5001d54d" +dependencies = [ + "vcell", +] + +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +dependencies = [ + "num-traits", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "fugit" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17186ad64927d5ac8f02c1e77ccefa08ccd9eaa314d5a4772278aa204a22f7e7" +dependencies = [ + "gcd", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "gcd" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hashbrown" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "indoc" +version = "2.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd" + +[[package]] +name = "instability" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf9fed6d91cfb734e7476a06bde8300a1b94e217e1b523b6f0cd1a01998c71d" +dependencies = [ + "darling", + "indoc", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" + +[[package]] +name = "litrs" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "micromath" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c8dda44ff03a2f238717214da50f65d5a53b45cd213a7370424ffdb6fae815" + +[[package]] +name = "minijinja" +version = "2.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd72e8b4e42274540edabec853f607c015c73436159b06c39c7af85a20433155" +dependencies = [ + "serde", +] + +[[package]] +name = "mipidsi" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba34dcbf61182ffa6992b5a4d9b566d5a99df127fd93f6d314213347329e92f" +dependencies = [ + "embedded-graphics-core", + "embedded-hal 1.0.0", + "heapless", + "nb 1.1.0", +] + +[[package]] +name = "mtgcount-rs" +version = "0.1.0" +dependencies = [ + "critical-section", + "display-interface", + "embedded-graphics", + "embedded-hal 1.0.0", + "embedded-hal-bus", + "esp-alloc", + "esp-backtrace", + "esp-hal", + "esp-println", + "esp32 0.38.0", + "micromath", + "mipidsi", + "u8g2-fonts", +] + +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.1.0", +] + +[[package]] +name = "nb" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "portable-atomic" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" + +[[package]] +name = "proc-macro-crate" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro-error-attr2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "proc-macro-error2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" +dependencies = [ + "proc-macro-error-attr2", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r0" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd7a31eed1591dcbc95d92ad7161908e72f4677f8fabf2a32ca49b4237cbf211" + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" + +[[package]] +name = "riscv" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea8ff73d3720bdd0a97925f0bf79ad2744b6da8ff36be3840c48ac81191d7a7" +dependencies = [ + "critical-section", + "embedded-hal 1.0.0", + "paste", + "riscv-macros", + "riscv-pac", +] + +[[package]] +name = "riscv-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f265be5d634272320a7de94cea15c22a3bfdd4eb42eb43edc528415f066a1f25" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "riscv-pac" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8188909339ccc0c68cfb5a04648313f09621e8b87dc03095454f1a11f6c5d436" + +[[package]] +name = "riscv-rt-macros" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc71814687c45ba4cd1e47a54e03a2dbc62ca3667098fbae9cc6b423956758fa" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "rustversion" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "semihosting" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e1c7d2b77d80283c750a39c52f1ab4d17234e8f30bca43550f5b2375f41d5f" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "strum" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f64def088c51c9510a8579e3c5d67c65349dcf755e5479ad3d010aa6454e2c32" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "typenum" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" + +[[package]] +name = "u8g2-fonts" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e4bdc43a7fb3720ece9ba4405b57db4fc479ad6af6b57090f6ff4c040f5d54b" +dependencies = [ + "embedded-graphics-core", +] + +[[package]] +name = "ufmt-write" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69" + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[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.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" +dependencies = [ + "memchr", +] + +[[package]] +name = "xtensa-lx" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68737a6c8f32ddcd97476acf68ddc6d411697fd94f64a601af16854b74967dff" +dependencies = [ + "critical-section", + "document-features", +] + +[[package]] +name = "xtensa-lx-rt" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235815f34d1bf9c2f9c07917e2b63efbcab5ca5ce9d8faddb97b7105eed1ade3" +dependencies = [ + "anyhow", + "document-features", + "enum-as-inner", + "minijinja", + "r0", + "serde", + "strum", + "toml", + "xtensa-lx", + "xtensa-lx-rt-proc-macros", +] + +[[package]] +name = "xtensa-lx-rt-proc-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c1ab67b22f0576b953a25c43bdfed0ff84af2e01ced85e95c29e7bac6bf2180" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..522fdae --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,42 @@ +[package] +edition = "2021" +name = "mtgcount-rs" +version = "0.1.0" + +[[bin]] +name = "mtgcount-rs" +path = "./src/bin/main.rs" + +[dependencies] +critical-section = "1.2.0" +display-interface = "0.5.0" +embedded-graphics = "0.8.1" +embedded-hal = "1.0.0" +embedded-hal-bus = "0.3.0" +esp-alloc = "0.7.0" +esp-backtrace = { version = "0.15.1", features = [ + "esp32", + "exception-handler", + "panic-handler", + "println", +] } +esp-hal = { version = "1.0.0-beta.0", features = ["esp32", "unstable"] } +esp-println = { version = "0.13.0", features = ["esp32"] } +esp32 = "0.38.0" +micromath = "2.1.0" +mipidsi = "0.9.0" +u8g2-fonts = "0.7.1" + +[profile.dev] +# Rust debug is too slow. +# For debug builds always builds with some optimization +opt-level = "s" + +[profile.release] +codegen-units = 1 # LLVM can perform better optimizations using a single thread +debug = 2 +debug-assertions = false +incremental = false +lto = 'fat' +opt-level = 's' +overflow-checks = false diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..d60b515 --- /dev/null +++ b/build.rs @@ -0,0 +1,40 @@ +fn main() { + linker_be_nice(); + // make sure linkall.x is the last linker script (otherwise might cause problems with flip-link) + println!("cargo:rustc-link-arg=-Tlinkall.x"); +} + +fn linker_be_nice() { + let args: Vec = std::env::args().collect(); + if args.len() > 1 { + let kind = &args[1]; + let what = &args[2]; + + match kind.as_str() { + "undefined-symbol" => match what.as_str() { + "_defmt_timestamp" => { + eprintln!(); + eprintln!("💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`"); + eprintln!(); + } + "_stack_start" => { + eprintln!(); + eprintln!("💡 Is the linker script `linkall.x` missing?"); + eprintln!(); + } + _ => (), + }, + // we don't have anything helpful for "missing-lib" yet + _ => { + std::process::exit(1); + } + } + + std::process::exit(0); + } + + println!( + "cargo:rustc-link-arg=-Wl,--error-handling-script={}", + std::env::current_exe().unwrap().display() + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..a2f5ab5 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "esp" diff --git a/src/bin/main.rs b/src/bin/main.rs new file mode 100644 index 0000000..82eae1a --- /dev/null +++ b/src/bin/main.rs @@ -0,0 +1,216 @@ +#![no_std] +#![no_main] + +use embedded_graphics::framebuffer::{buffer_size, Framebuffer}; +use embedded_graphics::pixelcolor::raw::LittleEndian; +use embedded_graphics::pixelcolor::Rgb565; +use embedded_graphics::draw_target::DrawTarget; +use embedded_graphics::image::ImageDrawable; + +use esp_backtrace as _; + +use esp_hal::clock::CpuClock; +use esp_hal::gpio::{self, InputConfig, OutputConfig}; +use esp_hal::rtc_cntl::sleep::{GpioWakeupSource, RtcSleepConfig}; +use esp_hal::rtc_cntl::Rtc; +use esp_hal::main; + +use esp_println::println; + +extern crate alloc; + +use mtgcount_rs::{self, TP_GESTURE, TP_X, TP_Y}; + +#[main] +fn main() -> ! { + // generator version: 0.3.1 + println!("Startup init"); + let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max()); + let peripherals = esp_hal::init(config); + + let pins = mtgcount_rs::init::UsedPins::init(peripherals); + + let mut buffer = [0_u8;256]; + + //set clocks; + + let mut iic = pins.init_iic(); + let mut display = pins.init_display(&mut buffer); + let mut framebuf: Framebuffer(240, 240)}> = Framebuffer::new(); + //let mut bgbuf: Framebuffer(240, 240)}> = Framebuffer::new(); + + + //start bl + println!("Begin backlight setup"); + println!("Start Low Power backlight config"); + let low_power = unsafe {esp_hal::peripherals::LPWR::steal()}; + low_power.register_block().clk_conf().modify(|_,w| w.ck8m_force_pd().clear_bit()); + low_power.register_block().clk_conf().modify(|_,w| w.ck8m_force_pu().set_bit()); + low_power.register_block().clk_conf().modify(|_,w| w.enb_ck8m().clear_bit()); + low_power.register_block().clk_conf().modify(|_,w| w.dig_clk8m_en().set_bit()); + + println!("Init Backlight peripherals"); + let (led, bl, rtcio) = pins.init_backlight(); + + let mux = unsafe{esp_hal::peripherals::IO_MUX::steal()}; + mux.register_block().gpio32().modify(|_,w| w.mcu_oe().set_bit()); + rtcio.register_block().enable().modify(|_,w| unsafe{w.enable().bits(0x80_00_00)}); + rtcio.register_block().xtal_32k_pad().modify(|_,w| w.x32n_hold().clear_bit()); + rtcio.register_block().xtal_32k_pad().modify(|_,w| unsafe{w.x32n_fun_sel().bits(0)}); + rtcio.register_block().xtal_32k_pad().modify(|_,w| w.x32n_slp_oe().set_bit()); + + let _ledc = esp_hal::ledc::Ledc::new(led); + //ledc.set_global_slow_clock(esp_hal::ledc::LSGlobalClkSource::APBClk); + + println!("Set apb_clk_sel"); + let test = unsafe {esp_hal::peripherals::LEDC::steal()}; + test.register_block().conf().write(|w| w.apb_clk_sel().clear_bit()); + test.register_block().lstimer(0).conf().modify(|_,w| w.para_up().set_bit()); + + //let mut lstimer0 = ledc.timer::(esp_hal::ledc::timer::Number::Timer0); + //lstimer0.configure(esp_hal::ledc::timer::config::Config { + // duty: esp_hal::ledc::timer::config::Duty::Duty5Bit, + // clock_source: esp_hal::ledc::timer::LSClockSource::APBClk, + // frequency: Rate::from_khz(2), + //}).unwrap(); + + let precision = 1 << 8u64; + let divisor = ((8_000_000u64) << 8) / 1_000 / precision; + println!("Set up lstimer0"); + println!("Lstimer divisor is:{}", divisor); + + test.register_block().lstimer(0).conf().modify(|_,w| unsafe { + w.tick_sel().bit(true); + w.rst().clear_bit(); + w.pause().clear_bit(); + w.div_num().bits(divisor as u32); + w.duty_res().bits(8) + }); + test.register_block().lstimer(0).conf().modify(|_,w| w.para_up().set_bit()); + + //let mut channel0 = ledc.channel(esp_hal::ledc::channel::Number::Channel0, bl); + //channel0.configure(esp_hal::ledc::channel::config::Config { + // timer: &lstimer0, + // duty_pct: 50, + // pin_config: esp_hal::ledc::channel::config::PinConfig::PushPull, + //}).unwrap(); + + let mut duty_percent = 100; + let duty_range = 2u32.pow(8); + let mut duty_value = (duty_range * duty_percent) / 100; + println!("Setup channel0"); + + test.register_block().lsch(0).duty().write(|w| unsafe { + w.duty().bits(duty_value<<4) + }); + test.register_block().lsch(0).conf1().write(|w| unsafe { + w.duty_start().set_bit(); + w.duty_inc().set_bit(); + w.duty_num().bits(0x1); + w.duty_cycle().bits(0x1); + w.duty_scale().bits(0x0) + }); + test.register_block().lsch(0).conf0().modify(|_,w| w.para_up().set_bit()); + + println!("Configure output signal"); + let newbl: esp_hal::gpio::interconnect::OutputSignal = bl.into(); + println!("line1"); + newbl.apply_output_config(&OutputConfig::default().with_drive_mode(gpio::DriveMode::PushPull)); + println!("line2"); + newbl.set_output_enable(true); + println!("Completed output signal config"); + + test.register_block().lsch(0).hpoint().write(|w| unsafe { + w.hpoint().bits(0x0) + }); + println!("Completed hpoint set"); + + test.register_block().lsch(0).conf0().modify(|_,w| unsafe { + w.sig_out_en().set_bit().timer_sel().bits(0) + }); + println!("Completed signal output enable"); + test.register_block().lsch(0).conf1().write(|w| unsafe { + w.duty_start().set_bit(); + w.duty_inc().set_bit(); + w.duty_num().bits(0x1); + w.duty_cycle().bits(0x1); + w.duty_scale().bits(0x0) + }); + test.register_block().lsch(0).conf0().modify(|_,w| w.para_up().set_bit()); + println!("Completed channel0 reupdate"); + + let signal = esp_hal::gpio::OutputSignal::LEDC_LS_SIG0; + signal.connect_to(&newbl); + println!("End Backlight setup"); + //end bl + + let mut read_buffer = [0_u8;1]; + + esp_alloc::heap_allocator!(size: 16 * 1024); + + let pinconf = InputConfig::default(); + let irq = pins.irq(); + let _wake_pin = esp_hal::gpio::Input::new(irq, pinconf).wakeup_enable(true,esp_hal::gpio::WakeEvent::LowLevel).unwrap(); + + let waker = GpioWakeupSource::new(); + println!("Start Sleep Config setup"); + let mut rtc_control = Rtc::new(low_power); + println!("line1"); + let mut rtc_config: RtcSleepConfig = RtcSleepConfig::default(); + println!("line2"); + rtc_config.set_int_8m_pd_en(false); + println!("Finish Sleep Config setup"); + + //let loop_delay = esp_hal::delay::Delay::new(); + + let mut gesture; + let mut x; + let mut y; + + println!("Systemstate init"); + let mut state = mtgcount_rs::state::SystemState::new(); + println!("screen: {:?}", state.screen); + + framebuf.clear(state.settings.color_scheme.get_color(&mtgcount_rs::display::ColorType::Background)).unwrap(); + display.clear(state.settings.color_scheme.get_color(&mtgcount_rs::display::ColorType::Background)).unwrap(); + mtgcount_rs::display::draw_screen(&state, &mut framebuf); + framebuf.as_image().draw(&mut display).unwrap(); + + loop { + //println!("Enterd Loop"); + iic.write_read(0x15, &[TP_GESTURE], &mut read_buffer).expect("Failed to do iic"); + gesture = read_buffer[0]; + iic.write_read(0x15, &[TP_X], &mut read_buffer).expect("Failed to do iic"); + x = read_buffer[0]; + iic.write_read(0x15, &[TP_Y], &mut read_buffer).expect("Failed to do iic"); + y = read_buffer[0]; + + mtgcount_rs::touch::get_touch_action(x as f32, y as f32, gesture, &mut state); + + duty_percent = state.settings.brightness as u32; + duty_value = (duty_range * duty_percent) / 100; + + //println!("Duty Percent: {}%", duty_percent); + + test.register_block().lsch(0).duty().write(|w| unsafe {w.duty().bits(duty_value<<4)}); + + test.register_block().lsch(0).conf1().write(|w| unsafe { + w.duty_start().set_bit(); + w.duty_inc().set_bit(); + w.duty_num().bits(0x1); + w.duty_cycle().bits(0x1); + w.duty_scale().bits(0x0) + }); + + test.register_block().lsch(0).conf0().modify(|_,w| w.para_up().set_bit()); + + mtgcount_rs::display::draw_screen(&state, &mut framebuf); + framebuf.as_image().draw(&mut display).unwrap(); + + framebuf.clear(state.settings.color_scheme.get_color(&mtgcount_rs::display::ColorType::Background)).unwrap(); + + rtc_control.sleep(&rtc_config,&[&waker]); + + } + // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-beta.0/examples/src/bin +} \ No newline at end of file diff --git a/src/bin/mini_ulp.s b/src/bin/mini_ulp.s new file mode 100644 index 0000000..fef9272 --- /dev/null +++ b/src/bin/mini_ulp.s @@ -0,0 +1,205 @@ + REG_WR 0x103, 0x17, 0x17, 1 + REG_WR 0x123, 0x18, 0x18, 0 + REG_WR 0x123, 0x11, 0x11, 1 + REG_WR 0x123, 0x06, 0x06, 1 +entry: + MOVE R0, dutycycle //6 + LD R0, R0, 0 //8 + LSH R1, R0, 4 //6 + ADD R0, R0, R1 //6 + ADD R0, R0, 10 //6 + JUMP R0 //4 + //36 +0x0a: + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 12 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 717 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 12 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 717 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 12 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 717 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 12 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 677 //6 + JUMP entry //4 +0x22: + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 84 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 645 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 84 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 645 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 84 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 645 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 84 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 605 //6 + JUMP entry //4 +0x3a: + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 156 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 573 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 156 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 573 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 156 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 573 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 156 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 533 //6 + JUMP entry //4 +0x52: + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 228 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 501 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 228 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 501 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 228 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 501 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 228 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 461 //6 + JUMP entry //4 +0x6a: + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 300 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 429 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 300 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 429 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 300 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 429 //6 + REG_WR 0x101, 0x17, 0x17, 1 //12 + WAIT 300 //6 + REG_WR 0x102, 0x17, 0x17, 1 //12 + WAIT 389 //6 + JUMP entry //4 +0x82: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 357 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 372 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 357 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 372 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 357 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 372 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 357 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 332 + JUMP entry +0x9a: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 285 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 444 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 285 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 444 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 285 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 444 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 285 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 404 + JUMP entry +0xb2: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 213 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 516 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 213 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 516 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 213 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 516 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 213 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 476 + JUMP entry +0xca: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 141 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 606 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 141 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 606 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 141 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 606 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 141 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 566 + JUMP entry +0xe2: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 69 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 660 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 69 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 660 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 69 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 660 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 69 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 620 + JUMP entry +0xfa: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 12 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1482 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 12 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1442 + JUMP entry + +dutycycle: + .long 0 \ No newline at end of file diff --git a/src/bin/ulp_program.s b/src/bin/ulp_program.s new file mode 100644 index 0000000..33f65b1 --- /dev/null +++ b/src/bin/ulp_program.s @@ -0,0 +1,1551 @@ + REG_WR 0x103, 0x17, 0x17, 1 + REG_WR 0x123, 0x18, 0x18, 0 + REG_WR 0x123, 0x11, 0x11, 1 + REG_WR 0x123, 0x06, 0x06, 1 +entry: + MOVE R0, dutycycle //6 + LD R0, R0, 0 //8 + LSH R1, R0, 2 //6 + ADD R0, R0, R1 //6 + ADD R0, R0, 10 //6 + JUMP R0 //4 + //36 +0x00: + REG_WR 0x102, 0x17, 0x17, 1 //12 + NOP //6 + NOP //6 + WAIT 2990 //6+2990 + JUMP entry //4 +0x01: + REG_WR 0x101, 0x17, 0x17, 1 //12 + REG_WR 0x102, 0x17, 0x17, 1 //12 + NOP //6 + WAIT 2984 //6+2984 + JUMP entry //4 +0x02: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 6 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2978 + JUMP entry +0x03: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 18 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2966 + JUMP entry +0x04: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 30 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2954 + JUMP entry +0x05: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 42 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2942 + JUMP entry +0x06: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 54 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2930 + JUMP entry +0x07: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 66 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2918 + JUMP entry +0x08: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 78 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2906 + JUMP entry +0x09: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 90 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2894 + JUMP entry +0x0a: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 102 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2882 + JUMP entry +0x0b: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 114 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2870 + JUMP entry +0x0c: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 126 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2858 + JUMP entry +0x0d: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 138 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2846 + JUMP entry +0x0e: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 150 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2834 + JUMP entry +0x0f: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 162 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2822 + JUMP entry +0x10: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 174 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2810 + JUMP entry +0x11: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 186 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2798 + JUMP entry +0x12: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 198 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2786 + JUMP entry +0x13: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 210 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2774 + JUMP entry +0x14: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 222 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2762 + JUMP entry +0x15: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 234 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2750 + JUMP entry +0x16: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 246 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2738 + JUMP entry +0x17: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 258 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2726 + JUMP entry +0x18: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 270 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2714 + JUMP entry +0x19: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 282 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2702 + JUMP entry +0x1a: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 294 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2690 + JUMP entry +0x1b: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 306 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2678 + JUMP entry +0x1c: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 318 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2666 + JUMP entry +0x1d: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 330 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2654 + JUMP entry +0x1e: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 342 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2642 + JUMP entry +0x1f: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 354 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2630 + JUMP entry +0x20: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 366 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2618 + JUMP entry +0x21: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 378 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2606 + JUMP entry +0x22: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 390 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2594 + JUMP entry +0x23: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 402 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2582 + JUMP entry +0x24: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 414 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2570 + JUMP entry +0x25: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 426 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2558 + JUMP entry +0x26: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 438 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2546 + JUMP entry +0x27: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 450 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2534 + JUMP entry +0x28: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 462 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2522 + JUMP entry +0x29: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 474 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2510 + JUMP entry +0x2a: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 486 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2498 + JUMP entry +0x2b: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 498 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2486 + JUMP entry +0x2c: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 510 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2474 + JUMP entry +0x2d: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 522 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2462 + JUMP entry +0x2e: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 534 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2450 + JUMP entry +0x2f: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 546 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2438 + JUMP entry +0x30: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 558 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2426 + JUMP entry +0x31: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 570 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2414 + JUMP entry +0x32: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 582 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2402 + JUMP entry +0x33: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 594 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2390 + JUMP entry +0x34: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 606 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2378 + JUMP entry +0x35: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 618 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2366 + JUMP entry +0x36: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 630 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2354 + JUMP entry +0x37: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 642 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2342 + JUMP entry +0x38: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 654 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2330 + JUMP entry +0x39: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 666 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2318 + JUMP entry +0x3a: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 678 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2306 + JUMP entry +0x3b: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 690 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2294 + JUMP entry +0x3c: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 702 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2282 + JUMP entry +0x3d: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 714 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2270 + JUMP entry +0x3e: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 726 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2258 + JUMP entry +0x3f: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 738 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2246 + JUMP entry +0x40: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 750 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2234 + JUMP entry +0x41: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 762 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2222 + JUMP entry +0x42: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 774 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2210 + JUMP entry +0x43: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 786 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2198 + JUMP entry +0x44: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 798 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2186 + JUMP entry +0x45: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 810 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2174 + JUMP entry +0x46: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 822 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2162 + JUMP entry +0x47: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 834 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2150 + JUMP entry +0x48: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 846 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2138 + JUMP entry +0x49: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 858 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2126 + JUMP entry +0x4a: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 870 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2114 + JUMP entry +0x4b: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 882 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2102 + JUMP entry +0x4c: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 894 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2090 + JUMP entry +0x4d: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 906 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2078 + JUMP entry +0x4e: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 918 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2066 + JUMP entry +0x4f: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 930 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2054 + JUMP entry +0x50: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 942 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2042 + JUMP entry +0x51: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 954 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2030 + JUMP entry +0x52: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 966 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2018 + JUMP entry +0x53: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 978 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 2006 + JUMP entry +0x54: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 990 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1994 + JUMP entry +0x55: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1002 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1982 + JUMP entry +0x56: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1014 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1970 + JUMP entry +0x57: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1026 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1958 + JUMP entry +0x58: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1038 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1946 + JUMP entry +0x59: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1050 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1934 + JUMP entry +0x5a: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1062 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1922 + JUMP entry +0x5b: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1074 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1910 + JUMP entry +0x5c: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1086 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1898 + JUMP entry +0x5d: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1098 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1886 + JUMP entry +0x5e: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1110 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1874 + JUMP entry +0x5f: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1122 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1862 + JUMP entry +0x60: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1134 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1850 + JUMP entry +0x61: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1146 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1838 + JUMP entry +0x62: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1158 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1826 + JUMP entry +0x63: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1170 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1814 + JUMP entry +0x64: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1182 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1802 + JUMP entry +0x65: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1194 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1790 + JUMP entry +0x66: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1206 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1778 + JUMP entry +0x67: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1218 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1766 + JUMP entry +0x68: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1230 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1754 + JUMP entry +0x69: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1242 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1742 + JUMP entry +0x6a: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1254 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1730 + JUMP entry +0x6b: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1266 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1718 + JUMP entry +0x6c: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1278 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1706 + JUMP entry +0x6d: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1290 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1694 + JUMP entry +0x6e: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1302 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1682 + JUMP entry +0x6f: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1314 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1670 + JUMP entry +0x70: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1326 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1658 + JUMP entry +0x71: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1338 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1646 + JUMP entry +0x72: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1350 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1634 + JUMP entry +0x73: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1362 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1622 + JUMP entry +0x74: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1374 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1610 + JUMP entry +0x75: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1386 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1598 + JUMP entry +0x76: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1398 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1586 + JUMP entry +0x77: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1410 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1574 + JUMP entry +0x78: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1422 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1562 + JUMP entry +0x79: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1434 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1550 + JUMP entry +0x7a: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1446 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1538 + JUMP entry +0x7b: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1458 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1526 + JUMP entry +0x7c: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1470 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1514 + JUMP entry +0x7d: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1482 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1502 + JUMP entry +0x7e: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1494 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1490 + JUMP entry +0x7f: + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1506 + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1478 + JUMP entry +0x80: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1506 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1478 + JUMP entry +0x81: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1494 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1490 + JUMP entry +0x82: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1482 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1502 + JUMP entry +0x83: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1470 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1514 + JUMP entry +0x84: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1458 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1526 + JUMP entry +0x85: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1446 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1538 + JUMP entry +0x86: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1434 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1550 + JUMP entry +0x87: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1422 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1562 + JUMP entry +0x88: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1410 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1574 + JUMP entry +0x89: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1398 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1586 + JUMP entry +0x8a: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1386 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1598 + JUMP entry +0x8b: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1374 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1610 + JUMP entry +0x8c: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1362 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1622 + JUMP entry +0x8d: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1350 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1634 + JUMP entry +0x8e: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1338 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1646 + JUMP entry +0x8f: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1326 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1658 + JUMP entry +0x90: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1314 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1670 + JUMP entry +0x91: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1302 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1682 + JUMP entry +0x92: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1290 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1694 + JUMP entry +0x93: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1278 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1706 + JUMP entry +0x94: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1266 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1718 + JUMP entry +0x95: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1254 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1730 + JUMP entry +0x96: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1242 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1742 + JUMP entry +0x97: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1230 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1754 + JUMP entry +0x98: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1218 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1766 + JUMP entry +0x99: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1206 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1778 + JUMP entry +0x9a: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1194 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1790 + JUMP entry +0x9b: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1182 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1802 + JUMP entry +0x9c: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1170 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1814 + JUMP entry +0x9d: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1158 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1826 + JUMP entry +0x9e: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1146 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1838 + JUMP entry +0x9f: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1134 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1850 + JUMP entry +0xa0: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1122 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1862 + JUMP entry +0xa1: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1110 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1874 + JUMP entry +0xa2: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1098 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1886 + JUMP entry +0xa3: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1086 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1898 + JUMP entry +0xa4: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1074 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1910 + JUMP entry +0xa5: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1062 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1922 + JUMP entry +0xa6: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1050 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1934 + JUMP entry +0xa7: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1038 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1946 + JUMP entry +0xa8: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1026 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1958 + JUMP entry +0xa9: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1014 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1970 + JUMP entry +0xaa: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 1002 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1982 + JUMP entry +0xab: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 990 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 1994 + JUMP entry +0xac: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 978 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2006 + JUMP entry +0xad: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 966 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2018 + JUMP entry +0xae: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 954 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2030 + JUMP entry +0xaf: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 942 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2042 + JUMP entry +0xb0: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 930 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2054 + JUMP entry +0xb1: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 918 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2066 + JUMP entry +0xb2: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 906 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2078 + JUMP entry +0xb3: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 894 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2090 + JUMP entry +0xb4: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 882 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2102 + JUMP entry +0xb5: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 870 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2114 + JUMP entry +0xb6: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 858 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2126 + JUMP entry +0xb7: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 846 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2138 + JUMP entry +0xb8: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 834 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2150 + JUMP entry +0xb9: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 822 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2162 + JUMP entry +0xba: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 810 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2174 + JUMP entry +0xbb: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 798 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2186 + JUMP entry +0xbc: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 786 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2198 + JUMP entry +0xbd: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 774 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2210 + JUMP entry +0xbe: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 762 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2222 + JUMP entry +0xbf: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 750 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2234 + JUMP entry +0xc0: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 738 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2246 + JUMP entry +0xc1: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 726 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2258 + JUMP entry +0xc2: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 714 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2270 + JUMP entry +0xc3: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 702 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2282 + JUMP entry +0xc4: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 690 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2294 + JUMP entry +0xc5: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 678 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2306 + JUMP entry +0xc6: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 666 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2318 + JUMP entry +0xc7: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 654 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2330 + JUMP entry +0xc8: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 642 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2342 + JUMP entry +0xc9: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 630 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2354 + JUMP entry +0xca: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 618 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2366 + JUMP entry +0xcb: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 606 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2378 + JUMP entry +0xcc: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 594 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2390 + JUMP entry +0xcd: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 582 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2402 + JUMP entry +0xce: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 570 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2414 + JUMP entry +0xcf: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 558 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2426 + JUMP entry +0xd0: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 546 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2438 + JUMP entry +0xd1: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 534 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2450 + JUMP entry +0xd2: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 522 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2462 + JUMP entry +0xd3: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 510 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2474 + JUMP entry +0xd4: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 498 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2486 + JUMP entry +0xd5: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 486 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2498 + JUMP entry +0xd6: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 474 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2510 + JUMP entry +0xd7: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 462 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2522 + JUMP entry +0xd8: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 450 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2534 + JUMP entry +0xd9: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 438 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2546 + JUMP entry +0xda: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 426 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2558 + JUMP entry +0xdb: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 414 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2570 + JUMP entry +0xdc: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 402 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2582 + JUMP entry +0xdd: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 390 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2594 + JUMP entry +0xde: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 378 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2606 + JUMP entry +0xdf: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 366 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2618 + JUMP entry +0xe0: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 354 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2630 + JUMP entry +0xe1: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 342 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2642 + JUMP entry +0xe2: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 330 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2654 + JUMP entry +0xe3: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 318 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2666 + JUMP entry +0xe4: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 306 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2678 + JUMP entry +0xe5: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 294 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2690 + JUMP entry +0xe6: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 282 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2702 + JUMP entry +0xe7: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 270 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2714 + JUMP entry +0xe8: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 258 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2726 + JUMP entry +0xe9: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 246 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2738 + JUMP entry +0xea: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 234 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2750 + JUMP entry +0xeb: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 222 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2762 + JUMP entry +0xec: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 210 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2774 + JUMP entry +0xed: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 198 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2786 + JUMP entry +0xee: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 186 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2798 + JUMP entry +0xef: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 174 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2810 + JUMP entry +0xf0: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 162 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2822 + JUMP entry +0xf1: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 150 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2834 + JUMP entry +0xf2: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 138 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2846 + JUMP entry +0xf3: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 126 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2858 + JUMP entry +0xf4: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 114 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2870 + JUMP entry +0xf5: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 102 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2882 + JUMP entry +0xf6: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 90 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2894 + JUMP entry +0xf7: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 78 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2906 + JUMP entry +0xf8: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 66 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2918 + JUMP entry +0xf9: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 54 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2930 + JUMP entry +0xfa: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 42 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2942 + JUMP entry +0xfb: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 30 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2954 + JUMP entry +0xfc: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 18 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2966 + JUMP entry +0xfd: + REG_WR 0x102, 0x17, 0x17, 1 + WAIT 6 + REG_WR 0x101, 0x17, 0x17, 1 + WAIT 2978 + JUMP entry +0xfe: + REG_WR 0x102, 0x17, 0x17, 1 //12 + REG_WR 0x101, 0x17, 0x17, 1 //12 + NOP //6 + WAIT 2984 //6+2984 + JUMP entry //4 +0xff: + REG_WR 0x101, 0x17, 0x17, 1 //12 + NOP //6 + NOP //6 + WAIT 2990 //6+2990 + JUMP entry //4 + +dutycycle: + .long 0 \ No newline at end of file diff --git a/src/display.rs b/src/display.rs new file mode 100644 index 0000000..fe2d46d --- /dev/null +++ b/src/display.rs @@ -0,0 +1,447 @@ +use embedded_graphics::prelude::{Angle, DrawTarget, Point, Primitive, RgbColor}; +use embedded_graphics::pixelcolor::Rgb565; +use embedded_graphics::Drawable; + +use u8g2_fonts::{fonts::{u8g2_font_7x13_tr, u8g2_font_9x15B_tr, u8g2_font_logisoso24_tr, u8g2_font_logisoso42_tr, u8g2_font_open_iconic_all_2x_t, u8g2_font_open_iconic_check_4x_t}, FontRenderer}; + +use micromath::F32Ext; + +extern crate alloc; +use alloc::{vec::Vec, string::ToString}; +use embedded_graphics::primitives::PrimitiveStyle; + +use crate::state::{MainScreenItem, Screen, SystemState}; +use crate::setting_screen::{setting_screen, setting_scroll}; + +pub const LARGE_FONT:FontRenderer = FontRenderer::new::(); +pub const MED_PLUS_FONT:FontRenderer = FontRenderer::new::(); +pub const MED_FONT:FontRenderer = FontRenderer::new::(); +pub const SMALL_FONT:FontRenderer = FontRenderer::new::(); +pub const ICONS:FontRenderer = FontRenderer::new::(); +pub const CHECK:FontRenderer = FontRenderer::new::(); + +const LIGHTCREAM: Rgb565 = Rgb565::new(31, 62, 26); +const LIGHTBLUE: Rgb565 = Rgb565::new(21, 55, 30); +const DARKBLUE: Rgb565 = Rgb565::new(1, 27, 22); +const LIGHTGREY: Rgb565 = Rgb565::new(25, 48, 23); +const DARKGREY: Rgb565 = Rgb565::new(8, 16, 8); +const LIGHTRED: Rgb565 = Rgb565::new(30, 42, 17); +const LIGHTGREEN: Rgb565 = Rgb565::new(19,52,21); + + +const ALMOSTBLACK: Rgb565 = Rgb565::new(3, 6, 3); + + + + +const CENTER: Point = Point::new(120, 120); + +#[derive(Debug,Clone, Copy)] +pub enum ColorType { + Primary, + Secondary, + Tertiary, + Background +} + +#[derive(Debug,Clone, Copy)] +pub enum ColorScheme { + Light, + Dark, + White, + Blue, + Black, + Red, + Green, + Azorius, + Dimir, +} + +impl ColorScheme { + pub fn get_color(&self, color_type: &ColorType) -> Rgb565 { + match self { + Self::Light => { + match color_type { + ColorType::Primary => Rgb565::BLACK, + ColorType::Secondary => Rgb565::BLACK, + ColorType::Tertiary => Rgb565::BLACK, + ColorType::Background => Rgb565::WHITE, + } + }, + Self::Dark => { + match color_type { + ColorType::Primary => Rgb565::WHITE, + ColorType::Secondary => ALMOSTBLACK, + ColorType::Tertiary => Rgb565::WHITE, + ColorType::Background => Rgb565::BLACK, + } + }, + Self::White => { + match color_type { + ColorType::Primary => Rgb565::BLACK, + ColorType::Secondary => Rgb565::BLACK, + ColorType::Tertiary => Rgb565::BLACK, + ColorType::Background => LIGHTCREAM, + } + }, + Self::Blue => { + match color_type { + ColorType::Primary => Rgb565::BLACK, + ColorType::Secondary => DARKBLUE, + ColorType::Tertiary => Rgb565::BLACK, + ColorType::Background => LIGHTBLUE + } + }, + Self::Black => { + match color_type { + ColorType::Primary => Rgb565::BLACK, + ColorType::Secondary => Rgb565::BLACK, + ColorType::Tertiary => Rgb565::BLACK, + ColorType::Background => LIGHTGREY, + } + }, + Self::Red => { + match color_type { + ColorType::Primary => Rgb565::BLACK, + ColorType::Secondary => Rgb565::BLACK, + ColorType::Tertiary => Rgb565::BLACK, + ColorType::Background => LIGHTRED, + } + }, + Self::Green => { + match color_type { + ColorType::Primary => Rgb565::BLACK, + ColorType::Secondary => Rgb565::BLACK, + ColorType::Tertiary => Rgb565::BLACK, + ColorType::Background => LIGHTGREEN, + } + }, + Self::Azorius => { + match color_type { + ColorType::Primary => DARKBLUE, + ColorType::Secondary => DARKBLUE, + ColorType::Tertiary => DARKBLUE, + ColorType::Background => LIGHTCREAM, + } + }, + Self::Dimir => { + match color_type { + ColorType::Primary => DARKGREY, + ColorType::Secondary => DARKGREY, + ColorType::Tertiary => DARKGREY, + ColorType::Background => LIGHTBLUE, + } + }, + } + } + + pub(crate) fn as_str(&self) -> &'static str { + match self { + ColorScheme::Light => "Light", + ColorScheme::Dark => "Dark", + ColorScheme::White => "White", + ColorScheme::Blue => "Blue", + ColorScheme::Black => "Black", + ColorScheme::Red => "Red", + ColorScheme::Green => "Green", + ColorScheme::Azorius => "Azorius", + ColorScheme::Dimir => "Dmir", + } + } + + pub fn inc(self) -> Self { + let mut tmp:u8 = self.into(); + tmp += 1; + if tmp > 8 { + tmp = 0 + } + Self::from(tmp) + } + + pub fn dec(self) -> Self { + let tmp:u8 = self.into(); + let tmp = tmp.checked_sub(1); + let tmp = match tmp { + Some(u) => u, + None => 8, + }; + Self::from(tmp) + } +} + +pub const COLORSCHEMES: usize = 9; + +impl From for ColorScheme { + + fn from(value: u8) -> Self { + match value { + 1 => Self::Dark, + 2 => Self::White, + 3 => Self::Blue, + 4 => Self::Black, + 5 => Self::Red, + 6 => Self::Green, + 7 => Self::Azorius, + 8 => Self::Dimir, + _ => Self::Light, + } + } +} + +impl Into for ColorScheme { + fn into(self) -> u8 { + match self { + ColorScheme::Light => 0, + ColorScheme::Dark => 1, + ColorScheme::White => 2, + ColorScheme::Blue => 3, + ColorScheme::Black => 4, + ColorScheme::Red => 5, + ColorScheme::Green => 6, + ColorScheme::Azorius => 7, + ColorScheme::Dimir => 8, + } + } +} + +pub fn draw_screen>(ctx: &SystemState, target: &mut A) -> () { + + let primary = ctx.settings.color_scheme.get_color(&ColorType::Primary); + let background = ctx.settings.color_scheme.get_color(&ColorType::Background); + + _ = target.clear(background); + + match &ctx.screen { + Screen::Main(selection) => { + + let style = PrimitiveStyle::with_stroke(ctx.settings.color_scheme.get_color(&ColorType::Secondary), 3); + + let bottom_count = + ctx.settings.show_cmd_tax as u8 + + ctx.settings.show_energy as u8 + + ctx.settings.show_experience as u8 + + ctx.settings.show_infect as u8 + + ctx.settings.show_tickets as u8; + + if (ctx.settings.opponenets > 0) & (ctx.settings.opponenets < 7) { + let top_positions = ctx.positions.get_top_list(ctx.settings.opponenets); + + for (pos, dmg) in top_positions.iter().zip(ctx.game.cmd_dmg) { + + _ = SMALL_FONT.render_aligned( + dmg.as_string_horizontal().as_str(), + pos.position, + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + } + + let start = (ctx.settings.opponenets as f32 * 15.)-90.; + let sweep = ctx.settings.opponenets as f32 * -30.; + let arc = embedded_graphics::primitives::Arc::with_center(CENTER, 160, Angle::from_degrees(start), Angle::from_degrees(sweep)); + + //println!("start: {}", start); + + let _ = arc.into_styled(style).draw(target); + + for i in 0..= ctx.settings.opponenets { + let angle = (start + 90. - (30.*(i as f32))) * crate::DEG_TO_RAD; + let (sin_t, cos_t) = angle.sin_cos(); + //println!("angle: {}, sin: {}, cos: {}", angle, sin_t, cos_t); + + let line1 = Point::new( + ((79. * sin_t)+120.) as i32, + ((-79. * cos_t)+120.) as i32 + ); + let line2 = Point::new( + ((125. * sin_t)+120.) as i32, + ((-125. * cos_t)+120.) as i32 + ); + + let drawline = embedded_graphics::primitives::Line::new(line1, line2); + + //println!("{:?}", drawline); + let _ = drawline.into_styled(style).draw(target); + + } + } + + if bottom_count != 0 { + let bottom_positions = ctx.positions.get_bottom_list(bottom_count); + + let mut bottom_vec = Vec::with_capacity(bottom_count as usize); + + if ctx.settings.show_cmd_tax { + let tmp = ctx.game.cmd_tax.as_string_horizontal(); + bottom_vec.push((tmp, '\u{0092}')); + } + if ctx.settings.show_energy { + let tmp = ctx.game.energy.to_string(); + bottom_vec.push((tmp,'\u{0060}')); + } + if ctx.settings.show_experience { + let tmp = ctx.game.experience.to_string(); + bottom_vec.push((tmp,'\u{0103}')); + } + if ctx.settings.show_tickets { + let tmp = ctx.game.tickets.to_string(); + bottom_vec.push((tmp, '\u{0106}')); + } + if ctx.settings.show_infect { + let tmp = ctx.game.infect.to_string(); + bottom_vec.push((tmp,'\u{005c}')); + } + + for (pos, content) in bottom_positions.iter().zip(bottom_vec) { + + _ = SMALL_FONT.render_aligned( + content.0.as_str(), + pos.position, + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target); + + _ = ICONS.render_aligned( + content.1, + pos.position, + u8g2_fonts::types::VerticalPosition::Top, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target); + } + + let start = (bottom_count as f32 * 15.)+90.; + let sweep = bottom_count as f32 * -30.; + let arc = embedded_graphics::primitives::Arc::with_center(CENTER, 160, Angle::from_degrees(start), Angle::from_degrees(sweep)); + let _ = arc.into_styled(style).draw(target); + + for i in 0..=bottom_count { + let angle = (start + 90. - (30.*(i as f32))) * crate::DEG_TO_RAD; + let (sin_t, cos_t) = angle.sin_cos(); + //println!("angle: {}, sin: {}, cos: {}", angle, sin_t, cos_t); + + let line1 = Point::new( + ((79. * sin_t)+120.) as i32, + ((-79. * cos_t)+120.) as i32 + ); + let line2 = Point::new( + ((125. * sin_t)+120.) as i32, + ((-125. * cos_t)+120.) as i32 + ); + + let drawline = embedded_graphics::primitives::Line::new(line1, line2); + + //println!("{:?}", drawline); + let _ = drawline.into_styled(style).draw(target); + } + } + + let center_item = match selection { + MainScreenItem::Dmg1 => (ctx.game.cmd_dmg[0].as_string_horizontal(),"Opponent 1"), + MainScreenItem::Dmg2 => (ctx.game.cmd_dmg[1].as_string_horizontal(),"Opponent 2"), + MainScreenItem::Dmg3 => (ctx.game.cmd_dmg[2].as_string_horizontal(),"Opponent 3"), + MainScreenItem::Dmg4 => (ctx.game.cmd_dmg[3].as_string_horizontal(),"Opponent 4"), + MainScreenItem::Dmg5 => (ctx.game.cmd_dmg[4].as_string_horizontal(),"Opponent 5"), + MainScreenItem::Dmg6 => (ctx.game.cmd_dmg[5].as_string_horizontal(),"Opponent 6"), + MainScreenItem::Tax => (ctx.game.cmd_tax.as_string_horizontal(),"Commander Tax"), + MainScreenItem::Energy => (ctx.game.energy.to_string(),"Energy"), + MainScreenItem::Experience => (ctx.game.experience.to_string(),"Experience"), + MainScreenItem::Tickets => (ctx.game.tickets.to_string(),"Tickets"), + MainScreenItem::Poison => (ctx.game.infect.to_string(),"Poison"), + _ => (ctx.game.life.to_string(),"Life"), + }; + + let _ = LARGE_FONT.render_aligned( + center_item.0.as_str(), + ctx.positions.center, + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + + let _ = SMALL_FONT.render_aligned( + center_item.1, + Point::new(120, 150), + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + + let content = match selection { + MainScreenItem::Dmg1 => Some(0), + MainScreenItem::Dmg2 => Some(1), + MainScreenItem::Dmg3 => Some(2), + MainScreenItem::Dmg4 => Some(3), + MainScreenItem::Dmg5 => Some(4), + MainScreenItem::Dmg6 => Some(5), + _ => None, + }; + + if let Some(pos) = content { + let content = if ctx.game.cmd_dmg[pos].is_partner { + "0" + } else { + "0|0" + }; + + let _ = SMALL_FONT.render_aligned( + content, + Point { x: 120, y: 170 }, + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + } else if *selection == MainScreenItem::Tax { + let content = if ctx.game.cmd_tax.is_partner { + "0" + } else { + "0|0" + }; + + let _ = SMALL_FONT.render_aligned( + content, + Point { x: 120, y: 170 }, + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + } + } + Screen::Settings(selection) => { + setting_scroll(ctx, selection, target); + } + } +} + + + +/* +opponents 1-6 + +life total + +tax +energy +experience +tix +poison + +opponents +starting life +new game +colors +brightness + +show tax +show energy +show experience +show tickets +show poison +*/ \ No newline at end of file diff --git a/src/init.rs b/src/init.rs new file mode 100644 index 0000000..1b85088 --- /dev/null +++ b/src/init.rs @@ -0,0 +1,115 @@ +use core::cell::Cell; +use embedded_hal_bus::spi::ExclusiveDevice; +use esp_hal::{delay::Delay, gpio::Output, i2c::master::I2c, peripherals::*, spi::master::Spi, time::Rate, Blocking}; +use mipidsi::{interface::SpiInterface, models::GC9A01}; + +pub struct UsedPins<'a> { + sda: Cell>>, + scl: Cell>>, + irq: Cell>>, + tp_rst: Cell>>, + + sclk: Cell>>, + mosi: Cell>>, + cs: Cell>>, + dc: Cell>>, + reset: Cell>>, + bl: Cell>>, + + iic: Cell>>, + spi: Cell>>, + lpwr: Cell>>, + ledc: Cell>>, + //dport: Cell>>, + io_mux: Cell>>, + //rtc_io: Cell>>, +} + +impl<'a> UsedPins<'a> { + + pub fn init(peripherals: esp_hal::peripherals::Peripherals) -> Self { + + UsedPins { + sda: Cell::new(Some(peripherals.GPIO21)), + scl: Cell::new(Some(peripherals.GPIO22)), + irq: Cell::new(Some(peripherals.GPIO19)), + tp_rst: Cell::new(Some(peripherals.GPIO4)), + + sclk: Cell::new(Some(peripherals.GPIO14)), + mosi: Cell::new(Some(peripherals.GPIO15)), + cs: Cell::new(Some(peripherals.GPIO5)), + dc: Cell::new(Some(peripherals.GPIO27)), + reset: Cell::new(Some(peripherals.GPIO33)), + bl: Cell::new(Some(peripherals.GPIO32)), + + iic: Cell::new(Some(peripherals.I2C0)), + spi: Cell::new(Some(peripherals.SPI2)), + lpwr: Cell::new(Some(peripherals.LPWR)), + + ledc: Cell::new(Some(peripherals.LEDC)), + //dport: Cell::new(Some(peripherals.DPORT)), + io_mux: Cell::new(Some(peripherals.RTC_IO)), + //rtc_io: Cell::new(Some(peripherals.LPWR)), + } + } + + pub fn irq(&self) -> GPIO19 { + let irq = self.irq.replace(None).unwrap(); + irq + } + + pub fn tp_rst(&self) -> GPIO4 { + let tp_rst = self.tp_rst.replace(None).unwrap(); + tp_rst + } + + pub fn get_lpwr(&self) -> LPWR<'a> { + let pin = self.lpwr.replace(None).unwrap(); + pin + } + + pub fn init_backlight(&self) -> (LEDC<'a>, GPIO32<'a>, RTC_IO<'a>) { + let bl = self.bl.replace(None).unwrap(); + let ledc = self.ledc.replace(None).unwrap(); + //let rtc_io = self.rtc_io.replace(None).unwrap(); + let io_mux = self.io_mux.replace(None).unwrap(); + + (ledc, bl, io_mux) + } + + pub fn init_iic(&self) -> I2c<'_, Blocking> { + let mut iic = I2c::new(self.iic.replace(None).unwrap(), esp_hal::i2c::master::Config::default()).unwrap() + .with_sda(self.sda.replace(None).unwrap()) + .with_scl(self.scl.replace(None).unwrap()); + + iic.write(0x15, &[0xFA_u8, 0b00010001]).expect("Failed to set irqctl"); + + iic + } + + pub fn init_display(&'a self, buffer: &'a mut [u8]) -> mipidsi::Display, Output<'a>, Delay>, Output<'a>>, GC9A01, Output<'a>> { + let spi = Spi::new( + self.spi.replace(None).unwrap(), + esp_hal::spi::master::Config::default() + .with_frequency(Rate::from_mhz(40)) + ).unwrap() + .with_sck(self.sclk.replace(None).unwrap()) + .with_mosi(self.mosi.replace(None).unwrap()); + + let cs_pin = esp_hal::gpio::Output::new(self.cs.replace(None).unwrap(), esp_hal::gpio::Level::Low, esp_hal::gpio::OutputConfig::default()); + let dc_pin = esp_hal::gpio::Output::new(self.dc.replace(None).unwrap(), esp_hal::gpio::Level::High, esp_hal::gpio::OutputConfig::default()); + let rs_pin = esp_hal::gpio::Output::new(self.reset.replace(None).unwrap(), esp_hal::gpio::Level::High, esp_hal::gpio::OutputConfig::default().with_pull(esp_hal::gpio::Pull::Up)); + let mut delay = esp_hal::delay::Delay::new(); + + let spi_dev = ExclusiveDevice::new(spi, cs_pin, delay).unwrap(); + let mipi_interface = mipidsi::interface::SpiInterface::new(spi_dev, dc_pin, buffer); + let display = mipidsi::Builder::new(GC9A01, mipi_interface) + .reset_pin(rs_pin) + .invert_colors(mipidsi::options::ColorInversion::Inverted) + .color_order(mipidsi::options::ColorOrder::Bgr) + .init(&mut delay).unwrap(); + + display + } +} + diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b831cd0 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,15 @@ +#![no_std] + +pub mod init; +pub mod state; +pub mod display; +pub mod touch; +pub mod setting_screen; + +pub const IIC_ADDRESS: u8 = 0x15_u8; +pub const TP_GESTURE: u8 = 0x01_u8; +pub const TP_X: u8 = 0x04_u8; +pub const TP_Y: u8 = 0x06_u8; + +pub const RAD_TO_DEG: f32 = 57.2957795; +pub const DEG_TO_RAD: f32 = 0.017453293; \ No newline at end of file diff --git a/src/setting_screen.rs b/src/setting_screen.rs new file mode 100644 index 0000000..ac8593d --- /dev/null +++ b/src/setting_screen.rs @@ -0,0 +1,492 @@ +use embedded_graphics::pixelcolor::Rgb565; +use embedded_graphics::prelude::{DrawTarget, Point, Primitive, RgbColor, Size}; +use embedded_graphics::primitives::{PrimitiveStyleBuilder, Rectangle}; +use embedded_graphics::Drawable; + +extern crate alloc; +use alloc::{vec::Vec, string::ToString}; +use u8g2_fonts::types::{FontColor, HorizontalAlignment, VerticalPosition}; + +use crate::state::{SettingScreenEntry, SettingScreenItem, SystemState}; +use crate::display::{CHECK, SMALL_FONT, MED_FONT, MED_PLUS_FONT}; + +use crate::display::{ColorScheme, COLORSCHEMES}; + +pub(crate) fn setting_screen(ctx: &SystemState, selection: &SettingScreenItem, target: &mut A) -> () + where A: DrawTarget +{ + let primary = ctx.settings.color_scheme.get_color(&crate::display::ColorType::Primary); + let background = ctx.settings.color_scheme.get_color(&crate::display::ColorType::Background); + + let top_count = 5; + let bottom_count = 5; + + let top_positions = &ctx.positions.top_setting_locations; + let bottom_positions = &ctx.positions.bottom_setting_locations; + + let mut top_vec = Vec::with_capacity(top_count as usize); + + top_vec.push("Opponents"); + top_vec.push("Starting\nLife"); + top_vec.push("New Game"); + top_vec.push("Color\nScheme"); + top_vec.push("Brightness"); + + let mut bottom_vec = Vec::with_capacity(bottom_count as usize); + + bottom_vec.push("Commander\nTax"); + bottom_vec.push("Energy"); + bottom_vec.push("Exp"); + bottom_vec.push("Tix"); + bottom_vec.push("Poison"); + + for (pos, content) in top_positions.iter().chain(bottom_positions.iter()).zip(top_vec.into_iter().chain(bottom_vec.into_iter())) { + _ = SMALL_FONT.render_aligned( + content, + pos.position, + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target); + } + + match selection.entry { + SettingScreenEntry::NewGame => { + let _ = MED_FONT.render_aligned( + "Start\nNew Game.", + ctx.positions.center, + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + }, + SettingScreenEntry::Opponents => { + let _ = MED_PLUS_FONT.render_aligned( + ctx.settings.opponenets.to_string().as_str(), + ctx.positions.center, + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + }, + SettingScreenEntry::StartingLife => { + let _ = MED_PLUS_FONT.render_aligned( + ctx.settings.starting_life.to_string().as_str(), + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + }, + SettingScreenEntry::Colors => { + let current_scheme_number: u8 = ctx.settings.color_scheme.into(); + let prev_scheme_number; + let check_sub = current_scheme_number.checked_sub(1); + if let Some(p) = check_sub { + prev_scheme_number = p; + } else { + prev_scheme_number = COLORSCHEMES as u8 - 1; + } + let prev_scheme: ColorScheme = prev_scheme_number.into(); + + let next_scheme_number; + let check_add = current_scheme_number + 1; + if check_add >= COLORSCHEMES as u8 { + next_scheme_number = 0; + } else { + next_scheme_number = check_add; + } + let next_scheme: ColorScheme = next_scheme_number.into(); + + let _ = MED_FONT.render_aligned( + prev_scheme.as_str(), + Point::new(120, 80), + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + + let _ = MED_PLUS_FONT.render_aligned( + ctx.settings.color_scheme.as_str(), + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + + let _ = MED_FONT.render_aligned( + next_scheme.as_str(), + Point::new(120, 160), + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + }, + SettingScreenEntry::Brightness => { + let _ = MED_PLUS_FONT.render_aligned( + ctx.settings.brightness.as_str(), + ctx.positions.center, + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + }, + SettingScreenEntry::ShowTax => { + //Yes/No rendering + let _ = MED_FONT.render_aligned( + "Show\nCommand Tax?", + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + draw_yes_no(primary, background, target, Some(ctx.settings.show_cmd_tax)); + }, + SettingScreenEntry::ShowEnergy => { + //Yes/No rendering + let _ = MED_FONT.render_aligned( + "Show\nEnergy?", + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + draw_yes_no(primary, background, target, Some(ctx.settings.show_energy)); + }, + SettingScreenEntry::ShowExperience => { + //Yes/No rendering + let _ = MED_FONT.render_aligned( + "Show\nExperience?", + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + draw_yes_no(primary, background, target, Some(ctx.settings.show_experience)); + }, + SettingScreenEntry::ShowTickets => { + //Yes/No rendering + let _ = MED_FONT.render_aligned( + "Show\nTickets?", + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + draw_yes_no(primary, background, target, Some(ctx.settings.show_tickets)); + }, + SettingScreenEntry::ShowPoison => { + //Yes/No rendering + let _ = MED_FONT.render_aligned( + "Show\nPoison?", + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + draw_yes_no(primary, background, target, Some(ctx.settings.show_infect)); + }, + }; +} + +fn draw_yes_no>(primary: Rgb565, background: Rgb565, display: &mut A, selected: Option) -> () { + let yes_color; + let no_color; + let rect_point; + + if let Some(sel) = selected { + if sel { + yes_color = background; + no_color = primary; + rect_point = Point::new(75, 125); + } else { + yes_color = primary; + no_color = background; + rect_point = Point::new(120,125); + } + let style = PrimitiveStyleBuilder::new() + .fill_color(primary) + .build(); + + let _ = Rectangle::new(rect_point, Size::new(45, 25)).into_styled(style).draw(display); + } else { + yes_color = primary; + no_color = primary; + } + + _ = MED_FONT.render_aligned( + "Yes", + Point{x: 110, y: 130}, + u8g2_fonts::types::VerticalPosition::Top, + u8g2_fonts::types::HorizontalAlignment::Right, + u8g2_fonts::types::FontColor::Transparent(yes_color), + display, + ); + + _ = MED_FONT.render_aligned( + "No", + Point{x: 135, y: 130}, + u8g2_fonts::types::VerticalPosition::Top, + u8g2_fonts::types::HorizontalAlignment::Left, + u8g2_fonts::types::FontColor::Transparent(no_color), + display, + ); +} + +pub(crate) fn setting_scroll(ctx: &SystemState, selection: &SettingScreenItem, target: &mut A) -> () + where A: DrawTarget +{ + let primary = ctx.settings.color_scheme.get_color(&crate::display::ColorType::Primary); + let background = ctx.settings.color_scheme.get_color(&crate::display::ColorType::Background); + + if !selection.inner { + let above = selection.entry.prev().as_str(); + let selected = selection.entry.as_str(); + let below = selection.entry.next().as_str(); + + let _above = MED_FONT.render_aligned( + above, + Point::new(120, 50), + VerticalPosition::Center, + HorizontalAlignment::Center, + FontColor::Transparent(primary), + target + ); + + let _selected = MED_PLUS_FONT.render_aligned( + selected, + Point::new(120, 120), + VerticalPosition::Center, + HorizontalAlignment::Center, + FontColor::Transparent(primary), + target + ); + + let _below = MED_FONT.render_aligned( + below, + Point::new(120, 190), + VerticalPosition::Center, + HorizontalAlignment::Center, + FontColor::Transparent(primary), + target + ); + } else { + setting_item(target); + match selection.entry { + SettingScreenEntry::NewGame => { + let _ = MED_PLUS_FONT.render_aligned( + selection.entry.as_str(), + Point::new(120, 120), + VerticalPosition::Center, + HorizontalAlignment::Center, + FontColor::Transparent(primary), + target, + ); + }, + SettingScreenEntry::Opponents => { + let _ = MED_PLUS_FONT.render_aligned( + ctx.settings.opponenets.to_string().as_str(), + ctx.positions.center, + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + }, + SettingScreenEntry::StartingLife => { + let _ = MED_PLUS_FONT.render_aligned( + ctx.settings.starting_life.to_string().as_str(), + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + }, + SettingScreenEntry::Colors => { + let current_scheme_number: u8 = ctx.settings.color_scheme.into(); + let prev_scheme_number; + let check_sub = current_scheme_number.checked_sub(1); + if let Some(p) = check_sub { + prev_scheme_number = p; + } else { + prev_scheme_number = COLORSCHEMES as u8 - 1; + } + let prev_scheme: ColorScheme = prev_scheme_number.into(); + + let next_scheme_number; + let check_add = current_scheme_number + 1; + if check_add >= COLORSCHEMES as u8 { + next_scheme_number = 0; + } else { + next_scheme_number = check_add; + } + let next_scheme: ColorScheme = next_scheme_number.into(); + + let _ = MED_FONT.render_aligned( + prev_scheme.as_str(), + Point::new(120, 70), + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + + let _ = MED_PLUS_FONT.render_aligned( + ctx.settings.color_scheme.as_str(), + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + + let _ = MED_FONT.render_aligned( + next_scheme.as_str(), + Point::new(120, 170), + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + }, + SettingScreenEntry::Brightness => { + let _ = MED_PLUS_FONT.render_aligned( + ctx.settings.brightness.as_str(), + ctx.positions.center, + u8g2_fonts::types::VerticalPosition::Center, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + } + SettingScreenEntry::ShowTax => { + let _ = MED_FONT.render_aligned( + "Show\nCommand Tax?", + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + draw_yes_no(primary, background, target, Some(ctx.settings.show_cmd_tax)); + }, + SettingScreenEntry::ShowEnergy => { + let _ = MED_FONT.render_aligned( + "Show\nEnergy?", + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + draw_yes_no(primary, background, target, Some(ctx.settings.show_energy)); + }, + SettingScreenEntry::ShowExperience => { + let _ = MED_FONT.render_aligned( + "Show\nExperience?", + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + draw_yes_no(primary, background, target, Some(ctx.settings.show_experience)); + }, + SettingScreenEntry::ShowTickets => { + let _ = MED_FONT.render_aligned( + "Show\nTickets?", + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + draw_yes_no(primary, background, target, Some(ctx.settings.show_tickets)); + }, + SettingScreenEntry::ShowPoison => { + let _ = MED_FONT.render_aligned( + "Show\nPoison?", + Point::new(120, 120), + u8g2_fonts::types::VerticalPosition::Bottom, + u8g2_fonts::types::HorizontalAlignment::Center, + u8g2_fonts::types::FontColor::Transparent(primary), + target + ); + draw_yes_no(primary, background, target, Some(ctx.settings.show_infect)); + }, + } + } +} + +pub fn setting_item(target: &mut A) -> () + where A: DrawTarget +{ + let _okay_outline_1 = CHECK.render_aligned( + '\u{0040}', + Point::new(26, 121), + VerticalPosition::Center, + HorizontalAlignment::Center, + FontColor::Transparent(Rgb565::BLACK), + target + ); + let _okay_outline_2 = CHECK.render_aligned( + '\u{0040}', + Point::new(26, 119), + VerticalPosition::Center, + HorizontalAlignment::Center, + FontColor::Transparent(Rgb565::BLACK), + target + ); + let _okay_outline_3 = CHECK.render_aligned( + '\u{0040}', + Point::new(24, 121), + VerticalPosition::Center, + HorizontalAlignment::Center, + FontColor::Transparent(Rgb565::BLACK), + target + ); + let _okay_outline_4 = CHECK.render_aligned( + '\u{0040}', + Point::new(24, 119), + VerticalPosition::Center, + HorizontalAlignment::Center, + FontColor::Transparent(Rgb565::BLACK), + target + ); + + let _okay = CHECK.render_aligned( + '\u{0040}', + Point::new(25, 120), + VerticalPosition::Center, + HorizontalAlignment::Center, + FontColor::Transparent(Rgb565::new(1, 54, 10)), + target + ); + + let _cancel = CHECK.render_aligned( + '\u{0044}', + Point::new(215, 120), + VerticalPosition::Center, + HorizontalAlignment::Center, + FontColor::Transparent(Rgb565::new(25, 8, 5)), + target + ); +} + + +/* +setting scroller -> internal screen check ok/ x cancel +*/ \ No newline at end of file diff --git a/src/state.rs b/src/state.rs new file mode 100644 index 0000000..735d41e --- /dev/null +++ b/src/state.rs @@ -0,0 +1,387 @@ +use core::panic; + +use crate::display::ColorScheme; +use embedded_graphics::prelude::{Angle, Point}; + +extern crate alloc; +use alloc::{string::String, string::ToString}; + +pub struct SystemState { + pub settings: Settings, + pub game: Game, + pub positions: Positions, + pub screen: Screen, +} + +impl SystemState { + pub fn new() -> Self { + Self { + settings: Settings { + opponenets: 1, + starting_life: 40, + brightness: Brightness::Three, + color_scheme: ColorScheme::Dark, + show_cmd_tax: true, + show_infect: true, + show_energy: true, + show_experience: true, + show_tickets: true, + }, + game: Game { life: 40, cmd_dmg: [CommanderDamage{main: 0, partner: 0, is_partner: true};6], infect: 0, cmd_tax: CommanderDamage { main: 0, partner: 0, is_partner: false }, energy: 0, experience: 0, tickets: 0, monarch: false}, + positions: Positions::init(), + screen: Screen::Main(MainScreenItem::Life), + } + } +} + +pub struct Settings { + pub opponenets: u8, + pub starting_life: i32, + pub color_scheme: ColorScheme, + pub brightness: Brightness, + pub show_cmd_tax: bool, + pub show_infect: bool, + pub show_experience: bool, + pub show_energy: bool, + pub show_tickets: bool, +} + +pub struct Game { + pub life: i32, + pub cmd_dmg: [CommanderDamage;6], + pub cmd_tax: CommanderDamage, + pub infect: u8, + pub energy: u16, + pub experience: u16, + pub tickets: u16, + pub monarch: bool, +} + +#[derive(Debug, Clone, Copy)] +pub struct CommanderDamage { + pub main: u8, + pub partner: u8, + pub is_partner: bool, +} + +impl CommanderDamage { + pub fn as_string_horizontal(&self) -> String { + match self.is_partner { + true => { + let mut tmpa = self.main.to_string(); + let tmpb = self.partner.to_string(); + tmpa.push('|'); + tmpa.push_str(&tmpb); + tmpa + }, + false => { + self.main.to_string() + } + } + } + pub fn as_string_vetical(&self) -> String { + match self.is_partner { + true => { + let mut tmpa = self.main.to_string(); + let tmpb = self.partner.to_string(); + tmpa.push('\n'); + tmpa.push_str(&tmpb); + tmpa + }, + false => { + self.main.to_string() + } + } + } +} + +pub struct Positions { + top_even: [PeripheralLocation;6], + top_odd: [PeripheralLocation;5], + bottom_even: [PeripheralLocation;6], + bottom_odd: [PeripheralLocation;5], + pub top_setting_locations: [PeripheralLocation;5], + pub bottom_setting_locations: [PeripheralLocation;5], + pub center: Point, +} + +impl Positions { + pub fn init() -> Self { + let top_odd = [ + PeripheralLocation{ position: Point::new(38, 71), angle: Angle::from_degrees(150.)}, + PeripheralLocation{ position: Point::new(72, 37), angle: Angle::from_degrees(120.)}, + PeripheralLocation{ position: Point::new(120, 20), angle: Angle::from_degrees(90.)}, + PeripheralLocation{ position: Point::new(168, 37), angle: Angle::from_degrees(60.)}, + PeripheralLocation{ position: Point::new(202, 71), angle: Angle::from_degrees(30.)}, + ]; + let top_even = [ + PeripheralLocation{ position: Point::new(23, 96), angle: Angle::from_degrees(165.)}, + PeripheralLocation{ position: Point::new(53, 52), angle: Angle::from_degrees(135.)}, + PeripheralLocation{ position: Point::new(95, 27), angle: Angle::from_degrees(105.)}, + PeripheralLocation{ position: Point::new(145, 27), angle: Angle::from_degrees(75.)}, + PeripheralLocation{ position: Point::new(187, 52), angle: Angle::from_degrees(45.)}, + PeripheralLocation{ position: Point::new(212, 96), angle: Angle::from_degrees(15.)}, + ]; + let bottom_odd = [ + PeripheralLocation{ position: Point::new(32, 170), angle: Angle::from_degrees(210.)}, + PeripheralLocation{ position: Point::new(70, 208), angle: Angle::from_degrees(240.)}, + PeripheralLocation{ position: Point::new(120, 215), angle: Angle::from_degrees(270.)}, + PeripheralLocation{ position: Point::new(168, 203), angle: Angle::from_degrees(300.)}, + PeripheralLocation{ position: Point::new(202, 169), angle: Angle::from_degrees(330.)}, + ]; + let bottom_even = [ + PeripheralLocation{ position: Point::new(28, 146), angle: Angle::from_degrees(195.)}, + PeripheralLocation{ position: Point::new(48, 190), angle: Angle::from_degrees(225.)}, + PeripheralLocation{ position: Point::new(95, 213), angle: Angle::from_degrees(255.)}, + PeripheralLocation{ position: Point::new(145, 213), angle: Angle::from_degrees(285.)}, + PeripheralLocation{ position: Point::new(187, 188), angle: Angle::from_degrees(315.)}, + PeripheralLocation{ position: Point::new(212, 146), angle: Angle::from_degrees(345.)}, + ]; + let top_setting_locations = [ + PeripheralLocation{ position: Point::new(38, 91), angle: Angle::from_degrees(162.)}, + PeripheralLocation{ position: Point::new(64, 53), angle: Angle::from_degrees(126.)}, + PeripheralLocation{ position: Point::new(120, 25), angle: Angle::from_degrees(90.)}, + PeripheralLocation{ position: Point::new(176, 53), angle: Angle::from_degrees(54.)}, + PeripheralLocation{ position: Point::new(210, 91), angle: Angle::from_degrees(18.)}, + ]; + let bottom_setting_locations = [ + PeripheralLocation{ position: Point::new(33, 170), angle: Angle::from_degrees(210.)},//(43,169) + PeripheralLocation{ position: Point::new(72, 203), angle: Angle::from_degrees(240.)}, + PeripheralLocation{ position: Point::new(120, 215), angle: Angle::from_degrees(270.)}, + PeripheralLocation{ position: Point::new(168, 203), angle: Angle::from_degrees(300.)}, + PeripheralLocation{ position: Point::new(202, 169), angle: Angle::from_degrees(330.)}, + ]; + + Self { + top_even, + top_odd, + bottom_even, + bottom_odd, + top_setting_locations, + bottom_setting_locations, + center: Point { x: 120, y: 120 } + } + } + + pub fn get_top_list(&self, count: u8) -> &[PeripheralLocation] { + match count { + 1 => &self.top_odd[2..3], + 2 => &self.top_even[2..4], + 3 => &self.top_odd[1..4], + 4 => &self.top_even[1..5], + 5 => &self.top_odd, + 6 => &self.top_even, + _ => panic!("Invalid count") + } + } + pub fn get_bottom_list(&self, count: u8) -> &[PeripheralLocation] { + match count { + 1 => &self.bottom_odd[2..3], + 2 => &self.bottom_even[2..4], + 3 => &self.bottom_odd[1..4], + 4 => &self.bottom_even[1..5], + 5 => &self.bottom_odd, + 6 => &self.bottom_even, + _ => panic!("Invalid count") + } + } +} + +#[derive(Debug, Clone, Copy)] +pub enum Screen{ + Main(MainScreenItem), + Settings(SettingScreenItem), +} + +#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)] +pub enum MainScreenItem { + Life, + Dmg1, + Dmg2, + Dmg3, + Dmg4, + Dmg5, + Dmg6, + Tax, + Energy, + Experience, + Tickets, + Poison, +} + + +#[derive(Debug, PartialEq, Clone, Copy)] +pub struct SettingScreenItem { + pub entry: SettingScreenEntry, + pub inner: bool, + pub prev: Option, +} + +#[derive(Debug, PartialEq, Clone, Copy)] +pub enum SettingScreenEntry { + NewGame, + Opponents, + StartingLife, + Colors, + Brightness, + ShowTax, + ShowEnergy, + ShowExperience, + ShowTickets, + ShowPoison, +} + +impl SettingScreenEntry { + pub fn prev(&self) -> Self { + match self { + SettingScreenEntry::NewGame => Self::ShowPoison, + SettingScreenEntry::Opponents => Self::NewGame, + SettingScreenEntry::StartingLife => Self::Opponents, + SettingScreenEntry::Colors => Self::StartingLife, + SettingScreenEntry::Brightness => Self::Colors, + SettingScreenEntry::ShowTax => Self::Brightness, + SettingScreenEntry::ShowEnergy => Self::ShowTax, + SettingScreenEntry::ShowExperience => Self::ShowEnergy, + SettingScreenEntry::ShowTickets => Self::ShowExperience, + SettingScreenEntry::ShowPoison => Self::ShowTickets, + } + } + + pub fn next(&self) -> Self { + match self { + SettingScreenEntry::NewGame => Self::Opponents, + SettingScreenEntry::Opponents => Self::StartingLife, + SettingScreenEntry::StartingLife => Self::Colors, + SettingScreenEntry::Colors => Self::Brightness, + SettingScreenEntry::Brightness => Self::ShowTax, + SettingScreenEntry::ShowTax => Self::ShowEnergy, + SettingScreenEntry::ShowEnergy => Self::ShowExperience, + SettingScreenEntry::ShowExperience => Self::ShowTickets, + SettingScreenEntry::ShowTickets => Self::ShowPoison, + SettingScreenEntry::ShowPoison => Self::NewGame, + } + } + + pub fn as_str(&self) -> &'static str { + match self { + SettingScreenEntry::NewGame => "New Game", + SettingScreenEntry::Opponents => "Opponents", + SettingScreenEntry::StartingLife => "Starting\nLife", + SettingScreenEntry::Colors => "Color\nScheme", + SettingScreenEntry::Brightness => "Brightness", + SettingScreenEntry::ShowTax => "Show\nCommander\nTax", + SettingScreenEntry::ShowEnergy => "Show\nEnergy", + SettingScreenEntry::ShowExperience => "Show\nExperience", + SettingScreenEntry::ShowTickets => "Show\nTickets", + SettingScreenEntry::ShowPoison => "Show\nPoison", + } + } +} + +#[derive(Clone, Copy)] +pub enum Brightness { + One, + Two, + Three, + Four, + Five, + Six, + Seven, + Eight, + Nine, + Ten, +} + +impl Brightness { + pub fn inc(self) -> Self { + match self { + Brightness::One => Self::Two, + Brightness::Two => Self::Three, + Brightness::Three => Self::Four, + Brightness::Four => Self::Five, + Brightness::Five => Self::Six, + Brightness::Six => Self::Seven, + Brightness::Seven => Self::Eight, + Brightness::Eight => Self::Nine, + Brightness::Nine => Self::Ten, + Brightness::Ten => Self::Ten, + } + } + + pub fn dec(self) -> Self { + match self { + Brightness::One => Self::One, + Brightness::Two => Self::One, + Brightness::Three => Self::Two, + Brightness::Four => Self::Three, + Brightness::Five => Self::Four, + Brightness::Six => Self::Five, + Brightness::Seven => Self::Six, + Brightness::Eight => Self::Seven, + Brightness::Nine => Self::Eight, + Brightness::Ten => Self::Nine, + } + } + pub fn as_str(&self) -> &'static str { + match self { + Brightness::One => "Min", + Brightness::Two => "2", + Brightness::Three => "3", + Brightness::Four => "4", + Brightness::Five => "5", + Brightness::Six => "6", + Brightness::Seven => "7", + Brightness::Eight => "8", + Brightness::Nine => "9", + Brightness::Ten => "Max", + } + } +} + +impl Into for Brightness { + fn into(self) -> u32 { + match self { + Brightness::One => 15, + Brightness::Two => 20, + Brightness::Three => 30, + Brightness::Four => 40, + Brightness::Five => 50, + Brightness::Six => 60, + Brightness::Seven => 70, + Brightness::Eight => 80, + Brightness::Nine => 90, + Brightness::Ten => 100, + } + } +} + +impl From for Brightness { + fn from(value: u32) -> Self { + if value <= 15 { + Brightness::One + } else if value <= 20 { + Brightness::Two + } else if value <= 30 { + Brightness::Three + } else if value <= 40 { + Brightness::Four + } else if value <= 50 { + Brightness::Five + } else if value <= 60 { + Brightness::Six + } else if value <= 70 { + Brightness::Seven + } else if value <= 80 { + Brightness::Eight + } else if value <= 90 { + Brightness::Nine + } else { + Brightness::Ten + } + } +} + +pub struct PeripheralLocation { + pub position: Point, + pub angle: Angle, +} \ No newline at end of file diff --git a/src/touch.rs b/src/touch.rs new file mode 100644 index 0000000..bd62be8 --- /dev/null +++ b/src/touch.rs @@ -0,0 +1,406 @@ +use crate::{display::ColorScheme, state::{CommanderDamage, Game, MainScreenItem, Screen, SettingScreenEntry, SettingScreenItem, SystemState}}; + +const CMDDMGLIST: [MainScreenItem;6] = [ + MainScreenItem::Dmg1, + MainScreenItem::Dmg2, + MainScreenItem::Dmg3, + MainScreenItem::Dmg4, + MainScreenItem::Dmg5, + MainScreenItem::Dmg6, +]; + +pub fn get_touch_action(x: f32, y: f32, gesture: u8, ctx: &mut SystemState) -> () { + let x = x - 120.; + let y = -(y - 120.); + let touch_rad = (x*x)+(y*y); + let angle; + + let next_state; + + if (gesture == 0x3) | (gesture == 0x4) { + ctx.screen = match &ctx.screen { + Screen::Main(_) => Screen::Settings(SettingScreenItem { entry: SettingScreenEntry::NewGame, inner: false , prev: None}), + Screen::Settings(_) => Screen::Main(MainScreenItem::Life), + }; + return; + } + + match &ctx.screen { + Screen::Main(selected) => { + + let mut bottom_selectable_list: [Option;5] = [const {None};5]; + let mut pos = 0; + if ctx.settings.show_cmd_tax { + bottom_selectable_list[pos] = Some(crate::state::MainScreenItem::Tax); + pos += 1; + } + if ctx.settings.show_energy { + bottom_selectable_list[pos] = Some(crate::state::MainScreenItem::Energy); + pos+=1; + }; + if ctx.settings.show_experience { + bottom_selectable_list[pos] = Some(crate::state::MainScreenItem::Experience); + pos+=1; + }; + if ctx.settings.show_tickets { + bottom_selectable_list[pos] = Some(crate::state::MainScreenItem::Tickets); + pos+=1; + }; + if ctx.settings.show_infect { + bottom_selectable_list[pos] = Some(crate::state::MainScreenItem::Poison); + }; + + let bottom_count = bottom_selectable_list.iter().fold(0, |acc, x| acc+x.is_some() as u8); + + if touch_rad > (70.*70.) { + angle = atan2_norm(y, x)*90.; + //ctx.game.life = angle as i32; //debug + let top; + let check_angles = if y >= 0. { + if ctx.settings.opponenets == 0 { + return; + } + top = true; + ctx.positions.get_top_list(ctx.settings.opponenets) + } else { + if bottom_count == 0 { + return; + } + top = false; + ctx.positions.get_bottom_list(bottom_count) + }; + + let touch_item = match check_angles.iter().position(|x| (x.angle.to_degrees()-angle).abs()<15.) { + Some(loc) => loc, + None => return, + }; + + let sel_match = if top { + Some(CMDDMGLIST.into_iter().nth(touch_item).unwrap_or(MainScreenItem::Dmg1)) + } else { + bottom_selectable_list[touch_item] + }; + + if let Some(selected_item) = sel_match { + if selected_item == *selected { + next_state = Screen::Main(MainScreenItem::Life); + } else { + next_state = Screen::Main(selected_item); + } + } else { + next_state = Screen::Main(MainScreenItem::Life); + } + + } else { + match selected { + crate::state::MainScreenItem::Life => { + let d = touch_inc_dec(y, gesture); + ctx.game.life = ctx.game.life.saturating_add(d as i32); + }, + + crate::state::MainScreenItem::Dmg1 => { + cmd_dmg_w_swap(ctx, x, y, gesture, 0); + }, + crate::state::MainScreenItem::Dmg2 => { + cmd_dmg_w_swap(ctx, x, y, gesture, 1); + }, + crate::state::MainScreenItem::Dmg3 => { + cmd_dmg_w_swap(ctx, x, y, gesture, 2); + }, + crate::state::MainScreenItem::Dmg4 => { + cmd_dmg_w_swap(ctx, x, y, gesture, 3); + }, + crate::state::MainScreenItem::Dmg5 => { + cmd_dmg_w_swap(ctx, x, y, gesture, 4); + }, + crate::state::MainScreenItem::Dmg6 => { + cmd_dmg_w_swap(ctx, x, y, gesture, 5); + }, + + crate::state::MainScreenItem::Tax => { + cmd_tax_w_swap(ctx, x, y, gesture); + }, + crate::state::MainScreenItem::Energy => { + let d = touch_inc_dec(y, gesture); + ctx.game.energy = ctx.game.energy.saturating_add_signed(d.into()); + }, + crate::state::MainScreenItem::Experience => { + let d = touch_inc_dec(y, gesture); + ctx.game.experience = ctx.game.experience.saturating_add_signed(d.into()); + }, + crate::state::MainScreenItem::Tickets => { + let d = touch_inc_dec(y, gesture); + ctx.game.tickets = ctx.game.tickets.saturating_add_signed(d.into()); + }, + crate::state::MainScreenItem::Poison => { + let d = touch_inc_dec(y, gesture); + ctx.game.infect = ctx.game.infect.saturating_add_signed(d.into()); + }, + }; + next_state = ctx.screen; + }; + }, + Screen::Settings(selected) => { + if !selected.inner { + if gesture == 0x01_u8 { + next_state = Screen::Settings(SettingScreenItem { entry: selected.entry.prev(), inner: false, prev: selected.prev }); + } else if gesture == 0x02_u8 { + next_state = Screen::Settings(SettingScreenItem { entry: selected.entry.next(), inner: false, prev: selected.prev }); + } else { + if y > 55. { + next_state = Screen::Settings(SettingScreenItem { entry: selected.entry.prev(), inner: false, prev: selected.prev}); + } else if y < -55. { + next_state = Screen::Settings(SettingScreenItem { entry: selected.entry.next(), inner: false, prev: selected.prev }); + } else { + let prev = match selected.entry { + SettingScreenEntry::NewGame => None, + SettingScreenEntry::Opponents => Some(ctx.settings.opponenets as u32), + SettingScreenEntry::StartingLife => Some(ctx.settings.starting_life as u32), + SettingScreenEntry::Colors => Some(Into::::into(ctx.settings.color_scheme) as u32), + SettingScreenEntry::Brightness => Some(ctx.settings.brightness.into()), + SettingScreenEntry::ShowTax => Some(ctx.settings.show_cmd_tax as u32), + SettingScreenEntry::ShowEnergy => Some(ctx.settings.show_energy as u32), + SettingScreenEntry::ShowExperience => Some(ctx.settings.show_experience as u32), + SettingScreenEntry::ShowTickets => Some(ctx.settings.show_tickets as u32), + SettingScreenEntry::ShowPoison => Some(ctx.settings.show_infect as u32), + }; + next_state = Screen::Settings(SettingScreenItem { entry: selected.entry, inner: true, prev: prev}); + } + } + } else { + if x < -75. { + match selected.entry { + SettingScreenEntry::NewGame => { + ctx.game = Game { + life: ctx.settings.starting_life, + cmd_dmg: [CommanderDamage{main: 0, partner: 0, is_partner: false};6], + cmd_tax: CommanderDamage { main: 0, partner: 0, is_partner: false }, + infect: 0, + energy: 0, + experience: 0, + tickets: 0, + monarch: false, + }; + next_state = Screen::Main(MainScreenItem::Life); + }, + _ => { + next_state = Screen::Settings(SettingScreenItem { entry: selected.entry, inner: false, prev: None }) + } + } + } else if x > 75. { + match selected.entry { + SettingScreenEntry::NewGame => {}, + SettingScreenEntry::Opponents => { + ctx.settings.opponenets = selected.prev.unwrap_or(0) as u8; + }, + SettingScreenEntry::StartingLife => { + ctx.settings.starting_life = selected.prev.unwrap_or(0) as i32; + }, + SettingScreenEntry::Colors => { + ctx.settings.color_scheme =Into::::into(selected.prev.unwrap_or(0) as u8); + }, + SettingScreenEntry::Brightness => { + ctx.settings.brightness = selected.prev.unwrap_or(0).into(); + }, + SettingScreenEntry::ShowTax => { + ctx.settings.show_cmd_tax = selected.prev.unwrap_or_default() != 0; + }, + SettingScreenEntry::ShowEnergy => { + ctx.settings.show_energy = selected.prev.unwrap_or_default() != 0; + }, + SettingScreenEntry::ShowExperience => { + ctx.settings.show_experience = selected.prev.unwrap_or_default() != 0; + }, + SettingScreenEntry::ShowTickets => { + ctx.settings.show_tickets = selected.prev.unwrap_or_default() != 0; + }, + SettingScreenEntry::ShowPoison => { + ctx.settings.show_infect = selected.prev.unwrap_or_default() != 0; + }, + } + next_state = Screen::Settings(SettingScreenItem { entry: selected.entry, inner: false, prev: None }) + } else { + match selected.entry { + SettingScreenEntry::NewGame => { + + }, + SettingScreenEntry::Opponents => { + ctx.settings.opponenets = ctx.settings.opponenets.saturating_add_signed(touch_inc_dec(y, gesture)); + }, + SettingScreenEntry::StartingLife => { + ctx.settings.starting_life = ctx.settings.starting_life.saturating_add(touch_inc_dec(y, gesture) as i32); + }, + SettingScreenEntry::Colors => { + if y > 40. { + ctx.settings.color_scheme = ctx.settings.color_scheme.dec(); + } else if y < -40. { + ctx.settings.color_scheme = ctx.settings.color_scheme.inc(); + } + }, + SettingScreenEntry::Brightness => { + let tmp = touch_inc_dec(y, gesture); + if tmp > 0 { + ctx.settings.brightness = ctx.settings.brightness.inc(); + } else { + ctx.settings.brightness = ctx.settings.brightness.dec(); + } + }, + SettingScreenEntry::ShowTax => { + let det = select_button(x, y, gesture); + if let Some(i) = det { + ctx.settings.show_cmd_tax = i; + } + }, + SettingScreenEntry::ShowEnergy => { + let det = select_button(x, y, gesture); + if let Some(i) = det { + ctx.settings.show_energy = i; + } + }, + SettingScreenEntry::ShowExperience => { + let det = select_button(x, y, gesture); + if let Some(i) = det { + ctx.settings.show_experience = i; + } + }, + SettingScreenEntry::ShowTickets => { + let det = select_button(x, y, gesture); + if let Some(i) = det { + ctx.settings.show_tickets = i; + } + }, + SettingScreenEntry::ShowPoison => { + let det = select_button(x, y, gesture); + if let Some(i) = det { + ctx.settings.show_infect = i; + } + }, + } + next_state = Screen::Settings(SettingScreenItem { entry: selected.entry, inner: selected.inner, prev: selected.prev }) + } + } + } + } + ctx.screen = next_state; +} + +/// Approximates `atan2(y,x)` normalized to the `[0, 4)` range with a maximum +/// error of `0.1620` degrees. +fn atan2_norm(lhs: f32, rhs: f32) -> f32 { + const SIGN_MASK: u32 = 0x8000_0000; + const B: f32 = 0.596_227; + + let y = lhs; + let x = rhs; + + // Extract sign bits from floating point values + let ux_s = SIGN_MASK & x.to_bits(); + let uy_s = SIGN_MASK & y.to_bits(); + + // Determine quadrant offset + let q = ((!ux_s & uy_s) >> 29 | ux_s >> 30) as f32; + + // Calculate arctangent in the first quadrant + let bxy_a = (B * x * y).abs(); + let n = bxy_a + y * y; + let atan_1q = n / (x * x + bxy_a + n); + + // Translate it to the proper quadrant + let uatan_2q = (ux_s ^ uy_s) | atan_1q.to_bits(); + q + f32::from_bits(uatan_2q) +} + +fn touch_inc_dec(y: f32, gesture: u8) -> i8 { + if gesture == 0x05 { + if y >= 0. { + 1 + } else { + -1 + } + } else if gesture == 0x02 { + 5 + } else if gesture == 0x01 { + -5 + } else { + 0 + } +} + +fn touch_left_right(x: f32, y: f32, gesture: u8) -> (i8, bool) { + if x <= 0. { + (touch_inc_dec(y, gesture), true) + } else { + (touch_inc_dec(y, gesture), false) + } +} + +fn cmd_dmg_calc(ctx: &mut SystemState, x: f32, y: f32, gesture: u8, pos: usize) { + if ctx.game.cmd_dmg[pos].is_partner { + let (d, left) = touch_left_right(x, y, gesture); + if left { + ctx.game.cmd_dmg[pos].main = ctx.game.cmd_dmg[pos].main.saturating_add_signed(d); + } else { + ctx.game.cmd_dmg[pos].partner = ctx.game.cmd_dmg[pos].partner.saturating_add_signed(d); + } + } else { + let d = touch_inc_dec(y, gesture); + ctx.game.cmd_dmg[pos].main = ctx.game.cmd_dmg[pos].main.saturating_add_signed(d); + } +} + +fn cmd_tax_calc(ctx: &mut SystemState, x: f32, y: f32, gesture: u8) { + if ctx.game.cmd_tax.is_partner { + let (mut d, left) = touch_left_right(x, y, gesture); + + if d >= 0 { + d = 2; + } else { + d =-2; + } + + if left { + ctx.game.cmd_tax.main = ctx.game.cmd_tax.main.saturating_add_signed(d); + } else { + ctx.game.cmd_tax.partner = ctx.game.cmd_tax.partner.saturating_add_signed(d); + } + } else { + let mut d = touch_inc_dec(y, gesture); + + if d >= 0 { + d = 2; + } else { + d =-2; + } + + ctx.game.cmd_tax.main = ctx.game.cmd_tax.main.saturating_add_signed(d); + } +} + +/// true is left selection false is right selection +fn select_button(x: f32, y: f32, _gesture: u8) -> Option { + if (y<60.) & (y>-60.) { + if x<=0. { + Some(true) + } else { + Some(false) + } + } else { + None + } +} + +fn cmd_dmg_w_swap(ctx: &mut SystemState, x: f32, y: f32, gesture: u8, pos: usize) { + if (x>-20.) & (x<20.) & (y< -30.)&(y>-50.) { + ctx.game.cmd_dmg[pos].is_partner = !ctx.game.cmd_dmg[pos].is_partner; + } else { + cmd_dmg_calc(ctx, x, y, gesture, pos); + } +} + +fn cmd_tax_w_swap(ctx: &mut SystemState, x: f32, y: f32, gesture: u8) { + if (x>-20.) & (x<20.) & (y< -30.)&(y>-50.) { + ctx.game.cmd_tax.is_partner = !ctx.game.cmd_tax.is_partner; + } else { + cmd_tax_calc(ctx, x, y, gesture); + } +} \ No newline at end of file diff --git a/template.yaml b/template.yaml new file mode 100644 index 0000000..990c8aa --- /dev/null +++ b/template.yaml @@ -0,0 +1,149 @@ +options: + - !Option + name: unstable-hal + display_name: Enable unstable HAL features. + help: "This configuration enables unstable esp-hal features. + These come with no stability guarantees, and could be changed or removed at any time." + + - !Option + name: alloc + display_name: Enable allocations via the esp-alloc crate. + help: esp-alloc comes with no stability guarantees at this time. + + - !Option + name: wifi + display_name: Enable Wi-Fi via the esp-wifi crate. + help: esp-wifi comes with no stability guarantees at this time. + requires: + - alloc + - unstable-hal + chips: + - esp32 + - esp32c2 + - esp32c3 + - esp32c6 + - esp32s2 + - esp32s3 + + - !Option + name: ble + display_name: Enable BLE via the esp-wifi crate. + help: esp-wifi comes with no stability guarantees at this time. + requires: + - alloc + - unstable-hal + chips: + - esp32 + - esp32c2 + - esp32c3 + - esp32c6 + - esp32h2 + - esp32s3 + + - !Option + name: embassy + display_name: Add embassy framework support. + help: esp-hal-embassy comes with no stability guarantees at this time. + requires: + - unstable-hal + + - !Option + name: probe-rs + display_name: Use probe-rs to flash and monitor instead of espflash. + help: probe-rs is a debugger that connects to the chips over JTAG. It can be used to flash and + monitor, and it can also be used to interactively debug an application, or run tests on the + hardware. Semihosting or RTT-based technologies like defmt-rtt require probe-rs. + chips: + - esp32c6 + - esp32h2 + - esp32s3 + + - !Option + name: probe-rs + display_name: Use probe-rs to flash and monitor instead of espflash. + help: probe-rs is a debugger that connects to the chips over JTAG. It can be used to flash and + monitor, and it can also be used to interactively debug an application, or run tests on the + hardware. Semihosting or RTT-based technologies like defmt-rtt require probe-rs. + + probe-rs requires a debug probe like esp-prog, and will not work with USB-UART adapters that + often come on development boards. + chips: + - esp32 + - esp32s2 + - esp32c2 + - esp32c3 + + - !Category + name: flashing-probe-rs + display_name: Flashing, logging and debugging (probe-rs) + requires: + - probe-rs + options: + - !Option + name: defmt + display_name: Use defmt to print messages. + selection_group: log-frontend + - !Option + name: panic-rtt-target + display_name: Use panic-rtt-target as the panic handler. + selection_group: panic-handler + requires: + - probe-rs + + - !Category + name: flashing-espflash + display_name: Flashing, logging and debugging (espflash) + requires: + - "!probe-rs" + options: + - !Option + name: log + display_name: Use the log crate to print messages. + selection_group: log-frontend + requires: + - "!probe-rs" + - !Option + name: defmt + display_name: Use defmt to print messages. + selection_group: log-frontend + - !Option + name: esp-backtrace + display_name: Use esp-backtrace as the panic handler. + selection_group: panic-handler + requires: + - "!probe-rs" + + - !Category + name: optional + display_name: Options + options: + - !Option + name: wokwi + display_name: Add support for Wokwi simulation using VS Code Wokwi extension. + chips: + - esp32 + - esp32c3 + - esp32c6 + - esp32h2 + - esp32s2 + - esp32s3 + + - !Option + name: dev-container + display_name: Add support for VS Code Dev Containers and GitHub Codespaces. + + - !Option + name: ci + display_name: Add GitHub Actions support with some basic checks. + + - !Category + name: editor + display_name: Optional editor config files for rust-analyzer + options: + - !Option + name: helix + display_name: Add rust-analyzer settings for Helix Editor + + - !Option + name: vscode + display_name: Add rust-analyzer settings for Visual Studio Code