Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Fix LCD init and merge resume support
Browse files Browse the repository at this point in the history
  • Loading branch information
nopjne authored and kbeckmann committed Feb 7, 2021
1 parent 8b5dd9a commit 0e2edb0
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Core/Inc/gw_lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern uint8_t emulator_framebuffer[(256 + 8 + 8) * 240] __attribute__((section
extern uint32_t active_framebuffer;



void lcd_deinit(SPI_HandleTypeDef *spi);
void lcd_init(SPI_HandleTypeDef *spi, LTDC_HandleTypeDef *ltdc);
void lcd_backlight_set(uint8_t brightness);
void lcd_backlight_on();
Expand Down
2 changes: 2 additions & 0 deletions Core/Inc/gw_linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ extern uint32_t __ram_exec_end__;
extern uint32_t _sitcram_hot;
extern uint32_t __itcram_hot_start__;
extern uint32_t __itcram_hot_end__;
extern uint8_t __configflash_start__;
extern uint8_t __configflash_end__;


// If this is not an array the compiler might put in a memory_chk with dest_size 1...
Expand Down
2 changes: 1 addition & 1 deletion Core/Src/gw_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void _OSPI_Program(OSPI_HandleTypeDef *hospi, uint32_t address, const uint8_t *
}

void OSPI_Program(OSPI_HandleTypeDef *hospi, uint32_t address, const uint8_t *buffer, size_t buffer_size) {
unsigned iterations = buffer_size / 256;
unsigned iterations = (buffer_size + 255) / 256;
unsigned dest_page = address / 256;

for(int i = 0; i < iterations; i++) {
Expand Down
28 changes: 8 additions & 20 deletions Core/Src/gw_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,20 @@ void lcd_backlight_on()
lcd_backlight_set(255);
}

void lcd_init(SPI_HandleTypeDef *spi, LTDC_HandleTypeDef *ltdc)
void lcd_deinit(SPI_HandleTypeDef *spi)
{
wdog_refresh();

// Turn display *off* completely.
lcd_backlight_off();

// Chip select low.
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
// 3.3v power to display *SET* to disable supply.
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_SET);
// Disable 1.8v.
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, GPIO_PIN_RESET);


// TURN OFF CHIP SELECT
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
// TURN OFF PD8
// Pull reset line(?) low. (Flakey without this)
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_8, GPIO_PIN_RESET);
}

// Turn off CS
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_Delay(100);
wdog_refresh();


void lcd_init(SPI_HandleTypeDef *spi, LTDC_HandleTypeDef *ltdc)
{
// Wake
// Enable 3.3v
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_RESET);
Expand Down Expand Up @@ -169,9 +160,6 @@ void lcd_init(SPI_HandleTypeDef *spi, LTDC_HandleTypeDef *ltdc)

memset(framebuffer1, 0, sizeof(framebuffer1));
memset(framebuffer2, 0, sizeof(framebuffer2));

// Finally enable the backlight
lcd_backlight_on();
}

