/*
 * AD5272.h - library for interface with AD5272 digital rheostat w/ I2C interface
 * AD5272 is 1024-position version (as opposed to 256 for AD5274)
 * Only covers reading and adjusting the wiper position - does not cover
 *    other features like setting memory, resetting, shutdown, toggling
 *    precision mode, reading memory, etc.
 * Based on previous code written for AD5274/Teensy (6/10/20)
 * Irene Hu
 * 
 * April 11, 2023
 * 
*/

#ifndef _AD5272
#define _AD5272

#include <Arduino.h> // need this for 'byte'

// these two are holdovers from the Teensy code
#define WIRESPEED_HZ 400000 // 400khz is high speed mode
#define WIRETIMEOUT_US 200000 // dunno, sample code set this parameter so i will too

// commands
#define ENABLE_WRITE 0x1c02
#define READ_RDAC 0x0800
#define WRITE_RDAC 0x0400 // this is for writing 0
// to write RDAC, 0x0400 must be OR'ed with appropriate number w/ proper 
// bits set for D0 through D9

// number of total positions
#define NUMPOS 1024


class AD5272
{
	public:
		// constructor
		AD5272(byte slaveaddr);

		// initializing - includes enabling writing
		int begin();
		
		// write and read wiper position
		int setwiper (int position);
		int readwiper (int *position);
		int readwiper(); // version returning the value directly
		

	private:
		// private variables
		byte _addr;
		
};

#endif
