Skip to content

Commit 03f6721

Browse files
committed
Thu 19 Dec 2019 08:37:43 EST
1 parent 94d77af commit 03f6721

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+32659
-14
lines changed

Launchers/.DS_Store

0 Bytes
Binary file not shown.

Launchers/retro-esp32-beta/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
3+
# project subdirectory.
4+
#
5+
6+
PROJECT_NAME := retro-esp32
7+
8+
include $(IDF_PATH)/make/project.mk
9+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
menu "Retro ESP32 Configuration"
2+
choice LCD_DRIVER_CHIP
3+
prompt "LCD Driver Chip"
4+
default LCD_DRIVER_CHIP_ODROID_GO
5+
help
6+
LCD Screen Driver
7+
8+
config LCD_DRIVER_CHIP_ODROID_GO
9+
bool "Odroid Go - 2.4\" [ILI9341]"
10+
11+
config LCD_DRIVER_CHIP_RETRO_ESP32
12+
bool "Retro ESP32 - 2.6\" [ILI9342]"
13+
14+
endchoice
15+
16+
choice MENU_HOT_KEYS
17+
prompt "MENU Key Options"
18+
default DEFAULT_MENU_KEY
19+
help
20+
Select Hot Key (Menu Button)
21+
22+
config DEFAULT_MENU_KEY
23+
bool "Odroid Go MENU Button"
24+
25+
config COMBO_MENU_KEY
26+
bool "START + SELECT as MENU button"
27+
28+
endchoice
29+
endmenu
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Component Makefile
3+
#
4+
# This Makefile can be left empty. By default, it will take the sources in the
5+
# src/ directory, compile them and link them into lib(subdirectory_name).a
6+
# in the build directory. This behaviour is entirely configurable,
7+
# please read the ESP-IDF documents if you need to do this.
8+
#
9+
10+
#CFLAGS :=
11+
#COMPONENT_DEPENDS :=
12+
#COMPONENT_ADD_INCLUDEDIRS := .
13+
#COMPONENT_SRCDIRS := .

Launchers/retro-esp32-beta/components/odroid/hourglass_empty_black_48dp.h

Lines changed: 240 additions & 0 deletions
Large diffs are not rendered by default.

Launchers/retro-esp32-beta/components/odroid/image_sd_card_alert.h

Lines changed: 8530 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Launchers/retro-esp32-beta/components/odroid/image_sd_card_unknown.h

Lines changed: 8530 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Launchers/retro-esp32-beta/components/odroid/image_splash.h

Lines changed: 8475 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
#include "odroid_audio.h"
2+
3+
#include "odroid_settings.h"
4+
5+
#include "freertos/FreeRTOS.h"
6+
#include "esp_system.h"
7+
#include "driver/i2s.h"
8+
#include "driver/rtc_io.h"
9+
10+
11+
12+
#define I2S_NUM (I2S_NUM_0)
13+
#define BUILTIN_DAC_ENABLED 1
14+
15+
static float Volume = 1.0f;
16+
static odroid_volume_level volumeLevel = ODROID_VOLUME_LEVEL4;
17+
static int volumeLevels[] = {0, 125, 250, 500, 1000};
18+
static int audio_sample_rate;
19+
20+
21+
odroid_volume_level odroid_audio_volume_get()
22+
{
23+
return volumeLevel;
24+
}
25+
26+
void odroid_audio_volume_set(odroid_volume_level value)
27+
{
28+
if (value >= ODROID_VOLUME_LEVEL_COUNT)
29+
{
30+
printf("odroid_audio_volume_set: value out of range (%d)\n", value);
31+
abort();
32+
}
33+
34+
volumeLevel = value;
35+
Volume = (float)volumeLevels[value] * 0.001f;
36+
}
37+
38+
void odroid_audio_volume_change()
39+
{
40+
int level = (volumeLevel + 1) % ODROID_VOLUME_LEVEL_COUNT;
41+
odroid_audio_volume_set(level);
42+
43+
odroid_settings_Volume_set(level);
44+
}
45+
46+
void odroid_audio_init(int sample_rate)
47+
{
48+
audio_sample_rate = sample_rate;
49+
50+
// NOTE: buffer needs to be adjusted per AUDIO_SAMPLE_RATE
51+
# if BUILTIN_DAC_ENABLED
52+
53+
i2s_config_t i2s_config = {
54+
//.mode = I2S_MODE_MASTER | I2S_MODE_TX, // Only TX
55+
.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN,
56+
.sample_rate = audio_sample_rate,
57+
.bits_per_sample = 16,
58+
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, //2-channels
59+
.communication_format = I2S_COMM_FORMAT_I2S_MSB,
60+
//.communication_format = I2S_COMM_FORMAT_PCM,
61+
.dma_buf_count = 4,
62+
//.dma_buf_len = 1472 / 2, // (368samples * 2ch * 2(short)) = 1472
63+
.dma_buf_len = 512, // (416samples * 2ch * 2(short)) = 1664
64+
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, //Interrupt level 1
65+
.use_apll = 0 //1
66+
};
67+
68+
i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
69+
70+
i2s_set_pin(I2S_NUM, NULL);
71+
i2s_set_dac_mode(/*I2S_DAC_CHANNEL_LEFT_EN*/ I2S_DAC_CHANNEL_BOTH_EN);
72+
73+
#else
74+
75+
i2s_config_t i2s_config = {
76+
.mode = I2S_MODE_MASTER | I2S_MODE_TX, // Only TX
77+
.sample_rate = audio_sample_rate,
78+
.bits_per_sample = 16,
79+
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, //2-channels
80+
.communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB,
81+
.dma_buf_count = 4,
82+
//.dma_buf_len = 1472 / 2, // (368samples * 2ch * 2(short)) = 1472
83+
.dma_buf_len = 512, // (416samples * 2ch * 2(short)) = 1664
84+
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, //Interrupt level 1
85+
.use_apll = 1
86+
};
87+
88+
i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
89+
90+
91+
i2s_pin_config_t pin_config = {
92+
.bck_io_num = 26,
93+
.ws_io_num = 25,
94+
.data_out_num = 27,
95+
.data_in_num = -1 //Not used
96+
};
97+
i2s_set_pin(I2S_NUM, &pin_config);
98+
99+
#endif
100+
101+
odroid_volume_level level = odroid_settings_Volume_get();
102+
odroid_audio_volume_set(level);
103+
}
104+
105+
void odroid_audio_terminate()
106+
{
107+
i2s_zero_dma_buffer(I2S_NUM);
108+
i2s_stop(I2S_NUM);
109+
110+
i2s_start(I2S_NUM);
111+
112+
113+
esp_err_t err = rtc_gpio_init(GPIO_NUM_25);
114+
err = rtc_gpio_init(GPIO_NUM_26);
115+
if (err != ESP_OK)
116+
{
117+
abort();
118+
}
119+
120+
err = rtc_gpio_set_direction(GPIO_NUM_25, RTC_GPIO_MODE_OUTPUT_ONLY);
121+
err = rtc_gpio_set_direction(GPIO_NUM_26, RTC_GPIO_MODE_OUTPUT_ONLY);
122+
if (err != ESP_OK)
123+
{
124+
abort();
125+
}
126+
127+
err = rtc_gpio_set_level(GPIO_NUM_25, 0);
128+
err = rtc_gpio_set_level(GPIO_NUM_26, 0);
129+
if (err != ESP_OK)
130+
{
131+
abort();
132+
}
133+
}
134+
135+
void odroid_audio_submit(short* stereoAudioBuffer, int frameCount)
136+
{
137+
short currentAudioSampleCount = frameCount * 2;
138+
139+
#if BUILTIN_DAC_ENABLED
140+
// Convert for built in DAC
141+
for (short i = 0; i < currentAudioSampleCount; i += 2)
142+
{
143+
int32_t dac0;
144+
int32_t dac1;
145+
146+
if (Volume == 0.0f)
147+
{
148+
// Disable amplifier
149+
dac0 = 0;
150+
dac1 = 0;
151+
}
152+
else
153+
{
154+
// Down mix stero to mono
155+
int32_t sample = stereoAudioBuffer[i];
156+
sample += stereoAudioBuffer[i + 1];
157+
sample >>= 1;
158+
159+
// Normalize
160+
const float sn = (float)sample / 0x8000;
161+
162+
// Scale
163+
const int magnitude = 127 + 127;
164+
const float range = magnitude * sn * Volume;
165+
166+
// Convert to differential output
167+
if (range > 127)
168+
{
169+
dac1 = (range - 127);
170+
dac0 = 127;
171+
}
172+
else if (range < -127)
173+
{
174+
dac1 = (range + 127);
175+
dac0 = -127;
176+
}
177+
else
178+
{
179+
dac1 = 0;
180+
dac0 = range;
181+
}
182+
183+
dac0 += 0x80;
184+
dac1 = 0x80 - dac1;
185+
186+
dac0 <<= 8;
187+
dac1 <<= 8;
188+
}
189+
190+
stereoAudioBuffer[i] = (int16_t)dac1;
191+
stereoAudioBuffer[i + 1] = (int16_t)dac0;
192+
}
193+
194+
#endif
195+
196+
int len = currentAudioSampleCount * sizeof(int16_t);
197+
int count = i2s_write_bytes(I2S_NUM, (const char *)stereoAudioBuffer, len, portMAX_DELAY);
198+
if (count != len)
199+
{
200+
printf("i2s_write_bytes: count (%d) != len (%d)\n", count, len);
201+
abort();
202+
}
203+
}
204+
205+
int odroid_audio_sample_rate_get()
206+
{
207+
return audio_sample_rate;
208+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
4+
#define ODROID_VOLUME_LEVEL_COUNT (5)
5+
6+
typedef enum
7+
{
8+
ODROID_VOLUME_LEVEL0 = 0,
9+
ODROID_VOLUME_LEVEL1 = 1,
10+
ODROID_VOLUME_LEVEL2 = 2,
11+
ODROID_VOLUME_LEVEL3 = 3,
12+
ODROID_VOLUME_LEVEL4 = 4,
13+
14+
_ODROID_VOLUME_FILLER = 0xffffffff
15+
} odroid_volume_level;
16+
17+
18+
odroid_volume_level odroid_audio_volume_get();
19+
void odroid_audio_volume_set(odroid_volume_level value);
20+
void odroid_audio_volume_change();
21+
void odroid_audio_init(int sample_rate);
22+
void odroid_audio_terminate();
23+
void odroid_audio_submit(short* stereoAudioBuffer, int frameCount);
24+
int odroid_audio_sample_rate_get();

0 commit comments

Comments
 (0)