Skip to content

Commit

Permalink
fix wire
Browse files Browse the repository at this point in the history
  • Loading branch information
gemu2015 committed Nov 19, 2024
1 parent b0ff4fb commit 41c9c34
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 90 deletions.
72 changes: 36 additions & 36 deletions lib/libesp32/CORE2_Library/AXP192.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ AXP192::AXP192()
void AXP192::begin(void)
{

Wire1.begin(21, 22);
Wire1.setClock(400000);
USE_Wire.begin(21, 22);
USE_Wire.setClock(400000);

//AXP192 30H
Write1Byte(0x30, (Read8bit(0x30) & 0x04) | 0X02);
Expand Down Expand Up @@ -79,19 +79,19 @@ void AXP192::begin(void)

void AXP192::Write1Byte(uint8_t Addr, uint8_t Data)
{
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.write(Data);
Wire1.endTransmission();
USE_Wire.beginTransmission(0x34);
USE_Wire.write(Addr);
USE_Wire.write(Data);
USE_Wire.endTransmission();
}

uint8_t AXP192::Read8bit(uint8_t Addr)
{
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.endTransmission();
Wire1.requestFrom(0x34, 1);
return Wire1.read();
USE_Wire.beginTransmission(0x34);
USE_Wire.write(Addr);
USE_Wire.endTransmission();
USE_Wire.requestFrom(0x34, 1);
return USE_Wire.read();
}

uint16_t AXP192::Read12Bit(uint8_t Addr)
Expand All @@ -115,57 +115,57 @@ uint16_t AXP192::Read13Bit(uint8_t Addr)
uint16_t AXP192::Read16bit(uint8_t Addr)
{
uint16_t ReData = 0;
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.endTransmission();
Wire1.requestFrom(0x34, 2);
USE_Wire.beginTransmission(0x34);
USE_Wire.write(Addr);
USE_Wire.endTransmission();
USE_Wire.requestFrom(0x34, 2);
for (int i = 0; i < 2; i++)
{
ReData <<= 8;
ReData |= Wire1.read();
ReData |= USE_Wire.read();
}
return ReData;
}

uint32_t AXP192::Read24bit(uint8_t Addr)
{
uint32_t ReData = 0;
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.endTransmission();
Wire1.requestFrom(0x34, 3);
USE_Wire.beginTransmission(0x34);
USE_Wire.write(Addr);
USE_Wire.endTransmission();
USE_Wire.requestFrom(0x34, 3);
for (int i = 0; i < 3; i++)
{
ReData <<= 8;
ReData |= Wire1.read();
ReData |= USE_Wire.read();
}
return ReData;
}

uint32_t AXP192::Read32bit(uint8_t Addr)
{
uint32_t ReData = 0;
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.endTransmission();
Wire1.requestFrom(0x34, 2);
USE_Wire.beginTransmission(0x34);
USE_Wire.write(Addr);
USE_Wire.endTransmission();
USE_Wire.requestFrom(0x34, 2);
for (int i = 0; i < 4; i++)
{
ReData <<= 8;
ReData |= Wire1.read();
ReData |= USE_Wire.read();
}
return ReData;
}

void AXP192::ReadBuff(uint8_t Addr, uint8_t Size, uint8_t *Buff)
{
Wire1.beginTransmission(0x34);
Wire1.write(Addr);
Wire1.endTransmission();
Wire1.requestFrom(0x34, (int)Size);
USE_Wire.beginTransmission(0x34);
USE_Wire.write(Addr);
USE_Wire.endTransmission();
USE_Wire.requestFrom(0x34, (int)Size);
for (int i = 0; i < Size; i++)
{
*(Buff + i) = Wire1.read();
*(Buff + i) = USE_Wire.read();
}
}

Expand Down Expand Up @@ -278,11 +278,11 @@ void AXP192::RestoreFromLightSleep(void)

uint8_t AXP192::GetWarningLeve(void)
{
Wire1.beginTransmission(0x34);
Wire1.write(0x47);
Wire1.endTransmission();
Wire1.requestFrom(0x34, 1);
uint8_t buf = Wire1.read();
USE_Wire.beginTransmission(0x34);
USE_Wire.write(0x47);
USE_Wire.endTransmission();
USE_Wire.requestFrom(0x34, 1);
uint8_t buf = USE_Wire.read();
return (buf & 0x01);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/libesp32/CORE2_Library/AXP192.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

#define AXP_ADDR 0X34


#ifdef CONFIG_IDF_TARGET_ESP32C3
#define USE_Wire Wire
#else
#define USE_Wire Wire1
#endif

#define PowerOff(x) SetSleep(x)

class AXP192 {
Expand Down
108 changes: 54 additions & 54 deletions lib/libesp32/CORE2_Library/BM8563_RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@ BM8563_RTC::BM8563_RTC()

void BM8563_RTC::begin(void)
{
Wire1.begin(21, 22);
USE_Wire.begin(21, 22);
WriteReg(0x00,0x00);
WriteReg(0x01,0x00);
WriteReg(0x0D,0x00);
}

void BM8563_RTC::WriteReg(uint8_t reg, uint8_t data)
{
Wire1.beginTransmission(RTC_ADRESS);
Wire1.write(reg);
Wire1.write(data);
Wire1.endTransmission();
USE_Wire.beginTransmission(RTC_ADRESS);
USE_Wire.write(reg);
USE_Wire.write(data);
USE_Wire.endTransmission();
}

uint8_t BM8563_RTC::ReadReg(uint8_t reg)
{
Wire1.beginTransmission(0x51);
Wire1.write(reg);
Wire1.endTransmission();
Wire1.requestFrom(0x51, 1);
return Wire1.read();
USE_Wire.beginTransmission(0x51);
USE_Wire.write(reg);
USE_Wire.endTransmission();
USE_Wire.requestFrom(0x51, 1);
return USE_Wire.read();
}

void BM8563_RTC::GetBm8563Time(void)
{
Wire1.beginTransmission(0x51);
Wire1.write(0x02);
Wire1.endTransmission();
Wire1.requestFrom(0x51, 7);
while (Wire1.available())
USE_Wire.beginTransmission(0x51);
USE_Wire.write(0x02);
USE_Wire.endTransmission();
USE_Wire.requestFrom(0x51, 7);
while (USE_Wire.available())
{

trdata[0] = Wire1.read();
trdata[1] = Wire1.read();
trdata[2] = Wire1.read();
trdata[3] = Wire1.read();
trdata[4] = Wire1.read();
trdata[5] = Wire1.read();
trdata[6] = Wire1.read();
trdata[0] = USE_Wire.read();
trdata[1] = USE_Wire.read();
trdata[2] = USE_Wire.read();
trdata[3] = USE_Wire.read();
trdata[4] = USE_Wire.read();
trdata[5] = USE_Wire.read();
trdata[6] = USE_Wire.read();
}

DataMask();
Expand Down Expand Up @@ -124,17 +124,17 @@ void BM8563_RTC::GetTime(RTC_TimeTypeDef *RTC_TimeStruct)
//if()
uint8_t buf[3] = {0};

Wire1.beginTransmission(0x51);
Wire1.write(0x02);
Wire1.endTransmission();
Wire1.requestFrom(0x51, 3);
USE_Wire.beginTransmission(0x51);
USE_Wire.write(0x02);
USE_Wire.endTransmission();
USE_Wire.requestFrom(0x51, 3);

while (Wire1.available())
while (USE_Wire.available())
{

buf[0] = Wire1.read();
buf[1] = Wire1.read();
buf[2] = Wire1.read();
buf[0] = USE_Wire.read();
buf[1] = USE_Wire.read();
buf[2] = USE_Wire.read();
}

RTC_TimeStruct->Seconds = Bcd2ToByte(buf[0] & 0x7f); //
Expand All @@ -148,31 +148,31 @@ void BM8563_RTC::SetTime(RTC_TimeTypeDef *RTC_TimeStruct)
if (RTC_TimeStruct == NULL)
return;

Wire1.beginTransmission(0x51);
Wire1.write(0x02);
Wire1.write(ByteToBcd2(RTC_TimeStruct->Seconds));
Wire1.write(ByteToBcd2(RTC_TimeStruct->Minutes));
Wire1.write(ByteToBcd2(RTC_TimeStruct->Hours));
Wire1.endTransmission();
USE_Wire.beginTransmission(0x51);
USE_Wire.write(0x02);
USE_Wire.write(ByteToBcd2(RTC_TimeStruct->Seconds));
USE_Wire.write(ByteToBcd2(RTC_TimeStruct->Minutes));
USE_Wire.write(ByteToBcd2(RTC_TimeStruct->Hours));
USE_Wire.endTransmission();
}

void BM8563_RTC::GetDate(RTC_DateTypeDef *RTC_DateStruct)
{

uint8_t buf[4] = {0};

Wire1.beginTransmission(0x51);
Wire1.write(0x05);
Wire1.endTransmission();
Wire1.requestFrom(0x51, 4);
USE_Wire.beginTransmission(0x51);
USE_Wire.write(0x05);
USE_Wire.endTransmission();
USE_Wire.requestFrom(0x51, 4);

while (Wire1.available())
while (USE_Wire.available())
{

buf[0] = Wire1.read();
buf[1] = Wire1.read();
buf[2] = Wire1.read();
buf[3] = Wire1.read();
buf[0] = USE_Wire.read();
buf[1] = USE_Wire.read();
buf[2] = USE_Wire.read();
buf[3] = USE_Wire.read();
}

RTC_DateStruct->Date = Bcd2ToByte(buf[0] & 0x3f);
Expand All @@ -194,25 +194,25 @@ void BM8563_RTC::SetDate(RTC_DateTypeDef *RTC_DateStruct)

if (RTC_DateStruct == NULL)
return;
Wire1.beginTransmission(0x51);
Wire1.write(0x05);
Wire1.write(ByteToBcd2(RTC_DateStruct->Date));
Wire1.write(ByteToBcd2(RTC_DateStruct->WeekDay));
USE_Wire.beginTransmission(0x51);
USE_Wire.write(0x05);
USE_Wire.write(ByteToBcd2(RTC_DateStruct->Date));
USE_Wire.write(ByteToBcd2(RTC_DateStruct->WeekDay));

if (RTC_DateStruct->Year < 2000)
{

Wire1.write(ByteToBcd2(RTC_DateStruct->Month) | 0x80);
Wire1.write(ByteToBcd2((uint8_t)(RTC_DateStruct->Year % 100)));
USE_Wire.write(ByteToBcd2(RTC_DateStruct->Month) | 0x80);
USE_Wire.write(ByteToBcd2((uint8_t)(RTC_DateStruct->Year % 100)));
}
else
{
/* code */
Wire1.write(ByteToBcd2(RTC_DateStruct->Month) | 0x00);
Wire1.write(ByteToBcd2((uint8_t)(RTC_DateStruct->Year % 100)));
USE_Wire.write(ByteToBcd2(RTC_DateStruct->Month) | 0x00);
USE_Wire.write(ByteToBcd2((uint8_t)(RTC_DateStruct->Year % 100)));
}

Wire1.endTransmission();
USE_Wire.endTransmission();
}

int BM8563_RTC::SetAlarmIRQ(int afterSeconds)
Expand Down
6 changes: 6 additions & 0 deletions lib/libesp32/CORE2_Library/BM8563_RTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

#define RTC_ADRESS 0x51

#ifdef CONFIG_IDF_TARGET_ESP32C3
#define USE_Wire Wire
#else
#define USE_Wire Wire1
#endif

typedef struct
{
uint8_t Hours;
Expand Down

0 comments on commit 41c9c34

Please sign in to comment.