Added new \ref SPI_GetCurrentMode() function to the SPI peripheral driver.
[pub/USBasp.git] / Demos / Host / Incomplete / BluetoothHost / BluetoothEvents.c
index 5996f30..f5a9eec 100644 (file)
@@ -1,13 +1,13 @@
 /*\r
              LUFA Library\r
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2010.\r
+     Copyright (C) Dean Camera, 2011.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
-      www.fourwalledcubicle.com\r
+           www.lufa-lib.org\r
 */\r
 \r
 /*\r
 */\r
 \r
 /*\r
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
 /** Pointer to the opened Bluetooth ACL channel structure for RFCOMM, used to send and receive data between the\r
  *  local and remote device once a RFCOMM channel has been opened.\r
  */\r
 /** Pointer to the opened Bluetooth ACL channel structure for RFCOMM, used to send and receive data between the\r
  *  local and remote device once a RFCOMM channel has been opened.\r
  */\r
-Bluetooth_Channel_t* RFCOMMChannel = NULL;\r
+Bluetooth_Channel_t* SerialChannel_ACL    = NULL;\r
 \r
 /** Pointer to the opened RFCOMM logical channel between local and remote device, once a RFCOMM ACL channel has been\r
  *  negotiated and a logical RFCOMM channel requested.\r
  */\r
 \r
 /** Pointer to the opened RFCOMM logical channel between local and remote device, once a RFCOMM ACL channel has been\r
  *  negotiated and a logical RFCOMM channel requested.\r
  */\r
-RFCOMM_Channel_t* SerialPortChannel = NULL;\r
+RFCOMM_Channel_t*    SerialChannel_RFCOMM = NULL;\r
 \r
 /** Bluetooth stack callback event for when the Bluetooth stack has fully initialized using the attached\r
  *  Bluetooth dongle.\r
 \r
 /** Bluetooth stack callback event for when the Bluetooth stack has fully initialized using the attached\r
  *  Bluetooth dongle.\r
@@ -115,68 +115,80 @@ void Bluetooth_DisconnectionComplete(void)
  */\r
 bool Bluetooth_ChannelConnectionRequest(const uint16_t PSM)\r
 {\r
  */\r
 bool Bluetooth_ChannelConnectionRequest(const uint16_t PSM)\r
 {\r
-       /* Always accept channel connection requests regardless of PSM */\r
-       return true;\r
+       /* Only accept connections for channels that will be used for RFCOMM or SDP data */\r
+       return ((PSM == CHANNEL_PSM_RFCOMM) || (PSM == CHANNEL_PSM_SDP));\r
 }\r
 \r
 /** Bluetooth stack callback event for when a Bluetooth ACL channel has been fully created and configured,\r
  *  either at the request of the local device, or the remote device.\r
  *\r
 }\r
 \r
 /** Bluetooth stack callback event for when a Bluetooth ACL channel has been fully created and configured,\r
  *  either at the request of the local device, or the remote device.\r
  *\r
- *  \param[in] Channel  Bluetooth ACL data channel information structure for the channel that can now be used\r
+ *  \param[in] ACLChannel  Bluetooth ACL data channel information structure for the channel that can now be used\r
  */\r
  */\r
-void Bluetooth_ChannelOpened(Bluetooth_Channel_t* const Channel)\r
+void Bluetooth_ChannelOpened(Bluetooth_Channel_t* const ACLChannel)\r
 {\r
        /* Save the RFCOMM channel for later use when we want to send RFCOMM data */\r
 {\r
        /* Save the RFCOMM channel for later use when we want to send RFCOMM data */\r
-       if (Channel->PSM == CHANNEL_PSM_RFCOMM)\r
-         RFCOMMChannel = Channel;\r
+       if (ACLChannel->PSM == CHANNEL_PSM_RFCOMM)\r
+         SerialChannel_ACL = ACLChannel;\r
 }\r
 \r
 /** Bluetooth stack callback event for a non-signal ACL packet reception. This callback fires once a connection\r
 }\r
 \r
 /** Bluetooth stack callback event for a non-signal ACL packet reception. This callback fires once a connection\r
- *  to a remote Bluetooth device has been made, and the remote device has sent a non-signalling ACL packet.\r
+ *  to a remote Bluetooth device has been made, and the remote device has sent a non-signaling ACL packet.\r
  *\r
  *\r
- *  \param[in] Data     Pointer to a buffer where the received data is stored\r
- *  \param[in] DataLen  Length of the packet data, in bytes\r
- *  \param[in] Channel  Bluetooth ACL data channel information structure for the packet's destination channel\r
+ *  \param[in] Data        Pointer to a buffer where the received data is stored\r
+ *  \param[in] DataLen     Length of the packet data, in bytes\r
+ *  \param[in] ACLChannel  Bluetooth ACL data channel information structure for the packet's destination channel\r
  */\r
  */\r
-void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* const Channel)\r
+void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* const ACLChannel)\r
 {\r
        /* Run the correct packet handler based on the received packet's PSM, which indicates the service being carried */\r
 {\r
        /* Run the correct packet handler based on the received packet's PSM, which indicates the service being carried */\r
-       switch (Channel->PSM)\r
+       switch (ACLChannel->PSM)\r
        {\r
                case CHANNEL_PSM_SDP:\r
                        /* Service Discovery Protocol packet */\r
        {\r
                case CHANNEL_PSM_SDP:\r
                        /* Service Discovery Protocol packet */\r
-                       SDP_ProcessPacket(Data, Channel);\r
+                       SDP_ProcessPacket(Data, ACLChannel);\r
                        break;\r
                case CHANNEL_PSM_RFCOMM:\r
                        /* RFCOMM (Serial Port) Protocol packet */\r
                        break;\r
                case CHANNEL_PSM_RFCOMM:\r
                        /* RFCOMM (Serial Port) Protocol packet */\r
-                       RFCOMM_ProcessPacket(Data, Channel);\r
-                       break;\r
-               default:\r
-                       /* Unknown Protocol packet */\r
-                       printf_P(PSTR("Unknown Packet Received (Channel 0x%04X, PSM: 0x%02X, Len: 0x%04X):\r\n"),\r
-                                     Channel->LocalNumber, Channel->PSM, DataLen);                     \r
+                       RFCOMM_ProcessPacket(Data, ACLChannel);\r
                        break;\r
        }\r
 }\r
 \r
                        break;\r
        }\r
 }\r
 \r
-void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const Channel)\r
+/** RFCOMM layer callback for event for when a RFCOMM logical channel has been fully opened and configured between\r
+ *  the local and remote device. Once open, this RFCOMM channel can be read from and written to freely until is it\r
+ *  closed by either end.\r
+ *\r
+ *  \param[in] RFCOMMChannel  RFCOMM channel that was opened\r
+ */ \r
+void RFCOMM_ChannelOpened(RFCOMM_Channel_t* const RFCOMMChannel)\r
 {\r
        /* Save the serial port RFCOMM logical channel for later use */\r
 {\r
        /* Save the serial port RFCOMM logical channel for later use */\r
-       SerialPortChannel = Channel;\r
+       SerialChannel_RFCOMM = RFCOMMChannel;\r
 }\r
 \r
 }\r
 \r
-/** RFCOMM layer callback for when a packet is received on an open RFCOMM channel.\r
+/** RFCOMM layer callback event for when a packet is received on an open RFCOMM channel.\r
  *\r
  *\r
- *  \param[in] Channel  RFCOMM channel that the data was directed to\r
- *  \param[in] DataLen  Length of the received data, in bytes\r
- *  \param[in] Data     Pointer to a buffer where the received data is stored\r
+ *  \param[in] ACLChannel  RFCOMM ACL channel that the data was directed to\r
+ *  \param[in] DataLen     Length of the received data, in bytes\r
+ *  \param[in] Data        Pointer to a buffer where the received data is stored\r
  */\r
  */\r
-void RFCOMM_DataReceived(RFCOMM_Channel_t* const Channel, uint16_t DataLen, const uint8_t* Data)\r
+void RFCOMM_DataReceived(RFCOMM_Channel_t* const ACLChannel, uint16_t DataLen, const uint8_t* Data)\r
 {\r
        /* Write the received bytes to the serial port */\r
        for (uint8_t i = 0; i < DataLen; i++)\r
          putchar(Data[i]);\r
        \r
        /* Echo the data back to the sending device */\r
 {\r
        /* Write the received bytes to the serial port */\r
        for (uint8_t i = 0; i < DataLen; i++)\r
          putchar(Data[i]);\r
        \r
        /* Echo the data back to the sending device */\r
-       RFCOMM_SendData(DataLen, Data, Channel, RFCOMMChannel);\r
+       RFCOMM_SendData(DataLen, Data, SerialChannel_RFCOMM, SerialChannel_ACL);\r
+}\r
+\r
+/** RFCOMM layer callback event for when the remote device has updated the channel terminal control signals\r
+ *  for a particular RFCOMM channel.\r
+ *\r
+ *  \param[in] RFCOMMChannel  RFCOMM logical channel whose signals were altered\r
+ */ \r
+void RFCOMM_ChannelSignalsReceived(RFCOMM_Channel_t* const RFCOMMChannel)\r
+{\r
+       // Currently do nothing in response to the remote device sending new terminal control signals\r
 }\r
 }\r
+