Skip to content

Commit 965bd07

Browse files
committed
AC101 corrections
1 parent 25c0107 commit 965bd07

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

src/Driver/ac101/ac101.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ void ac101_set_i2c_handle(i2c_bus_handle_t handle){
2020

2121

2222
static error_t ac101_write_reg(uint8_t reg_add, uint16_t data){
23-
return i2c_bus_write_bytes(i2c_handle, AC101_ADDR, &reg_add, sizeof(reg_add), (uint8_t*) &data, sizeof(data));
23+
uint8_t send_buff[2];
24+
send_buff[0] = (data >> 8) & 0xff;
25+
send_buff[1] = data & 0xff;
26+
return i2c_bus_write_bytes(i2c_handle, AC101_ADDR, &reg_add, sizeof(reg_add), (uint8_t*) send_buff, sizeof(send_buff));
2427
}
2528

2629
static error_t ac101_read_i2c(uint8_t devAddr, uint8_t reg_add, uint8_t *p_data, size_t size) {

src/Driver/ac101/ac101.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define I2C_MASTER_READ 1
1212

1313

14-
#define AC101_ADDR 0x1a /*!< Device address*/
14+
#define AC101_ADDR 0x34 /*!< Device address 0x1a/0x34 */
1515

1616
#undef READ_BIT
1717
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */

src/DriverPins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ class PinsAudioKitAC101Class : public DriverPins {
576576
// sd pins
577577
addSPI(ESP32PinsSD);
578578
// add i2c codec pins: scl, sda, port, frequency
579-
addI2C(PinFunction::CODEC, 32, 22);
579+
addI2C(PinFunction::CODEC, 32, 33);
580580
// add i2s pins: mclk, bck, ws,data_out, data_in ,(port)
581581
addI2S(PinFunction::CODEC, 0, 27, 26, 25, 35);
582582

src/Utils/I2C.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,19 @@ error_t i2c_bus_read_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg,
3737
reglen, datalen, reg[0]);
3838
TwoWire *p_wire = (TwoWire *)bus;
3939
assert(reglen == 1);
40-
assert(datalen == 1);
4140
assert(p_wire!=nullptr);
4241

43-
outdata[0] = 0;
42+
memset(outdata,0,datalen);
4443
int result = RESULT_OK;
4544

4645
p_wire->beginTransmission(addr >> 1);
47-
p_wire->write(reg[0]);
46+
p_wire->write(reg, reglen);
4847
int rc = p_wire->endTransmission();
4948
if (rc != 0) {
5049
AD_LOGE("->p_wire->endTransmission: %d", rc);
5150
}
5251

53-
uint8_t result_len =
54-
p_wire->requestFrom((uint16_t)(addr >> 1), (uint8_t)1, (uint8_t) true);
52+
uint8_t result_len = p_wire->requestFrom((addr >> 1), datalen, (int) true);
5553
if (result_len > 0) {
5654
result_len = p_wire->readBytes(outdata, datalen);
5755
} else {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"folders": [
3+
{
4+
"path": ".."
5+
}
6+
],
7+
"settings": {
8+
"files.associations": {
9+
"driverconstants.h": "c",
10+
"*.tcc": "cpp",
11+
"stdbool.h": "c"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)