Commit graph

12208 commits

Author SHA1 Message Date
mojyack
bbdada7690 usb: enable cpu boost for specific class drivers
add needs_cpu_boost field to usb_class_driver and manage boost state in
usb_core, similar to needs_exclusive_storage.

Change-Id: Ieb0cd7bedda5b24bb0d209d5ce907db30f4815db
2026-05-04 18:15:52 +09:00
mojyack
732f7bcfd9 usb: allow class drivers to return error from init_connection()
Change-Id: Idcd48dd00d9d2f06c49a347e02a41a5de7252431
2026-05-04 18:15:49 +09:00
mojyack
3c10b21c10 usb: hold class_driver instance in each driver
Change-Id: Ia2f857bffcc6c3cca4dee59791c48c628082595b
2026-05-03 15:18:51 -04:00
Solomon Peachy
82a0921399 build: Fix yellow in 6d387e2e7f when panic is not supported
Change-Id: I8b896ef05ca27b3abc05d5d6910d5f6b9741047c
2026-05-03 15:10:03 -04:00
mojyack
6d387e2e7f usb: allow class drivers to override max packet size
this is required to make hid endpoint of iap class driver work,
especially on ipodvideo(arc).
at least for arc, it is required to set mps as 64 instead of 512 on
highspeed, or some accessories ignore incoming hid reports.

Change-Id: I242060faced28a66204146a9c36ef10626d6d265
2026-05-03 14:59:15 -04:00
mojyack
fad99773e3 send iap status change notifications
install iap event notification callbacks in various locations

Change-Id: I637a3ad18cb07ca056ad9b678400ba11d2f8faad
2026-05-03 14:20:29 -04:00
mojyack
e50ad40814 usb: increase usb thread stack size
Change-Id: I07283a68056e095efba8019dac2aa37d65c0ef6c
2026-05-03 14:15:56 -04:00
mojyack
757e683506 usb: core: handle apple vendor usb request
Change-Id: Iab5135774353630e7bce4939f40ca35940e214f3
2026-05-03 13:03:42 -04:00
mojyack
3bb656625b usb: add usb iAP driver
add class driver source files.
also register iap audio sink.
usbstack/iap/libiap directory is imported from libiap.

Change-Id: I776c5caec33fe9efadc448e2e3b37d500bf19c9f
2026-05-03 12:40:54 -04:00
mojyack
2b9e4a8d70 config: define USB_ENABLE_IAP
iap is only enabled for idevices.
it will not work without apple vendor id anyway.

Change-Id: I1696dbc8a2304fc5eecc5432b4c52e25801c468e
2026-05-03 12:40:54 -04:00
Solomon Peachy
81fcb10f8f metadata: Normalize all metadata to Unicode NFC form
* Standalone database tool
 * Simulator builds
 * Target firmware (Hosted and Native, for all >2MB targets)

Change-Id: Ia7361affc2fc6a08e73c31ecc9ef3a4008c2415d
2026-05-03 07:07:07 -04:00
Aidan MacDonald
bafc796ce7 Fix errors from stdint.h removal (cf6fb81346)
Change-Id: Ie9457121448f47db14300e035dc5b5eccd086884
2026-05-02 23:22:03 +01:00
Aidan MacDonald
cf6fb81346 firmware: drop hand-rolled <stdint.h> from libc
Perhaps this was needed in the distant past, but these days
GCC provides a working <stdint.h> for freestanding targets.

Change-Id: I4f02f12058a13b6a086ccc52f02a12ce21a986c1
2026-05-02 22:33:12 +01:00
mojyack
472acce401 reggen.h: fix broken stm32 build with gcc-14
Change-Id: Ib504e6a75ac88be325adc6dd19c88bf263178f2d
2026-05-02 17:28:45 -04:00
Christian Soffke
88d4903d10 gui: fix "lock screens" making UI viewport disappear
Themes like Adwaitapod, Themify, or FreshOS have
custom "lock screens" that are drawn on top of the
UI viewport.

Request a full skin update when unlocked, so you don't
have to press a button to make the hidden UI viewport
appear again.

Change-Id: Idf5023b4e12f7aea1cd7a2e9d9ab2f754387dc48
2026-05-02 16:53:02 +02:00
Christian Soffke
83e55164f4 gui: remove SBS lock/unlock redraw lag
Stop the lock indicators on the SBS from lagging
behind their actual state when lock notifications
are disabled.

Request immediate skin update in button loop, so
the device doesn't feel laggy.

Change-Id: I42955f65d9ad4ca9196549d806538d1badb5f79d
2026-05-02 16:52:03 +02:00
Aidan MacDonald
80e3c0b065 mips: require 8-byte stack alignment
The o32 ABI requires at least 8-byte alignment. This fixes
the float formatting weirdness seen in quake (FS#13821).

Change-Id: I4b587946884d7b35cef420e607c7e127664849e2
2026-04-25 12:36:46 +01:00
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