Skip to content

Commit 8c1e949

Browse files
committed
untested simulator
1 parent b27f0b0 commit 8c1e949

4 files changed

Lines changed: 122 additions & 27 deletions

File tree

common/droidboot_platform_common.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ droidboot_error droidboot_platform_init()
4242
return droidboot_internal_platform_init();
4343
}
4444

45-
ssize_t dridboot_sd_read_block(void *buf, uint32_t block, uint count)
45+
ssize_t droidboot_sd_read_block(void *buf, uint32_t block, uint count)
4646
{
4747
return dridboot_internal_sd_read_block(buf, block, count);
4848
}
4949

50-
ssize_t dridboot_sd_write_block(const void *buf, uint32_t block, uint count)
50+
ssize_t droidboot_sd_write_block(const void *buf, uint32_t block, uint count)
5151
{
5252
return dridboot_internal_sd_write_block(buf, block, count);
5353
}
@@ -72,11 +72,6 @@ bool droidboot_have_fallback()
7272
return droidboot_internal_have_fallback();
7373
}
7474

75-
int droidboot_get_disp_buffer_height()
76-
{
77-
return droidboot_internal_get_disp_buffer_height();
78-
}
79-
8075
bool droidboot_use_double_buffering()
8176
{
8277
return droidboot_internal_use_double_buffering();

common/droidboot_platform_common.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,13 @@ int droidboot_platform_settings_dev_open(struct ext4_blockdev *bdev);
5353
int droidboot_platform_settings_dev_close(struct ext4_blockdev *bdev);
5454

5555
droidboot_error droidboot_platform_init(void);
56-
ssize_t dridboot_sd_read_block(void *buf, uint32_t block, uint count);
57-
ssize_t dridboot_sd_write_block(const void *buf, uint32_t block, uint count);
56+
ssize_t droidboot_sd_read_block(void *buf, uint32_t block, uint count);
57+
ssize_t droidboot_sd_write_block(const void *buf, uint32_t block, uint count);
5858
uint32_t droidboot_sd_blklen(void);
5959
uint64_t droidboot_sd_blkcnt(void);
6060
bool droidboot_sd_exists(void);
6161
bool droidboot_have_fallback(void);
6262

63-
int droidboot_get_disp_buffer_height(void);
6463
bool droidboot_use_double_buffering(void);
6564

6665
void droidboot_lvgl_threads_init(void);

simulator/simulator.c

Lines changed: 117 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,124 @@
11
#include <stdio.h>
22
#include "simulator.h"
3+
#include "droidboot_main.h"
34
#include <android/log.h>
45
#include <unistd.h>
6+
#include <pthread.h>
7+
#include <android/bitmap.h>
8+
#include <jni.h>
59

6-
void droidboot_internal_fb_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
7-
{
8-
// TODO
9-
}
10+
static pthread_t t, t2;
11+
static bool s_simulator_running, s_simulator_vol_down_pressed, s_simulator_vol_up_pressed, s_simulator_pwr_pressed;
12+
static uint32_t last_pressed_key;
13+
static JNIEnv* s_simulator_jnienv;
14+
static jobject s_simulator_bitmap;
15+
static jint s_simulator_h, s_simulator_w;
1016

1117
int droidboot_internal_get_display_height()
1218
{
13-
return 1920; // TODO
19+
return s_simulator_h;
1420
}
1521

1622
int droidboot_internal_get_display_width()
1723
{
18-
return 1080; // TODO
24+
return s_simulator_w;
25+
}
26+
27+
JNIEXPORT void simulator_start(JNIEnv* env, jobject bitmap, jint w, jint h) {
28+
s_simulator_jnienv = env;
29+
s_simulator_bitmap = bitmap;
30+
s_simulator_h = h;
31+
s_simulator_w = w;
32+
droidboot_init();
33+
droidboot_show_dualboot_menu();
1934
}
2035

21-
void droidboot_internal_key_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
36+
JNIEXPORT void simulator_key(jint key) {
37+
s_simulator_vol_down_pressed = key == 1;
38+
s_simulator_vol_up_pressed = key == 2;
39+
s_simulator_pwr_pressed = key == 3;
40+
}
41+
42+
void droidboot_internal_fb_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
2243
{
23-
// TODO
44+
if (s_simulator_bitmap != NULL) {
45+
void *addr;
46+
while (!AndroidBitmap_lockPixels(s_simulator_jnienv, s_simulator_bitmap, &addr)) {
47+
droidboot_internal_platform_system_log("failed locking bitmap, trying again");
48+
usleep(10000);
49+
}
50+
int w = (area->x2 - area->x1 + 1);
51+
long int location = 0;
52+
long int byte_location = 0;
53+
unsigned char bit_location = 0;
54+
int32_t y;
55+
for (y = area->y1; y <= area->y2; y++) {
56+
location = (area->x1 + 0) + (y + 0) * droidboot_internal_get_display_width();
57+
memcpy(&addr[location], (uint32_t *) color_p, (area->x2 - area->y2 + 1) * 4);
58+
color_p += w;
59+
}
60+
61+
while (!AndroidBitmap_unlockPixels(s_simulator_jnienv, s_simulator_bitmap)) {
62+
droidboot_internal_platform_system_log("failed unlocking bitmap, trying again");
63+
usleep(10000);
64+
}
65+
}
66+
// Inform the graphics library that we are ready with the flushing
67+
lv_disp_flush_ready(disp_drv);
68+
}
69+
70+
//Read keys state
71+
void droidboot_internal_key_read(lv_indev_drv_t* drv, lv_indev_data_t* data)
72+
{
73+
if (s_simulator_vol_up_pressed){
74+
data->key = LV_KEY_PREV;
75+
last_pressed_key = LV_KEY_PREV;
76+
data->state = LV_INDEV_STATE_PRESSED;
77+
} else if (s_simulator_vol_down_pressed){
78+
data->key = LV_KEY_NEXT;
79+
last_pressed_key = LV_KEY_NEXT;
80+
data->state = LV_INDEV_STATE_PRESSED;
81+
} else if (s_simulator_pwr_pressed){
82+
data->key = LV_KEY_ENTER;
83+
last_pressed_key = LV_KEY_ENTER;
84+
data->state = LV_INDEV_STATE_PRESSED;
85+
} else {
86+
data->key=last_pressed_key;
87+
data->state = LV_INDEV_STATE_RELEASED;
88+
}
2489
}
2590

2691
droidboot_error droidboot_internal_platform_init()
2792
{
93+
s_simulator_running = true;
2894
return DROIDBOOT_EOK;
2995
}
3096

3197
ssize_t dridboot_internal_sd_read_block(void *buf, uint32_t block, uint count)
3298
{
99+
if (!droidboot_internal_sd_exists())
100+
return 0;
33101
return 0; // TODO
34102
}
35103

36104
ssize_t dridboot_internal_sd_write_block(const void *buf, uint32_t block, uint count)
37105
{
106+
if (!droidboot_internal_sd_exists())
107+
return 0;
38108
return 0; // TODO
39109
}
40110

41111
uint32_t droidboot_internal_sd_blklen()
42112
{
113+
if (!droidboot_internal_sd_exists())
114+
return 0;
43115
return 0; // TODO
44116
}
45117

46118
uint64_t droidboot_internal_sd_blkcnt()
47119
{
120+
if (!droidboot_internal_sd_exists())
121+
return 0;
48122
return 0; // TODO
49123
}
50124

@@ -58,21 +132,46 @@ bool droidboot_internal_have_fallback()
58132
return true;
59133
}
60134

