📄 keyin_m04_c2.c
字号:
/****************************************************************************************************/
/*$Header :
/* AUTHOR : TC PUI
/* FILE NAME: KEYIN.C
/* PURPOSE : KEY CONTROL
/* MODEL : 2003 CIS MODEL (KEYPAD)
/* Copyright (c) 2002 Sony Corporation All Rights Reserved
/****************************************************************************************************/
#define _KEYCNT_C
#include "_main_M04_C2.h"
/****************************************************************************************************/
/* local variables definition which are refered only this file
/****************************************************************************************************/
#define _KEY_NUM 2
typedef union keyflag {
struct keybit {
unsigned char bit7 :1;
unsigned char bit6 :1;
unsigned char bit5 :1;
unsigned char bit4 :1;
unsigned char bit3 :1;
unsigned char slp :1; /* u-com sleep request flag */
unsigned char fst :1; /* input first flag */
unsigned char req :1; /* event request flag */
} bit;
unsigned char byte;
} KEYFLAG_;
typedef struct keyport {
unsigned int buff; /* key id buffer */
unsigned int stat; /* key port state */
unsigned int time; /* key port timer */
KEYFLAG_ flag; /* key port flag */
} KEY_;
KEY_ _key[_KEY_NUM]; /* key struct data */
unsigned int _mltplxkey_time;
/****************************************************************************************************/
/* static variable definition
/****************************************************************************************************/
static unsigned char GetADKeyId(unsigned char ch);
static unsigned char GetKeyAct(unsigned char id, unsigned char ch);
/****************************************************************************************************/
/* static define value
/****************************************************************************************************/
#define _ADV_NUM 9 /* number of a/d value */
#define _ADL_NUM 8 /* DONT'T CHANGE!! : total a/d line for micom */
/* Ad Channel Define */
#define ADC_CH0 0 /* A/D Converter Channel 0 */
#define ADC_CH1 1 /* A/D Converter Channel 1 */
#define ADC_CH2 2 /* A/D Converter Channel 2 */
#define ADC_CH3 3 /* A/D Converter Channel 3 */
#define ADC_CH4 4 /* A/D Converter Channel 4 */
#define ADC_CH5 5 /* A/D Converter Channel 5 */
#define ADC_CH6 6 /* A/D Converter Channel 6 */
#define ADC_CH7 7 /* A/D Converter Channel 7 */
/* Ad Threshold Value */
#define _ADTH_KOFF 976 /* a/d threshold: key off */
#define _ADTH_KEY7 876 /* a/d threshold: key 6 */
#define _ADTH_KEY6 758 /* a/d threshold: key 5 */
#define _ADTH_KEY5 600 /* a/d threshold: key 4 */
#define _ADTH_KEY4 435 /* a/d threshold: key 3 */
#define _ADTH_KEY3 302 /* a/d threshold: key 2 */
#define _ADTH_KEY2 166 /* a/d threshold: key 1 */
#define _ADTH_KEY1 42 /* a/d threshold: key 0 */
#define _ADTH_KEY0 0 /* a/d threshold: key 0 */
/* GetKeyAct */
#define _KEYOFF 0x00 /* key action : off */
#define _KEY1ST 0x01 /* key action : on first */
#define _KEYCNT 0x02 /* key action : on continue */
#define _UNKNWN 0xff /* key action : unknown */
#define _CHATOK 3 /* key state : chattering o.k. count */
#define _KEY1TRG 0x80 /* key state : key on first trigger */
#define _KEYEND 0xff /* key state : conunt up end value */
/****************************************************************************************************/
/* FUNCTION : IniKey
/* PURPOSE : key initialize
/* INPUT : None
/* RETURN VALUE : None
/****************************************************************************************************/
void KeyInitialize(void)
{
unsigned char i;
for (i=0; i<_KEY_NUM; i++) {
_key[i].buff = K_OFF; /* key buffer */
_key[i].stat = CLEAR; /* key state */
_key[i].time = CLEAR; /* key timer */
_key[i].flag.byte = CLEAR; /* key flag */
}
ADC1.BYTE = 0x01; /* start A/D conversion */
ADC2.BYTE = 0x01;
IDSwitch.Learn = OFF;
IDSwitch.Test = OFF;
IDSwitch.IDNum = SIRCOM_ID1;
_mltplxkey_time = _500mS;
return;
}
/****************************************************************************************************/
/* FUNCTION : KeyControl
/* PURPOSE : key control
/* INPUT : None
/* RETURN VALUE : None
/****************************************************************************************************/
void KeyControl(void)
{
static const unsigned int KeyEventTable[MAX_KEY] = {
EV_NOP, /* 000 K_OFF = 0, */
EV_KEYPOWERONOFF, /* 001 K_POWERONOFF, */
EV_KEYPOWERON, /* 002 K_POWERON, */
EV_KEYPOWEROFF, /* 003 K_POWEROFF, */
EV_KEYVOLUP, /* 004 K_VOLUMEUP, */
EV_KEYVOLDW, /* 005 K_VOLUMEDW, */
EV_KEYMUTING, /* 006 K_MUTING, */
};
unsigned int event, tasktm;
unsigned char task = FALSE, id, act;
if (sircs_out_stt == _SOUT_END){
IDSircsIn(); /* ID switch for SIRCS input */
if (IDSwitch.Test == ON){
P_SPK_RELAY = OFF;
}
if(Is10msATimeOver(&siro_time) == FALSE){ /* No key detection */
return;
}
if (keysts < _KEY_NUM){
id = GetADKeyId(keysts); /* get a/d key id */
act = GetKeyAct(id, keysts); /* get key action */
if (act == _KEYOFF) { /* flag & ch control */
_key[keysts].flag.bit.req = _key[keysts].flag.bit.fst = CLEAR;
} else if (act == _KEY1ST) {
_key[keysts].flag.bit.req = _key[keysts].flag.bit.fst = SET;
}
event = EV_NOP; /* clear event no.(fail safe) */
if ((_key[keysts].flag.bit.req)/* && ((_key[keysts].flag.bit.fst) || (Is10msATimeOver(&_key[keysts].time)))*/) {
event = KeyEventTable[id];
if (_key[keysts].flag.bit.fst) {
task = TRUE ;
} else {
task = FALSE ;
}
tasktm = EventExecute(event, task);
_key[keysts].flag.bit.fst = CLEAR; /* key on first flag clear */
if (tasktm == NULL) {
_key[keysts].flag.bit.req = CLEAR; /* key on request flag clear */
} else {
_key[keysts].time = tasktm;
}
}
}
if (++keysts >= _KEY_NUM){
keysts = CLEAR;
}
}
return;
}
/****************************************************************************************************/
/* FUNCTION : KeyControl_0
/* PURPOSE : key control outside for loop
/* INPUT : None
/* RETURN VALUE : None
/****************************************************************************************************/
void KeyControl_0(void)
{
unsigned char i,id;
if (Is10msAInterval()) {
IDSircsIn(); /* ID switch for SIRCS input */
for (i = 0; i < _KEY_NUM; i++) {
if (i < _KEY_NUM) {
id = GetADKeyId(i); /* get a/d key id */
GetKeyAct(id, i); /* get key action */
}
}
}
return;
}
/****************************************************************************************************/
/* FUNCTION : GetADKeyId
/* PURPOSE : get adkey id
/* INPUT : ad channel
/* RETURN VALUE : None
/****************************************************************************************************/
static unsigned char GetADKeyId(unsigned char ch)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -