#include "nau88u10yg.h"


bool xAudioCodecReadRegister(tI2cIO *i2c, uint16_t AdrRegQwery, uint16_t *DataRegResult) {
    uint8_t pack = AdrRegQwery << 1 | 0b0 << 0;
    uint8_t i2cPack[2]={0};
    uint16_t data = 0;
    I2cWrite(i2c, NAU88U10YG_ADDRESS_WRITE, &pack, 1, NAU88U10YG_IO_TIMEOUT);
    uint16_t result = I2cRead(i2c, NAU88U10YG_ADDRESS_READ, (uint8_t *) &data, 2, NAU88U10YG_IO_TIMEOUT);
    i2cPack[0] = data>>8;
    i2cPack[1] = data;
    *DataRegResult = (uint16_t)*i2cPack;
    return result;
}



bool xAudioCodecWriteRegister(tI2cIO *i2c, NAU88U10YG_RegAddrPacket packet){
    uint8_t i2cPack[2]={0};
    i2cPack[0] = packet.raw>>8;
    i2cPack[1] = packet.raw;
    return I2cWrite(i2c,NAU88U10YG_ADDRESS_WRITE,i2cPack,2,NAU88U10YG_IO_TIMEOUT);
}

bool xAudioCodecWrite_Register8b_Data8b(tI2cIO *i2c, uint8_t reg, uint8_t data){
    uint8_t i2cPack[2]={0};
    i2cPack[0] = reg;
    i2cPack[1] = data;
    return I2cWrite(i2c,NAU88U10YG_ADDRESS_WRITE,i2cPack,2,NAU88U10YG_IO_TIMEOUT)==2;
}