Compare commits
2 Commits
53930497e4
...
feae22b277
Author | SHA1 | Date |
---|---|---|
Astro | feae22b277 | |
Astro | c53c9a289f |
|
@ -25,7 +25,7 @@ pub struct Dac<SPI: Transfer<u8>, S: OutputPin> {
|
|||
|
||||
impl<SPI: Transfer<u8>, S: OutputPin> Dac<SPI, S> {
|
||||
pub fn new(spi: SPI, mut sync: S) -> Self {
|
||||
let _ = sync.set_high();
|
||||
let _ = sync.set_low();
|
||||
|
||||
Dac {
|
||||
spi,
|
||||
|
@ -34,11 +34,14 @@ impl<SPI: Transfer<u8>, S: OutputPin> Dac<SPI, S> {
|
|||
}
|
||||
|
||||
fn write(&mut self, mut buf: [u8; 3]) -> Result<(), SPI::Error> {
|
||||
let _ = self.sync.set_low();
|
||||
let result = self.spi.transfer(&mut buf);
|
||||
// pulse sync to start a new transfer. leave sync idle low
|
||||
// afterwards to save power as recommended per datasheet.
|
||||
let _ = self.sync.set_high();
|
||||
cortex_m::asm::nop();
|
||||
let _ = self.sync.set_low();
|
||||
|
||||
result.map(|_| ())
|
||||
self.spi.transfer(&mut buf)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// value: `0..0x20_000`
|
||||
|
|
|
@ -144,7 +144,7 @@ fn main() -> ! {
|
|||
let ref_adc_data = channels.read_ref_adc(channel);
|
||||
let state = channels.channel_state(channel);
|
||||
let _ = writeln!(
|
||||
socket, "t={} raw{}=0x{:06X} ref_adc={}",
|
||||
socket, "t={} raw{}=0x{:06X} ref_adc=0x{:X}",
|
||||
state.adc_time, channel, adc_data,
|
||||
ref_adc_data
|
||||
);
|
||||
|
|
|
@ -35,7 +35,7 @@ impl ChannelPins for Channel0 {
|
|||
type DacSync = PE4<Output<PushPull>>;
|
||||
type Shdn = PE10<Output<PushPull>>;
|
||||
type RefAdc = Adc<ADC1>;
|
||||
type RefPin = PA0<Analog>;
|
||||
type RefPin = PA4<Analog>;
|
||||
}
|
||||
|
||||
impl ChannelPins for Channel1 {
|
||||
|
@ -43,7 +43,7 @@ impl ChannelPins for Channel1 {
|
|||
type DacSync = PF6<Output<PushPull>>;
|
||||
type Shdn = PE15<Output<PushPull>>;
|
||||
type RefAdc = Adc<ADC2>;
|
||||
type RefPin = PA3<Analog>;
|
||||
type RefPin = PA5<Analog>;
|
||||
}
|
||||
|
||||
/// SPI peripheral used for communication with the ADC
|
||||
|
@ -108,7 +108,7 @@ impl Pins {
|
|||
let _ = shdn0.set_low();
|
||||
let mut ref0_adc = Adc::adc1(adc1, true, Default::default());
|
||||
ref0_adc.enable();
|
||||
let ref0_pin = gpioa.pa0.into_analog();
|
||||
let ref0_pin = gpioa.pa4.into_analog();
|
||||
let channel0 = ChannelPinSet {
|
||||
dac_spi: dac0_spi,
|
||||
dac_sync: dac0_sync,
|
||||
|
@ -125,7 +125,7 @@ impl Pins {
|
|||
let _ = shdn1.set_low();
|
||||
let mut ref1_adc = Adc::adc2(adc2, true, Default::default());
|
||||
ref1_adc.enable();
|
||||
let ref1_pin = gpioa.pa3.into_analog();
|
||||
let ref1_pin = gpioa.pa5.into_analog();
|
||||
let channel1 = ChannelPinSet {
|
||||
dac_spi: dac1_spi,
|
||||
dac_sync: dac1_sync,
|
||||
|
|
Loading…
Reference in New Issue