3      Copyright (C) Dean Camera, 2009. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, and distribute this software 
  13   and its documentation for any purpose and without fee is hereby 
  14   granted, provided that the above copyright notice appear in all 
  15   copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting 
  17   documentation, and that the name of the author not be used in 
  18   advertising or publicity pertaining to distribution of the 
  19   software without specific, written prior permission. 
  21   The author disclaim all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  33  *  Header file for BootloaderCDC.c. 
  43                 #include <avr/eeprom.h> 
  46                 #include "Descriptors.h" 
  48                 #include <LUFA/Drivers/USB/USB.h>                // USB Functionality 
  51                 /** CDC Class Specific request to get the line encoding on a CDC-ACM virtual serial port, including the 
  52                  *  baud rate, parity, stop bits and data bits. 
  54                 #define REQ_GetLineEncoding          0x21 
  56                 /** CDC Class Specific request to set the line encoding on a CDC-ACM virtual serial port, including the 
  57                  *  baud rate, parity, stop bits and data bits. 
  59                 #define REQ_SetLineEncoding          0x20 
  61                 /** CDC Class Specific request to set the state of the serial handshake lines (such as DCD and RTS) on 
  62                  *  a CDC-ACM virtual serial port. 
  64                 #define REQ_SetControlLineState      0x22 
  66                 /** Version major of the CDC bootloader. */ 
  67                 #define BOOTLOADER_VERSION_MAJOR     0x01 
  69                 /** Version minor of the CDC bootloader. */ 
  70                 #define BOOTLOADER_VERSION_MINOR     0x00 
  72                 /** Hardware version major of the CDC bootloader. */ 
  73                 #define BOOTLOADER_HWVERSION_MAJOR   0x01 
  75                 /** Hardware version minor of the CDC bootloader. */ 
  76                 #define BOOTLOADER_HWVERSION_MINOR   0x00 
  78                 /** Eight character bootloader firmware identifier reported to the host when requested */ 
  79                 #define SOFTWARE_IDENTIFIER          "LUFA-CDC" 
  82                 /** Indicates that this module will catch the USB_Disconnect event when thrown by the library. */ 
  83                 HANDLES_EVENT(USB_Disconnect
); 
  85                 /** Indicates that this module will catch the USB_ConfigurationChanged event when thrown by the library. */ 
  86                 HANDLES_EVENT(USB_ConfigurationChanged
); 
  88                 /** Indicates that this module will catch the USB_UnhandledControlPacket event when thrown by the library. */ 
  89                 HANDLES_EVENT(USB_UnhandledControlPacket
); 
  92                 /** Type define for a non-returning pointer to the start of the loaded application in flash memory. */ 
  93                 typedef void (*AppPtr_t
)(void) ATTR_NO_RETURN
; 
  95                 /** Type define for the CDC-ACM virtual serial port line encoding options, including baud rate, format, parity 
  96                  *  and size of each data chunk in bits. 
 100                         uint32_t BaudRateBPS
; /**< Baud rate in BPS */ 
 101                         uint8_t  CharFormat
; /**< Character format, an entry from the BootloaderCDC_CDC_LineCodingFormats_t enum */ 
 102                         uint8_t  ParityType
; /**< Parity mode, an entry from the BootloaderCDC_CDC_LineCodeingParity_t enum */ 
 103                         uint8_t  DataBits
; /**< Size of each data chunk, in bits */ 
 107                 /** Enum for the possible line encoding formats on a CDC-ACM virtual serial port */ 
 108                 enum BootloaderCDC_CDC_LineCodingFormats_t
 
 110                         OneStopBit          
= 0, /**< Single stop bit */ 
 111                         OneAndAHalfStopBits 
= 1, /**< 1.5 stop bits */ 
 112                         TwoStopBits         
= 2, /**< Two stop bits */ 
 115                 /** Enum for the possible parity modes on a CDC-ACM virtual serial port */ 
 116                 enum BootloaderCDC_CDC_LineCodeingParity_t
 
 118                         Parity_None         
= 0, /**< No data parity checking */ 
 119                         Parity_Odd          
= 1, /**< Odd data parity checking */ 
 120                         Parity_Even         
= 2, /**< Even data parity checking */ 
 121                         Parity_Mark         
= 3, /**< Mark data parity checking */ 
 122                         Parity_Space        
= 4, /**< Space data parity checking */ 
 128         /* Function Prototypes: */ 
 129                 #if defined(INCLUDE_FROM_BOOTLOADERCDC_C) || defined(__DOXYGEN__) 
 130                         static void ProgramReadWriteMemoryBlock(const uint8_t Command
); 
 131                         static uint8_t FetchNextCommandByte(void); 
 132                         static void WriteNextResponseByte(const uint8_t Response
);