面向对象写单片机程序-程序分层
typedef struct InputDevice {
char *name;
int (*GetInputEvent)(PInputEvent ptInputEvent);
int (*DeviceInit)(void);
int (*DeviceExit)(void);
struct InputDevice *pNext;
}InputDevice, *PInputDevice;
static PInputDevice g_ptInputDevices;
void InitInputDevices(void)
{
PInputDevice pDev = g_ptInputDevices;
while(pDev)
{
pDev->DeviceInit();
pDev = pDev->pNext;
}
}
......
static int GPIOKeyInit(void)
{
KAL_GPIOKkeyInit();
return 0;
}
static InputDevice g_tKeyDevice = {
"gpio_key",
NULL,
GPIOKeyInit,
NULL,
};
- KAL(Kernel Abstract Layer):设备抽象层
void KAL_GPIOKkeyInit(void)
{
#if defined(CONFIG_NOOS)
CAL_GPIOKkeyInit();
#elif defined(CONFIG_FREERTOS)
FreeRTOS_GPIOKkeyInit();
#elif defined(CONFIG_RTTHREAD)
RTTread_GPIOKkeyInit();
#endif
}
- CAL(Chip Abstract Layer):芯片抽象层
void CAL_GPIOKkeyInit(void)
{
#if defined(CONFIG_ST_HAL)
KEY_GPIO_ReInit();
#else
MY_KEY_GPIO_ReInit
#endif
}