Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XPROGTarget.h 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 XPROGTarget.c.
  29. */
  30. #ifndef _XPROG_TARGET_
  31. #define _XPROG_TARGET_
  32. /* Includes: */
  33. #include <avr/io.h>
  34. #include <avr/interrupt.h>
  35. #include <stdbool.h>
  36. #include <LUFA/Common/Common.h>
  37. #include "../V2Protocol.h"
  38. #include "XPROGProtocol.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. /** Serial carrier TPI/PDI speed in Hz, when hardware TPI/PDI mode is used. */
  48. #define XPROG_HARDWARE_SPEED 2000000
  49. /** Total number of bits in a single USART frame. */
  50. #define BITS_IN_USART_FRAME 12
  51. /** \name PDI Related Constants
  52. * @{
  53. */
  54. #define PDI_CMD_LDS(AddressSize, DataSize) (0x00 | ( AddressSize << 2) | DataSize)
  55. #define PDI_CMD_LD(PointerAccess, DataSize) (0x20 | (PointerAccess << 2) | DataSize)
  56. #define PDI_CMD_STS(AddressSize, DataSize) (0x40 | ( AddressSize << 2) | DataSize)
  57. #define PDI_CMD_ST(PointerAccess, DataSize) (0x60 | (PointerAccess << 2) | DataSize)
  58. #define PDI_CMD_LDCS(PDIReg) (0x80 | PDIReg)
  59. #define PDI_CMD_REPEAT(DataSize) (0xA0 | DataSize)
  60. #define PDI_CMD_STCS(PDIReg) (0xC0 | PDIReg)
  61. #define PDI_CMD_KEY 0xE0
  62. #define PDI_REG_STATUS 0
  63. #define PDI_REG_RESET 1
  64. #define PDI_REG_CTRL 2
  65. #define PDI_STATUS_NVM (1 << 1)
  66. #define PDI_RESET_KEY 0x59
  67. #define PDI_NVMENABLE_KEY (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF}
  68. #define PDI_DATASIZE_1BYTE 0
  69. #define PDI_DATASIZE_2BYTES 1
  70. #define PDI_DATASIZE_3BYTES 2
  71. #define PDI_DATASIZE_4BYTES 3
  72. #define PDI_POINTER_INDIRECT 0
  73. #define PDI_POINTER_INDIRECT_PI 1
  74. #define PDI_POINTER_DIRECT 2
  75. /** @} */
  76. /** \name TPI Related Constants
  77. * @{
  78. */
  79. #define TPI_CMD_SLD(PointerAccess) (0x20 | PointerAccess)
  80. #define TPI_CMD_SST(PointerAccess) (0x60 | PointerAccess)
  81. #define TPI_CMD_SSTPR 0x68
  82. #define TPI_CMD_SIN(Address) (0x10 | ((Address & 0x30) << 1) | (Address & 0x0F))
  83. #define TPI_CMD_SOUT(Address) (0x90 | ((Address & 0x30) << 1) | (Address & 0x0F))
  84. #define TPI_CMD_SLDCS(TPIReg) (0x80 | TPIReg)
  85. #define TPI_CMD_SSTCS(TPIReg) (0xC0 | TPIReg)
  86. #define TPI_CMD_SKEY 0xE0
  87. #define TPI_REG_STATUS 0x00
  88. #define TPI_REG_CTRL 0x02
  89. #define TPI_REG_ID 0x0F
  90. #define TPI_STATUS_NVM (1 << 1)
  91. #define TPI_NVMENABLE_KEY (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF}
  92. #define TPI_POINTER_INDIRECT 0
  93. #define TPI_POINTER_INDIRECT_PI 4
  94. /** @} */
  95. /* Function Prototypes: */
  96. void XPROGTarget_EnableTargetPDI(void);
  97. void XPROGTarget_EnableTargetTPI(void);
  98. void XPROGTarget_DisableTargetPDI(void);
  99. void XPROGTarget_DisableTargetTPI(void);
  100. void XPROGTarget_SendByte(const uint8_t Byte);
  101. uint8_t XPROGTarget_ReceiveByte(void);
  102. void XPROGTarget_SendIdle(void);
  103. bool XPROGTarget_WaitWhileNVMBusBusy(void);
  104. #if (defined(INCLUDE_FROM_XPROGTARGET_C) && defined(ENABLE_XPROG_PROTOCOL))
  105. static void XPROGTarget_SetTxMode(void);
  106. static void XPROGTarget_SetRxMode(void);
  107. #endif
  108. #endif