adjust folder to be shorter

This commit is contained in:
2023-11-20 01:46:19 +01:00
parent 2092354bc9
commit 17db1b8a45
14 changed files with 166 additions and 79 deletions

17
rust/.cargo/config.toml Normal file
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
rust/.gitignore vendored Normal file
View File

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

8
rust/.idea/.gitignore generated 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>

8
rust/.idea/modules.xml generated Normal file
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>

11
rust/.idea/plant-ctrl2.iml generated Normal file
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>

6
rust/.idea/vcs.xml generated Normal file
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
rust/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
rust/build.rs Normal file
View File

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

2
rust/rust-toolchain.toml Normal file
View File

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

10
rust/sdkconfig.defaults Normal file
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
rust/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

166
rust/src/main.rs Normal file
View File

@@ -0,0 +1,166 @@
use chrono::Utc;
use embedded_hal::digital::v1_compat::OldOutputPin;
use esp_idf_hal::adc::config::Config;
use esp_idf_hal::adc::{AdcDriver, AdcChannelDriver, attenuation};
use shift_register_driver::sipo::{ShiftRegister24, ShiftRegisterPin};
use esp_idf_hal::gpio::PinDriver;
use esp_idf_hal::prelude::Peripherals;
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;
struct BatteryState {
state_charge_percent: u8,
max_error_percent: u8,
remaining_milli_ampere_hour: u32,
max_milli_ampere_hour: u32,
design_milli_ampere_hour:u32,
voltage_milli_volt: u16,
average_current_milli_ampere: u16,
temperature_tenth_kelvin: u32,
average_time_to_empty_minute: u16,
average_time_to_full_minute: u16,
average_discharge_power_cycle_milli_watt: u16,
cycle_count: u16,
state_health_percent: u8
}
trait PlantCtrlBoardInteraction{
fn battery_state() -> BatteryState;
fn is_day() -> bool;
fn water_temperature_c() -> u16;
fn tank_sensor_mv() -> u16;
fn set_low_voltage_in_cycle();
fn clear_low_voltage_in_cycle();
fn low_voltage_in_cycle(low_voltage:bool);
//keep state during deepsleep
fn light(enable:bool);
fn plant_count() -> i8;
fn measure_moisture_b_hz(plant:i8) -> i16;
fn measure_moisture_a_hz(plant:i8) -> i16;
fn measure_moisture_p_hz(plant:i8) -> i16;
fn pump(plant:i8, enable:bool);
fn last_pump_time(plant:i8) -> chrono::DateTime<Utc>;
fn store_last_pump_time(plant:i8, time: chrono::DateTime<Utc>);
fn store_consecutive_pump_count(plant:i8, count:i16);
fn consecutive_pump_count(plant:i8) -> i16;
//keep state during deepsleep
fn fault(plant:i8, enable:bool);
fn default() -> Self;
}
trait Plant{
fn setPump(pump:bool);
}
struct PlantHal<'d>{
pump:ShiftRegisterPin<'d>
}
struct PlantCtrlBoard{
dummy:i32
}
impl PlantCtrlBoardInteraction for PlantCtrlBoard {
fn default() -> Self {
let peripherals = Peripherals::take().unwrap();
let mut adc = AdcDriver::new(peripherals.adc1, &Config::new().calibration(true)).unwrap();
let mut adc_pin: esp_idf_hal::adc::AdcChannelDriver<{ attenuation::DB_11 }, _> = AdcChannelDriver::new(peripherals.pins.gpio39).unwrap();
let analog_value = adc.read(&mut adc_pin);
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 }
}
fn plant_count() -> i8 {
todo!()
}
fn fault(plant:i8, state:bool) {
todo!()
}
fn pump(plant:i8, state:bool) {
todo!()
}
fn battery_state() -> BatteryState {
todo!()
}
fn is_day() -> bool {
todo!()
}
fn water_temperature_c() -> u16 {
todo!()
}
fn tank_sensor_mv() -> u16 {
todo!()
}
fn light(enable:bool) {
todo!()
}
fn measure_moisture_b_hz(plant:i8) -> i16 {
todo!()
}
fn measure_moisture_a_hz(plant:i8) -> i16 {
todo!()
}
fn measure_moisture_p_hz(plant:i8) -> i16 {
todo!()
}
fn last_watering_time(plant:i8) -> chrono::DateTime<Utc> {
todo!()
}
}
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();
}