forked from M-Labs/artiq
parent
917a4185eb
commit
c646409dbe
|
@ -25,27 +25,29 @@ fn set_pins(card_index: usize, chan_index: usize, pins: u32) {
|
|||
pub fn program(card_index: usize, chan_index: usize, atten: u8) {
|
||||
assert!(card_index < 4 && chan_index < 2);
|
||||
|
||||
// 0b111111 = 1dB
|
||||
info!("card {} channel {} set to {}{} dB",
|
||||
card_index, chan_index,
|
||||
atten / 2, if atten % 2 != 0 { ".5" } else { "" });
|
||||
|
||||
// 0b111111 = 0dB
|
||||
// 0b111110 = 0.5dB
|
||||
// 0b111101 = 1dB
|
||||
// 0b111100 = 1.5dB
|
||||
// ...
|
||||
// 0b011111 = 16dB
|
||||
// ...
|
||||
// 0b000000 = 31.5dB
|
||||
let atten = !(atten << 2);
|
||||
let atten = !atten << 2;
|
||||
|
||||
let set_pins = |pins| set_pins(card_index, chan_index, pins);
|
||||
set_pins(PIN_RST);
|
||||
set_pins(0);
|
||||
for n in 0..8 {
|
||||
for n in (0..8).rev() {
|
||||
let sin = if atten & 1 << n != 0 { PIN_SIN } else { 0 };
|
||||
set_pins(sin);
|
||||
set_pins(sin | PIN_CLK);
|
||||
}
|
||||
set_pins(PIN_LE);
|
||||
|
||||
info!("card {} channel {} set to {}{} dB",
|
||||
card_index, chan_index,
|
||||
atten / 2, if atten % 2 != 0 { ".5" } else { "" });
|
||||
}
|
||||
|
||||
/// See `program`.
|
||||
|
|
Loading…
Reference in New Issue