Updated bootloaders to use the new main() function layout and remove any references...
[pub/USBasp.git] / Bootloaders / CDC / BootloaderCDC.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /** \file
32 *
33 * Header file for BootloaderCDC.c.
34 */
35
36 #ifndef _CDC_H_
37 #define _CDC_H_
38
39 /* Includes: */
40 #include <avr/io.h>
41 #include <avr/wdt.h>
42 #include <avr/boot.h>
43 #include <avr/eeprom.h>
44 #include <avr/power.h>
45 #include <stdbool.h>
46
47 #include "Descriptors.h"
48
49 #include <LUFA/Drivers/USB/USB.h> // USB Functionality
50
51 /* Preprocessor Checks: */
52 #if !defined(SIGNATURE_0) || !defined(SIGNATURE_1) || !defined(SIGNATURE_2)
53 #error Device signature byte constants are not defined due to outdated avr-libc version. See demo documentation.
54 #endif
55
56 /* Macros: */
57 /** CDC Class Specific request to get the line encoding on a CDC-ACM virtual serial port, including the
58 * baud rate, parity, stop bits and data bits.
59 */
60 #define REQ_GetLineEncoding 0x21
61
62 /** CDC Class Specific request to set the line encoding on a CDC-ACM virtual serial port, including the
63 * baud rate, parity, stop bits and data bits.
64 */
65 #define REQ_SetLineEncoding 0x20
66
67 /** CDC Class Specific request to set the state of the serial handshake lines (such as DCD and RTS) on
68 * a CDC-ACM virtual serial port.
69 */
70 #define REQ_SetControlLineState 0x22
71
72 /** Version major of the CDC bootloader. */
73 #define BOOTLOADER_VERSION_MAJOR 0x01
74
75 /** Version minor of the CDC bootloader. */
76 #define BOOTLOADER_VERSION_MINOR 0x00
77
78 /** Hardware version major of the CDC bootloader. */
79 #define BOOTLOADER_HWVERSION_MAJOR 0x01
80
81 /** Hardware version minor of the CDC bootloader. */
82 #define BOOTLOADER_HWVERSION_MINOR 0x00
83
84 /** Eight character bootloader firmware identifier reported to the host when requested */
85 #define SOFTWARE_IDENTIFIER "LUFACDC"
86
87 /* Type Defines: */
88 /** Type define for a non-returning pointer to the start of the loaded application in flash memory. */
89 typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;
90
91 /** Type define for the CDC-ACM virtual serial port line encoding options, including baud rate, format, parity
92 * and size of each data chunk in bits.
93 */
94 typedef struct
95 {
96 uint32_t BaudRateBPS; /**< Baud rate in BPS */
97 uint8_t CharFormat; /**< Character format, an entry from the BootloaderCDC_CDC_LineCodingFormats_t enum */
98 uint8_t ParityType; /**< Parity mode, an entry from the BootloaderCDC_CDC_LineCodeingParity_t enum */
99 uint8_t DataBits; /**< Size of each data chunk, in bits */
100 } CDC_Line_Coding_t;
101
102 /* Enums: */
103 /** Enum for the possible line encoding formats on a CDC-ACM virtual serial port */
104 enum BootloaderCDC_CDC_LineCodingFormats_t
105 {
106 OneStopBit = 0, /**< Single stop bit */
107 OneAndAHalfStopBits = 1, /**< 1.5 stop bits */
108 TwoStopBits = 2, /**< Two stop bits */
109 };
110
111 /** Enum for the possible parity modes on a CDC-ACM virtual serial port */
112 enum BootloaderCDC_CDC_LineCodeingParity_t
113 {
114 Parity_None = 0, /**< No data parity checking */
115 Parity_Odd = 1, /**< Odd data parity checking */
116 Parity_Even = 2, /**< Even data parity checking */
117 Parity_Mark = 3, /**< Mark data parity checking */
118 Parity_Space = 4, /**< Space data parity checking */
119 };
120
121 /* Function Prototypes: */
122 void CDC_Task(void);
123 void SetupHardware(void);
124 void ResetHardware(void);
125
126 void EVENT_USB_Disconnect(void);
127 void EVENT_USB_ConfigurationChanged(void);
128 void EVENT_USB_UnhandledControlPacket(void);
129
130 #if defined(INCLUDE_FROM_BOOTLOADERCDC_C) || defined(__DOXYGEN__)
131 static void ReadWriteMemoryBlock(const uint8_t Command);
132 static uint8_t FetchNextCommandByte(void);
133 static void WriteNextResponseByte(const uint8_t Response);
134 #endif
135
136 #endif