Fix pin conflict
This commit is contained in:
parent
ce70442a2a
commit
a58f4463ad
26
src/main.rs
26
src/main.rs
@ -21,7 +21,7 @@ fn main() -> ! {
|
|||||||
// Bind the log crate to the ESP Logging facilities
|
// Bind the log crate to the ESP Logging facilities
|
||||||
esp_idf_svc::log::EspLogger::initialize_default();
|
esp_idf_svc::log::EspLogger::initialize_default();
|
||||||
|
|
||||||
log::info!("Hello, world!");
|
log::info!("Hello, world! APP HAS INITIALIZED!!!!!");
|
||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
||||||
let mut wav_tbl: [i16; TBL_LEN] = [0; TBL_LEN];
|
let mut wav_tbl: [i16; TBL_LEN] = [0; TBL_LEN];
|
||||||
@ -39,23 +39,33 @@ fn main() -> ! {
|
|||||||
//
|
//
|
||||||
|
|
||||||
//i2s setup
|
//i2s setup
|
||||||
|
log::info!("i2s setup...");
|
||||||
let std_config = StdConfig::philips(RATE, DataBitWidth::Bits16);
|
let std_config = StdConfig::philips(RATE, DataBitWidth::Bits16);
|
||||||
let bclk = peripherals.pins.gpio1;
|
let bclk = peripherals.pins.gpio1;
|
||||||
let _din = peripherals.pins.gpio4;
|
let _din = peripherals.pins.gpio4;
|
||||||
let dout = peripherals.pins.gpio6;
|
let dout = peripherals.pins.gpio5;
|
||||||
let mclk = AnyIOPin::none();
|
let mclk = AnyIOPin::none();
|
||||||
let ws = peripherals.pins.gpio2;
|
let ws = peripherals.pins.gpio2;
|
||||||
let mut i2s =
|
log::info!("i2s driver setup...");
|
||||||
I2sDriver::<I2sTx>::new_std_tx(peripherals.i2s0, &std_config, bclk, dout, mclk, ws)
|
let result = I2sDriver::<I2sTx>::new_std_tx(peripherals.i2s0, &std_config, bclk, dout, mclk, ws);
|
||||||
.unwrap();
|
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();
|
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 mut phase: f32 = 0.0;
|
||||||
let phase_delta = (440.0 / RATE as f32) * TBL_LEN as f32;
|
let phase_delta = (440.0 / RATE as f32) * TBL_LEN as f32;
|
||||||
let timeout = TickType::from(Duration::from_secs_f32(
|
let timeout = TickType::from(Duration::from_secs_f32(
|
||||||
2. * buffer.len() as f32 / RATE as f32,
|
2. * buffer.len() as f32 / RATE as f32,
|
||||||
));
|
));
|
||||||
|
log::info!("Entering main loop");
|
||||||
loop {
|
loop {
|
||||||
// Generate 440hz tone
|
// Generate 440hz tone
|
||||||
for i in (0..buffer.len() - 1).step_by(2) {
|
for i in (0..buffer.len() - 1).step_by(2) {
|
||||||
@ -63,8 +73,10 @@ fn main() -> ! {
|
|||||||
buffer[i + 1] = wav_tbl[phase as usize];
|
buffer[i + 1] = wav_tbl[phase as usize];
|
||||||
phase = (phase + phase_delta) % (TBL_LEN as f32);
|
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
|
// Send samples to i2s device
|
||||||
i2s.write_all(bytes, timeout.0).unwrap();
|
i2s.write_all(bytes, timeout.0).unwrap();
|
||||||
|
log::info!("Wrote to buffer!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user