Created
March 31, 2017 10:53
-
-
Save latonita/66775b2531a37c3922ea2322c932b792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************************************** | |
Chrysler/Jeep radio AUX in "hardcore" enabler. | |
Very first version: i'm hacking into I2C bus inside radio and controlling SAA7709H DSP chip manually :) | |
1. check whether CD input is enabled by user | |
1.1 then change input AUX instead of CD | |
1.2 and turn on bluetooth receiver which is connected to radio's VES IN connector | |
Later I went the way i planne dinitially - I managed to find magic CAN BUS message which tells radio | |
that VES is here and radio enables AUX in itself. No hardcore I2C hacking anymore. | |
(c) 2014 Anton Viktorov <latonita@yandex.ru>, github.com/latonita | |
***********************************************************************************************/ | |
#include <Wire.h> | |
#define MY_ADDR 0x08 | |
#define SAA7709_ADDR 0x1C | |
#define SAA_ERROR 0xFF | |
#define SAA_WHATEVER 0x00 | |
#define SAA_CD 0x01 | |
#define SAA_CD_AUX 0x02 | |
#define CHECK_DELAY 4321 | |
#define CHECK_DELAY_AUX 9234 | |
#define LED 13 | |
#define BLUETOOTH_SWITCH A1 | |
byte radioMode = SAA_WHATEVER; | |
unsigned long newMillis = 0; | |
byte data[3] = { 0, 0, 0 }; | |
byte magic[5] = { 0x0F, 0xFA, 0x0F, 0xF0, 0x1B }; | |
byte switchToAux() { | |
int wrote = 0; | |
Wire.beginTransmission(SAA7709_ADDR); | |
wrote = Wire.write(magic, 5); | |
Wire.endTransmission(); | |
return (wrote == 5) ? SAA_WHATEVER : SAA_ERROR; | |
} | |
byte getCurrentMode() { | |
byte mode = SAA_ERROR; | |
int retCode = 0; | |
Wire.beginTransmission(SAA7709_ADDR); | |
Wire.write(0x0F); | |
Wire.write(0xFB); | |
retCode = Wire.endTransmission(false); | |
if ( retCode == 0) { | |
delay(15); | |
if (Wire.requestFrom(SAA7709_ADDR, 3, true) == 3) { | |
data[0] = Wire.read(); | |
data[1] = Wire.read(); | |
data[2] = Wire.read(); | |
if ((data[0] == 0x40) && (data[1] == 0x03) && (data[2] == 0x01)) { | |
mode = SAA_CD; | |
} else { | |
mode = SAA_WHATEVER; | |
} | |
} else { | |
Serial.println("Reading mode - wrong number of bytes"); | |
} | |
} else { | |
Serial.print("Can't read mod."); | |
Serial.println(retCode); | |
} | |
return mode; | |
} | |
void setup() { | |
pinMode(BLUETOOTH_SWITCH, OUTPUT); | |
digitalWrite(BLUETOOTH_SWITCH, LOW); | |
pinMode(LED, OUTPUT); | |
digitalWrite(LED, LOW); | |
pinMode(A4,INPUT); | |
pinMode(A5,INPUT); | |
//TODO: PULLUP/PULLDOWN 50/50 all unused pins to minimize digital hum + connect them physically | |
Wire.begin(MY_ADDR); | |
Serial.begin(9600); | |
Serial.println("\nSAA7709H I2C Hack by latonita. v3"); | |
newMillis = millis() + CHECK_DELAY; | |
} | |
void loop() { | |
int ret = 0; | |
byte mode = SAA_ERROR; | |
if (millis() > newMillis) { | |
digitalWrite(LED, radioMode == SAA_CD_AUX ? HIGH : LOW); | |
digitalWrite(BLUETOOTH_SWITCH, radioMode == SAA_CD_AUX ? HIGH : LOW); | |
//check current mode | |
mode = getCurrentMode(); | |
if (mode != SAA_ERROR) { | |
Serial.print("state = "); | |
Serial.print(radioMode); | |
Serial.print(", user selection = "); | |
Serial.println(mode); | |
if (radioMode == SAA_WHATEVER && mode == SAA_CD) { | |
//bad but helps to avoid "argh" sound | |
digitalWrite(BLUETOOTH_SWITCH, HIGH); | |
delay(500); | |
if (switchToAux() != SAA_ERROR) { | |
radioMode = SAA_CD_AUX; | |
Serial.println("Switched to AUX"); | |
} else { | |
Serial.println("Can't switch to AUX"); | |
digitalWrite(BLUETOOTH_SWITCH, LOW); | |
} | |
} else if (radioMode == SAA_CD_AUX && mode == SAA_WHATEVER) { | |
//cd switched, forget it | |
radioMode = SAA_WHATEVER; | |
Serial.println("Switch back to radio"); | |
} | |
} | |
newMillis = millis() + (radioMode == SAA_CD_AUX ? CHECK_DELAY_AUX : CHECK_DELAY); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment