Commit graph

11431 commits

Author SHA1 Message Date
Aidan MacDonald
2512ed1c56 Make inline functions in headers 'static inline'
Future-proofing against newer versions of GCC/binutils which
are stricter about the use of 'inline' functions in headers.

Change-Id: Id620812ed340f0d790ba6c5b8b5cb1d700acfbbf
2021-12-02 21:31:54 +00:00
Solomon Peachy
4162a46184 config: Get rid of an (incorrect) duplicate definition for USB_DESIGNWARE
Change-Id: I9778a1a7b5e2e15b3775dbaed719c64b4e52194b
2021-11-29 20:14:41 -05:00
Aidan MacDonald
98f1271aec x1000: Fix AIC I2S divider clamping with EXCLK source
Change-Id: I19c2d25bbd7276ac5efd6f6b3b9ee64d6801f972
2021-11-27 15:27:45 -05:00
Aidan MacDonald
9eaa14dc02 usb-designware: fix setup packet error handling
This handles the case where the host sends a new setup packet
in the middle of an ongoing control transfer.

Change-Id: I1d2e02467e9b813c9827cc0699cb87a500515e31
2021-11-27 09:29:44 -05:00
Aidan MacDonald
e4d8431211 Update microtar users to new library API
Change-Id: I8e74efb53b8a8c9a4d69b2a20024434e2868e4e0
2021-11-27 13:13:39 +00:00
Aidan MacDonald
44acbc6629 Shanling Q1: enable multi-touch reporting
The FT6x06 driver used for the Shanling Q1's touchscreen
has been extended to report more than one touch point. It
can also return the gesture detected by the controller,
but this doesn't seem to report anything useful on the Q1.

Multi-touch is only useful in 3x3 grid mode since the Rockbox
button API cannot report more than one touch point.

The FiiO M3K uses the same driver so it's been updated to the
multi-touch API, but functionality is unchanged.

Change-Id: I4de42f44808d6eb902e3da212d8f936b7a5042c7
2021-11-24 18:49:03 -05:00
Solomon Peachy
3d07ec46ee jz47x0: Minor code quality improvements in the jz47xx USB drivers
* Replace magic nubmers with #defined constant
 * Tweak some logf messages

No functional changes!

Change-Id: I6a5e4c371a471197a8edbb853967e461621d73f8
2021-11-22 08:08:12 -05:00
Aidan MacDonald
bff63a4f90 touchscreen: change odd sentinel value for time of last touch
Using tick 0xffff does not make any sense, use -1 instead.

Change-Id: Id574eb35418c6713c4fc91ed539aadc42fd29aa5
2021-11-21 20:26:20 +00:00
Aidan MacDonald
ad66c3b807 touchscreen: use repeat acceleration for button input
Touch devices have physical buttons too, and these should be
subject to repeat acceleration. That feature was disabled for
the sake of better touch event responsiveness (apparently).

So, re-enable the acceleration feature & add a special case
to exempt BUTTON_TOUCHSCREEN from acceleration.

Change-Id: I9e097e27457fbd6b824f098e8b325ff35c59dde4
2021-11-21 20:26:20 +00:00
Wolfram Sang
336ea51af6 WIP: Samsung YPR0/1: switch to generic SI47xx polling
Should work(tm). But I don't have the hardware, so it needs to be
tested.

Change-Id: Ic086434f570dcddacb5b7e7a1acce4b8cafc5c03
2021-11-18 16:53:57 -05:00
Wolfram Sang
de0346065b Sansa Clip+: add RDS support
Based on a patch by Amaury Pouly which was based on a patch from Ryan
Hitchman.

I mainly moved the code for polling into the tuner driver so it can be
reused by other targets. I added the CONFIG parameter for the polling
frequency (in ticks) to save energy. Also, I did some minor cleanups.

Change-Id: I95a62e7e1e42c62dbf47ecb27a3b312a42be62aa
2021-11-18 16:44:21 -05:00
Aidan MacDonald
701d4ba77e x1000: Merge makefiles used for the bootloader
All three X1000 native targets turned out to have a very
similar boot configuration and used a nearly identical
makefile. Eliminate this duplication by moving the logic
into the main makefile.

Change-Id: I13044b9675c0abd605b8accdb2fee4f54549b020
2021-11-18 14:14:54 -05:00
Aidan MacDonald
6e61e6f0c8 usb_core: don't buffer control request unnecessarily
Due to how the old control request API worked, the request
pointer (and the pointed-to contents) passed by the driver
must remain valid for the lifetime of the request.

The buffered copy wasn't used consistently anyway, so it
should be safe to just get rid of it.

(This only affects the old API compatibility layer.)

Change-Id: I00294c718a7515a91b84f7c7cae5220c73aa5960
2021-11-14 17:58:39 +00:00
Aidan MacDonald
f8810be6de usb_core: More legacy control API fixes
In the old API, usb_core_transfer_complete() would ignore
any completions on EP0. The legacy control API will also
ignore most completions on EP0, but it only did so after
filling in the completion event.

If the driver submits a spurious completion on EP0, then
this could clobber a previously queued completion event.

Fix this by deciding whether to ignore the completion
*before* modifying the event data.

Change-Id: I68526898a96efa594ada4e94bb6851aaaf12e92a
2021-11-13 18:37:33 +00:00
Dana Conrad
59ef877c94 x1000: delay power thread until valid battery read
Appears to return 0 until the axp has (presumably) completed
its first real measurement.

Note about erosq: keep the power_inint() delay large to ensure
nothing breaks in the bootloader for the time being.

Change-Id: I444e858207cc401c42f1e6ceacf067ad543d4ff8
2021-11-12 16:31:27 -05:00
Wolfram Sang
67fb558c89 as3525: debug: use 'kHz' where applicable instead of "MHz" or "KHz"
Change-Id: I84c24402d664b5a1a37c81aebfc438bd04bc8af4
2021-11-10 21:53:15 -05:00
Dana Conrad
9ee321cf90 ErosqNative: increase battery stabilization delay again
Hopefully 250 is long enough for any devices out there!

Change-Id: I80e084dceb62acd8d1f51d873b18a4be9c3447d8
2021-11-10 07:22:57 -05:00
Aidan MacDonald
7af98ce6bb usb: Fix possible SET ADDRESS data corruption
The address from the packet needs to be saved before sending
the response -- after the response the request being pointed
to could get overwritten. This used to be done correctly but
I unintentionally broke it when updating the handler to the
new control request API.

Change-Id: I9b11548baf20dce44a82301731405dc8e8f1cef3
2021-11-09 14:45:07 +00:00
William Wilgus
9f1cab154c lcd-16bit-common move bugfix to sim only
Ive seen no ill effects having this disabled on target so
limit it to the sim to stop Address Sanitizer from dumping
on the extra byte read. the bad data is never used AFAICT
since the loop ends

Change-Id: I8cb54e9d1f8fe28747867d861a015edb3dbfa5ff
2021-11-08 17:52:09 -05:00
Aidan MacDonald
8c954c68e5 usb: Attempt to fix race condition in compatibility layer
Because usb_core_legacy_control_request() is called by an
interrupt handler the global variables used to track the
current control request at the very least need to be volatile.

It might also be necessary to disable IRQs but I'm not sure
of that.

Change-Id: I0f0bb86d0ad63734e8d3c73cb1c52fedf5a98120
2021-11-08 21:46:36 +00:00
Solomon Peachy
5e663f0420 xduoox3ii: Ignore the remote events when headphones aren't plugged in
This prevents the actual insertion/removal from triggering false events

Change-Id: I54114ce903e110c31eca6b2ce258a0cf5f6b782b
2021-11-03 13:16:40 -04:00
William Wilgus
684565b8f3 USB fix red for device without HAVE_USB_POWER again.
Change-Id: I3122d532cbb8d5b5cb9040f08707c1514bc1b18e
2021-10-31 21:36:21 -04:00
William Wilgus
d72a0ed65d Use USB events for storing plugin_menu state
use usb connected callback to cancel menu reentry after USB plug/unplug

Change-Id: I8267deed6e8ada94ca527392f56f50ef22def1d7
2021-10-31 12:42:24 -04:00
William Wilgus
7a6737f471 USB Events fix red on devices without HAVE_USB_POWER
Change-Id: I112e6379d4bed019d7e047e5802f104e250d926e
2021-10-31 12:30:27 -04:00
William Wilgus
894a9d9063 USB add Insertion and Extraction callback events
We have this nice event library laying around probably a few more places
we could use event callbacks

Change-Id: I9180fa9d78788d161f2587110644ca3e08df6f50
2021-10-31 12:02:38 -04:00
Aidan MacDonald
0f68866ae5 fiiom3k: bump power on delay to 200ms
Needed due to a report that 80ms was not working.

Change-Id: I5f0f750b0530f5b84ffba58c5d7ff8b283095c4b
2021-10-18 23:03:04 +01:00
Aidan MacDonald
957add9d75 fiiom3k: adjust power on delay to 80ms
OST timer fix (7a5130a277) causes a boot failure on some units,
the battery voltage reading needs more time to stabilize.

Change-Id: Ic4a9ba90a16fab8ac6d27dbbe7af381f7c810f8f
2021-10-18 21:45:03 +01:00
Dana Conrad
6253cdebed ErosQNative: Fix mdelay calls due to g3859
The battery stabilization delay call seems to need to be
about 170 at minimum now, let's do 190 for safety (+20ms).

Change-Id: Ifd0248891abe827dfcc3e6baf48cc5bef0d0cc1c
2021-10-16 16:58:19 -04:00
Aidan MacDonald
7a5130a277 x1000: fix broken OST2 timer prescaler
It turns out the prescaler fields in OST_CTRL are 2 bits wide,
not 3. The programming manual (as usual) is ambiguous and its
diagram shows 2-bit wide fields, but the bit positions in the
text give a 3-bit wide field. Ingenic's Linux code and my own
testing shows that they are, in fact, 2 bits wide.

This caused the OST2 divisor to be 16 instead of 4; the OST1
divisor was correct. This means that all udelay/mdelay calls
took 4x longer than they should've. After this change the OST2
prescaler will be 4, as intended, and udelay/mdelay calls will
wait for the intended duration.

Change-Id: I2ac0a9190f49b59a840c649bf586131f5f9fde82
2021-10-16 16:58:19 -04:00
Aidan MacDonald
d085d01f5e x1000: enable DMA for USB driver
This boosts USB transfer performance a bit, ~10% for reads and
~25% for writes, for large-ish file transfers. Rockbox is still
around 33-50% slower than the OF.

Change-Id: I236a1e5c69a290c47ed27b70cb2631111fc157ed
2021-10-16 21:14:42 +01:00
Aidan MacDonald
4fc37eb47f usb-designware: port to new USB API
List of all platforms using this driver:

- Sansa Clip+ (tested, works)
- Sansa Clip v2 (untested)
- Sansa Clip Zip (tested, works)
- Sansa Fuze v2 (untested)
- iPod 6G (untested)
- iPod Nano 2G (untested)
- FiiO M3K (tested, works)
- Shanling Q1 (tested, works)
- Eros Q (tested, works)

Change-Id: I403ec64b030ea38f22cb52b31865639a78cd11e4
2021-10-16 21:14:42 +01:00
Aidan MacDonald
24294bda15 usb: ensure RX buffers are a multiple of the packet size
When performing an OUT transfer which is not a multiple of the
max packet size, the last packet of the OUT transfer should be
a short packet. However, there's no guarantee the host sends
the expected amount of data in the final packet.

