-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
69 lines (62 loc) · 1.82 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdlib.h>
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "esp8266.h"
#include "quickjs/quickjs-libc.h"
const int gpio = 2;
/* This task uses the high level GPIO API (esp_gpio.h) to blink an LED.
*
*/
void blinkenTask(void *pvParameters) {
gpio_enable(gpio, GPIO_OUTPUT);
while(1) {
gpio_write(gpio, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
gpio_write(gpio, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
const uint32_t hello_size = 98;
const uint8_t hello[98] = {
0x01, 0x04, 0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f,
0x6c, 0x65, 0x06, 0x6c, 0x6f, 0x67, 0x16, 0x48,
0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72,
0x6c, 0x64, 0x38, 0x2e, 0x2e, 0x2f, 0x71, 0x75,
0x69, 0x63, 0x6b, 0x6a, 0x73, 0x2f, 0x65, 0x78,
0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x68,
0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x6a, 0x73, 0x0d,
0x00, 0x02, 0x00, 0x9e, 0x01, 0x00, 0x01, 0x00,
0x03, 0x00, 0x00, 0x14, 0x01, 0xa0, 0x01, 0x00,
0x00, 0x00, 0x36, 0xc8, 0x00, 0x00, 0x00, 0x40,
0xc9, 0x00, 0x00, 0x00, 0x04, 0xca, 0x00, 0x00,
0x00, 0x24, 0x01, 0x00, 0xd0, 0x28, 0x96, 0x03,
0x01, 0x00,
};
int argc = 0;
char** argv[0] = {};
void runJS(void) {
JSRuntime *rt;
JSContext *ctx;
rt = JS_NewRuntime();
ctx = JS_NewContextRaw(rt);
JS_AddIntrinsicBaseObjects(ctx);
JS_AddIntrinsicDate(ctx);
JS_AddIntrinsicStringNormalize(ctx);
JS_AddIntrinsicJSON(ctx);
JS_AddIntrinsicMapSet(ctx);
JS_AddIntrinsicTypedArrays(ctx);
JS_AddIntrinsicPromise(ctx);
/* js_std_add_helpers(ctx, argc, argv); */
js_std_eval_binary(ctx, hello, hello_size, 0);
js_std_loop(ctx);
JS_FreeContext(ctx);
JS_FreeRuntime(rt);
return;
}
void user_init(void) {
uart_set_baud(0, 115200);
runJS();
xTaskCreate(blinkenTask, "blinkenTask", 256, NULL, 2, NULL);
}