mirror of
https://github.com/siemens-mobile-hacks/patches-src.git
synced 2026-11-25 22:27:17 +00:00
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
#include <swilib.h>
|
|
|
|
#ifdef NEWSGOLD
|
|
#ifdef ELKA
|
|
#ifdef E71_45
|
|
#include "E71_45.h"
|
|
#endif
|
|
#define ACCESSORIES_COUNT 6
|
|
#else
|
|
#ifdef S75_52
|
|
#include "S75_52.h"
|
|
#endif
|
|
#define ACCESSORIES_COUNT 4
|
|
#endif
|
|
#endif
|
|
|
|
#define _IsAnyOfAccessoriesConnected ((int (*)(uint8_t *, uint8_t))(ADDR_IsAnyOfAccessoriesConnected))
|
|
|
|
#define IsDisabledUSBCharging() !((*ADDR_RamAccessoriesFlags) & (1U << 21))
|
|
|
|
#define Set ((int (*)(void *, int, int))(ADDR_Set))
|
|
|
|
__attribute__((target("thumb")))
|
|
__attribute__((section(".text.Hook_1")))
|
|
int Hook_1(void *r0, int r1, int r2) {
|
|
if (IsDisabledUSBCharging()) {
|
|
if (_IsAnyOfAccessoriesConnected(ACCESSORIES, 6)) {
|
|
return 0;
|
|
}
|
|
}
|
|
return Set(r0, r1, r2);
|
|
}
|
|
|
|
#define GetState ((int (*)(void *))(ADDR_GetState))
|
|
|
|
__attribute__((target("thumb")))
|
|
__attribute__((section(".text.Hook_2")))
|
|
int Hook_2(void *r0) {
|
|
int state = GetState(r0);
|
|
if (IsDisabledUSBCharging()) {
|
|
if (state == 1) {
|
|
state = 0;
|
|
} else if (state == 2) {
|
|
if (_IsAnyOfAccessoriesConnected(ACCESSORIES, ACCESSORIES_COUNT)) {
|
|
state = 0;
|
|
}
|
|
}
|
|
}
|
|
return state;
|
|
}
|