Commit graph

4941 commits

Author SHA1 Message Date
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
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
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
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
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
Aidan MacDonald
84362141a0 x1000: Unified flash bootloader installer
Change-Id: Ib1d41d4e7d663ff8a21eb08108c13568f7408533
2021-07-11 15:39:50 +01:00
James Buren
fa743258ea filesystem: implement os_modtime for unix
Change-Id: If030d526f29aa786b5a37402413d804752286cf5
2021-07-11 12:40:08 +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
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
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
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
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
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
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
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ń
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