📄 radio.c
字号:
/************************************************************************
*
* Copyright(c) 2004 ItoM BV
* All Rights Reserved.
*
* LV2400x evaluation kit: Radio implementations
* File name: Radio.c
* Radio implementation
*************************************************************************/
#include <stdio.h>
#include "common.h"
#include "Lv24Ekit.h"
/* ************************************************************************************************
*
* Function: AdjustVolume
*
* Authors: Hung van Le
* Purpose: Adjust the sotware volume level (ie mute is a level extra)
* Input: byVolume: new volume level
* When byVolume = VOLUME_UP: increase volume level (defined in Lv24Ekit.h)
* When byVolume = VOLUME_DOWN: decrease volume level (defined in Lv24Ekit.h)
* Output: Status as defined in LvErr.h
* Comments:
* Software add a level extra to volume level to implement volume level 0 = silent (ie mute audio)
* So there are n+1 volume levels (where n=maximal hardware level)
* 0: Audio muted
* 1: Audio unmute, hardware volume at 0
* 2: Audio unmute, hardware volume at 1
* ...
* n+1: Audio unmute, hardware volume at maximum (=n)
* ************************************************************************************************
* Copyright (c) 2004. Semiconductor Ideas to the Market (ItoM) B.V. All rights reserved.
* ************************************************************************************************ */
BYTE AdjustVolume(BYTE byVolume)
{
BYTE byMaxVol, byCurVolume;
// Determine current volume level and volume limit
byCurVolume = GetHwFeatureValue(IHCAP_VOLUME);
byMaxVol = GetHwFeatureLimit(IHCAP_VOLUME);
// Do nothing if no change in volume level
if (byCurVolume == byVolume)
return(LVLS_NO_ERROR);
// Adjust volume
if (byVolume==VOLUME_UP)
byCurVolume++;
else if (byVolume==VOLUME_DOWN)
byCurVolume--;
else
byCurVolume = byVolume;
// Check new volume level
if (byCurVolume == 0xFF) // Wrap from 0 to FF
byCurVolume = 0;
else if (byCurVolume>byMaxVol)
byCurVolume = byMaxVol;
// Update hardware setting
if (byCurVolume == 0)
{
SetChipAudioMute(TRUE, MUTESRC_VOLUME);
}
else
{
SetChipAudioMute(FALSE, MUTESRC_VOLUME);
byCurVolume--; // Compensate mute level
}
SetChipVolume(byCurVolume);
return(LVLS_NO_ERROR);
} // End AdjustVolume
/* ************************************************************************************************
*
* Function: SetFrequency
*
* Authors: Hung van Le
* Purpose: Set the frequency using display frequency
* Input:
* WORD wDisplayFreq: the frequency to be set in 10 kHz-unit (ie 87.5 MHz is 8750)
* Output: Status as defined in LvErr.h
* Global: g_wLastMsrRF will be updated
* Comments: None
*
* ************************************************************************************************
* Copyright (c) 2004. Semiconductor Ideas to the Market (ItoM) B.V. All rights reserved.
* ************************************************************************************************ */
BYTE SetFrequency(WORD wDisplayFreq)
{
BYTE byResult;
#ifdef SUPPORT_AMFM
if ( (g_byStnFlag & STN_AM_MODE) == STN_AM_MODE )
byResult = SetAmFrequency(wDisplayFreq);
else
byResult = SetRfFrequency(DisplayFreqToRf(wDisplayFreq));
#endif // SUPPORT_AMFM
#ifdef FM_ONLY
byResult = SetRfFrequency(DisplayFreqToRf(wDisplayFreq));
#endif // FM_ONLY
// Report the final status via CallBack before exit
CallBack(CRSN_STN_CHNG);
return(byResult);
} // End SetFrequency
/* ************************************************************************************************
*
* Function: GetDisplayFrequency
*
* Authors: Hung van Le
* Purpose: Derive the display frequency from the current RF frequency
* Input: WORD wSpacing: spacing in 10 kHz unit - see also comment
* Output: The display frequency in 10 kHz unit
* Global: g_wLastMsrRF: the current RF frequency of the radio hardware
* g_wDisplayBandHigh, g_wDisplayBandLow: the current display frequency limit (depends on region)
* Comments: The display frequency = RF frequency + (set_IF_frequency) * IF_phase
* Where:
* RF frequency: current RF oscillator frequency
* Set_IF_frequency: The calibrated IF frequency
* IF_phase: -1 or +1 (-1 for LV2400x)
* The display frequency will be rounded at the display spacing
*
* ************************************************************************************************
* Copyright (c) 2004. Semiconductor Ideas to the Market (ItoM) B.V. All rights reserved.
* ************************************************************************************************ */
WORD GetDisplayFrequency(WORD wSpacing)
{
WORD wDispFreq;
WORD wTmp;
#ifdef SUPPORT_AMFM
if ( (g_byStnFlag & STN_AM_MODE) == STN_AM_MODE )
{
wTmp = FmRfToAmRf(g_wLastMsrRF); // Convert the FM-RF to AM-RF
wDispFreq = RfToDisplayFreq(wTmp); // Convert RF to display frequency
}
else
{
wDispFreq = RfToDisplayFreq(g_wLastMsrRF);
}
#endif // SUPPORT_AMFM
#ifdef FM_ONLY
// Determine the rough display frequency
wDispFreq = RfToDisplayFreq(g_wLastMsrRF);
#endif //FM_ONLY
// Align the Display-Frequency according to spacing
// Verify with display band
if (wDispFreq < g_wDisplayBandLow)
{
wDispFreq = g_wDisplayBandLow;
}
else
{
if (wDispFreq > g_wDisplayBandHigh)
{
wDispFreq = g_wDisplayBandHigh;
}
else
{
wTmp = (wDispFreq % wSpacing);
if ( wTmp != 0 )
{
wDispFreq = wDispFreq - wTmp; // Assume down rounding
if ( wTmp >= (wSpacing/2)) // Rest frequency exceeds half
wDispFreq += wSpacing; // up rounding
}
}
}
return(wDispFreq);
} // End GetDisplayFrequency
/* ************************************************************************************************
*
* Function: SetRegion
*
* Authors: Hung van Le
* Purpose: Set the (FM) radio region
* Input: byRegion: the required region to be set. Supports are:
* REGION_NONE: use hardware limit
* REGION_JAPAN: Japan FM band
* REGION_US: US FM band
* REGION_EUROPE: Europe FM band
* Output: Status as defined in LvErr.h
* Global: g_wHwRfHigh, g_wHwRfLow (RO): for determine the band limits of REGION_NONE
* g_wDisplayBandHigh, g_wDisplayBandLow (W): modified according to band limit of byRegion
* g_byRegion (W): keep track of current region
* Comments: The region are defined Lv24Ekit.h
*
* ************************************************************************************************
* Copyright (c) 2004. Semiconductor Ideas to the Market (ItoM) B.V. All rights reserved.
* ************************************************************************************************ */
BYTE SetRegion(BYTE byRegion)
{
#ifdef SUPPORT_AMFM
if ( (g_byStnFlag & STN_AM_MODE) == STN_AM_MODE )
{
// AM region (band limits are in kHz)
g_wFreqGrid = 9; // Default frequency grid for AM in kHz unit
switch (byRegion)
{
case REGION_EUROPE_AM_MW: // AM MW Europe (522 kHz-1611 kHz, grid=9 kHz) (Also for W-Europe)
g_wDisplayBandLow = 522;
g_wDisplayBandHigh = 1611;
//g_byFreqGrid = 9;
break;
case REGION_JAPAN_AM_MW: // AM MW Japan (522 kHz-1629 kHz, grid=9 kHz)
g_wDisplayBandLow = 522;
g_wDisplayBandHigh = 1629;
//g_byFreqGrid = 9;
break;
case REGION_USA_AM_MW: // AM MW USA (520 kHz-1710 kHz, grid=10 kHz)
g_wDisplayBandLow = 520;
g_wDisplayBandHigh = 1710;
g_wFreqGrid = 10;
break;
//case REGION_AM_LW: // AM LW (146 kHz- 281 kHz, grid=1 kHz) (All regions)
// g_wDisplayBandLow = 146;
// g_wDisplayBandHigh = 281;
// g_wFreqGrid = 1;
// break;
//case REGION_AM_SW: // AM LW (2280 kHz-21850 kHz, grid=5 kHz) (All regions)
// m_wDisplayBandLow = 2280;
// m_wDisplayBandHigh = 21850;
// g_wFreqGrid = 5;
// break;
//case REGION_NONE:
default: // Not suport - force to none
g_wDisplayBandHigh = RfToDisplayFreq(g_wHwRfHigh);
g_wDisplayBandLow = RfToDisplayFreq(g_wHwRfLow);
break;
}
// Update current region
g_byRegion = byRegion;
return(LVLS_NO_ERROR);
}
#endif // SUPPORT_AMFM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -