Skip to content

Commit

Permalink
Merge pull request #7 from pebri86/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
pebri86 authored Oct 11, 2019
2 parents e15f519 + 7bbd6fd commit cb3ac15
Show file tree
Hide file tree
Showing 17 changed files with 5,364 additions and 2,738 deletions.
9 changes: 7 additions & 2 deletions esplay-gnuboy/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <power.h>
#include "display_gb.h"
#include "menu.h"
#include "gb_frame.h"

extern int debug_trace;

Expand Down Expand Up @@ -460,8 +461,8 @@ void app_main(void)
set_display_brightness(get_backlight_settings());
audio_volume_set(get_volume_settings());

//display_show_splash();
//vTaskDelay(2000);
// battery
battery_level_init();

// Gamepad
gamepad_init();
Expand Down Expand Up @@ -517,6 +518,10 @@ void app_main(void)
// Clear display
write_gb_frame(NULL, SCALE_STRETCH);

// draw frame
//renderGfx(0,0,32,240,gb_frame.pixel_data,0,0,gb_frame.width);
//renderGfx(32+256,0,32,240,gb_frame.pixel_data,32,0,gb_frame.width);

// Load ROM
loader_init(NULL);

Expand Down
23 changes: 15 additions & 8 deletions esplay-launcher/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static void drawHomeScreen()
UG_PutString(160, 50 + (56 * 2) + 13 + 18, "MENU");
ui_flush();
battery_level_read(&bat_state);
drawVolume(get_volume_settings() * 25);
drawVolume(get_volume_settings());
drawBattery(bat_state.percentage);
if (wifi_en)
renderGraphics(320 - (50), 0, 24 * 6, 0, 24, 12);
Expand Down Expand Up @@ -246,9 +246,9 @@ static void showOptionPage(int selected)
break;
case 1:
if (i == selected)
ui_display_progress((320 - 100 - 3), top + 2, 100, 8, (volume * 100) / 4, C_BLACK, C_YELLOW, C_BLACK);
ui_display_progress((320 - 100 - 3), top + 2, 100, 8, (volume * 100) / 100, C_BLACK, C_YELLOW, C_BLACK);
else
ui_display_progress((320 - 100 - 3), top + 2, 100, 8, (volume * 100) / 4, C_WHITE, C_BLACK, C_WHITE);
ui_display_progress((320 - 100 - 3), top + 2, 100, 8, (volume * 100) / 100, C_WHITE, C_BLACK, C_WHITE);
break;
case 2:
if (i == selected)
Expand Down Expand Up @@ -308,7 +308,7 @@ static int showOption()
break;
case 1:
v = get_volume_settings();
v--;
v -= 5;
if (v < 0)
v = 0;
set_volume_settings(v);
Expand Down Expand Up @@ -347,9 +347,9 @@ static int showOption()
break;
case 1:
v = get_volume_settings();
v++;
if (v > 4)
v = 4;
v += 5;
if (v > 100)
v = 100;
set_volume_settings(v);
break;
case 2:
Expand Down Expand Up @@ -395,6 +395,7 @@ void app_main(void)
{
nvs_flash_init();
esplay_system_init();

gamepad_init();

// Display
Expand Down Expand Up @@ -462,6 +463,7 @@ void app_main(void)
int menuItem = 0;
int prevItem = 0;
int scroll = 0;
int doRefresh = 1;
input_gamepad_state prevKey;
gamepad_read(&prevKey);
while (1)
Expand All @@ -474,13 +476,15 @@ void app_main(void)
if (menuItem > NUM_EMULATOR - 1)
menuItem = 0;
scroll = -SCROLLSPD;
doRefresh = 1;
}
if (!prevKey.values[GAMEPAD_INPUT_RIGHT] && joystick.values[GAMEPAD_INPUT_RIGHT] && !scroll)
{
menuItem--;
if (menuItem < 0)
menuItem = NUM_EMULATOR - 1;
scroll = SCROLLSPD;
doRefresh = 1;
}
if (scroll > 0)
scroll += SCROLLSPD;
Expand All @@ -497,9 +501,10 @@ void app_main(void)
{
scrollGfx(scroll + ((scroll > 0) ? -320 : 320), 78, 0, (56 * menuItem) + 12, 320, 56);
}
else
else if (doRefresh)
{
scrollGfx(0, 78, 0, (56 * menuItem) + 12, 320, 56);
doRefresh = 0;
}
if (!prevKey.values[GAMEPAD_INPUT_A] && joystick.values[GAMEPAD_INPUT_A])
{
Expand All @@ -526,6 +531,7 @@ void app_main(void)
ui_clear_screen();
ui_flush();
drawHomeScreen();
doRefresh = 1;
}
if (!prevKey.values[GAMEPAD_INPUT_B] && joystick.values[GAMEPAD_INPUT_B])
resume();
Expand All @@ -538,6 +544,7 @@ void app_main(void)

ui_clear_screen();
drawHomeScreen();
doRefresh = 1;
}
prevKey = joystick;
vTaskDelay(10 / portTICK_PERIOD_MS);
Expand Down
8 changes: 7 additions & 1 deletion esplay-nofrendo/components/nofrendo-esp32/video_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "power.h"
#include "display_nes.h"
#include "menu.h"
#include "gb_frame.h"

#define DEFAULT_SAMPLERATE 32000
#define DEFAULT_FRAGSIZE 512
Expand Down Expand Up @@ -256,7 +257,7 @@ static void videoTask(void *arg)

if (bmp == 2)
{
write_nes_frame(NULL, opt);;
//write_frame_rectangleLE(32,0,256,240,NULL);
int ret = showMenu();
switch (ret)
{
Expand Down Expand Up @@ -510,6 +511,11 @@ int osd_init()
return -1;

write_nes_frame(NULL, SCALE_STRETCH);

// draw frame
//renderGfx(0,0,32,240,gb_frame.pixel_data,0,0,gb_frame.width);
//renderGfx(32+256,0,32,240,gb_frame.pixel_data,32,0,gb_frame.width);

vidQueue = xQueueCreate(1, sizeof(bitmap_t *));
xTaskCreatePinnedToCore(&videoTask, "videoTask", 1024*3, NULL, 5, NULL, 1);
osd_initinput();
Expand Down
4 changes: 2 additions & 2 deletions esplay-nofrendo/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ int app_main(void)

set_display_brightness(get_backlight_settings());

//display_show_splash();
//vTaskDelay(1000);
// battery
battery_level_init();

switch (esp_sleep_get_wakeup_cause())
{
Expand Down
6 changes: 3 additions & 3 deletions esplay-nofrendo/sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ CONFIG_SPIRAM_IGNORE_NOTFOUND=y
CONFIG_SPIRAM_USE_MEMMAP=y
CONFIG_SPIRAM_USE_CAPS_ALLOC=
CONFIG_SPIRAM_USE_MALLOC=
CONFIG_SPIRAM_TYPE_AUTO=
CONFIG_SPIRAM_TYPE_ESPPSRAM32=y
CONFIG_SPIRAM_TYPE_AUTO=y
CONFIG_SPIRAM_TYPE_ESPPSRAM32=
CONFIG_SPIRAM_TYPE_ESPPSRAM64=
CONFIG_SPIRAM_SIZE=4194304
CONFIG_SPIRAM_SIZE=-1
CONFIG_SPIRAM_SPEED_40M=y
CONFIG_SPIRAM_MEMTEST=y
CONFIG_SPIRAM_CACHE_WORKAROUND=y
Expand Down
88 changes: 54 additions & 34 deletions esplay-sdk/esplay-components/esplay-hal/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,38 @@
#include "freertos/FreeRTOS.h"
#include "esp_system.h"
#include "driver/i2s.h"
#include "driver/gpio.h"
#include "driver/rtc_io.h"

static float Volume = 0.5f;
static esplay_volume_level volumeLevel = ESPLAY_VOLUME_LEVEL1;
static int volumeLevels[] = {0, 25, 40, 80, 120};
static int volumeLevel = 25;
static int sampleRate;

esplay_volume_level audio_volume_get()
int audio_volume_get()
{
return volumeLevel;
}

void audio_volume_set(esplay_volume_level value)
void audio_volume_set(int value)
{
if (value >= VOLUME_LEVEL_COUNT)
if (value > VOLUME_LEVEL_COUNT)
{
printf("audio_volume_set: value out of range (%d)\n", value);
abort();
}

volumeLevel = value;
Volume = (float)volumeLevels[value] * 0.001f;
}

void audio_volume_change()
{
int level = (volumeLevel + 1) % VOLUME_LEVEL_COUNT;
audio_volume_set(level);
Volume = (float)volumeLevel * 0.001f;

// settings_Volume_set(level);
if(volumeLevel != 0)
audio_amp_enable();
else
audio_amp_disable();
}

void audio_init(int sample_rate)
{
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT);
printf("%s: sample_rate=%d\n", __func__, sample_rate);

// NOTE: buffer needs to be adjusted per AUDIO_SAMPLE_RATE
Expand All @@ -49,7 +48,8 @@ void audio_init(int sample_rate)
//.dma_buf_len = 1472 / 2, // (368samples * 2ch * 2(short)) = 1472
.dma_buf_len = 512, // (416samples * 2ch * 2(short)) = 1664
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, //Interrupt level 1
.use_apll = false};
.use_apll = false
};

i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
i2s_pin_config_t pin_config = {
Expand All @@ -59,38 +59,58 @@ void audio_init(int sample_rate)
.data_in_num = -1 //Not used
};
i2s_set_pin(I2S_NUM, &pin_config);
sampleRate = sample_rate;
}

void audio_submit(short *stereoAudioBuffer, int frameCount)
{

short currentAudioSampleCount = frameCount * 2;

for (short i = 0; i < currentAudioSampleCount; ++i)
if (volumeLevel != 0)
{
int sample = stereoAudioBuffer[i] * Volume;
if (sample > 32767)
sample = 32767;
else if (sample < -32767)
sample = -32767;

stereoAudioBuffer[i] = (short)sample;
}

int len = currentAudioSampleCount * sizeof(int16_t);
size_t count;
i2s_write(I2S_NUM, (const char *)stereoAudioBuffer, len, &count, portMAX_DELAY);
if (count != len)
{
printf("i2s_write_bytes: count (%d) != len (%d)\n", count, len);
abort();
short currentAudioSampleCount = frameCount * 2;

for (short i = 0; i < currentAudioSampleCount; ++i)
{
int sample = stereoAudioBuffer[i] * Volume;
if (sample > 32767)
sample = 32767;
else if (sample < -32767)
sample = -32767;

stereoAudioBuffer[i] = (short)sample;
}

int len = currentAudioSampleCount * sizeof(int16_t);
size_t count;
i2s_write(I2S_NUM, (const char *)stereoAudioBuffer, len, &count, portMAX_DELAY);
if (count != len)
{
printf("i2s_write_bytes: count (%d) != len (%d)\n", count, len);
abort();
}
}
}

void audio_terminate()
{
audio_amp_disable();
i2s_zero_dma_buffer(I2S_NUM);
i2s_stop(I2S_NUM);

i2s_start(I2S_NUM);
}

void audio_resume()
{
if (volumeLevel != 0)
audio_amp_enable();
}

void audio_amp_enable()
{
gpio_set_level(GPIO_NUM_4, 1);
}

void audio_amp_disable()
{
gpio_set_level(GPIO_NUM_4, 0);
}
4 changes: 4 additions & 0 deletions esplay-sdk/esplay-components/esplay-hal/gamepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ static uint8_t i2c_keypad_read()

i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
#if 0
i2c_master_write_byte(cmd, 0x38 << 1 | READ_BIT, ACK_CHECK_EN);
#else
i2c_master_write_byte(cmd, 0x20 << 1 | READ_BIT, ACK_CHECK_EN);
#endif
i2c_master_read_byte(cmd, data + len - 1, NACK_VAL);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 1000 / portTICK_RATE_MS);
Expand Down
12 changes: 6 additions & 6 deletions esplay-sdk/esplay-components/esplay-hal/include/audio.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#ifndef AUDIO_H
#define AUDIO_H

#include "settings.h"

#define I2S_NUM I2S_NUM_0
#define VOLUME_LEVEL_COUNT (5)
#define VOLUME_LEVEL_COUNT (100)


void audio_init(int sample_rate);
void audio_submit(short *stereoAudioBuffer, int frameCount);
void audio_terminate();
esplay_volume_level audio_volume_get();
void audio_volume_set(esplay_volume_level value);
void audio_volume_change();
void audio_resume();
int audio_volume_get();
void audio_volume_set(int value);
void audio_amp_enable();
void audio_amp_disable();

#endif
14 changes: 13 additions & 1 deletion esplay-sdk/esplay-components/esplay-hal/include/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@ typedef struct
int percentage;
} battery_state;

typedef enum
{
NO_CHRG = 0,
CHARGING,
FULL_CHARGED
} charging_state;

#define USB_PLUG_PIN GPIO_NUM_32
#define CHRG_STATE_PIN GPIO_NUM_33

void system_sleep();
void esplay_system_init();
void battery_level_init();
void battery_level_read(battery_state *out_state);
void battery_level_force_voltage(float volts);
void battery_monitor_enabled_set(int value);
void battery_monitor_enabled_set(int value);
charging_state getChargeStatus();
void system_led_set(int state);
Loading

0 comments on commit cb3ac15

Please sign in to comment.