+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#define INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C\r
-#include "BluetoothACLPackets.h"\r
-\r
-void Bluetooth_ProcessACLPackets(void)\r
-{\r
- Bluetooth_ACL_Header_t ACLPacketHeader;\r
-\r
- Pipe_SelectPipe(BLUETOOTH_DATA_IN_PIPE);\r
- Pipe_SetToken(PIPE_TOKEN_IN);\r
- Pipe_Unfreeze();\r
- \r
- if (!(Pipe_ReadWriteAllowed()))\r
- {\r
- Pipe_Freeze();\r
- return;\r
- }\r
- \r
- Pipe_Read_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));\r
- \r
- Bluetooth_DataPacket_Header_t DataHeader;\r
- Pipe_Read_Stream_LE(&DataHeader, sizeof(DataHeader));\r
-\r
- BT_DEBUG("(ACL) Packet Received", NULL);\r
- BT_DEBUG("(ACL) -- Connection Handle: 0x%04X", ACLPacketHeader.ConnectionHandle);\r
- BT_DEBUG("(ACL) -- Data Length: 0x%04X", ACLPacketHeader.DataLength);\r
- BT_DEBUG("(ACL) -- Destination Channel: 0x%04X", DataHeader.DestinationChannel);\r
- BT_DEBUG("(ACL) -- Payload Length: 0x%04X", DataHeader.PayloadLength);\r
-\r
- if (DataHeader.DestinationChannel == BLUETOOTH_CHANNEL_SIGNALING)\r
- {\r
- Bluetooth_SignalCommand_Header_t SignalCommandHeader;\r
- Pipe_Read_Stream_LE(&SignalCommandHeader, sizeof(SignalCommandHeader));\r
-\r
- switch (SignalCommandHeader.Code)\r
- {\r
- case BLUETOOTH_SIGNAL_CONNECTION_REQUEST:\r
- Bluetooth_ProcessSignalPacket_ConnectionRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
- break;\r
- case BLUETOOTH_SIGNAL_CONFIGURATION_REQUEST:\r
- Bluetooth_ProcessSignalPacket_ConfigurationRequest(&ACLPacketHeader, &DataHeader, &SignalCommandHeader);\r
- break; \r
- default:\r
- BT_DEBUG("(ACL) >> Unknown Signalling Command 0x%02X", SignalCommandHeader.Code);\r
- \r
- Pipe_Discard_Stream(ACLPacketHeader.DataLength);\r
- Pipe_ClearCurrentBank(); \r
- Pipe_Freeze();\r
- break;\r
- }\r
- }\r
- else\r
- {\r
- uint8_t DataPayload[DataHeader.PayloadLength];\r
- Pipe_Read_Stream_LE(&DataPayload, sizeof(DataPayload));\r
- DataHeader.PayloadLength = 0;\r
- \r
- BT_DEBUG("(ACL) -- Data Payload: ", NULL);\r
- for (uint16_t B = 0; B < sizeof(DataPayload); B++)\r
- printf("0x%02X ", DataPayload[B]);\r
- BT_DEBUG("", NULL);\r
-\r
- Pipe_Discard_Stream(ACLPacketHeader.DataLength);\r
- Pipe_ClearCurrentBank(); \r
- Pipe_Freeze();\r
- }\r
-}\r
-\r
-static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
- Bluetooth_DataPacket_Header_t* DataHeader,\r
- Bluetooth_SignalCommand_Header_t* SignalCommandHeader)\r
-{\r
- Bluetooth_SignalCommand_ConnectionRequest_t ConnectionRequest;\r
- \r
- Pipe_Read_Stream_LE(&ConnectionRequest, sizeof(ConnectionRequest));\r
-\r
- BT_DEBUG("(ACL) >> L2CAP Connection Request", NULL);\r
- BT_DEBUG("(ACL) -- PSM: 0x%04X", ConnectionRequest.PSM);\r
- BT_DEBUG("(ACL) -- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);\r
- \r
- Pipe_ClearCurrentBank();\r
- Pipe_Freeze();\r
- Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
- Pipe_SetToken(PIPE_TOKEN_OUT);\r
- Pipe_Unfreeze();\r
- \r
- Bluetooth_SignalCommand_ConnectionResponse_t ConnectionResponse;\r
-\r
- ACLPacketHeader->DataLength = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(ConnectionResponse);\r
- DataHeader->PayloadLength = sizeof(*SignalCommandHeader) + sizeof(ConnectionResponse);\r
- DataHeader->DestinationChannel = BLUETOOTH_CHANNEL_SIGNALING;\r
- SignalCommandHeader->Code = BLUETOOTH_SIGNAL_CONNECTION_RESPONSE;\r
- SignalCommandHeader->Length = sizeof(ConnectionResponse);\r
- \r
- Bluetooth_Channel_t* ChannelData = Bluetooth_InitChannelData(ConnectionRequest.SourceChannel, ConnectionRequest.PSM);\r
- \r
- ConnectionResponse.Result = (ChannelData == NULL) ? BLUETOOTH_CONNECTION_REFUSED_RESOURCES :\r
- BLUETOOTH_CONNECTION_SUCCESSFUL;\r
- ConnectionResponse.DestinationChannel = ChannelData->LocalNumber;\r
- ConnectionResponse.SourceChannel = ChannelData->RemoteNumber;\r
- ConnectionResponse.Status = 0x00;\r
-\r
- Pipe_Write_Stream_LE(ACLPacketHeader, sizeof(*ACLPacketHeader));\r
- Pipe_Write_Stream_LE(DataHeader, sizeof(*DataHeader));\r
- Pipe_Write_Stream_LE(SignalCommandHeader, sizeof(*SignalCommandHeader));\r
- Pipe_Write_Stream_LE(&ConnectionResponse, sizeof(ConnectionResponse));\r
- \r
- Pipe_ClearCurrentBank(); \r
- Pipe_Freeze();\r
- \r
- BT_DEBUG("(ACL) Packet Sent", NULL);\r
- BT_DEBUG("(ACL) -- Connection Handle: 0x%04X", ACLPacketHeader->ConnectionHandle);\r
- BT_DEBUG("(ACL) -- Data Length: 0x%04X", ACLPacketHeader->DataLength);\r
- BT_DEBUG("(ACL) -- Destination Channel: 0x%04X", DataHeader->DestinationChannel);\r
- BT_DEBUG("(ACL) -- Payload Length: 0x%04X", DataHeader->PayloadLength); \r
- BT_DEBUG("(ACL) >> L2CAP Connection Response", NULL);\r
- BT_DEBUG("(ACL) -- Source Channel: 0x%04X", ConnectionResponse.SourceChannel);\r
- BT_DEBUG("(ACL) -- Destination Channel: 0x%04X", ConnectionResponse.DestinationChannel);\r
-}\r
-\r
-static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
- Bluetooth_DataPacket_Header_t* DataHeader,\r
- Bluetooth_SignalCommand_Header_t* SignalCommandHeader)\r
-{\r
- Bluetooth_SignalCommand_ConfigurationRequest_t ConfigurationRequest;\r
- \r
- Pipe_Read_Stream_LE(&ConfigurationRequest, sizeof(ConfigurationRequest));\r
-\r
- BT_DEBUG("(ACL) >> L2CAP Configuration Request", NULL);\r
- BT_DEBUG("(ACL) -- Destination Channel: 0x%04X", ConfigurationRequest.DestinationChannel);\r
- \r
- Pipe_ClearCurrentBank();\r
- Pipe_Freeze();\r
- Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);\r
- Pipe_SetToken(PIPE_TOKEN_OUT);\r
- Pipe_Unfreeze();\r
- \r
- Bluetooth_SignalCommand_ConfigurationResponse_t ConfigurationResponse;\r
-\r
- ACLPacketHeader->DataLength = sizeof(*DataHeader) + sizeof(*SignalCommandHeader) + sizeof(ConfigurationResponse);\r
- DataHeader->PayloadLength = sizeof(*SignalCommandHeader) + sizeof(ConfigurationResponse);\r
- DataHeader->DestinationChannel = BLUETOOTH_CHANNEL_SIGNALING;\r
- SignalCommandHeader->Code = BLUETOOTH_SIGNAL_CONFIGURATION_RESPONSE;\r
- SignalCommandHeader->Length = sizeof(ConfigurationResponse);\r
- \r
- Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConfigurationRequest.DestinationChannel, CHANNEL_LOOKUP_BY_DESTINATION);\r
-\r
- if (ChannelData != NULL)\r
- ChannelData->State = Channel_Open;\r
- \r
- // TODO: Add channel config data to the tail of ConfigurationResponse\r
-\r
- ConfigurationResponse.SourceChannel = ChannelData->RemoteNumber;\r
- ConfigurationResponse.Flags = 0x00;\r
- ConfigurationResponse.Result = (ChannelData != NULL) ? BLUETOOTH_CONFIGURATION_SUCCESSFUL : BLUETOOTH_CONFIGURATION_REJECTED;\r
-\r
- Pipe_Write_Stream_LE(ACLPacketHeader, sizeof(*ACLPacketHeader));\r
- Pipe_Write_Stream_LE(DataHeader, sizeof(*DataHeader));\r
- Pipe_Write_Stream_LE(SignalCommandHeader, sizeof(*SignalCommandHeader));\r
- Pipe_Write_Stream_LE(&ConfigurationResponse, sizeof(ConfigurationResponse));\r
- \r
- Pipe_ClearCurrentBank(); \r
- Pipe_Freeze();\r
- \r
- BT_DEBUG("(ACL) Packet Sent", NULL);\r
- BT_DEBUG("(ACL) -- Connection Handle: 0x%04X", ACLPacketHeader->ConnectionHandle);\r
- BT_DEBUG("(ACL) -- Data Length: 0x%04X", ACLPacketHeader->DataLength);\r
- BT_DEBUG("(ACL) -- Destination Channel: 0x%04X", DataHeader->DestinationChannel);\r
- BT_DEBUG("(ACL) -- Payload Length: 0x%04X", DataHeader->PayloadLength); \r
- BT_DEBUG("(ACL) >> L2CAP Configuration Response", NULL);\r
-}\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#ifndef _BLUETOOTH_ACLPACKETS_\r
-#define _BLUETOOTH_ACLPACKETS_\r
-\r
- /* Includes: */\r
- #include <avr/io.h>\r
- #include <string.h>\r
- #include <stdbool.h>\r
-\r
- #include <LUFA/Drivers/USB/USB.h>\r
- \r
- #include "BluetoothStack.h"\r
- \r
- /* Macros: */\r
- #define BLUETOOTH_CHANNEL_SIGNALING 0x0001\r
- #define BLUETOOTH_CHANNEL_CONNECTIONLESS 0x0002\r
- \r
- #define BLUETOOTH_SIGNAL_CONNECTION_REQUEST 0x02\r
- #define BLUETOOTH_SIGNAL_CONNECTION_RESPONSE 0x03\r
- #define BLUETOOTH_SIGNAL_CONFIGURATION_REQUEST 0x04\r
- #define BLUETOOTH_SIGNAL_CONFIGURATION_RESPONSE 0x05\r
- \r
- #define BLUETOOTH_CONNECTION_SUCCESSFUL 0x0000\r
- #define BLUETOOTH_CONNECTION_REFUSED_RESOURCES 0x0004\r
- \r
- #define BLUETOOTH_CONFIGURATION_SUCCESSFUL 0x0000\r
- #define BLUETOOTH_CONFIGURATION_REJECTED 0x0002\r
- #define BLUETOOTH_CONFIGURATION_UNKNOWNOPTIONS 0x0003\r
-\r
- \r
- /* Type Defines: */\r
- typedef struct\r
- {\r
- uint16_t ConnectionHandle;\r
- uint16_t DataLength;\r
- } Bluetooth_ACL_Header_t;\r
-\r
- typedef struct\r
- {\r
- uint16_t PayloadLength;\r
- uint16_t DestinationChannel;\r
- } Bluetooth_DataPacket_Header_t;\r
- \r
- typedef struct\r
- {\r
- uint8_t Code;\r
- uint8_t Identifier;\r
- uint16_t Length;\r
- } Bluetooth_SignalCommand_Header_t;\r
- \r
- typedef struct\r
- {\r
- uint16_t PSM;\r
- uint16_t SourceChannel;\r
- } Bluetooth_SignalCommand_ConnectionRequest_t;\r
-\r
- typedef struct\r
- {\r
- uint16_t DestinationChannel;\r
- uint16_t SourceChannel;\r
- uint16_t Result;\r
- uint16_t Status;\r
- } Bluetooth_SignalCommand_ConnectionResponse_t;\r
- \r
- typedef struct\r
- {\r
- uint16_t DestinationChannel;\r
- uint16_t Flags;\r
- uint8_t Options[];\r
- } Bluetooth_SignalCommand_ConfigurationRequest_t;\r
-\r
- typedef struct\r
- {\r
- uint16_t SourceChannel;\r
- uint16_t Flags;\r
- uint16_t Result;\r
- uint8_t Config;\r
- } Bluetooth_SignalCommand_ConfigurationResponse_t;\r
- \r
- /* Function Prototypes: */\r
- void Bluetooth_ProcessACLPackets(void);\r
-\r
- #if defined(INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C)\r
- static inline void Bluetooth_ProcessSignalPacket_ConnectionRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
- Bluetooth_DataPacket_Header_t* DataHeader,\r
- Bluetooth_SignalCommand_Header_t* SignalCommandHeader);\r
- static inline void Bluetooth_ProcessSignalPacket_ConfigurationRequest(Bluetooth_ACL_Header_t* ACLPacketHeader,\r
- Bluetooth_DataPacket_Header_t* DataHeader,\r
- Bluetooth_SignalCommand_Header_t* SignalCommandHeader);\r
- #endif\r
- \r
-#endif\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#ifndef _BLUETOOTH_CLASS_CODES_H_\r
-#define _BLUETOOTH_CLASS_CODES_H_\r
-\r
- /* Macros: */\r
- #define DEVICE_CLASS_SERVICE_POSITIONING (1UL << 16)\r
- #define DEVICE_CLASS_SERVICE_NETWORKING (1UL << 17)\r
- #define DEVICE_CLASS_SERVICE_RENDERING (1UL << 18)\r
- #define DEVICE_CLASS_SERVICE_CAPTURING (1UL << 19)\r
- #define DEVICE_CLASS_SERVICE_OBJECTTRANSFER (1UL << 20)\r
- #define DEVICE_CLASS_SERVICE_AUDIO (1UL << 21)\r
- #define DEVICE_CLASS_SERVICE_TELEPHONY (1UL << 22)\r
- #define DEVICE_CLASS_SERVICE_INFORMATION (1UL << 23)\r
- \r
- #define DEVICE_CLASS_MAJOR_MISC (0x00 << 8)\r
- #define DEVICE_CLASS_MAJOR_COMPUTER (0x01 << 8)\r
- #define DEVICE_CLASS_MAJOR_PHONE (0x02 << 8)\r
- #define DEVICE_CLASS_MAJOR_LAN (0x03 << 8)\r
- #define DEVICE_CLASS_MAJOR_AUDIOVIDEO (0x04 << 8)\r
- #define DEVICE_CLASS_MAJOR_PERIPHERAL (0x05 << 8)\r
- #define DEVICE_CLASS_MAJOR_IMAGING (0x06 << 8)\r
- #define DEVICE_CLASS_MAJOR_UNCLASSIFIED (0x1F << 8)\r
-\r
- #define DEVICE_CLASS_MINOR_COMPUTER_UNCATEGORIZED (0x00 << 2)\r
- #define DEVICE_CLASS_MINOR_COMPUTER_DESKTOP (0x01 << 2)\r
- #define DEVICE_CLASS_MINOR_COMPUTER_SERVER (0x02 << 2)\r
- #define DEVICE_CLASS_MINOR_COMPUTER_LAPTOP (0x03 << 2)\r
- #define DEVICE_CLASS_MINOR_COMPUTER_HANDHELD (0x04 << 2)\r
- #define DEVICE_CLASS_MINOR_COMPUTER_PALM (0x05 << 2)\r
- #define DEVICE_CLASS_MINOR_COMPUTER_WEARABLE (0x06 << 2)\r
- \r
- #define DEVICE_CLASS_MINOR_PHONE_UNCATEGORIZED (0x00 << 2)\r
- #define DEVICE_CLASS_MINOR_PHONE_CELLULAR (0x01 << 2)\r
- #define DEVICE_CLASS_MINOR_PHONE_CORDLESS (0x02 << 2)\r
- #define DEVICE_CLASS_MINOR_PHONE_SMARTPHONE (0x03 << 2)\r
- #define DEVICE_CLASS_MINOR_PHONE_WIREDMODEM (0x04 << 2)\r
- #define DEVICE_CLASS_MINOR_PHONE_ISDN (0x05 << 2)\r
-\r
- #define DEVICE_CLASS_MINOR_LAN_FULLY_AVAILABLE (0x00 << 5)\r
- #define DEVICE_CLASS_MINOR_LAN_1_TO_17_PC_UTILIZED (0x01 << 5)\r
- #define DEVICE_CLASS_MINOR_LAN_17_TO_33_PC_UTILIZED (0x02 << 5)\r
- #define DEVICE_CLASS_MINOR_LAN_33_TO_50_PC_UTILIZED (0x03 << 5)\r
- #define DEVICE_CLASS_MINOR_LAN_50_TO_67_PC_UTILIZED (0x04 << 5)\r
- #define DEVICE_CLASS_MINOR_LAN_67_TO_83_PC_UTILIZED (0x05 << 5)\r
- #define DEVICE_CLASS_MINOR_LAN_83_TO_99_PC_UTILIZED (0x06 << 5)\r
- #define DEVICE_CLASS_MINOR_NO_SERVICE_AVAILABLE (0x07 << 5)\r
- \r
- #define DEVICE_CLASS_MINOR_AV_UNCATEGORIZED (0x00 << 2)\r
- #define DEVICE_CLASS_MINOR_AV_HEADSET (0x01 << 2)\r
- #define DEVICE_CLASS_MINOR_AV_HANDSFREE (0x02 << 2)\r
- #define DEVICE_CLASS_MINOR_AV_MICROPHONE (0x04 << 2)\r
- #define DEVICE_CLASS_MINOR_AV_LOUDSPEAKER (0x05 << 2)\r
- #define DEVICE_CLASS_MINOR_AV_HEADPHONES (0x06 << 2)\r
- #define DEVICE_CLASS_MINOR_AV_PORTABLE_AUDIO (0x07 << 2)\r
- #define DEVICE_CLASS_MINOR_AV_CARAUDIO (0x08 << 2)\r
- #define DEVICE_CLASS_MINOR_AV_SETTOP_BOX (0x09 << 2)\r
- #define DEVICE_CLASS_MINOR_AV_HIFI (0x0A << 2)\r
- #define DEVICE_CLASS_MINOR_AV_VCR (0x0B << 2)\r
- #define DEVICE_CLASS_MINOR_AV_VIDEO_CAMERA (0x0C << 2)\r
- #define DEVICE_CLASS_MINOR_AV_CAMCORDER (0x0D << 2)\r
- #define DEVICE_CLASS_MINOR_AV_VIDEO_MONITOR (0x0E << 2)\r
- #define DEVICE_CLASS_MINOR_AV_DISPLAY_AND_LOUDSPEAKER (0x0F << 2)\r
- #define DEVICE_CLASS_MINOR_AV_VIDEO_CONFERENCING (0x10 << 2)\r
- #define DEVICE_CLASS_MINOR_AV_GAMING_TOY (0x12 << 2)\r
- \r
- #define DEVICE_CLASS_MINOR_PERIPHERAL_KEYBOARD (0x01 << 6)\r
- #define DEVICE_CLASS_MINOR_PERIPHERAL_POINTING (0x02 << 6)\r
- #define DEVICE_CLASS_MINOR_PERIPHERAL_COMBO (0x03 << 6)\r
- #define DEVICE_CLASS_MINOR_PERIPHERAL_UNCATEGORIZED (0x00 << 2)\r
- #define DEVICE_CLASS_MINOR_PERIPHERAL_JOYSTICK (0x01 << 2)\r
- #define DEVICE_CLASS_MINOR_PERIPHERAL_GAMEPAD (0x02 << 2)\r
- #define DEVICE_CLASS_MINOR_PERIPHERAL_REMOTE_CONTROL (0x03 << 2)\r
- #define DEVICE_CLASS_MINOR_PERIPHERAL_SENSING_DEVICE (0x04 << 2)\r
- #define DEVICE_CLASS_MINOR_PERIPHERAL_DIGITIZER (0x05 << 2)\r
- #define DEVICE_CLASS_MINOR_PERIPHERAL_CARD_READER (0x06 << 2)\r
-\r
- #define DEVICE_CLASS_MINOR_IMAGING_DISPLAY (1 << 4)\r
- #define DEVICE_CLASS_MINOR_IMAGING_CAMERA (1 << 5)\r
- #define DEVICE_CLASS_MINOR_IMAGING_SCANNER (1 << 6)\r
- #define DEVICE_CLASS_MINOR_IMAGING_PRINTER (1 << 7)\r
-\r
-#endif\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#include "BluetoothHCICommands.h"\r
-\r
-static Bluetooth_HCICommand_Header_t HCICommandHeader;\r
-static Bluetooth_HCIEvent_Header_t HCIEventHeader;\r
-\r
- uint8_t Bluetooth_HCIProcessingState;\r
-static uint8_t Bluetooth_TempDeviceAddress[6];\r
-\r
-static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint8_t ParamLength)\r
-{\r
- uint8_t CommandBuffer[sizeof(HCICommandHeader) + HCICommandHeader.ParameterLength];\r
-\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
- {\r
- bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_DEVICE),\r
- bRequest: 0,\r
- wValue: 0,\r
- wIndex: 0,\r
- wLength: sizeof(CommandBuffer)\r
- };\r
- \r
- memset(CommandBuffer, 0x00, sizeof(CommandBuffer));\r
- memcpy(CommandBuffer, &HCICommandHeader, sizeof(HCICommandHeader));\r
- \r
- if (ParamLength)\r
- memcpy(&CommandBuffer[sizeof(HCICommandHeader)], Parameters, ParamLength);\r
-\r
- return USB_Host_SendControlRequest(CommandBuffer);\r
-}\r
-\r
-static bool Bluetooth_GetNextHCIEventHeader(void)\r
-{\r
- Pipe_SelectPipe(BLUETOOTH_EVENTS_PIPE);\r
- Pipe_Unfreeze();\r
- \r
- if (!(Pipe_ReadWriteAllowed()))\r
- return false;\r
- \r
- Pipe_Read_Stream_LE(&HCIEventHeader, sizeof(HCIEventHeader));\r
- \r
- return true;\r
-}\r
-\r
-static void Bluetooth_DiscardRemainingHCIEventParameters(void)\r
-{\r
- Pipe_SelectPipe(BLUETOOTH_EVENTS_PIPE);\r
- Pipe_Discard_Stream(HCIEventHeader.ParameterLength);\r
- Pipe_ClearCurrentBank();\r
-}\r
-\r
-void Bluetooth_ProcessHCICommands(void)\r
-{\r
- uint8_t ErrorCode;\r
-\r
- switch (Bluetooth_HCIProcessingState)\r
- {\r
- case Bluetooth_Init:\r
- Pipe_SelectPipe(BLUETOOTH_EVENTS_PIPE);\r
- Pipe_SetInfiniteINRequests();\r
- \r
- memset(&Bluetooth_Connection, 0x00, sizeof(Bluetooth_Connection));\r
- \r
- Bluetooth_HCIProcessingState = Bluetooth_Init_Reset; \r
- break;\r
- case Bluetooth_Init_Reset:\r
- HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
- {\r
- OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_RESET},\r
- ParameterLength: 0,\r
- };\r
- \r
- BT_DEBUG("(HCI) Enter State: Bluetooth_Init_Reset", NULL);\r
-\r
- ErrorCode = Bluetooth_SendHCICommand(NULL, 0);\r
-\r
- do\r
- {\r
- while (!(Bluetooth_GetNextHCIEventHeader()));\r
- Bluetooth_DiscardRemainingHCIEventParameters();\r
- } while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);\r
-\r
- Bluetooth_HCIProcessingState = Bluetooth_Init_ReadBufferSize;\r
- break;\r
- case Bluetooth_Init_ReadBufferSize:\r
- HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
- {\r
- OpCode: {OGF: OGF_CTRLR_INFORMATIONAL, OCF: OGF_CTRLR_INFORMATIONAL_READBUFFERSIZE},\r
- ParameterLength: 0,\r
- };\r
- \r
- BT_DEBUG("(HCI) Enter State: Bluetooth_Init_ReadBufferSize", NULL);\r
-\r
- ErrorCode = Bluetooth_SendHCICommand(NULL, 0);\r
-\r
- do\r
- {\r
- while (!(Bluetooth_GetNextHCIEventHeader()));\r
- Bluetooth_DiscardRemainingHCIEventParameters();\r
- } while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);\r
-\r
- Bluetooth_HCIProcessingState = Bluetooth_Init_SetEventMask; \r
- break;\r
- case Bluetooth_Init_SetEventMask:\r
- HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
- {\r
- OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_SET_EVENT_MASK},\r
- ParameterLength: 8,\r
- };\r
- \r
- BT_DEBUG("(HCI) Enter State: Bluetooth_Init_SetEventMask", NULL);\r
- \r
- uint8_t EventMask[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};\r
- ErrorCode = Bluetooth_SendHCICommand(&EventMask, 8);\r
-\r
- BT_DEBUG("(HCI) -- Event mask: 0x%02X%02X%02X%02X%02X%02X%02X%02X", EventMask[7], EventMask[6], EventMask[5], EventMask[4],\r
- EventMask[3], EventMask[2], EventMask[1], EventMask[0]);\r
- do\r
- {\r
- while (!(Bluetooth_GetNextHCIEventHeader()));\r
- Bluetooth_DiscardRemainingHCIEventParameters();\r
- } while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);\r
- \r
-\r
- Bluetooth_HCIProcessingState = Bluetooth_Init_SetLocalName; \r
- break;\r
- case Bluetooth_Init_SetLocalName:\r
- HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
- {\r
- OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_WRITE_LOCAL_NAME},\r
- ParameterLength: 248,\r
- };\r
-\r
- BT_DEBUG("(HCI) Enter State: Bluetooth_Init_SetLocalName", NULL);\r
- BT_DEBUG("(HCI) -- Name: %s", Bluetooth_DeviceConfiguration.Name);\r
-\r
- ErrorCode = Bluetooth_SendHCICommand(Bluetooth_DeviceConfiguration.Name, strlen(Bluetooth_DeviceConfiguration.Name));\r
- \r
- do\r
- {\r
- while (!(Bluetooth_GetNextHCIEventHeader()));\r
- Bluetooth_DiscardRemainingHCIEventParameters();\r
- } while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);\r
- \r
- Bluetooth_HCIProcessingState = Bluetooth_Init_SetDeviceClass;\r
- break;\r
- case Bluetooth_Init_SetDeviceClass:\r
- HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
- {\r
- OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_WRITE_CLASS_OF_DEVICE},\r
- ParameterLength: 3,\r
- };\r
-\r
- BT_DEBUG("(HCI) Enter State: Bluetooth_Init_SetDeviceClass", NULL);\r
-\r
- ErrorCode = Bluetooth_SendHCICommand(&Bluetooth_DeviceConfiguration.Class, 3);\r
-\r
- do\r
- {\r
- while (!(Bluetooth_GetNextHCIEventHeader()));\r
- Bluetooth_DiscardRemainingHCIEventParameters();\r
- } while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);\r
-\r
- Bluetooth_HCIProcessingState = Bluetooth_Init_WriteScanEnable; \r
- break;\r
- case Bluetooth_Init_WriteScanEnable:\r
- HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
- {\r
- OpCode: {OGF: OGF_CTRLR_BASEBAND, OCF: OCF_CTRLR_BASEBAND_WRITE_SCAN_ENABLE},\r
- ParameterLength: 1,\r
- };\r
- \r
- BT_DEBUG("(HCI) Enter State: Bluetooth_Init_WriteScanEnable", NULL);\r
-\r
- uint8_t Interval = InquiryAndPageScans;\r
- ErrorCode = Bluetooth_SendHCICommand(&Interval, 1);\r
-\r
- do\r
- {\r
- while (!(Bluetooth_GetNextHCIEventHeader()));\r
- Bluetooth_DiscardRemainingHCIEventParameters();\r
- } while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);\r
-\r
- Bluetooth_HCIProcessingState = Bluetooth_PrepareToProcessEvents;\r
- break;\r
- case Bluetooth_PrepareToProcessEvents:\r
- BT_DEBUG("(HCI) Enter State: Bluetooth_ProcessEvents", NULL);\r
-\r
- Bluetooth_HCIProcessingState = Bluetooth_ProcessEvents;\r
- break;\r
- case Bluetooth_ProcessEvents:\r
- if (Bluetooth_GetNextHCIEventHeader())\r
- {\r
- BT_DEBUG("(HCI) Event Code: 0x%02X", HCIEventHeader.EventCode);\r
- \r
- if (HCIEventHeader.EventCode == EVENT_COMMAND_STATUS)\r
- {\r
- Bluetooth_HCIEvent_CommandStatus_Header_t CommandStatusHeader;\r
-\r
- Pipe_Read_Stream_LE(&CommandStatusHeader, sizeof(CommandStatusHeader));\r
- HCIEventHeader.ParameterLength -= sizeof(CommandStatusHeader);\r
- \r
- BT_DEBUG("(HCI) >> Command status: 0x%02X", CommandStatusHeader.CommandStatus);\r
- \r
- if (CommandStatusHeader.CommandStatus)\r
- Bluetooth_HCIProcessingState = Bluetooth_Init;\r
- }\r
- else if (HCIEventHeader.EventCode == EVENT_CONNECTION_REQUEST)\r
- {\r
- Bluetooth_HCIEvent_ConnectionRequest_Header_t ConnectionRequestParams;\r
- \r
- Pipe_Read_Stream_LE(&ConnectionRequestParams, sizeof(ConnectionRequestParams));\r
- HCIEventHeader.ParameterLength -= sizeof(ConnectionRequestParams);\r
-\r
- BT_DEBUG("(HCI) >> Connection Request from device %02X:%02X:%02X:%02X:%02X:%02X",\r
- ConnectionRequestParams.RemoteAddress[5], ConnectionRequestParams.RemoteAddress[4], \r
- ConnectionRequestParams.RemoteAddress[3], ConnectionRequestParams.RemoteAddress[2], \r
- ConnectionRequestParams.RemoteAddress[1], ConnectionRequestParams.RemoteAddress[0]);\r
- BT_DEBUG("(HCI) -- Device Class: 0x%02X%04X", ConnectionRequestParams.ClassOfDevice_Service,\r
- ConnectionRequestParams.ClassOfDevice_MajorMinor);\r
- BT_DEBUG("(HCI) -- Link Type: 0x%02x", ConnectionRequestParams.LinkType);\r
- \r
- memcpy(Bluetooth_TempDeviceAddress, ConnectionRequestParams.RemoteAddress,\r
- sizeof(Bluetooth_TempDeviceAddress));\r
-\r
- Bluetooth_HCIProcessingState = (Bluetooth_Connection.IsConnected) ? Bluetooth_Conn_RejectConnection :\r
- Bluetooth_Conn_AcceptConnection;\r
- }\r
- else if (HCIEventHeader.EventCode == EVENT_DISCONNECTION_COMPLETE)\r
- {\r
- BT_DEBUG("(HCI) >> Disconnection from device complete.", NULL);\r
- Bluetooth_HCIProcessingState = Bluetooth_Init;\r
- }\r
- else if (HCIEventHeader.EventCode == EVENT_CONNECTION_COMPLETE)\r
- {\r
- Bluetooth_HCIEvent_ConnectionComplete_Header_t ConnectionCompleteParams;\r
- \r
- Pipe_Read_Stream_LE(&ConnectionCompleteParams, sizeof(ConnectionCompleteParams));\r
- HCIEventHeader.ParameterLength -= sizeof(ConnectionCompleteParams);\r
-\r
- BT_DEBUG("(HCI) >> Connection to device complete.", NULL);\r
- BT_DEBUG("(HCI) -- Status: %d", ConnectionCompleteParams.Status);\r
- BT_DEBUG("(HCI) -- Handle: %d", ConnectionCompleteParams.ConnectionHandle);\r
- \r
- if (ConnectionCompleteParams.Status == 0x00)\r
- {\r
- memcpy(Bluetooth_Connection.DeviceAddress, ConnectionCompleteParams.RemoteAddress,\r
- sizeof(Bluetooth_Connection.DeviceAddress));\r
- Bluetooth_Connection.ConnectionHandle = ConnectionCompleteParams.ConnectionHandle;\r
- Bluetooth_Connection.IsConnected = true;\r
- }\r
- }\r
- else if (HCIEventHeader.EventCode == EVENT_PIN_CODE_REQUEST)\r
- {\r
- Pipe_Read_Stream_LE(&Bluetooth_TempDeviceAddress, sizeof(Bluetooth_TempDeviceAddress));\r
- HCIEventHeader.ParameterLength -= sizeof(Bluetooth_TempDeviceAddress);\r
-\r
- BT_DEBUG("(HCI) >> PIN code Request from device %02X:%02X:%02X:%02X:%02X:%02X", \r
- Bluetooth_TempDeviceAddress[5], Bluetooth_TempDeviceAddress[4], Bluetooth_TempDeviceAddress[3],\r
- Bluetooth_TempDeviceAddress[2], Bluetooth_TempDeviceAddress[1], Bluetooth_TempDeviceAddress[0]);\r
- \r
- Bluetooth_HCIProcessingState = Bluetooth_Conn_SendPINCode;\r
- }\r
- \r
- BT_DEBUG("(HCI) -- Unread Event Param Length: %d", HCIEventHeader.ParameterLength);\r
-\r
- Bluetooth_DiscardRemainingHCIEventParameters();\r
- }\r
-\r
- break;\r
- case Bluetooth_Conn_AcceptConnection:\r
- HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
- {\r
- OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST},\r
- ParameterLength: sizeof(Bluetooth_HCICommand_AcceptConnectionRequest_Params_t),\r
- };\r
- \r
- BT_DEBUG("(HCI) Enter State: Bluetooth_Conn_AcceptConnection", NULL);\r
-\r
- Bluetooth_HCICommand_AcceptConnectionRequest_Params_t AcceptConnectionParams;\r
- \r
- memcpy(AcceptConnectionParams.RemoteAddress, Bluetooth_TempDeviceAddress,\r
- sizeof(Bluetooth_TempDeviceAddress));\r
- AcceptConnectionParams.SlaveRole = true;\r
-\r
- Bluetooth_SendHCICommand(&AcceptConnectionParams, sizeof(AcceptConnectionParams));\r
- \r
- Bluetooth_HCIProcessingState = Bluetooth_PrepareToProcessEvents;\r
- break;\r
- case Bluetooth_Conn_RejectConnection:\r
- HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
- {\r
- OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST},\r
- ParameterLength: sizeof(Bluetooth_HCICommand_RejectConnectionRequest_Params_t),\r
- };\r
- \r
- BT_DEBUG("(HCI) Enter State: Bluetooth_Conn_RejectConnection", NULL);\r
-\r
- Bluetooth_HCICommand_RejectConnectionRequest_Params_t RejectConnectionParams;\r
-\r
- memcpy(RejectConnectionParams.RemoteAddress, Bluetooth_TempDeviceAddress,\r
- sizeof(Bluetooth_TempDeviceAddress));\r
- RejectConnectionParams.Reason = ERROR_LIMITED_RESOURCES;\r
-\r
- Bluetooth_SendHCICommand(&AcceptConnectionParams, sizeof(AcceptConnectionParams));\r
- \r
- Bluetooth_HCIProcessingState = Bluetooth_PrepareToProcessEvents;\r
- break;\r
- case Bluetooth_Conn_SendPINCode:\r
- HCICommandHeader = (Bluetooth_HCICommand_Header_t)\r
- {\r
- OpCode: {OGF: OGF_LINK_CONTROL, OCF: OCF_LINK_CONTROL_PIN_CODE_REQUEST_REPLY},\r
- ParameterLength: sizeof(Bluetooth_HCICommand_PinCodeResponse_Params_t),\r
- };\r
- \r
- BT_DEBUG("(HCI) Enter State: Bluetooth_Conn_SendPINCode", NULL);\r
- BT_DEBUG("(HCI) -- PIN: %s", Bluetooth_DeviceConfiguration.PINCode);\r
-\r
- Bluetooth_HCICommand_PinCodeResponse_Params_t PINCodeRequestParams;\r
- \r
- memcpy(PINCodeRequestParams.RemoteAddress, Bluetooth_TempDeviceAddress,\r
- sizeof(Bluetooth_TempDeviceAddress));\r
- PINCodeRequestParams.PINCodeLength = strlen(Bluetooth_DeviceConfiguration.PINCode);\r
- memcpy(PINCodeRequestParams.PINCode, Bluetooth_DeviceConfiguration.PINCode,\r
- sizeof(Bluetooth_DeviceConfiguration.PINCode));\r
- \r
- Bluetooth_SendHCICommand(&PINCodeRequestParams, sizeof(PINCodeRequestParams));\r
- \r
- do\r
- {\r
- while (!(Bluetooth_GetNextHCIEventHeader()));\r
- Bluetooth_DiscardRemainingHCIEventParameters();\r
- } while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);\r
-\r
- Bluetooth_HCIProcessingState = Bluetooth_PrepareToProcessEvents;\r
- break;\r
- }\r
-}\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#ifndef _BLUETOOTH_HCICOMMANDS_H_\r
-#define _BLUETOOTH_HCICOMMANDS_H_\r
-\r
- /* Includes: */\r
- #include <avr/io.h>\r
- #include <string.h>\r
- #include <stdbool.h>\r
-\r
- #include <LUFA/Drivers/USB/USB.h>\r
-\r
- #include "BluetoothStack.h"\r
- #include "BluetoothClassCodes.h"\r
-\r
- /* Macros: */\r
- #define OGF_LINK_CONTROL 0x01\r
- #define OGF_CTRLR_BASEBAND 0x03\r
- #define OGF_CTRLR_INFORMATIONAL 0x04\r
-\r
- #define OCF_LINK_CONTROL_INQUIRY 0x0001\r
- #define OCF_LINK_CONTROL_INQUIRY_CANCEL 0x0002\r
- #define OCF_LINK_CONTROL_PERIODIC_INQUIRY 0x0003\r
- #define OCF_LINK_CONTROL_EXIT_PERIODIC_INQUIRY 0x0004\r
- #define OCF_LINK_CONTROL_CREATE_CONNECTION 0x0005\r
- #define OCF_LINK_CONTROL_DISCONNECT 0x0006\r
- #define OCF_LINK_CONTROL_CREATE_CONNECTION_CANCEL 0x0008\r
- #define OCF_LINK_CONTROL_ACCEPT_CONNECTION_REQUEST 0x0009\r
- #define OCF_LINK_CONTROL_REJECT_CONNECTION_REQUEST 0x000A\r
- #define OCF_LINK_CONTROL_LINK_KEY_REQUEST_REPLY 0x000B\r
- #define OCF_LINK_CONTROL_LINK_KEY_REQUEST_NEG_REPLY 0x000C\r
- #define OCF_LINK_CONTROL_PIN_CODE_REQUEST_REPLY 0x000D\r
- #define OCF_LINK_CONTROL_PIN_CODE_REQUEST_NEG_REPLY 0x000E\r
- #define OCF_LINK_CONTROL_CHANGE_CONNECTION_PACKET_TYPE 0x000F\r
- #define OCF_LINK_CONTROL_REMOTE_NAME_REQUEST 0x0019\r
- #define OCF_CTRLR_BASEBAND_SET_EVENT_MASK 0x0001\r
- #define OCF_CTRLR_BASEBAND_RESET 0x0003\r
- #define OCF_CTRLR_BASEBAND_WRITE_PIN_TYPE 0x000A\r
- #define OCF_CTRLR_BASEBAND_WRITE_LOCAL_NAME 0x0013\r
- #define OCF_CTRLR_BASEBAND_READ_LOCAL_NAME 0x0014\r
- #define OCF_CTRLR_BASEBAND_WRITE_SCAN_ENABLE 0x001A\r
- #define OCF_CTRLR_BASEBAND_WRITE_CLASS_OF_DEVICE 0x0024\r
- #define OCF_CTRLR_BASEBAND_WRITE_SIMPLE_PAIRING_MODE 0x0056\r
- #define OCF_CTRLR_BASEBAND_WRITE_AUTHENTICATION_ENABLE 0x0020\r
- #define OGF_CTRLR_INFORMATIONAL_READBUFFERSIZE 0x0005\r
- \r
- #define EVENT_COMMAND_STATUS 0x0F\r
- #define EVENT_COMMAND_COMPLETE 0x0E\r
- #define EVENT_CONNECTION_COMPLETE 0x03\r
- #define EVENT_CONNECTION_REQUEST 0x04\r
- #define EVENT_DISCONNECTION_COMPLETE 0x05\r
- #define EVENT_REMOTE_NAME_REQUEST_COMPLETE 0x07\r
- #define EVENT_PIN_CODE_REQUEST 0x16\r
- \r
- #define ERROR_LIMITED_RESOURCES 0x0D\r
- \r
- /* Type Defines: */\r
- typedef struct\r
- {\r
- struct\r
- {\r
- int OCF : 10;\r
- int OGF : 6;\r
- } OpCode;\r
-\r
- uint8_t ParameterLength;\r
- uint8_t Parameters[];\r
- } Bluetooth_HCICommand_Header_t;\r
-\r
- typedef struct\r
- {\r
- uint8_t EventCode;\r
- uint8_t ParameterLength;\r
- } Bluetooth_HCIEvent_Header_t;\r
-\r
- typedef struct\r
- {\r
- uint8_t CommandStatus;\r
- uint8_t CommandPackets;\r
-\r
- struct\r
- {\r
- int OCF : 10;\r
- int OGF : 6;\r
- } OpCode;\r
- } Bluetooth_HCIEvent_CommandStatus_Header_t;\r
- \r
- typedef struct\r
- {\r
- uint8_t RemoteAddress[6];\r
- uint8_t ClassOfDevice_Service;\r
- uint16_t ClassOfDevice_MajorMinor;\r
- uint8_t LinkType;\r
- } Bluetooth_HCIEvent_ConnectionRequest_Header_t;\r
-\r
- typedef struct\r
- {\r
- uint8_t Status;\r
- uint16_t ConnectionHandle;\r
- uint8_t RemoteAddress[6];\r
- uint8_t LinkType;\r
- uint8_t EncryptionEnabled;\r
- } Bluetooth_HCIEvent_ConnectionComplete_Header_t;\r
- \r
- typedef struct\r
- {\r
- uint8_t RemoteAddress[6];\r
- uint8_t SlaveRole;\r
- } Bluetooth_HCICommand_AcceptConnectionRequest_Params_t;\r
- \r
- typedef struct\r
- {\r
- uint8_t RemoteAddress[6];\r
- uint8_t Reason;\r
- } Bluetooth_HCICommand_RejectConnectionRequest_Params_t;\r
-\r
- typedef struct\r
- {\r
- uint8_t RemoteAddress[6];\r
- uint8_t PINCodeLength;\r
- char PINCode[16];\r
- } Bluetooth_HCICommand_PinCodeResponse_Params_t;\r
- \r
- /* Enums: */\r
- enum Bluetooth_ScanEnable_Modes_t\r
- {\r
- NoScansEnabled = 0,\r
- InquiryScanOnly = 1,\r
- PageScanOnly = 2,\r
- InquiryAndPageScans = 3,\r
- };\r
-\r
- enum BluetoothStack_States_t\r
- {\r
- Bluetooth_Init = 0,\r
- Bluetooth_Init_Reset = 1,\r
- Bluetooth_Init_ReadBufferSize = 2,\r
- Bluetooth_Init_SetEventMask = 3,\r
- Bluetooth_Init_SetLocalName = 4,\r
- Bluetooth_Init_SetDeviceClass = 5,\r
- Bluetooth_Init_WriteScanEnable = 6,\r
- Bluetooth_PrepareToProcessEvents = 7,\r
- Bluetooth_ProcessEvents = 8,\r
- Bluetooth_Conn_AcceptConnection = 9,\r
- Bluetooth_Conn_RejectConnection = 10,\r
- Bluetooth_Conn_SendPINCode = 11,\r
- };\r
- \r
- /* External Variables: */\r
- extern uint8_t Bluetooth_HCIProcessingState;\r
-\r
- /* Function Prototypes: */\r
- void Bluetooth_ProcessHCICommands(void);\r
-\r
- #if defined(INCLUDE_FROM_BLUETOOTHHCICOMMANDS_C)\r
- static uint8_t Bluetooth_SendHCICommand(void* Parameters, uint8_t ParamLength);\r
- static bool Bluetooth_GetNextHCIEventHeader(void);\r
- static void Bluetooth_DiscardRemainingHCIEventParameters(void);\r
- static void Bluetooth_ProcessHCICommands(void);\r
- #endif\r
- \r
-#endif\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/*\r
- Bluetooth Dongle host demo application.\r
- \r
- ** NOT CURRENTLY FUNCTIONAL - DO NOT USE **\r
-*/\r
-\r
-/*\r
- USB Mode: Host\r
- USB Class: Bluetooth USB Transport Class\r
- USB Subclass: Bluetooth HCI USB Transport\r
- Relevant Standards: Bluetooth 2.0 Standard\r
- Bluetooth 2.0 HCI USB Transport Layer Addendum\r
- Bluetooth Assigned Numbers (Baseband)\r
- Usable Speeds: Full Speed Mode\r
-*/\r
-\r
-#include "BluetoothHost.h"\r
-\r
-/* Project Tags, for reading out using the ButtLoad project */\r
-BUTTLOADTAG(ProjName, "LUFA BT Host App");\r
-BUTTLOADTAG(BuildTime, __TIME__);\r
-BUTTLOADTAG(BuildDate, __DATE__);\r
-BUTTLOADTAG(LUFAVersion, "LUFA V" LUFA_VERSION_STRING);\r
-\r
-/* Scheduler Task List */\r
-TASK_LIST\r
-{\r
- { Task: USB_USBTask , TaskStatus: TASK_STOP },\r
- { Task: USB_Bluetooth_Host , TaskStatus: TASK_STOP },\r
- { Task: Bluetooth_Task , TaskStatus: TASK_STOP },\r
-};\r
-\r
-Bluetooth_Device_t Bluetooth_DeviceConfiguration =\r
- {\r
- Class: (DEVICE_CLASS_SERVICE_CAPTURING | DEVICE_CLASS_MAJOR_COMPUTER | DEVICE_CLASS_MINOR_COMPUTER_PALM),\r
- PINCode: "0000",\r
- Name: "LUFA Bluetooth Demo"\r
- };\r
-\r
-\r
-int main(void)\r
-{\r
- /* Disable watchdog if enabled by bootloader/fuses */\r
- MCUSR &= ~(1 << WDRF);\r
- wdt_disable();\r
-\r
- /* Disable clock division */\r
- clock_prescale_set(clock_div_1);\r
-\r
- /* Hardware Initialization */\r
- SerialStream_Init(9600, false);\r
- LEDs_Init();\r
- \r
- /* Indicate USB not ready */\r
- UpdateStatus(Status_USBNotReady);\r
-\r
- /* Startup message */\r
- puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY\r
- "Bluetooth Host Demo running.\r\n" ESC_INVERSE_OFF));\r
- \r
- /* Initialize Scheduler so that it can be used */\r
- Scheduler_Init();\r
-\r
- /* Initialize USB Subsystem */\r
- USB_Init();\r
- \r
- /* Scheduling routine never returns, so put this last in the main function */\r
- Scheduler_Start();\r
-}\r
-\r
-EVENT_HANDLER(USB_DeviceAttached)\r
-{\r
- puts_P(PSTR("Device Attached.\r\n"));\r
- UpdateStatus(Status_USBEnumerating);\r
- \r
- /* Start USB management task to enumerate the device */\r
- Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
-}\r
-\r
-EVENT_HANDLER(USB_DeviceUnattached)\r
-{\r
- /* Stop USB management and Bluetooth tasks */\r
- Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
- Scheduler_SetTaskMode(USB_Bluetooth_Host, TASK_STOP);\r
- Scheduler_SetTaskMode(Bluetooth_Task, TASK_STOP);\r
- \r
- puts_P(PSTR("\r\nDevice Unattached.\r\n"));\r
- UpdateStatus(Status_USBNotReady);\r
-}\r
-\r
-EVENT_HANDLER(USB_DeviceEnumerationComplete)\r
-{\r
- /* Once device is fully enumerated, start the Bluetooth Host task */\r
- Scheduler_SetTaskMode(USB_Bluetooth_Host, TASK_RUN);\r
- Scheduler_SetTaskMode(Bluetooth_Task, TASK_RUN);\r
- \r
- UpdateStatus(Status_USBReady);\r
-}\r
-\r
-EVENT_HANDLER(USB_HostError)\r
-{\r
- USB_ShutDown();\r
-\r
- puts_P(PSTR(ESC_BG_RED "Host Mode Error\r\n"));\r
- printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
-\r
- UpdateStatus(Status_HardwareError);\r
- for(;;);\r
-}\r
-\r
-EVENT_HANDLER(USB_DeviceEnumerationFailed)\r
-{\r
- puts_P(PSTR(ESC_BG_RED "Dev Enum Error\r\n"));\r
- printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
- printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);\r
- \r
- UpdateStatus(Status_EnumerationError);\r
-}\r
-\r
-TASK(USB_Bluetooth_Host)\r
-{\r
- uint8_t ErrorCode;\r
-\r
- switch (USB_HostState)\r
- {\r
- case HOST_STATE_Addressed:\r
- puts_P(PSTR("Getting Device Data.\r\n"));\r
- \r
- /* Get and process the configuration descriptor data */\r
- if ((ErrorCode = ProcessDeviceDescriptor()) != SuccessfulDeviceRead)\r
- {\r
- if (ErrorCode == ControlErrorDuringDeviceRead)\r
- puts_P(PSTR("Control Error (Get Device).\r\n"));\r
- else\r
- puts_P(PSTR("Invalid Device.\r\n"));\r
-\r
- printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
- \r
- /* Indicate error via status LEDs */\r
- LEDs_SetAllLEDs(LEDS_LED1);\r
-\r
- /* Wait until USB device disconnected */\r
- while (USB_IsConnected);\r
- break;\r
- }\r
-\r
- puts_P(PSTR("Bluetooth Dongle Detected.\r\n"));\r
-\r
- /* Standard request to set the device configuration to configuration 1 */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
- {\r
- bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
- bRequest: REQ_SetConfiguration,\r
- wValue: 1,\r
- wIndex: 0,\r
- wLength: 0,\r
- };\r
- \r
- /* Send the request, display error and wait for device detatch if request fails */\r
- if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
- {\r
- puts_P(PSTR("Control Error (Set Configuration).\r\n"));\r
- printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
-\r
- /* Indicate error via status LEDs */\r
- LEDs_SetAllLEDs(LEDS_LED1);\r
-\r
- /* Wait until USB device disconnected */\r
- while (USB_IsConnected);\r
- break;\r
- }\r
- \r
- USB_HostState = HOST_STATE_Configured;\r
- break;\r
- case HOST_STATE_Configured:\r
- puts_P(PSTR("Getting Config Data.\r\n"));\r
- \r
- /* Get and process the configuration descriptor data */\r
- if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)\r
- {\r
- if (ErrorCode == ControlErrorDuringConfigRead)\r
- puts_P(PSTR("Control Error (Get Configuration).\r\n"));\r
- else\r
- puts_P(PSTR("Invalid Device.\r\n"));\r
-\r
- printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
- \r
- /* Indicate error via status LEDs */\r
- LEDs_SetAllLEDs(LEDS_LED1);\r
-\r
- /* Wait until USB device disconnected */\r
- while (USB_IsConnected);\r
- break;\r
- }\r
-\r
- puts_P(PSTR("Bluetooth Dongle Enumerated.\r\n"));\r
-\r
- USB_HostState = HOST_STATE_Ready;\r
- break;\r
- case HOST_STATE_Ready:\r
- if (Bluetooth_HCIProcessingState != Bluetooth_ProcessEvents)\r
- {\r
- UpdateStatus(Status_BluetoothBusy);\r
- }\r
- else\r
- {\r
- if (Bluetooth_Connection.IsConnected)\r
- UpdateStatus(Status_BluetoothConnected);\r
- else\r
- UpdateStatus(Status_USBReady);\r
- }\r
- \r
- break;\r
- }\r
-}\r
-\r
-/** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to\r
- * log to a serial port, or anything else that is suitable for status updates.\r
- *\r
- * \param CurrentStatus Current status of the system, from the MouseHostViaInt_StatusCodes_t enum\r
- */\r
-void UpdateStatus(uint8_t CurrentStatus)\r
-{\r
- uint8_t LEDMask = LEDS_NO_LEDS;\r
- \r
- /* Set the LED mask to the appropriate LED mask based on the given status code */\r
- switch (CurrentStatus)\r
- {\r
- case Status_USBNotReady:\r
- LEDMask = (LEDS_LED1);\r
- break;\r
- case Status_USBEnumerating:\r
- LEDMask = (LEDS_LED1 | LEDS_LED2);\r
- break;\r
- case Status_USBReady:\r
- LEDMask = (LEDS_LED2);\r
- break;\r
- case Status_EnumerationError:\r
- case Status_HardwareError:\r
- LEDMask = (LEDS_LED1 | LEDS_LED3);\r
- break;\r
- case Status_BluetoothConnected:\r
- LEDMask = (LEDS_LED2 | LEDS_LED4);\r
- break; \r
- case Status_BluetoothBusy:\r
- LEDMask = (LEDS_LED2 | LEDS_LED3 | LEDS_LED4);\r
- break; \r
- }\r
- \r
- /* Set the board LEDs to the new LED mask */\r
- LEDs_SetAllLEDs(LEDMask);\r
-}\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#ifndef _BLUETOOTH_HOST_H_\r
-#define _BLUETOOTH_HOST_H_\r
-\r
- /* Includes: */\r
- #include <avr/io.h>\r
- #include <avr/wdt.h>\r
- #include <avr/pgmspace.h>\r
- #include <avr/power.h>\r
- #include <stdio.h>\r
-\r
- #include "BluetoothStack.h"\r
-\r
- #include "DeviceDescriptor.h"\r
- #include "ConfigDescriptor.h"\r
-\r
- #include <LUFA/Version.h> // Library Version Information\r
- #include <LUFA/Common/ButtLoadTag.h> // PROGMEM tags readable by the ButtLoad project\r
- #include <LUFA/Drivers/Misc/TerminalCodes.h> // ANSI Terminal Escape Codes\r
- #include <LUFA/Drivers/USB/USB.h> // USB Functionality\r
- #include <LUFA/Drivers/AT90USBXXX/Serial_Stream.h> // Serial stream driver\r
- #include <LUFA/Drivers/Board/LEDs.h> // LEDs driver\r
- #include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management\r
-\r
- /* Macros: */\r
- #define BLUETOOTH_DATA_IN_PIPE 1\r
- #define BLUETOOTH_DATA_OUT_PIPE 2\r
- #define BLUETOOTH_EVENTS_PIPE 3\r
-\r
- /* Task Definitions: */\r
- TASK(USB_Bluetooth_Host);\r
-\r
- /* Enums: */\r
- /** Enum for the possible status codes for passing to the UpdateStatus() function. */\r
- enum MouseHostViaInt_StatusCodes_t\r
- {\r
- Status_USBNotReady = 0, /**< USB is not ready (disconnected from a USB device) */\r
- Status_USBEnumerating = 1, /**< USB interface is enumerating */\r
- Status_USBReady = 2, /**< USB interface is connected and ready */\r
- Status_EnumerationError = 3, /**< Software error while enumerating the attached USB device */\r
- Status_HardwareError = 4, /**< Hardware error while enumerating the attached USB device */\r
- Status_BluetoothConnected = 5, /**< Bluetooth stack connected to device and idle */\r
- Status_BluetoothBusy = 6, /**< Bluetooth stack busy */ \r
- };\r
- \r
- /* Event Handlers: */\r
- HANDLES_EVENT(USB_DeviceAttached);\r
- HANDLES_EVENT(USB_DeviceUnattached);\r
- HANDLES_EVENT(USB_DeviceEnumerationComplete);\r
- HANDLES_EVENT(USB_HostError);\r
- HANDLES_EVENT(USB_DeviceEnumerationFailed);\r
-\r
- /* Function Prototypes: */\r
- void UpdateStatus(uint8_t CurrentStatus);\r
- \r
-#endif\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#include "BluetoothStack.h"\r
-\r
-Bluetooth_Connection_t Bluetooth_Connection = {IsConnected: false};\r
-\r
-Bluetooth_Device_t Bluetooth_DeviceConfiguration ATTR_WEAK =\r
- {\r
- Class: DEVICE_CLASS_MAJOR_MISC,\r
- PINCode: "0000",\r
- Name: "LUFA BT Device"\r
- };\r
-\r
-TASK(Bluetooth_Task)\r
-{\r
- if (!(USB_IsConnected) || (USB_HostState != HOST_STATE_Ready))\r
- Bluetooth_HCIProcessingState = Bluetooth_Init;\r
- \r
- Bluetooth_ProcessHCICommands();\r
- Bluetooth_ProcessACLPackets();\r
-}\r
-\r
-Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource)\r
-{\r
- Bluetooth_Channel_t* CurrentChannelStructure;\r
-\r
- for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)\r
- {\r
- CurrentChannelStructure = &Bluetooth_Connection.Channels[i];\r
- \r
- uint16_t CurrentChannelNumber = ((SearchBySource) ? CurrentChannelStructure->RemoteNumber : CurrentChannelStructure->LocalNumber);\r
- \r
- if (CurrentChannelNumber == ChannelNumber)\r
- return CurrentChannelStructure;\r
- }\r
-\r
- return NULL;\r
-}\r
-\r
-Bluetooth_Channel_t* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber, uint16_t PSM)\r
-{\r
- Bluetooth_Channel_t* CurrentChannelStructure;\r
-\r
- for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)\r
- {\r
- CurrentChannelStructure = &Bluetooth_Connection.Channels[i];\r
- \r
- if (CurrentChannelStructure->State == Channel_Closed)\r
- {\r
- CurrentChannelStructure->RemoteNumber = RemoteChannelNumber;\r
- CurrentChannelStructure->LocalNumber = (BLUETOOTH_CHANNELNUMBER_BASEOFFSET + i);\r
- CurrentChannelStructure->PSM = PSM;\r
- CurrentChannelStructure->State = Channel_Config;\r
- \r
- return CurrentChannelStructure;\r
- } \r
- }\r
-\r
- return NULL;\r
-}\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#ifndef _BLUETOOTH_STACK_\r
-#define _BLUETOOTH_STACK_\r
-\r
- /* Includes: */\r
- #include <LUFA/Drivers/USB/USB.h>\r
- #include <LUFA/Scheduler/Scheduler.h>\r
- \r
- #include "BluetoothHost.h"\r
- #include "BluetoothHCICommands.h"\r
- #include "BluetoothACLPackets.h"\r
- \r
- /* Macros: */\r
- #define BLUETOOTH_MAX_OPEN_CHANNELS 2\r
- #define BLUETOOTH_CHANNELNUMBER_BASEOFFSET 0x0040\r
- \r
- #define CHANNEL_LOOKUP_BY_SOURCE true\r
- #define CHANNEL_LOOKUP_BY_DESTINATION false\r
- \r
- #define BT_DEBUG(s, ...) printf_P(PSTR(s "\r\n"), __VA_ARGS__)\r
- \r
- /* Enums: */\r
- enum Bluetooth_Channel_State_t\r
- {\r
- Channel_Closed = 0,\r
- Channel_WaitConnect = 1,\r
- Channel_WaitConnectRsp = 2,\r
- Channel_Config = 3,\r
- Channel_Open = 4,\r
- Channel_WaitDisconnect = 5,\r
- };\r
-\r
- /* Type Defines: */\r
- typedef struct\r
- {\r
- uint8_t State;\r
- uint16_t LocalNumber;\r
- uint16_t RemoteNumber;\r
- uint16_t PSM;\r
- uint16_t MTU;\r
- } Bluetooth_Channel_t;\r
-\r
- typedef struct\r
- {\r
- bool IsConnected;\r
- uint16_t ConnectionHandle;\r
- uint8_t DeviceAddress[6];\r
- Bluetooth_Channel_t Channels[BLUETOOTH_MAX_OPEN_CHANNELS];\r
- } Bluetooth_Connection_t;\r
- \r
- typedef struct\r
- {\r
- uint32_t Class;\r
- char PINCode[16];\r
- char Name[];\r
- } Bluetooth_Device_t;\r
- \r
- /* Tasks: */\r
- TASK(Bluetooth_Task);\r
-\r
- /* Function Prototypes: */\r
- Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchBySource);\r
- Bluetooth_Channel_t* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber, uint16_t PSM);\r
-\r
- /* External Variables: */\r
- extern Bluetooth_Device_t Bluetooth_DeviceConfiguration;\r
- extern Bluetooth_Connection_t Bluetooth_Connection;\r
-\r
-#endif\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#include "ConfigDescriptor.h"\r
-\r
-uint8_t ProcessConfigurationDescriptor(void)\r
-{\r
- uint8_t* ConfigDescriptorData;\r
- uint16_t ConfigDescriptorSize;\r
- uint8_t FoundEndpoints = 0;\r
- \r
- /* Get Configuration Descriptor size from the device */\r
- if (USB_Host_GetDeviceConfigDescriptor(&ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)\r
- return ControlErrorDuringConfigRead;\r
- \r
- /* Ensure that the Configuration Descriptor isn't too large */\r
- if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)\r
- return DescriptorTooLarge;\r
- \r
- /* Allocate enough memory for the entire config descriptor */\r
- ConfigDescriptorData = alloca(ConfigDescriptorSize);\r
-\r
- /* Retrieve the entire configuration descriptor into the allocated buffer */\r
- USB_Host_GetDeviceConfigDescriptor(&ConfigDescriptorSize, ConfigDescriptorData);\r
- \r
- /* Validate returned data - ensure first entry is a configuration header descriptor */\r
- if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)\r
- return InvalidConfigDataReturned;\r
-\r
- /* The bluetooth USB transport addendium mandates that the data (not streaming voice) endpoints\r
- be in the first interface descriptor (interface 0) */\r
- USB_Host_GetNextDescriptorOfType(&ConfigDescriptorSize, &ConfigDescriptorData, DTYPE_Interface);\r
- \r
- /* Ensure that an interface was found, and the end of the descriptor was not reached */\r
- if (!(ConfigDescriptorSize))\r
- return NoInterfaceFound;\r
-\r
- /* Get the data IN, data OUT and event notification endpoints for the bluetooth interface */\r
- while (FoundEndpoints != ((1 << BLUETOOTH_DATA_IN_PIPE) | (1 << BLUETOOTH_DATA_OUT_PIPE) |\r
- (1 << BLUETOOTH_EVENTS_PIPE)))\r
- {\r
- /* Fetch the next endpoint from the current bluetooth interface */\r
- if (USB_Host_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
- NextInterfaceBluetoothDataEndpoint))\r
- {\r
- /* Descriptor not found, error out */\r
- return NoEndpointFound;\r
- }\r
- \r
- USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t);\r
-\r
- /* Check if the endpoint is a bulk or interrupt type endpoint */\r
- if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT)\r
- {\r
- if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)\r
- {\r
- /* Configure the events IN pipe */\r
- Pipe_ConfigurePipe(BLUETOOTH_EVENTS_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN,\r
- EndpointData->EndpointAddress, EndpointData->EndpointSize,\r
- PIPE_BANK_SINGLE);\r
-\r
- Pipe_SetInfiniteINRequests();\r
- Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS);\r
- \r
- /* Set the flag indicating that the events notification pipe has been found */\r
- FoundEndpoints |= (1 << BLUETOOTH_EVENTS_PIPE); \r
- }\r
- }\r
- else\r
- {\r
- if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)\r
- {\r
- /* Configure the data IN pipe */\r
- Pipe_ConfigurePipe(BLUETOOTH_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN,\r
- EndpointData->EndpointAddress, EndpointData->EndpointSize,\r
- PIPE_BANK_SINGLE);\r
-\r
- Pipe_SetInfiniteINRequests();\r
-\r
- /* Set the flag indicating that the data IN pipe has been found */\r
- FoundEndpoints |= (1 << BLUETOOTH_DATA_IN_PIPE);\r
- }\r
- else\r
- {\r
- /* Configure the data OUT pipe */\r
- Pipe_ConfigurePipe(BLUETOOTH_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT,\r
- EndpointData->EndpointAddress, EndpointData->EndpointSize,\r
- PIPE_BANK_SINGLE);\r
-\r
- /* Set the flag indicating that the data OUT pipe has been found */\r
- FoundEndpoints |= (1 << BLUETOOTH_DATA_OUT_PIPE);\r
- } \r
- }\r
-\r
- }\r
-\r
- /* Valid data found, return success */\r
- return SuccessfulConfigRead;\r
-}\r
-\r
-DESCRIPTOR_COMPARATOR(NextInterfaceBluetoothDataEndpoint)\r
-{\r
- /* PURPOSE: Find next interface endpoint descriptor before next interface descriptor */\r
-\r
- if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)\r
- return Descriptor_Search_Found;\r
- else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)\r
- return Descriptor_Search_Fail;\r
-\r
- return Descriptor_Search_NotFound;\r
-}\r
-\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#ifndef _CONFIGDESCRIPTOR_H_\r
-#define _CONFIGDESCRIPTOR_H_\r
-\r
- /* Includes: */\r
- #include <LUFA/Drivers/USB/USB.h> // USB Functionality\r
- #include <LUFA/Drivers/USB/Class/ConfigDescriptor.h> // Configuration Descriptor Parser\r
- \r
- #include "BluetoothHost.h"\r
- \r
- /* Macros: */\r
- #define MAX_CONFIG_DESCRIPTOR_SIZE 512\r
-\r
- /* Enums: */\r
- enum BluetoothHost_GetConfigDescriptorDataCodes_t\r
- {\r
- SuccessfulConfigRead = 0,\r
- ControlErrorDuringConfigRead = 1,\r
- InvalidConfigDataReturned = 2,\r
- DescriptorTooLarge = 3,\r
- NoInterfaceFound = 4,\r
- NoEndpointFound = 5,\r
- };\r
- \r
- /* Configuration Descriptor Comparison Functions: */\r
- DESCRIPTOR_COMPARATOR(NextInterfaceBluetoothDataEndpoint);\r
-\r
- /* Function Prototypes: */\r
- uint8_t ProcessConfigurationDescriptor(void); \r
-\r
-#endif\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#include "DeviceDescriptor.h"\r
-\r
-uint8_t ProcessDeviceDescriptor(void)\r
-{\r
- USB_Descriptor_Device_t DeviceDescriptor;\r
-\r
- /* Standard request to get the device descriptor */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
- {\r
- bmRequestType: (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),\r
- bRequest: REQ_GetDescriptor,\r
- wValue: (DTYPE_Device << 8),\r
- wIndex: 0,\r
- wLength: sizeof(USB_Descriptor_Device_t),\r
- };\r
-\r
- /* Send the request to retrieve the device descriptor */\r
- if (USB_Host_SendControlRequest((void*)&DeviceDescriptor) != HOST_SENDCONTROL_Successful)\r
- return ControlErrorDuringDeviceRead;\r
- \r
- /* Validate returned data - ensure the returned data is a device descriptor */\r
- if (DeviceDescriptor.Header.Type != DTYPE_Device)\r
- return InvalidDeviceDataReturned;\r
- \r
- if ((DeviceDescriptor.Class != BLUETOOTH_DEVICE_CLASS) ||\r
- (DeviceDescriptor.SubClass != BLUETOOTH_DEVICE_SUBCLASS) ||\r
- (DeviceDescriptor.Protocol != BLUETOOTH_DEVICE_PROTOCOL))\r
- {\r
- return IncorrectDevice;\r
- }\r
- \r
- return SuccessfulDeviceRead;\r
-}\r
+++ /dev/null
-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2009.\r
- \r
- dean [at] fourwalledcubicle [dot] com\r
- www.fourwalledcubicle.com\r
-*/\r
-\r
-/*\r
- Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, and distribute this software\r
- and its documentation for any purpose and without fee is hereby\r
- granted, provided that the above copyright notice appear in all\r
- copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-#ifndef _DEVICEDESCRIPTOR_H_\r
-#define _DEVICEDESCRIPTOR_H_\r
-\r
- /* Includes: */\r
- #include <LUFA/Drivers/USB/USB.h> // USB Functionality\r
- \r
- #include "BluetoothHost.h"\r
- \r
- /* Macros: */\r
- #define BLUETOOTH_DEVICE_CLASS 0xE0\r
- #define BLUETOOTH_DEVICE_SUBCLASS 0x01\r
- #define BLUETOOTH_DEVICE_PROTOCOL 0x01\r
-\r
- /* Enums: */\r
- enum BluetoothHost_GetDeviceDescriptorDataCodes_t\r
- {\r
- SuccessfulDeviceRead = 0,\r
- ControlErrorDuringDeviceRead = 1,\r
- InvalidDeviceDataReturned = 2,\r
- IncorrectDevice = 3,\r
- };\r
-\r
- /* Function Prototypes: */\r
- uint8_t ProcessDeviceDescriptor(void); \r
-\r
-#endif\r
+++ /dev/null
-# Hey Emacs, this is a -*- makefile -*-\r
-#----------------------------------------------------------------------------\r
-# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.\r
-# >> Modified for use with the LUFA project. <<\r
-#\r
-# Released to the Public Domain\r
-#\r
-# Additional material for this makefile was written by:\r
-# Peter Fleury\r
-# Tim Henigan\r
-# Colin O'Flynn\r
-# Reiner Patommel\r
-# Markus Pfaff\r
-# Sander Pool\r
-# Frederik Rouleau\r
-# Carlos Lamas\r
-# Dean Camera\r
-# Opendous Inc.\r
-# Denver Gingerich\r
-#\r
-#----------------------------------------------------------------------------\r
-# On command line:\r
-#\r
-# make all = Make software.\r
-#\r
-# make clean = Clean out built project files.\r
-#\r
-# make coff = Convert ELF to AVR COFF.\r
-#\r
-# make extcoff = Convert ELF to AVR Extended COFF.\r
-#\r
-# make program = Download the hex file to the device, using avrdude.\r
-# Please customize the avrdude settings below first!\r
-#\r
-# make dfu = Download the hex file to the device, using dfu-programmer (must\r
-# have dfu-programmer installed).\r
-#\r
-# make flip = Download the hex file to the device, using Atmel FLIP (must\r
-# have Atmel FLIP installed).\r
-#\r
-# make dfu-ee = Download the eeprom file to the device, using dfu-programmer\r
-# (must have dfu-programmer installed).\r
-#\r
-# make flip-ee = Download the eeprom file to the device, using Atmel FLIP\r
-# (must have Atmel FLIP installed).\r
-#\r
-# make doxygen = Generate DoxyGen documentation for the project (must have\r
-# DoxyGen installed)\r
-#\r
-# make debug = Start either simulavr or avarice as specified for debugging, \r
-# with avr-gdb or avr-insight as the front end for debugging.\r
-#\r
-# make filename.s = Just compile filename.c into the assembler code only.\r
-#\r
-# make filename.i = Create a preprocessed source file for use in submitting\r
-# bug reports to the GCC project.\r
-#\r
-# To rebuild project do "make clean" then "make all".\r
-#----------------------------------------------------------------------------\r
-\r
-\r
-# MCU name\r
-MCU = at90usb1287\r
-\r
-\r
-# Target board (see library BoardTypes.h documentation, USER or blank for projects not requiring\r
-# LUFA board drivers). If USER is selected, put custom board drivers in a directory called \r
-# "Board" inside the application directory.\r
-BOARD = USBKEY\r
-\r
-\r
-# Processor frequency.\r
-# This will define a symbol, F_CPU, in all source code files equal to the \r
-# processor frequency. You can then use this symbol in your source code to \r
-# calculate timings. Do NOT tack on a 'UL' at the end, this will be done\r
-# automatically to create a 32-bit value in your source code.\r
-# Typical values are:\r
-# F_CPU = 1000000\r
-# F_CPU = 1843200\r
-# F_CPU = 2000000\r
-# F_CPU = 3686400\r
-# F_CPU = 4000000\r
-# F_CPU = 7372800\r
-# F_CPU = 8000000\r
-# F_CPU = 11059200\r
-# F_CPU = 14745600\r
-# F_CPU = 16000000\r
-# F_CPU = 18432000\r
-# F_CPU = 20000000\r
-F_CPU = 8000000\r
-\r
-\r
-# Input clock frequency.\r
-# This will define a symbol, F_CLOCK, in all source code files equal to the \r
-# input clock frequency (before any prescaling is performed). This value may\r
-# differ from F_CPU if prescaling is used on the latter, and is required as the\r
-# raw input clock is fed directly to the PLL sections of the AVR for high speed\r
-# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'\r
-# at the end, this will be done automatically to create a 32-bit value in your\r
-# source code.\r
-#\r
-# If no clock division is performed on the input clock inside the AVR (via the\r
-# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.\r
-F_CLOCK = 8000000\r
-\r
-\r
-# Output format. (can be srec, ihex, binary)\r
-FORMAT = ihex\r
-\r
-\r
-# Target file name (without extension).\r
-TARGET = BluetoothHost\r
-\r
-\r
-# Object files directory\r
-# To put object files in current directory, use a dot (.), do NOT make\r
-# this an empty or blank macro!\r
-OBJDIR = .\r
-\r
-\r
-# List C source files here. (C dependencies are automatically generated.)\r
-SRC = $(TARGET).c \\r
- DeviceDescriptor.c \\r
- ConfigDescriptor.c \\r
- BluetoothStack.c \\r
- BluetoothHCICommands.c \\r
- BluetoothACLPackets.c \\r
- ../../LUFA/Scheduler/Scheduler.c \\r
- ../../LUFA/Drivers/AT90USBXXX/Serial_Stream.c \\r
- ../../LUFA/Drivers/AT90USBXXX/Serial.c \\r
- ../../LUFA/Drivers/USB/Class/ConfigDescriptor.c \\r
- ../../LUFA/Drivers/USB/LowLevel/LowLevel.c \\r
- ../../LUFA/Drivers/USB/LowLevel/Pipe.c \\r
- ../../LUFA/Drivers/USB/LowLevel/Host.c \\r
- ../../LUFA/Drivers/USB/LowLevel/HostChapter9.c \\r
- ../../LUFA/Drivers/USB/HighLevel/USBTask.c \\r
- ../../LUFA/Drivers/USB/HighLevel/USBInterrupt.c \\r
- ../../LUFA/Drivers/USB/HighLevel/Events.c \\r
- \r
-# List C++ source files here. (C dependencies are automatically generated.)\r
-CPPSRC = \r
-\r
-\r
-# List Assembler source files here.\r
-# Make them always end in a capital .S. Files ending in a lowercase .s\r
-# will not be considered source files but generated files (assembler\r
-# output from the compiler), and will be deleted upon "make clean"!\r
-# Even though the DOS/Win* filesystem matches both .s and .S the same,\r
-# it will preserve the spelling of the filenames, and gcc itself does\r
-# care about how the name is spelled on its command-line.\r
-ASRC =\r
-\r
-\r
-# Optimization level, can be [0, 1, 2, 3, s]. \r
-# 0 = turn off optimization. s = optimize for size.\r
-# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)\r
-OPT = s\r
-\r
-\r
-# Debugging format.\r
-# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.\r
-# AVR Studio 4.10 requires dwarf-2.\r
-# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.\r
-DEBUG = dwarf-2\r
-\r
-\r
-# List any extra directories to look for include files here.\r
-# Each directory must be seperated by a space.\r
-# Use forward slashes for directory separators.\r
-# For a directory that has spaces, enclose it in quotes.\r
-EXTRAINCDIRS = ../../\r
-\r
-\r
-# Compiler flag to set the C Standard level.\r
-# c89 = "ANSI" C\r
-# gnu89 = c89 plus GCC extensions\r
-# c99 = ISO C99 standard (not yet fully implemented)\r
-# gnu99 = c99 plus GCC extensions\r
-CSTANDARD = -std=gnu99\r
-\r
-\r
-# Place -D or -U options here for C sources\r
-CDEFS = -DF_CPU=$(F_CPU)UL -DF_CLOCK=$(F_CLOCK)UL -DBOARD=BOARD_$(BOARD)\r
-CDEFS += -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DUSB_HOST_ONLY -DNO_STREAM_CALLBACKS\r
-CDEFS += -DUSE_STATIC_OPTIONS="(USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"\r
-\r
-# Place -D or -U options here for ASM sources\r
-ADEFS = -DF_CPU=$(F_CPU)\r
-\r
-\r
-# Place -D or -U options here for C++ sources\r
-CPPDEFS = -DF_CPU=$(F_CPU)UL\r
-#CPPDEFS += -D__STDC_LIMIT_MACROS\r
-#CPPDEFS += -D__STDC_CONSTANT_MACROS\r
-\r
-\r
-\r
-#---------------- Compiler Options C ----------------\r
-# -g*: generate debugging information\r
-# -O*: optimization level\r
-# -f...: tuning, see GCC manual and avr-libc documentation\r
-# -Wall...: warning level\r
-# -Wa,...: tell GCC to pass this to the assembler.\r
-# -adhlns...: create assembler listing\r
-CFLAGS = -g$(DEBUG)\r
-CFLAGS += $(CDEFS)\r
-CFLAGS += -O$(OPT)\r
-CFLAGS += -funsigned-char\r
-CFLAGS += -funsigned-bitfields\r
-CFLAGS += -ffunction-sections\r
-CFLAGS += -fpack-struct\r
-CFLAGS += -fshort-enums\r
-CFLAGS += -finline-limit=20\r
-CFLAGS += -Wall\r
-CFLAGS += -Wstrict-prototypes\r
-CFLAGS += -Wundef\r
-#CFLAGS += -fno-unit-at-a-time\r
-#CFLAGS += -Wunreachable-code\r
-#CFLAGS += -Wsign-compare\r
-CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)\r
-CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))\r
-CFLAGS += $(CSTANDARD)\r
-\r
-\r
-#---------------- Compiler Options C++ ----------------\r
-# -g*: generate debugging information\r
-# -O*: optimization level\r
-# -f...: tuning, see GCC manual and avr-libc documentation\r
-# -Wall...: warning level\r
-# -Wa,...: tell GCC to pass this to the assembler.\r
-# -adhlns...: create assembler listing\r
-CPPFLAGS = -g$(DEBUG)\r
-CPPFLAGS += $(CPPDEFS)\r
-CPPFLAGS += -O$(OPT)\r
-CPPFLAGS += -funsigned-char\r
-CPPFLAGS += -funsigned-bitfields\r
-CPPFLAGS += -fpack-struct\r
-CPPFLAGS += -fshort-enums\r
-CPPFLAGS += -fno-exceptions\r
-CPPFLAGS += -Wall\r
-CFLAGS += -Wundef\r
-#CPPFLAGS += -mshort-calls\r
-#CPPFLAGS += -fno-unit-at-a-time\r
-#CPPFLAGS += -Wstrict-prototypes\r
-#CPPFLAGS += -Wunreachable-code\r
-#CPPFLAGS += -Wsign-compare\r
-CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)\r
-CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))\r
-#CPPFLAGS += $(CSTANDARD)\r
-\r
-\r
-#---------------- Assembler Options ----------------\r
-# -Wa,...: tell GCC to pass this to the assembler.\r
-# -adhlns: create listing\r
-# -gstabs: have the assembler create line number information; note that\r
-# for use in COFF files, additional information about filenames\r
-# and function names needs to be present in the assembler source\r
-# files -- see avr-libc docs [FIXME: not yet described there]\r
-# -listing-cont-lines: Sets the maximum number of continuation lines of hex \r
-# dump that will be displayed for a given single line of source input.\r
-ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100\r
-\r
-\r
-#---------------- Library Options ----------------\r
-# Minimalistic printf version\r
-PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min\r
-\r
-# Floating point printf version (requires MATH_LIB = -lm below)\r
-PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt\r
-\r
-# If this is left blank, then it will use the Standard printf version.\r
-PRINTF_LIB = \r
-#PRINTF_LIB = $(PRINTF_LIB_MIN)\r
-#PRINTF_LIB = $(PRINTF_LIB_FLOAT)\r
-\r
-\r
-# Minimalistic scanf version\r
-SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min\r
-\r
-# Floating point + %[ scanf version (requires MATH_LIB = -lm below)\r
-SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt\r
-\r
-# If this is left blank, then it will use the Standard scanf version.\r
-SCANF_LIB = \r
-#SCANF_LIB = $(SCANF_LIB_MIN)\r
-#SCANF_LIB = $(SCANF_LIB_FLOAT)\r
-\r
-\r
-MATH_LIB = -lm\r
-\r
-\r
-# List any extra directories to look for libraries here.\r
-# Each directory must be seperated by a space.\r
-# Use forward slashes for directory separators.\r
-# For a directory that has spaces, enclose it in quotes.\r
-EXTRALIBDIRS = \r
-\r
-\r
-\r
-#---------------- External Memory Options ----------------\r
-\r
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),\r
-# used for variables (.data/.bss) and heap (malloc()).\r
-#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff\r
-\r
-# 64 KB of external RAM, starting after internal RAM (ATmega128!),\r
-# only used for heap (malloc()).\r
-#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff\r
-\r
-EXTMEMOPTS =\r
-\r
-\r
-\r
-#---------------- Linker Options ----------------\r
-# -Wl,...: tell GCC to pass this to linker.\r
-# -Map: create map file\r
-# --cref: add cross reference to map file\r
-LDFLAGS = -Wl,-Map=$(TARGET).map,--cref\r
-LDFLAGS += -Wl,--relax \r
-LDFLAGS += -Wl,--gc-sections\r
-LDFLAGS += $(EXTMEMOPTS)\r
-LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))\r
-LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)\r
-#LDFLAGS += -T linker_script.x\r
-\r
-\r
-\r
-#---------------- Programming Options (avrdude) ----------------\r
-\r
-# Programming hardware: alf avr910 avrisp bascom bsd \r
-# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500\r
-#\r
-# Type: avrdude -c ?\r
-# to get a full listing.\r
-#\r
-AVRDUDE_PROGRAMMER = jtagmkII\r
-\r
-# com1 = serial port. Use lpt1 to connect to parallel port.\r
-AVRDUDE_PORT = usb\r
-\r
-AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex\r
-#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep\r
-\r
-\r
-# Uncomment the following if you want avrdude's erase cycle counter.\r
-# Note that this counter needs to be initialized first using -Yn,\r
-# see avrdude manual.\r
-#AVRDUDE_ERASE_COUNTER = -y\r
-\r
-# Uncomment the following if you do /not/ wish a verification to be\r
-# performed after programming the device.\r
-#AVRDUDE_NO_VERIFY = -V\r
-\r
-# Increase verbosity level. Please use this when submitting bug\r
-# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> \r
-# to submit bug reports.\r
-#AVRDUDE_VERBOSE = -v -v\r
-\r
-AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)\r
-AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)\r
-AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)\r
-AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)\r
-\r
-\r
-\r
-#---------------- Debugging Options ----------------\r
-\r
-# For simulavr only - target MCU frequency.\r
-DEBUG_MFREQ = $(F_CPU)\r
-\r
-# Set the DEBUG_UI to either gdb or insight.\r
-# DEBUG_UI = gdb\r
-DEBUG_UI = insight\r
-\r
-# Set the debugging back-end to either avarice, simulavr.\r
-DEBUG_BACKEND = avarice\r
-#DEBUG_BACKEND = simulavr\r
-\r
-# GDB Init Filename.\r
-GDBINIT_FILE = __avr_gdbinit\r
-\r
-# When using avarice settings for the JTAG\r
-JTAG_DEV = /dev/com1\r
-\r
-# Debugging port used to communicate between GDB / avarice / simulavr.\r
-DEBUG_PORT = 4242\r
-\r
-# Debugging host used to communicate between GDB / avarice / simulavr, normally\r
-# just set to localhost unless doing some sort of crazy debugging when \r
-# avarice is running on a different computer.\r
-DEBUG_HOST = localhost\r
-\r
-\r
-\r
-#============================================================================\r
-\r
-\r
-# Define programs and commands.\r
-SHELL = sh\r
-CC = avr-gcc\r
-OBJCOPY = avr-objcopy\r
-OBJDUMP = avr-objdump\r
-SIZE = avr-size\r
-AR = avr-ar rcs\r
-NM = avr-nm\r
-AVRDUDE = avrdude\r
-REMOVE = rm -f\r
-REMOVEDIR = rm -rf\r
-COPY = cp\r
-WINSHELL = cmd\r
-\r
-# Define Messages\r
-# English\r
-MSG_ERRORS_NONE = Errors: none\r
-MSG_BEGIN = -------- begin --------\r
-MSG_END = -------- end --------\r
-MSG_SIZE_BEFORE = Size before: \r
-MSG_SIZE_AFTER = Size after:\r
-MSG_COFF = Converting to AVR COFF:\r
-MSG_EXTENDED_COFF = Converting to AVR Extended COFF:\r
-MSG_FLASH = Creating load file for Flash:\r
-MSG_EEPROM = Creating load file for EEPROM:\r
-MSG_EXTENDED_LISTING = Creating Extended Listing:\r
-MSG_SYMBOL_TABLE = Creating Symbol Table:\r
-MSG_LINKING = Linking:\r
-MSG_COMPILING = Compiling C:\r
-MSG_COMPILING_CPP = Compiling C++:\r
-MSG_ASSEMBLING = Assembling:\r
-MSG_CLEANING = Cleaning project:\r
-MSG_CREATING_LIBRARY = Creating library:\r
-\r
-\r
-\r
-\r
-# Define all object files.\r
-OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o) \r
-\r
-# Define all listing files.\r
-LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst) \r
-\r
-\r
-# Compiler flags to generate dependency files.\r
-GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d\r
-\r
-\r
-# Combine all necessary flags and optional flags.\r
-# Add target processor to flags.\r
-ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)\r
-ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)\r
-ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)\r
-\r
-\r
-\r
-\r
-\r
-# Default target.\r
-all: begin gccversion sizebefore build checkhooks checklibmode checkboard sizeafter end\r
-\r
-# Change the build target to build a HEX file or a library.\r
-build: elf hex eep lss sym\r
-#build: lib\r
-\r
-\r
-elf: $(TARGET).elf\r
-hex: $(TARGET).hex\r
-eep: $(TARGET).eep\r
-lss: $(TARGET).lss\r
-sym: $(TARGET).sym\r
-LIBNAME=lib$(TARGET).a\r
-lib: $(LIBNAME)\r
-\r
-\r
-\r
-# Eye candy.\r
-# AVR Studio 3.x does not check make's exit code but relies on\r
-# the following magic strings to be generated by the compile job.\r
-begin:\r
- @echo\r
- @echo $(MSG_BEGIN)\r
-\r
-end:\r
- @echo $(MSG_END)\r
- @echo\r
-\r
-\r
-# Display size of file.\r
-HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex\r
-ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf\r
-MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )\r
-FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )\r
-\r
-sizebefore:\r
- @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \\r
- 2>/dev/null; echo; fi\r
-\r
-sizeafter:\r
- @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \\r
- 2>/dev/null; echo; fi\r
-\r
-checkhooks: build\r
- @echo\r
- @echo ------- Unhooked LUFA Events -------\r
- @$(shell) (grep -s '^Event.*LUFA/.*\\.o' $(TARGET).map | \\r
- cut -d' ' -f1 | cut -d'_' -f2- | grep ".*") || \\r
- echo "(None)"\r
- @echo ------------------------------------\r
-\r
-checklibmode:\r
- @echo\r
- @echo ----------- Library Mode -----------\r
- @$(shell) ($(CC) $(ALL_CFLAGS) -E -dM - < /dev/null \\r
- | grep 'USB_\(DEVICE\|HOST\)_ONLY' | cut -d' ' -f2 | grep ".*") \\r
- || echo "No specific mode (both device and host mode allowable)."\r
- @echo ------------------------------------\r
-\r
-checkboard:\r
- @echo\r
- @echo ---------- Selected Board ----------\r
- @echo Selected board model is $(BOARD).\r
- @echo ------------------------------------\r
- \r
-# Display compiler version information.\r
-gccversion : \r
- @$(CC) --version\r
-\r
-\r
-\r
-# Program the device. \r
-program: $(TARGET).hex $(TARGET).eep\r
- $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)\r
-\r
-flip: $(TARGET).hex\r
- batchisp -hardware usb -device $(MCU) -operation erase f\r
- batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program\r
- batchisp -hardware usb -device $(MCU) -operation start reset 0\r
-\r
-dfu: $(TARGET).hex\r
- dfu-programmer $(MCU) erase\r
- dfu-programmer $(MCU) flash --debug 1 $(TARGET).hex\r
- dfu-programmer $(MCU) reset\r
-\r
-flip-ee: $(TARGET).hex $(TARGET).eep\r
- copy $(TARGET).eep $(TARGET)eep.hex\r
- batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase\r
- batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program\r
- batchisp -hardware usb -device $(MCU) -operation start reset 0\r
-\r
-dfu-ee: $(TARGET).hex $(TARGET).eep\r
- dfu-programmer $(MCU) flash-eeprom --debug 1 --suppress-bootloader-mem $(TARGET).eep\r
- dfu-programmer $(MCU) reset\r
-\r
-\r
-# Generate avr-gdb config/init file which does the following:\r
-# define the reset signal, load the target file, connect to target, and set \r
-# a breakpoint at main().\r
-gdb-config: \r
- @$(REMOVE) $(GDBINIT_FILE)\r
- @echo define reset >> $(GDBINIT_FILE)\r
- @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)\r
- @echo end >> $(GDBINIT_FILE)\r
- @echo file $(TARGET).elf >> $(GDBINIT_FILE)\r
- @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)\r
-ifeq ($(DEBUG_BACKEND),simulavr)\r
- @echo load >> $(GDBINIT_FILE)\r
-endif\r
- @echo break main >> $(GDBINIT_FILE)\r
-\r
-debug: gdb-config $(TARGET).elf\r
-ifeq ($(DEBUG_BACKEND), avarice)\r
- @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.\r
- @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \\r
- $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)\r
- @$(WINSHELL) /c pause\r
-\r
-else\r
- @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \\r
- $(DEBUG_MFREQ) --port $(DEBUG_PORT)\r
-endif\r
- @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)\r
-\r
-\r
-\r
-\r
-# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.\r
-COFFCONVERT = $(OBJCOPY) --debugging\r
-COFFCONVERT += --change-section-address .data-0x800000\r
-COFFCONVERT += --change-section-address .bss-0x800000\r
-COFFCONVERT += --change-section-address .noinit-0x800000\r
-COFFCONVERT += --change-section-address .eeprom-0x810000\r
-\r
-\r
-\r
-coff: $(TARGET).elf\r
- @echo\r
- @echo $(MSG_COFF) $(TARGET).cof\r
- $(COFFCONVERT) -O coff-avr $< $(TARGET).cof\r
-\r
-\r
-extcoff: $(TARGET).elf\r
- @echo\r
- @echo $(MSG_EXTENDED_COFF) $(TARGET).cof\r
- $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof\r
-\r
-\r
-\r
-# Create final output files (.hex, .eep) from ELF output file.\r
-%.hex: %.elf\r
- @echo\r
- @echo $(MSG_FLASH) $@\r
- $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@\r
-\r
-%.eep: %.elf\r
- @echo\r
- @echo $(MSG_EEPROM) $@\r
- -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \\r
- --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0\r
-\r
-# Create extended listing file from ELF output file.\r
-%.lss: %.elf\r
- @echo\r
- @echo $(MSG_EXTENDED_LISTING) $@\r
- $(OBJDUMP) -h -z -S $< > $@\r
-\r
-# Create a symbol table from ELF output file.\r
-%.sym: %.elf\r
- @echo\r
- @echo $(MSG_SYMBOL_TABLE) $@\r
- $(NM) -n $< > $@\r
-\r
-\r
-\r
-# Create library from object files.\r
-.SECONDARY : $(TARGET).a\r
-.PRECIOUS : $(OBJ)\r
-%.a: $(OBJ)\r
- @echo\r
- @echo $(MSG_CREATING_LIBRARY) $@\r
- $(AR) $@ $(OBJ)\r
-\r
-\r
-# Link: create ELF output file from object files.\r
-.SECONDARY : $(TARGET).elf\r
-.PRECIOUS : $(OBJ)\r
-%.elf: $(OBJ)\r
- @echo\r
- @echo $(MSG_LINKING) $@\r
- $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)\r
-\r
-\r
-# Compile: create object files from C source files.\r
-$(OBJDIR)/%.o : %.c\r
- @echo\r
- @echo $(MSG_COMPILING) $<\r
- $(CC) -c $(ALL_CFLAGS) $< -o $@ \r
-\r
-\r
-# Compile: create object files from C++ source files.\r
-$(OBJDIR)/%.o : %.cpp\r
- @echo\r
- @echo $(MSG_COMPILING_CPP) $<\r
- $(CC) -c $(ALL_CPPFLAGS) $< -o $@ \r
-\r
-\r
-# Compile: create assembler files from C source files.\r
-%.s : %.c\r
- $(CC) -S $(ALL_CFLAGS) $< -o $@\r
-\r
-\r
-# Compile: create assembler files from C++ source files.\r
-%.s : %.cpp\r
- $(CC) -S $(ALL_CPPFLAGS) $< -o $@\r
-\r
-\r
-# Assemble: create object files from assembler source files.\r
-$(OBJDIR)/%.o : %.S\r
- @echo\r
- @echo $(MSG_ASSEMBLING) $<\r
- $(CC) -c $(ALL_ASFLAGS) $< -o $@\r
-\r
-\r
-# Create preprocessed source for use in sending a bug report.\r
-%.i : %.c\r
- $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ \r
- \r
-\r
-# Target: clean project.\r
-clean: begin clean_list clean_binary end\r
-\r
-clean_binary:\r
- $(REMOVE) $(TARGET).hex\r
- \r
-clean_list:\r
- @echo $(MSG_CLEANING)\r
- $(REMOVE) $(TARGET).eep\r
- $(REMOVE) $(TARGET)eep.hex\r
- $(REMOVE) $(TARGET).cof\r
- $(REMOVE) $(TARGET).elf\r
- $(REMOVE) $(TARGET).map\r
- $(REMOVE) $(TARGET).sym\r
- $(REMOVE) $(TARGET).lss\r
- $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)\r
- $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)\r
- $(REMOVE) $(SRC:.c=.s)\r
- $(REMOVE) $(SRC:.c=.d)\r
- $(REMOVE) $(SRC:.c=.i)\r
- $(REMOVEDIR) .dep\r
-\r
-\r
-doxygen:\r
- @echo Generating Project Documentation...\r
- @doxygen Doxygen.conf\r
- @echo Documentation Generation Complete.\r
-\r
-clean_doxygen:\r
- rm -rf Documentation\r
-\r
-# Create object files directory\r
-$(shell mkdir $(OBJDIR) 2>/dev/null)\r
-\r
-\r
-# Include the dependency files.\r
--include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)\r
-\r
-\r
-# Listing of phony targets.\r
-.PHONY : all checkhooks checklibmode checkboard \\r
-begin finish end sizebefore sizeafter gccversion \\r
-build elf hex eep lss sym coff extcoff clean \\r
-clean_list clean_binary program debug gdb-config \\r
-doxygen dfu flip flip-ee dfu-ee
\ No newline at end of file
make -C AudioOutput clean
make -C AudioOutput all
- make -C BluetoothHost clean
- make -C BluetoothHost all
-
make -C CDC clean
make -C CDC all
%:
make -C AudioInput $@
make -C AudioOutput $@
- make -C BluetoothHost $@
make -C CDC $@
make -C CDCHost $@
make -C DualCDC $@
* to Kenneth Clubb)\r
* - Added DataflashManager_WriteBlocks_RAM() and DataflashManager_ReadBlocks_RAM() functions to the MassStorage demo, to allow for easy\r
* interfacing with a FAT library for dataflash file level access\r
+ * - Incomplete non-functional BluetoothHost demo removed until it has reached a stable state to prevent confusion\r
*\r
* \section Sec_ChangeLog090209 Version 090209\r
*\r