Commit e0af6014 authored by Dean Camera's avatar Dean Camera

Added incomplete PrinterHost demo application.

Seperated out Lib components of the incomplete BluetoothHost demo application out into a seperate Lib subfolder.

Changed F_CLOCK entries in project makefiles to alias to F_CPU by default, as this is the most common case.
parent b462f2d4
......@@ -89,7 +89,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Starting byte address of the bootloader
......
......@@ -89,7 +89,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Starting byte address of the bootloader
......
......@@ -89,7 +89,7 @@ F_CPU = 16000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 16000000
F_CLOCK = $(F_CPU)
# Starting byte address of the bootloader
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -214,10 +214,10 @@ static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* MSInterfaceInf
*/
static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo)
{
uint32_t TotalLUNs = (LUN_MEDIA_BLOCKS - 1);
uint32_t MediaBlockSize = VIRTUAL_MEMORY_BLOCK_SIZE;
uint32_t LastBlockAddressInLUN = (LUN_MEDIA_BLOCKS - 1);
uint32_t MediaBlockSize = VIRTUAL_MEMORY_BLOCK_SIZE;
Endpoint_Write_Stream_BE(&TotalLUNs, sizeof(TotalLUNs), NO_STREAM_CALLBACK);
Endpoint_Write_Stream_BE(&LastBlockAddressInLUN, sizeof(LastBlockAddressInLUN), NO_STREAM_CALLBACK);
Endpoint_Write_Stream_BE(&MediaBlockSize, sizeof(MediaBlockSize), NO_STREAM_CALLBACK);
Endpoint_ClearIN();
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -254,9 +254,9 @@ static bool ReadInCommandBlock(void)
return false;
/* Verify the command block - abort if invalid */
if ((CommandBlock.Signature != CBW_SIGNATURE) ||
(CommandBlock.LUN >= TOTAL_LUNS) ||
(CommandBlock.SCSICommandLength > MAX_SCSI_COMMAND_LENGTH))
if ((CommandBlock.Signature != CBW_SIGNATURE) ||
(CommandBlock.LUN >= TOTAL_LUNS) ||
(CommandBlock.SCSICommandLength > MAX_SCSI_COMMAND_LENGTH))
{
/* Stall both data pipes until reset by host */
Endpoint_StallTransaction();
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......
......@@ -50,7 +50,6 @@ int main(void)
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
/* Startup message */
puts_P(PSTR(ESC_RESET ESC_BG_WHITE ESC_INVERSE_ON ESC_ERASE_DISPLAY
"Bluetooth Host Demo running.\r\n" ESC_INVERSE_OFF));
......@@ -111,6 +110,7 @@ void EVENT_USB_DeviceEnumerationFailed(uint8_t ErrorCode, uint8_t SubErrorCode)
{
puts_P(PSTR(ESC_BG_RED "Dev Enum Error\r\n"));
printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);
printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);
printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
......
......@@ -38,7 +38,7 @@
#include <avr/power.h>
#include <stdio.h>
#include "BluetoothStack.h"
#include "Lib/BluetoothStack.h"
#include "DeviceDescriptor.h"
#include "ConfigDescriptor.h"
......
......@@ -101,7 +101,7 @@ F_CPU = 8000000
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_CLOCK = 8000000
F_CLOCK = $(F_CPU)
# Output format. (can be srec, ihex, binary)
......@@ -133,9 +133,9 @@ LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
SRC = $(TARGET).c \
DeviceDescriptor.c \
ConfigDescriptor.c \
BluetoothStack.c \
BluetoothHCICommands.c \
BluetoothACLPackets.c \
Lib/BluetoothStack.c \
Lib/BluetoothHCICommands.c \
Lib/BluetoothACLPackets.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
......
/*
LUFA Library
Copyright (C) Dean Camera, 2009.
dean [at] fourwalledcubicle [dot] com
www.fourwalledcubicle.com
*/
/*
Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
#include "ConfigDescriptor.h"
uint8_t ProcessConfigurationDescriptor(void)
{
uint8_t* ConfigDescriptorData;
uint16_t ConfigDescriptorSize;
uint8_t ErrorCode;
uint8_t FoundEndpoints = 0;
uint8_t FoundEndpointMask;
/* Get Configuration Descriptor size from the device */
if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)
return ControlError;
/* Ensure that the Configuration Descriptor isn't too large */
if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)
return DescriptorTooLarge;
/* Allocate enough memory for the entire config descriptor */
ConfigDescriptorData = alloca(ConfigDescriptorSize);
/* Retrieve the entire configuration descriptor into the allocated buffer */
USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);
/* Validate returned data - ensure first entry is a configuration header descriptor */
if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
return InvalidConfigDataReturned;
/* Get the printer interface from the configuration descriptor */
if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
NextPrinterInterface)))
{
/* Descriptor not found, error out */
return NoInterfaceFound;
}
/* Get the printer's communication protocol */
PrinterProtocol = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_Interface_t).Protocol;
/* Determine what endpoints to look for from the protocol */
switch (PrinterProtocol)
{
case PROTOCOL_UNIDIRECTIONAL:
FoundEndpointMask = (1 << PRINTER_DATA_OUT_PIPE);
break;
case PROTOCOL_BIDIRECTIONAL:
case PROTOCOL_IEEE1284:
FoundEndpointMask = ((1 << PRINTER_DATA_OUT_PIPE) | (1 << PRINTER_DATA_IN_PIPE));
break;
default:
return NoInterfaceFound;
}
/* Get the IN and OUT data endpoints for the mass storage interface */
while (FoundEndpoints != FoundEndpointMask)
{
/* Fetch the next bulk endpoint from the current printer interface */
if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
NextInterfaceBulkDataEndpoint)))
{
/* Descriptor not found, error out */
return NoEndpointFound;
}
USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t);
/* Check if the endpoint is a bulk IN or bulk OUT endpoint, set appropriate globals */
if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
{
/* Configure the data IN pipe */
Pipe_ConfigurePipe(PRINTER_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN,
EndpointData->EndpointAddress, EndpointData->EndpointSize,
PIPE_BANK_SINGLE);
Pipe_SetInfiniteINRequests();
/* Set the flag indicating that the data IN pipe has been found */
FoundEndpoints |= (1 << PRINTER_DATA_IN_PIPE);
}
else
{
/* Configure the data OUT pipe */
Pipe_ConfigurePipe(PRINTER_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT,
EndpointData->EndpointAddress, EndpointData->EndpointSize,
PIPE_BANK_SINGLE);
/* Set the flag indicating that the data OUT pipe has been found */
FoundEndpoints |= (1 << PRINTER_DATA_OUT_PIPE);
}
}
/* Valid data found, return success */
return SuccessfulConfigRead;
}
uint8_t NextPrinterInterface(void* CurrentDescriptor)
{
/* PURPOSE: Find next mass storage class interface descriptor */
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
{
/* Check the descriptor class and protocol, break out if correct class/protocol interface found */
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == PRINTER_CLASS) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == PRINTER_SUBCLASS))
{
return DESCRIPTOR_SEARCH_Found;
}
}
return DESCRIPTOR_SEARCH_NotFound;
}
uint8_t NextInterfaceBulkDataEndpoint(void* CurrentDescriptor)
{
/* PURPOSE: Find next interface bulk endpoint descriptor before next interface descriptor */
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
{
uint8_t EndpointType = (DESCRIPTOR_CAST(CurrentDescriptor,
USB_Descriptor_Endpoint_t).Attributes & EP_TYPE_MASK);
/* Check the endpoint type, break out if correct BULK type endpoint found */
if (EndpointType == EP_TYPE_BULK)
return DESCRIPTOR_SEARCH_Found;
}
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
{
return DESCRIPTOR_SEARCH_Fail;
}
return DESCRIPTOR_SEARCH_NotFound;
}
/*
LUFA Library
Copyright (C) Dean Camera, 2009.
dean [at] fourwalledcubicle [dot] com
www.fourwalledcubicle.com
*/
/*
Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
#