Skip to content

Commit 7c3f3c5

Browse files
committed
EC working!
1 parent 0b84f2f commit 7c3f3c5

File tree

3 files changed

+130
-122
lines changed

3 files changed

+130
-122
lines changed

ec/platformio.ini

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88
; Please visit documentation for the other options and examples
99
; https://docs.platformio.org/page/projectconf.html
1010

11-
[env:teensy41]
12-
platform = teensy
13-
board = teensy41
11+
[env:esp32-s3-devkitc-1]
12+
platform = espressif32
13+
board = esp32-s3-devkitc-1
1414
framework = arduino
15-
upload_protocol = teensy-cli
15+
monitor_speed = 115200
16+
monitor_dtr = 1
17+
monitor_rts = 1
18+
19+
board_build.flash_mode = qio
20+
board_upload.flash_size = 8MB
21+
board_upload.maximum_size = 8388608
22+
23+
build_flags = '-D ARDUINO_USB_MODE=1' '-D ARDUINO_USB_CDC_ON_BOOT=1'
1624
lib_deps =
1725
adafruit/Adafruit HUSB238 Library@^1.0.1

ec/src/main.cpp

Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,136 @@
11
#include <Wire.h>
2+
#include <Arduino.h>
23
#include "Adafruit_HUSB238.h"
34
#include "LTC2943.h"
45

5-
void setup() {
6-
Wire.begin();
7-
Serial.begin(0);
8-
LTC2943_write(LTC2943_I2C_ADDRESS, LTC2943_CONTROL_REG, (LTC2943_AUTOMATIC_MODE | LTC2943_PRESCALAR_M_4096));
9-
delay(1000);
10-
}
6+
// void setup() {
7+
// Wire.begin(2, 1);
8+
// Serial.begin(115200);
9+
// LTC2943_write(LTC2943_I2C_ADDRESS, LTC2943_CONTROL_REG, (LTC2943_AUTOMATIC_MODE | LTC2943_PRESCALAR_M_4096));
10+
// delay(1000);
11+
// }
1112

12-
uint16_t voltage;
13+
// uint16_t voltage;
1314

14-
void loop() {
15-
uint16_t charge;
16-
uint16_t current;
17-
uint16_t temperature;
18-
uint16_t voltage;
15+
// void loop() {
16+
// uint16_t charge;
17+
// uint16_t current;
18+
// uint16_t temperature;
19+
// uint16_t voltage;
1920

20-
LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_VOLTAGE_MSB_REG, &voltage);
21-
Serial.print("VOLT: ");
22-
Serial.println(LTC2943_code_to_voltage(voltage), 4);
21+
// LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_VOLTAGE_MSB_REG, &voltage);
22+
// Serial.print("VOLT: ");
23+
// Serial.println(LTC2943_code_to_voltage(voltage), 4);
2324

24-
LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_ACCUM_CHARGE_MSB_REG, &charge);
25-
Serial.print("CHRG: ");
26-
Serial.println(LTC2943_code_to_coulombs(charge, 0.05, 4096), 4);
25+
// LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_ACCUM_CHARGE_MSB_REG, &charge);
26+
// Serial.print("CHRG: ");
27+
// Serial.println(LTC2943_code_to_coulombs(charge, 0.01, 4096), 4);
2728

28-
LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CURRENT_MSB_REG, &current);
29-
Serial.print("CURR: ");
30-
Serial.println(LTC2943_code_to_current(current, 0.05), 4);
29+
// LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CURRENT_MSB_REG, &current);
30+
// Serial.print("CURR: ");
31+
// Serial.println(LTC2943_code_to_current(current, 0.01), 4);
3132

32-
LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_TEMPERATURE_MSB_REG, &temperature);
33-
Serial.print("TEMP: ");
34-
Serial.println(LTC2943_code_to_celcius_temperature(temperature), 4);
33+
// LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_TEMPERATURE_MSB_REG, &temperature);
34+
// Serial.print("TEMP: ");
35+
// Serial.println(LTC2943_code_to_celcius_temperature(temperature), 4);
3536

36-
delay(1000);
37-
}
37+
// delay(1000);
38+
// }
3839

39-
// Adafruit_HUSB238 husb238;
40+
Adafruit_HUSB238 husb238;
4041

41-
// #define BQ25713_ADDRESS 0x6B // I2C address of the BQ25713
42-
// #define VBUS_REG 0x27 // Register for VBUS voltage (as per the datasheet)
42+
#define BQ25713_ADDRESS 0x6B // I2C address of the BQ25713
43+
#define VBUS_REG 0x27 // Register for VBUS voltage (as per the datasheet)
4344

44-
// // Function to read a 16-bit register
45-
// uint16_t readRegister(uint8_t reg)
46-
// {
47-
// Wire.beginTransmission(BQ25713_ADDRESS);
48-
// Wire.write(reg); // Send register address
49-
// Wire.endTransmission(false);
45+
// Function to read a 16-bit register
46+
uint16_t readRegister(uint8_t reg)
47+
{
48+
Wire.beginTransmission(BQ25713_ADDRESS);
49+
Wire.write(reg); // Send register address
50+
Wire.endTransmission(false);
5051

51-
// Wire.requestFrom(BQ25713_ADDRESS, 1);
52-
// return Wire.read(); // Combine high and low byte
53-
// }
52+
Wire.requestFrom(BQ25713_ADDRESS, 1);
53+
return Wire.read(); // Combine high and low byte
54+
}
5455

55-
// void setup()
56-
// {
57-
// Serial.begin(115200);
58-
// while (!Serial)
59-
// delay(10);
60-
// Serial.println("Adafruit HUSB238 Test Sketch");
61-
62-
// // Initialize the HUSB238
63-
// if (husb238.begin(HUSB238_I2CADDR_DEFAULT, &Wire))
64-
// {
65-
// Serial.println("HUSB238 initialized successfully.");
66-
// }
67-
// else
68-
// {
69-
// Serial.println("Couldn't find HUSB238, check your wiring?");
70-
// while (1)
71-
// ;
72-
// }
73-
// // Change to that voltage
74-
// husb238.selectPD((PD_SRC_15V));
75-
// // Perform the actual PD voltage request!
76-
// husb238.requestPD();
77-
// delay(2000);
78-
79-
// Wire.beginTransmission(BQ25713_ADDRESS);
80-
// Wire.write(0x01);
81-
// Wire.write(0b00000000);
82-
// Wire.endTransmission();
83-
84-
// Wire.beginTransmission(BQ25713_ADDRESS);
85-
// Wire.write(0x03);
86-
// Wire.write(0b00000100);
87-
// Wire.endTransmission();
88-
89-
// Wire.beginTransmission(BQ25713_ADDRESS);
90-
// Wire.write(0x3B);
91-
// Wire.write(0b10100000);
92-
// Wire.endTransmission();
93-
94-
// Wire.beginTransmission(BQ25713_ADDRESS);
95-
// Wire.write(0x3A);
96-
// Wire.write(0b11111111);
97-
// Wire.endTransmission();
98-
// }
56+
void setup()
57+
{
58+
Serial.begin(115200);
59+
Wire.begin(2, 1);
60+
while (!Serial)
61+
delay(10);
62+
63+
// Initialize the HUSB238
64+
if (husb238.begin(HUSB238_I2CADDR_DEFAULT, &Wire))
65+
{
66+
Serial.println("HUSB238 initialized successfully.");
67+
}
68+
else
69+
{
70+
while (1)
71+
;
72+
}
73+
// Change to that voltage
74+
husb238.selectPD((PD_SRC_15V));
75+
// Perform the actual PD voltage request!
76+
husb238.requestPD();
77+
delay(2000);
78+
79+
Wire.beginTransmission(BQ25713_ADDRESS);
80+
Wire.write(0x01);
81+
Wire.write(0b00000000);
82+
Wire.endTransmission();
83+
84+
Wire.beginTransmission(BQ25713_ADDRESS);
85+
Wire.write(0x03);
86+
Wire.write(0b00000100);
87+
Wire.endTransmission();
88+
89+
Wire.beginTransmission(BQ25713_ADDRESS);
90+
Wire.write(0x3B);
91+
Wire.write(0b10100000);
92+
Wire.endTransmission();
93+
94+
Wire.beginTransmission(BQ25713_ADDRESS);
95+
Wire.write(0x3A);
96+
Wire.write(0b11111111);
97+
Wire.endTransmission();
98+
}
9999

100-
// void debugPrint(String info, uint8_t data)
101-
// {
102-
// Serial.print(info);
103-
// Serial.print("0x");
104-
// Serial.print(data, HEX);
105-
// Serial.print(", 0b");
106-
// Serial.print(data, BIN);
107-
// Serial.print(", ");
108-
// Serial.print(data, DEC);
109-
// Serial.println();
110-
// Serial.println();
111-
// }
100+
void debugPrint(String info, uint8_t data)
101+
{
102+
Serial.print(info);
103+
Serial.print("0x");
104+
Serial.print(data, HEX);
105+
Serial.print(", 0b");
106+
Serial.print(data, BIN);
107+
Serial.print(", ");
108+
Serial.print(data, DEC);
109+
Serial.println();
110+
Serial.println();
111+
}
112112

113-
// void loop()
114-
// {
115-
// delay(1000); // Short delay to stabilize
116-
117-
// Serial.println("\n\n");
118-
119-
// debugPrint("ChargerStatus 0x21:", readRegister(0x21));
120-
// debugPrint("ChargerStatus 0x20:", readRegister(0x20));
121-
// debugPrint("ChargeOption0 0x01:", readRegister(0x01));
122-
// debugPrint("ChargeOption0 0x00:", readRegister(0x00));
123-
// debugPrint("ADCOptions 0x3B:", readRegister(0x3B));
124-
// debugPrint("ADCOptions 0x3A:", readRegister(0x3A));
125-
126-
// debugPrint("VSYS 0x26:", readRegister(0x26));
127-
// debugPrint("ICHG 0x29:", readRegister(0x29));
128-
// debugPrint("IDCHG 0x28:", readRegister(0x28));
129-
130-
// Serial.print("VBUS: ");
131-
// Serial.println(readRegister(0x27) * 0.064);
132-
// Serial.print("VSYS: ");
133-
// Serial.println(readRegister(0x2D) * 0.064);
134-
// Serial.print("VBAT: ");
135-
// Serial.println(readRegister(0x2C) * 0.064);
136-
// }
113+
void loop()
114+
{
115+
delay(1000); // Short delay to stabilize
116+
117+
Serial.println("\n\n");
118+
119+
debugPrint("ChargerStatus 0x21:", readRegister(0x21));
120+
debugPrint("ChargerStatus 0x20:", readRegister(0x20));
121+
debugPrint("ChargeOption0 0x01:", readRegister(0x01));
122+
debugPrint("ChargeOption0 0x00:", readRegister(0x00));
123+
debugPrint("ADCOptions 0x3B:", readRegister(0x3B));
124+
debugPrint("ADCOptions 0x3A:", readRegister(0x3A));
125+
126+
debugPrint("VSYS 0x26:", readRegister(0x26));
127+
debugPrint("ICHG 0x29:", readRegister(0x29));
128+
debugPrint("IDCHG 0x28:", readRegister(0x28));
129+
130+
Serial.print("VBUS: ");
131+
Serial.println(readRegister(0x27) * 0.064);
132+
Serial.print("VSYS: ");
133+
Serial.println(readRegister(0x2D) * 0.064);
134+
Serial.print("VBAT: ");
135+
Serial.println(readRegister(0x2C) * 0.064);
136+
}

ec/src/test.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)