Skip to content

Commit 5532d67

Browse files
committed
SVCalls and display_draw_string : both are almost working fine.
1 parent 4553367 commit 5532d67

File tree

5 files changed

+279
-108
lines changed

5 files changed

+279
-108
lines changed

README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Copy the files you obtained to the `./src/javascript/` folder on this project (t
6464

6565
Here is a short documentation for each function that I've ported from their interface in [`eadk.h`](https://github.com/numworks/epsilon/blob/master/eadk/include/eadk/eadk.h) to a working version in JavaScript.
6666

67+
I've exposed an `Eadk` module (see example in JavaScript below, or [here](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/issues/3#issuecomment-2910813161)), which comes ready with these functions and constants:
68+
6769
> *Legend:*
6870
> - ✅ = code written, function tested!
6971
> - ✅? = code written, function not yet working!
@@ -72,7 +74,7 @@ Here is a short documentation for each function that I've ported from their inte
7274
### ✅? Eadk predefined colors
7375
`Eadk.color_black`, `Eadk.color_white`, `Eadk.color_red`, `Eadk.color_green`, `Eadk.color_blue` are the five predefined colors.
7476

75-
### ? Screen width and height
77+
### ✅ Screen width and height
7678
`Eadk.SCREEN_WIDTH` and `Eadk.SCREEN_HEIGHT` are the screen's width and height, respectively.
7779

7880
### ✅ Controlling the screen's brightness
@@ -85,31 +87,38 @@ Returns the screen's brightness, it's a 8 bits integer (`uint8_t` in C), ranging
8587
Sets the screen's brightness to this value.
8688
`brightness` **must** be an integer value which fits inside a `uint8_t`, between 0 and 256.
8789

88-
### Accessing the Battery levels
90+
### Accessing the Battery levels
8991

90-
#### `bool Eadk.battery_is_charging()`
92+
#### `bool Eadk.battery_is_charging()`
9193

9294
Indicates whether the battery is charging.
9395

94-
#### `uint8_t Eadk.battery_level()`
96+
#### `uint8_t Eadk.battery_level()`
9597

9698
Returns a 8 bits integer giving the battery level.
9799

98-
#### `float Eadk.battery_voltage()`
100+
#### `float Eadk.battery_voltage()`
99101

100102
Returns a floating value of the battery voltage (in Volt, I guess?).
101103

102104
> These functions are missing from the hardware!
103105
> See [this issue on NumWorks/epsilon's repository](https://github.com/numworks/epsilon/issues/2326)
104-
> TODO: [I could try to implement them myself, by SVC calls](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/issues/5)
106+
> DONE: [I just implemented them myself, by SVC calls](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/issues/5)
107+
108+
### ✅ Display
109+
110+
#### ❌✅ `void Eadk.display_draw_string(const char* text, uint16_t x, uint16_t y, bool large_font, uint16_t text_color, uint16_t background_color)`
105111

106-
### Display
112+
Displays a given `text` string, at a `{x,y}` position, in large/small font (`large_font`?), with the text in `text_color` and the background in `background_color`.
107113

108-
#### `void Eadk.display_draw_string(const char* text, uint16_t x, uint16_t y, bool large_font, uint16_t text_color, uint16_t background_color)`
114+
For instance:
115+
```javascript
116+
Eadk.display_draw_string(text, x, y, large, text_color, background_color);
117+
```
109118

110-
TODO: I still haven't been able to define this one correctly, due to the `char* text` that I don't know how to declare in JSON (in the JSON to C process used by `jswrap_` to generate the corresponding C code).
119+
> TODO: it's still a bit buggy!
111120
112-
### Timing
121+
### Timing
113122

114123
#### `void Eadk.timing_usleep(uint32_t us)`
115124

@@ -123,17 +132,17 @@ Sleep for `ms` micro-seconds
123132

124133
Time since boot of the machine? Not clear. FIXME:
125134

126-
### Miscellanious
135+
### Miscellanious
127136

128-
#### `bool Eadk.usb_is_plugged()`
137+
#### `bool Eadk.usb_is_plugged()`
129138

130139
Indicates whether the USB is plugged.
131140

132141
> This function is missing from the hardware!
133142
> See [this issue on NumWorks/epsilon's repository](https://github.com/numworks/epsilon/issues/2326)
134-
> TODO: [I could try to implement it myself, by SVC calls](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/issues/5)
143+
> DONE: [I just implemented it myself, by SVC calls](https://github.com/Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator/issues/5)
135144
136-
#### ? `uint32_t Eadk.random()`
145+
#### `uint32_t Eadk.random()`
137146

138147
Returns an almost truly random number, generated from the hardware RNG (a uint32_t, unsigned 32 bits integer).
139148

src/javascript/espruino_embedded.c

Lines changed: 82 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9996,6 +9996,7 @@ JsVar *jspGetPrototypeOwner(JsVar *proto) {
99969996
}
99979997
return 0;
99989998
}
9999+
999910000
typedef uint16_t eadk_color_t;
1000010001
static const eadk_color_t eadk_color_black = 0x0;
1000110002
static const eadk_color_t eadk_color_white = 0xFFFF;
@@ -10215,18 +10216,19 @@ extern const char* eadk_external_data;
1021510216
extern size_t eadk_external_data_size;
1021610217
bool eadk_usb_is_plugged();
1021710218
uint32_t eadk_random();
10218-
int jswrap_color_black(void);
10219-
int jswrap_color_white(void);
10220-
int jswrap_color_red(void);
10221-
int jswrap_color_green(void);
10222-
int jswrap_color_blue(void);
10223-
int jswrap_SCREEN_WIDTH(void);
10224-
int jswrap_SCREEN_HEIGHT(void);
10219+
int16_t jswrap_color_black(void);
10220+
int16_t jswrap_color_white(void);
10221+
int16_t jswrap_color_red(void);
10222+
int16_t jswrap_color_green(void);
10223+
int16_t jswrap_color_blue(void);
10224+
int32_t jswrap_SCREEN_WIDTH(void);
10225+
int32_t jswrap_SCREEN_HEIGHT(void);
1022510226
int jswrap_backlight_brightness(void);
1022610227
void jswrap_backlight_set_brightness(int brightness);
1022710228
_Bool jswrap_battery_is_charging();
1022810229
uint8_t jswrap_battery_level();
1022910230
float jswrap_battery_voltage();
10231+
void jswrap_display_draw_string(JsVar *args);
1023010232
void jswrap_timing_usleep(uint32_t us);
1023110233
void jswrap_timing_msleep(uint32_t ms);
1023210234
uint64_t jswrap_timing_millis();
@@ -10571,11 +10573,12 @@ static const JswSymPtr jswSymbols_Eadk[] = {
1057110573
{ 146, JSWAT_INT32 | JSWAT_EXECUTE_IMMEDIATELY, (void*)jswrap_color_green},
1057210574
{ 158, JSWAT_INT32 | JSWAT_EXECUTE_IMMEDIATELY, (void*)jswrap_color_red},
1057310575
{ 168, JSWAT_INT32 | JSWAT_EXECUTE_IMMEDIATELY, (void*)jswrap_color_white},
10574-
{ 180, JSWAT_INT32, (void*)jswrap_random},
10575-
{ 187, JSWAT_INT32, (void*)jswrap_timing_millis},
10576-
{ 201, JSWAT_VOID | (JSWAT_INT32 << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*1)), (void*)jswrap_timing_msleep},
10577-
{ 215, JSWAT_VOID | (JSWAT_INT32 << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*1)), (void*)jswrap_timing_usleep},
10578-
{ 229, JSWAT_BOOL, (void*)jswrap_usb_is_plugged}
10576+
{ 180, JSWAT_VOID | (JSWAT_ARGUMENT_ARRAY << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*1)), (void*)jswrap_display_draw_string},
10577+
{ 200, JSWAT_INT32, (void*)jswrap_random},
10578+
{ 207, JSWAT_INT32, (void*)jswrap_timing_millis},
10579+
{ 221, JSWAT_VOID | (JSWAT_INT32 << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*1)), (void*)jswrap_timing_msleep},
10580+
{ 235, JSWAT_VOID | (JSWAT_INT32 << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*1)), (void*)jswrap_timing_usleep},
10581+
{ 249, JSWAT_BOOL, (void*)jswrap_usb_is_plugged}
1057910582
};
1058010583
static const unsigned char jswSymbolIndex_Eadk = 0;
1058110584
static const JswSymPtr jswSymbols_global[] = {
@@ -10897,7 +10900,7 @@ static const JswSymPtr jswSymbols_heatshrink[] = {
1089710900
{ 9, JSWAT_JSVAR | (JSWAT_JSVAR << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*1)), (void*)jswrap_heatshrink_decompress}
1089810901
};
1089910902
static const unsigned char jswSymbolIndex_heatshrink = 26;
10900-
static const char jswSymbols_Eadk_str[] = "SCREEN_HEIGHT\0SCREEN_WIDTH\0backlight_brightness\0backlight_set_brightness\0battery_is_charging\0battery_level\0battery_voltage\0color_black\0color_blue\0color_green\0color_red\0color_white\0random\0timing_millis\0timing_msleep\0timing_usleep\0usb_is_plugged\0";
10903+
static const char jswSymbols_Eadk_str[] = "SCREEN_HEIGHT\0SCREEN_WIDTH\0backlight_brightness\0backlight_set_brightness\0battery_is_charging\0battery_level\0battery_voltage\0color_black\0color_blue\0color_green\0color_red\0color_white\0display_draw_string\0random\0timing_millis\0timing_msleep\0timing_usleep\0usb_is_plugged\0";
1090110904
static const char jswSymbols_global_str[] = "Array\0ArrayBuffer\0ArrayBufferView\0Boolean\0DataView\0Date\0Eadk\0Error\0Float32Array\0Float64Array\0Function\0HIGH\0Infinity\0Int16Array\0Int32Array\0Int8Array\0InternalError\0JSON\0LOW\0Math\0Modules\0NaN\0Number\0Object\0ReferenceError\0RegExp\0String\0SyntaxError\0TypeError\0Uint16Array\0Uint24Array\0Uint32Array\0Uint8Array\0Uint8ClampedArray\0arguments\0atob\0btoa\0console\0decodeURIComponent\0encodeURIComponent\0eval\0global\0globalThis\0isFinite\0isNaN\0parseFloat\0parseInt\0print\0require\0trace\0";
1090210905
static const char jswSymbols_Array_proto_str[] = "concat\0every\0fill\0filter\0find\0findIndex\0forEach\0includes\0indexOf\0join\0length\0map\0pop\0push\0reduce\0reverse\0shift\0slice\0some\0sort\0splice\0toString\0unshift\0";
1090310906
static const char jswSymbols_Array_str[] = "isArray\0";
@@ -10925,7 +10928,7 @@ static const char jswSymbols_Modules_str[] = "addCached\0getCached\0removeAllCac
1092510928
static const char jswSymbols_Math_str[] = "E\0LN10\0LN2\0LOG10E\0LOG2E\0PI\0SQRT1_2\0SQRT2\0abs\0acos\0asin\0atan\0atan2\0ceil\0clip\0cos\0exp\0floor\0log\0max\0min\0pow\0randInt\0random\0round\0sign\0sin\0sqrt\0tan\0wrap\0";
1092610929
static const char jswSymbols_heatshrink_str[] = "compress\0decompress\0";
1092710930
const JswSymList jswSymbolTables[] = {
10928-
{jswSymbols_Eadk, jswSymbols_Eadk_str, 17},
10931+
{jswSymbols_Eadk, jswSymbols_Eadk_str, 18},
1092910932
{jswSymbols_global, jswSymbols_global_str, 50},
1093010933
{jswSymbols_Array_proto, jswSymbols_Array_proto_str, 23},
1093110934
{jswSymbols_Array, jswSymbols_Array_str, 1},
@@ -11202,6 +11205,13 @@ JsVar *jswCallFunctionHack(void *function, JsnArgumentType argumentSpecifier, Js
1120211205
result = jsvNewFromFloat(((JsVarFloat(*)())function)());
1120311206
return result;
1120411207
}
11208+
case JSWAT_VOID | (JSWAT_ARGUMENT_ARRAY << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*1)): {
11209+
JsVar *result = 0;
11210+
JsVar *argArray = (paramCount>0)?jsvNewArray(&paramData[0],paramCount-0):jsvNewEmptyArray();
11211+
((void(*)(JsVar*))function)(argArray);
11212+
jsvUnLock(argArray);
11213+
return result;
11214+
}
1120511215
case JSWAT_JSVAR | (JSWAT_ARGUMENT_ARRAY << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*1)): {
1120611216
JsVar *result = 0;
1120711217
JsVar *argArray = (paramCount>0)?jsvNewArray(&paramData[0],paramCount-0):jsvNewEmptyArray();
@@ -11365,13 +11375,6 @@ JsVar *jswCallFunctionHack(void *function, JsnArgumentType argumentSpecifier, Js
1136511375
((void(*)(JsVar*))function)(((paramCount>0)?paramData[0]:0));
1136611376
return result;
1136711377
}
11368-
case JSWAT_VOID | (JSWAT_ARGUMENT_ARRAY << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*1)): {
11369-
JsVar *result = 0;
11370-
JsVar *argArray = (paramCount>0)?jsvNewArray(&paramData[0],paramCount-0):jsvNewEmptyArray();
11371-
((void(*)(JsVar*))function)(argArray);
11372-
jsvUnLock(argArray);
11373-
return result;
11374-
}
1137511378
case JSWAT_JSVAR | (JSWAT_JSVAR << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*1)) | (JSWAT_JSVAR << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*2)) | (JSWAT_JSVAR << ((((JSWAT_MASK+1)== 1)? 0: ((JSWAT_MASK+1)== 2)? 1: ((JSWAT_MASK+1)== 4)? 2: ((JSWAT_MASK+1)== 8)? 3: ((JSWAT_MASK+1)== 16)? 4: ((JSWAT_MASK+1)== 32)? 5: ((JSWAT_MASK+1)== 64)? 6: ((JSWAT_MASK+1)== 128)? 7: ((JSWAT_MASK+1)== 256)? 8: ((JSWAT_MASK+1)== 512)? 9: ((JSWAT_MASK+1)== 1024)?10: ((JSWAT_MASK+1)== 2048)?11: ((JSWAT_MASK+1)== 4096)?12: ((JSWAT_MASK+1)== 8192)?13: ((JSWAT_MASK+1)==16384)?14: ((JSWAT_MASK+1)==32768)?15:10000 )*3)): {
1137611379
JsVar *result = 0;
1137711380
result = (((JsVar*(*)(JsVar*,JsVar*,JsVar*))function)(((paramCount>0)?paramData[0]:0),((paramCount>1)?paramData[1]:0),((paramCount>2)?paramData[2]:0)));
@@ -12434,42 +12437,43 @@ const JshPinInfo pinInfo[33] = {
1243412437
{ JSH_PORTD, JSH_PIN0+31, JSH_ANALOG_NONE, { } },
1243512438
{ JSH_PORTD, JSH_PIN0+32, JSH_ANALOG_NONE, { } },
1243612439
};
12437-
int jswrap_color_black(void);
12438-
int jswrap_color_white(void);
12439-
int jswrap_color_red(void);
12440-
int jswrap_color_green(void);
12441-
int jswrap_color_blue(void);
12442-
int jswrap_SCREEN_WIDTH(void);
12443-
int jswrap_SCREEN_HEIGHT(void);
12440+
int16_t jswrap_color_black(void);
12441+
int16_t jswrap_color_white(void);
12442+
int16_t jswrap_color_red(void);
12443+
int16_t jswrap_color_green(void);
12444+
int16_t jswrap_color_blue(void);
12445+
int32_t jswrap_SCREEN_WIDTH(void);
12446+
int32_t jswrap_SCREEN_HEIGHT(void);
1244412447
int jswrap_backlight_brightness(void);
1244512448
void jswrap_backlight_set_brightness(int brightness);
1244612449
_Bool jswrap_battery_is_charging();
1244712450
uint8_t jswrap_battery_level();
1244812451
float jswrap_battery_voltage();
12452+
void jswrap_display_draw_string(JsVar *args);
1244912453
void jswrap_timing_usleep(uint32_t us);
1245012454
void jswrap_timing_msleep(uint32_t ms);
1245112455
uint64_t jswrap_timing_millis();
1245212456
_Bool jswrap_usb_is_plugged();
1245312457
uint32_t jswrap_random();
12454-
int jswrap_color_black(void) {
12458+
int16_t jswrap_color_black(void) {
1245512459
return 0x0;
1245612460
}
12457-
int jswrap_color_white(void) {
12461+
int16_t jswrap_color_white(void) {
1245812462
return 0xFFFF;
1245912463
}
12460-
int jswrap_color_red(void) {
12464+
int16_t jswrap_color_red(void) {
1246112465
return 0xF800;
1246212466
}
12463-
int jswrap_color_green(void) {
12467+
int16_t jswrap_color_green(void) {
1246412468
return 0x07E0;
1246512469
}
12466-
int jswrap_color_blue(void) {
12470+
int16_t jswrap_color_blue(void) {
1246712471
return 0x001F;
1246812472
}
12469-
int jswrap_SCREEN_WIDTH(void) {
12473+
int32_t jswrap_SCREEN_WIDTH(void) {
1247012474
return 320;
1247112475
}
12472-
int jswrap_SCREEN_HEIGHT(void) {
12476+
int32_t jswrap_SCREEN_HEIGHT(void) {
1247312477
return 240;
1247412478
}
1247512479
int jswrap_backlight_brightness(void) {
@@ -12480,13 +12484,52 @@ void jswrap_backlight_set_brightness(int brightness) {
1248012484
eadk_backlight_set_brightness(brightness);
1248112485
}
1248212486
_Bool jswrap_battery_is_charging(void) {
12483-
return 0;
12487+
_Bool returnValue; __asm__ volatile("svc %[immediate] ; mov %[returnValue], r0" : [returnValue] "=r"(returnValue) : [immediate] "I"(3) : "r0", "r1", "r2", "r3"); return returnValue;
1248412488
}
1248512489
uint8_t jswrap_battery_level(void) {
12486-
return 0;
12490+
uint8_t returnValue; __asm__ volatile("svc %[immediate] ; mov %[returnValue], r0" : [returnValue] "=r"(returnValue) : [immediate] "I"(4) : "r0", "r1", "r2", "r3"); return returnValue;
1248712491
}
1248812492
float jswrap_battery_voltage(void) {
12489-
return 0.0f;
12493+
float returnValue; __asm__ volatile("svc %[immediate] ; mov %[returnValue], r0" : [returnValue] "=r"(returnValue) : [immediate] "I"(5) : "r0", "r1", "r2", "r3"); return returnValue;
12494+
}
12495+
void jswrap_display_draw_string(JsVar *args) {
12496+
int argc = jsvGetArrayLength(args);
12497+
if (argc < 6) {
12498+
jsError("Arg error: too few args (%i)", argc);
12499+
return;
12500+
}
12501+
if (!jsvIsString(jsvGetArrayItem(args, 0))) {
12502+
jsError("Arg error: bad arg type [0]");
12503+
return;
12504+
}
12505+
const char* text = jsvAsString(jsvGetArrayItem(args, 0));
12506+
if (!jsvIsInt(jsvGetArrayItem(args, 1))) {
12507+
jsError("Arg error: bad arg type [1]");
12508+
return;
12509+
}
12510+
uint16_t x = (uint16_t)jsvGetInteger(jsvGetArrayItem(args, 1));
12511+
if (!jsvIsInt(jsvGetArrayItem(args, 2))) {
12512+
jsError("Arg error: bad arg type [2]");
12513+
return;
12514+
}
12515+
uint16_t y = (uint16_t)jsvGetInteger(jsvGetArrayItem(args, 2));
12516+
if (!jsvIsInt(jsvGetArrayItem(args, 3))) {
12517+
jsError("Arg error: bad arg type [3]");
12518+
return;
12519+
}
12520+
_Bool large_font = jsvGetBool(jsvGetArrayItem(args, 3));
12521+
if (!jsvIsInt(jsvGetArrayItem(args, 4))) {
12522+
jsError("Arg error: bad arg type [4]");
12523+
return;
12524+
}
12525+
uint16_t text_color = (uint16_t)jsvGetInteger(jsvGetArrayItem(args, 4));
12526+
if (!jsvIsInt(jsvGetArrayItem(args, 5))) {
12527+
jsError("Arg error: bad arg type [5]");
12528+
return;
12529+
}
12530+
uint16_t background_color = (uint16_t)jsvGetInteger(jsvGetArrayItem(args, 5));
12531+
eadk_display_draw_string(text, (eadk_point_t){x, y}, large_font, (eadk_color_t)text_color, (eadk_color_t)background_color);
12532+
return;
1249012533
}
1249112534
void jswrap_timing_usleep(uint32_t us) {
1249212535
return eadk_timing_usleep(us);
@@ -12498,7 +12541,7 @@ uint64_t jswrap_timing_millis() {
1249812541
return eadk_timing_millis();
1249912542
}
1250012543
_Bool jswrap_usb_is_plugged() {
12501-
return 0;
12544+
_Bool returnValue; __asm__ volatile("svc %[immediate] ; mov %[returnValue], r0" : [returnValue] "=r"(returnValue) : [immediate] "I"(52) : "r0", "r1", "r2", "r3"); return returnValue;
1250212545
}
1250312546
uint32_t jswrap_random() {
1250412547
return eadk_random();

0 commit comments

Comments
 (0)