Caterina.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2011.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaim all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. *
  28. * Header file for BootloaderCDC.c.
  29. */
  30. #ifndef _CDC_H_
  31. #define _CDC_H_
  32. /* Includes: */
  33. #include <avr/io.h>
  34. #include <avr/wdt.h>
  35. #include <avr/boot.h>
  36. #include <avr/eeprom.h>
  37. #include <avr/power.h>
  38. #include <avr/interrupt.h>
  39. #include <stdbool.h>
  40. #include "Descriptors.h"
  41. #include <LUFA/Drivers/USB/USB.h>
  42. /* Macros: */
  43. /** Version major of the CDC bootloader. */
  44. #define BOOTLOADER_VERSION_MAJOR 0x01
  45. /** Version minor of the CDC bootloader. */
  46. #define BOOTLOADER_VERSION_MINOR 0x00
  47. /** Hardware version major of the CDC bootloader. */
  48. #define BOOTLOADER_HWVERSION_MAJOR 0x01
  49. /** Hardware version minor of the CDC bootloader. */
  50. #define BOOTLOADER_HWVERSION_MINOR 0x00
  51. /** Eight character bootloader firmware identifier reported to the host when requested */
  52. #define SOFTWARE_IDENTIFIER "CATERINA"
  53. #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
  54. #define LED_SETUP() DDRC |= (1<<7); DDRB |= (1<<0); DDRD |= (1<<5);
  55. #define L_LED_OFF() PORTC &= ~(1<<7)
  56. #define L_LED_ON() PORTC |= (1<<7)
  57. #define L_LED_TOGGLE() PORTC ^= (1<<7)
  58. #if DEVICE_PID == 0x0037 // polarity of the RX and TX LEDs is reversed on the Micro
  59. #define TX_LED_OFF() PORTD &= ~(1<<5)
  60. #define TX_LED_ON() PORTD |= (1<<5)
  61. #define RX_LED_OFF() PORTB &= ~(1<<0)
  62. #define RX_LED_ON() PORTB |= (1<<0)
  63. #else
  64. #define TX_LED_OFF() PORTD |= (1<<5)
  65. #define TX_LED_ON() PORTD &= ~(1<<5)
  66. #define RX_LED_OFF() PORTB |= (1<<0)
  67. #define RX_LED_ON() PORTB &= ~(1<<0)
  68. #endif
  69. /* Type Defines: */
  70. /** Type define for a non-returning pointer to the start of the loaded application in flash memory. */
  71. typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;
  72. /* Function Prototypes: */
  73. void StartSketch(void);
  74. void LEDPulse(void);
  75. void CDC_Task(void);
  76. void SetupHardware(void);
  77. void EVENT_USB_Device_ConfigurationChanged(void);
  78. #if defined(INCLUDE_FROM_CATERINA_C) || defined(__DOXYGEN__)
  79. #if !defined(NO_BLOCK_SUPPORT)
  80. static void ReadWriteMemoryBlock(const uint8_t Command);
  81. #endif
  82. static uint8_t FetchNextCommandByte(void);
  83. static void WriteNextResponseByte(const uint8_t Response);
  84. #endif
  85. #endif