Skip to content

Commit 8ea38e7

Browse files
committed
Working with BSP.
1 parent b0cdcc1 commit 8ea38e7

File tree

21 files changed

+320
-1814
lines changed

21 files changed

+320
-1814
lines changed

.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
build/
1+
managed_components/**
2+
build/*
3+
dependencies.lock
4+
sdkconfig
25
sdkconfig.old
3-
*.nes
4-
6+
.vscode/*
7+
.devcontainer/*
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: "1.0.0"
2+
description: esp_nes
3+
dependencies:
4+
idf: ">=5.0"
5+
esp-box: "2.4.0"

components/esp_nes/osd.c

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: CC0-1.0
5+
*/
6+
7+
/*******************************************************************************
8+
* Includes
9+
*******************************************************************************/
10+
#include <freertos/FreeRTOS.h>
11+
#include <freertos/timers.h>
12+
#include <freertos/task.h>
13+
#include <freertos/queue.h>
14+
#include <string.h>
15+
16+
#define LOBYTE(u16) ((uint8_t)(((uint16_t)(u16)) & 0xff))
17+
#define HIBYTE(u16) ((uint8_t)((((uint16_t)(u16))>>8) & 0xff))
18+
19+
//Nes stuff wants to define this as well...
20+
#undef false
21+
#undef true
22+
#undef bool
23+
24+
#include "noftypes.h"
25+
#include "nofconfig.h"
26+
#include "nofrendo.h"
27+
#include "bitmap.h"
28+
#include "osd.h"
29+
#include "bsp/esp-bsp.h"
30+
31+
32+
/*******************************************************************************
33+
* Function definitions
34+
*******************************************************************************/
35+
/* Video functions */
36+
static int app_osd_video_init(int width, int height);
37+
static void app_osd_video_shutdown(void);
38+
static int app_osd_video_set_mode(int width, int height);
39+
static void app_osd_video_set_palette(rgb_t *palette);
40+
static void app_osd_video_clear(uint8 color);
41+
static bitmap_t *app_osd_video_lock_write(void);
42+
static void app_osd_video_free_write(int num_dirties, rect_t *dirty_rects);
43+
static void app_osd_video_custom_blit(bitmap_t *primary, int num_dirties, rect_t *dirty_rects);
44+
45+
/* Audio functions */
46+
/*******************************************************************************
47+
* Local variables
48+
*******************************************************************************/
49+
50+
static viddriver_t vid_driver = {
51+
.name = "Vid Driver",
52+
.init = app_osd_video_init,
53+
.shutdown = app_osd_video_shutdown,
54+
.set_mode = app_osd_video_set_mode,
55+
.set_palette = app_osd_video_set_palette,
56+
.clear = app_osd_video_clear,
57+
.lock_write = app_osd_video_lock_write,
58+
.free_write = app_osd_video_free_write,
59+
.custom_blit = app_osd_video_custom_blit,
60+
.invalidate = false,
61+
};
62+
63+
static TimerHandle_t timer;
64+
static uint16 colorPalette[256];
65+
static bitmap_t *vidBitmap = NULL;
66+
67+
static lv_obj_t * lvgl_video_canvas = NULL;
68+
uint8_t * vid_buffer = NULL;
69+
70+
/*******************************************************************************
71+
* Public API functions
72+
*******************************************************************************/
73+
74+
void osd_getvideoinfo(vidinfo_t *info)
75+
{
76+
info->default_width = 256;
77+
info->default_height = BSP_LCD_V_RES;
78+
info->driver = &vid_driver;
79+
}
80+
81+
void osd_getsoundinfo(sndinfo_t *info)
82+
{
83+
}
84+
85+
void osd_setsound(void (*playfunc)(void *buffer, int size))
86+
{
87+
}
88+
89+
int osd_init(void)
90+
{
91+
uint32_t buf_size = 256 * BSP_LCD_V_RES * sizeof(uint16_t);
92+
vid_buffer = heap_caps_malloc(buf_size, MALLOC_CAP_DEFAULT);
93+
assert(vid_buffer);
94+
memset(vid_buffer, 0, buf_size);
95+
96+
bsp_display_lock(0);
97+
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_black(), 0);
98+
lvgl_video_canvas = lv_canvas_create(lv_scr_act());
99+
lv_canvas_set_buffer(lvgl_video_canvas, vid_buffer, 256, BSP_LCD_V_RES, LV_IMG_CF_TRUE_COLOR);
100+
lv_obj_center(lvgl_video_canvas);
101+
bsp_display_unlock();
102+
103+
return 0;
104+
}
105+
106+
void osd_shutdown(void)
107+
{
108+
}
109+
110+
/* This is os-specific part of main() */
111+
int osd_main(int argc, char *argv[])
112+
{
113+
config.filename = "config.cfg";
114+
return main_loop("rom", system_autodetect);
115+
}
116+
117+
int osd_installtimer(int frequency, void *func, int funcsize, void *counter, int countersize)
118+
{
119+
printf("Timer install, freq=%d\n", frequency);
120+
timer=xTimerCreate("nes",configTICK_RATE_HZ/frequency, pdTRUE, NULL, func);
121+
xTimerStart(timer, 0);
122+
return 0;
123+
}
124+
125+
/* File system interface */
126+
void osd_fullname(char *fullname, const char *shortname)
127+
{
128+
strncpy(fullname, shortname, PATH_MAX);
129+
}
130+
131+
/* This gives filenames for storage of saves */
132+
char *osd_newextension(char *string, char *ext)
133+
{
134+
return string;
135+
}
136+
137+
void osd_getinput(void)
138+
{
139+
}
140+
141+
void osd_getmouse(int *x, int *y, int *button)
142+
{
143+
}
144+
145+
/* This gives filenames for storage of PCX snapshots */
146+
int osd_makesnapname(char *filename, int len)
147+
{
148+
return -1;
149+
}
150+
151+
/*******************************************************************************
152+
* Private API functions
153+
*******************************************************************************/
154+
155+
static int app_osd_video_init(int width, int height)
156+
{
157+
return 0;
158+
}
159+
160+
static void app_osd_video_shutdown(void)
161+
{
162+
163+
}
164+
165+
/* set a video mode */
166+
static int app_osd_video_set_mode(int width, int height)
167+
{
168+
return 0;
169+
}
170+
171+
/* copy nes palette over to hardware */
172+
static void app_osd_video_set_palette(rgb_t *palette)
173+
{
174+
uint16 c;
175+
176+
for (int i = 0; i < 256; i++)
177+
{
178+
c=(palette[i].b>>3)+((palette[i].g>>2)<<5)+((palette[i].r>>3)<<11);
179+
colorPalette[i]=c;
180+
}
181+
}
182+
183+
/* clear all frames to a particular color */
184+
static void app_osd_video_clear(uint8 color)
185+
{
186+
bsp_display_lock(0);
187+
188+
for(int x=0; x<256; x++)
189+
{
190+
for(int y=0; y<BSP_LCD_V_RES; y++)
191+
{
192+
vid_buffer[(x*BSP_LCD_V_RES*2) + (y*2)] = HIBYTE(colorPalette[color]);
193+
vid_buffer[(x*BSP_LCD_V_RES*2) + (y*2)+1] = LOBYTE(colorPalette[color]);
194+
}
195+
}
196+
197+
lv_obj_invalidate(lvgl_video_canvas);
198+
bsp_display_unlock();
199+
}
200+
201+
/* acquire the directbuffer for writing */
202+
static bitmap_t *app_osd_video_lock_write(void)
203+
{
204+
vidBitmap = bmp_create(256, BSP_LCD_V_RES, 256*sizeof(uint16));
205+
return vidBitmap;
206+
}
207+
208+
static void app_osd_video_free_write(int num_dirties, rect_t *dirty_rects)
209+
{
210+
bmp_destroy(&vidBitmap);
211+
vidBitmap = NULL;
212+
}
213+
214+
static void app_osd_video_custom_blit(bitmap_t *primary, int num_dirties, rect_t *dirty_rects)
215+
{
216+
const uint8_t * data = primary->data;
217+
bsp_display_lock(0);
218+
219+
for(int x=0; x<256; x++)
220+
{
221+
for(int y=0; y<BSP_LCD_V_RES; y++)
222+
{
223+
vid_buffer[(x*BSP_LCD_V_RES*2) + (y*2)] = HIBYTE(colorPalette[data[0]]);
224+
vid_buffer[(x*BSP_LCD_V_RES*2) + (y*2)+1] = LOBYTE(colorPalette[data[0]]);
225+
data++;
226+
}
227+
}
228+
229+
lv_obj_invalidate(lvgl_video_canvas);
230+
bsp_display_unlock();
231+
}

components/nofrendo/nes/nes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#ifndef NES_VISIBLE_HEIGHT
3939
#define NES_VISIBLE_HEIGHT 240
4040
#endif /* !NES_VISIBLE_HEIGHT */
41-
#define NES_SCREEN_WIDTH 320
41+
#define NES_SCREEN_WIDTH 256
4242
#define NES_SCREEN_HEIGHT 240
4343

4444
/* NTSC = 60Hz, PAL = 50Hz */

dependencies.lock

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,45 @@
11
dependencies:
2+
espressif/esp-box:
3+
component_hash: b11e8c8255c16744b26c8ec0d83a82090b73512af7c634bb912e9f971e94b565
4+
source:
5+
service_url: https://api.components.espressif.com/
6+
type: service
7+
version: 2.4.0
8+
espressif/esp_codec_dev:
9+
component_hash: 5ab5f76a60abc4f8478aae2a6deb57c848b9762803b50c40c48b86b49bf10119
10+
source:
11+
service_url: https://api.components.espressif.com/
12+
type: service
13+
version: 1.0.1
14+
espressif/esp_lcd_touch:
15+
component_hash: 847284c65f8d5aaa9a801f5b3d3dac0ba0a5a2dc1bb68890989e84dd9c4a9d53
16+
source:
17+
service_url: https://api.components.espressif.com/
18+
type: service
19+
version: 1.0.4
20+
espressif/esp_lcd_touch_tt21100:
21+
component_hash: 27d0ec1226e2ce81ad6a170b27530dbcf959cd1fb9abe1ba207509a8a2f2ed22
22+
source:
23+
service_url: https://api.components.espressif.com/
24+
type: service
25+
version: 1.0.7~1
26+
espressif/esp_lvgl_port:
27+
component_hash: 6821066c79fd4920077cb4449c68fde741783a545cae5b6b6019eedad7afa00f
28+
source:
29+
service_url: https://api.components.espressif.com/
30+
type: service
31+
version: 1.1.0
232
idf:
333
component_hash: null
434
source:
535
type: idf
636
version: 5.2.0
7-
manifest_hash: 7284b3df06eb72d5241b3a780d5ebf9ddb58f2de63b062aba2b5ff7559b51636
8-
target: esp32
37+
lvgl/lvgl:
38+
component_hash: 1b50316b27a2a46269a1334b90a2cfc690ac8173f346d6e4992188add7971b79
39+
source:
40+
service_url: https://api.components.espressif.com/
41+
type: service
42+
version: 8.3.7
43+
manifest_hash: 08856f7064c440c8cf4efaa2c767ad28e39600fc8b2a4e9d432ef19f8d168f9c
44+
target: esp32s3
945
version: 1.0.0

games/supermario.nes

40 KB
Binary file not shown.

main/idf_component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ description: NES Emulator
22

33
dependencies:
44
idf: ">=5.0"
5+
esp-box: "2.4.0"

main/main.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
#include "freertos/FreeRTOS.h"
2-
#include "esp_wifi.h"
1+
/*
2+
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: CC0-1.0
5+
*/
6+
37
#include "esp_system.h"
4-
#include "esp_event.h"
58
#include "nvs_flash.h"
6-
#include "driver/gpio.h"
79
#include "nofrendo.h"
810
#include "esp_partition.h"
911
#include "esp_spi_flash.h"
10-
11-
12+
#include "bsp/esp-bsp.h"
1213

1314
char *osd_getromdata() {
1415
char* romdata;
@@ -32,6 +33,13 @@ char *osd_getromdata() {
3233

3334
int app_main(void)
3435
{
36+
/* Initialize display and LVGL */
37+
lv_disp_t * display = bsp_display_start();
38+
39+
/* Set display brightness to 100% */
40+
bsp_display_backlight_on();
41+
42+
3543
printf("NoFrendo start!\n");
3644
nofrendo_main(0, NULL);
3745
printf("NoFrendo died? WtF?\n");

0 commit comments

Comments
 (0)