Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GLOBAL] Refactor: HAL #664

Draft
wants to merge 148 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
1fc1e9c
HAL: PMIC - First Commit, Replaces XPowersLib
rouing Jan 8, 2025
3fd047d
Attempt 1: Fixing CTOR
rouing Jan 8, 2025
682217a
Attempt 2: Fixing
rouing Jan 9, 2025
7455157
Attempt 3: Fixing M5SCS3
rouing Jan 9, 2025
24411dd
Attempt 3: Pointers?
rouing Jan 9, 2025
24b2f33
Attempt 4: Fix Includes
rouing Jan 9, 2025
274305d
Attempt 5: Pointers
rouing Jan 9, 2025
aab3a33
Attempt 6: More fixes
rouing Jan 9, 2025
39c3d1c
Attempt 7: Typedef issues
rouing Jan 9, 2025
656647b
Milestone?
rouing Jan 9, 2025
e895167
Fix Smoochie board
rouing Jan 9, 2025
3112f9e
Merge branch 'pr3y:main' into dev-hal
rouing Jan 9, 2025
fa8e098
[PMIC] [SY6970] Fix/Cleanup
rouing Jan 9, 2025
26b8acb
[RFID] [PN532] Add Datasheet
rouing Jan 9, 2025
3c79349
[FUEL] [BQ7220] Add Registers
rouing Jan 9, 2025
9f77274
[FUEL] [BQ7220] Header Guard
rouing Jan 9, 2025
8bf2893
[RTC] [BM8563] Add Registers
rouing Jan 10, 2025
53ed10b
Merge branch 'dev-hal' of https://github.com/rouing/Bruce into dev-hal
rouing Jan 10, 2025
a09ff24
[RTC] [BM8563] Add Datasheet
rouing Jan 10, 2025
4280867
[RTC] Library Prep
rouing Jan 10, 2025
dd4efa6
[RTC] Prep
rouing Jan 11, 2025
8c8f264
[PMIC] Cleanup
rouing Jan 11, 2025
7944a04
[FUEL] Prep
rouing Jan 11, 2025
604d226
[m5stack-cplus1_1] Prep conversion to HAL lib
rouing Jan 11, 2025
bcf47be
Add clang-format
rouing Jan 11, 2025
d066eb3
Merge branch 'pr3y:main' into dev-hal
rouing Jan 11, 2025
740fb2a
Formatting
rouing Jan 11, 2025
c1626bb
[Global] Cang formatter adjust
rouing Jan 11, 2025
f502dd0
add to gitignore
rouing Jan 11, 2025
9bdeb96
.
rouing Jan 11, 2025
5d50371
[PMIC] Chores
rouing Jan 11, 2025
740b00e
Datasheets
rouing Jan 12, 2025
fad566e
Clang Formatter
rouing Jan 12, 2025
cc74d1c
.
rouing Jan 12, 2025
c153bf6
[RTC] More Prep
rouing Jan 12, 2025
b9d838f
Chores
rouing Jan 12, 2025
0c13f13
[RTC] Additions
rouing Jan 16, 2025
23af6e4
[PMIC] .
rouing Jan 16, 2025
3793c09
[BUS] Add SMBus
rouing Jan 17, 2025
0911f46
2432W328R and 2432S024R try
bmorcelli Jan 17, 2025
fc4999b
colors and dog feed
bmorcelli Jan 17, 2025
7a62fee
feed the dog
bmorcelli Jan 17, 2025
d691d7c
2432W328R and 2432S024R try 2
bmorcelli Jan 18, 2025
f0be51c
Atualizar o CYD-2432S028.ini
bmorcelli Jan 18, 2025
76fee60
[PMIC] Datasheet Updates
rouing Jan 18, 2025
ea97d10
Merge branch 'pr3y:main' into dev-hal
rouing Jan 19, 2025
68c1b02
pl-PL keyboard, 2432S024R ney lib test
bmorcelli Jan 20, 2025
560893b
Merge branch 'pr3y:main' into main
bmorcelli Jan 20, 2025
17d96ac
fix
bmorcelli Jan 20, 2025
0a37f76
Merge branch 'main' of https://github.com/bmorcelli/Bruce
bmorcelli Jan 20, 2025
4944338
libdep
bmorcelli Jan 20, 2025
4eacee0
forget lib, copy instead
bmorcelli Jan 20, 2025
d055d2d
SPI working, finger crossed!
bmorcelli Jan 20, 2025
29a2757
&
bmorcelli Jan 20, 2025
3143508
Update TV-B-Gone.cpp
stormyzio Jan 20, 2025
529e9bb
Merge branch 'pr3y:main' into dev-hal
rouing Jan 21, 2025
e25c815
new try on CYD-2432S024 and 2430W328R
bmorcelli Jan 21, 2025
63b5b99
CYD2432W328R
bmorcelli Jan 21, 2025
d7dc159
watchdog
bmorcelli Jan 21, 2025
4f01f00
Merge branch 'pr3y:main' into dev-hal
rouing Jan 22, 2025
54b68cf
Bunch of stuff
rouing Jan 22, 2025
0549c19
[PMIC] More changes
rouing Jan 22, 2025
db0324c
Fix?
rouing Jan 22, 2025
607ff33
[SMBUS[ Fix
rouing Jan 22, 2025
7d0e854
Disabling WDT
bmorcelli Jan 22, 2025
db8d23a
fix: back btn on cplus1_1
Lamnxzp Jan 22, 2025
2c87dd5
Add power-off menu item for T-Display S3
epiHATR Jan 22, 2025
95981ec
Change Select button to PIN 16
epiHATR Jan 22, 2025
27795a6
Merge branch 'pr3y:main' into Add-t-display-s3-power-off
epiHATR Jan 23, 2025
8832c73
Fix raw sniffer not writing to SDCard CYD
7wp81x Jan 24, 2025
7e66338
Merge branch 'pr3y:main' into dev-hal
rouing Jan 25, 2025
91e1108
Merge branch 'pr3y:main' into main
bmorcelli Jan 26, 2025
a98cdf7
added text editor for WebUi
AZachia Jan 28, 2025
03e5b18
Change file allocation in serialcmds to dynamic
Tawank Jan 28, 2025
d3b7c20
Fix gif memory allocation in js interpreter
Tawank Jan 28, 2025
a561200
fix for some restartings
bmorcelli Jan 28, 2025
cfb7d78
unified lib
bmorcelli Jan 28, 2025
8399833
Add psram info to getFreeHeapSize in js
Tawank Jan 28, 2025
a48e64b
Change c_function to c_lightfunc in global js functions
Tawank Jan 28, 2025
24439fe
Change js cheap allocation to PSRAM
Tawank Jan 28, 2025
e8daaff
Fix wifiScan function in js
Tawank Jan 28, 2025
d0e3b55
Merge pull request #728 from 7wp81x/patch-1
pr3y Jan 28, 2025
40e370d
Merge pull request #706 from stormyzio/patch-1
pr3y Jan 28, 2025
13f3eee
Fix wifiConnect function in js
Tawank Jan 28, 2025
bbbe7c0
Merge pull request #716 from epiHATR/Add-t-display-s3-power-off
pr3y Jan 28, 2025
cd197b6
T-Embed Battery Fix, new try on S024R and W328R
bmorcelli Jan 29, 2025
a08217d
log enforcement on S024R and W328R
bmorcelli Jan 29, 2025
c5dfa42
Merge branch 'pr3y:main' into main
bmorcelli Jan 29, 2025
494192d
Merge pull request #743 from bmorcelli/main
pr3y Jan 29, 2025
0de3bad
Merge branch 'main' into interpreter_js_file_fix
Tawank Jan 29, 2025
5a72881
Merge remote-tracking branch 'upstream/main'
AZachia Jan 29, 2025
b555cea
Remove pl_PL keyboard layout make an alias to en_US
Tawank Jan 29, 2025
d5dd94c
Merge pull request #722 from Lamnxzp/fix
pr3y Jan 29, 2025
3e35cd8
fixed InputHandler condition to digitalRead on cplus1
pr3y Jan 29, 2025
3c16c93
cplus1 prev button fix?
pr3y Jan 29, 2025
27d0497
Merge pull request #742 from Tawank/interpreter_js_file_fix
pr3y Jan 29, 2025
d75c463
Merge pull request #746 from Tawank/pl_layout
pr3y Jan 29, 2025
c9328c7
Merge remote-tracking branch 'upstream/main'
AZachia Jan 29, 2025
6abe5b0
Merge pull request #741 from AZachia/main
pr3y Jan 30, 2025
9842133
.
rouing Jan 31, 2025
d1c612f
.
rouing Jan 31, 2025
3b99b23
Merge branch 'dev-hal' of https://github.com/rouing/Bruce into dev-hal
rouing Jan 31, 2025
1364f94
temp changes
rouing Jan 31, 2025
ff5665d
HAL: PMIC - First Commit, Replaces XPowersLib
rouing Jan 8, 2025
2e9bfeb
Attempt 1: Fixing CTOR
rouing Jan 8, 2025
dc51530
Attempt 2: Fixing
rouing Jan 9, 2025
cac7216
Attempt 3: Fixing M5SCS3
rouing Jan 9, 2025
3028174
Attempt 3: Pointers?
rouing Jan 9, 2025
489cd6e
Attempt 4: Fix Includes
rouing Jan 9, 2025
c772c08
Attempt 5: Pointers
rouing Jan 9, 2025
c1d6914
Attempt 6: More fixes
rouing Jan 9, 2025
8cedd8b
Attempt 7: Typedef issues
rouing Jan 9, 2025
d271d2c
Milestone?
rouing Jan 9, 2025
f10588b
Fix Smoochie board
rouing Jan 9, 2025
e3427b4
[PMIC] [SY6970] Fix/Cleanup
rouing Jan 9, 2025
3030c4c
[RFID] [PN532] Add Datasheet
rouing Jan 9, 2025
df70bcd
[FUEL] [BQ7220] Add Registers
rouing Jan 9, 2025
a178c24
[FUEL] [BQ7220] Header Guard
rouing Jan 9, 2025
0358f49
[RTC] [BM8563] Add Registers
rouing Jan 10, 2025
929d096
[RTC] [BM8563] Add Datasheet
rouing Jan 10, 2025
7542f06
[RTC] Library Prep
rouing Jan 10, 2025
62c3633
[RTC] Prep
rouing Jan 11, 2025
a63520b
[PMIC] Cleanup
rouing Jan 11, 2025
1d55ac1
[FUEL] Prep
rouing Jan 11, 2025
5b16f30
[m5stack-cplus1_1] Prep conversion to HAL lib
rouing Jan 11, 2025
2e4d658
Add clang-format
rouing Jan 11, 2025
f4d4ef6
Formatting
rouing Jan 11, 2025
89b06b1
[Global] Cang formatter adjust
rouing Jan 11, 2025
c422bdc
add to gitignore
rouing Jan 11, 2025
4bc2492
.
rouing Jan 11, 2025
7069e4d
[PMIC] Chores
rouing Jan 11, 2025
073c7cc
Datasheets
rouing Jan 12, 2025
c9bdb08
Clang Formatter
rouing Jan 12, 2025
1730e70
.
rouing Jan 12, 2025
33b7a58
[RTC] More Prep
rouing Jan 12, 2025
8c94f13
Chores
rouing Jan 12, 2025
e1605aa
[RTC] Additions
rouing Jan 16, 2025
88afc4a
[PMIC] .
rouing Jan 16, 2025
abd5b6c
[BUS] Add SMBus
rouing Jan 17, 2025
b47faee
[PMIC] Datasheet Updates
rouing Jan 18, 2025
e12ca06
Bunch of stuff
rouing Jan 22, 2025
6b64aa4
[PMIC] More changes
rouing Jan 22, 2025
fd10a49
Fix?
rouing Jan 22, 2025
047626d
[SMBUS[ Fix
rouing Jan 22, 2025
4b3aa65
.
rouing Jan 31, 2025
c6cd43b
.
rouing Jan 31, 2025
9710250
temp changes
rouing Jan 31, 2025
75215a0
Merge remote-tracking branch 'origin/dev-hal' into dev-hal
rouing Jan 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
BasedOnStyle: LLVM
UseTab: Never
IndentWidth: 4
TabWidth: 2
BreakBeforeBraces: Allman
IncludeBlocks: Regroup
ColumnLimit: 0
AccessModifierOffset: -4
NamespaceIndentation: All
FixNamespaceComments: true
BitFieldColonSpacingStyle: Both
AllowShortIfStatementsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortNamespacesOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlignConsecutiveDeclarations: true
AlignArrayOfStructures: Left
AlignConsecutiveBitFields:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: false
AcrossComments: true
AlignCaseColons: true
AlignConsecutiveTableGenDefinitionColons: true
AlignTrailingComments: true
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: true
SortUsingDeclarations: LexicographicNumeric
SpaceBeforeCaseColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeJsonColon: true
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentExternBlock: Indent
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Checks: '-*,clang-analyzer-cplusplus*,llvm-header-guard'
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
3208150197b1bd422021c608f57b9b3e4e7040f9

1b84d09669504d4c0c6ab25678ed7c15bd610432
7 changes: 7 additions & 0 deletions .github/workflows/buil_parallel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ jobs:
family: "ESP32",
partitions: { bootloader_addr: "0x1000" },
}
- {
vendor: "CYD",
name: "CYD-2432W328R",
env: "CYD-2432W328R",
family: "ESP32",
partitions: { bootloader_addr: "0x1000" },
}
- {
vendor: "CYD",
name: "CYD-2432W328C(inv_colors)_and_CYD-2432S024C",
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
.vscode/launch.json
.vscode/extensions.json
.vscode/ipch
.vscode/settings.json
Bruce3_*.bin
bruce.conf
_*.sh
tmp
ISSUES.md
ISSUES.md
.vscode/settings.json
12 changes: 9 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"idf.portWin": "COM4",
"files.associations": {
"*.k": "kamailio",
"iosfwd": "cpp",
"iostream": "cpp",
"array": "cpp",
Expand Down Expand Up @@ -57,10 +57,16 @@
"iomanip": "cpp",
"chrono": "cpp",
"ratio": "cpp",
"*.tpp": "cpp"
"*.tpp": "cpp",
"condition_variable": "cpp",
"mutex": "cpp",
"thread": "cpp",
"esp_log.h": "c"
},
"githubPullRequests.ignoredPullRequestBranches": [
"main"
],
"cmake.sourceDirectory": "C:/Projetos/Bruce/lib/M5GFX"
"yaml.schemas": {
"https://json.schemastore.org/clang-tidy.json": "file:///c%3A/Users/cardoin/Documents/Repo/Forks/Bruce/.clang-tidy"
}
}
36 changes: 27 additions & 9 deletions boards/CYD-2432S028.ini
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ build_flags =
-DILI9341_2_DRIVER=1
-DUSE_HSPI_PORT=1
-DTFT_HEIGHT=320
-DTFT_WIDTH=240 ;240-20 lower margin
-DTFT_WIDTH=240
-DTFT_MISO=12
-DTFT_MOSI=13
-DTFT_SCLK=14
Expand Down Expand Up @@ -213,21 +213,39 @@ build_flags =
-DLITE_VERSION=1


[env:CYD-2432W328R]
extends = env:CYD-2432S028
build_flags =
${env:CYD-2432S028.build_flags}
-DTFT_INVERSION_ON # TFT is not color inverted
-DTFT_BL=27
# from https://github.com/pr3y/Bruce/issues/690#issuecomment-2602933450
# uses the same driver as CYD-2432S024R, but with different calibration Data, trying same as 2432S028R
-DESP32DMA
-DTOUCH_OFFSET_ROTATION=1
-DSPI_FREQUENCY=55000000
-DSPI_READ_FREQUENCY=20000000
-DSPI_TOUCH_FREQUENCY=2500000
-DUSE_TFT_eSPI_TOUCH
-DTOUCH_CONFIG_INT_GPIO_NUM=36
-DCYD2432W328R


[env:CYD-2432S024R] # CYD-2432S024R
extends = env:CYD-2432S028
build_flags =
${env:CYD-2432S028.build_flags}
;-DTFT_INVERSION_ON TFT is not color inverted
-DTFT_INVERSION_ON # TFT is not color inverted
-DTFT_BL=27

-DTOUCH_XPT2046_SPI
-DXPT2046_SPI_BUS_MOSI_IO_NUM=13
-DXPT2046_SPI_BUS_MISO_IO_NUM=12
-DXPT2046_SPI_BUS_SCLK_IO_NUM=14
-DXPT2046_SPI_CONFIG_CS_GPIO_NUM=33
-DXPT2046_TOUCH_CONFIG_INT_GPIO_NUM=36
# https://github.com/Fr4nkFletcher/ESP32-Marauder-Cheap-Yellow-Display/blob/master/User_Setup_cyd24.h
-DESP32DMA
-DTOUCH_OFFSET_ROTATION=1
-DSPI_FREQUENCY=55000000
-DSPI_READ_FREQUENCY=20000000
-DSPI_TOUCH_FREQUENCY=2500000
-DUSE_TFT_eSPI_TOUCH
-DTOUCH_CONFIG_INT_GPIO_NUM=36
-DCYD2432S024R


################################# END OF CYD MODELS ####################################################
65 changes: 55 additions & 10 deletions boards/CYD-2432S028/interface.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#include "interface.h"
#include "core/powerSave.h"
#include "core/utils.h"
#include <Arduino.h>

#if defined(HAS_CAPACITIVE_TOUCH)
#include "CYD28_TouchscreenC.h"
#define CYD28_DISPLAY_HOR_RES_MAX 240
#define CYD28_DISPLAY_VER_RES_MAX 320
CYD28_TouchC touch(CYD28_DISPLAY_HOR_RES_MAX, CYD28_DISPLAY_VER_RES_MAX);
#elif defined(USE_TFT_eSPI_TOUCH)
#define XPT2046_CS TOUCH_CS
bool _IH_touched = false;
void IRAM_ATTR _IH_touch(void){
_IH_touched=true;
}
#else
#include "CYD28_TouchscreenR.h"
#define CYD28_DISPLAY_HOR_RES_MAX 320
Expand All @@ -24,20 +31,23 @@
** Location: main.cpp
** Description: initial setup for the device
***************************************************************************************/
SPIClass touchSPI;
void _setup_gpio() {
#ifndef HAS_CAPACITIVE_TOUCH // Capacitive Touchscreen uses I2C to communicate
pinMode(XPT2046_CS, OUTPUT);
digitalWrite(XPT2046_CS, HIGH);
#endif
//touchSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);

#if !defined(USE_TFT_eSPI_TOUCH) // Use libraries
if(!touch.begin()) {
Serial.println("Touch IC not Started");
log_i("Touch IC not Started");
} else log_i("Touch IC Started");

#ifndef HAS_CAPACITIVE_TOUCH // Capacitive Touchscreen uses I2C to communicate
digitalWrite(XPT2046_CS, LOW);
#endif

#if defined(USE_TFT_eSPI_TOUCH)
pinMode(TOUCH_CS, OUTPUT);
attachInterrupt(TOUCH_CONFIG_INT_GPIO_NUM,_IH_touch,FALLING);
#endif
}

/***************************************************************************************
Expand Down Expand Up @@ -76,9 +86,44 @@ void _setBrightness(uint8_t brightval) {
** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
**********************************************************************/
void InputHandler(void) {
if (touch.touched()) { //touch.tirqTouched() &&
static long tmp=0;
if (millis()-tmp>200) { // I know R3CK.. I Should NOT nest if statements..
// but it is needed to not keep SPI bus used without need, it save resources

#if defined(USE_TFT_eSPI_TOUCH)
#if defined(CYD2432S024R)
//uint16_t calData[5] = { 481, 3053, 433, 3296, 3 }; // from https://github.com/Fr4nkFletcher/ESP32-Marauder-Cheap-Yellow-Display/blob/3eed991e9336d3e711e3eb5d6ece7ba023132fef/esp32_marauder/Display.cpp#L43
#elif defined(CYD2432W328R)
//uint16_t calData[5] = { 350, 3465, 188, 3431, 2 }; // from https://github.com/Fr4nkFletcher/ESP32-Marauder-Cheap-Yellow-Display/blob/3eed991e9336d3e711e3eb5d6ece7ba023132fef/esp32_marauder/Display.cpp#L40
#endif
uint16_t calData[5] = { 391, 3491, 266, 3505, 7 };
tft.setTouch(calData);
TouchPoint t;
checkPowerSaveTime();

if(_IH_touched) {
NextPress=false;
PrevPress=false;
UpPress=false;
DownPress=false;
SelPress=false;
EscPress=false;
AnyKeyPress=false;
NextPagePress=false;
PrevPagePress=false;
touchPoint.pressed=false;
_IH_touched=false;
digitalWrite(TFT_CS,HIGH);
digitalWrite(TOUCH_CS,LOW);
tft.getTouch(&t.x, &t.y,50);
digitalWrite(TOUCH_CS,HIGH);
Serial.printf("Touched with Z=%d", tft.getTouchRawZ());
#else
if(touch.touched()) {
auto t = touch.getPointScaled();
t = touch.getPointScaled();
#endif

if(bruceConfig.rotation==3) {
t.y = (tftHeight+20)-t.y;
t.x = tftWidth-t.x;
Expand All @@ -93,6 +138,7 @@ void InputHandler(void) {
t.x = t.y;
t.y = (tftHeight+20)-tmp;
}
Serial.printf("Touch Pressed on x=%d, y=%d\n",t.x, t.y);

if(!wakeUpScreen()) AnyKeyPress = true;
else goto END;
Expand All @@ -103,12 +149,11 @@ void InputHandler(void) {
touchPoint.pressed=true;
touchHeatMap(touchPoint);

tmp=millis();
}
}
END:
if(AnyKeyPress) {
long tmp=millis();
while((millis()-tmp)<200 && (touch.touched()));
}
delay(0);
}

/*********************************************************************
Expand Down
1 change: 0 additions & 1 deletion boards/lilygo-t-embed-cc1101.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ build_flags =

lib_deps =
${env.lib_deps}
lewisxhe/XPowersLib @0.2.6
mathertel/RotaryEncoder @1.5.3
fastled/FastLED @3.9.4
38 changes: 20 additions & 18 deletions boards/lilygo-t-embed-cc1101/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ IRAM_ATTR void checkPosition();
#if defined(T_EMBED_1101)
// Power handler for battery detection
#include <Wire.h>
#include <XPowersLib.h>
#include <HAL.hpp>
#include <esp32-hal-dac.h>
XPowersPPM PPM;
PMIC pmic;
#elif defined(T_EMBED)
#include <driver/adc.h>
#include <esp_adc_cal.h>
Expand All @@ -25,6 +25,7 @@ IRAM_ATTR void checkPosition();
#include <bq27220.h>
BQ27220 bq;
#endif
TwoWire* myWire = &Wire;
/***************************************************************************************
** Function name: _setup_gpio()
** Description: initial setup for the device
Expand All @@ -47,22 +48,22 @@ void _setup_gpio() {
pinMode(PIN_POWER_ON, OUTPUT);
digitalWrite(PIN_POWER_ON, HIGH); // Power on CC1101 and LED
bool pmu_ret = false;
Wire.begin(GROVE_SDA, GROVE_SCL);
pmu_ret = PPM.init(Wire, GROVE_SDA, GROVE_SCL, BQ25896_SLAVE_ADDRESS);
myWire->begin(GROVE_SDA, GROVE_SCL);
pmu_ret = pmic.init(Wire, GROVE_SDA, GROVE_SCL, BQ25896_SLAVE_ADDRESS);
if(pmu_ret) {
PPM.setSysPowerDownVoltage(3300);
PPM.setInputCurrentLimit(3250);
Serial.printf("getInputCurrentLimit: %d mA\n",PPM.getInputCurrentLimit());
PPM.disableCurrentLimitPin();
PPM.setChargeTargetVoltage(4208);
PPM.setPrechargeCurr(64);
PPM.setChargerConstantCurr(832);
PPM.getChargerConstantCurr();
Serial.printf("getChargerConstantCurr: %d mA\n",PPM.getChargerConstantCurr());
PPM.enableADCMeasure();
PPM.enableCharge();
PPM.enableOTG();
PPM.disableOTG();
pmic.setSysPowerDownVoltage(3300);
pmic.setInputCurrentLimit(3250);
Serial.printf("getInputCurrentLimit: %d mA\n",pmic.getInputCurrentLimit());
pmic.disableCurrentLimitPin();
pmic.setChargeTargetVoltage(4208);
pmic.setPrechargeCurr(64);
pmic.setChargerConstantCurr(832);
pmic.getChargerConstantCurr();
Serial.printf("getChargerConstantCurr: %d mA\n",pmic.getChargerConstantCurr());
pmic.enableMeasure(HAL::PMIC::MeasureMode::CONTINUOUS);
pmic.enableCharge();
pmic.enableOTG();
pmic.disableOTG();
}
#else
pinMode(BAT_PIN,INPUT); // Battery value
Expand Down Expand Up @@ -92,7 +93,8 @@ void _setup_gpio() {
int getBattery() {
int percent=0;
#if defined(USE_BQ27220_VIA_I2C)
percent=bq.getChargePcnt();
//percent=bq.getChargePcnt(); // this function runs bq.getRemainCap()/bq.getFullChargeCap().... bq.getFullChargeCap() is hardcoded int 3000.
percent=bq.getRemainCap()/10.7; // My battery is 1300mAh and bq.getRemainCap() doesn't go upper than 1083, that is why i'm dividing by 10.7 (var/1070)*100
#elif defined(T_EMBED)
uint8_t _batAdcCh = ADC1_GPIO4_CHANNEL;
uint8_t _batAdcUnit = 1;
Expand Down
1 change: 0 additions & 1 deletion boards/lilygo-t-embed.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ build_flags =

lib_deps =
${env.lib_deps}
lewisxhe/XPowersLib @0.2.6
mathertel/RotaryEncoder @1.5.3
fastled/FastLED @3.9.4
2 changes: 1 addition & 1 deletion boards/m5stack-core.ini
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ build_flags =

lib_deps =
${env.lib_deps}
m5stack/M5Unified @ ^0.2.2
m5stack/M5Unified @ 0.2.2

[env:m5stack-core4mb]
extends=m5stack-core_base
Expand Down
2 changes: 1 addition & 1 deletion boards/m5stack-core2.ini
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ build_flags =

lib_deps =
${env.lib_deps}
m5stack/M5Unified @ ^0.2.2
m5stack/M5Unified @ 0.2.2
2 changes: 1 addition & 1 deletion boards/m5stack-cores3.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ build_flags =
-DRF_RX_PINS='{{"M5 RF433R", GROVE_SCL}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}'
lib_deps =
${env.lib_deps}
m5stack/M5Unified @ ^0.2.2
m5stack/M5Unified @ 0.2.2

Loading