Skip to content

Commit 6acd7e1

Browse files
committed
Compile error rp2040
1 parent 0847001 commit 6acd7e1

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

src/Driver.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -1098,13 +1098,11 @@ class AudioDriverWM8978Class : public AudioDriver {
10981098
bool begin(CodecConfig codecCfg, DriverPins &pins) override {
10991099
bool rc = true;
11001100
auto i2c = pins.getI2CPins(PinFunction::CODEC);
1101-
if (!i2c) {
1102-
rc = wm8078.begin();
1103-
} else {
1101+
if (i2c && i2c.value().p_wire != nullptr) {
11041102
auto i2c_pins = i2c.value();
1105-
rc = wm8078.begin(i2c_pins.sda, i2c_pins.scl, i2c_pins.frequency);
1103+
wm8078.setWire(*i2c_pins.p_wire);
11061104
}
1107-
1105+
rc = wm8078.begin();
11081106
setConfig(codecCfg);
11091107

11101108
// setup initial default volume

src/Driver/wm8978/WM8978.cpp

+15-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#include "WM8978.h"
22

3-
#include <Arduino.h>
4-
#include <Wire.h>
5-
#include <stdio.h>
6-
73
// WM8978 register value buffer zone (total 58 registers 0 to 57), occupies 116
84
// bytes of memory Because the IIC WM8978 operation does not support read
95
// operations, so save all the register values in the local Write WM8978
@@ -29,10 +25,10 @@ uint8_t WM8978::Write_Reg(uint8_t reg, uint16_t val) {
2925
char buf[2];
3026
buf[0] = (reg << 1) | ((val >> 8) & 0X01);
3127
buf[1] = val & 0XFF;
32-
Wire.beginTransmission(
28+
p_wire->beginTransmission(
3329
WM8978_ADDR); // Send data to the slave with device number 4
34-
Wire.write((const uint8_t*)buf, 2);
35-
Wire.endTransmission(); // Stop sending
30+
p_wire->write((const uint8_t*)buf, 2);
31+
p_wire->endTransmission(); // Stop sending
3632
REGVAL_TBL[reg] = val; // Save register value to local
3733
return 0;
3834
}
@@ -317,15 +313,15 @@ void WM8978::setHPF(uint8_t enable) {
317313
}
318314

319315
bool WM8978::begin() {
320-
Wire.beginTransmission(WM8978_ADDR);
321-
const uint8_t error = Wire.endTransmission();
316+
p_wire->beginTransmission(WM8978_ADDR);
317+
const uint8_t error = p_wire->endTransmission();
322318
if (error) {
323-
log_e("No WM8978 dac @ i2c address: 0x%X", WM8978_ADDR);
319+
AD_LOGE("No WM8978 dac @ i2c address: 0x%X", WM8978_ADDR);
324320
return false;
325321
}
326322
const int err = Init();
327323
if (err) {
328-
log_e("WM8978 init err: 0x%X", err);
324+
AD_LOGE("WM8978 init err: 0x%X", err);
329325
return false;
330326
}
331327
cfgI2S(2, 0); // Philips 16bit
@@ -347,11 +343,11 @@ bool WM8978::begin() {
347343
return true;
348344
}
349345

350-
bool WM8978::begin(const uint8_t sda, const uint8_t scl,
351-
const uint32_t frequency) {
352-
if (!Wire.begin(sda, scl, frequency)) {
353-
log_e("Wire setup error sda=%i scl=%i frequency=%i", sda, scl, frequency);
354-
return false;
355-
}
356-
return begin();
357-
}
346+
// bool WM8978::begin(const uint8_t sda, const uint8_t scl,
347+
// const uint32_t frequency) {
348+
// if (!p_wire->begin(sda, scl, frequency)) {
349+
// AD_LOGE("Wire setup error sda=%i scl=%i frequency=%i", sda, scl, frequency);
350+
// return false;
351+
// }
352+
// return begin();
353+
// }

src/Driver/wm8978/WM8978.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#define __WM8978_H
33

44
#include <stdio.h>
5+
#include "Common.h"
6+
#include "Utils/I2C.h"
7+
#include "Wire.h"
58

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

@@ -35,8 +38,8 @@ class WM8978 {
3538
WM8978() {}
3639
~WM8978() {}
3740
bool begin(); /* use this function if you want to setup i2c before */
38-
bool begin(const uint8_t sda, const uint8_t scl,
39-
const uint32_t frequency = 100000);
41+
// bool begin(const uint8_t sda, const uint8_t scl,
42+
// const uint32_t frequency = 100000);
4043
void cfgADDA(uint8_t dacen, uint8_t adcen);
4144
void cfgInput(uint8_t micen, uint8_t lineinen, uint8_t auxen);
4245
void cfgOutput(uint8_t dacen, uint8_t bpsen);
@@ -56,8 +59,12 @@ class WM8978 {
5659
void setNoise(uint8_t enable, uint8_t gain);
5760
void setALC(uint8_t enable, uint8_t maxgain, uint8_t mingain);
5861
void setHPF(uint8_t enable);
62+
void setWire(TwoWire& wire){
63+
p_wire = &wire;
64+
}
5965

6066
private:
67+
TwoWire* p_wire = &Wire;
6168
uint8_t Init(void);
6269
uint8_t Write_Reg(uint8_t reg, uint16_t val);
6370
uint16_t Read_Reg(uint8_t reg);

0 commit comments

Comments
 (0)