#ifndef _BIWAK_BU21026MUV_H_
#define _BIWAK_BU21026MUV_H_

#include <biwak/gpio.h>
#include <biwak/i2c_slave.h>
#include <biwak/input.h>

// With both address pins low the address is 0x48 (without R/W)

namespace OperationO0
{
   constexpr int setPower      = 0x00;
   constexpr int driveX        = 0x80;
   constexpr int driveY        = 0x90;
   constexpr int driveZ        = 0xA0;
   constexpr int measureX      = 0xC0;
   constexpr int measureY      = 0xD0;
};

namespace OperationO1
{
   constexpr int setup         = 0xB0;
}

namespace OperationO2
{
   constexpr int softwareReset = 0x50;
}


namespace Operand0
{
   constexpr int pdKeepReading  = 0x04;
   constexpr int resolution8Bit = 0x02;
   constexpr int resolution12Bit= 0x00;
   constexpr int defaultValue   = resolution12Bit;
}

namespace Operand1
{
   constexpr int mafEnabled    = 0x00;
}

class CBu21026muv // : public CInput
      : public CI2cSlave
{
private:
   CInput   m_interrupt;
   //CI2cSlave     &m_i2cSlave;
   int m_xVpp;
   int m_yVpp;
   int m_xOffset, m_xSize;
   int m_yOffset, m_ySize;
   constexpr static int addr=0x48<<1;

public:
   CBu21026muv(CI2c &i2c, EGpioPeripheral periphery, EGpioPin pin);
   CInput &getInterruptInput()
   {
      return(m_interrupt);
   }
   void calibrate(int xOffset, int xVpp, int xSize, int yOffset, int yVpp, int ySize );
   bool readCoordinates(int &x, int &y, bool raw=false);
   // virtual void interrupt(EInterrupt eInterrupt, int iData, void* pData);

#if 0
   int transformX(int xraw);
   int transformY(int yraw);
#endif
   void interrupt(bool);
};


#endif // _BIWAK_BU21026MUV_H_
