📄 mt6189a1_drv.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*******************************************************************************
*
* Filename:
* ---------
* MT6189A1_drv.c
*
* Project:
* --------
* MAUI
*
* Description:
* ------------
*
* FM Radio Driver (MT6189A1)
*
* Author:
* -------
* -------
*
*******************************************************************************/
#include "l1audio_def.h"
#if (defined(MT6189A1))
static uint8 cw_cache[66] = {0};
#define USE_I2C
/// #define MT6189_DEBUG
/// #define MT6189_DEBUG_DUMP_LOG
#define FM_RST_PIN 34
#define FM_CLK_PIN 26
#define FM_SE_PIN 38
#define FM_POWER_PIN 2
#define FM_SDA_PIN 48
#define FM_SCL_PIN 47
#define FM_RST_PIN_OUPUT_HIGH GPIO_ModeSetup(FM_RST_PIN, 0);\
GPIO_InitIO(1, FM_RST_PIN);\
GPIO_WriteIO(1, FM_RST_PIN);
#define FM_RST_PIN_OUPUT_LOW GPIO_ModeSetup(FM_RST_PIN, 0);\
GPIO_InitIO(1, FM_RST_PIN);\
GPIO_WriteIO(0, FM_RST_PIN);
#define FM_SE_PIN_OUPUT_HIGH GPIO_ModeSetup(FM_SE_PIN, 0);\
GPIO_InitIO(1, FM_SE_PIN);\
GPIO_WriteIO(1, FM_SE_PIN);
#define FM_SE_PIN_OUPUT_LOW GPIO_ModeSetup(FM_SE_PIN, 0);\
GPIO_InitIO(1, FM_SE_PIN);\
GPIO_WriteIO(0, FM_SE_PIN);
/* MT6189 Control Word */
#define CW(_A,_B) (const)(uint8)((_A << 1) + _B)
/* General propose constant */
#define MT6189 96 /// Device ID of MT6189 = 96
#define OP_WRITE 0 /// Write to MT6189
#define OP_READ 1 /// Read from MT6189
#define MT6189_WRITE 32 // 0x20
#define MT6189_READ 33 // 0x21
#define SET_FREQ_FAIL -1
#define LO_INJECTION 0
#define HI_INJECTION 1
#define RSSI_CHECK_FAIL 2
#define FM_TUNER_GRID 100
#define PRESET_IF 140 /// Preset IF: 140 khz
#define IF_MEASURE_COUNT 2 /// 2 * 1,9 ms
#define VCO_LOCKING_TIME 8 /// 8 * 4.615 ms
#define CALIBRATION_FAIL_COUNT_THRESHOLD 5
#define REF_CLK_32K
#define PRESET_IF_CNT 274 /// 140000 * 64 / 32768 = 273.4375
#define PRESET_IF_DELTA 30 //30
#define IF_CONVERT_FACTOR 512 /// 32768 / 64 = 512
/*
#define REF_CLK_26M
#define PRESET_IF_CNT 265 /// 140000 * 49152 / 26000000 = 264.66
#define PRESET_IF_DELTA 29
#define IF_CONVERT_FACTOR 529 /// 26000000 / 49152 = 529
*/
/* Serial communication interfaces */
void SerialCommInit(void);
void SerialCommRelease(void);
void SerialCommCryClkOn(void);
void SerialCommCryClkOff(void);
void GPIO_WriteIO(char data,char port);
int16 FMDrv_Search( uint8 search_direct);
void FMDrv_SetFreq_back( int16 curf ) ;
#if defined USE_I2C
void SerialCommStart(void);
void SerialCommStop(void);
uint8 SerialCommTxByte(uint8 data);
void SerialCommRxByte(uint8 *data, uint8 ack);
#elif defined USE_3_WIRE
#endif
typedef struct {
uint8 addr;
uint8 value;
} ctrl_word_setting;
typedef struct {
uint8 addr;
uint8 and;
uint8 or;
} ctrl_word_operation;
extern uint8 const FM_RADIO_INPUT_LEVEL_THRESHOLD;
/// Global variables for current FM status
static int16 _current_frequency = -1;
static uint8 _current_level = 0x80;
static bool _is_fm_on = false;
static bool _is_fm_mute = false;
static uint8 _rssi_threshold;
static uint8 _valid_rssi = 0;
static uint16 PRESET_IF_CNT_PLUS; //add to adjust IF rounding
void Delay_ms(kal_uint32 times)
{
kal_uint32 delay1;
kal_uint16 delay2;
for(delay1=0;delay1<times;delay1++)
for(delay2=0;delay2<4700;delay2++){ } // about 1ms
}
static void MT6189_Mute(uint8 mute);
void FMDrv_EvaluateRSSIThreshold(void);
uint16 FMshadowReg[45];
uint16 cwFMDefault[]={
#if 1
0x0000,
0x0000,
0xd881, //0x02
0x0000, //87.5M
0x4400, //0x04
0x05f8, //0x05
0x0000,
0x00cd,
0x0096,
0x0020,
0x4163,
0x0806,
0x5800,
0x5800,
0x5800,
0x5800,
0x4c08, //0x4817UL,
0x20a2,
0x0000,
0x000f,
0x06de,
0xecc0,
0x0200,
0x5383,
0x95a4,
0xe848,
0x0700, //0x0500UL,
0x00ff, //0x00a4UL,
0x889b,
0x0d84,
0x4f04,
0x8832,
0x7f71,
0x0660,
0x4010,
0x6002,
0x1808,
0x6458,
0x787f,
0x0100,
0xc040,
0xc020,
0x0024,
0x0400,
0x0020,
#else
0x0000,
0x0000,
0xd881, //0x02
0xa200,
0x4400, //0x04
0x10ff, //0x05
0x0000,
0x00cd,
0x0096,
0x0020,
0x4163,
0x0806,
0x5800,
0x5800,
0x5800,
0x5800,
0x4c08,
0x20a2,
0x0000,
0x000f,
0x06de,
0xecc0,
0x0200,
0x5383,
0x95a4,
0xe848,
0x0700,
0x00ff,
0x889b,
0x0d84,
0x4f04,
0x8832,
0x7f71,
0x0660,
0x4010,
0x6002,
0x1808,
0x6458,
0x787f,
0x0100,
0xc040,
0xc020,
0x0024,
0x0400,
0x0020,
#endif
};
static uint8 MT6189_ReadCache(uint8 CW)
{
if (CW < 52)
return cw_cache[CW];
else
return cw_cache[CW-142];
}
static void MT6189_ReadByte(uint8 CW, uint8 *data)
{
SerialCommStart(); /// send the start sequence
SerialCommTxByte(MT6189_READ); /// device ID and R/W bit
SerialCommRxByte(data, 0); /// read data and send ACK
SerialCommStop(); /// send the stop sequence
}
/* MT6189 does not support sequential write. */
static bool MT6189_WriteByte(uint8 CW, uint8 data)
{
SerialCommStart(); /// send the start sequence
SerialCommTxByte(MT6189_WRITE); /// device ID and R/W bit
SerialCommTxByte(data); /// data to be written
SerialCommStop(); /// send the stop sequence
return true;
}
kal_uint8 FmWaitSTC1(void)
{
Delay_ms(100); // min 100ms
return 1;
}
kal_uint8 FmWaitSTC0(void)
{
Delay_ms(50);
return 1;
}
static uint16 MT6189_GetCurRSSI(void)
{
uint8 data1,data2,data3,data4;
kal_prompt_trace(MOD_MMI,"enter MT6189_GetCurRSSI");
Delay_ms(50);
SerialCommStart(); /// send the start sequence
SerialCommTxByte(MT6189_READ); /// device ID and R/W bit
SerialCommRxByte(&data1, 0); /// read data and send ACK
SerialCommRxByte(&data2, 0); /// read data and send ACK
SerialCommRxByte(&data3, 0); /// read data and send ACK
SerialCommRxByte(&data4, 1); /// read data and send ACK
SerialCommStop(); /// send the stop sequence
return (data3*0x3f);
}
static void MT6189_Mute(uint8 mute)
{
}
static int32 MT6189_GetCurIFCnt(uint8 count, uint8 early_check)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -