key_scan.h 4.06 KB
#ifndef	_KEY_SCAN_H_
#define	_KEY_SCAN_H_

#include "app_i2c.h"

#define TOP_OPEN		1
#define TOP_CLOSE		0
#define HOLD_ON			1
#define HOLD_OFF		0

enum {
	KEY_DOWN,
	KEY_UP,
	KEY_HOLD
};


#if(defined OTK5283P || defined OTK5282P)
//*** *********************************************************
//* ----------------------------------------------------------
//* Batter Voltage Range | Corresponding ADC Voltage Value    |
//*  4.2V                | 0xE8B                              |
//*  4.1V                | 0xE31                              |
//*  4.0V                | 0xDDA                              |
//*  3.9V                | 0xD82                              |
//*  3.8V                | 0xD2B                              |
//*  3.7V                | 0xCD3                              |
//*  3.6V                | 0xC78                              |
//*  3.5V                | 0xC1F                              |
//*  3.4V                | 0xBC3                              |
//*  3.3V                | 0xB6F                              |
//*  3.2V                | 0xB11                              |
//*  3.1V                | 0xABD                              |
//*  3.0V                | 0xA60                              |
//*  2.9V                | 0xA05
//*  2.85V               | 0x9D9                              |
//* ----------------------------------------------------------               
//* below "P" means Percent(%)
//* It needs constant current of using 0.2c-0.3c or 1c to charge during 3.2-4.2v. 
//* Standard charging mothed: 0.2C constant current, 4.2V constant voltage charge to 4.2,continue 
//* charging nutill current decline to less than 0.01C.

    #define BATT_VOL_TRICKLE  0xA60  // it needs to tickle charge while battery level is less than 3.0v
    #define BATT_VOL_LOW      0xC1F  // @3.5v 0.2C dischanging curve
    #define BATT_VOL_20P      0xC78  // @3.6v 0.2C dischanging curve
    #define BATT_VOL_MID      0xD2B  // @3.7v 0.2C dischanging curve
    #define BATT_VOL_70P      0xD2B  // @3.8v 0.2C dischanging curve
    #define BATT_VOL_80P      0xD82  // @3.9v 0.2C dischanging curve
    #define BATT_VOL_90P      0xDDA  // @4.0v 0.2C dischanging curve
    #define BATT_VOL_FULL     0xE8B  // @4.2v-4.0v
    #define BATT_VOL_PWE_OFF  0xC00 

    
    enum {
           enBATT_VOL_00P,
           enBATT_VOL_10P,
           enBATT_VOL_20P,
           enBATT_VOL_50P =5,
           enBATT_VOL_70P =7,
           enBATT_VOL_80P,
           enBATT_VOL_90P,
           enBATT_VOL_100P,
        };

    #define ADAPTER_DET_PIN              GPIO2_11_INDEX

    #if 1
    #define ADAPTER_DET_PIN_INPUT_SET    GPIO_MUXFUNCTION_SELECT(ADAPTER_DET_PIN, MUX_SEL_GPIO_INPUT)
    #else 
    #define PIN_HIGH_TEST    GPIO_MUXFUNCTION_SELECT(ADAPTER_DET_PIN, MUX_SEL_GPIO_OUTPUT);\
                             GPIO_OUTPUT_LEVEL_SET  (ADAPTER_DET_PIN, GPIO_HIGH)

    #define PIN_LOW_TEST     GPIO_MUXFUNCTION_SELECT(ADAPTER_DET_PIN, MUX_SEL_GPIO_OUTPUT);\
                             GPIO_OUTPUT_LEVEL_SET  (ADAPTER_DET_PIN, GPIO_LOW)
    #endif
#endif



extern U8 top_status;


void KeyScan_init(void);
void KeyScan_open (void);
void KeyScan_close (void);
void KeyScan_fini (void);
void vAdTask(void); 
void KeyScan_repeat_enable (void);
void KeyScan(U32 ticks);

U8 hold_key_detect (void);
U8 top_key_detect(void);
U8 cd_open_close_key_detect(void);

U8 PLAY_key_detect(void);
U8 resume_key_detect(void);
void vAd0MapMainKey (U16 *key_ad);
void vAd1MapMainKey (U16 *key_ad);
void vAd2MapMainKey (U16 *key_ad);
void vRemoteMapMainKey(U32 *key_ad);
void vRemoteCDMapMainKey(U16 *key_ad);
void vRemoteUSBMapMainKey(U16 *key_ad);

U8 rotary_KeyScan(void);

U8 USB_Detect(void);
U8 PowerOff_Detect(void);

void cd_input_timer_handler(void);
void power_protect_polling(void);
void amp_protect_polling(void);

void bt_auto_connected_polling(void);
void bt_auto_disconnected_polling(void);


void headphone_detect_polling(void);
void mic_external_detect_polling(void);

void battery_energy_indicator(U16 average);
static void print_no_battery_or_is_bad (void);

extern volatile U8 NTCdetect;


#endif //_KEY_SCAN_H_