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"
25 #define CMD(x) ((x) << 19)
26 #define CMD_WR_INPUT_N CMD(0) // write input N
27 #define CMD_UP_DAC_N CMD(1) // update DAC N from input reg
28 #define CMD_WR_INPUT_N_LDAC CMD(2) // write input N, update all
29 #define CMD_WR_UP_DAC_N CMD(3) // write and update N
30 #define CMD_WR_PWR_CONFIG CMD(4) // write power up/down config reg
31 #define CMD_SW_RESET CMD(5) // force s/w reset
32 #define CMD_WR_LDAC_CFG CMD(6) // write LDAC config reg
33 #define CMD_WR_INT_REF_CFG CMD(7) // write internal ref cfg reg (AD5623R only)
36 //#define SPI_SS_DEBUG SPI_SS_TX_DB
37 #define SPI_SS_DEBUG 0
42 spi_transact(SPI_TXONLY, SPI_SS_RX_DAC | SPI_SS_DEBUG, v, 24, SPIF_PUSH_RISE);
48 spi_transact(SPI_TXONLY, SPI_SS_TX_DAC | SPI_SS_DEBUG, v, 24, SPIF_PUSH_RISE);
54 _write_tx(CMD_SW_RESET | 0x1); // power-on reset
55 _write_rx(CMD_SW_RESET | 0x1); // power-on reset
59 lsdac_write_rx(int which_dac, int value)
61 _write_rx(CMD_WR_UP_DAC_N | ((which_dac & 0x7) << 16) | ((value << 4) & 0xffff));
65 lsdac_write_tx(int which_dac, int value)
67 _write_tx(CMD_WR_UP_DAC_N | ((which_dac & 0x7) << 16) | ((value << 4) & 0xffff));