make sound work

This commit is contained in:
Tobias Gunkel
2025-08-16 23:06:15 +02:00
parent b71c83a5ca
commit f7c5959b0a
58 changed files with 25933 additions and 25820 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
#include <Arduino.h>
#include "peanut_gb_options.h"
#include "minigb_apu.h"
#include "peanut_gb.h"
#include "gbcolors.h"
-1
View File
@@ -1,7 +1,6 @@
#pragma once
#define PEANUT_GB_HEADER_ONLY
#include "peanut_gb_options.h"
#include "peanut_gb.h"
#define GBCOLOR_HEADER_ONLY
+3
View File
@@ -1,8 +1,11 @@
#include "common.h"
#include "input.h"
#include "i2s-audio.h"
#include "gb.h"
extern i2s_config_t i2s_config;
static struct
{
unsigned a : 1;
+19 -7
View File
@@ -2,7 +2,7 @@
#include "common.h"
#define USE_FRAMEBUFFER
//#define USE_FRAMEBUFFER
static TFT_eSPI tft = TFT_eSPI();
#ifdef USE_FRAMEBUFFER
@@ -16,7 +16,7 @@ static uint8_t scaledLineOffsetTable[LCD_HEIGHT]; // scaled to 240 lines
/* Pixel data is stored in here. */
static uint8_t pixels_buffer[LCD_WIDTH];
volatile ScalingMode scalingMode = ScalingMode::NORMAL;
volatile ScalingMode scalingMode = ScalingMode::STRETCH_KEEP_ASPECT;
static int lcd_line_busy = 0;
@@ -32,13 +32,14 @@ static void calcExtraLineTable() {
void lcd_init(void) {
tft.init();
// tft.initDMA();
#ifdef USE_FRAMEBUFFER
tft.initDMA();
#endif
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
}
void lcd_draw_line(struct gb_s* gb, const uint8_t pixels[LCD_WIDTH],
const uint_fast8_t line) {
void lcd_draw_line(struct gb_s* gb, const uint8_t pixels[LCD_WIDTH], const uint_fast8_t line) {
union core_cmd cmd;
/* Wait until previous line is sent. */
@@ -71,7 +72,11 @@ void lcd_write_pixels_normal(const uint16_t* pixels, uint8_t line, uint_fast16_t
const uint16_t colOffset = (DISPLAY_WIDTH - count) / 2;
const uint16_t screenLineOffset = (DISPLAY_HEIGHT - LCD_HEIGHT) / 2;
const uint16_t lineOffset = screenLineOffset + line;
#ifdef USE_FRAMEBUFFER
lcd_pushColors(lineOffset * DISPLAY_WIDTH + colOffset, pixels, count);
#else
lcd_pushColors(colOffset, lineOffset, pixels, count);
#endif
}
void lcd_write_pixels_stretched(const uint16_t* pixels, uint8_t line, uint_fast16_t count) {
@@ -94,7 +99,7 @@ void lcd_write_pixels_stretched(const uint16_t* pixels, uint8_t line, uint_fast1
#else
lcd_pushColors(0, lineOffset, doubledPixels, stretchedWidth);
if (lineRepeated) {
lcd_pushColors(0, lineOffset, doubledPixels, stretchedWidth);
lcd_pushColors(0, lineOffset + 1, doubledPixels, stretchedWidth);
}
#endif
}
@@ -123,7 +128,7 @@ void lcd_write_pixels_stretched_keep_aspect(const uint16_t* pixels, uint8_t line
#else
lcd_pushColors(colOffset, lineOffset, doubledPixels, stretchedWidth);
if (lineRepeated) {
lcd_pushColors(colOffset, lineOffset, doubledPixels, stretchedWidth);
lcd_pushColors(colOffset, lineOffset + 1, doubledPixels, stretchedWidth);
}
#endif
}
@@ -173,6 +178,13 @@ void core1_lcd_draw_line(const uint_fast8_t line) {
lcd_write_pixels(fb, line, LCD_WIDTH);
__atomic_store_n(&lcd_line_busy, 0, __ATOMIC_SEQ_CST);
#ifdef USE_FRAMEBUFFER
if (line == LCD_HEIGHT - 1) {
tft.setSwapBytes(true);
tft.pushImageDMA(0, 0, framebuffer.width(), framebuffer.height(), (uint16_t *) framebuffer.getPointer());
}
#endif
}
void core1DispatchLoop() {
+8 -6
View File
@@ -30,7 +30,7 @@
// #include "sdcard.h"
#include "common.h"
#include "game_bin.h"
#include "i2s.h"
#include "i2s-audio.h"
#define GBCOLOR_HEADER_ONLY
#include "gbcolors.h"
@@ -63,7 +63,7 @@ static uint8_t manual_palette_selected = 0;
struct gb_s gb;
palette_t palette; // Colour palette
i2s_config_t i2s_config;
uint_fast32_t frames = 0;
#define putstdio(x) write(1, x, strlen(x))
@@ -205,14 +205,16 @@ void setup() {
#if ENABLE_SOUND
// Allocate memory for the stream buffer
stream = malloc(AUDIO_BUFFER_SIZE_BYTES);
stream = (uint16_t*) malloc(AUDIO_BUFFER_SIZE_BYTES);
assert(stream != NULL);
memset(stream, 0, AUDIO_BUFFER_SIZE_BYTES); // Zero out the stream buffer
// Initialize I2S sound driver
i2s_config_t i2s_config = i2s_get_default_config();
i2s_config = i2s_get_default_config();
i2s_config.sample_freq = AUDIO_SAMPLE_RATE;
i2s_config.dma_trans_count = AUDIO_SAMPLES;
i2s_config.data_pin = 26, // DIN
i2s_config.clock_pin_base = 27, // BCLK + LRC
i2s_volume(&i2s_config, 2);
i2s_init(&i2s_config);
#endif
@@ -241,8 +243,8 @@ void loop() {
frames++;
#if ENABLE_SOUND
if (!gb.direct.frame_skip) {
audio_callback(NULL, stream, AUDIO_BUFFER_SIZE_BYTES);
i2s_dma_write(&i2s_config, stream);
audio_callback(NULL, (int16_t*) stream, AUDIO_BUFFER_SIZE_BYTES);
i2s_dma_write(&i2s_config, (int16_t*) stream);
}
#endif