leighleighleigh / saab-93NG-bluetooth-aux

A module to augment the Aux-In functionality of SAAB 93NG's (2002/3+), to add Bluetooth media playback and steering wheel media control support. If your SAAB has an optic-fiber MOST bus, this will work for you.
GNU General Public License v3.0
10 stars 6 forks source link

Automatically switching to Aux input when connected to Bluetooth #3

Closed jokubasver closed 2 years ago

jokubasver commented 3 years ago

One of the annoying things with the Saab audio system is that it doesn't remember the last used audio input source, especially when primarily using aux. I was wondering if there is a way to read info from EHU or ICM to know in which source input the radio is in. This way, let's say if we are connected to Bluetooth, we could send source button commands, read the current source input, and stop once the radio is in aux mode.

Obviously a dumb and easy way of achieving a similar result would be to just send two source button commands on boot up to get into aux, but this won't always work (for example, if the car was running recently, a single source button click will get you into aux, not two)

Any ideas on how to implement something like this?

leighleighleigh commented 3 years ago

I originally had plans to tap into the I2C data between the EHU and it's display module, and detect when 'AUX' was being shown on screen - then trigger SRC button presses appropriately. This is a pretty hacky solution, but it would probably work.

I intended to do this by means of an 'I2C forwarding' microcontroller, which would sit between the display and the ICM and monitor the data, but it might be possible to watch the regular data stream with something like this instead ?

There are also heaps of TX/RX and SDA/SCL pins labelled on the bottom of the EHU, as I'm sure you have seen. I would love to know what information is available there.

Keep in mind that we can trigger the SRC button on the steering wheel from the I-BUS - so if there was some data on the I-BUS that indicated the EHU/ICM state we would be able to do it with a software update! :) I searched for a while in 2019 to find messages that represent audio state, but I don't recall finding anything...

leighleighleigh commented 3 years ago

I just opened the spare EHU unit I've got kicking around. The SAA7706H looks to be the main DSP IC, datasheet here. Not heaps of info on the specific register values, but this is much more than I expected to find already :)

jokubasver commented 3 years ago

Yeah, my idea was on the I-BUS too, but I haven't found anything about seeing SRC states on the I-BUS either. It might be there, but would need to sniff the BUS.

Do you have an account on trionictuning.com? Lots of good info there on the R&D/Tools general section.

Thread on EHU reverse-engineering (with the main focus of adjusting the cross-over frequency to get more bass): https://www.trionictuning.com/forum/viewtopic.php?f=46&t=5685

Thread on an open-source eSID project ideas (with lots of info on the I-BUS): https://www.trionictuning.com/forum/viewtopic.php?f=46&t=8566&sid=4ea27c35c44cbe517dc4e77c69f9ee5e

You could also put up a thread there about this project, people would definitely be interested. I found this project just by searching "saab" on GitHub lol

leighleighleigh commented 3 years ago

I sure do, same handle as here. The EHU thread is awesome, definitely going to put any DSP I2C findings there. The pSID project is a bit of a mess imho XD

I did make a post regarding my own SID hacking here, and I did eventually get some text on the SID - but I hadn't figured out the protocol enough to be able to build an eSID equivalent, and taking my SID in and out of the car was getting tiring haha.

jokubasver commented 2 years ago

Finally I got this idea to work!

I sniffed the I-BUS and I can confirm that there is no data in regards to the radio input state.

My next attack vector was the SAA7706 I2C found in the EHU, where it would be possible to read which audio input is active, but I quickly dropped this idea as to read I2C I would need to write first, and it all just seemed too complicated...

Then, inspired by your HPD hacker project, I decided to listen on the SID-ICM bus. I used an MCP2551 as that was the only CAN transceiver in stock locally. It's a 5V part, but with some resistors on the RX line, it works fine with the ESP32. Since I didn't have any intentions of displaying something on the SID (I only wanted to read the Aux input state), I'm just using one CAN transceiver to spy on the SID-ICM bus.

I couldn't find the Aux "play" message, as found in your HPD Hacker code, however, I did find a chunk of data that indicates Aux mode. Then, simply by sending SRC button commands via I-BUS and checking if that SID Aux message is finally seen, I can reliably enter Aux when connected to Bluetooth!

Here's the code if you are interested: https://github.com/jokubasver/saab-93NG-bluetooth-aux/commit/f86eb39e984ae5de91b66a5be0720a2987c7b667

leighleighleigh commented 2 years ago

That is so awesome! Surely the next step is to display song information on the SID, too ;)

Thanks for sharing your work, it's made my day! Good to see that you are using the in-built serial port on the ESP32, too - I don't know what I was thinking using an external IC on the HPD-Hacker.

As a complete coincidence, yesterday I dug out the first bluetooth-aux PCB (the one in the photo on the README) and flashed it with all your new features! Although the ESP32 doesn't have 24-bit audio using A2DP SBC, like the store-bought Bluetooth receiver I've been using - having the steering-wheel controls back is 100% worth it.

Now I just need to buy an I2S microphone, and it will be perfect. Again, thanks for contributing to the project!

Question: where are you tapping into the I-bus, HPD-bus, and AUX-output wires? If I remember correctly you have installed all of this inside the ICM unit, I'd love to see any photos you have of it.

I'm also interested in designing a revision of the PCB that fits perfectly inside the ICM2, as a type of "ICM2+" upgrade kit. What are your thoughts on that?

jokubasver commented 2 years ago

I wanted to leave the 3.5mm aux functionality stock, so I simply left the standard Saab aux jack in place, and soldered my own audio cable to the EHU pins directly, and that goes in to the Bluetooth PCB.

EHU pins is where I'm also grabbing 5V and GND. The reason why I use 5V off the EHU is that it stays active in all key positions, whereas the 12V cigarette is on only in ON key position. If it's possible to use 12V from the ICM, and if that voltage line turns on/off in sync with the radio - that would be the better, simpler approach for installation.

I'm tapping to the I-BUS from the ICM (ICM1 in my case) - also by soldering a wire on the ICM PCB.

As for the SID CAN - I soldered on the SID PCB, but I should trace the wires on the ICM, that way it would be neater (and it's also a pain in the a** to route the wire down below the SID)

I'll send you some pics later of the install

I was thinking of a new PCB too - maybe using an ESP32-A1S, which has a built-in high quality, well supported in ESP-IDF ES8388 audio codec. Thus - no need for an external DAC, and a simple 3.5mm lav mic could be used instead of an INMP441 or the like. Throw in some CAN transceivers (to integrate HPD/SID hacking), an isolated DC-DC converter and it would be quite nice!