Commit graph

12191 commits

Author SHA1 Message Date
mojyack
6dc731dff2 include pcm.h in pcm_mixer.h for pcm_peaks
Change-Id: I074fff95b5147a343d23e22e876b33884a173c97
2026-04-24 20:07:29 +09:00
Aidan MacDonald
d02ad9b749 pcm: improve workaround for false -Warray-bounds in pcm_switch_sink
Change-Id: I81ff414ed07bbc61367250c25dc99c11e79d21d2
2026-04-23 20:43:07 -04:00
Christian Soffke
d1abd788d0 pcm_mixer: fix missing NULL check for play_cbs
Fixes Metronome plugin crashing
(regression introduced in cb04b81)

Does *not* fix missing Metronome sound
(regression introduced in 017dd72)

Change-Id: I1da9aa2c937b267a3d5b122c431eaa9f7e748440
2026-04-23 15:13:17 +02:00
Aidan MacDonald
e661c35b29 dircache: increase stack size to avoid stack overflows
On FS#13821, a test build with -fstack-protector-all
(which adds 4 bytes of stack to each function, roughly)
overflowed the dircache stack on the Hifiwalker H2.
In my own testing, the dircache thread hit 94% stack
use on the Fiio M3K using the same settings.

That seems a bit too close to the limit, especially
since the dircache uses recursion and might consume
more stack space for deeply nested directories.

Adding 768 bytes should provide enough of a safety
margin. This increases the stack size from 1.25k to
2k on most targets, including all X1000 targets.

Change-Id: I900c19da9fb33f539d02b00830aedeb15c7449e2
2026-04-22 22:07:28 +01:00
Aidan MacDonald
d815053360 Add support for -fstack-protector in native builds
-fstack-protector only needs a small amount of runtime
support to work on native builds. It increases code size
by ~1.5% on ARM/MIPS; -fstack-protector-strong adds 3-4%.
This is disabled by default and must be enabled by passing
'--with-stack-protector' to configure.

Change-Id: If952e711d3673c9b469895f08c7bff70b3d95df6
2026-04-21 21:16:28 -04:00
Solomon Peachy
9dce0c3258 Work around a false positive compiler warning in pcm_switch_sink()
CC firmware/pcm.c
firmware/pcm.c: In function ‘pcm_switch_sink’:
firmware/pcm.c:311:38: warning: array subscript 1 is above array bounds of ‘struct pcm_sink *[1]’ [-Warray-bounds]
  311 |     struct pcm_sink* old_sink = sinks[cur_sink];
      |                                 ~~~~~^~~~~~~~~~
