Skip to content

Commit

Permalink
untested simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Aug 1, 2024
1 parent b27f0b0 commit 8c1e949
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 27 deletions.
9 changes: 2 additions & 7 deletions common/droidboot_platform_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ droidboot_error droidboot_platform_init()
return droidboot_internal_platform_init();
}

ssize_t dridboot_sd_read_block(void *buf, uint32_t block, uint count)
ssize_t droidboot_sd_read_block(void *buf, uint32_t block, uint count)
{
return dridboot_internal_sd_read_block(buf, block, count);
}

ssize_t dridboot_sd_write_block(const void *buf, uint32_t block, uint count)
ssize_t droidboot_sd_write_block(const void *buf, uint32_t block, uint count)
{
return dridboot_internal_sd_write_block(buf, block, count);
}
Expand All @@ -72,11 +72,6 @@ bool droidboot_have_fallback()
return droidboot_internal_have_fallback();
}

int droidboot_get_disp_buffer_height()
{
return droidboot_internal_get_disp_buffer_height();
}

bool droidboot_use_double_buffering()
{
return droidboot_internal_use_double_buffering();
Expand Down
5 changes: 2 additions & 3 deletions common/droidboot_platform_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ int droidboot_platform_settings_dev_open(struct ext4_blockdev *bdev);
int droidboot_platform_settings_dev_close(struct ext4_blockdev *bdev);

droidboot_error droidboot_platform_init(void);
ssize_t dridboot_sd_read_block(void *buf, uint32_t block, uint count);
ssize_t dridboot_sd_write_block(const void *buf, uint32_t block, uint count);
ssize_t droidboot_sd_read_block(void *buf, uint32_t block, uint count);
ssize_t droidboot_sd_write_block(const void *buf, uint32_t block, uint count);
uint32_t droidboot_sd_blklen(void);
uint64_t droidboot_sd_blkcnt(void);
bool droidboot_sd_exists(void);
bool droidboot_have_fallback(void);

int droidboot_get_disp_buffer_height(void);
bool droidboot_use_double_buffering(void);

void droidboot_lvgl_threads_init(void);
Expand Down
132 changes: 117 additions & 15 deletions simulator/simulator.c
Original file line number Diff line number Diff line change
@@ -1,50 +1,124 @@
#include <stdio.h>
#include "simulator.h"
#include "droidboot_main.h"
#include <android/log.h>
#include <unistd.h>
#include <pthread.h>
#include <android/bitmap.h>
#include <jni.h>

void droidboot_internal_fb_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
// TODO
}
static pthread_t t, t2;
static bool s_simulator_running, s_simulator_vol_down_pressed, s_simulator_vol_up_pressed, s_simulator_pwr_pressed;
static uint32_t last_pressed_key;
static JNIEnv* s_simulator_jnienv;
static jobject s_simulator_bitmap;
static jint s_simulator_h, s_simulator_w;

int droidboot_internal_get_display_height()
{
return 1920; // TODO
return s_simulator_h;
}

int droidboot_internal_get_display_width()
{
return 1080; // TODO
return s_simulator_w;
}

JNIEXPORT void simulator_start(JNIEnv* env, jobject bitmap, jint w, jint h) {
s_simulator_jnienv = env;
s_simulator_bitmap = bitmap;
s_simulator_h = h;
s_simulator_w = w;
droidboot_init();
droidboot_show_dualboot_menu();
}

void droidboot_internal_key_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
JNIEXPORT void simulator_key(jint key) {
s_simulator_vol_down_pressed = key == 1;
s_simulator_vol_up_pressed = key == 2;
s_simulator_pwr_pressed = key == 3;
}

void droidboot_internal_fb_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
// TODO
if (s_simulator_bitmap != NULL) {
void *addr;
while (!AndroidBitmap_lockPixels(s_simulator_jnienv, s_simulator_bitmap, &addr)) {
droidboot_internal_platform_system_log("failed locking bitmap, trying again");
usleep(10000);
}
int w = (area->x2 - area->x1 + 1);
long int location = 0;
long int byte_location = 0;
unsigned char bit_location = 0;
int32_t y;
for (y = area->y1; y <= area->y2; y++) {
location = (area->x1 + 0) + (y + 0) * droidboot_internal_get_display_width();
memcpy(&addr[location], (uint32_t *) color_p, (area->x2 - area->y2 + 1) * 4);
color_p += w;
}

while (!AndroidBitmap_unlockPixels(s_simulator_jnienv, s_simulator_bitmap)) {
droidboot_internal_platform_system_log("failed unlocking bitmap, trying again");
usleep(10000);
}
}
// Inform the graphics library that we are ready with the flushing
lv_disp_flush_ready(disp_drv);
}

