You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
5.5 KiB

/******************************************************************************
版权所有 (C), 2018-2099, Radkil
******************************************************************************
文 件 名 : msp_MK32.h
版 本 号 : 初稿
作 者 : radkil
生成日期 : 2026年9月22日
最近修改 :
功能描述 : msp_MK32.c 的头文件
修改历史 :
1.日 期 : 2026年9月22日
作 者 : radkil
修改内容 : 创建文件
******************************************************************************/
/*----------------------------------------------*
* 外部变量说明 *
*----------------------------------------------*/
/*----------------------------------------------*
* 外部函数原型说明 *
*----------------------------------------------*/
/*----------------------------------------------*
* 内部函数原型说明 *
*----------------------------------------------*/
/*----------------------------------------------*
* 全局变量 *
*----------------------------------------------*/
/*----------------------------------------------*
* 模块级变量 *
*----------------------------------------------*/
/*----------------------------------------------*
* 常量定义 *
*----------------------------------------------*/
/*----------------------------------------------*
* 宏定义 *
*----------------------------------------------*/
#ifndef __MSP_MK32_H__
#define __MSP_MK32_H__
#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */
/*==============================================*
* include header files *
*----------------------------------------------*/
/*==============================================*
* constants or macros define *
*----------------------------------------------*/
typedef enum {
MODE_NULL = 0,
MODE_DEFAULT,
MODE_VERTICAL_LEFT,
MODE_VERTICAL_RIGHT,
MODE_MAX
} E_BHBF_RBMode;
typedef enum {
SUB_MODE_NULL = 0,
SUB_MODE_DEFAULT,
SUB_MODE_MAX
} E_BHBF_RBSubMode;
typedef void (*ActionFunc)(void);
#ifdef IS_TABLE
typedef enum {
KEY_SA_UP = 0,
KEY_SA_DOWN,
KEY_SA_DEFAULT,
KEY_SB_UP,
KEY_SB_DOWN,
KEY_SB_DEFAULT,
KEY_SC_UP,
KEY_SC_DOWN,
KEY_SC_DEFAULT,
KEY_SD_UP,
KEY_SD_DOWN,
KEY_SD_DEFAULT,
BTN_S1_CLICK,
BTN_S2_CLICK,
JOY_LEFT_UP,
JOY_LEFT_DWON,
JOY_LEFT_LEFT,
JOY_LEFT_RIGHT,
JOY_RIGHT_UP,
JOY_RIGHT_DWON,
JOY_RIGHT_LEFT,
JOY_RIGHT_RIGHT,
JOY_DEFAULT,
E_STOP, // 急停,MK32指SE和SF值-1000
KEY_MAX
} E_BHBF_KEY;
extern const ActionFunc g_ActionTable[KEY_MAX][MODE_MAX][SUB_MODE_MAX];
#define SAFE_DISPATCH(key) \
do { \
if ((key) < KEY_MAX) \
{ \
ActionFunc _fn = g_ActionTable[(key)][(_iMode)][(_iSubMode)]; \
if (_fn) _fn(); \
} \
} while (0)
#else
typedef struct{
E_BHBF_RBMode m_iMode; //主模式
E_BHBF_RBSubMode m_iSubMode; //副模式
ActionFunc m_ptFunc; //执行函数
} TKeyTree;
typedef struct {
TKeyTree E_Stop[MODE_MAX*SUB_MODE_MAX];
TKeyTree SA_Up[MODE_MAX*SUB_MODE_MAX];
TKeyTree SA_Down[MODE_MAX*SUB_MODE_MAX];
TKeyTree SA_Default[MODE_MAX*SUB_MODE_MAX];
TKeyTree SB_Up[MODE_MAX*SUB_MODE_MAX];
TKeyTree SB_Down[MODE_MAX*SUB_MODE_MAX];
TKeyTree SC_Up[MODE_MAX*SUB_MODE_MAX];
TKeyTree SC_Down[MODE_MAX*SUB_MODE_MAX];
TKeyTree SC_Default[MODE_MAX*SUB_MODE_MAX];
TKeyTree Joy_Default[MODE_MAX*SUB_MODE_MAX];
TKeyTree Joy_Left_Up[MODE_MAX*SUB_MODE_MAX];
TKeyTree Joy_Left_Down[MODE_MAX*SUB_MODE_MAX];
TKeyTree Joy_Left_Left[MODE_MAX*SUB_MODE_MAX];
TKeyTree Joy_Left_Right[MODE_MAX*SUB_MODE_MAX];
} TKeyForest;
extern const TKeyForest g_ActionTable;
static inline void SafeDispatch(const TKeyTree *table, int count, int mode, int sub_mode)
{
for (int i = 0; i < count; i++)
{
if (table[i].m_iMode == mode && table[i].m_iSubMode == sub_mode)
{
if (table[i].m_ptFunc != NULL)
{
table[i].m_ptFunc();
}
return;
}
}
for (int i = 0; i < count; i++)
{
if (table[i].m_iMode == mode && table[i].m_iSubMode == SUB_MODE_DEFAULT)
{
if (table[i].m_ptFunc != NULL)
{
table[i].m_ptFunc();
}
return;
}
}
for (int i = 0; i < count; i++)
{
if (table[i].m_iMode == MODE_DEFAULT && table[i].m_iSubMode == SUB_MODE_DEFAULT)
{
if (table[i].m_ptFunc != NULL)
{
table[i].m_ptFunc();
}
return;
}
}
}
#define SAFE_DISPATCH(field) \
SafeDispatch(g_ActionTable.field, \
sizeof(g_ActionTable.field) / sizeof(TKeyTree), \
_iMode, _iSubMode)
#endif
/*==============================================*
* project-wide global variables *
*----------------------------------------------*/
/*==============================================*
* routines' or functions' implementations *
*----------------------------------------------*/
void MK32_Key_Func(SP_MSP_MK32_Button *_pstMK32, int _iMode, int _iSubMode);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* __MSP_MK32_H__ */