diff --git a/board/PlantCtrlESP32.kicad_pcb b/board/PlantCtrlESP32.kicad_pcb index 87f2e6a..da74505 100644 --- a/board/PlantCtrlESP32.kicad_pcb +++ b/board/PlantCtrlESP32.kicad_pcb @@ -224,7 +224,7 @@ (net 86 "CD3") (net 87 "CD4") (net 88 "CD5") - (net 89 "Net-(D4-A)") + (net 89 "Net-(D10-A)") (net 90 "Net-(D2-K)") (net 91 "CD6") (net 92 "CD7") @@ -2002,7 +2002,7 @@ (size 0.975 1.4) (layers "F.Cu" "F.Paste" "F.Mask") (roundrect_rratio 0.25) - (net 116 "S_VIN") + (net 89 "Net-(D10-A)") (pinfunction "A") (pintype "passive") (uuid "5225bf31-35e5-43d5-ab7f-6f07c9612ac9") @@ -5838,7 +5838,7 @@ (drill 1.8) (layers "*.Cu" "*.Mask") (remove_unused_layers no) - (net 89 "Net-(D4-A)") + (net 89 "Net-(D10-A)") (pinfunction "Pin_2") (pintype "passive") (uuid "89dfe9c4-5493-4752-9393-9fb47fc1991f") @@ -94085,7 +94085,7 @@ (size 1.6 1.9) (layers "B.Cu" "B.Paste" "B.Mask") (roundrect_rratio 0.15625) - (net 89 "Net-(D4-A)") + (net 89 "Net-(D10-A)") (pinfunction "A") (pintype "passive") (uuid "45eef262-a0c3-45fb-86b8-e35570b1b820") @@ -101822,7 +101822,7 @@ ) ) ) - (gr_text "PlantCtrl V3.1" + (gr_text "PlantCtrl V3.2" (at 219.08 107.77 0) (layer "F.SilkS") (uuid "5ed408bf-a427-4794-bcf8-6f61a0d34323") @@ -118277,6 +118277,134 @@ (net 88) (uuid "ccae565d-81db-478c-a24f-6964a8443c03") ) + (segment + (start 199.23 71.02) + (end 198.5925 71.6575) + (width 0.2) + (layer "F.Cu") + (net 89) + (uuid "2758b681-9280-45f5-9e15-87300e9bbbf5") + ) + (segment + (start 198.5925 71.6575) + (end 198.5925 74.9575) + (width 0.2) + (layer "F.Cu") + (net 89) + (uuid "365047f2-2bd8-4e4a-8762-f735631436fc") + ) + (segment + (start 197.526263 57.071259) + (end 199.08 55.517522) + (width 0.2) + (layer "F.Cu") + (net 89) + (uuid "447e7c8b-fd7b-43ca-a8af-9591a0c96077") + ) + (segment + (start 199.23 67.12) + (end 197.526263 65.416263) + (width 0.2) + (layer "F.Cu") + (net 89) + (uuid "514c8cb7-8c20-4e79-a89b-183d8d6eb291") + ) + (segment + (start 199.23 68.996732) + (end 199.23 71.02) + (width 0.2) + (layer "F.Cu") + (net 89) + (uuid "5aa7fda6-fc9b-4c71-8c94-f22b906e9366") + ) + (segment + (start 197.526263 65.416263) + (end 197.526263 57.071259) + (width 0.2) + (layer "F.Cu") + (net 89) + (uuid "aada9dad-31bb-47c4-bd2b-460f7dae2040") + ) + (segment + (start 199.08 55.517522) + (end 199.08 51.51) + (width 0.2) + (layer "F.Cu") + (net 89) + (uuid "ab2af992-d49e-4f64-ac31-c0d54e20439a") + ) + (segment + (start 199.23 70.325022) + (end 199.23 67.12) + (width 0.2) + (layer "F.Cu") + (net 89) + (uuid "ff9efd59-ad74-4311-92b3-9e77d715d585") + ) + (via + (at 199.08 51.51) + (size 0.8) + (drill 0.4) + (layers "F.Cu" "B.Cu") + (net 89) + (uuid "12ddafb4-b563-4a8e-9ab4-5ece26c3862e") + ) + (segment + (start 199.08 51.51) + (end 199.51 51.08) + (width 0.2) + (layer "In2.Cu") + (net 89) + (uuid "355c666a-8c48-4408-a56f-7e94f5422883") + ) + (segment + (start 199.51 51.08) + (end 204.67 51.08) + (width 0.2) + (layer "In2.Cu") + (net 89) + (uuid "37522d91-b664-4d3b-8b7e-82d20895aa0b") + ) + (segment + (start 204.67 51.08) + (end 206.63 49.12) + (width 0.2) + (layer "In2.Cu") + (net 89) + (uuid "548d2bee-03fa-4e0a-a4e8-aba17738c3ad") + ) + (segment + (start 206.63 49.12) + (end 243.93 49.12) + (width 0.2) + (layer "In2.Cu") + (net 89) + (uuid "70525e1f-4470-47f0-a5fb-a5d4115a67ad") + ) + (segment + (start 250.33 53.47) + (end 260.23 43.57) + (width 0.2) + (layer "In2.Cu") + (net 89) + (uuid "8ccb7a12-4326-408c-9a43-3c7fbc461569") + ) + (segment + (start 248.28 53.47) + (end 250.33 53.47) + (width 0.2) + (layer "In2.Cu") + (net 89) + (uuid "a34990de-334a-4324-b0e5-5418cb880926") + ) + (segment + (start 243.93 49.12) + (end 248.28 53.47) + (width 0.2) + (layer "In2.Cu") + (net 89) + (uuid "ddb3be01-a033-47c2-82a1-03ec78364a30") + ) (segment (start 258.755 42.095) (end 260.23 43.57) @@ -120877,78 +121005,6 @@ (net 115) (uuid "e986b2c5-68bb-496a-aead-e7ec4e70ddcc") ) - (segment - (start 197.526263 57.071259) - (end 199.08 55.517522) - (width 0.2) - (layer "F.Cu") - (net 116) - (uuid "21bd6373-df9a-4a98-a8cf-b82336f62268") - ) - (segment - (start 199.23 71.02) - (end 198.5925 71.6575) - (width 0.2) - (layer "F.Cu") - (net 116) - (uuid "2758b681-9280-45f5-9e15-87300e9bbbf5") - ) - (segment - (start 198.5925 71.6575) - (end 198.5925 74.9575) - (width 0.2) - (layer "F.Cu") - (net 116) - (uuid "365047f2-2bd8-4e4a-8762-f735631436fc") - ) - (segment - (start 199.08 51.51) - (end 198.3 50.73) - (width 0.2) - (layer "F.Cu") - (net 116) - (uuid "4d6e5690-ae53-47e3-9b62-f2837475f82f") - ) - (segment - (start 199.23 67.12) - (end 197.526263 65.416263) - (width 0.2) - (layer "F.Cu") - (net 116) - (uuid "4fac2999-3d83-4054-a930-98b5a7d69276") - ) - (segment - (start 199.23 68.996732) - (end 199.23 71.02) - (width 0.2) - (layer "F.Cu") - (net 116) - (uuid "5aa7fda6-fc9b-4c71-8c94-f22b906e9366") - ) - (segment - (start 199.08 55.517522) - (end 199.08 51.51) - (width 0.2) - (layer "F.Cu") - (net 116) - (uuid "89e4415c-c301-4ef4-8a9b-40dbb8eac448") - ) - (segment - (start 197.526263 65.416263) - (end 197.526263 57.071259) - (width 0.2) - (layer "F.Cu") - (net 116) - (uuid "f65b08ff-0f84-4886-90ec-4a336610cec2") - ) - (segment - (start 199.23 70.325022) - (end 199.23 67.12) - (width 0.2) - (layer "F.Cu") - (net 116) - (uuid "fd01b622-2f4d-47cc-8562-8dcc412e8948") - ) (via (at 198.3 50.73) (size 0.8) @@ -120957,37 +121013,45 @@ (net 116) (uuid "ace97433-55e8-4ac9-bf58-2ab211a8cb16") ) + (segment + (start 206.48 48.77) + (end 235.424888 48.77) + (width 0.2) + (layer "In2.Cu") + (net 116) + (uuid "00e22fb6-91cb-487c-a824-67bd524d9b12") + ) (segment (start 198.3 50.73) - (end 205.665 50.73) + (end 204.52 50.73) (width 0.2) (layer "In2.Cu") (net 116) - (uuid "3324c801-6932-4b71-9a6d-a3007165027e") + (uuid "27bb072b-e6c0-45ce-942b-9fda90cafa1d") ) (segment - (start 241.18 43.014887) - (end 234.804887 49.39) + (start 235.424888 48.77) + (end 235.452444 48.742444) (width 0.2) (layer "In2.Cu") (net 116) - (uuid "54c1c40a-8a61-4c14-ac57-9818372d26a3") + (uuid "3381a1bc-1d4c-4d40-81a4-914885200493") ) (segment - (start 234.804887 49.39) - (end 207.005 49.39) + (start 204.52 50.73) + (end 206.48 48.77) (width 0.2) (layer "In2.Cu") (net 116) - (uuid "56944a23-0d0d-4fb5-b338-7d994172ddf5") + (uuid "380fc37a-1399-41f6-9031-b932d6f678f4") ) (segment - (start 205.665 50.73) - (end 207.005 49.39) + (start 235.452444 48.742444) + (end 241.18 43.014887) (width 0.2) (layer "In2.Cu") (net 116) - (uuid "65bbc0d2-18b6-4d39-a412-925c5d3e87af") + (uuid "f07016f4-647f-49b6-894a-8caf3ef6e5d7") ) (segment (start 234.415 43.335) @@ -130304,7 +130368,7 @@ (xy 200.457379 77.222621) (xy 200.572375 77.310861) (xy 200.706291 77.36633) (xy 200.85 77.38525) (xy 200.979204 77.368239) (xy 201.039362 77.379389) (xy 201.062124 77.396385) (xy 201.807635 78.141895) (xy 201.807636 78.141897) (xy 201.878103 78.212364) (xy 201.878104 78.212364) (xy 201.878105 78.212365) - (xy 201.970171 78.2505) (xy 201.970172 78.2505) (xy 202.2305 78.2505) (xy 202.288691 78.269407) + (xy 201.970171 78.2505) (xy 201.970172 78.2505) (xy 202.069828 78.2505) (xy 202.2305 78.2505) (xy 202.288691 78.269407) (xy 202.324655 78.318907) (xy 202.3295 78.3495) (xy 202.3295 79.014827) (xy 202.340135 79.068284) (xy 202.336688 79.068969) (xy 202.340128 79.112716) (xy 202.308154 79.164882) (xy 202.251625 79.188292) (xy 202.192131 79.174004) (xy 202.173864 79.159603) (xy 201.709397 78.695136) (xy 201.709395 78.695135) diff --git a/board/PlantCtrlESP32.kicad_prl b/board/PlantCtrlESP32.kicad_prl index 78641cf..9375f7c 100644 --- a/board/PlantCtrlESP32.kicad_prl +++ b/board/PlantCtrlESP32.kicad_prl @@ -1,6 +1,6 @@ { "board": { - "active_layer": 31, + "active_layer": 2, "active_layer_preset": "", "auto_track_width": false, "hidden_netclasses": [], diff --git a/board/PlantCtrlESP32.kicad_sch b/board/PlantCtrlESP32.kicad_sch index 2774ea3..6ba74bc 100644 --- a/board/PlantCtrlESP32.kicad_sch +++ b/board/PlantCtrlESP32.kicad_sch @@ -8510,6 +8510,12 @@ (color 0 0 0 0) (uuid "1b762162-080c-4e36-b68b-d3bd15571f83") ) + (junction + (at 273.05 467.36) + (diameter 0) + (color 0 0 0 0) + (uuid "1de64cec-e748-4c12-b5b5-b7d914424890") + ) (junction (at 368.3 265.43) (diameter 0) @@ -8546,6 +8552,12 @@ (color 0 0 0 0) (uuid "21c9489c-b7e7-411e-8242-06cb982ccdfb") ) + (junction + (at 273.05 482.6) + (diameter 0) + (color 0 0 0 0) + (uuid "2235abed-6314-47fb-bd0d-6abfcbf38d24") + ) (junction (at 541.02 400.05) (diameter 0) @@ -9032,12 +9044,6 @@ (color 0 0 0 0) (uuid "7a5115d1-34f1-4afd-aab6-8c3f89df22ba") ) - (junction - (at 278.13 482.6) - (diameter 0) - (color 0 0 0 0) - (uuid "7a5501a9-aa4e-4c2f-97d2-dcc56d614fb0") - ) (junction (at 671.83 160.02) (diameter 0) @@ -9452,12 +9458,6 @@ (color 0 0 0 0) (uuid "caf08951-498e-42d7-836c-4ada133aecad") ) - (junction - (at 283.21 467.36) - (diameter 0) - (color 0 0 0 0) - (uuid "cb8921f4-3acf-46e6-9e1b-664450a97706") - ) (junction (at 279.4 373.38) (diameter 0) @@ -10002,7 +10002,7 @@ ) (wire (pts - (xy 266.7 467.36) (xy 274.32 467.36) + (xy 266.7 467.36) (xy 273.05 467.36) ) (stroke (width 0) @@ -10380,16 +10380,6 @@ ) (uuid "15af01a4-7363-43c2-898d-32d02445b190") ) - (wire - (pts - (xy 278.13 482.6) (xy 283.21 482.6) - ) - (stroke - (width 0) - (type default) - ) - (uuid "15e8b968-0e04-4252-9336-7658e7b54757") - ) (wire (pts (xy 313.69 281.94) (xy 313.69 311.15) @@ -11492,7 +11482,7 @@ ) (wire (pts - (xy 281.94 467.36) (xy 283.21 467.36) + (xy 281.94 467.36) (xy 288.29 467.36) ) (stroke (width 0) @@ -11920,16 +11910,6 @@ ) (uuid "44dee16c-8d98-4384-9085-7986bb6aa07e") ) - (wire - (pts - (xy 283.21 467.36) (xy 288.29 467.36) - ) - (stroke - (width 0) - (type default) - ) - (uuid "4556036e-79b2-4f34-bdcf-b8ba10bb992f") - ) (wire (pts (xy 322.58 392.43) (xy 322.58 391.16) @@ -14510,6 +14490,16 @@ ) (uuid "ac28658d-8891-469f-b9b0-f3590d03e4f2") ) + (wire + (pts + (xy 273.05 482.6) (xy 278.13 482.6) + ) + (stroke + (width 0) + (type default) + ) + (uuid "acb3069f-8377-4110-9353-ea5c82b02245") + ) (wire (pts (xy 425.45 128.27) (xy 425.45 142.24) @@ -14570,6 +14560,16 @@ ) (uuid "afa01955-a88a-4042-8d04-4c237614a0f0") ) + (wire + (pts + (xy 273.05 467.36) (xy 274.32 467.36) + ) + (stroke + (width 0) + (type default) + ) + (uuid "b011ffab-b912-471f-a965-a13d3340092b") + ) (wire (pts (xy 57.15 311.15) (xy 55.88 311.15) @@ -15452,7 +15452,7 @@ ) (wire (pts - (xy 266.7 482.6) (xy 278.13 482.6) + (xy 266.7 482.6) (xy 273.05 482.6) ) (stroke (width 0) @@ -43669,7 +43669,7 @@ ) (symbol (lib_id "Device:R") - (at 283.21 478.79 180) + (at 273.05 478.79 180) (unit 1) (exclude_from_sim no) (in_bom yes) @@ -43678,7 +43678,7 @@ (fields_autoplaced yes) (uuid "8ac36e7f-4156-4025-90ad-b66992971bf1") (property "Reference" "R9" - (at 278.13 478.79 90) + (at 267.97 478.79 90) (effects (font (size 1.27 1.27) @@ -43686,7 +43686,7 @@ ) ) (property "Value" "10k" - (at 280.67 478.79 90) + (at 270.51 478.79 90) (effects (font (size 1.27 1.27) @@ -43694,7 +43694,7 @@ ) ) (property "Footprint" "Resistor_SMD:R_0603_1608Metric" - (at 284.988 478.79 90) + (at 274.828 478.79 90) (effects (font (size 1.27 1.27) @@ -43703,7 +43703,7 @@ ) ) (property "Datasheet" "~" - (at 283.21 478.79 0) + (at 273.05 478.79 0) (effects (font (size 1.27 1.27) @@ -43712,7 +43712,7 @@ ) ) (property "Description" "" - (at 283.21 478.79 0) + (at 273.05 478.79 0) (effects (font (size 1.27 1.27) @@ -43721,7 +43721,7 @@ ) ) (property "LCSC_PART_NUMBER" "C212284" - (at 283.21 478.79 0) + (at 273.05 478.79 0) (effects (font (size 1.27 1.27) @@ -51423,7 +51423,7 @@ ) (symbol (lib_id "Device:LED") - (at 283.21 471.17 90) + (at 273.05 471.17 90) (unit 1) (exclude_from_sim no) (in_bom yes) @@ -51432,7 +51432,7 @@ (fields_autoplaced yes) (uuid "d6463491-6b0c-4c56-a803-1a561e555f73") (property "Reference" "D10" - (at 287.02 471.4875 90) + (at 276.86 471.4875 90) (effects (font (size 1.27 1.27) @@ -51441,7 +51441,7 @@ ) ) (property "Value" "RED" - (at 287.02 474.0275 90) + (at 276.86 474.0275 90) (effects (font (size 1.27 1.27) @@ -51450,7 +51450,7 @@ ) ) (property "Footprint" "LED_SMD:LED_0805_2012Metric" - (at 283.21 471.17 0) + (at 273.05 471.17 0) (effects (font (size 1.27 1.27) @@ -51459,7 +51459,7 @@ ) ) (property "Datasheet" "~" - (at 283.21 471.17 0) + (at 273.05 471.17 0) (effects (font (size 1.27 1.27) @@ -51468,7 +51468,7 @@ ) ) (property "Description" "" - (at 283.21 471.17 0) + (at 273.05 471.17 0) (effects (font (size 1.27 1.27) @@ -51477,7 +51477,7 @@ ) ) (property "LCSC_PART_NUMBER" "C205441" - (at 283.21 471.17 0) + (at 273.05 471.17 0) (effects (font (size 1.27 1.27) diff --git a/rust/.cargo/config.toml b/rust/.cargo/config.toml index 3fe4917..c78df86 100644 --- a/rust/.cargo/config.toml +++ b/rust/.cargo/config.toml @@ -4,14 +4,13 @@ target = "riscv32imac-esp-espidf" [target.riscv32imac-esp-espidf] linker = "ldproxy" -runner = "espflash flash --monitor --baud 921600 --partition-table partitions.csv -b no-reset" # Select this runner for espflash v2.x.x - +#runner = "espflash flash --monitor --baud 921600 --partition-table partitions.csv -b no-reset" # Select this runner in case of usb ttl +runner = "espflash flash --monitor --baud 921600 --partition-table partitions.csv" # Select this runner for espflash v2.x.x #runner = "cargo runner" -#runner = "espflash flash --monitor --partition-table partitions.csv -b no-reset" # Select this runner for espflash v2.x.x -# runner = "espflash flash --monitor --baud 921600 --partition-table partitions.csv -b no-reset" # Select this runner for espflash v2.x.x -# runner = espflash erase-parts otadata +#runner = "espflash flash --monitor --partition-table partitions.csv -b no-reset" # create upgrade image file for webupload +# runner = espflash erase-parts otadata //ensure flash is clean rustflags = [ "--cfg", "espidf_time64"] # Extending time_t for ESP IDF 5: https://github.com/esp-rs/rust/issues/110 diff --git a/rust/Cargo.toml b/rust/Cargo.toml index d451cfc..3970b6d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -37,7 +37,6 @@ partition_table = "partitions.csv" [features] default = ["std", "embassy", "esp-idf-svc/native"] - pio = ["esp-idf-svc/pio"] std = ["alloc", "esp-idf-svc/binstart", "esp-idf-svc/std"] alloc = ["esp-idf-svc/alloc"] @@ -46,38 +45,49 @@ experimental = ["esp-idf-svc/experimental"] embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-svc/embassy-time-driver"] [dependencies] -log = { version = "0.4", default-features = false } -serde = { version = "1.0.192", features = ["derive"] } -average = { version = "0.14.1" , features = ["std"] } -#esp32 = "0.28.0" -bit_field = "0.10.2" +#ESP stuff +embedded-svc = { version = "0.28.0", features = ["experimental"] } +esp-idf-hal = "0.44.1" +esp-idf-sys = { version = "0.35.0", features = ["binstart", "native"] } +esp-idf-svc = { version = "0.49.1", default-features = false } +embedded-hal = "1.0.0" +heapless = { version = "0.8", features = ["serde"] } +embedded-hal-bus = { version = "0.2.0", features = ["std"] } + +#Hardware additional driver ds18b20 = "0.1.1" -embedded-svc = { version = "0.27.0", features = ["experimental"] } -esp-idf-hal = "0.43.0" -esp-idf-sys = { version = "0.34.0", features = ["binstart", "native"] } -esp-idf-svc = { version = "0.48.0", default-features = false } -esp_idf_build = "0.1.3" +bq34z100 = { version = "0.3.0", features = ["flashstream"] } +one-wire-bus = "0.1.1" +ds323x = "0.5.1" + +#pure code dependencies +log = { version = "0.4", default-features = false } +once_cell = "1.19.0" +anyhow = { version = "1.0.75", features = ["std", "backtrace"] } +average = { version = "0.14.1" , features = ["std"] } +bit_field = "0.10.2" +strum = { version = "0.26.1", features = ["derive"] } +measurements = "0.11.0" +schemars = "0.8.16" + +#json +serde = { version = "1.0.192", features = ["derive"] } +serde_json = "1.0.108" + +#timezone chrono = { version = "0.4.23", default-features = false , features = ["iana-time-zone" , "alloc"] } chrono-tz = {version="0.8.0", default-features = false , features = [ "filter-by-regex" ]} -embedded-hal = "1.0.0" -one-wire-bus = "0.1.1" -anyhow = { version = "1.0.75", features = ["std", "backtrace"] } -schemars = "0.8.16" -heapless = { version = "0.8", features = ["serde"] } -serde_json = "1.0.108" -strum = { version = "0.26.1", features = ["derive"] } -once_cell = "1.19.0" -measurements = "0.11.0" -bq34z100 = { version = "0.3.0" , features = ["flashstream"] } + [patch.crates-io] #esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal.git" } -esp-idf-hal = { git = "https://github.com/empirephoenix/esp-idf-hal.git" } +#esp-idf-hal = { git = "https://github.com/empirephoenix/esp-idf-hal.git" } #esp-idf-sys = { git = "https://github.com/empirephoenix/esp-idf-sys.git" } #esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys.git" } #esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf-svc.git" } -#bq34z100 = { path = "../../bq34z100_rust" } +ds323x = { git = "https://github.com/empirephoenix/ds323x-rs.git" } +bq34z100 = { path = "../../bq34z100_rust" } [build-dependencies] -embuild = "0.31.3" +embuild = "0.32.0" vergen = { version = "8.2.6", features = ["build", "git", "gitcl"] } diff --git a/rust/src/plant_hal.rs b/rust/src/plant_hal.rs index fff6338..c15839f 100644 --- a/rust/src/plant_hal.rs +++ b/rust/src/plant_hal.rs @@ -1,10 +1,12 @@ use bq34z100::{Bq34Z100Error, Bq34z100g1, Bq34z100g1Driver}; use chrono_tz::Europe::Berlin; +use ds323x::Ds323x; +use embedded_hal_bus::i2c::MutexDevice; use embedded_svc::wifi::{ AccessPointConfiguration, AccessPointInfo, AuthMethod, ClientConfiguration, Configuration, }; -use esp_idf_hal::adc::attenuation; +use esp_idf_hal::adc::{attenuation, Resolution}; use esp_idf_hal::adc::oneshot::config::AdcChannelConfig; use esp_idf_hal::adc::oneshot::{AdcChannelDriver, AdcDriver}; use esp_idf_hal::i2c::{APBTickType, I2cConfig, I2cDriver, I2cError}; @@ -24,6 +26,7 @@ use anyhow::anyhow; use anyhow::{bail, Ok, Result}; use std::ffi::CString; use std::fs::File; +use std::ops::Deref; use std::path::Path; use chrono::{DateTime, Utc}; @@ -219,7 +222,8 @@ pub struct PlantCtrlBoard<'a> { pub wifi_driver: EspWifi<'a>, one_wire_bus: OneWire>, mqtt_client: Option>, - battery_driver: Option, Delay>>, + battery_driver: Option>, Delay>>, + rtc: Option>>, ds323x::ic::DS3231>> } impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> { @@ -1013,7 +1017,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> { } fn print_battery( - battery_driver: &mut Bq34z100g1Driver, + battery_driver: &mut Bq34z100g1Driver>, Delay>, ) -> Result<(), Bq34Z100Error> { println!("Try communicating with battery"); let fwversion = battery_driver.fw_version().unwrap_or_else(|e| { @@ -1084,20 +1088,24 @@ impl CreatePlantHal<'_> for PlantHal { let sda = peripherals.pins.gpio20.downgrade(); let driver = I2cDriver::new(i2c, sda, scl, &config).unwrap(); - let i2c_port = driver.port(); let mut timeout: i32 = 0; esp!(unsafe { esp_idf_sys::i2c_get_timeout(i2c_port, &mut timeout) }).unwrap(); println!("init i2c timeout is {}", timeout); - //esp!(unsafe { esp_idf_sys::i2c_set_timeout(i2c_port, 22)}).unwrap(); + let i2c_mutex = Arc::new(Mutex::new(driver)); - let mut battery_driver: Bq34z100g1Driver = Bq34z100g1Driver { - i2c: driver, + let i2c_battery_device = MutexDevice::new(&i2c_mutex); + + let mut battery_driver: Bq34z100g1Driver, Delay> = Bq34z100g1Driver { + i2c: i2c_battery_device, delay: Delay::new(0), flash_block_data: [0; 32], }; + let i2c_rtc_device = MutexDevice::new(&i2c_mutex); + let rtc = Ds323x::new_ds3231(i2c_rtc_device); + let mut clock = PinDriver::input_output(peripherals.pins.gpio15.downgrade())?; clock.set_pull(Pull::Floating).unwrap(); let mut latch = PinDriver::input_output(peripherals.pins.gpio3.downgrade())?; @@ -1139,6 +1147,8 @@ impl CreatePlantHal<'_> for PlantHal { ResetReason::Brownout => true, ResetReason::TaskWatchdog => true, ResetReason::DeepSleep => false, + ResetReason::USBPeripheral => true, + ResetReason::JTAG => true, }; if reset_store { println!("Clear and reinit RTC store"); @@ -1212,7 +1222,7 @@ impl CreatePlantHal<'_> for PlantHal { let adc_config = AdcChannelConfig { attenuation: attenuation::DB_11, - resolution: esp_idf_hal::adc::config::Resolution::Resolution12Bit, + resolution: Resolution::Resolution12Bit, calibration: true, }; let tank_driver = AdcDriver::new(peripherals.adc1)?; @@ -1265,8 +1275,8 @@ impl CreatePlantHal<'_> for PlantHal { signal_counter: counter_unit1, wifi_driver, mqtt_client: None, - //battery_driver: None, battery_driver: Some(battery_driver), + rtc: Some(rtc) }); let _ = rv.lock().is_ok_and(|mut board| { diff --git a/rust/src/webserver/0100_2_02-bq34z100.df.fs b/rust/src/webserver/0100_2_02-bq34z100.df.fs deleted file mode 100644 index c859afc..0000000 --- a/rust/src/webserver/0100_2_02-bq34z100.df.fs +++ /dev/null @@ -1,197 +0,0 @@ -;-------------------------------------------------------- -;Verify Existing Firmware Version -;-------------------------------------------------------- -W: AA 00 01 00 -C: AA 00 00 01 -W: AA 00 02 00 -C: AA 00 02 02 -;-------------------------------------------------------- -;Unseal device -;-------------------------------------------------------- -W: AA 00 14 04 -W: AA 00 72 36 -W: AA 00 FF FF -W: AA 00 FF FF -X: 1000 -;-------------------------------------------------------- -;Go To ROM Mode -;-------------------------------------------------------- -W: AA 00 00 0F -X: 1000 -;-------------------------------------------------------- -;Data Block -;-------------------------------------------------------- -W: 16 00 03 00 00 -W: 16 64 03 00 -X: 20 -C: 16 66 00 -W: 16 00 02 00 00 00 EA FF 33 FA FA 33 B5 FB 33 95 FE 33 AD FE 33 FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F FF FF 3F 02 02 3F 58 CB 33 C3 A0 08 1F 00 00 00 00 00 FF AA 0E FB A7 0E FF A6 0E FF A1 0E FF A0 0E FE A3 0E 54 A2 0E DE FF 3A 67 FF 3A E2 FF 33 FF AF 0E -W: 16 64 3D 38 -X: 2 -C: 16 66 00 -W: 16 00 02 01 00 00 01 4F 03 3F 11 0C D9 FF 30 E0 FF 35 2F 10 0C E0 FF 35 FF FF 23 E3 AF 04 E2 BF 04 D1 FF 36 E2 A0 04 E3 A1 04 00 C7 02 01 C6 02 E5 AF 04 E3 BF 01 E4 AF 04 E2 BF 01 FF AC 0E E1 1C 04 8A FF 31 E2 A0 04 E3 A1 04 02 AB 18 7F 2B 0E FF 1B 0E BF FF 32 FC FA 0E FB AF 0C 02 2B 18 FF 1B 0E 98 FF 36 -W: 16 64 AE 2C -X: 2 -C: 16 66 00 -W: 16 00 05 -W: 16 64 05 00 -X: 170 -C: 16 66 00 -C: 16 04 0A 91 AF DC -W: 16 00 0C 00 00 00 83 DE -W: 16 64 6D 01 -X: 400 -C: 16 66 00 -W: 16 00 0A 00 00 00 7E 22 B7 35 92 38 D0 0B F9 F1 E5 BC 00 00 14 B0 51 F6 C9 F4 14 52 09 21 32 6D 00 00 00 00 D0 7E -W: 16 64 0B 0D -X: 2 -C: 16 66 00 -W: 16 00 0A 01 00 00 17 DF 00 00 17 F3 00 00 3A 36 FD 91 00 25 30 01 00 EF 02 11 05 01 00 00 10 01 00 3C 00 50 3C 00 -W: 16 64 40 06 -X: 2 -C: 16 66 00 -W: 16 00 0A 02 00 00 64 3C 00 20 03 E8 00 00 04 10 68 FE D5 FB 95 00 02 00 14 03 E8 01 00 01 F4 00 1E 00 3C 0E 10 00 -W: 16 64 05 08 -X: 2 -C: 16 66 00 -W: 16 00 0A 03 00 00 0A 46 05 32 01 0F 01 F4 00 64 46 50 0A 0D 0C 0C C0 01 90 00 64 19 00 01 00 14 00 01 00 14 03 23 -W: 16 64 E0 04 -X: 2 -C: 16 66 00 -W: 16 00 0A 04 00 00 07 08 25 5A 32 0F 64 60 00 A0 0B B8 00 C8 28 01 F4 00 00 00 00 00 00 00 00 00 00 43 80 04 00 00 -W: 16 64 B0 05 -X: 2 -C: 16 66 00 -W: 16 00 0A 05 00 00 0F 00 2A 04 0A 7D 00 00 01 0A FE 76 E7 54 00 28 03 E8 02 01 2C F0 00 04 18 0D 5B 0D 28 0D 02 0D -W: 16 64 94 06 -X: 2 -C: 16 66 00 -W: 16 00 0A 06 00 00 0A 0D 06 0D 06 0D 07 0D 06 0D 05 0D 04 0D 04 0D 03 0D 08 0D 04 0C F9 0C ED 0C EC 0C E0 0C DA 0C -W: 16 64 A5 05 -X: 2 -C: 16 66 00 -W: 16 00 0A 07 00 00 D6 0C D7 0C DA 0C D9 0C D9 0C D8 0C D5 0C D2 0C D2 0C D0 0C C9 0C BE 0C B4 0C A7 0C 9A 0C 8A 0C -W: 16 64 31 0D -X: 2 -C: 16 66 00 -W: 16 00 0A 08 00 00 85 0C 7E 0C 2D 0B 64 09 64 FD 9E 03 6B 05 37 00 58 01 FA 01 D6 01 17 01 50 01 94 01 E2 01 CE 02 -W: 16 64 57 09 -X: 2 -C: 16 66 00 -W: 16 00 0A 09 00 00 62 FF 67 01 99 03 7D 05 9C 00 DA 02 CB 03 AD 04 A1 04 72 02 F1 03 A0 03 85 03 E7 04 86 04 EE 02 -W: 16 64 8E 0B -X: 2 -C: 16 66 00 -W: 16 00 0A 0A 00 00 AB 01 0C FE D1 FE EE FF 28 FF 76 FF 51 00 13 00 88 FE 42 FD 29 05 9B 23 48 FF 7E FF 8B FF 6C FF -W: 16 64 F0 11 -X: 2 -C: 16 66 00 -W: 16 00 0A 0B 00 00 46 FF 97 FF 8D FF 97 FF 98 FF 84 FF 8C FF AB FF B1 FF B1 FF 92 FF 74 FF 35 FF 0B FF 06 FF 5E FF -W: 16 64 65 17 -X: 2 -C: 16 66 00 -W: 16 00 0A 0C 00 00 13 FF 17 FF 10 FE C7 FE D8 FF 0C FF 05 FE E3 FF 2E FF 1D FE B7 00 00 01 C2 00 32 FF CE 02 26 64 -W: 16 64 25 11 -X: 2 -C: 16 66 00 -W: 16 00 0A 0D 00 00 7B 1F BE 77 60 7E 00 00 00 00 64 00 19 00 64 28 63 5F 64 62 00 64 00 1E 00 B4 00 64 00 F0 00 FA -W: 16 64 D9 08 -X: 2 -C: 16 66 00 -W: 16 00 0A 0E 00 00 11 10 10 68 49 FA 18 37 09 18 00 04 00 14 00 00 0A F0 00 0A 05 00 32 01 C2 14 14 00 00 3C 00 4B -W: 16 64 29 05 -X: 2 -C: 16 66 00 -W: 16 00 0A 0F 00 00 00 28 00 3C 3C 01 90 36 72 04 14 FF FF FF FF 01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10 04 -W: 16 64 02 0E -X: 2 -C: 16 66 00 -W: 16 00 0A 10 00 00 01 75 FE 79 08 1E FF 83 7F FF 00 AF 00 04 0A 64 01 00 3C 00 00 00 00 00 00 00 00 00 00 00 00 00 -W: 16 64 8B 06 -X: 2 -C: 16 66 00 -W: 16 00 0A 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -W: 16 64 1B 00 -X: 2 -C: 16 66 00 -W: 16 00 0A 12 00 00 02 26 02 01 F4 02 58 02 02 26 0E 00 00 00 00 00 00 00 00 00 00 00 00 17 00 DC 84 E5 5F 60 1C 0E -W: 16 64 12 05 -X: 2 -C: 16 66 00 -W: 16 00 0A 13 00 00 10 00 21 00 01 00 01 03 E8 64 17 70 64 00 FE 70 10 68 10 68 10 04 0A 32 1E 00 0A 2D 37 01 01 03 -W: 16 64 C9 05 -X: 2 -C: 16 66 00 -W: 16 00 0A 14 00 00 0B 62 71 33 34 7A 31 30 30 2D 47 31 0B 54 65 78 61 73 20 49 6E 73 74 2E 04 4C 49 46 4F 00 96 00 -W: 16 64 D3 08 -X: 2 -C: 16 66 00 -W: 16 00 0A 15 00 00 AF 00 4B 00 64 0A F0 02 0B 54 10 CC 02 10 68 64 01 03 05 00 00 00 00 00 00 00 00 00 00 00 00 00 -W: 16 64 9B 04 -X: 2 -C: 16 66 00 -W: 16 00 0A 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF -W: 16 64 13 0D -X: 2 -C: 16 66 00 -W: 16 00 0A 17 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF -W: 16 64 01 20 -X: 2 -C: 16 66 00 -W: 16 00 0A 18 00 00 FF 55 00 1A 00 1C 00 23 00 35 00 1E 00 20 00 27 00 22 00 25 00 42 00 3F 00 41 00 76 00 9D 02 0A -W: 16 64 91 04 -X: 2 -C: 16 66 00 -W: 16 00 0A 19 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -W: 16 64 23 00 -X: 2 -C: 16 66 00 -W: 16 00 0A 1A 00 00 FF FF 00 1A 00 1C 00 23 00 35 00 1E 00 20 00 27 00 22 00 25 00 42 00 3F 00 41 00 76 00 9D 02 0A -W: 16 64 3D 05 -X: 2 -C: 16 66 00 -W: 16 00 0A 1B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -W: 16 64 25 00 -X: 2 -C: 16 66 00 -W: 16 00 0A 1C 00 00 11 10 10 68 49 FA 18 37 09 18 00 04 00 14 00 00 0A F0 00 0A 05 00 32 01 C2 14 14 00 00 3C 00 4B -W: 16 64 37 05 -X: 2 -C: 16 66 00 -W: 16 00 0A 1D 00 00 00 28 00 3C 3C 01 90 36 72 04 14 FF FF FF FF 01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10 04 -W: 16 64 10 0E -X: 2 -C: 16 66 00 -W: 16 00 0A 1E 00 00 FF FF FF FF 00 00 02 6B FF FF FD 93 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF -W: 16 64 0B 1C -X: 2 -C: 16 66 00 -W: 16 00 0A 1F 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF -W: 16 64 09 20 -X: 2 -C: 16 66 00 -W: 16 00 08 -W: 16 64 08 00 -X: 2 -C: 16 66 00 -C: 16 04 F1 4C -W: 16 00 05 -W: 16 64 05 00 -X: 170 -C: 16 66 00 -C: 16 04 0A 91 AF DC -W: 16 00 01 00 00 05 54 54 15 -W: 16 64 C3 00 -X: 20 -C: 16 66 00 -W: 16 00 05 -W: 16 64 05 00 -X: 170 -C: 16 66 00 -C: 16 04 5F E5 84 DC -;-------------------------------------------------------- -;Execute Flash Code -;-------------------------------------------------------- -W: 16 00 0F -W: 16 64 0F 00 -X: 4000 diff --git a/rust/src/webserver/webserver.rs b/rust/src/webserver/webserver.rs index 6343e79..835ea3d 100644 --- a/rust/src/webserver/webserver.rs +++ b/rust/src/webserver/webserver.rs @@ -9,10 +9,9 @@ use std::{ use crate::{espota::OtaUpdate, BOARD_ACCESS}; use core::result::Result::Ok; -use embedded_svc::http::{Method}; +use embedded_svc::http::Method; use esp_idf_hal::delay::Delay; use esp_idf_svc::http::server::{Configuration, EspHttpServer}; -use esp_idf_sys::vTaskDelay; use heapless::String; use serde::{Deserialize, Serialize};