/** * @file control_AK4452_F32.cpp * @author Piotr Zapart * @brief driver for the AK4452 DAC * @version 0.1 * @date 2024-06-14 * * @copyright Copyright (c) 2024 www.hexefx.com * 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 ." */ #include "control_AK4452_F32.h" #define AK4452_REG_CTRL1 (0x00) #define AK4452_REG_CTRL1_DFLT (0x0C) #define AK4452_BIT_RSTN (1<<0) #define AK4452_DIF_MASK (0x0E) #define AK4452_DIF_SHIFT (0x01) #define AK4452_DIF(x) (((x)<begin(); ctrlBus->setClock(400000); if (!writeReg(AK4452_REG_CTRL1, 0x00)) // put the registers in reset mode { return false; // codec not found } // DIF[2:0] = 0b111 - 32bit I2S, Normal mode // DFS[2:0] = 0b000 (default) Normal speed mode // DSDSEL[1:0] = 0b10 256fs writeReg(AK4452_REG_DSD2, AK4452_BIT_DSDSEL1); writeReg(AK4452_REG_CTRL1, AK4452_DIF(AK4452_DIF_32B_I2S) | AK4452_BIT_RSTN); configured = true; return true; } bool AudioControlAK4452_F32::writeReg(uint8_t addr, uint8_t val) { ctrlBus->beginTransmission(i2cAddr); ctrlBus->write(addr); ctrlBus->write(val); return ctrlBus->endTransmission() == 0; } bool AudioControlAK4452_F32::readReg(uint8_t addr, uint8_t *valPtr) { ctrlBus->beginTransmission(i2cAddr); ctrlBus->write(addr); if (ctrlBus->endTransmission(false) != 0) return false; if (ctrlBus->requestFrom((int)i2cAddr, 1) < 1) return false; *valPtr = ctrlBus->read(); return true; } uint8_t AudioControlAK4452_F32::modifyReg(uint8_t reg, uint8_t val, uint8_t iMask) { uint8_t val1; val1 = (readReg(reg, &val1) & (~iMask)) | val; if (!writeReg(reg, val1)) return 0; return val1; }