#include "platform.h"
#include "hal_headfile.h"
#include "system.h"
#include "debug.h"
#include "config.h"
#include "key.h"
#include "led.h"
#include "deal.h"

// 2. ENC ON/OFF 输入控制:          GPIO02输入    低电平有效     开机默认ENC ON
// 3. 声音输出 DEMUTE/MUTE控制 :    GPIO03输入   低电平有效      开机默认声音输出DEMUTE

#define   KEY_ENC_ON     HOLD_KEY1_UP
#define   KEY_ENC_OFF    HOLD_KEY1_DOWN

#define   KEY_MUTE_OFF   HOLD_KEY2_UP
#define   KEY_MUTE_ON    HOLD_KEY2_DOWN

void deal_key(void)
{
    uint8_t key_value = 0;
    key_value = key_scan();

    if (key_value == KEY_NULL)
    {
        return;
    }

    debug("key_value = %d\r\n", key_value);

    switch (key_value)
    {
    case KEY_UP:
        break;

    case KEY_DOWN:
        break;

    case KEY_LEFT:
        break;

    case KEY_RIGHT:
        break;

    case KEY_OK:
        break;

    case KEY_POWERON:
        break;

    case KEY_POWEROFF:
        break;

    case KEY_ENC_ON:
        //debug("KEY_ENC_ON\r\n");
    	aec_param.enable = ENABLE;
        led_denoise_set(ENABLE);
        break;

    case KEY_ENC_OFF:
        //debug("KEY_ENC_OFF\r\n");
    	aec_param.enable = DISABLE;
        led_denoise_set(DISABLE);
        break;

    case KEY_MUTE_ON:
        //debug("KEY_MUTE_ON\r\n");
        codec_dac_set_volume(0);
        led_mute_set(ENABLE);
        break;

    case KEY_MUTE_OFF:
        //debug("KEY_MUTE_OFF\r\n");
        led_mute_set(DISABLE);
        codec_dac_set_volume(aec_param.hp_volume);
        break;
    }
}
