📄 hid_mouse_sm.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006
Part of BlueLab 3.5.2-release
FILE NAME
hid_mouse_sm.c
DESCRIPTION
This file contains the state machine functions.
NOTES
*/
/****************************************************************************
Header files
*/
#include "hid_mouse.h"
#include "hid_mouse_sm.h"
/*************************************************************************
NAME
appHandleDeferedAction
DESCRIPTION
This function is called to check if there is a defered actions.
RETURNS
void
*/
static void appHandleDeferedAction(appTaskData *theApp)
{
/* Check if we have an unplug pending */
if (theApp->unplug_pending)
{
/* Clear flag */
theApp->unplug_pending = FALSE;
/* Resend unplug message to ourselves */
MessageSend(&theApp->task, APP_INTERNAL_UNPLUG_IND, 0);
}
/* Check if we have an shutdown pending */
if (theApp->shutdown_pending)
{
/* Clear flag */
theApp->shutdown_pending = FALSE;
/* Resend unplug message to ourselves */
MessageSend(&theApp->task, APP_INTERNAL_SHUTDOWN_IND, 0);
}
}
/*************************************************************************
NAME
appExitInitialising
DESCRIPTION
This function is called on exit to the initialising state.
Enables power hold.
RETURNS
void
*/
static void appExitInitialising(appTaskData *theApp)
{
#ifdef HID_MASK_POWER_HOLD
/* Turn power supply on */
PioSet(HID_MASK_POWER_HOLD, HID_MASK_POWER_HOLD);
#endif
}
/*************************************************************************
NAME
appEnterDiscoverable
DESCRIPTION
This function is called on entry to the discoverable state.
Enables inquiry scan, and flashes LED.
RETURNS
void
*/
static void appEnterDiscoverable(appTaskData *theApp)
{
MAIN_PRINT(("appEnterDiscoverable\n"));
/* Delete all trusted devices */
ConnectionSmDeleteAllAuthDevices(APP_MOUSE_ATTR_PS_BASE);
/* Make this device discoverable (inquiry scan), and connectable (page scan) */
ConnectionWriteScanEnable(hci_scan_enable_inq_and_page);
/* Clear host and authorised addresses */
BdaddrSetZero(&theApp->host_bd_addr);
BdaddrSetZero(&theApp->auth_bd_addr);
/* Start discoverable timeout */
MessageSendLater(&theApp->task, APP_INTERNAL_DISCOVERABLE_TIMEOUT_IND, 0, D_SEC(APP_DISCOVERABLE_TIMEOUT));
/* Configure HID transform */
SourceConfigure(StreamHidSource(), VM_SOURCE_HID_IDLE_MODE, 0);
SourceConfigure(StreamHidSource(), VM_SOURCE_HID_SAMPLE_RATE, 0);
/* Flash status LED */
appLedUpdate(&theApp->led, 500, 500, 0);
}
/*************************************************************************
NAME
appExitDiscoverable
DESCRIPTION
Called on exit of discoverable state. Disables inquiry and page scan.
RETURNS
void
*/
static void appExitDiscoverable(appTaskData *theApp)
{
MAIN_PRINT(("appExitDiscoverable\n"));
/* Make this device not connectable */
ConnectionWriteScanEnable(hci_scan_enable_off);
/* Cancel discoverable timeout message */
MessageCancelAll(&theApp->task, APP_INTERNAL_DISCOVERABLE_TIMEOUT_IND);
/* Turn off status LED */
appLedUpdate(&theApp->led, 0, -1, 0);
}
/*************************************************************************
NAME
appEnterCabledConnecting
DESCRIPTION
Called on entry to the connecting state. Attempt to retreive the
trusted device information.
RETURNS
void
*/
static void appEnterCabledConnecting(appTaskData *theApp)
{
MAIN_PRINT(("appEnterCabledConnecting\n"));
/* Attempt to get most recent host, don't care about associated attribute */
ConnectionSmGetIndexedAttribute(APP_MOUSE_ATTR_PS_BASE, theApp->trusted_device_index, 0);
/* Configure HID transform */
SourceConfigure(StreamHidSource(), VM_SOURCE_HID_IDLE_MODE, 0);
SourceConfigure(StreamHidSource(), VM_SOURCE_HID_SAMPLE_RATE, 100);
/* Flash status LED */
appLedUpdate(&theApp->led, 100, 100, 0);
}
/*************************************************************************
NAME
appExitCabledConnecting
DESCRIPTION
Called on exit of the connecting state.
RETURNS
void
*/
static void appExitCabledConnecting(appTaskData *theApp)
{
MAIN_PRINT(("appExitCabledConnecting\n"));
/* Turn off status LED */
appLedUpdate(&theApp->led, 0, -1, 0);
}
/*************************************************************************
NAME
appEnterCabledConnected
DESCRIPTION
Called on entry to the connected state.
Initialises the keyboard state and configures and connects the HID
transform.
RETURNS
void
*/
static void appEnterCabledConnected(appTaskData *theApp)
{
MAIN_PRINT(("appEnterCabledConnected\n"));
/* Set default led, idle rate and protocol */
theApp->mouse_idle_rate = 0;
theApp->mouse_protocol = hid_protocol_report;
/* Configure HID transform */
SourceConfigure(StreamHidSource(), VM_SOURCE_HID_IDLE_MODE, 0);
SourceConfigure(StreamHidSource(), VM_SOURCE_HID_SAMPLE_RATE, 0xFFFF);
/* Connect HID transform in interrupt sink */
PanicFalse(StreamConnect(StreamHidSource(), theApp->interrupt_sink));
/* Get clock offset */
ConnectionReadClockOffset(&theApp->task, theApp->interrupt_sink);
}
/*************************************************************************
NAME
appExitCabledConnected
DESCRIPTION
This function is called when exiting the connected state, reconfigures
the HID source to idle, and disconnects it from the interrupt sink.
RETURNS
void
*/
static void appExitCabledConnected(appTaskData *theApp)
{
MAIN_PRINT(("appExitCabledConnected\n"));
/* Disconnect HID tranform from interrupt sink */
StreamDisconnect(StreamHidSource(), theApp->interrupt_sink);
/* Cancel unplug timeout message */
MessageCancelAll(&theApp->task, APP_INTERNAL_UNPLUG_TIMEOUT_IND);
}
/*************************************************************************
NAME
appEnterCabledDisconnecting
DESCRIPTION
This function is called on entry to the local disconnecting state.
Initiates disconnection if HID connection.
RETURNS
void
*/
static void appEnterCabledDisconnecting(appTaskData *theApp)
{
MAIN_PRINT(("appEnterCabledDisconnecting\n"));
/* Disconnect HID connection */
HidDisconnect(theApp->hid);
}
/*************************************************************************
NAME
appEnterCabledDisconnected
DESCRIPTION
This function is called on entry to the connected state. Make
the device connectable.
RETURNS
void
*/
static void appEnterCabledDisconnected(appTaskData *theApp)
{
MAIN_PRINT(("appEnterCabledDisconnected\n"));
/* Configure HID transform */
SourceConfigure(StreamHidSource(), VM_SOURCE_HID_IDLE_MODE, 0);
SourceConfigure(StreamHidSource(), VM_SOURCE_HID_SAMPLE_RATE, 1000);
/* Make this device not connectable */
ConnectionWriteScanEnable(hci_scan_enable_off);
}
/*************************************************************************
NAME
appEnterIdle
DESCRIPTION
This function is called on entry to the idle state.
Turn off power supply.
RETURNS
void
*/
static void appEnterIdle(appTaskData *theApp)
{
MAIN_PRINT(("appEnterIdle\n"));
#ifdef HID_MASK_POWER_HOLD
/* Turn off power supply */
PioSet(HID_MASK_POWER_HOLD, 0);
#endif
/* Configure HID transform */
SourceConfigure(StreamHidSource(), VM_SOURCE_HID_IDLE_MODE, 0);
SourceConfigure(StreamHidSource(), VM_SOURCE_HID_SAMPLE_RATE, 0);
}
/*************************************************************************
NAME
appExitIdle
DESCRIPTION
This function is called on exit to the idle state.
Enables power hold.
RETURNS
void
*/
static void appExitIdle(appTaskData *theApp)
{
#ifdef HID_MASK_POWER_HOLD
/* Turn power supply on */
PioSet(HID_MASK_POWER_HOLD, HID_MASK_POWER_HOLD);
#endif
}
/*************************************************************************
NAME
appSetState
DESCRIPTION
Called to change state.
Handles calling the state entry and exit functions.
RETURNS
void
*/
void appSetState(appTaskData *theApp, app_state state)
{
/* Handle state exit functions */
switch (theApp->state)
{
case appInitialising:
appExitInitialising(theApp);
break;
case appDiscoverable:
appExitDiscoverable(theApp);
break;
case appCabledConnecting:
appExitCabledConnecting(theApp);
break;
case appCabledConnected:
appExitCabledConnected(theApp);
break;
case appIdle:
appExitIdle(theApp);
break;
default:
break;
}
/* Handle state entry functions */
switch (state)
{
case appDiscoverable:
appEnterDiscoverable(theApp);
break;
case appCabledConnecting:
appEnterCabledConnecting(theApp);
break;
case appCabledConnected:
appEnterCabledConnected(theApp);
break;
case appCabledDisconnecting:
appEnterCabledDisconnecting(theApp);
break;
case appCabledDisconnected:
appEnterCabledDisconnected(theApp);
break;
case appIdle:
appEnterIdle(theApp);
default:
break;
}
/* Set new state */
theApp->state = state;
/* Handle any defered actions */
appHandleDeferedAction(theApp);
}
/*************************************************************************
NAME
appGetState
DESCRIPTION
Returns the current application state.
RETURNS
app_state - Current state.
*/
app_state appGetState(appTaskData *theApp)
{
return theApp->state;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -