3 * Copyright 2008 Free Software Foundation, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "memory_map.h"
24 // AD9712 or AD7922 1 MS/s, 10-/12-bit ADCs
26 //#define SPI_SS_DEBUG SPI_SS_RX_DB
27 #define SPI_SS_DEBUG 0
37 * The ADC's are pipelined. That is, you have to tell them
38 * which of the two inputs you want one cycle ahead of time.
39 * We could optimize and keep track of which one we used last
40 * time, but for simplicity we'll always tell it which
41 * one we want. This takes 2 16-bit xfers, one to set the
42 * input and one to read the one we want.
46 _lsadc_read(int which_adc, int slave_select)
49 int channel = which_adc & 0x1;
51 // Set CHN and STY equal to channel number. We don't want "daisy chain mode"
52 uint16_t cmd = (channel << 13) | (channel << 12);
54 spi_transact(SPI_TXONLY, slave_select | SPI_SS_DEBUG,
55 cmd, 16, SPIF_PUSH_RISE | SPIF_LATCH_RISE);
57 r = spi_transact(SPI_TXRX, slave_select | SPI_SS_DEBUG,
58 cmd, 16, SPIF_PUSH_RISE | SPIF_LATCH_RISE);
64 lsadc_read_rx(int which_adc)
66 return _lsadc_read(which_adc, SPI_SS_RX_ADC);
70 lsadc_read_tx(int which_adc)
72 return _lsadc_read(which_adc, SPI_SS_TX_ADC);