firmware/pcm.c:79:25: note: while referencing ‘sinks’
   79 | static struct pcm_sink* sinks[PCM_SINK_NUM] = {
      |

PCM_SINK_NUM is 1, and cur_sink is initialized to 0.  It can never be set
above 0.  cur_sink can never be >= PCM_SINK_NUM, ie 0, but for some reason
the compiler thinks otherwise.... sometimes.

This only shows up on native ARM builds with GCC9.5.0

Change-Id: I1aa731a4ee21c46a264c8b70833e3b43e777e8a7
2026-04-17 21:56:38 -04:00
mojyack
9ffc8a00ce pcm_mixer: implement mixer_switch_sink
Change-Id: I1549470774f96a6f470817cbc5fe4611812de6fa
2026-04-17 20:54:10 -04:00
mojyack
be4b0591ee pcm: implement pcm_switch_sink
Change-Id: Iace01c2e97950cc794f3cf755dc358da6f3daa7f
2026-04-17 20:52:23 -04:00
Christian Soffke
cc7418dd8b dsp: add option to swap left and right channels
Change-Id: Id4b518638436576cfb5e747548f10ece6e58eba0
2026-04-16 21:08:53 -04:00
Roman Artiukhin
a496e01173 hiby: ability to add/remove input device
Required for dynamic inputs (like bluetooth).
Files are now opened with O_NONBLOCK, and inputs are automatically removed on poll errors.
Also added call to close all devices on power off.

Change-Id: I8991bdb881fdc00135d1fd5b01ac900c0b007aeb
2026-04-16 08:03:06 -04:00
Solomon Peachy
41893b250f ipod4g: Pull LCD framebuffer out of IRAM
The recent pcm_mixer changes caused us to overflow IRAM by a whopping 8
bytes.  This can _probably_ be mitigated with some clever reworking but
we were clearly already on the hairy edge.

Future pending changes are likely to increase IRAM pressure so even if
we solve this issue the odds are it will reappear at a future point.

(the ipod4g's framebuffer is 5KB.  This doesn't affect the mini2g as its
 framebuffer is under 4KB, and the ipodcolor doesn't put its framebuffer
 in IRAM at all)

Change-Id: I2f50d998e969a706cc9d3a0e057cf8e6c303c9b4
2026-04-14 10:27:20 -04:00
mojyack
498a9fffeb pcm_mixer: remove mixer_sampr
Change-Id: I693b3c2ab639f09e918790dd6a06977991f872cc
2026-04-14 07:43:35 -04:00
mojyack
e2040cc98c pcm_mixer: introduce mixer_buffer_cbs
intended to add sampr_changed callback to buffer hook as well as mixer
playback

Change-Id: I9df6194a884cfb813342a827b7fdc3bccbe3d60c
2026-04-14 06:50:39 -04:00
mojyack
cb04b8167c pcm_mixer: introduce mixer_play_cbs
the added sampr_changed callback can be used to notify the mixer user of
frequency changes

Change-Id: I309db76576090fd5c019a1ba082af446129dd4a3
2026-04-14 06:47:36 -04:00
mojyack
03060090c9 usb: arc: implement batched request api
Change-Id: I9d677286589a336d7258cf2c9d3c7d2847243dfa
2026-03-29 09:04:10 -04:00
mojyack
f84003fa40 usb: add fallback implementation of emulated batch api
some targets can process requests fast enough without dedicated
batch api implementation.
provide generic implementationn for such targets.

Change-Id: I152681441e70e0e98396274d9305d371d2bbfbe3
2026-03-29 09:03:56 -04:00
mojyack
d2b76a99f3 usb: introduce batched request api
in order to implement iap digital audio interface, we have to send
a pcm packet every usb frame i.e. 1000 packets per second.
this rate can't be achieved with current standard request-response design,
even with fast_completion_handler.
this is why this new api is needed.

Change-Id: Id3d7dd037660871e2bdb69656f63ff13280c3804
2026-03-29 09:03:29 -04:00
Solomon Peachy
3f4d5a527b bootloader: Don't compile sound.c in bootloader builds
(a) Nothing uses it, and (b) stuff it needs isn't built either

Change-Id: Ib8b46e00d4306f7d05b47883bfaa98497a075db5
2026-03-28 12:43:59 -04:00
Solomon Peachy
42ad3c75d2 Fix red in 36f34089d6
Can't reference settings in bootloader builds

Change-Id: I471c3ca61ec4c93d38317278b79b973192aa28bb
2026-03-28 12:41:43 -04:00
Solomon Peachy
36f34089d6 volume: Apply limits inside sound_set_volume()
This way all paths to setting the volume respect the limits, instead
of only callers of setvol(), which only applies to (some?) interactive
paths.

Change-Id: Ia8ece22aafcb04df33021071cb933eaeb1146502
2026-03-28 08:55:57 -04:00
Solomon Peachy
5ce96b84d8 pcm_mixer: Explicitly initialize the mixer frequency in the pcm init path
Change-Id: I5b79dbb0608ef182fd5592797c6211ce5299999c
2026-03-28 08:55:07 -04:00
Solomon Peachy
a84a38dd87 pcm: Fix up some compile warnings that show up under some sim builds
firmware/pcm_mixer.c:36:35: warning: conversion from ‘long unsigned int’ to ‘unsigned int’ changes value from ‘18446744073709551615’ to ‘4294967295’ [-Woverflow]
   36 | static unsigned int mixer_sampr = -1UL;
      |
firmware/pcm_mixer.c:269:21: warning: comparison is always false due to limited range of data type [-Wtype-limits]
  269 |     if (mixer_sampr == -1UL)
      |                     ^~

So drop the 'L' and everything is peachy.

Change-Id: I9440d3300931be229c6c4b01bdc1d09b55c34d88
2026-03-28 08:54:33 -04:00
Solomon Peachy
daef425c59 pcm_mixer: Get default sample rate from pcm layer.
Change-Id: I6eccb37556e70f23112bbb0e26f4a45ac0930245
2026-03-28 08:16:04 -04:00
Solomon Peachy
759ef2767a pcm: Make pcm_is_ready a per-sink property instead of a global.
All that matters is that the _current_ sink is ready, not all possible
sinks.  When switching sinks we will need to ensure tehy are initialized
before switching over.

Change-Id: I341f7e9dcb4e2add4d0b292b68b69eb08dec0194
2026-03-28 07:09:54 -04:00
Solomon Peachy
ae724ba5f3 as3525: PCM driver init references the sink directly
Change-Id: I42e8f04214790676d6f177669cdeda58fa8e8c28
2026-03-25 10:13:36 -04:00
Aidan MacDonald
da53cc0f14 echoplayer: pcm: increase SAI FIFO buffer depth
Change the SAI FIFO threshold so that it is always
kept topped up at maximum; DMA needs to do single
transfers to the peripheral now. Ignore FEIF errors
since they seem to occur constantly with this setup
(though it's not exactly clear why this happens).

FEIF only indicates that the SAI made a DMA request
while the DMA FIFO is empty, which isn't a fatal error.
The DMA channel will simply service the request when
it is ready.

Keeping the SAI FIFO constantly full increases the
overall timing margin before underrun so losing the
FEIF info isn't a big deal in practice.

Change-Id: I16eb1cbb17039db76938bd86c4921b8060c83556
2026-03-25 07:33:19 -04:00
Solomon Peachy
e923b354a6 FS#13836 - Remove the pcm sink_mutex to unbreak usb_dac mode
The purpose of the mutex is to make it possible to switch pcm sinks
safely, but pcm_play_lock/unlock and pcm_set_frequency need to be
called from IRQ context which is fundamentally incompatible with
our mutex implementation.

The proper path forward will be to promote the counter-based per-sink
lock/unlock implementation to the pcm core, and only allowing sink
switching when the counter is 0.

In the mean time, just remove sink_mutex entirely as the sink switching
code has yet to be committed.

Change-Id: I029459d7ec6ea47c6e2b8fce52d203129a282832
2026-03-21 08:06:20 -04:00
Aidan MacDonald
acd3a5f0ce echoplayer: implement ADC to read battery voltage
Change-Id: I8043e7d2f02c10cb8c9d9ec59b7d216945431481
2026-03-18 12:51:51 +00:00
Vencislav Atanasov
a77c5d2219 3ds: Various fixes, mostly for compiler warnings
- Move all devkitpro includes before the Rockbox ones so that the macros which are both conflicting and unused can be undef'd
- Remove unused result variables
- Exclude an unused function from being compiled for this target
- Fix hex number formatting
- Fix the return value of dummy functions
- Fix macro redefinition in the plugins keypad config
- Remove duplicate button mapping
- Turn off -Wchar-subscripts as it's already handled in Rockbox's ctype.h

Change-Id: I3f5a3d492c585f233277a380feaea5fe877a044f
2026-03-13 10:24:36 -04:00
Vencislav Atanasov
aa834e83aa 3ds: Fix crash on shutdown
It is required to call gfxExit() before exiting the app if gfxInit() was previously called. Otherwise, the GSP thread continues to run after the stack is invalidated. The missing code is already in lcd_shutdown(), but it was never called because HAVE_LCD_SHUTDOWN was not defined for the ctru target.

Change-Id: I8999df6372cd593c5b52478028ad7421b23d5f92
2026-03-11 22:26:44 +02:00
mojyack
e13befb925 pp5020: ata: do not yield in ata_wait_intrq()
Confirmed on iFlash-modded ipodvideo, USB mass storage connections
frequently fail with bus resets during mount on macOS, and trigger
"reset high-speed USB device" errors on Linux during sequential
reads.

The root cause is: storage_read_sectors() calls yield() via
ata_wait_intrq(), which switches to the main thread running
handle_usb_events() loop. This calls send_event(GUI_EVENT_ACTIONUPDATE),
triggering LCD redraw that takes approximately 110ms. This stalls the
ATA DMA completion, causing the USB bulk transfer to time out from the
host's perspective.

This commit removes the yield to prevent the reading thread from being
preempted by the lengthy LCD redraw during DMA completion.

This also improves sequential read throughput from ~13MB/s to ~18MB/s.

Change-Id: Ia552f97aa0169c93c4f21e250d13dc3a626661d4
2026-03-10 18:17:41 -04:00
Aidan MacDonald
9605b453da Fix yellow in c72ffa7a9a ("diacritic: Critical bugfixes")
Change-Id: Ie780cab7e9926165cab1e48319c6743e3b6accb1
2026-03-10 10:14:42 +00:00
Solomon Peachy
a2b754d829 unicode: Support diacritic marks > 0xffff (disabled for now)
* Terminating record of the max unicode codepoint (0x10ffff)
 * Add in Arabic diacritic marks in the 0x10efa..10efff range

This is currently disasbled due to it effectively doubling the
size of our diacritic table. The diacritics added are unlikely
to be seen in practice as they are used only in some formal
Quaranic contexts.  If we identify other diacritic marks above
0xffff, then we can turn this code on.

Change-Id: I50c2eace18c70be6fe7199fccab190e7da401089
2026-03-09 21:57:34 -04:00
Solomon Peachy
c72ffa7a9a diacritic: Critical bugfixes
* When the codepoint > 0xffff, don't overflow past the end
   of our diacritic table (Fixed by William Wilgus)
 * Truncation of the 'info' field causes the RTL flag to be dropped
   (RTL flag is b15 but we truncate it into an 8-bit variable)

Both bugs introduced in a2c10f6189 (September 2025)

Change-Id: Id5425606f2cf91d3b3a81f4b67a97d546de81e41
2026-03-09 21:52:37 -04:00
Aidan MacDonald
add06955a2 firmware: add copyright headers to core_alloc.c/h
These files have been missing copyright headers since
they were added in comit d0b72e2590 ("GSoC/Buflib:
Add buflib memory alocator to the core.").

Thomas Martitz seems to be the original author, which
is documented in the commit metadata and backed up by
emails from the rockbox-dev archive, for example [1].

[1]: https://www.rockbox.org/mail/archive/rockbox-dev-archive-2011-08/0000.shtml

Change-Id: Id1a3abd4975674ffbc6f7e9123ee57d49bcaa38e
2026-03-09 10:26:18 +00:00
Solomon Peachy
e8daf314be mrobe500: fix yellow in a24142b234
LCD_FUDGE is now defined in the cpu header, as it's needed for memory
layouts.

Change-Id: I3a91581286cb7765f8217da34c6c87c15e74b399
2026-03-06 16:24:13 -05:00
Aidan MacDonald
a24142b234 firmware: cleanup duplicated DM320 LCD memory defines
Move the rather large block of code that's been copied
in three separate linker scripts into the CPU header.

Change-Id: I9f38e4901fa4ff699f00d97064a9cdaf7cfd6aab
2026-03-06 15:55:35 -05:00
Aidan MacDonald
99dd797169 firmware: cleanup PortalPlayer NOCACHE_BASE defines
Move the definition of NOCACHE_BASE to the CPU headers
instead of having them copy-and-pasted in a few places.

Change-Id: Ibbab27a5a07906d46dbd4dd9065f2238bc885d6b
2026-03-06 14:15:29 -05:00
Solomon Peachy
408f155f53 build: fix red in 7eeb4e4302
STORAGE_WANTS_ALIGN needs to be ignored for simulator builds

Change-Id: I4d788f91d3d1ed81c0621b9adac985ca188d918c
2026-03-06 13:37:27 -05:00
Aidan MacDonald
7eeb4e4302 firmware: refactor CACHEALIGN_BITS/SIZE defines
Mostly motivated by PP needing CACHEALIGN_SIZE in linker
scripts, which can't include system.h, so move these to
cpu.h instead. Also gets rid of the default 32 byte line
size that was used if the target didn't define alignment
itself. RK24xx, DM320, and JZ4740 were missing this but
have been confirmed (from datasheets) to use 32-byte cache
lines.

Add checks to make sure the macros are appropriately
(un)defined based on the HAVE_CPU_CACHE_ALIGN define,
and make sure their values are consistent when they
are defined.

Disable HAVE_CPU_CACHE_ALIGN for hosted targets since it
arguably doesn't matter if there's a cache, if we aren't
responsible for cache maintenance.

A few files in rbcodec use CACHEALIGN_SIZE, but these
can be converted to MEM_ALIGN_SIZE, which is identical
to CACHEALIGN_SIZE if the latter is defined. On other
targets, it aligns to at least sizeof(intptr_t).

Change-Id: If8cf8f6ec327dc3732f4cd5022a858546b9e63d6
2026-03-06 14:49:00 +00:00
Aidan MacDonald
dbfedcd65e stm32h743: rename CPU header to match other platform conventions
Change-Id: Ie7564df983aed460947ebde3bf73f8147d5bc974
2026-03-06 14:01:38 +00:00
Aidan MacDonald
f44b6c78e0 misc: respect standard __ASSEMBLER__ define in CPU headers
The JZ47xx and S5L87xx processor families used their own
special defines (__ASSEMBLY__ and ASM respectively) in
their CPU headers to check if they were included from an
assembly source file.

For GCC the standard seems to be __ASSEMBLER__, so check
for that instead and remove the non-standard symbols.
Being more consistent across platforms makes it easier to
include cpu.h from cross-platform files (eg. plugin.lds).

Change-Id: I282930cad34e1a2ff18166f3b4338548b34f4a49
2026-03-05 21:13:50 +00:00
Aidan MacDonald
cf1e3fd5a3 misc: remove leftover pnx0101 support code
Remove now-unused stuff related to the PNX0101 processor,
which was missed during the removal of the IFP-7xx port.

Change-Id: I5ff248b3e83cb67a357743130c3e51ed84a720e5
2026-03-05 15:41:06 +00:00
Solomon Peachy
cef29a1986 fat: fsinfo structure references _clusters_ not sectors
These fields are defined by FAT32 itself, and are specified as 32-bit
values.  So switch them from sector_t to simple uint32_t.

Change-Id: I98afecfbe1f8a1b83fbdd4ec3fea016b8e0b985d
2026-03-04 13:10:46 -05:00
Aidan MacDonald
87f2024631 echoplayer: clock FMC from PLL1Q
Unlinking the FMC from the bus clock should make it
simpler to do CPU frequency scaling later on.

Change-Id: Ia87bbe3dd01ff25ea1520309680017b400471bfe
2026-03-04 10:23:23 -05:00
Aidan MacDonald
b155e2c35a echoplayer: modify LCD timings to disable PLL3 fractional mode
According to the datasheet, the PLL fractional mode is
apparently not supported in the medium VCO range.

The LCD isn't picky about front/back porch settings so
modify these to get a dot clock close to 6 MHz (within
~0.1% error).

Change-Id: I51647534db8c2b261391864db9262a0b04548e6d
2026-03-04 10:23:17 -05:00
Solomon Peachy
ea570c5728 pcm: Make more of the low-level PCM API private
* pcm_play_data
 * pcm_play_stop
 * pcm_play_stop_int
 * pcm_is_playing
 * pcm_set_frequency
 * pcm_get_frequency
 * pcm_apply_settings

Now, the only user of these functions are the mixer and recording layers
that provide a higher-level API to plugins and the main [playback]
application.

Outside of the PCM core, pcm_apply_settings() was only used immediately
following a call to mixer_set_frequency(), so the latter function
now always calls the former.

Change-Id: I61c3144dc156b9de9b7963160b525c6d10c6ad4b
2026-03-03 13:09:21 -05:00
Aidan MacDonald
84fa538979 echoplayer: add PCM debug menu
Display DMA error counters and the SAI underrun counter
in the debug menu.

Change-Id: I235bfcb0fa965d87c30deeb300535141eda5f974
2026-03-03 09:24:01 -05:00
Aidan MacDonald
5c1ae51193 echoplayer: implement audio playback
Playback is implemented using a target-specific PCM layer,
using the STM32H7 SAI & DMA registers directly. There are
a number of pop/click issues:

1. Slight click when powering up the amplifiers
2. Click when starting and stopping playback
3. Popping when changing playback frequency
4. Popping when shutting down

It should be possible to eliminate or at least mitigate
(2) to (4) in software, but (1) happens as a result of
powering on the amplifiers while everything is muted so
might be unavoidable.

Change-Id: I398b66596176fb2341beb7deba7bf6f4f3fb82b3
2026-03-03 09:23:23 -05:00
Aidan MacDonald
a1b7e7b134 sdmmc_host: mark tCardInfo initialized at end of card init
This is needed to display card info in the debug menu.

Change-Id: I2e45edd9a9e26834efac48cea892157588c546a7
2026-03-02 17:11:33 -05:00