fw: testing and fix a couple blocking bugs!

This commit is contained in:
David Lenfesty 2023-04-15 12:59:54 -06:00
parent b7b556f6d2
commit 005a053624
3 changed files with 25 additions and 8 deletions

View File

@ -1,7 +1,7 @@
MEMORY
{
RAM : ORIGIN = 0x01002000, LENGTH = 4K
FLASH : ORIGIN = 0x01000000, LENGTH = 8K
RAM : ORIGIN = 0x01004000, LENGTH = 4K
FLASH : ORIGIN = 0x01000000, LENGTH = 12K
}
REGION_ALIAS("REGION_TEXT", FLASH);

View File

@ -44,7 +44,7 @@ impl AmlibI2c{
}
fn is_nack(&self) -> bool {
unsafe { read_reg::<u8>(self.base_addr + SR) & 0x02 != 0 }
unsafe { read_reg::<u8>(self.base_addr + SR) & 0x02 == 0 }
}
}
@ -105,6 +105,10 @@ impl Read<SevenBitAddress> for AmlibI2c {
return Err(Error::Busy);
}
// Set read ACK to 1. Should probably ideally be done in an init() function
// but it doesn't really matter
write_reg(self.base_addr + CR, 0x30u8);
// START
write_reg(self.base_addr + CR, 0x01u8);

View File

@ -7,6 +7,7 @@ use core::{arch::asm, ptr::{write_volatile, read_volatile}};
use core::fmt::Write;
use embedded_hal::prelude::{_embedded_hal_blocking_i2c_Write, _embedded_hal_blocking_i2c_Read};
use mcp4726::Status;
use riscv_rt::entry;
mod eth;
@ -36,19 +37,31 @@ fn main() -> ! {
//let mut buf = [0u8; 1];
//i2c.read(0b110_0011, &mut buf);
let mut buf = [0u8; 8];
i2c.read(0x63, &mut buf[0..4]).unwrap();
writeln!(uart, "DAC Read before config: {:x}, {:x}, {:x}, {:x}", buf[0], buf[1], buf[2], buf[3]).unwrap();
let mut dac = mcp4726::MCP4726::new(3);
writeln!(uart, "Reading DAC status");
dac.read_status(&mut i2c).unwrap();
writeln!(uart, "Configuring DAC");
writeln!(uart, "Reading DAC status").unwrap();
match dac.read_status(&mut i2c) {
Ok(status) => writeln!(uart, "Is ready? {}, device powered? {}", status.ready, status.device_powered).unwrap(),
Err(e) => {
writeln!(uart, "Error: {:?}", e).unwrap();
panic!();
}
}
writeln!(uart, "Configuring DAC").unwrap();
dac.write_config(&mut i2c, mcp4726::Config {
vref_source: mcp4726::VRef::UnbufferedVRef,
vref_source: mcp4726::VRef::UnbufferedVDD,
operation: mcp4726::PowerDown::NormalOperation,
use_2x_gain: false,
}).unwrap();
writeln!(uart, "Setting DAC");
writeln!(uart, "Setting DAC").unwrap();
dac.write_dac(&mut i2c, 0x0800).unwrap();
i2c.read(0x63, &mut buf[0..4]).unwrap();
writeln!(uart, "DAC Read after config: {:x}, {:x}, {:x}, {:x}", buf[0], buf[1], buf[2], buf[3]).unwrap();
loop {
//eth::tranmsit();
//writeln!(uart, "Hello world!");