From 13aa84722e925d67fa017b1c72267890cfdae1b5 Mon Sep 17 00:00:00 2001 From: ohmytime Date: Sat, 27 Jan 2024 20:59:07 +0800 Subject: [PATCH] Support 12M and 55M oscillators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Depending on the voltage of IO15, different crystal oscillators are supported. IO15: 0V → 9.216M IO15: 1V → 12M IO15: 2V → 55.466M IO15: (2V~3.3V] → 4M --- src/TEF6686.cpp | 18 +++++++++++++++++- src/TEF6686.h | 2 ++ src/Tuner_Interface.cpp | 16 ++++++++++++++++ src/constants.h | 4 ++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index 9e13d63..8e71844 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -3,6 +3,7 @@ #include #include // https://github.com/PaulStoffregen/Time #include "SPIFFS.h" +#include "constants.h" unsigned long rdstimer = 0; unsigned long bitStartTime = 0; @@ -123,12 +124,27 @@ uint16_t TEF6686::TestAF() { void TEF6686::init(byte TEF) { uint8_t bootstatus; + int xtalADC = 0; Tuner_I2C_Init(); devTEF_APPL_Get_Operation_Status(&bootstatus); if (bootstatus == 0) { Tuner_Patch(TEF); delay(50); - if (digitalRead(15) == LOW) Tuner_Init(tuner_init_tab9216); else Tuner_Init(tuner_init_tab4000); + + xtalADC = analogRead(15); + if (xtalADC > XTAL_0V_ADC && xtalADC < XTAL_0V_ADC + XTAL_ADC_TOL) { + Tuner_Init(tuner_init_tab9216); + log_v("XTAL : 9.216M"); + } else if (xtalADC > XTAL_1V_ADC - XTAL_ADC_TOL && xtalADC < XTAL_1V_ADC + XTAL_ADC_TOL) { + Tuner_Init(tuner_init_tab12000); + log_v("XTAL : 12M"); + } else if (xtalADC > XTAL_2V_ADC - XTAL_ADC_TOL && xtalADC < XTAL_2V_ADC + XTAL_ADC_TOL) { + Tuner_Init(tuner_init_tab55000); + log_v("XTAL : 55M"); + } else if (xtalADC > XTAL_2V_ADC + XTAL_ADC_TOL) { + Tuner_Init(tuner_init_tab4000); + log_v("XTAL : 4M"); + } power(1); Tuner_Init(tuner_init_tab); } diff --git a/src/TEF6686.h b/src/TEF6686.h index bffcbbb..e6fa021 100644 --- a/src/TEF6686.h +++ b/src/TEF6686.h @@ -9,6 +9,8 @@ extern const unsigned char tuner_init_tab[] PROGMEM; extern const unsigned char tuner_init_tab9216[] PROGMEM; extern const unsigned char tuner_init_tab4000[] PROGMEM; +extern const unsigned char tuner_init_tab12000[] PROGMEM; +extern const unsigned char tuner_init_tab55000[] PROGMEM; enum RDS_GROUPS { RDS_GROUP_0A, RDS_GROUP_0B, RDS_GROUP_1A, RDS_GROUP_1B, RDS_GROUP_2A, RDS_GROUP_2B, RDS_GROUP_3A, RDS_GROUP_3B, diff --git a/src/Tuner_Interface.cpp b/src/Tuner_Interface.cpp index bdf1333..8796d9a 100644 --- a/src/Tuner_Interface.cpp +++ b/src/Tuner_Interface.cpp @@ -50,6 +50,22 @@ const unsigned char tuner_init_tab9216[] PROGMEM = { 2, 0xff, 100, }; +const unsigned char tuner_init_tab12000[] PROGMEM = { + 3, 0x14, 0x00, 0x01, + 2, 0xff, 50, + 9, 0x40, 0x04, 0x01, 0x00, 0xB7, 0x1B, 0x00, 0x00, 0x00, + 5, 0x40, 0x05, 0x01, 0x00, 0x01, + 2, 0xff, 100, +}; + +const unsigned char tuner_init_tab55000[] PROGMEM = { + 3, 0x14, 0x00, 0x01, + 2, 0xff, 50, + 9, 0x40, 0x04, 0x01, 0x03, 0x4E, 0x5A, 0xAE, 0x00, 0x01, + 5, 0x40, 0x05, 0x01, 0x00, 0x01, + 2, 0xff, 100, +}; + bool Tuner_WriteBuffer(unsigned char *buf, uint16_t len) { Wire.beginTransmission(0x64); for (uint16_t i = 0; i < len; i++) Wire.write(buf[i]); diff --git a/src/constants.h b/src/constants.h index 119cef6..36fb5cd 100644 --- a/src/constants.h +++ b/src/constants.h @@ -23,6 +23,10 @@ #define BATTERY_LOW_VALUE 3.0 #define BATTERY_FULL_VALUE 4.2 +#define XTAL_0V_ADC 0 +#define XTAL_1V_ADC 1050 +#define XTAL_2V_ADC 2250 +#define XTAL_ADC_TOL 300 #define LANGUAGE_CHS 14