📄 hal.c
字号:
/*
Rather small Hardware Abstraction Layer (HAL) for headset
*/
#include "hal.h"
#include <codec.h>
#include <pio.h>
/* TODO tidy this up once the new traps are supported by the firmware */
/* Scale the supplied gain to be within the specified range */
static uint16 scaleGainToRange(uint8 gain, uint16 max_range, uint16 max_gain)
{
return (((((gain * 10) * max_range)/max_gain) + 5)/10);
}
/*
HALsetVolume
Set the headset speaker volume.
*/
void HALsetVolume(uint8 vol)
{
uint16 scaled_val = 0;
/* Get the range supported by the codec */
uint16 range = CodecOutputGainRange() - 1;
/* If the range is zero don't bother setting anything */
if (!range)
return;
/* If the range is not zero scale the gain to be in that range */
scaled_val = scaleGainToRange(vol, range, 15);
/* Set the codec gain */
CodecSetOutputGain(scaled_val);
}
/*
HALsetLED
Set the state of an LED. For this example the leds are just
mapped directly to PIO lines.
*/
/*lint -esym(759, HALsetLED) -esym(765,HALsetLED) -esym(714,HALsetLED) */
void HALsetLED(uint8 bit, uint8 state)
{
PioSet(bit, bit*state);
}
/*
HALsetMicrophone
Set the headset microphone gain.
*/
void HALsetMicrophone(uint8 gain)
{
uint16 scaled_val = 0;
/* Get the range supported by the codec */
uint16 range = CodecInputGainRange() - 1;
/* If the range is zero don't bother setting anything */
if (!range)
return;
/* If the range is not zero scale the gain to be in that range */
scaled_val = scaleGainToRange(gain, range, 15);
/* Set the codec gain */
CodecSetInputGain(scaled_val);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -