Skip to content

Commit

Permalink
Compile error rp2040
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Apr 27, 2024
1 parent 0847001 commit 6acd7e1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
8 changes: 3 additions & 5 deletions src/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -1098,13 +1098,11 @@ class AudioDriverWM8978Class : public AudioDriver {
bool begin(CodecConfig codecCfg, DriverPins &pins) override {
bool rc = true;
auto i2c = pins.getI2CPins(PinFunction::CODEC);
if (!i2c) {
rc = wm8078.begin();
} else {
if (i2c && i2c.value().p_wire != nullptr) {
auto i2c_pins = i2c.value();
rc = wm8078.begin(i2c_pins.sda, i2c_pins.scl, i2c_pins.frequency);
wm8078.setWire(*i2c_pins.p_wire);
}

rc = wm8078.begin();
setConfig(codecCfg);

// setup initial default volume
Expand Down
34 changes: 15 additions & 19 deletions src/Driver/wm8978/WM8978.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "WM8978.h"

#include <Arduino.h>
#include <Wire.h>
#include <stdio.h>

// WM8978 register value buffer zone (total 58 registers 0 to 57), occupies 116
// bytes of memory Because the IIC WM8978 operation does not support read
// operations, so save all the register values in the local Write WM8978
Expand All @@ -29,10 +25,10 @@ uint8_t WM8978::Write_Reg(uint8_t reg, uint16_t val) {
char buf[2];
buf[0] = (reg << 1) | ((val >> 8) & 0X01);
buf[1] = val & 0XFF;
Wire.beginTransmission(
p_wire->beginTransmission(
WM8978_ADDR); // Send data to the slave with device number 4
Wire.write((const uint8_t*)buf, 2);
Wire.endTransmission(); // Stop sending
p_wire->write((const uint8_t*)buf, 2);
p_wire->endTransmission(); // Stop sending
REGVAL_TBL[reg] = val; // Save register value to local
return 0;
}
Expand Down Expand Up @@ -317,15 +313,15 @@ void WM8978::setHPF(uint8_t enable) {
}

bool WM8978::begin() {
Wire.beginTransmission(WM8978_ADDR);
const uint8_t error = Wire.endTransmission();
p_wire->beginTransmission(WM8978_ADDR);
const uint8_t error = p_wire->endTransmission();
if (error) {
log_e("No WM8978 dac @ i2c address: 0x%X", WM8978_ADDR);
AD_LOGE("No WM8978 dac @ i2c address: 0x%X", WM8978_ADDR);
return false;
}
const int err = Init();
if (err) {
log_e("WM8978 init err: 0x%X", err);
AD_LOGE("WM8978 init err: 0x%X", err);
return false;
}
cfgI2S(2, 0); // Philips 16bit
Expand All @@ -347,11 +343,11 @@ bool WM8978::begin() {
return true;
}

bool WM8978::begin(const uint8_t sda, const uint8_t scl,
const uint32_t frequency) {
if (!Wire.begin(sda, scl, frequency)) {
log_e("Wire setup error sda=%i scl=%i frequency=%i", sda, scl, frequency);
return false;
}
return begin();
}
// bool WM8978::begin(const uint8_t sda, const uint8_t scl,
// const uint32_t frequency) {
// if (!p_wire->begin(sda, scl, frequency)) {
// AD_LOGE("Wire setup error sda=%i scl=%i frequency=%i", sda, scl, frequency);
// return false;
// }
// return begin();
// }
11 changes: 9 additions & 2 deletions src/Driver/wm8978/WM8978.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define __WM8978_H

#include <stdio.h>
#include "Common.h"
#include "Utils/I2C.h"
#include "Wire.h"

#define WM8978_ADDR 0X1A // WM8978��������ַ,�̶�Ϊ0X1A

Expand Down Expand Up @@ -35,8 +38,8 @@ class WM8978 {
WM8978() {}
~WM8978() {}
bool begin(); /* use this function if you want to setup i2c before */
bool begin(const uint8_t sda, const uint8_t scl,
const uint32_t frequency = 100000);
// bool begin(const uint8_t sda, const uint8_t scl,
// const uint32_t frequency = 100000);
void cfgADDA(uint8_t dacen, uint8_t adcen);
void cfgInput(uint8_t micen, uint8_t lineinen, uint8_t auxen);
void cfgOutput(uint8_t dacen, uint8_t bpsen);
Expand All @@ -56,8 +59,12 @@ class WM8978 {
void setNoise(uint8_t enable, uint8_t gain);
void setALC(uint8_t enable, uint8_t maxgain, uint8_t mingain);
void setHPF(uint8_t enable);
void setWire(TwoWire& wire){
p_wire = &wire;
}

private:
TwoWire* p_wire = &Wire;
uint8_t Init(void);
uint8_t Write_Reg(uint8_t reg, uint16_t val);
uint16_t Read_Reg(uint8_t reg);
Expand Down

0 comments on commit 6acd7e1

Please sign in to comment.