eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 11f07441cf1126147d1bccd3a8cb63896f80a35a
parent f7e7e0dced293b663ba2d021308793b8be3a9b8b
Author: Daniel Barlow <dan@telent.net>
Date:   Fri, 14 Nov 2025 22:10:56 +0000

write honda k-line init sequence

per the logic analyser, the tx line goes up and down for the requist
number of milliseconds, then it goes up and down some more, faster,
when I send bytes. the first four bytes take ~ 3 seconds, so I guess
that's 10400 baud maybe

Diffstat:
Msrc/bin/main.rs | 57++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 52 insertions(+), 5 deletions(-)

diff --git a/src/bin/main.rs b/src/bin/main.rs @@ -12,6 +12,7 @@ use esp_hal::{ timer::timg::TimerGroup, gpio::{Level, Output, OutputConfig}, clock::CpuClock, + uart::{Uart,Config,DataBits}, main, }; // use esp_hal::clock::CpuClock; @@ -34,7 +35,12 @@ fn main() -> ! { esp_println::logger::init_logger_from_env(); let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max()); - let peripherals = esp_hal::init(config); + let mut peripherals = esp_hal::init(config); + + // XXX what is this for? + // apparently it's copyable whatever it is as no complaints + // when I call >1 function with it as param + let output_config = OutputConfig::default(); esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 66320); @@ -48,14 +54,55 @@ fn main() -> ! { let radio_init = esp_radio::init().expect("Failed to initialize Wi-Fi/BLE controller"); let _connector = BleConnector::new(&radio_init, peripherals.BT, Default::default()); - let mut led = Output::new(peripherals.GPIO0, Level::High, OutputConfig::default()); + let mut led = Output::new(peripherals.GPIO8, Level::High, output_config); led.set_high(); let delay = Delay::new(); + let tx = peripherals.GPIO21.reborrow(); + + let mut output = Output::new(tx, Level::High, OutputConfig::default()); + + // this is just so that I can distinguish where my code actually + // starts running when I look at the signal analyser + + info!("waiting..."); + delay.delay_millis(2000); + output.set_low(); + delay.delay_millis(20); + output.set_high(); + delay.delay_millis(2000); + + info!("let's go!"); + + output.set_low(); + delay.delay_millis(70); + output.set_high(); + delay.delay_millis(120); + + let mut uart = Uart::new( + peripherals.UART0, + esp_hal::uart::Config::default() + .with_baudrate(10_400) + .with_data_bits(DataBits::_8) + ) + .expect("now I got a reason") + .with_rx(peripherals.GPIO20) + .with_tx(peripherals.GPIO21.reborrow()); + + uart.write(b"\xfe\x04\xff\xff").expect("write failed"); + let _ = uart.flush(); + delay.delay_millis(200); + uart.write(b"\x72\x05\x00\xF0\x99").expect("write 2 failed"); + let _ = uart.flush(); + loop { - info!("Hello world!"); - led.toggle(); - delay.delay_millis(500); + info!("waiting"); + let mut buf = [0u8; 80]; + let bytes = uart.read(&mut buf[..]).expect("read failed"); + if bytes>0 { led.toggle(); } + + info!("got {bytes}"); + delay.delay_millis(50); } // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0/examples/src/bin