chanched GPIO Pin configuration

This commit is contained in:
Philipp_EndevourOS 2025-08-11 14:27:41 +02:00
parent a015d6b983
commit 6831d7776c
4 changed files with 34 additions and 56 deletions

29
Cargo.lock generated
View File

@ -1038,7 +1038,6 @@ dependencies = [
"picoserve",
"smoltcp",
"static_cell",
"ws2812-spi",
]
[[package]]
@ -1522,15 +1521,6 @@ 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"
@ -1652,15 +1642,6 @@ 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"
@ -2050,16 +2031,6 @@ 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"

View File

@ -61,7 +61,6 @@ picoserve = { version = "0.16.0", features = ["embassy", "log"] }
embassy-sync = { version = "0.7.0", features = ["log"] }
ds3231 = { version = "0.3.0", features = ["async", "temperature_f32"] }
ws2812-spi = "0.5.1"
chrono = { version = "0.4.41", default-features = false }
dir-embed = "0.3.0"

View File

@ -14,7 +14,7 @@ pub enum FeedbackState {
}
#[embassy_executor::task]
pub async fn feedback_task(buzzer: peripherals::GPIO19<'static>) {
pub async fn feedback_task(buzzer: peripherals::GPIO21<'static>) {
debug!("Starting feedback task");
let mut buzzer = init::hardware::setup_buzzer(buzzer);
loop {

View File

@ -2,13 +2,14 @@ use embassy_executor::Spawner;
use embassy_net::{Stack, driver};
use embassy_sync::blocking_mutex::Mutex;
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
use esp_hal::config;
use esp_hal::gpio::{Input, Pull};
use esp_hal::i2c::master::Config;
use esp_hal::peripherals::{
self, GPIO0, GPIO1, GPIO3, GPIO4, GPIO5, GPIO6, GPIO7, GPIO19, GPIO21, GPIO22, GPIO23, I2C0,
self, GPIO0, GPIO1, GPIO2, GPIO21, GPIO22, GPIO23, GPIO16, GPIO17, GPIO20, GPIO10, GPIO19, GPIO6, GPIO7, I2C0,
UART1,
};
use esp_hal::spi::master::Spi;
use esp_hal::spi::master::Config as Spi_config;
use esp_hal::time::Rate;
use esp_hal::{
Async,
@ -27,14 +28,18 @@ use crate::init::wifi;
/*************************************************
* GPIO Pinout Xiao Esp32c6
*
* D0 -> GPIO0 -> Level Shifter OE
* D1 -> GPIO1 -> Level Shifter A0 -> LED
* D3 -> GPIO21 -> SQW Interrupt RTC //not in use anymore
* D4 -> GPIO22 -> SDA
* D5 -> GPIO23 -> SCL
* D7 -> GPIO17 -> Level Shifter A1 -> NFC Reader
* D8 -> GPIO19 -> Buzzer
*
* D0 -> GPIO0 -> Level Shifter OE
* D1 -> GPIO1 -> Level Shifter A0 -> LED
* D2 -> GPIO2 -> SPI/CS
* D3 -> GPIO21 -> Buzzer
* D4 -> GPIO22 -> I2C/SDA
* D5 -> GPIO23 -> I2C/SCL
* D6 -> GPIO16 -> UART/TX
* D7 -> GPIO17 -> UART/RX -> Level Shifter A1 -> NFC Reader
* D8 -> GPIO19 -> SPI/SCLK
* D9 -> GPIO20 -> SPI/MISO
* D10 -> GPIO10 -> SPI/MOSI
*
*************************************************/
#[panic_handler]
@ -52,7 +57,7 @@ pub async fn hardware_init(
Uart<'static, Async>,
Stack<'static>,
I2c<'static, Async>,
GPIO19<'static>,
GPIO21<'static>,
) {
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
@ -74,11 +79,21 @@ pub async fn hardware_init(
init_lvl_shifter(peripherals.GPIO0);
let uart_device = setup_uart(peripherals.UART1, peripherals.GPIO7, peripherals.GPIO6);
let uart_device = setup_uart(peripherals.UART1, peripherals.GPIO16, peripherals.GPIO17);
let i2c_device = setup_i2c(peripherals.I2C0, peripherals.GPIO22, peripherals.GPIO23);
let buzzer_gpio = peripherals.GPIO19;
let buzzer_gpio = peripherals.GPIO21;
let spi = match Spi::new(peripherals.SPI2 , Spi_config::default()) {
Ok(spi) => spi.with_mosi(peripherals.GPIO18).with_miso(peripherals.GPIO20),
Err(e) => {
error!("Failed to initialize I2C: {:?}", e);
panic!(); //TODO panic!
}
};
debug!("hardware init done");
@ -94,8 +109,8 @@ fn init_lvl_shifter(oe_pin: GPIO0<'static>) {
fn setup_uart(
uart1: UART1<'static>,
uart_rx: GPIO7<'static>,
uart_tx: GPIO6<'static>,
uart_tx: GPIO16<'static>,
uart_rx: GPIO17<'static>,
) -> Uart<'static, Async> {
let uard_device = Uart::new(uart1, esp_hal::uart::Config::default().with_baudrate(9600));
@ -103,7 +118,7 @@ fn setup_uart(
Ok(block) => block.with_rx(uart_rx).with_tx(uart_tx).into_async(),
Err(e) => {
error!("Failed to initialize UART: {e}");
panic!();
panic!(); //TODO panic!
}
}
}
@ -119,20 +134,13 @@ fn setup_i2c(
Ok(i2c) => i2c.with_sda(sda).with_scl(scl).into_async(),
Err(e) => {
error!("Failed to initialize I2C: {:?}", e);
panic!();
panic!(); //TODO panic!
}
};
i2c
}
pub async fn setup_rtc_iterrupt(sqw_pin: GPIO21<'static>) -> Input<'static> {
debug!("init rtc interrupt");
let config = esp_hal::gpio::InputConfig::default().with_pull(Pull::Up); //Active low interrupt in rtc
let sqw_interrupt = Input::new(sqw_pin, config);
sqw_interrupt
}
pub fn setup_buzzer(buzzer_gpio: GPIO19<'static>) -> Output<'static> {
pub fn setup_buzzer(buzzer_gpio: GPIO21<'static>) -> Output<'static> {
let config = esp_hal::gpio::OutputConfig::default()
.with_drive_strength(esp_hal::gpio::DriveStrength::_40mA);
let buzzer = Output::new(buzzer_gpio, esp_hal::gpio::Level::Low, config);