The DWC2 USB controller handles this case by accepting any size
packet and copying it out to memory. So if the packet is bigger
than expected, it'll overrun the caller's buffer and Bad Things
will happen.

The USB 2.0 spec seems to endorse this behavior. Section 8.5.1
says "an ACK handshake indicates the endpoint has space for a
wMaxPacketSize data payload." So it is possible that other USB
controllers share the DWC2's behavior.

The simplest solution is to force all USB RX buffers to be big
enough to hold the transfer size, rounded up to a multiple of
the max packet size. For example, a transfer of 700 bytes would
require a 1024-byte buffer if the MPS = 512 bytes.

Change-Id: Ibb84d2b2d53aec8800a3a7c2449f7a17480acbcf
2021-10-16 21:14:42 +01:00
Aidan MacDonald
a665c1faad usb: remove dead code in usb_storage driver
Change-Id: Id6fc3520dad1adace33fd1014288ccb4cf5818af
2021-10-16 21:14:42 +01:00
Aidan MacDonald
988f244c74 usb: port usb_storage control request handling to new API
Change-Id: I1a19e09fdc0f05473d53c39bab0761d5cb8f6ff0
2021-10-16 21:14:42 +01:00
Aidan MacDonald
1b2cc053d3 usb: port usb_hid control request handling to new API
Change-Id: I9028cf06e91c9fcbe271f6ad81d6b252cb4e7cec
2021-10-16 21:14:42 +01:00
Aidan MacDonald
3318ba4795 usb: port usb_serial control requests handling to new API
Change-Id: I1405c9279e0e8e490e2bb2d03ff192b36db2634b
2021-10-16 21:14:42 +01:00
Aidan MacDonald
77731c3579 usb: port usb_core control request handling to new API
Change-Id: I3850c9cfcb87831e56884c83e31f728590b76f83
2021-10-16 21:14:42 +01:00
Aidan MacDonald
82efb1150e usb: implement new API with legacy emulation layer
All existing USB drivers now define USB_LEGACY_CONTROL_API to
enable the emulation layer.

Control request handlers will be ported in follow-up commits.

Change-Id: I4be1ce7c372f2f6fee5978a4858c841b72e77405
2021-10-16 21:14:42 +01:00
Aidan MacDonald
dff8320a5d usb: add request data argument to all control request handlers
Change-Id: I237143fa0d95c914b8e25ed22f8acde96ec00551
2021-10-16 21:14:42 +01:00
Aidan MacDonald
b69d43c247 usb: give USB transfer completion events two data pointers
Change-Id: I036cc7f02c2f86a364d2dba59493a6aa893f2c16
2021-10-16 21:14:42 +01:00
Aidan MacDonald
ec164c389c usb: introduce new control request API
Change-Id: I6545d8985ab683c026f28f6a7c0e23b40d0a6506
2021-10-16 15:58:43 -04:00
Dana Conrad
e0468074fe ErosQNative: Remove duplicate play_last_sample() call
My brain dun goofed, oops

Change-Id: Ifd57310f3ba105cdc37c4342691cbc589a492310
2021-10-06 17:36:53 -05:00
James Buren
c0a59b9a6a usbstack: Revise usb string descriptor table to use enum values for indices
This makes it possible for macros of conditionally included string
descriptors to get a correct index no matter what other usb drivers
are enabled or disabled due to the nature behavior of enums.

Change-Id: I8ccebbd316605bed0f5d90b6b73fab4a333c02fa
2021-10-06 17:59:17 -04:00
Aidan MacDonald
4be81c2385 x1000: tweak USB fifo sizes
The old sizes limited the number of usable endpoints and were
unnecessarily large.

Change-Id: Ia17d3b62ecc40c8ca289d78f2275c7842c09deed
2021-10-06 22:40:52 +01:00
Dana Conrad
67d4da5342 ErosQNative: Initialize AIC FIFO to -1
Write -1 to AIC_DR to initialize the "last sample"
to -1 in order to prevent power-on clicks.

It appears necessary to completely fill the FIFO,
otherwise I was able to get a click out of it, however
uncommon it was.

Not only does this prevent a click when first
playing a song after power-on, but it also seems to prevent
any click at all when powering on - previously, a small
click may have been heard when first booting.

Change-Id: I2b81c2fa6af9809ef1c354d7a08ca8f9893a7690
2021-10-06 17:31:30 -04:00
Aidan MacDonald
465c216636 Fix includes in usb_class_driver.h
Change-Id: I602ec80d02b5f4f586386026a6312d048fa7dac3
2021-10-06 21:31:42 +01:00
Aidan MacDonald
3ae6fbc600 x1000: default to sending 0 samples on underflow
Previously it used the last sample, which turns out to be broken.
The AIC appears to send out a random non-zero sample continously
after boot -- probably because the last sample is uninitialized by
the hardware. Disabling playback is supposed to make it send zero
samples irregardless of the LSMP bit according to the docs, but it
doesn't seem to work this way.

- Change eliminates the white noise heard on the M3K after boot.
- Change has no adverse effects on the Q1.
- Leave Eros Q on the old setting since sending zeros exacerbates
  clicking due to DAC's automute feature.

Change-Id: I9996793fc34f4475b19700d076b11505353b3836
2021-10-05 12:46:01 +01:00
Aidan MacDonald
fd568d90a4 m3k: don't use mixer controls for volume control
According to a forum user, there's an audible click when changing
the volume between -32 and -32.5 dB with some headphones. Fix this
by not (ab)using the DAC digital mixer for volume control.

The mixer only provides an extra -6 dB of hardware volume range,
so the only side effect is that software volume will now kick in
at -32 dB instead of -38 dB.

Change-Id: If24d9bc0058eff3c1a29aefb155a2e378522623c
2021-10-05 12:46:00 +01:00
William Wilgus
7c67a48332 Sansa E200v1 Bootloader attempt at enabling USB in boot loader
there is a 1MB free region that is used to load the firmware but we
shouldn't need that till after a USB connection

so here is my 2nd try

Change-Id: I2552db3a7fba019d7e7188984432f758ddafe548
2021-10-04 10:56:33 -04:00
Aidan MacDonald
75524a7eec Shanling Q1: default to USB force charging
Force charging must be set or the Q1 will not draw 500 mA from
an AC adapter (see 0ca0940f01).

Change-Id: I4ec6dc7728a5aa4d7f07580556efb960948c24a8
2021-10-02 16:14:17 +01:00
William Wilgus
a62fdf4751 scroll engine, allow clipped text in viewport
loosen the requirements on the scroll viewport allow clipped text

Change-Id: I7099d423ccfbd7bae12e6ba43b8a6b4b864175b7
2021-10-02 10:31:04 -04:00
Aidan MacDonald
3a89fdee96 x1000: fix hang that may occur in USB mode
Upon getting a USB reset, the USB core will update charging
current by calling usb_charging_maxcurrent_change(). On all
current X1000 targets this may cause a hang, since changing
the charge current involves a blocking I2C transaction.

Eg. if the host issues a reset when we're already configured
as part of error recovery, the change from 500 mA -> 100 mA
will cause a hang.

Change-Id: I5b45272c01fa16b179ae3d16bbc50c7fab9a416b
2021-10-02 15:09:46 +01:00
William Wilgus
95b10ac74e Add ability to dump cpu boost log to disk, include thread names
0.) B 0 /rockbox/apps/main.c:405
1.) B 1 /rockbox/firmware/kernel/thread.c thread[dircache]:1508
2.) B 2 /rockbox/apps/tagcache.c:4772
3.) U 3 /rockbox/apps/tagcache.c:4793

add logic to show count after log rolls over
clean-up

Change-Id: Ibda0a56e5d8d89aa8b7649f4f9fa64eb1ff0e08f
2021-09-30 21:13:22 -04:00
William Wilgus
b662ff945a Bugfix AS3525 usb driver unboosted the cpu without first boosting it
Change-Id: Id2d45870a9128b19ace0e8d5c16d3b3fa4b923dd
2021-09-29 01:17:45 -04:00
Dana Conrad
6d98c9e6b2 ErosQ Native: Adjust battery % scale
Adjust the battery scale to be a little better. I've set
the 100% (discharge) point to be where the battery sags to
when it is done charging but still plugged in.

Not quite sure how best to set the charge scale, it's just
equal to the discharge scale for now.

Change-Id: I9a2730c0b2051300af9eeddb4f67164f38a29002
2021-09-26 18:27:53 -04:00
Solomon Peachy
38b2648f48 win32: Add a stub for os_modtime() to make sim builds happy
Change-Id: Iea90776df2a92777c8e07c5a6b6635b6734d6690
2021-09-26 09:31:58 -04:00
Aidan MacDonald
672bbe434b usb: rename usb_drv_recv() to usb_recv_recv_nonblocking()
IMHO the current name is somewhat misleading:

- usb_drv_send() is blocking and we have usb_drv_send_nonblocking()
  for the non-blocking case. This inconsistent naming can only
  promote confusion. (And what would we call a blocking receive?)

- Other hardware abstraction APIs in Rockbox are usually blocking:
  storage, LCD, backlight, audio... in other words, blocking is the
  default expected behavior, with non-blocking calls being a rarity.

Change-Id: I05b41088d09eab582697674f4f06fdca0c8950af
2021-09-20 22:41:29 +01:00
Aidan MacDonald
99f333c64f usb_hid: fix accidental fallthrough
Successful SET REPORT requests would spuriously fail because of the
fall through to GET REPORT.

Change-Id: I8e7d1a1120afc6975d07d47b11c12c9e9ca51dd2
2021-09-20 17:38:56 -04:00
Dana Conrad
0ca0940f01 Make USB Charging default value configurable per device
A reasonable default assumption for a user
would be that they can plug their device into
a USB AC adapter and it will charge with as much
current as it reasonably can. With the previous
default, an AC adapter will only do 100mA, basically
a trickle charge.

Make this configurable default per-device, so as not
to break old devices without testing.

Define TARGET_USB_CHARGING_DEFAULT to USB_CHARGING_FORCE
to use the new default.

Tested on both erosQ Native and M3K.

Change-Id: I77265d356a41d67357ebc6e9f7e0c25a37b74931
2021-09-19 21:13:09 -04:00
James D. Smith
760277e096 Dir cache: Fix resume of relative path playlists.
Slightly modified from original patch by Fabrice Bellard.

Change-Id: I9ae04fa460f0f1b9c616e6f99505d4c5d4358f68
2021-09-19 21:05:58 -04:00
Christian Soffke
67c4231e34 iPod mini backlight initialization
Fixes backlight not turning on after booting (tested on an iPod Mini 2G).

backlight_hw_init() copied from iPod 4G.

Change-Id: I9c32ca5ecd3dc74ea997e6cb843da79d303b0615
2021-09-12 13:35:35 -04:00
Dana Conrad
17263a813b ErosQ (both): avoid clipping due to DC offset bandaid
Set the maximum volume on both hosted and native ports
to -2 dB.

Verified behavior here on native and by borkitall on irc
for hosted.

Change-Id: I3aebc2bb4b9294a4137a33694c83139c0d76099a
2021-09-05 15:50:21 +00:00
William Wilgus
cab8cea0f0 lcd_putsxyofs 16 bit lcd_mono_bitmap_part [AS] part duex
'Bugfix' mono_bitmap_part reads ahead in the buffer,
if the height is <= char bit pixels other memory gets read
found with [Address Sanitizer]

also g#3332 since this is clearly a problem across the code
instead place the check for height < 8 in the lcd_mono_bitmap_part function

second try places the check above the negative y offset
this was causing glitches on the Q1 and likely other TS targets
since a negative y was added to height it made it < CHAR_BIT setting
stride = 0 even though the bitmap was >= CHAR_BIT high

Change-Id: I13bb8ab472c2ae61302a6de5d9e2c78243354460
2021-08-26 20:19:26 +00:00
Solomon Peachy
b2386405b9 xduoox3: Disable bootloader USB mode entirely
It's not yet working and because all storage is removable (and the OF
works fine) it's of limited utility aynway.

Change-Id: I8a6a59ac16503d0f4574c3934f473cac54e86858
2021-08-26 11:59:01 -04:00
William Wilgus
dbd051394e Revert "lcd_putsxyofs 16 bit lcd_mono_bitmap_part [AS]"
This reverts commit 49edfc237b.

Reason for revert: font rendering bug, https://gist.github.com/amachronic/5fa75da280432127de4b44ee2d760281

Change-Id: I13b5f0eedb2926bce67051c8f0bb2ae5dea9f299
2021-08-25 13:05:02 +00:00
Aidan MacDonald
4cbb5b4201 x1000: trigger the virtual LED on disk activity
Change-Id: Ic129e79e0b192cb0c39e5f05ad602e0ea7a9213f
2021-08-18 23:17:07 +01:00
Aidan MacDonald
5a4cc8da3f Drop HAVE_RTC_RAM
Only Archos players ever used this feature and it isn't implemented
on any current targets.

Change-Id: I39c8455480a3fe33cd25b667e8d4d6ff3a092d3e
2021-08-15 20:41:58 +01:00
Solomon Peachy
cc6b036ef5 logf: Fix an incorrect fix in 835d0c737a
Change-Id: I060033d9a7cd54bab75e4f82e3de002bdb027af2
2021-08-15 09:03:16 -04:00
Solomon Peachy
25cebf2f85 Fix red from 04fe77a4
Change-Id: I13a7b067e60eabe27be1fe983a7cced3ae8b18e3
2021-08-14 17:56:15 -04:00
Solomon Peachy
04fe77a465 Remove the (very) incomplete port for the Tatung TPJ-1102
It was barely even a stub, and hasn't seen any development since 2009

Change-Id: I0aa15d9a7b90ae8c771924d9f401380d4cc0fab9
2021-08-14 16:29:39 -04:00
Aidan MacDonald
786d06742a Remove Samsung YP-Z5 port
It has only a couple GB of onboard flash storage with no storage
driver in Rockbox. It hasn't seen any meaningful development since
its initial commit, it's not on the build farm, and the bootloader
build is broken by other refactoring.

Change-Id: Idd9e3c46fac9b96f416ce444182f97a50770e747
2021-08-14 14:13:54 +01:00
William Wilgus
2df306923a file_internal.c guard file_cache_reset() from null pointer
I feel this is probably unlikely to be called with a NULL pointer
for cachep but being that we are already doing the check why not
guard file_cache_reset as well

Change-Id: I1a13767ef28a4129ae3513f7aa999fb6c1d6fad8
2021-08-13 06:32:44 -04:00
Dana Conrad
6de6e1459d Eros Q Hosted: Apply DC Bias to PCM Data
Similar to the native port, the hosted port benefits from
adding a -1 dc bias to the PCM data. This prevents almost
all clicking artifacts.

Change-Id: Ic6378716774b6d88df23c476e2ef54d49f33dc72
2021-08-12 10:07:49 +00:00
Dana Conrad
77a98ada12 Eros Q Native: Make Mute logic channel-independent
An oversight on my part meant that setting channel balance to
100% L or 100% R would mute both channels - this logic will
prevent that.

Change-Id: I912c2745784fbbbd7a773e1234179801f2ca4680
2021-08-10 18:15:53 -05:00
James Buren
e4c5b082e8 inflate: fix public function pointers
Change-Id: I7f1273b832a04a7d7c1b386c08c17438e3d93fc2
2021-08-09 16:25:43 +00:00
William Wilgus
275c762bb2 As3525 wavpack_enc document some intentional switch fall through
Change-Id: I56bf439df2c05653d65f49238e886e4ef2291176
2021-08-08 09:27:27 -04:00
Solomon Peachy
39fff5cb53 move PCM_NATIVE_BITDEPTH definiton into global config code
Change-Id: I391bcffca670916c2c88426e2ba2603351326cee
2021-08-07 11:18:19 -04:00
Dana Conrad
a2bbd1a549 Fix warnings from 56b0dde545
Need a default bit depth in pcm-x1000.c

Change-Id: I2c6af227975d2f47609b51090638012d8406ec1e
2021-08-07 09:43:17 -05:00
Dana Conrad
56b0dde545 Higher bitdepth software volume scaling
Operates between 0 and -74 dB (mute) without issue

Change-Id: I497e002bd8db43833a09ebbc29212fbb6cc8ebfd
2021-08-07 14:21:47 +00:00
Dana Conrad
16b0098256 ErosQ Native: Add DC Offset to PCM data
A small negative offset seems to silence all
play/pause clicking on the PCM5102A.

Also adding PCM soft muting, and muting the headphone amp
when the headphones are detected as removed. This has been
tested to not cause any unintended side effects on the
line out.

Also confirmed the numerical dB values are (approx.) correct.

Change-Id: I689d68887c86add9cc5e0ccb0c7de01aaa69b4d9
2021-08-07 14:21:47 +00:00
James Buren
60933d98c6 inflate: import initial module for deflate decompression
This will eventually be used by the ZIP module and other things
that support DEFLATE based streams.

Change-Id: I4acc9561eb56c9c368d1defab9c14e0454d105e1
2021-08-07 03:03:27 +00:00
Aidan MacDonald
1a9a5fc279 Fix wrong printf format in system-hosted.c
Change-Id: I73722f0711a295152a98ab784cd6cf76379ef52e
2021-08-06 18:23:17 +00:00
Aidan MacDonald
b8b195a296 Fix hosted glibc backtrace
According to backtrace(3) man page, the string returned from
backtrace_symbols() contains the return address so we shouldn't
need to print it ourselves.

Change-Id: Ia779207285c9ea0052b9aee3d84ee8380bf46d82
2021-08-06 18:54:34 +01:00
Aidan MacDonald
34fcea0b20 Fix path buffer overflow in screendump
Overflow is due to a hidden assumption in create_datetime_filename()
and create_numbered_filename() where buffer must be >= MAX_PATH bytes.

Change-Id: I9d36517d861b6925352380d551afc5439edbb340
2021-08-06 15:46:53 +00:00
Solomon Peachy
835d0c737a logf: Fix two issues with logf_panic_dump()
* It had a (read) buffer overflow when dumping the stuff on the back half of the buffer
 * a highly questionable code construct was nuked

Change-Id: I7f6f119524fc2095f788fc9b3d356459955d3ace
2021-08-06 10:08:00 -04:00
Solomon Peachy
f3010c6a8e hosted: Fix rtc_write_datetime() error handling
(if mktime() fails, don't attempt to write its result to the RTC)

Change-Id: Ib09b8dccafdef032119db76f10af74dfc220cc21
2021-08-05 13:44:11 +00:00
William Wilgus
cb6b0d2c0e disk.c ensure a valid volume is returned from get_free_volume()
volume is used for element math and indexing into buffers
-1  volume is bad

Change-Id: I1ec75ef3a848c154ea80905224ea9a3a14bf8151
2021-08-05 11:01:29 +00:00
Aidan MacDonald
005c414e5f Document intentional fallthroughs + fix harmless unintended ones
Change-Id: I1ca5b1027ec30cbf61093bab35b980196ed14e6b
2021-08-04 18:59:46 +00:00
Solomon Peachy
37bfcab23f powermgmt: Clean up some convoluted #ifdefs
Makes it more explicit what code is used under which circumstances.

Change-Id: I0a482dd48e1eb4b119ca6d8dca2b8aa450445fd1
2021-08-04 09:39:37 -04:00
Dana Conrad
a2fd00cf38 Software Volume: Remove sample rounding
Change-Id: I630139333d64b4c8cae86939ecfc52c44a34ffea
2021-08-01 02:20:00 +00:00
James Buren
fad4c75163 crc32/adler32: add full copyright notice to source files
Change-Id: Ifa04be9a6e419772c18b21e81fe1f246f4248af7
2021-07-31 01:30:39 +00:00
James Buren
f32fc84ef6 adler32: import adapted implementation from tinf/zlib
This adds an adapted version of the adler32 algorithm from tinf/zlib
which will be necessary to support ZLIB deflate streams in the future.

Change-Id: Ie60e15acb288acf56a2d44e3d3e912e1b3eb2216
2021-07-30 23:11:49 +00:00
Solomon Peachy
7318d393ea libc: atoi() is supposed to return 0 if handed a NULL pointer
Change-Id: I2d77532536ca83e5c9c2d7622a0e672082969f75
2021-07-30 01:41:13 +00:00
Aidan MacDonald
05d4d6a4f2 Fix remaining yellow from e532714d1f
Change-Id: If0bdd1fb3c8ee3324562638bc4c4181357a8fd53
2021-07-25 14:36:47 +00:00
Aidan MacDonald
148fac6f34 Fix yellow from e532714d1f
Change-Id: I4f49e93fc1efa78874fb76de6a436ad1fc894cc5
2021-07-25 15:22:33 +01:00
Aidan MacDonald
e532714d1f pcm: Remove unused function pcm_play_dma_get_peak_buffer()
Change-Id: Ifd20fb14a22489cdb99154c01f69809a1e70d0c5
2021-07-25 14:07:41 +00:00
Solomon Peachy
cb92280eca usb_storage: Fix a memset in SCSI_INQUIRY that overflowed its buffer
The funny thing is that the memset() for the field in question was
redundant, as the overall inquiry structure was memset(0) already.

Change-Id: I8bec0c93c9317823ff39cf7133535e3bf58fb987
2021-07-23 00:26:35 +00:00
William Wilgus
b91ad60d63 timefuncs.c valid_time() should return false if tm == NULL and not try to deref
luckily no one has
yet..

Change-Id: I4117db84b013fa826958aea635daa0a24ee534b6
2021-07-20 23:25:31 +00:00
Aidan MacDonald
07a3f6bcdb add Eros Q native simulator build
Change-Id: Ifdc882d19020da2e18234d6276409ad3e7efa138
2021-07-18 13:51:30 +01:00
Dana Conrad
3e7a09cb0d New Port: Eros Q Native
What works:
- LCD: 16-bit RGB565
- all buttons, including scrollwheel
- SD Card
- Battery level and charging/not charging status
- USB
- audio
- sample rate switching
- HP / LO detect, with "safe" fixed LO volume -
   LO volume will only be put to user-defined max volume
   if headphones are not present.
- rtc
- Plugins build, tried a couple and they seem OK
- Bootloader, installable to nand via usbboot

What doesn't work:
- Dual Boot
- power on/off has intermittent, low volume audio click
   (sometimes it's completely silent, sometimes there's
    a click)
- Audio uses 16-bit volume scaling, so clicking/popping
   is pretty bad at lower volumes - need 32 bit volume
   scaling, 24 bit I2S data
- USB HID keys not yet defined
- no jztool support

Unknowns:
- Stereo Switch pins: Direction select, AC_DC
   (probably not even hooked up)
- What is the actual purpose of the Stereo Swtich?
- How does the bluetooth module connect?

"Someday" stuff:
- get LCD working at higher bit depth
- Bluetooth

Change-Id: I70dda8fc092c6e3f4352f2245e4164193f803c33
2021-07-18 12:14:35 +00:00
James Buren
64a24591ae crc32: add fast variant of regular crc_32r function
This relies on a macro, CRC32R_FAST, to select which version to
compile with. In tests the fast version is 2x faster at the expense
of requiring 960 more bytes for the lookup table. For now the default
is the space optimized version but in the future I would like to enable
this for ports where we can afford the extra storage and/or memory
requirements.

Change-Id: I25397dadedc3187bb02b2444f8b8ded77c2509b6
2021-07-18 05:17:31 +00:00
Solomon Peachy
cd17decd5a xduoox3ii: Add "Super Slow" filter roll-off
I'm not happy with the proliferation of filter-roll-off options
but I don't have a less ugly solution.

Change-Id: I740fca006fa0c3443a467acfea55b6574d48346b
2021-07-17 08:18:31 -04:00
Aidan MacDonald
4c60bc9e68 New port: Shanling Q1 native
- Audio playback works
- Touchscreen and buttons work
- Bootloader works and is capable of dual boot
- Plugins are working
- Cabbiev2 theme has been ported
- Stable for general usage

Thanks to Marc Aarts for porting Cabbiev2 and plugin bitmaps.

There's a few minor known issues:

- Bootloader must be installed manually using 'usbboot' as there is
  no support in jztool yet.

- Keymaps may be lacking, need further testing and feedback.

- Some plugins may not be fully adapted to the screen size and could
  benefit from further tweaking.

- LCD shows abnormal effects under some circumstances: for example,
  after viewing a mostly black screen an afterimage appears briefly
  when going back to a brightly-lit screen. Sudden power-off without
  proper shutdown of the backlight causes a "dissolving" effect.

- CW2015 battery reporting driver is buggy, and disabled for now.
  Battery reporting is currently voltage-based using the AXP192.

Change-Id: I635e83f02a880192c5a82cb0861ad3a61c137c3a
2021-07-13 22:01:33 +01:00
Aidan MacDonald
3abb7c5dd5 x1000: revamp MSC driver card detection logic
Debounce logic now handles both removal and insertion and verifies
the detection is stable for 100ms before taking any action.

This solves the bootloader "file not found" issue on the Shanling Q1.
It seems a false removal event was generated, causing the filesystem
to be automatically unmounted. Probably this is due to some transient
noise at boot. Delays didn't solve the problem, probably because the
bogus hotplug event was queued, and normal mdelay() would simply delay
event delivery.

Change-Id: I8b03fb3550309f5a7ab4be0be7465a3dab2d3450
2021-07-13 22:01:17 +01:00
James Buren
3c4fdf10e2 crc32: add fast variant of regular crc_32 function
This relies on a macro, CRC32_FAST, to select which version to compile
with. In tests the fast version is 2x faster at the expense of requiring
960 more bytes for the lookup table. For now the default is the speed
optimized version but in the future I would like to enable this for ports
where we can afford the extra storage and/or memory requirements.

Change-Id: I8c7fde6b6ff130f0fdc7c8e472825e25bcdba022
2021-07-13 04:41:32 +00:00
Aidan MacDonald
84362141a0 x1000: Unified flash bootloader installer
Change-Id: Ib1d41d4e7d663ff8a21eb08108c13568f7408533
2021-07-11 15:39:50 +01:00
James Buren
1298e47134 zip: include strlcpy.h
Change-Id: Ic26a95e35a005837cbd3c8d9318d2cced9b726ff
2021-07-11 13:17:54 +00:00
James Buren
fa743258ea filesystem: implement os_modtime for unix
Change-Id: If030d526f29aa786b5a37402413d804752286cf5
2021-07-11 12:40:08 +00:00
James Buren
8846e087c0 zip: implement zip extraction support
This adds code sufficient to extract files to available storage given a
suitable root directory to extract to. It works on an already open zip
handle and also supports chain-loading a secondary callback in the event
that integration into the process is desired.

Change-Id: Id200d8f20d84a0cbd22906470de8bbd21d4525ef
2021-07-11 05:14:20 +00:00
James Buren
a1bcca645b zip: rename modts field to mtime
This brings it more in line with other structs with this exact same data
type and usage.

Change-Id: I5fe8564750ef28ccd0b12efedca2e6958369f712
2021-07-10 13:44:03 +00:00
Tomasz Moń
6c084ac3ea
Sansa Connect: Ensure LCD starts before backlight
Extra delay prevents white flash after hold switch release.

Change-Id: Ib0d33937dcbb738b913388e7df92ffdf9346c9f9
2021-07-10 13:20:29 +02:00
Tomasz Moń
b4ecd612f7
Sansa Connect: Use deviceid in USB Serial Number
Atmel AT88SC6416C CryptoMemory is almost I2C compatible. The device
is connected to bitbanged I2C bus shared with compliant I2C devices.

Change-Id: Iec54702db1bdfb93c01291eef18ec60391c63b16
2021-07-10 08:56:32 +02:00
Tomasz Moń
8de163b8ae
Sansa Connect: Fix reported CPU frequency
Make frequency related comments accurate. Disable UART0 clock.

Change-Id: I224a3d6656ad53165dcff68ed716fa2c6863240d
2021-07-09 14:16:05 +02:00
Tomasz Moń
60e2cd6de9 DM320: Regorganize LCD and TTB memory layout
Do not introduce any change for M:Robe 500 as it uses the two LCD frames
in non-obvious way.

Sansa Connect and Creative ZVM use only single front framebuffer.
Place TTB at DRAM end to minimize memory loss due to alignment.
Reserve as little as possible memory for the LCD frames.
On Sansa Connect this change extends audio buffer by 858 KiB.

Change-Id: I21bdeec4cfba86d71803a39acd651a87e73767e6
2021-07-09 09:24:38 +00:00
James Buren
a9f36efa62 file/fat: rework utime function as modtime extension
This eliminates the dependence on a special struct since we were only
using the modtime anyway. But it no longer fits any known standard APIs
so I have converted it to our own extension instead. This can still be
adapted to existing hosted APIs if the need arises.

Change-Id: Ic8800698ddfd3a1a48b7cf921c0d0f865302d034
2021-07-08 17:47:51 +00:00
Solomon Peachy
a0f1236e88 Fix yellow in android builds.
Change-Id: Ic22908e249f2db85c029e1644c9531a12ed87993
2021-07-08 13:06:41 -04:00
Aidan MacDonald
0e1a90ea1d x1000: SPL refactoring
This streamlines the boot code a bit and reduces target specific
boilerplate. The clock init hack used by the bootloader has been
"standardized" and works for the main Rockbox binary now, so you
can boot rockbox.bin over USB without special hacks.

Change-Id: I7c1fac37df5a45873583ce6818eaedb9f71a782b
2021-07-08 16:01:38 +00:00
Aidan MacDonald
65aa9ce570 x1000: more CPM register definitions
Change-Id: Ie6fa343a65a6bd19e578664b10bac771289ed0b3
2021-07-08 16:01:38 +00:00
Solomon Peachy
39b82afb45 Fix warnings introduced in c174d3a5 (redux)
Change-Id: Icc871bd9875aa0d092a4fba3e8a6c3a598053854
2021-07-08 14:16:25 +00:00
Solomon Peachy
78eb87f453 Revert "Hosted & tool builds need utime.h"
This reverts commit a8fd590003.

Reason for revert: Inverted polarity and it didn't work anyway.

Change-Id: Ife548ce4608405e3243c84a1d72090603fd2decc
2021-07-08 14:07:58 +00:00
Solomon Peachy
a8fd590003 Hosted & tool builds need utime.h
Should fix the warnings introduced in c174d3a5

Change-Id: Ib4bd863caef4dedf28dadab8b58b9a165ed4ef9b
2021-07-08 13:55:12 +00:00
James Buren
c174d3a544 file/fat: add utime function
This emulates the traditional utime function from UNIX clones to allow
for manual updates of the modification timestamp on files and directories.

This should only prove useful for non-native targets as those usually
have a libc version of utime.

Change-Id: Iea8a1d328e78b92c400d3354ee80689c7cf53af8
2021-07-08 13:15:30 +00:00
James Buren
49ca4b3e5e timefuncs: add dostime_localtime function
This does the opposite of dostime_mktime, converting time_t back to
the two dos date time values. We use gmtime_r for native because that
is what is available and acts the same as localtime_r on other platforms
with a regular libc available.

Change-Id: If79469d0aae2d7c5dcdd905fbf04963669aa1138
2021-07-07 17:31:00 +00:00
Tomasz Moń
bce6771730
Sansa Connect: Reduce USB RX buffers from 129 to 2
Reducing number of fake RX buffers saves a bit more than 127 KiB RAM.
Fix compilation with CPPI logging enabled.

Change-Id: If1ad3a6fc251e284caaac78c2406a58f3d6547bb
2021-07-07 18:48:24 +02:00
Tomasz Moń
99bf506407 Sansa Connect: Prevent unresponsive interface
AVR interrupt signal can remain active if the state has changed during
state read. In such case, there won't be intterupt and the interface
would appear unresponsive until AVR thread received event (e.g. USB
connection/disconnect). Solve the issue by not waiting for event if AVR
interrupt signal is active prior to event wait.

Change-Id: I86e388c7cd6da76e3abe7bf7114940f331e4c308
2021-07-07 14:51:15 +00:00
Solomon Peachy
e9ae1e9a8b Fix red introduced in 841e704fc3
Change-Id: I5a924f77231a4764f3ad9b196875f5bf073945d6
2021-07-07 13:49:24 +00:00
Tomasz Moń
841e704fc3
Sansa Connect: Read HDQ battery data
Make it possible for target to provide voltage, percentage and time to
empty values. The voltage measurement is nice to have in debug menu even
if the actions are taken only based on percentage. Perform battery level
estimation based on voltage only if percentage is not available.

Use time to empty based on actual power consumption. This makes the
estimated runtime displayed in Rockbox Info to react to backlight
setting. The bq27000 updates time to empty estimate every 5.12 seconds
so it is possible to see the estimate with backlight off on the screen
if user enters Rockbox Info, activates hold switch, waits 11 seconds and
releases the hold switch.

Change-Id: Iafe3fa0fb334e3428e3a0ad05b2c020d208dc934
2021-07-07 08:24:01 +02:00
James Buren
b87e75f768 zip: import initial module
This provides rudimentary support for parsing the contents of a ZIP
file. For now this just supports uncompressed file entries but DEFLATE
support is planned. This also only implements a low level public API
so more work will be needed to make it usable by application code.

Change-Id: Ia68b3078e5276666a0e5023f4bc7a9f94272738a
2021-07-05 19:30:05 +00:00
Tomasz Moń
2acf8db3e1
Sansa Connect: Power off LCD to save power
Prevent startup screen flash by properly using AVR LCM functions. Power
off LCD when not needed to improve battery runtime.

Change-Id: I76e3c5c0208774f189fbc6f7d7b3c9e22c062285
2021-07-05 15:19:52 +02:00
Tomasz Moń
89d3ca77b6
Sansa Connect: Fix power off panic screen
Queue power off requests because power_off() can be called within tick
context that must not acquire mutex.

Change-Id: I6f1a8f81d15518876cd03556118fc9eb37b8175f
2021-07-04 13:08:42 +02:00
Tomasz Moń
e11fa5f74e Sansa Connect: Initial libertas WiFi driver port
Import non-free firmware image from linux-firmware package.

Firmware loading works but is disabled at compile time because just
loading firmware without configuring device results in higher power
consumption without any benefit to end user.

Change-Id: I8fd252c49385ede1ea4e0f9b1e29adeb331ab8ae
2021-07-04 07:41:44 +00:00
James Buren
c9f2308a1d fat: move fattime_mktime to timefuncs
This moves the time conversion function to timefuncs since it has
uses on ports that don't use the FAT driver. This function has no
dependency on the FAT driver as it is so this should not cause any
issues. To reflect this separation the function was renamed to
dostime_mktime since it is really for DOS timestamps. The places
where it was used have also been updated.

Change-Id: Id98b1448d5c6fcda286846e1d2c736db682bfb52
2021-07-03 00:19:58 +00:00
Aidan MacDonald
9f950d8bbf x1000: NAND rewrite
This new design saves on binary size and stack usage. The API is
also block- and page-based, requiring awareness of the chip layout
to use properly. Out-of-band areas are also exposed for reading
and writing.

The byte-oriented routines are kept for compatibility with the
existing installer and SPL.

Change-Id: Iaacc694d2f651ab74d45330e0434ee778a0d91bc
2021-06-27 19:09:03 +01:00
Tomasz Moń
3c7c71030f
Sansa Connect: Ensure adequate AVR Slave Select delay
Waiting 10 us between selecting slave and transmitting data on SPI
resolves spurious startup glitches.

Cache last read monotime value as it can differ from the first one.

Change-Id: Ia6ac5696f6ee2bc3c6a8be27e33aaddd9ff4ce2a
2021-06-27 13:32:20 +02:00
Tomasz Moń
1b81bd8a61
Sansa Connect: Discard invalid monotime reads
Read monotime twice in a row and only accept the value if it matches or
the two reads are 1 second apart.

Change-Id: Ibd289103a20404dd1b2bbd131fdfa8905852c788
2021-06-27 13:14:11 +02:00
Tomasz Moń
a4ab636423
Sansa Connect: More reliable AVR communication
AVR requires bigger delays between retries. Read state instead of
version for synchronization purposes as it shifts more bytes.

Change-Id: Ib7fa980496d3bc7744a086b45e1865861ef58b88
2021-06-27 12:20:56 +02:00
Tomasz Moń
ead4bc0769
Sansa Connect: Retry AVR commands only 3 times
If the commands repeatedly fail it is likely that the AVR is not
programmed. In such case simply continue normal operation. This is
especially important in bootloader as it makes it possible to load new
rockbox build using bootloader USB mode. Otherwise, the only recovery
option would be to use I2C serial.

Change-Id: I4b0999833e9a906ec6353bdfdd5b68211f07ac81
2021-06-25 18:30:11 +02:00
Tomasz Moń
3738510953
Sansa Connect: Implement RTC functionality
Use 32-bit monotime AVR counter for time tracking. Set the time by
adding fixed offset to the counter value. Store the offset in rockbox
directory to make it persistent between reboots.

Do not implement alarm functionality as wakeup is only possible from
sleep and not from complete power off.

Change-Id: I615c7eb4df8ab0619dcbfcff107bc7051a15aace
2021-06-25 16:12:06 +02:00
Tomasz Moń
635ec5bbbd Sansa Connect: Manually drive SPI Slave Select
Keep Slave Select active during command transmission. This relaxes
timing requirements on the AVR side.

Change-Id: Ia1a6cf45aba3c11f6aeaa7441c6793807ca827f0
2021-06-25 14:10:15 +00:00
Tomasz Moń
b5c40d9991
Sansa Connect: Refactor AVR command handling
Add defines for all commands handled by AVR, including the unknown
opcodes (0xC5, 0xD3, 0xD4, 0xD5, 0xD6).

Properly synchronize with AVR and keep repeating command until it looks
like AVR has accepted it.

Change-Id: I3d42e973f135e33092c71c9887421906a900ab58
2021-06-22 19:18:17 +02:00
James Buren
581081a3df mi4: replace chksum_crc32 with crc_32r
This uses an equivalent algorithm but with a different initial value
than we normally use (all bits off vs all bits on). Use the new crc_32r
to replace the original MI4 crc32 implementation.

This frees up some extra space on mi4 targets which gives us more
room on a few very space constrained targets (sansa c200/e200, etc).

Change-Id: Iaaac3ae353b30566156b1404cbf31ca32926203d
2021-06-21 09:36:54 +00:00
James Buren
fc92081080 rockbox: add a crc32 reverse polynomial function
This uses the reverse of the polynomial used by the current crc_32
function. The code for this was derived from the implementation used
by tinf. This version is space optimized and should be a good way to
reduce code duplication in other parts of rockbox that use the same
crc32 algorithm. This is mainly of use in areas where DEFLATE is in
use.

Change-Id: I918da5b4ea4dc441c0e7e6b5007abcc2da463bcb
2021-06-21 03:37:17 +00:00
Tomasz Moń
2ca5774cf9 Sansa Connect: Indicate charging status
Consider battery level down to 0 as safe as OF continues to operate
normally even when at level 0.

Change-Id: Ie3889e5662b9fa6588e20ad02d8953f29e28800c
2021-06-20 10:33:46 +00:00
Aidan MacDonald
a3f2b64a46 Enable float formatting in printf
Needed for g#3415, and if the comment is to be believed, this needed
updating for recent MIPS targets anyway.

Just blanket enable everything for all targets with >= 8 MiB of RAM.
The only targets with less than this are the Sansa Clip, c200v2, and
m200v4, which all have 2 MB of RAM.

The added code size is around 4 KiB to 7 KiB, depending on the target.

Change-Id: I5773482a13543dabb1f93f713a21f1382a9c5a22
2021-06-16 19:49:55 +00:00
Tomasz Moń
f6c7407cc3 DM320: Use SD/MMC data done interrupt
Wait on semaphore until DMA finishes instead of busy waiting. This
allows the CPU to be used by other tasks during transfers.

Increase peripheral clock frequency, divide AHB by 2 instead of 3.
Function clock frequency is AHB divided by MMC divider + 1.

Change-Id: Ic890634da7e3541962ea3501eae8fa2ca2db606a
2021-06-15 07:31:29 +00:00
Aidan MacDonald
95408f2117 FiiO M3K: Add dual boot support
Change-Id: Ic34d50855b317b5f4073b232dbf458edf82f55e1
2021-06-14 20:45:14 +01:00
Aidan MacDonald
89f4064743 x1000: Extend CPM registers for dual boot
Change-Id: I283834a653506fd95ff8b56897e5f3afaf375cf5
2021-06-14 20:45:14 +01:00
Aidan MacDonald
2d6ddd0c5b x1000: NAND driver bugfixes
- Missing mutex unlock in nand_open()
- SET_FEATURE command incorrectly issued as a read operation
- Inverted protection bits, not sure how that happened...
- Block erase skipped ahead by a wrong amount, causing erases
  spanning multiple blocks to erase the wrong blocks

This code was buggy as hell... it's in need of a major overhaul.
It's not very flexible or reliable, and access to the flash is
useful during development of a new port, even if not useful once
the port is complete.

Change-Id: Ib85ee7453beab9657e3d19798ebaa09174b3649e
2021-06-14 20:45:14 +01:00
Tomasz Moń
02c4ec294c Sansa Connect: Properly setup internal speaker
Switch to internal speaker when headphones are disconnected.

Change-Id: I7c04ac139ad540d85f960e9dadc2faaf4f856055
2021-06-14 12:48:16 +00:00
Tomasz Moń
f3f9d1fb95 USB Serial: Implement Abstract Control Management
On devices that can assign interrupt IN, bulk IN and bulk OUT endpoints
this change results in the serial interface working out of the box on
Linux and Windows. On Linux it is registered as ttyACM device and on
Windows it is assigned a COM port number.

On devices that cannot assign the interrupt IN this change won't have
any effect.

Implement minimum required interface control requests. Respond with
whatever line coding was set to make terminal programs happy.

Change-Id: Id7d3899d8546e45d7cb4ecc3fe464908cb59e810
2021-06-12 14:47:15 +00:00
Tomasz Moń
663d846cf3 Sansa Connect: Disable endpoint double buffering
Disabling double buffering results in expected CPPI TX behaviour. With
the double buffering enabled, sending single ZLP resulted in two ZLPs
being available. The two ZLPs is problematic because this causes Windows
to reset USB device after failed SCSI command.

The problematic sequence on Windows 10 was as follows:
  * Host sends SCSI Mode Sense(6) Informational Exceptions Control(0x1C)
  * Device sends ZLP
  * Device sends command failed response

With endpoint double buffering enabled the ZLP was read twice by host.
As host was expecting command response on the second read (and got ZLP
instead), host attempts recovery by resetting USB device and retrying.

Change-Id: I64e95998f429ffb7b14143d956b1f29d20218d14
2021-06-12 13:54:54 +00:00
Aidan MacDonald
d01f3192f2 Spin off common ft6x06 code to a driver
Allows for the i2c boilerplate to be shared between the M3K and
Shanling Q1 ports. M3K-specific quirks remain in button-fiiom3k.

Change-Id: I8879b603cefc16416bb200f1c484ca916d935c6a
2021-06-11 20:09:38 +01:00
Tomasz Moń
551c74da55
Sansa Connect: Remove fake battery voltage scale
Use battery percentage as reported by AVR.

Change-Id: Id697d460b240798eb0b103f9e1f419906b87e9ca
2021-06-10 08:43:32 +02:00
Tomasz Moń
f26499bd67
Sansa Connect: Add missing include
Include usb.h to have usb_acknowledge() prototype.

Change-Id: I2dd951315a93e7c1c456358d715f9ec44bf9e5af
2021-06-10 08:02:23 +02:00
Tomasz Moń
163e3507f8
Sansa Connect: Working USB Mass Storage
Acknowledge SYS_USB_CONNECTED in all queues so USB task can gain
exclusive access to the storage.

Reduce CPPI requeue timeout to speed up disk access.

Change-Id: I322aae4cac679696bb8186ccacf838a18f0715e9
2021-06-09 20:52:36 +02:00
Tomasz Moń
a11c88e0df
Sansa Connect: Fix sending ZLP on non-zero endpoint
This fixes panic when mass storage driver sends failed result.

Change-Id: I14ae975b1f23aee7bc2f7bad6ed68dde29cf5e36
2021-06-09 19:13:49 +02:00
Tomasz Moń
efa173a923 Sansa Connect: Fix bulk transfers greater than 64 bytes
Correctly set endpoint maximum packet size so host will not consider
end of transfer after receiving first packet when transfer is larger
than 64 bytes (at High Speed the endpoint max packet size was set to
64 but according to descriptor it is 512).

Split DMA transfers up to CPPI_MAX_FRAG so we get single interrupt
after each call to tnetv_cppi_send().

Change-Id: I385b66bc5d71975a4e3e9167efac0b1334bd3ffc
2021-06-09 10:21:06 +00:00
Tomasz Moń
7f3d0ce814 DM320: Fix SDHC response format 2 handling
Return complete R2 response to caller. Due to incorrect bitfield
handling only bits [127-96] were ever returned to caller.

Change-Id: I83726af35fb24a8051fcca8b8d019ad89d17500e
2021-06-09 10:09:50 +00:00
Aidan MacDonald
55c95a9cf5 FiiO M3K: filter touchpad input when it's disabled
I had hoped this would fix FS#13297, but no luck. Might as well
do this change anyway, because it's the "right" thing to do.

Change-Id: I55819c881d2141dd565e1c1f21460578c9114ff6
2021-06-07 22:28:58 +01:00
Aidan MacDonald
2b23d3ecaf x1000: Allow setting IRQ handlers dynamically
Avoids having to #define the names of GPIO pin interrupt handlers,
as they can now be set at runtime instead.

Change-Id: Ib5da1bdb475ff7b64280fe7cdd00adab63389152
2021-06-06 11:06:43 +00:00
Aidan MacDonald
e85bc74b30 x1000: GPIO refactor
The GPIO API was pretty clunky and pin settings were decentralized,
making it hard to see what was happening and making GPIO stuff look
like a mess, frankly.

Instead of passing clunky (port, pin) pairs everywhere, GPIOs are now
identified with a single int. The extra overhead should be minimal as
GPIO configuration is generally not on a performance-critical path.

Pin assignments are now mostly consolidated in gpio-target.h and put
in various tables so gpio_init() can assign most pins at boot time.

Most drivers no longer need to touch GPIOs and basic pin I/O stuff
can happen without config since pins are put into the right state.
IRQ pins still need to be configured manually before use.

Change-Id: Ic5326284b0b2a2f613e9e76a41cb50e24af3aa47
2021-06-06 11:06:14 +00:00
Tomasz Moń
474293a12b Sansa Connect: Initial TNETV105 driver port
Port USB driver from Sansa Connect Linux kernel sources. The device
successfully enumerates and responds to SCSI commands but actual disk
access does not work. The SCSI response sent to host mentions that both
internal storage and microsd card are not present.

Change-Id: Ic6c07da12382c15c0b069f23a75f7df9765b7525
2021-06-06 07:57:38 +00:00
Tomasz Moń
77603c344d DM320: Fix buffer overrun in sdmmc driver
Modify count, buffer and start address only after successful transfer.
This makes the retry operation to use the same address and buffer as the
just failed transfer.

Change-Id: I4f49bbdc861d634e33ea5e939a9693474411d24d
2021-06-05 18:41:02 +00:00
Solomon Peachy
ce5fe4d108 ata: fix a typo in a definition that's thankfully not used.
Change-Id: I6f2d4d05249dc01b48caa1507ee0e71496c67ba6
2021-06-03 21:04:29 -04:00
Solomon Peachy
00440f2137 ipod6g:: Get rid of magic command numbers in ata driver
Use CMD_* macros instead.  Makes the code a bit easier to follow.

No functional change.

Change-Id: Ieb3d8f6fcca503421d3067aafbd0011a908368e0
2021-06-04 01:03:51 +00:00
Aidan MacDonald
cec6422ace x1000: LCD driver minor fixes & improvements
- Use unsigned bitfields in 'lcd_tgt_config'
- Set DTIMES when using an 8-bit bus width
- Allow using DMA big-endian mode
- Provide an #ifdef to avoid stopping DMA in the middle of a frame
- Correctly #ifdef LCD sleep code when target does not implement it

Change-Id: I327c6b05223638b876d5ab62cb6e48f82e6d5fa5
2021-06-03 22:54:59 +00:00
Aidan MacDonald
a6b5de6a89 x1000: minor adjustments to PWM code
- Change busy loop to wait on the timer flag instead of hoping to
  catch the timer at exactly the right moment... unsurprisingly,
  that did not work well with higher frequency PWM outputs.
- Put GPIO data into a dedicated const array.

Change-Id: I2a920ed265c192da197a18c7242f3205d11636d3
2021-06-02 23:52:53 +01:00
Aidan MacDonald
0187fca640 axp173 driver: rename to "axp-pmu" + other changes
The old name was a bit misleading. AXP173 is sort of the lowest common
denominator of a series of related chips. The M3K uses an AXP192 which
has a few extra features vs. the AXP173.

New voltage regulator stuff was added for the sake of the Shanling Q1
native port (that player also uses an AXP192).

Change-Id: Id0c162c23094bb03d13fae2d6c332e3047968d6e
2021-06-01 19:57:41 +00:00
Aidan MacDonald
2066465b78 FiiO M3K: minor fixes
- Drop obsolete NAND patch script (it's simpler to use 'dd' directly)
- Remove an outdated comment
- Fix missing 'void' in a function definition
- Reset the poweroff timer when we poke the backlight

Change-Id: I752624386f30ac95f41a731d2b6be837e12275a9
2021-06-01 00:26:20 +01:00
Aidan MacDonald
663c5268ac AK4376 driver: refactoring
Some audiohw API calls are shared between playback and recording,
eg. frequency settings. Implementing these in the DAC driver won't
work for the M3K, as it uses a separate codec for microphone input.

Change-Id: Ieb0a267f8a81b9e2bbf0bbca951c5778f8dcd203
2021-05-31 23:00:14 +01:00
Aidan MacDonald
f63edb52ef x1000: refactor AIC initialization
Have pcm-x1000 handle most work, so target's audiohw code touches
only the relevant settings.

Change-Id: Icf3d1b7ca428ac50a5a16ecec39ed8186ac5ae13
2021-05-30 19:17:50 +00:00
Aidan MacDonald
c78ba1aa68 MIPS: add another mipsr2 endian function
Used by WAV and AIFF encoders for recording.

Change-Id: If1bf05583c6b5c123c91eb9c4dfe0e11efd3a0f7
2021-05-29 15:35:50 +00:00
Aidan MacDonald
f64e8dc33c x1000: Complete the register definitions
I think this covers everything now, although some fields are missing
enum values. Those can be added in if and when they are needed.

Change-Id: Ib1a94ba9c9a5949b6a038f8c1a49786823fae58f
2021-05-29 16:34:32 +01:00
Aidan MacDonald
5cbeb88541 FiiO M3K: keymap improvements & fixes
- Add support for skip and seek while the player is locked.
  (Thanks to @bahus for the suggestion)
- Fix touch zones because the down button zone ended up being
  a lot smaller than expected due to the touchpad's wonkiness.
  Also added a visual display of the touchpad to its debug menu.
- Fixes the pictureflow keymap because it was mostly unusable.

Change-Id: Ic0da4f8df3613ff7828ce1cb940ed9e77ada3281
2021-05-22 12:20:44 +00:00
Tomasz Moń
00b4626790 Sansa Connect: Clear recoverzap parameter
Clearing recoverzap parameter exists the Recovery Mode. This makes it
possible to run Rockbox on Sansa Connect without relying on original
Linux firmware.

Enable write-through cache on flash memory as write-back complicates
handling without any real benefits. The flash memory accepts commands
as series of writes at predefined addresses, so it is important that
the cache does not interfere with the writes.

Change-Id: I219f962f20953d84df43012cf16bbb16d673add8
2021-05-21 18:55:14 +00:00
Solomon Peachy
0c62177575 FS12845: Fix uninitialized read
Change-Id: If0e5b65a70e10b624416e2a15e0b3df29c2b4591
2021-05-19 17:09:48 -04:00
Aidan MacDonald
ad64293ae6 X1000: fix SD driver issues
- Added panic check for unaligned addresses
- Properly set 50 MHz high-speed mode timings

Change-Id: Ia0b3e5a6612c2053a28c2c3125de8ea92100912e
2021-05-14 10:30:58 +00:00
Aidan MacDonald
eb0336eded FAT: align writes when bounce buffering is enabled
Motivation: turns out the DMA in the M3K's MSC controller is buggy,
and can't handle unaligned addresses properly despite the HW docs
claiming otherwise.

Extending the FAT driver bounce buffering code is the easiest way
to work around the problem (but probably not the most efficient).

Change-Id: I1b59b0eb4bbc881d317ff10c64ecadb1f9041236
2021-05-14 10:30:41 +00:00
Solomon Peachy
ff28d238b8 ibasso: DX50/DX90 support 192KHz audio
Also bump max battery capacity to 7300mAh, to accomodate
oversized aftermarket units that require case mods.

Change-Id: I743e550b0c0843ab17529e70b5d592ea0e9a79d8
2021-05-13 21:40:22 -04:00
Dana Conrad
84a3cbe24d ErosQ: Small keymap changes
- Move WPS Stop to Power (Hold)
- Add WPS Hotkey to Wheel scroll Fwd/Back
- Add WPS Quickscreen to Play (Hold)
- Add Tree Hotkey to Play (Hold)

Change-Id: Id74622138353521f736c0de1009a354307b108eb
2021-05-12 11:01:27 +00:00
Moshe Piekarski
b895fb6643 Add tm->yday to RTC ports missing it
Change-Id: I86882262bafb8d06f925aabb87ebd1b5dcb0cd53
2021-05-12 10:52:03 +00:00
Aidan MacDonald
3f26fcf340 FiiO M3K: New bootloader
SPL and UCL-compressed bootloader are now packed into one output,
bootloader.m3k, eliminating the separate SPL build phase.

The Rockbox bootloader now has a recovery menu, accessible by
holding VOL+ when booting, that lets you back up, restore, and
update the bootloader from the device.

Change-Id: I642c6e5fb83587a013ab2fbfd1adab439561ced2
2021-05-12 10:35:20 +00:00
Aidan MacDonald
3748117ee3 Add standalone UCL decompressor
Change-Id: Ibdb128ad66a7dcdd617dc83dfd294c0b24d4901d
2021-05-12 10:35:20 +00:00
Aidan MacDonald
15ad1c42db X1000: simplify NAND driver
- Removed unnecessary layers of generic code
- Software ECC is gone since we don't need it now (and maybe not ever)
- Removed bounce buffering, so callers must now align buffers

Change-Id: I33fbac9d9d12a4657980b8618c7d62bfa91e2ea0
2021-05-06 08:37:26 +01:00
William Wilgus
49edfc237b lcd_putsxyofs 16 bit lcd_mono_bitmap_part [AS]
'Bugfix' mono_bitmap_part reads ahead in the buffer,
if the height is <= char bit pixels other memory gets read
found with [Address Sanitizer]

also g#3332 since this is clearly a problem across the code
instead place the check for height < 8 in the lcd_mono_bitmap_part function

Change-Id: I917cbbd568fd5474b76a98c8919467e2538e0f0c
2021-04-30 21:26:06 -04:00
Aidan MacDonald
16a1993cad x1000: Remove some #ifdef SPL in the sfc/nand code
Change-Id: I554d590bfa700e521a74b5216e09f9673902d676
2021-04-28 20:04:10 +01:00
Aidan MacDonald
423fcf951a x1000: Rewrite clk_get code so it's more data driven
This is not pretty, but at least it should be usable by the SPL.

Change-Id: I1c0cdb910109c882160e3effd7c778e4d961842c
2021-04-28 20:04:10 +01:00
Aidan MacDonald
20fc928221 x1000: Centralize common definitions, memory layout
Change-Id: I8daad058ae55d4b750b1ae407153e4917de5d095
2021-04-28 20:04:10 +01:00
Aidan MacDonald
ed8c977e2f x1000: Fix stupid bug in the SPL
This overwrote the first 2 instructions of crt0 in the bootloader!
I'm really not sure how this *didn't* cause a fatal exception.

This address isn't special as far as I know, so just move it to the
TCSM by making it a static variable.

Change-Id: I58e1486804aeb2b68325e8de2aa1874c97abef19
2021-04-28 20:04:10 +01:00
Aidan MacDonald
d5695822a7 MIPS: remove .MIPS.abiflags section
The abiflags data is only used to communicate ABI information to a
program loader -- you can see what info is stored with readelf -A.
Dropping it shaves 24 bytes off of every binary (including plugins).

Change-Id: Iae78eeffe5c840ff67717707fb94821d24aac8ec
2021-04-26 12:41:06 +00:00
Solomon Peachy
7d0d32dbc6 Nuke the never-functional iriver ifp-7xx port
It never worked, and hasn't compiled in something like a decade, Given
the HW capabilities (limited onboard flash, no expandability) there's
really no point in trying to fix/complete it.

Change-Id: I7d175089840396f8891645bd10010d730dd5bfdc
2021-04-26 07:42:58 -04:00
Solomon Peachy
3ba2f6e5c7 Nuke all TCC77x targets: iAudio 7, Sansa C100, M200(v1-3), Logik DAX
They were never finished, never saw any release ever, and haven't
compiled for the better part of a decade.  Given their HW capabilities [1],
they are not worth trying to fix.

[1] 1-2MB RAM, ~256MB onboard flash, no expandability

Change-Id: I7b2a5806d687114c22156bb0458d4a10a9734190
2021-04-26 07:41:51 -04:00
Aidan MacDonald
77188e41f5 X1000: remove bogus GPIO Z mutex
There's absolutely no way for gpio_config() to get called from two
different threads due to the co-operative threading model, and it
is unsafe to call from IRQ context no matter what we do.

Change-Id: I58f7d1f68c7a414610bb020e26b774cb1015a3b0
2021-04-25 14:27:35 +00:00
Aidan MacDonald
a2dfafb2b2 X1000: disable SFC DMA
Change-Id: Ia33896b4a19da6eaaf3e5c057891ab10d75f31e1
2021-04-25 14:16:12 +00:00
Aidan MacDonald
d6220f618b MIPS: emulate -ffunction-sections with macros in mmu-mips
Using a macro to put each function in its own .icode-based section
allows us to put the functions in IRAM _and_ have linker GC. This
removes a troublesome #ifdef BOOTLOADER_SPL on the X1000 target.

Change-Id: Ia7b59778f5c36b7970dee4280547e434a1f4fc5a
2021-04-25 14:04:38 +00:00
Solomon Peachy
aab72f969f ata: Rework power management behavior a bit
After continued reports of corruption using iFlash adapters, I went
digging for more clues, and this combination of changes seemed to
solve data corruption with the iFlash adapters on the ipod video:

 1) Instead of SLEEP, use STANDBY_IMMEDIATE when we detect drive
    as an SSD or CFA-compliant device.  The latter is technically higher
    power than the former, but what this means in practice is unclear.
 2) Don't check ATA powermanagement flag prior to issuing powermgmt
    commands. This reverts the previous "workaround" for the FC1307A --
    and PM is a mandatory part of the ATA spec for any CFA device.
 3) Prior to issuing SLEEP/STANDBY_IMMEDIATE, issue FLUSH CACHE.  The
    ATA spec says this is redundant for the latter, but says nothing
    about the former.  Either way it is always safe to call first.
 4) Delete all other FC1307A_WORKAROUND code related to powermgmt flags.

Change-Id: I492d06664c097d9bbd5cccfb9f5b516da165b1ee
2021-04-23 13:07:45 +00:00
Aidan MacDonald
79d1b68fe2 FiiO M3K: disable USB DMA
Although data transfer is reliable with DMA, it seems to cause hangs
and lockups during the early stages of connection and it's not clear
what the cause might be.

Change-Id: I9a83089c31d28309f0534dcdedf3c8c8348e6e3d
2021-04-23 00:30:52 +01:00
Aidan MacDonald
75cb8ba8a4 FiiO M3K/X1000: add USB support
This only required a minor patch to the usb-designware driver due
to DMA requiring physical addresses -- on the X1000, these differ
from virtual addresses so we have to do the usual conversion.

Both the mass storage and HID drivers work, but there are a few
issues so this can't be considered 100% stable yet.

- Mass storage might not be detected properly on insertion,
  and USB has to be replugged before it shows up
- HID driver may occasionally panic or hang the machine

Change-Id: Ia3ce7591d5928ec7cbca7953abfef01bdbd873ef
2021-04-21 18:31:55 +00:00
Aidan MacDonald
088ebb5fac Minor enhancements to axp173 driver
- Added register names to reduce usage of magic numbers
- Added function to control max charging current, needed for USB
- Corrected comment about axp173, since FiiO M3K has an axp192

Change-Id: I6604ce8d44e5a2ee84061cf042d17ccc4734ac57
2021-04-21 18:31:55 +00:00
Aidan MacDonald
9313274302 FiiO M3K: fix LCD weirdness when booting via RoLo
Change-Id: I2234a0d1b3095adbcca0bbd060fd5a7e13a895c1
2021-04-21 19:10:34 +01:00
Aidan MacDonald
c71a47f649 Move usb-designware out of ARM target tree
Change-Id: Ic981737976655596ea622b7b4d15a2d841bd993d
2021-04-18 18:45:28 +01:00
Aidan MacDonald
92140752d7 FiiO M3K: disable CPU frequency switching
After conducting some simplistic tests, I found that the power usage
did not appear to be affected by the CPU frequency.

I tested by playing back a 44.1 KHz FLAC file on single track repeat,
and measured current with the AXP173's battery discharge current ADC.
The button and LCD backlights were set to always on. Headphones were
unplugged and the volume was muted to eliminate any influence from
the headphone amp.

On average the current usage was between 78-81 mA at 1008 MHz, 252 MHz,
and 112 MHz. If anything, 1008 MHz drew _less_ current than the lower
frequencies, by about 1-3 mA.

A possible explanation for this, assuming it's not just a bias of the
test, is that the CPU idle state saves so much power that it's better
to maximize the real time that the CPU spends idling. More systematic
testing is needed to confirm this.

Change-Id: I527473e8c4c12bc1e94f8d4e849fecc108022abe
2021-04-17 20:24:36 +00:00
Aidan MacDonald
fceffb7d4a x1000: disable CPU idle stats by default
There's no point including this in normal builds: the stats are not
used for anything, they are not really of interest to anyone except
developers, and add a small overhead to the kernel tick.

Change-Id: I1b4f67cc62d11d634a8cec279dca513dd10eea96
2021-04-17 20:24:21 +00:00
Aidan MacDonald
01d1eb4258 FiiO M3K/X1000: Do system clock initialization in the SPL
Initializing the clocks in the SPL brings Rockbox in line with
how the FiiO M3K's original SPL works. It's likely other X1000
devices do this too.

There was a logic error in the previous setup: the code falsely
assumed that DDR memory would always be running from MPLL, but
it would be switched to APLL by the bootloader. Rockbox would
then try to re-init APLL, albeit with the same parameters. Maybe
this was the cause of the boot hang on some units.

Change-Id: I64064585e491bbdf1e95fe9428c91a9314f2a917
2021-04-17 20:24:07 +00:00
Aidan MacDonald
e123c5d2f2 x1000: don't reset all GPIOs at boot
What we really want is to avoid any interrupts being generated
before the drivers which handle them are properly initialized.
Intead of trashing all GPIOs, search for the problem pins and
fix them, leaving the others alone.

This fixes the M3K's button light flickering on boot and should
stop the M3K from entering a potentially confusing "dead" state
where all the lights are off but the CPU is still on.

Change-Id: I13a6da0f0950190396bff5d6e8c343c668e8fea1
2021-04-17 20:23:47 +00:00
Aidan MacDonald
1b8542490d x1000: Redesign SPL, and allow it to flash the bootloader
SPL is now designed so core X1000 code is in control of the boot,
under the reasonable assumption that the device boots from flash.
It should not be too hard to adapt to other X1000 ports.

The biggest functional change is that the SPL can now read/write
the flash, under the control of a host computer. The SPL relies
on the boot ROM for USB communication, so the host has to execute
the SPL multiple times following a protocol.

Change-Id: I3ffaa00e4bf191e043c9df0e2e64d15193ff42c9
2021-04-17 20:22:49 +00:00
William Wilgus
85fbbd9c7f 16 bit lcd_mono_bitmap
'Bugfix' mono_bitmap_part reads ahead in the buffer,
if the height is <= char bit pixels other memory gets read

Change-Id: I6e0d7a9017e1f9c371ffbd56af149ac20cb82341
2021-04-17 15:33:58 +00:00
Dana Conrad
4dc602dd7f erosq: Tweak volume scale to be approximately correct
Tested on eros q, everything measured from line out,
open circuit.

- volume steps were approximately double the dB they
  were labelled as, so "-2 dB" would result in a change
  of about -4 dB from maximum (0, +6.2dBV)
- maximum volume defining the line out volume only
  changed every 10 values, and then was not close
  to correct- "-10 dB" resulted in -2.5 dB from maximum

This gets the volume dB approximately correct, and
maximum volume correctly sets the line out volume.
I was unable to get odd values in the max volume
to work, so set the step size to 2 instead of one.

For "consumer level" (-10dBV), set to -16.
For "Pro level" (+4dBu -> ~1.8dBV), set to -4.

Change-Id: I898b85d768153579a893b23551019af88f865d21
2021-04-17 12:09:19 +00:00
Solomon Peachy
42dba708e3 hosted: Don't open alsa control device directly
It was just being used as a proxy "yeah, we called hw_init()" so
just use a flag for that directly.

affects rocker, erosq, xduoo x3ii/x20, and fiiom3klinux

Change-Id: I14bd9f8d91f1d6cc8de0982a7426e2a103c6bfce
2021-04-14 01:39:57 +00:00
Solomon Peachy
ec4b5c794e ibasso: Found a reliable way to determine if SD card is present at startup
Change-Id: If02788a50e141cc2e5b1a6cde2df2a5ef5713e30
2021-04-13 14:28:30 +00:00
Solomon Peachy
c0a49d9bdf ibasso: Default to assuming the external SD card is inserted
Detection at startup is proving to be unreliable.  Even if card is not
present at startup, upon insertion it will sort itself out properly.

Change-Id: I9ee90b724c90c530a39264f698c200a48aa72b1d
2021-04-12 21:54:59 +00:00
Solomon Peachy
b6fce99046 ibasso: Implement proper PIVOT_ROOT filesystem access
Including direct use of the external SD card mount

Known issue:  If SD card is inserted at startup, it must be
              ejected and reinserted to be registered.

