rust init

This commit is contained in:
Empire 2023-11-20 00:05:47 +01:00
parent ec67450a0a
commit ae8ff86c1a
14 changed files with 224 additions and 0 deletions

View File

@ -0,0 +1,17 @@
[build]
target = "xtensa-esp32-espidf"
[target.xtensa-esp32-espidf]
linker = "ldproxy"
# runner = "espflash --monitor" # Select this runner for espflash v1.x.x
runner = "espflash flash --monitor" # Select this runner for espflash v2.x.x
rustflags = [ "--cfg", "espidf_time64"] # Extending time_t for ESP IDF 5: https://github.com/esp-rs/rust/issues/110
[unstable]
build-std = ["std", "panic_abort"]
[env]
MCU="esp32"
# Note: this variable is not used by the pio builder (`cargo build --features pio`)
ESP_IDF_VERSION = "v5.1.1"

4
plant-ctrl2/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/.vscode
/.embuild
/target
/Cargo.lock

8
plant-ctrl2/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/plant-ctrl2.iml" filepath="$PROJECT_DIR$/.idea/plant-ctrl2.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

58
plant-ctrl2/Cargo.toml Normal file
View File

@ -0,0 +1,58 @@
[package]
name = "plant-ctrl2"
version = "0.1.0"
authors = ["Empire Phoenix"]
edition = "2021"
resolver = "2"
rust-version = "1.71"
[profile.release]
opt-level = "s"
strip = true
lto = "fat"
codegen-units = 1
[profile.dev]
debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "s"
lto = "fat"
codegen-units = 1
[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"]
nightly = ["esp-idf-svc/nightly"]
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 }
esp-idf-svc = { version = "0.47.3", default-features = false }
serde = { version = "1.0.192", features = ["derive"] }
minimq = "0.8.0"
average = { version = "0.14.1" , features = ["std"] }
esp32 = "0.27.0"
bit_field = "0.10.2"
ds18b20 = "0.1.1"
embedded-svc = { version = "0.26.4", features = ["experimental"] }
esp-idf-hal = "0.42.5"
esp-idf-sys = { version = "0.33.7", features = ["binstart", "native"] }
esp-ota = "0.2.0"
esp_idf_build = "0.1.3"
datetime = "0.5.2"
build-time = "0.1.2"
chrono = { version = "0.4.23", default-features = false , features = ["iana-time-zone"] }
chrono-tz = "0.8.0"
paste = "1.0.14"
embedded-hal = "0.2.7"
dummy-pin = "0.1.1"
shift-register-driver = "0.1.1"
#?bq34z100 required
[build-dependencies]
embuild = "0.31.3"

3
plant-ctrl2/build.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
embuild::espidf::sysenv::output();
}

View File

@ -0,0 +1,2 @@
[toolchain]
channel = "esp"

View File

@ -0,0 +1,10 @@
# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K)
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8000
# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default).
# This allows to use 1 ms granuality for thread sleeps (10 ms by default).
#CONFIG_FREERTOS_HZ=1000
# Workaround for https://github.com/espressif/esp-idf/issues/7631
#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n
#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n

12
plant-ctrl2/setup.txt Normal file
View File

@ -0,0 +1,12 @@
cargo install cargo-generate
cargo install ldproxy
cargo install espup
cargo install espflash
cargo install cargo-espflash
cargo generate esp-rs/esp-idf-template cargo
export PATH="$PATH:$HOME/.cargo/bin"
espup install
rustup toolchain link esp ~/.rustup/toolchains/esp/
cargo install ldproxy

79
plant-ctrl2/src/main.rs Normal file
View File

@ -0,0 +1,79 @@
use embedded_hal::digital::v1_compat::OldOutputPin;
use shift_register_driver::sipo::{ShiftRegister24, ShiftRegisterPin};
use esp_idf_hal::gpio::{PinDriver};
use esp_idf_hal::prelude::Peripherals;
use dummy_pin::DummyPin;
use embedded_hal::digital::v2::OutputPin;
#[macro_use]
extern crate shift_register_driver;
trait PlantCtrlBoardInteraction{
fn measure_moisture() -> i16;
fn default() -> Self;
}
trait Plant{
fn setPump(pump:bool);
}
struct PlantHal<'d>{
pump:ShiftRegisterPin<'d>
}
struct PlantCtrlBoard{
dummy:i32
}
impl PlantCtrlBoardInteraction for PlantCtrlBoard {
fn measure_moisture() -> i16 {
//pcnr here
return 1_i16;
}
fn default() -> Self {
let peripherals = Peripherals::take().unwrap();
let clock = OldOutputPin::from(PinDriver::output(peripherals.pins.gpio21).unwrap());
let latch = OldOutputPin::from(PinDriver::output(peripherals.pins.gpio22).unwrap());
let data = OldOutputPin::from(PinDriver::output(peripherals.pins.gpio19).unwrap());
let shift_register = ShiftRegister24::new(clock, latch, data);
let registerOutput = shift_register.decompose();
Self { dummy: 12 }
}
}
const PLANT_COUNT:usize = 8;
#[link_section = ".rtc.data"]
static mut LAST_WATERING_TIMESTAMP: [u64; PLANT_COUNT] = [0; PLANT_COUNT];
#[link_section = ".rtc.data"]
static mut CONSECUTIVE_WATERING_PLANT: [u64; PLANT_COUNT] = [0; PLANT_COUNT];
#[link_section = ".rtc.data"]
static mut LOW_VOLTAGE_DETECTED:bool = false;
fn main() {
// It is necessary to call this function once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
esp_idf_svc::sys::link_patches();
// Bind the log crate to the ESP Logging facilities
esp_idf_svc::log::EspLogger::initialize_default();
log::info!("Hello, world!");
let board = PlantCtrlBoard::default();
}

Binary file not shown.