|
7 | 7 | /******************************************************************************* |
8 | 8 | * Includes |
9 | 9 | *******************************************************************************/ |
| 10 | + |
10 | 11 | #include <freertos/FreeRTOS.h> |
11 | 12 | #include <freertos/timers.h> |
12 | 13 | #include <freertos/task.h> |
13 | 14 | #include <freertos/queue.h> |
14 | 15 | #include <string.h> |
15 | 16 |
|
| 17 | +#include "esp_system.h" |
| 18 | +#include "nvs_flash.h" |
| 19 | +#include "esp_partition.h" |
| 20 | +#include "spi_flash_mmap.h" |
| 21 | + |
16 | 22 | static const char *TAG = "OSD"; |
17 | 23 |
|
18 | 24 | #define LOBYTE(u16) ((uint8_t)(((uint16_t)(u16)) & 0xff)) |
@@ -40,6 +46,11 @@ static const char *TAG = "OSD"; |
40 | 46 | #define APP_DEFAULT_HEIGHT 240 |
41 | 47 | #define APP_DEFAULT_SCALE (BSP_LCD_V_RES/APP_DEFAULT_HEIGHT) |
42 | 48 |
|
| 49 | +// LVGL image declare |
| 50 | +LV_IMG_DECLARE(img_supermario) |
| 51 | +LV_IMG_DECLARE(img_donkeykong) |
| 52 | +LV_IMG_DECLARE(img_qbert) |
| 53 | + |
43 | 54 | typedef struct { |
44 | 55 | hid_host_device_handle_t hid_device_handle; |
45 | 56 | hid_host_driver_event_t event; |
@@ -71,11 +82,13 @@ static void app_osd_video_clear(uint8 color); |
71 | 82 | static bitmap_t *app_osd_video_lock_write(void); |
72 | 83 | static void app_osd_video_free_write(int num_dirties, rect_t *dirty_rects); |
73 | 84 | static void app_osd_video_custom_blit(bitmap_t *primary, int num_dirties, rect_t *dirty_rects); |
74 | | - |
75 | 85 | /* Audio functions */ |
76 | 86 |
|
77 | 87 | /* USB functions */ |
78 | 88 | static void app_hid_init(void); |
| 89 | + |
| 90 | +/* Game selection */ |
| 91 | +static void app_lvgl_game_selection(void); |
79 | 92 | /******************************************************************************* |
80 | 93 | * Local variables |
81 | 94 | *******************************************************************************/ |
@@ -105,10 +118,39 @@ static uint8_t * vid_buffer = NULL; |
105 | 118 | static QueueHandle_t hid_queue = NULL; |
106 | 119 | static gamepad_t app_gamepad; |
107 | 120 | static gamepad_t app_gamepad_tmp; |
| 121 | + |
| 122 | +/* GAME */ |
| 123 | +static const char * APP_GAME_SUPERMARIO = "nesrom1"; |
| 124 | +static const char * APP_GAME_DONKEYKONG = "nesrom2"; |
| 125 | +static const char * APP_GAME_QBERT = "nesrom3"; |
| 126 | +/* Selected partion with game */ |
| 127 | +static const char * app_selected_game = NULL; |
| 128 | +static lv_obj_t * game_selection = NULL; |
108 | 129 | /******************************************************************************* |
109 | 130 | * Public API functions |
110 | 131 | *******************************************************************************/ |
111 | 132 |
|
| 133 | +char *osd_getromdata() |
| 134 | +{ |
| 135 | + /* Wait for select the game */ |
| 136 | + while(app_selected_game == NULL) |
| 137 | + { |
| 138 | + vTaskDelay(pdMS_TO_TICKS(100)); |
| 139 | + }; |
| 140 | + |
| 141 | + char* romdata; |
| 142 | + const esp_partition_t* part; |
| 143 | + spi_flash_mmap_handle_t hrom; |
| 144 | + esp_err_t err; |
| 145 | + nvs_flash_init(); |
| 146 | + part=esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, app_selected_game); |
| 147 | + if (part==0) printf("Couldn't find rom part!\n"); |
| 148 | + err=esp_partition_mmap(part, 0, 1024*1024, SPI_FLASH_MMAP_DATA, (const void**)&romdata, &hrom); |
| 149 | + if (err!=ESP_OK) printf("Couldn't map rom part!\n"); |
| 150 | + printf("Initialized. ROM@%p\n", romdata); |
| 151 | + return (char*)romdata; |
| 152 | +} |
| 153 | + |
112 | 154 | void osd_getvideoinfo(vidinfo_t *info) |
113 | 155 | { |
114 | 156 | info->default_width = APP_DEFAULT_WIDTH; |
@@ -139,6 +181,9 @@ int osd_init(void) |
139 | 181 | lv_canvas_set_buffer(lvgl_video_canvas, vid_buffer, APP_DEFAULT_SCALE*APP_DEFAULT_WIDTH, APP_DEFAULT_SCALE*APP_DEFAULT_HEIGHT, LV_IMG_CF_TRUE_COLOR); |
140 | 182 | lv_obj_center(lvgl_video_canvas); |
141 | 183 | bsp_display_unlock(); |
| 184 | + |
| 185 | + /* Show selection of the game */ |
| 186 | + app_lvgl_game_selection(); |
142 | 187 |
|
143 | 188 | return 0; |
144 | 189 | } |
@@ -282,6 +327,103 @@ int osd_makesnapname(char *filename, int len) |
282 | 327 | * Private API functions |
283 | 328 | *******************************************************************************/ |
284 | 329 |
|
| 330 | +static void app_lvgl_btn_supermario(lv_event_t *e) |
| 331 | +{ |
| 332 | + lv_obj_del(game_selection); |
| 333 | + app_selected_game = APP_GAME_SUPERMARIO; |
| 334 | +} |
| 335 | + |
| 336 | +static void app_lvgl_btn_donkeykong(lv_event_t *e) |
| 337 | +{ |
| 338 | + lv_obj_del(game_selection); |
| 339 | + app_selected_game = APP_GAME_DONKEYKONG; |
| 340 | +} |
| 341 | + |
| 342 | +static void app_lvgl_btn_qbert(lv_event_t *e) |
| 343 | +{ |
| 344 | + lv_obj_del(game_selection); |
| 345 | + app_selected_game = APP_GAME_QBERT; |
| 346 | +} |
| 347 | + |
| 348 | +static void app_lvgl_btn_reset(lv_event_t *e) |
| 349 | +{ |
| 350 | + esp_restart(); |
| 351 | +} |
| 352 | + |
| 353 | +static void app_lvgl_game_selection(void) |
| 354 | +{ |
| 355 | + bsp_display_lock(0); |
| 356 | + lv_obj_set_style_bg_color(lv_scr_act(), lv_color_black(), 0); |
| 357 | + |
| 358 | + lv_obj_t * btn_rst = lv_btn_create(lv_scr_act()); |
| 359 | + lv_obj_t * lbl = lv_label_create(btn_rst); |
| 360 | + lv_label_set_text_static(lbl, LV_SYMBOL_PREV""); |
| 361 | + lv_obj_add_event_cb(btn_rst, app_lvgl_btn_reset, LV_EVENT_CLICKED, NULL); |
| 362 | + |
| 363 | + game_selection = lv_obj_create(lv_scr_act()); |
| 364 | + lv_obj_set_size(game_selection, BSP_LCD_H_RES, 2*(BSP_LCD_V_RES/3)); |
| 365 | + lv_obj_set_flex_flow(game_selection, LV_FLEX_FLOW_COLUMN); |
| 366 | + lv_obj_set_style_bg_color(game_selection, lv_color_black(), 0); |
| 367 | + lv_obj_set_style_border_color(game_selection, lv_color_black(), 0); |
| 368 | + lv_obj_align(game_selection, LV_ALIGN_CENTER, 0, 0); |
| 369 | + lv_obj_set_style_pad_top(game_selection, 0, 0); |
| 370 | + lv_obj_set_style_pad_bottom(game_selection, 0, 0); |
| 371 | + lv_obj_set_style_pad_left(game_selection, 0, 0); |
| 372 | + lv_obj_set_style_pad_right(game_selection, 0, 0); |
| 373 | + lv_obj_set_flex_align(game_selection, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); |
| 374 | + |
| 375 | + lv_obj_t * label = lv_label_create(game_selection); |
| 376 | + lv_obj_set_style_text_color(label, lv_color_white(), 0); |
| 377 | + lv_label_set_text_static(label, "SELECT THE GAME"); |
| 378 | + |
| 379 | + lv_obj_t * games = lv_obj_create(game_selection); |
| 380 | + lv_obj_set_style_bg_color(games, lv_color_black(), 0); |
| 381 | + lv_obj_set_style_border_color(games, lv_color_black(), 0); |
| 382 | + lv_obj_set_size(games, BSP_LCD_H_RES-10, BSP_LCD_V_RES/2); |
| 383 | + lv_obj_align(games, LV_ALIGN_CENTER, 0, 0); |
| 384 | + lv_obj_set_flex_flow(games, LV_FLEX_FLOW_ROW); |
| 385 | + lv_obj_set_style_pad_top(games, 0, 0); |
| 386 | + lv_obj_set_style_pad_bottom(games, 0, 0); |
| 387 | + lv_obj_set_style_pad_left(games, 0, 0); |
| 388 | + lv_obj_set_style_pad_right(games, 0, 0); |
| 389 | + lv_obj_set_flex_align(games, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); |
| 390 | + |
| 391 | + lv_obj_t * btn = lv_btn_create(games); |
| 392 | + lv_obj_t *img = lv_img_create(btn); |
| 393 | + lv_img_set_src(img, &img_supermario); |
| 394 | + lv_obj_align(img, LV_ALIGN_TOP_MID, 0, 0); |
| 395 | + lv_obj_set_style_radius(btn, 0, 0); |
| 396 | + lv_obj_set_style_pad_top(btn, 15, 0); |
| 397 | + lv_obj_set_style_pad_bottom(btn, 15, 0); |
| 398 | + lv_obj_set_style_pad_left(btn, 15, 0); |
| 399 | + lv_obj_set_style_pad_right(btn, 15, 0); |
| 400 | + lv_obj_add_event_cb(btn, app_lvgl_btn_supermario, LV_EVENT_CLICKED, NULL); |
| 401 | + |
| 402 | + btn = lv_btn_create(games); |
| 403 | + img = lv_img_create(btn); |
| 404 | + lv_img_set_src(img, &img_donkeykong); |
| 405 | + lv_obj_align(img, LV_ALIGN_TOP_MID, 0, 0); |
| 406 | + lv_obj_set_style_radius(btn, 0, 0); |
| 407 | + lv_obj_set_style_pad_top(btn, 15, 0); |
| 408 | + lv_obj_set_style_pad_bottom(btn, 15, 0); |
| 409 | + lv_obj_set_style_pad_left(btn, 15, 0); |
| 410 | + lv_obj_set_style_pad_right(btn, 15, 0); |
| 411 | + lv_obj_add_event_cb(btn, app_lvgl_btn_donkeykong, LV_EVENT_CLICKED, NULL); |
| 412 | + |
| 413 | + btn = lv_btn_create(games); |
| 414 | + img = lv_img_create(btn); |
| 415 | + lv_img_set_src(img, &img_qbert); |
| 416 | + lv_obj_align(img, LV_ALIGN_TOP_MID, 0, 0); |
| 417 | + lv_obj_set_style_radius(btn, 0, 0); |
| 418 | + lv_obj_set_style_pad_top(btn, 15, 0); |
| 419 | + lv_obj_set_style_pad_bottom(btn, 15, 0); |
| 420 | + lv_obj_set_style_pad_left(btn, 15, 0); |
| 421 | + lv_obj_set_style_pad_right(btn, 15, 0); |
| 422 | + lv_obj_add_event_cb(btn, app_lvgl_btn_qbert, LV_EVENT_CLICKED, NULL); |
| 423 | + |
| 424 | + bsp_display_unlock(); |
| 425 | +} |
| 426 | + |
285 | 427 | static int app_osd_video_init(int width, int height) |
286 | 428 | { |
287 | 429 | return 0; |
@@ -375,7 +517,6 @@ static void app_usb_hid_host_interface_callback(hid_host_device_handle_t hid_dev |
375 | 517 | case HID_HOST_INTERFACE_EVENT_INPUT_REPORT: |
376 | 518 | data = hid_host_device_get_data(hid_device_handle, &data_length); |
377 | 519 | if (dev->proto == HID_PROTOCOL_NONE) { |
378 | | - gamepad_t *gamepad = (gamepad_t*)data; |
379 | 520 | if (data_length < 8) { |
380 | 521 | break; |
381 | 522 | } |
|
0 commit comments