void HAL_LTDC_ReloadEventCallback (LTDC_HandleTypeDef *hltdc) {
Expand Down
13 changes: 12 additions & 1 deletion Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ int _write(int file, char *ptr, int len)
void store_erase(const uint8_t *flash_ptr, size_t size)
{
// Only allow pointers in the SAVEFLASH allocated area
assert((flash_ptr >= &__SAVEFLASH_START__) && ((flash_ptr + size) <= &__SAVEFLASH_END__));
assert(
((flash_ptr >= &__SAVEFLASH_START__) && ((flash_ptr + size) <= &__SAVEFLASH_END__)) ||
((flash_ptr >= &__configflash_start__) && ((flash_ptr + size) <= &__configflash_end__))
);

// Convert mem mapped pointer to flash address
uint32_t save_address = flash_ptr - &__EXTFLASH_START__;
Expand Down Expand Up @@ -262,6 +265,11 @@ void store_save(const uint8_t *flash_ptr, const uint8_t *data, size_t size)
// Only allow 4kB aligned pointers
assert((save_address & (4*1024 - 1)) == 0);

int diff = memcmp((void*)flash_ptr, data, size);
if (diff == 0) {
return;
}

store_erase(flash_ptr, size);

OSPI_DisableMemoryMapped(&hospi1);
Expand Down Expand Up @@ -292,6 +300,9 @@ void GW_EnterDeepSleep(void)

lcd_backlight_off();

// Deinit the LCD, save power.
lcd_deinit(&hspi2);

// Leave a trace in RAM that we entered standby mode
boot_magic = BOOT_MAGIC_STANDBY;

Expand Down
9 changes: 3 additions & 6 deletions Core/Src/porting/gb/main_gb.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "common.h"
#include "rom_manager.h"

#define APP_ID 20
#define ODROID_APPID_GB 1

#define NVS_KEY_SAVE_SRAM "sram"

Expand Down Expand Up @@ -490,7 +490,7 @@ void pcm_submit() {

rg_app_desc_t * init(uint8_t load_state)
{
odroid_system_init(APP_ID, AUDIO_SAMPLE_RATE);
odroid_system_init(ODROID_APPID_GB, AUDIO_SAMPLE_RATE);
odroid_system_emu_init(&LoadState, &SaveState, &netplay_callback);

// Hack: Use the same buffer twice
Expand Down Expand Up @@ -534,8 +534,7 @@ rg_app_desc_t * init(uint8_t load_state)

emu_init();

//pal_set_dmg(odroid_settings_Palette_get());
pal_set_dmg(2);
pal_set_dmg(odroid_settings_Palette_get());

// Don't load state if the pause button is held while booting
uint32_t boot_buttons = GW_GetBootButtons();
Expand Down Expand Up @@ -602,8 +601,6 @@ void app_main_gb(uint8_t load_state)
if (power_pressed) {
printf("Power PRESSED %ld\n", power_pressed);
HAL_SAI_DMAStop(&hsai_BlockA1);
lcd_backlight_off();

if(!joystick.values[ODROID_INPUT_VOLUME]) {
// Always save as long as PAUSE is not pressed
SaveState("");
Expand Down
5 changes: 2 additions & 3 deletions Core/Src/porting/nes/main_nes.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "common.h"
#include "rom_manager.h"

#define APP_ID 30
#define ODROID_APPID_NES 2

// #define blit blit_nearest
// #define blit blit_normal
Expand Down Expand Up @@ -455,7 +455,6 @@ void osd_getinput(void)
if (buttons & B_POWER) {
printf("Power PRESSED %ld\n", power_pressed);
HAL_SAI_DMAStop(&hsai_BlockA1);

if(!(buttons & B_PAUSE)) {
SaveState("");
}
Expand Down Expand Up @@ -502,7 +501,7 @@ int app_main_nes(uint8_t load_state)

memset(framebuffer1, 0x0, sizeof(framebuffer1));
memset(framebuffer2, 0x0, sizeof(framebuffer2));
odroid_system_init(APP_ID, AUDIO_SAMPLE_RATE);
odroid_system_init(ODROID_APPID_NES, AUDIO_SAMPLE_RATE);
odroid_system_emu_init(&LoadState, &SaveState, NULL);

uint32_t buttons = GW_GetBootButtons();
Expand Down
6 changes: 6 additions & 0 deletions Core/Src/porting/odroid_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@

uint8_t audio_level = ODROID_AUDIO_VOLUME_MAX;

void odroid_audio_init(int sample_rate)
{
audio_level = odroid_settings_Volume_get();
}

void odroid_audio_submit(short* stereoAudioBuffer, int frameCount)
{
}

void odroid_audio_volume_set(int level)
{
audio_level = level;
odroid_settings_Volume_set(audio_level);
}

int odroid_audio_volume_get()
Expand Down
15 changes: 15 additions & 0 deletions Core/Src/porting/odroid_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

static const uint8_t backlightLevels[] = {128, 144, 160, 192, 255};
static odroid_display_backlight_t backlightLevel = ODROID_BACKLIGHT_LEVEL4;
static odroid_display_rotation_t rotationMode = ODROID_DISPLAY_ROTATION_OFF;
static odroid_display_scaling_t scalingMode = ODROID_DISPLAY_SCALING_FILL;
static odroid_display_filter_t filterMode = ODROID_DISPLAY_FILTER_OFF;

short odroid_display_queue_update(odroid_video_frame_t *frame, odroid_video_frame_t *previousFrame)
{
Expand Down Expand Up @@ -47,3 +50,15 @@ void odroid_display_set_backlight(odroid_display_backlight_t level)
odroid_settings_Backlight_set(level);
}


void odroid_display_init()
{
backlightLevel = odroid_settings_Backlight_get();
lcd_backlight_set(backlightLevels[backlightLevel]);

scalingMode = odroid_settings_DisplayScaling_get();
filterMode = odroid_settings_DisplayFilter_get();
rotationMode = odroid_settings_DisplayRotation_get();

printf("LCD init done.\n");
}
Loading

0 comments on commit 0e2edb0

Please sign in to comment.