/* ds1085.h - register names for the frequency synthesizer chip.
 *  Copyright (C) 2022 by Jed Marti
 *   This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see https://www.gnu.org/licenses/.
 */

#ifndef ds1085_h
#define ds1085_h

// This is the byte we send to get things started. Top 4 bits are DL1058
// address top 3 of low nibble set by ds1085ADDR_BYTE (default is 0xB0).
#define DS1085  0xB0

// register indices.
enum {
  ds1085DAC_WORD = 0x08,
  ds1085OFFSET = 0x0E,
  ds1085MUX_WORD = 0x02,
  ds1085DIV_WORD = 0x01,
  ds1085ADDR_BYTE = 0x0D,
  ds1085RANGE_REG = 0x37,
  ds1085WRITE_E2 = 0x3F
};

// Band plan structure - solutions are in meters<nnn>.h computed the hard way
// by ds1085.c on Linux.
typedef struct {
  uint32_t  frequency;              // The frequency
  int8_t    offset;                 // Offset from center -6 -> +6.
  uint8_t   prescale;               // Prescale value for IM0, IM1, 0-3.
  uint16_t  divisor;                // Divisor - 2 << 6.
  uint16_t  dac;                    // DAC control << 6.
} ftable;


void setFrequency(void);
void readDS1085(void);

#endif


// EOF
