mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2026-05-01 02:59:09 +00:00
Compare commits
4 Commits
23bb1126a6
...
4dda9548d3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dda9548d3 | ||
|
|
46e207bd2a | ||
|
|
8cb118e0ee | ||
|
|
9b4df77112 |
115
Cargo.lock
generated
115
Cargo.lock
generated
@@ -275,6 +275,20 @@ dependencies = [
|
||||
"litrs 0.4.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ds3231"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06092da010fc293e78440557ff06ec633e06204d93a11e120c69be9a40745931"
|
||||
dependencies = [
|
||||
"bitfield 0.19.1",
|
||||
"cfg-if",
|
||||
"chrono",
|
||||
"embedded-hal 1.0.0",
|
||||
"maybe-async-cfg",
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "edge-dhcp"
|
||||
version = "0.6.0"
|
||||
@@ -970,6 +984,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"bleps",
|
||||
"critical-section",
|
||||
"ds3231",
|
||||
"edge-dhcp",
|
||||
"edge-nal",
|
||||
"edge-nal-embassy",
|
||||
@@ -990,6 +1005,7 @@ dependencies = [
|
||||
"picoserve",
|
||||
"smoltcp",
|
||||
"static_cell",
|
||||
"ws2812-spi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1164,6 +1180,43 @@ version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d"
|
||||
|
||||
[[package]]
|
||||
name = "manyhow"
|
||||
version = "0.11.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b33efb3ca6d3b07393750d4030418d594ab1139cee518f0dc88db70fec873587"
|
||||
dependencies = [
|
||||
"manyhow-macros",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "manyhow-macros"
|
||||
version = "0.11.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46fce34d199b78b6e6073abf984c9cf5fd3e9330145a93ee0738a7443e371495"
|
||||
dependencies = [
|
||||
"proc-macro-utils",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maybe-async-cfg"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8dbfaa67a76e2623580df07d6bb5e7956c0a4bae4b418314083a9c619bd66627"
|
||||
dependencies = [
|
||||
"manyhow",
|
||||
"proc-macro2",
|
||||
"pulldown-cmark",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "md-5"
|
||||
version = "0.10.6"
|
||||
@@ -1362,6 +1415,17 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-utils"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eeaf08a13de400bc215877b5bdc088f241b12eb42f0a548d3390dc1c56bb7071"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.95"
|
||||
@@ -1371,6 +1435,17 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pulldown-cmark"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "679341d22c78c6c649893cbd6c3278dcbe9fc4faa62fea3a9296ae2b50c14625"
|
||||
dependencies = [
|
||||
"bitflags 2.9.1",
|
||||
"memchr",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
@@ -1398,6 +1473,15 @@ version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||
|
||||
[[package]]
|
||||
name = "rgb"
|
||||
version = "0.8.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "riscv"
|
||||
version = "0.12.1"
|
||||
@@ -1513,6 +1597,21 @@ version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
||||
|
||||
[[package]]
|
||||
name = "smart-leds-trait"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edeb89c73244414bb0568611690dd095b2358b3fda5bae65ad784806cca00157"
|
||||
dependencies = [
|
||||
"rgb",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smoltcp"
|
||||
version = "0.12.0"
|
||||
@@ -1648,6 +1747,12 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
@@ -1896,6 +2001,16 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ws2812-spi"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2fd98e2b649252eced2ec3aa8d5048e7d2ac294276b0567939bbf47741f9934"
|
||||
dependencies = [
|
||||
"embedded-hal 1.0.0",
|
||||
"smart-leds-trait",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xtensa-lx"
|
||||
version = "0.12.0"
|
||||
|
||||
@@ -60,6 +60,9 @@ edge-nal-embassy = { version = "0.6.0", features = ["log"] }
|
||||
picoserve = { version = "0.16.0", features = ["embassy", "log"] }
|
||||
embassy-sync = { version = "0.7.0", features = ["log"] }
|
||||
|
||||
ds3231 = "0.3.0"
|
||||
ws2812-spi = "0.5.1"
|
||||
|
||||
|
||||
[profile.dev]
|
||||
# Rust debug is too slow.
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::Stack;
|
||||
use esp_hal::peripherals::{GPIO1, GPIO2, UART1};
|
||||
use esp_hal::peripherals::{self, GPIO0, GPIO1, GPIO3, GPIO4, GPIO5, GPIO6, GPIO7, GPIO22, GPIO23, I2C0, UART1};
|
||||
use esp_hal::time::Rate;
|
||||
use esp_hal::{
|
||||
Async,
|
||||
clock::CpuClock,
|
||||
timer::{systimer::SystemTimer, timg::TimerGroup},
|
||||
uart::Uart,
|
||||
i2c::master::I2c,
|
||||
gpio::{Output, OutputConfig}
|
||||
};
|
||||
use esp_println::logger::init_logger;
|
||||
use log::error;
|
||||
@@ -39,23 +42,63 @@ pub async fn hardware_init(spawner: &mut Spawner) -> (Uart<'static, Async>, Stac
|
||||
let interfaces = wifi::setup_wifi(timer1.timer0, rng, peripherals.WIFI, spawner);
|
||||
let stack = network::setup_network(network_seed, interfaces.ap, spawner);
|
||||
|
||||
let uart_devie = setup_uart(peripherals.UART1, peripherals.GPIO1, peripherals.GPIO2);
|
||||
init_lvl_shifter(peripherals.GPIO0);
|
||||
|
||||
(uart_devie, stack)
|
||||
let uart_device = setup_uart(peripherals.UART1, peripherals.GPIO7, peripherals.GPIO6);
|
||||
|
||||
let i2c_device = setup_i2c(peripherals.I2C0, peripherals.GPIO22, peripherals.GPIO23);
|
||||
|
||||
//TODO change to get I2C device back / maybe init for each protocol
|
||||
|
||||
(uart_device, stack)
|
||||
}
|
||||
|
||||
// Initialize the level shifter for the NFC reader and LED (output-enable (OE) input is low, all outputs are placed in the high-impedance (Hi-Z) state)
|
||||
fn init_lvl_shifter(oe_pin: GPIO0<'static>){
|
||||
let mut oe_lvl_shifter = Output::new(oe_pin, esp_hal::gpio::Level::Low, OutputConfig::default());
|
||||
oe_lvl_shifter.set_high();
|
||||
}
|
||||
|
||||
fn setup_uart(
|
||||
uart1: UART1<'static>,
|
||||
gpio1: GPIO1<'static>,
|
||||
gpio2: GPIO2<'static>,
|
||||
uart_rx: GPIO7<'static>,
|
||||
uart_tx: GPIO6<'static>,
|
||||
) -> Uart<'static, Async> {
|
||||
let uard_device = Uart::new(uart1, esp_hal::uart::Config::default().with_baudrate(9600));
|
||||
|
||||
match uard_device {
|
||||
Ok(block) => block.with_rx(gpio1).with_tx(gpio2).into_async(),
|
||||
Ok(block) => block.with_rx(uart_rx).with_tx(uart_tx).into_async(),
|
||||
Err(e) => {
|
||||
error!("Failed to initialize UART: {e}");
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_i2c(
|
||||
i2c0: I2C0<'static>,
|
||||
sda: GPIO22<'static>,
|
||||
scl: GPIO23<'static>,
|
||||
) -> I2c<'static, Async> {
|
||||
let config = esp_hal::i2c::master::Config::default().with_frequency(Rate::from_khz(400));
|
||||
let i2c_device = I2c::new(i2c0, config);
|
||||
match i2c_device {
|
||||
Ok(block) => block.with_sda(sda).with_scl(scl).into_async(),
|
||||
Err(e) => {
|
||||
error!("Failed to initialize I2C: {e}");
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_spi_led() {
|
||||
|
||||
}
|
||||
|
||||
fn setup_rtc() {
|
||||
//TODO
|
||||
//setup rtc with i2c
|
||||
//setup interrupt for SQW
|
||||
//setup 24-h alarm
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ mod webserver;
|
||||
type TallyChannel = PubSubChannel<NoopRawMutex, TallyID, 8, 2, 1>;
|
||||
type TallyPublisher = Publisher<'static, NoopRawMutex, TallyID, 8, 2, 1>;
|
||||
|
||||
static mut UTC_TIME: u64 = 0;
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(mut spawner: Spawner) {
|
||||
let (uart_device, stack) = init::hardware_init(&mut spawner).await;
|
||||
@@ -73,7 +75,7 @@ async fn rfid_reader_task(mut uart_device: Uart<'static, Async>, chan: TallyPubl
|
||||
debug!("Looking for NFC...");
|
||||
match uart_device.read_async(&mut uart_buffer).await {
|
||||
Ok(n) => {
|
||||
let mut hex_str = heapless::String::<128>::new();
|
||||
let mut hex_str = heapless::String::<64>::new();
|
||||
for byte in &uart_buffer[..n] {
|
||||
core::fmt::Write::write_fmt(&mut hex_str, format_args!("{:02X} ", byte)).ok();
|
||||
}
|
||||
|
||||
9
src/hardware/fram.rs
Normal file
9
src/hardware/fram.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
const DEVICE_TYPE_CODE: u8 = 0b10100000;
|
||||
|
||||
const DEVICE_ADDRESS_CODE: u8 = 0b000000; // 3 bits for device address | default A0 = 0 A1 = 0 A2 = 0
|
||||
|
||||
const WRITE_CODE: u8 = 0b00000000; // 0 for write
|
||||
const READ_CODE: u8 = 0b00000001; // 1 for read
|
||||
|
||||
const DEVICE_ADDRESS_WRITE: u8 = DEVICE_TYPE_CODE | DEVICE_ADDRESS_CODE | WRITE_CODE; // I2C address write for FRAM
|
||||
const DEVICE_ADDRESS_READ: u8 = DEVICE_TYPE_CODE | DEVICE_ADDRESS_CODE | READ_CODE; // I2C address read for FRAM
|
||||
0
src/hardware/rtc.rs
Normal file
0
src/hardware/rtc.rs
Normal file
Reference in New Issue
Block a user