Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
117 changes: 116 additions & 1 deletion api/extapp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])();
}
Expand Down Expand Up @@ -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);
}
142 changes: 140 additions & 2 deletions api/extapp_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stddef.h>
#include <stdbool.h>

#define API_VERSION 2
#define API_VERSION 3

#ifdef __cplusplus
#define EXTERNC extern "C"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions api/extapp_startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Binary file modified apps/BadApple/app.elf
Binary file not shown.
2 changes: 1 addition & 1 deletion apps/BadApple/sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Binary file modified apps/CHIP-8/app.elf
Binary file not shown.
2 changes: 1 addition & 1 deletion apps/CHIP-8/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Binary file modified apps/Example-Cpp/app.elf
Binary file not shown.
4 changes: 2 additions & 2 deletions apps/Example-Cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Binary file modified apps/Example/app.elf
Binary file not shown.
2 changes: 1 addition & 1 deletion apps/Example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Binary file modified apps/HexEdit/app.elf
Binary file not shown.
2 changes: 1 addition & 1 deletion apps/HexEdit/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions apps/KhiCAS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Binary file modified apps/KhiCAS/app.elf
Binary file not shown.
4 changes: 2 additions & 2 deletions apps/KhiCAS/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -203,7 +203,7 @@ void GetKey(int * key) {
}

bool inexammode(){
return extapp_inexammode();
return extapp_inExamMode();
}

} // end extern "C"
Binary file modified apps/Nofrendo/app.elf
Binary file not shown.
Loading