61-
int droidboot_internal_get_disp_buffer_height()
135+
bool droidboot_internal_use_double_buffering()
62136
{
137+
return true;
138+
}
139+
140+
//lvgl thread
141+
static void* droidboot_lv_tick_inc_thread(void * arg) {
142+
/*Handle LitlevGL tick*/
143+
while (s_simulator_running) {
144+
sleep(1);
145+
lv_tick_inc(1);
146+
//lv_timer_handler();
147+
}
63148
return 0;
64149
}
65150

66-
bool droidboot_internal_use_double_buffering()
67-
{
68-
return true;
151+
//lvgl thread
152+
static void* droidboot_lv_timer_handler_thread(void * arg) {
153+
/*Handle LitlevGL tick*/
154+
while (s_simulator_running) {
155+
sleep(1);
156+
lv_timer_handler();
157+
}
158+
return 0;
69159
}
70160

71161
void droidboot_internal_lvgl_threads_init()
72162
{
73-
// TODO
163+
pthread_create(&t, NULL, droidboot_lv_tick_inc_thread, NULL);
164+
pthread_create(&t2, NULL, droidboot_lv_timer_handler_thread, NULL);
74165
}
75166

167+
JNIEXPORT void simulator_stop()
168+
{
169+
s_simulator_running = false;
170+
pthread_join(t, NULL);
171+
pthread_join(t2, NULL);
172+
s_simulator_bitmap = NULL;
173+
s_simulator_jnienv = NULL;
174+
}
76175

77176
void droidboot_internal_platform_on_screen_log(const char *buf)
78177
{
@@ -86,7 +185,7 @@ void droidboot_internal_platform_system_log(const char *buf)
86185

87186
void droidboot_internal_delay(unsigned int time)
88187
{
89-
sleep(time);
188+
usleep(time*1000);
90189
}
91190

92191
void droidboot_internal_boot_linux_from_ram(void *kernel_raw, off_t kernel_raw_size, void *ramdisk_raw, off_t ramdisk_size, void *dtb_raw, off_t dtb_raw_size, void *dtbo_raw, off_t dtbo_raw_size, char *options)
@@ -118,11 +217,14 @@ void *droidboot_internal_get_dtbo_load_addr()
118217
{
119218
return NULL;
120219
}
220+
121221
bool droidboot_internal_append_ramdisk_to_kernel()
122222
{
123223
return true;
124224
}
125225

226+
// Nothing to do here, we have threads
126227
void droidboot_internal_platform_tasks()
127228
{
128-
}
229+
usleep(200000);
230+
}

simulator/simulator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ uint32_t droidboot_internal_sd_blklen();
1919
uint64_t droidboot_internal_sd_blkcnt();
2020
bool droidboot_internal_sd_exists();
2121
bool droidboot_internal_have_fallback();
22-
int droidboot_internal_get_disp_buffer_height();
2322
bool droidboot_internal_use_double_buffering();
2423
void droidboot_internal_lvgl_threads_init();
2524
void droidboot_internal_platform_on_screen_log(const char *buf);
@@ -33,6 +32,6 @@ void *droidboot_internal_get_dtb_load_addr();
3332
void *droidboot_internal_get_dtbo_load_addr();
3433
bool droidboot_internal_append_ramdisk_to_kernel();
3534
void droidboot_internal_platform_tasks();
36-
35+
void simulator_teardown();
3736

3837
#endif //ABM_SIMULATOR_H

0 commit comments

Comments
 (0)