//Read keys state
void droidboot_internal_key_read(lv_indev_drv_t* drv, lv_indev_data_t* data)
{
if (s_simulator_vol_up_pressed){
data->key = LV_KEY_PREV;
last_pressed_key = LV_KEY_PREV;
data->state = LV_INDEV_STATE_PRESSED;
} else if (s_simulator_vol_down_pressed){
data->key = LV_KEY_NEXT;
last_pressed_key = LV_KEY_NEXT;
data->state = LV_INDEV_STATE_PRESSED;
} else if (s_simulator_pwr_pressed){
data->key = LV_KEY_ENTER;
last_pressed_key = LV_KEY_ENTER;
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->key=last_pressed_key;
data->state = LV_INDEV_STATE_RELEASED;
}
}

droidboot_error droidboot_internal_platform_init()
{
s_simulator_running = true;
return DROIDBOOT_EOK;
}

ssize_t dridboot_internal_sd_read_block(void *buf, uint32_t block, uint count)
{
if (!droidboot_internal_sd_exists())
return 0;
return 0; // TODO
}

ssize_t dridboot_internal_sd_write_block(const void *buf, uint32_t block, uint count)
{
if (!droidboot_internal_sd_exists())
return 0;
return 0; // TODO
}

uint32_t droidboot_internal_sd_blklen()
{
if (!droidboot_internal_sd_exists())
return 0;
return 0; // TODO
}

uint64_t droidboot_internal_sd_blkcnt()
{
if (!droidboot_internal_sd_exists())
return 0;
return 0; // TODO
}

Expand All @@ -58,21 +132,46 @@ bool droidboot_internal_have_fallback()
return true;
}

int droidboot_internal_get_disp_buffer_height()
bool droidboot_internal_use_double_buffering()
{
return true;
}

//lvgl thread
static void* droidboot_lv_tick_inc_thread(void * arg) {
/*Handle LitlevGL tick*/
while (s_simulator_running) {
sleep(1);
lv_tick_inc(1);
//lv_timer_handler();
}
return 0;
}

bool droidboot_internal_use_double_buffering()
{
return true;
//lvgl thread
static void* droidboot_lv_timer_handler_thread(void * arg) {
/*Handle LitlevGL tick*/
while (s_simulator_running) {
sleep(1);
lv_timer_handler();
}
return 0;
}

void droidboot_internal_lvgl_threads_init()
{
// TODO
pthread_create(&t, NULL, droidboot_lv_tick_inc_thread, NULL);
pthread_create(&t2, NULL, droidboot_lv_timer_handler_thread, NULL);
}

JNIEXPORT void simulator_stop()
{
s_simulator_running = false;
pthread_join(t, NULL);
pthread_join(t2, NULL);
s_simulator_bitmap = NULL;
s_simulator_jnienv = NULL;
}

void droidboot_internal_platform_on_screen_log(const char *buf)
{
Expand All @@ -86,7 +185,7 @@ void droidboot_internal_platform_system_log(const char *buf)

void droidboot_internal_delay(unsigned int time)
{
sleep(time);
usleep(time*1000);
}

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)
Expand Down Expand Up @@ -118,11 +217,14 @@ void *droidboot_internal_get_dtbo_load_addr()
{
return NULL;
}

bool droidboot_internal_append_ramdisk_to_kernel()
{
return true;
}

// Nothing to do here, we have threads
void droidboot_internal_platform_tasks()
{
}
usleep(200000);
}
3 changes: 1 addition & 2 deletions simulator/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ uint32_t droidboot_internal_sd_blklen();
uint64_t droidboot_internal_sd_blkcnt();
bool droidboot_internal_sd_exists();
bool droidboot_internal_have_fallback();
int droidboot_internal_get_disp_buffer_height();
bool droidboot_internal_use_double_buffering();
void droidboot_internal_lvgl_threads_init();
void droidboot_internal_platform_on_screen_log(const char *buf);
Expand All @@ -33,6 +32,6 @@ void *droidboot_internal_get_dtb_load_addr();
void *droidboot_internal_get_dtbo_load_addr();
bool droidboot_internal_append_ramdisk_to_kernel();
void droidboot_internal_platform_tasks();

void simulator_teardown();

#endif //ABM_SIMULATOR_H

0 comments on commit 8c1e949

Please sign in to comment.