Keyboard firmwares for Atmel AVR and Cortex-M
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 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 disclaims 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 XMEGANVM.c.
  29. */
  30. #ifndef _XMEGA_NVM_
  31. #define _XMEGA_NVM_
  32. /* Includes: */
  33. #include <avr/io.h>
  34. #include <avr/interrupt.h>
  35. #include <stdbool.h>
  36. #include <LUFA/Common/Common.h>
  37. #include "XPROGProtocol.h"
  38. #include "XPROGTarget.h"
  39. #include "Config/AppConfig.h"
  40. /* Preprocessor Checks: */
  41. #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
  42. #undef ENABLE_ISP_PROTOCOL
  43. #if !defined(ENABLE_XPROG_PROTOCOL)
  44. #define ENABLE_XPROG_PROTOCOL
  45. #endif
  46. #endif
  47. /* Defines: */
  48. #define XMEGA_CRC_LENGTH_BYTES 3
  49. #define XMEGA_NVM_REG_ADDR0 0x00
  50. #define XMEGA_NVM_REG_ADDR1 0x01
  51. #define XMEGA_NVM_REG_ADDR2 0x02
  52. #define XMEGA_NVM_REG_DAT0 0x04
  53. #define XMEGA_NVM_REG_DAT1 0x05
  54. #define XMEGA_NVM_REG_DAT2 0x06
  55. #define XMEGA_NVM_REG_CMD 0x0A
  56. #define XMEGA_NVM_REG_CTRLA 0x0B
  57. #define XMEGA_NVM_REG_CTRLB 0x0C
  58. #define XMEGA_NVM_REG_INTCTRL 0x0D
  59. #define XMEGA_NVM_REG_STATUS 0x0F
  60. #define XMEGA_NVM_REG_LOCKBITS 0x10
  61. #define XMEGA_NVM_BIT_CTRLA_CMDEX (1 << 0)
  62. #define XMEGA_NVM_CMD_NOOP 0x00
  63. #define XMEGA_NVM_CMD_CHIPERASE 0x40
  64. #define XMEGA_NVM_CMD_READNVM 0x43
  65. #define XMEGA_NVM_CMD_LOADFLASHPAGEBUFF 0x23
  66. #define XMEGA_NVM_CMD_ERASEFLASHPAGEBUFF 0x26
  67. #define XMEGA_NVM_CMD_ERASEFLASHPAGE 0x2B
  68. #define XMEGA_NVM_CMD_WRITEFLASHPAGE 0x2E
  69. #define XMEGA_NVM_CMD_ERASEWRITEFLASH 0x2F
  70. #define XMEGA_NVM_CMD_FLASHCRC 0x78
  71. #define XMEGA_NVM_CMD_ERASEAPPSEC 0x20
  72. #define XMEGA_NVM_CMD_ERASEAPPSECPAGE 0x22
  73. #define XMEGA_NVM_CMD_WRITEAPPSECPAGE 0x24
  74. #define XMEGA_NVM_CMD_ERASEWRITEAPPSECPAGE 0x25
  75. #define XMEGA_NVM_CMD_APPCRC 0x38
  76. #define XMEGA_NVM_CMD_ERASEBOOTSEC 0x68
  77. #define XMEGA_NVM_CMD_ERASEBOOTSECPAGE 0x2A
  78. #define XMEGA_NVM_CMD_WRITEBOOTSECPAGE 0x2C
  79. #define XMEGA_NVM_CMD_ERASEWRITEBOOTSECPAGE 0x2D
  80. #define XMEGA_NVM_CMD_BOOTCRC 0x39
  81. #define XMEGA_NVM_CMD_READUSERSIG 0x03
  82. #define XMEGA_NVM_CMD_ERASEUSERSIG 0x18
  83. #define XMEGA_NVM_CMD_WRITEUSERSIG 0x1A
  84. #define XMEGA_NVM_CMD_READCALIBRATION 0x02
  85. #define XMEGA_NVM_CMD_READFUSE 0x07
  86. #define XMEGA_NVM_CMD_WRITEFUSE 0x4C
  87. #define XMEGA_NVM_CMD_WRITELOCK 0x08
  88. #define XMEGA_NVM_CMD_LOADEEPROMPAGEBUFF 0x33
  89. #define XMEGA_NVM_CMD_ERASEEEPROMPAGEBUFF 0x36
  90. #define XMEGA_NVM_CMD_ERASEEEPROM 0x30
  91. #define XMEGA_NVM_CMD_ERASEEEPROMPAGE 0x32
  92. #define XMEGA_NVM_CMD_WRITEEEPROMPAGE 0x34
  93. #define XMEGA_NVM_CMD_ERASEWRITEEEPROMPAGE 0x35
  94. #define XMEGA_NVM_CMD_READEEPROM 0x06
  95. /* Function Prototypes: */
  96. bool XMEGANVM_WaitWhileNVMBusBusy(void);
  97. bool XMEGANVM_WaitWhileNVMControllerBusy(void);
  98. bool XMEGANVM_EnablePDI(void);
  99. void XMEGANVM_DisablePDI(void);
  100. bool XMEGANVM_GetMemoryCRC(const uint8_t CRCCommand,
  101. uint32_t* const CRCDest);
  102. bool XMEGANVM_ReadMemory(const uint32_t ReadAddress,
  103. uint8_t* ReadBuffer,
  104. uint16_t ReadSize);
  105. bool XMEGANVM_WriteByteMemory(const uint8_t WriteCommand,
  106. const uint32_t WriteAddress,
  107. const uint8_t Byte);
  108. bool XMEGANVM_WritePageMemory(const uint8_t WriteBuffCommand,
  109. const uint8_t EraseBuffCommand,
  110. const uint8_t WritePageCommand,
  111. const uint8_t PageMode,
  112. const uint32_t WriteAddress,
  113. const uint8_t* WriteBuffer,
  114. uint16_t WriteSize);
  115. bool XMEGANVM_EraseMemory(const uint8_t EraseCommand,
  116. const uint32_t Address);
  117. #if defined(INCLUDE_FROM_XMEGANVM_C)
  118. static void XMEGANVM_SendNVMRegAddress(const uint8_t Register);
  119. static void XMEGANVM_SendAddress(const uint32_t AbsoluteAddress);
  120. #endif
  121. #endif