diff --git a/src/main.rs b/src/main.rs index 6d70a4d..f192407 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ fn main() -> ! { // Bind the log crate to the ESP Logging facilities esp_idf_svc::log::EspLogger::initialize_default(); - log::info!("Hello, world!"); + log::info!("Hello, world! APP HAS INITIALIZED!!!!!"); let peripherals = Peripherals::take().unwrap(); let mut wav_tbl: [i16; TBL_LEN] = [0; TBL_LEN]; @@ -39,23 +39,33 @@ fn main() -> ! { // //i2s setup + log::info!("i2s setup..."); let std_config = StdConfig::philips(RATE, DataBitWidth::Bits16); let bclk = peripherals.pins.gpio1; let _din = peripherals.pins.gpio4; - let dout = peripherals.pins.gpio6; + let dout = peripherals.pins.gpio5; let mclk = AnyIOPin::none(); let ws = peripherals.pins.gpio2; - let mut i2s = - I2sDriver::::new_std_tx(peripherals.i2s0, &std_config, bclk, dout, mclk, ws) - .unwrap(); + log::info!("i2s driver setup..."); + let result = I2sDriver::::new_std_tx(peripherals.i2s0, &std_config, bclk, dout, mclk, ws); + if let Err(e) = result { + log::error!("Error Initializing I2sDriver!"); + log::error!("{:?}", e); + loop {std::thread::sleep(std::time::Duration::from_secs(5));} + } + let mut i2s = result.unwrap(); + log::info!("i2s tx enable ..."); i2s.tx_enable().unwrap(); + log::info!("Done! tx enabled!!!!"); - let mut buffer: [i16; 1024] = [0; 1024]; // Should be even length + const BUF_LEN: usize = 2046; + let mut buffer: [i16; BUF_LEN] = [0; BUF_LEN]; // Should be even length let mut phase: f32 = 0.0; let phase_delta = (440.0 / RATE as f32) * TBL_LEN as f32; let timeout = TickType::from(Duration::from_secs_f32( 2. * buffer.len() as f32 / RATE as f32, )); + log::info!("Entering main loop"); loop { // Generate 440hz tone for i in (0..buffer.len() - 1).step_by(2) { @@ -63,8 +73,10 @@ fn main() -> ! { buffer[i + 1] = wav_tbl[phase as usize]; phase = (phase + phase_delta) % (TBL_LEN as f32); } - let bytes: &[u8; 2048] = unsafe { transmute(&buffer) }; + log::info!("Generated tone!"); + let bytes: &[u8; BUF_LEN*2] = unsafe { transmute(&buffer) }; // Send samples to i2s device i2s.write_all(bytes, timeout.0).unwrap(); + log::info!("Wrote to buffer!"); } }