diff --git a/api/extapp_api.c b/api/extapp_api.c index 4d665e259..888420761 100644 --- a/api/extapp_api.c +++ b/api/extapp_api.c @@ -4,6 +4,32 @@ extern void (* const *_api_base)(void); +// We need to redefine DataTime struct to match the one in extapp_api.h file, because we can't include it directly +struct DateTime { + int tm_sec; + int tm_min; + int tm_hour; // 0-23 + int tm_mday; // 1-31 + int tm_mon; // 1-12 + int tm_year; + int tm_wday; // 0-6, 0 is Monday +}; + +// Settings +struct Settings { + // 0 for degrees, 1 for radians, 2 for gradians + uint8_t angleUnit; + // 0 for decimal, 1 for Scientific, 2 for Engineering + uint8_t displayMode; + // Raw number of digits, max is 14 + uint8_t numberOfSignificantDigits; + // 0 for real, 1 for cartesian, 2 for polar + uint8_t complexFormat; + // If true, the big font should be used. + bool largeFont; +}; + + uint64_t extapp_millis() { return ((uint64_t (*)(void))_api_base[0])(); } @@ -96,6 +122,95 @@ bool extapp_writememory(unsigned char * dest,const unsigned char * data,size_t l return ((bool (*)(unsigned char *, const unsigned char *, size_t))_api_base[22])(dest,data,length); } -bool extapp_inexammode(){ +bool extapp_inExamMode(){ return ((bool (*)(void ))_api_base[23])(); } + +uint8_t extapp_getBrightness(){ + return ((uint8_t (*)(void ))_api_base[24])(); +} + +void extapp_setBrightness(uint8_t brightness){ + ((void (*)(uint8_t))_api_base[25])(brightness); +} + +int extapp_batteryLevel(){ + return ((int (*)(void ))_api_base[26])(); +} + +float extapp_batteryVoltage(){ + return ((float (*)(void ))_api_base[27])(); +} + +bool extapp_batteryCharging(){ + return ((bool (*)(void ))_api_base[28])(); +} + +int extapp_batteryPercentage(){ + return ((int (*)(void ))_api_base[29])(); +} + +struct DateTime extapp_getDateTime(){ + return ((struct DateTime (*)(void ))_api_base[30])(); +} + +void extapp_setDateTime(struct DateTime dt){ + ((void (*)(struct DateTime))_api_base[31])(dt); +} + +void extapp_setRTCMode(int mode){ + ((void (*)(int))_api_base[32])(mode); +} + +int extapp_getRTCMode(){ + return ((int (*)(void ))_api_base[33])(); +} + +void extapp_getTime(struct DateTime *dt){ + ((void (*)(struct DateTime *))_api_base[34])(dt); +} + +uint32_t extapp_random(){ + return ((uint32_t (*)(void ))_api_base[35])(); +} + +void extapp_reloadTitleBar(){ + ((void (*)(void ))_api_base[36])(); +} + +const char * extapp_username(){ + return ((const char * (*)(void ))_api_base[37])(); +} + +const char * extapp_getOS(){ + return ((const char * (*)(void ))_api_base[38])(); +} + +const char * extapp_getOSVersion(){ + return ((const char * (*)(void ))_api_base[39])(); +} + +void extapp_getOSCommit(char *commit){ + ((void (*)(char *))_api_base[40])(commit); +} + +size_t extapp_storageSize(){ + return ((size_t (*)(void ))_api_base[41])(); +} + +size_t extapp_storageAvailable(){ + return ((size_t (*)(void ))_api_base[42])(); +} + +size_t extapp_storageUsed(){ + return ((size_t (*)(void ))_api_base[43])(); +} + + +struct Settings extapp_getSettings(){ + return ((struct Settings (*)(void ))_api_base[44])(); +} + +void extapp_setSettings(struct Settings settings){ + ((void (*)(struct Settings))_api_base[45])(settings); +} diff --git a/api/extapp_api.h b/api/extapp_api.h index ebd7f2c82..6f3811772 100644 --- a/api/extapp_api.h +++ b/api/extapp_api.h @@ -5,7 +5,7 @@ #include #include -#define API_VERSION 2 +#define API_VERSION 3 #ifdef __cplusplus #define EXTERNC extern "C" @@ -244,6 +244,33 @@ #define KEY_PRGM_SHIFT 78 #define KEY_PRGM_MENU 48 +// Types definitions +// Date and time +struct DateTime { + int tm_sec; + int tm_min; + int tm_hour; // 0-23 + int tm_mday; // 1-31 + int tm_mon; // 1-12 + int tm_year; + int tm_wday; // 0-6, 0 is Monday +}; + +// Settings +// TODO: Improve this structure when using C++ +struct Settings { + // 0 for degrees, 1 for radians, 2 for gradians + uint8_t angleUnit; + // 0 for decimal, 1 for Scientific, 2 for Engineering + uint8_t displayMode; + // Raw number of digits, max is 14 + uint8_t numberOfSignificantDigits; + // 0 for real, 1 for cartesian, 2 for polar + uint8_t complexFormat; + // If true, the big font should be used. + bool largeFont; +}; + // External API functions /** * Get the current date, in milliseconds, from the boot, excluding suspended time @@ -408,7 +435,118 @@ EXTERNC bool extapp_writesector(unsigned char * dest,const unsigned char * data * Get if the exam mode is active * @return bool, true if the exam mode is active */ -EXTERNC bool extapp_inexammode(); +EXTERNC bool extapp_inExamMode(); +/** + * Get the actual brightness + * @return uint8_t, the actual brightness + */ +EXTERNC uint8_t extapp_getBrightness(); +/** + * Set the brightness + * @param brightness uint8_t, the brightness to set + */ +EXTERNC void extapp_setBrightness(uint8_t brightness); +/** + * Get the battery level (0-3, 0 is empty, 1 is low, 2 is somewhere in between, 3 is full) + * @return int, the battery level + */ +EXTERNC int extapp_batteryLevel(); +/** + * Get the battery voltage (in V) + * @return float, the battery voltage + */ +EXTERNC float extapp_batteryVoltage(); +/** + * Get if the battery is charging + * @return bool, true if the battery is charging + */ +EXTERNC bool extapp_batteryCharging(); +/** + * Get battery percentage (0-100), computed from battery voltage + * @return int, the battery percentage + */ +EXTERNC int extapp_batteryPercentage(); +/** + * Get the current RTC time + * @return DateTime, the current RTC time + */ +EXTERNC struct DateTime extapp_getDateTime(); + +/** + * Set the RTC time + * @param dt DateTime, the time to set + */ +EXTERNC void extapp_setDateTime(struct DateTime dt); +/** + * Set the RTC mode (0 for disabled, 1 for LSI (low consumption), 2 for HSE (high precision)) + * @param mode int, the mode to set + */ +EXTERNC void extapp_setRTCMode(int mode); +/** + * Get the RTC mode (0 for disabled, 1 for LSI (low consumption), 2 for HSE (high precision)) + * @return int, the RTC mode + */ +EXTERNC int extapp_getRTCMode(); +/** + * Get the current time from 2000-01-01 00:00:00 + * @return uint64_t, the current time from 2000-01-01 00:00:00 + */ +EXTERNC uint64_t extapp_getTime(); +/** + * Get a 32 bit true random number that can be casted to any (32 bit or less) type + * @return uint32_t, the random number + */ +EXTERNC uint32_t extapp_random(); +/** + * Reload the title bar + */ +EXTERNC void extapp_reloadTitleBar(); +/** + * Get the username + * @return const char *, the username + */ +EXTERNC const char * extapp_username(); +/** + * Get the OS name + * @return const char *, the OS name + */ +EXTERNC const char * extapp_getOS(); +/** + * Get the OS version + * @return const char *, the OS version + */ +EXTERNC const char * extapp_getOSVersion(); +/** + * Get the OS commit hash + * @return const char *, the OS commit hash + */ +EXTERNC const char * extapp_getOSCommit(); +/** + * Get the RAM storage size + * @return size_t, the RAM storage size + */ +EXTERNC size_t extapp_storageSize(); +/** + * Get the available RAM storage size + * @return size_t, the available RAM storage size + */ +EXTERNC size_t extapp_storageAvailable(); +/** + * Get the used RAM storage size + * @return size_t, the used RAM storage size + */ +EXTERNC size_t extapp_storageUsed(); +/** + * Get the settings + * @return struct Settings, the settings + */ +EXTERNC struct Settings extapp_getSettings(); +/** + * Set the settings + * @param settings struct Settings, the settings to set + */ +EXTERNC void extapp_setSettings(struct Settings settings); + EXTERNC uint32_t _heap_size; EXTERNC void *_heap_base; EXTERNC void *_heap_ptr; diff --git a/api/extapp_startup.c b/api/extapp_startup.c index 4038f055e..512f08af9 100644 --- a/api/extapp_startup.c +++ b/api/extapp_startup.c @@ -15,14 +15,14 @@ extern char _bss_section_end_ram; extern cxx_constructor _init_array_start; extern cxx_constructor _init_array_end; -extern void extapp_main(void); +extern void extapp_main(int argc, char *argv[]); void *_heap_base, *_heap_ptr; const void *_api_base; uint32_t _heap_size; jmp_buf oom_jmp_buf; -uint32_t _extapp_start(const uint32_t api_version, const void * api_base, void * heap, const uint32_t heap_size) { +uint32_t _extapp_start(const uint32_t api_version, const void * api_base, void * heap, const uint32_t heap_size, int argc, char * argv[]) { if(api_version != API_VERSION) { return 1; @@ -43,7 +43,7 @@ uint32_t _extapp_start(const uint32_t api_version, const void * api_base, void * for (cxx_constructor * c = &_init_array_start; c<&_init_array_end; c++) { (*c)(); } - extapp_main(); + extapp_main(argc, argv); } return result; diff --git a/apps/BadApple/app.elf b/apps/BadApple/app.elf index d1c64da18..0034c8707 100644 Binary files a/apps/BadApple/app.elf and b/apps/BadApple/app.elf differ diff --git a/apps/BadApple/sample.c b/apps/BadApple/sample.c index 73555b5c3..ccd5bb114 100644 --- a/apps/BadApple/sample.c +++ b/apps/BadApple/sample.c @@ -5,7 +5,7 @@ #include "vdo.h" -void extapp_main() { +void extapp_main(int argc, char * argv[]) { for(unsigned int len = 0; len < vdo_len;) { uint64_t start = extapp_millis(); extapp_waitForVBlank(); diff --git a/apps/CHIP-8/app.elf b/apps/CHIP-8/app.elf index 9909f6786..f30e56056 100644 Binary files a/apps/CHIP-8/app.elf and b/apps/CHIP-8/app.elf differ diff --git a/apps/CHIP-8/main.c b/apps/CHIP-8/main.c index c353e7ac9..14bb99054 100644 --- a/apps/CHIP-8/main.c +++ b/apps/CHIP-8/main.c @@ -8,7 +8,7 @@ #include "inc/peripherals.h" #include "inc/selector.h" -void extapp_main(void) { +void extapp_main(int argc, char * argv[]) { char * rom_filename = select_rom(); init_display(); diff --git a/apps/Example-Cpp/app.elf b/apps/Example-Cpp/app.elf index 5d628750d..f2fe030d0 100644 Binary files a/apps/Example-Cpp/app.elf and b/apps/Example-Cpp/app.elf differ diff --git a/apps/Example-Cpp/main.cpp b/apps/Example-Cpp/main.cpp index 5f89ec852..9026614ac 100644 --- a/apps/Example-Cpp/main.cpp +++ b/apps/Example-Cpp/main.cpp @@ -6,9 +6,9 @@ #include "inc/peripherals.h" #include "inc/selector.h" -extern "C" void extapp_main(); +extern "C" void extapp_main(int argc, char *argv[]); -void extapp_main(void) { +void extapp_main(int argc, char * argv[]) { // Wait for the key to be released before starting the application Peripherals::waitForKeyReleased(); diff --git a/apps/Example/app.elf b/apps/Example/app.elf index 37fc24acd..a3b5d696c 100644 Binary files a/apps/Example/app.elf and b/apps/Example/app.elf differ diff --git a/apps/Example/main.c b/apps/Example/main.c index 5efa9a1c8..e71a18c2a 100644 --- a/apps/Example/main.c +++ b/apps/Example/main.c @@ -6,7 +6,7 @@ #include "inc/peripherals.h" #include "inc/selector.h" -void extapp_main(void) { +void extapp_main(int argc, char * argv[]) { // Wait for the key to be released before starting the application waitForKeyReleased(); diff --git a/apps/HexEdit/app.elf b/apps/HexEdit/app.elf index 7de857055..1e897ba5f 100644 Binary files a/apps/HexEdit/app.elf and b/apps/HexEdit/app.elf differ diff --git a/apps/HexEdit/main.c b/apps/HexEdit/main.c index 06954b680..71dde9554 100644 --- a/apps/HexEdit/main.c +++ b/apps/HexEdit/main.c @@ -132,7 +132,7 @@ void handle_scroll(int delta) { draw_ui(); } -void extapp_main() +void extapp_main(int argc, char * argv[]) { extapp_pushRectUniform(0, 0, LCD_WIDTH, LCD_HEIGHT, 0xFFFF); draw_ui(); diff --git a/apps/KhiCAS/README.md b/apps/KhiCAS/README.md index 39953d41d..a40aacc6e 100644 --- a/apps/KhiCAS/README.md +++ b/apps/KhiCAS/README.md @@ -21,6 +21,8 @@ bool iskeydown(int key) { } ``` -7. If you have build error, please check if the Makfile is modified. If yes, restore the file to the original state. -8. You can try to run `make cleanall` in the folder `apps/KhiCAS` to clean the build and rebuild the program. -9. If it continues to crash, please ask for help in an issue on the GitHub repository or on the Discord server. +7. Rename `extapp_inexammode` to `extapp_inExamMode` in the file `apps/KhiCAS/main.cpp` +8. Replace `void extapp_main() {` by `void extapp_main(int argc, char * argv[]) {` in the file `apps/KhiCAS/main.cpp` +9. If you have build error, please check if the Makfile is modified. If yes, restore the file to the original state. +10. You can try to run `make cleanall` in the folder `apps/KhiCAS` to clean the build and rebuild the program. +11. If it continues to crash, please ask for help in an issue on the GitHub repository or on the Discord server. diff --git a/apps/KhiCAS/app.elf b/apps/KhiCAS/app.elf index c78186864..ef6dfc191 100644 Binary files a/apps/KhiCAS/app.elf and b/apps/KhiCAS/app.elf differ diff --git a/apps/KhiCAS/src/main.cpp b/apps/KhiCAS/src/main.cpp index 1ff6953c9..2aa401bcb 100644 --- a/apps/KhiCAS/src/main.cpp +++ b/apps/KhiCAS/src/main.cpp @@ -22,7 +22,7 @@ extern "C" const char * mp_hal_input(const char * prompt) { extern "C" { int ext_main(); -void extapp_main() { +void extapp_main(int argc, char * argv[]) { ext_main(); } @@ -203,7 +203,7 @@ void GetKey(int * key) { } bool inexammode(){ - return extapp_inexammode(); + return extapp_inExamMode(); } } // end extern "C" diff --git a/apps/Nofrendo/app.elf b/apps/Nofrendo/app.elf index 7c629bcf3..d0cad66b1 100644 Binary files a/apps/Nofrendo/app.elf and b/apps/Nofrendo/app.elf differ diff --git a/apps/Nofrendo/epsilon/main.c b/apps/Nofrendo/epsilon/main.c index 3e7aab732..febbe5b32 100644 --- a/apps/Nofrendo/epsilon/main.c +++ b/apps/Nofrendo/epsilon/main.c @@ -122,7 +122,7 @@ static const char * select_rom() { } } -void extapp_main() { +void extapp_main(int argc, char * argv[]) { //Create commandline args const char *args[3]; args[0]="nofrendo"; diff --git a/apps/Peanut-GB/app.elf b/apps/Peanut-GB/app.elf index 619e9a857..c7723d574 100644 Binary files a/apps/Peanut-GB/app.elf and b/apps/Peanut-GB/app.elf differ diff --git a/apps/Peanut-GB/main.c b/apps/Peanut-GB/main.c index 6305696b1..0ca0e8b0b 100644 --- a/apps/Peanut-GB/main.c +++ b/apps/Peanut-GB/main.c @@ -160,7 +160,7 @@ static bool wasMSpFPressed = false; static uint8_t saveCooldown = 0; static bool MSpFfCounter = false; -void extapp_main() { +void extapp_main(int argc, char * argv[]) { struct gb_s gb; enum gb_init_error_e gb_ret; struct priv_t priv = { diff --git a/apps/Periodic/app.elf b/apps/Periodic/app.elf index 87b07fa7d..66e426cfa 100644 Binary files a/apps/Periodic/app.elf and b/apps/Periodic/app.elf differ diff --git a/apps/Periodic/periodic.c b/apps/Periodic/periodic.c index ebefaaa41..cedee60df 100644 --- a/apps/Periodic/periodic.c +++ b/apps/Periodic/periodic.c @@ -237,7 +237,7 @@ void copy(const char * text) { extapp_msleep(500); } -void extapp_main(void) { +void extapp_main(int argc, char * argv[]) { char buf[128]; bool partial_draw = false, redraw = true; int cursor_pos = 0; diff --git a/apps/UnitCircle/app.elf b/apps/UnitCircle/app.elf index e03fc9fb0..fc8819e61 100644 Binary files a/apps/UnitCircle/app.elf and b/apps/UnitCircle/app.elf differ diff --git a/apps/UnitCircle/main.c b/apps/UnitCircle/main.c index 579675c83..fe0612367 100644 --- a/apps/UnitCircle/main.c +++ b/apps/UnitCircle/main.c @@ -6,7 +6,7 @@ #include "inc/peripherals.h" #include "inc/selector.h" -void extapp_main(void) { +void extapp_main(int argc, char * argv[]) { // Wait for the key to be released before starting the application waitForKeyReleased();