Change-Id: I5f420160bda32135cbb088c1e8b04b6e3a73018e
2021-04-12 18:19:06 +00:00
Solomon Peachy
bc416ff590 misc: Only include rbpaths.h and string-extra.h in places that need it
(Don't include rbpaths.h in settings.h, or string-extra.h in rbpaths.h)

Build-tested on rocker, erosq, mini2g, nano2g,
                xduoox3, clipzip, dx50, and uisim

Change-Id: If32e9c9910f5c8247a655cb64522b84d6d7ccbb5
2021-04-10 12:08:12 -04:00
Solomon Peachy
1303be3437 ibasso: Get rid of #include "settings.h" in the button code
(It mucks with paths causing the input device open to fail)

Change-Id: I1e8a63d09c229ed9bacbd599a7869e875df21fd2
2021-04-10 10:25:20 -04:00
James Buren
448f98d9c0 pp: fix adc mistake where base 10 was used instead of base 16
Change-Id: I8562af8a11a22cd9edec149b2519ac0205d2b2dc
2021-04-10 01:13:09 +00:00
Solomon Peachy
13dbcab6c0 erosq: When mucking with the clickwheel, ensure we keep the screen awake!
Change-Id: I49d39f301f4b44c2477a657e2af964b97d73cf6b
2021-04-09 19:21:02 -04:00
Solomon Peachy
cd64aa2b10 xduoox3: Global volume_limit now applies to the line output as well
The X3's line out is a bit hot, at ~4.3Vpp, so allow it to be backed off.

(On my X3, backing it off to -6dB brings Vpp down to ~3.4V)

Change-Id: Iea38ef1c6a1b183d0f8fb4eaf2bf9ed6b350a532
2021-04-09 15:54:04 -04:00
Aidan MacDonald
c0a823e2ab x1000: Trim unused cache functions from the SPL build
Change-Id: Ib645d8ff10cfc672de8ac2debaa17d7dd50dfafb
2021-04-09 10:53:36 +00:00
Aidan MacDonald
54b8e9131c Revert "sound: add sound_numdecimals() to round out the sound setting query API"
There is already a sound_numdecimals() function, according to Git
it's been around since 2005. No need to add another one :).

This reverts commit 92a0ab8789.

Change-Id: I533ebf1763dd7a27346842982493d4550f05ad7c
2021-04-09 10:52:02 +00:00
Solomon Peachy
1e2a9a651c erosq: Switch to 32-bit PCM output, and do volume scaling in driver
Should improve audio output quality, especially at lower volumes.

Change-Id: I31c38f05fe4b554b092511f0fe7aaad9f346f6c5
2021-04-08 23:58:49 -04:00
Solomon Peachy
e86d90905b alsa: Fix an #ifdef typo in 54fcb907c1
HAE_ALSA_32BIT -> HAVE_ALSA_32BIT

Change-Id: Icf375d42f6b20e8393b6ffe6d23b3ac96abb571b
2021-04-08 23:10:41 -04:00
Solomon Peachy
54fcb907c1 alsa: instead of per-target tests, use HAVE_ALSA_32BIT
Affects all Sony NWZ (linux) and the fiio m3k linux targets.

Change-Id: I2fcf121bd026103d2b72332a5a52cc2b5e93949f
2021-04-08 23:02:15 -04:00
Solomon Peachy
e17337c9aa ErosQ: fix panic on startup caused by ad55da5f
It turns out #include "settings.h" pulls in rbpaths.h which ends up
remapping open() to the path-mangling rockbox open().

By defining RB_FILESYSTEM_OS we prevent the remap.  My mistake for not
testing this before committing!

Change-Id: I2978eb7b413693c4cb887b7ac7b2457780db7d25
2021-04-08 21:58:08 -04:00
Dana Conrad
ad55da5f87 ErosQ: Set Line Level Output volume
With a full-scale 440Hz tone, the line out voltage
measured approx. 5.8Vpp at the 0 setting. WAY too hot!
(9 dBV, in fact)

For 0.894Vpp (-10 dBV - consumer devices), -18 appears to be
about right for line level signals, but for "pro" equipment
a different level may be desired.

Therefore, the user to cap the line out level by re-using the global
volume limit setting.

Change-Id: I0d1d6482ea95537e9a2d00884eaee2713771c614
2021-04-08 14:37:14 -04:00
Aidan MacDonald
4b26372591 MIPS: make sure to fill 'jr' branch delay slot with 'nop'
Inline assembly in RoLO and the FiiO M3K bootloader used 'jr' to
jump to a newly loaded Rockbox binary, but incorrectly left the
branch delay slot open. That gives GCC an opening to place illegal
instrutions, etc, which might cause an unhandled exception.

Change-Id: Ia7a561fe530e94a41189d25f18a767c448177960
2021-04-07 19:59:57 +01:00
Solomon Peachy
213d372c92 FS#13272: Fix up volume_limit to respect decimilaztion.
Change-Id: Ib0e5ddcd660115f156ddb545e45bbe7da42f9709
2021-04-07 14:38:54 -04:00
amachronic
28c89386af x1000: Improve NAND driver API
- Proper error codes are now returned from all functions. These codes will
  be used by a host-side flash tool for error reporting.

- nand_erase_block() was replaced by nand_erase_bytes(). The caller can't
  know how big an eraseblock is with the current API, so next best thing
  is to verify the correct alignment inside the call and reject the erase
  if it isn't properly aligned.

- Fixed typo in nandcmd_block_erase() which would cause an SFC error to be
  interpreted as success. Yikes.

Change-Id: Id4ac9b44fa7fc2fcb81ff19ba730df78457c0383
2021-04-06 17:27:12 +01:00
amachronic
b5558c1cf9 x1000: place SPL's NAND bounce buffers in DRAM
This frees up 2 KiB in the SPL's memory map, leaving more room for code.

Change-Id: I01bbe2ab2905b2773a8b76d8c53e9f3d55bd040f
2021-04-06 17:27:09 +01:00
amachronic
1b314502c8 Remove a duplicate const
Change-Id: I0e6f4d609eb03155de4cd16aa98cab25f54a6681
2021-04-06 17:27:08 +01:00
Solomon Peachy
74ae18cc8a fiiom3k_linux: Enable HAVE_TOUCHPAD and add in missing bits
Change-Id: I78fa5fdb3648adfaa40f6d5f3c255666a85e2761
2021-04-05 13:57:01 +00:00
James Buren
962d412917 hdd1630/hdd6330: update battery capacities
Ensure the default setting reflects what the service manual says the
official battery capacity is. Change the ranges to reflect what
replacement batteries are actually available.

This range is actually much shorter in reality due to these units
requiring the rarer 3 pin battery type that uses a thermistor. As such
there's only one real replacement battery for each.

So the HDD1630 caps out around 700 mah while the HDD6330 caps out around
680 mah.

Change-Id: I2dbbba83ad2cd6e1d84e3481c4af84a06c45e16b
2021-04-04 13:27:00 +00:00
Solomon Peachy
afec380a0d gigabeats: Fix hang on startup caused by a stack overflow
headphone ADC thread stack was slightly too small.  Bump it up a bit.

(it was _perfectly_ sized for the prior older toolchain+optimization flags...)

Change-Id: I2ca67c2b85c54f879892a31e281d7696f893389c
2021-04-01 20:24:59 -04:00
Solomon Peachy
2f785c7797 PP: More cache invalidation fixes
Take into account the size of the pointer in the loop termination
condition.

Change-Id: Ib4f7625ef143149a0d691a2109bad67aece6241c
2021-04-01 10:57:29 -04:00
Solomon Peachy
9f7f1a841a PP: Use CURRENT_CORE instead of IF_COP_CORE(CPU)
Use of IF_COP_CORE was mistakenly introduced as part of 89acde6af2,
effectively short-circuiting multiple tests resulting in the code
paths always being executed, on both cores.

Use the correct macro, so per-CPU paths are handled properly.

Change-Id: Id346cf759fc1b06b7d56694d7af1f469caf785a4
2021-04-01 08:45:43 -04:00
Solomon Peachy
0b20038d87 FiiO M3K: Hopefully fix the sim build
Change-Id: If5a58a4b3913645068cee95d4553f285eb55d182
2021-04-01 10:54:36 +00:00
William Wilgus
89acde6af2 H10 PP Crash -- Fixed
This appears to finally fix the issue
turns out the status register we were writing was only for the CPU
COP cache flush wiped out the CPU cache
--

Added some defines to cut down on the magic numbers
Added some comments explaining such

Set the address to full 20 bit address
0x1FFFFF which is then left shifted 11 internally --  somewhere around 4GB?

Link explains the cache status bits
https://daniel.haxx.se/sansa/memory_controller.txt

Change-Id: I57b7187c2f71a5b54ce145bf3a21ed492a8993cb
2021-04-01 00:52:57 -04:00
Solomon Peachy
058a9ec945 Add M3K native to the simulator
Change-Id: If3e877d2df189e44076631fd571cf6aa70ce6ca8
2021-03-28 12:08:31 -04:00
Aidan MacDonald
3ec66893e3 New port: FiiO M3K on bare metal
Change-Id: I7517e7d5459e129dcfc9465c6fbd708619888fbe
2021-03-28 00:01:37 +00:00
Solomon Peachy
83fcbedc65 rk27xx: Take advantage of STORAGE_NEEDS_BOUNCE_BUFFER
(And get rid of its custom realignment code)

Change-Id: Iff27d717b870d3db239310421776744ea6863373
2021-03-27 17:18:21 -04:00
Solomon Peachy
961ffa61dd Use STORAGE_NEEDS_BOUNCE_BUFFER instead of STORAGE_NEEDS_ALIGN
Enable its use in the jz47xx MIPS targets.

(accidently committed g#3249 before making these changes)

Change-Id: I1791946f632901f0c7a94b04b009671aa0d71717
2021-03-27 15:02:18 -04:00
Solomon Peachy
c96dc1c886 xduoox3ii: Wrap the remote key detection in USE_REMOTE
Makes it straightforward to disable for debugging or defective hardware

Change-Id: Ie72786f6e9eabf396a05ef8a02e422c34c97691a
2021-03-27 14:43:17 -04:00
Aidan MacDonald
ea1aef9b82 Have FAT filesystem respect storage buffer alignment on reads
This is just a minor cleanup of Solomon Peachy's code, and using
per-filesystem buffers instead of a single static buffer.

Tested and working on the FiiO M3K.

Change-Id: I3c19e8cc24e2f8aa07668c9d1c6d63364815050a
2021-03-27 14:43:17 -04:00
James Buren
018372bf39 usb: implement macro for initializing USB strings
This uses the new unicode string literal feature that is available
now to greatly simplify the initialization of these special string
types. This makes them much more readable at a quick glance.

Change-Id: Iad8b49aa763486608e3bb7e83fb8abfb48ce0a7b
2021-03-25 13:26:03 -05:00
Solomon Peachy
7652e6f8df rk27xx: Get rid of duplicate STORAGE_WANTS_ALIGN
Change-Id: I278d42858cc33da3710c8ca8f42d14c6d57509ca
2021-03-25 12:23:06 -04:00
Solomon Peachy
d5cc74ebd8 build: Get rid of suplerflous '-Os' references in linker calls
We should be using global optimization flags, and -Os is already our
default.

Change-Id: Iaba511b2b4fa2ee0f1eb1ad28024be954f4c5f03
2021-03-25 12:20:15 -04:00
William Wilgus
3d9d2de34d Revert "lcd framebuffer - Bugfix #2 ensure proper alignment"
This reverts commit 3a5c5edbf6.

Reason for revert:pulling in system.h breaks SDL

:(

Change-Id: Ied5e08de4770aa0da87c14b304480448db349423
2021-03-25 06:34:58 +00:00
William Wilgus
3a5c5edbf6 lcd framebuffer - Bugfix #2 ensure proper alignment
-- apparenty 0x4 aligned doesn't work properly

requires 0x8 alignment at least for the h10 20gb
but enabled for all processors that define MEM_ALIGN_ATTR

Change-Id: I11edaab183b91a6d158f1f439f173b9b699dc914
2021-03-25 00:32:26 -04:00
William Wilgus
ed99b305a9 Revert "lcd framebuffer - Bugfix ensure proper alignment"
This reverts commit ffee661ab7.

Reason for revert: <INSERT REASONING HERE>
iAudio M5  `IRAM' overflowed by 48 bytes

Change-Id: Id808a72c6eacabc562d53eac8acd36b45f678a97
2021-03-24 18:44:35 +00:00
William Wilgus
ffee661ab7 lcd framebuffer - Bugfix ensure proper alignment
-- apparenty 0x4 aligned doesn't work properly

requires 0x8 alignment at least for the h10 20gb
but enabled for all arm processors

assign the default framebuffer to the default_vp as well

Change-Id: I0b76c30f2ddb5d6d2f7c6a132e4081aee58da17b
2021-03-24 18:22:01 +00:00
Aidan MacDonald
94b40ed314 Add asynchronous I2C bus API
The driver core is based off of the i.MX233 I2C implementation and
should work on any platform.

Change-Id: I3b9c15e12a689ef02a51c285be08d29d35e323dc
2021-03-23 15:42:54 +00:00