]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/lufa/LUFA-git/Projects/AVRISP-MKII/Lib/XPROG/XPROGTarget.h
Merge commit '22b6e15a179031afb7c3534cf7b109b0668b602c'
[max/tmk_keyboard.git] / tmk_core / protocol / lufa / LUFA-git / Projects / AVRISP-MKII / Lib / XPROG / XPROGTarget.h
1 /*
2              LUFA Library
3      Copyright (C) Dean Camera, 2014.
4
5   dean [at] fourwalledcubicle [dot] com
6            www.lufa-lib.org
7 */
8
9 /*
10   Copyright 2014  Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12   Permission to use, copy, modify, distribute, and sell this
13   software and its documentation for any purpose is hereby granted
14   without fee, provided that the above copyright notice appear in
15   all 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 disclaims 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 XPROGTarget.c.
34  */
35
36 #ifndef _XPROG_TARGET_
37 #define _XPROG_TARGET_
38
39         /* Includes: */
40                 #include <avr/io.h>
41                 #include <avr/interrupt.h>
42                 #include <stdbool.h>
43
44                 #include <LUFA/Common/Common.h>
45
46                 #include "../V2Protocol.h"
47                 #include "XPROGProtocol.h"
48                 #include "Config/AppConfig.h"
49
50         /* Preprocessor Checks: */
51                 #if ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1))
52                         #undef ENABLE_ISP_PROTOCOL
53
54                         #if !defined(ENABLE_XPROG_PROTOCOL)
55                                 #define ENABLE_XPROG_PROTOCOL
56                         #endif
57                 #endif
58
59                 /** Serial carrier TPI/PDI speed in Hz, when hardware TPI/PDI mode is used. */
60                 #define XPROG_HARDWARE_SPEED       2000000
61
62                 /** Total number of bits in a single USART frame. */
63                 #define BITS_IN_USART_FRAME        12
64
65                 /** \name PDI Related Constants
66                  * @{
67                  */
68                 #define PDI_CMD_LDS(AddressSize, DataSize)  (0x00 | (  AddressSize << 2) | DataSize)
69                 #define PDI_CMD_LD(PointerAccess, DataSize) (0x20 | (PointerAccess << 2) | DataSize)
70                 #define PDI_CMD_STS(AddressSize, DataSize)  (0x40 | (  AddressSize << 2) | DataSize)
71                 #define PDI_CMD_ST(PointerAccess, DataSize) (0x60 | (PointerAccess << 2) | DataSize)
72                 #define PDI_CMD_LDCS(PDIReg)                (0x80 | PDIReg)
73                 #define PDI_CMD_REPEAT(DataSize)            (0xA0 | DataSize)
74                 #define PDI_CMD_STCS(PDIReg)                (0xC0 | PDIReg)
75                 #define PDI_CMD_KEY                         0xE0
76
77                 #define PDI_REG_STATUS             0
78                 #define PDI_REG_RESET              1
79                 #define PDI_REG_CTRL               2
80
81                 #define PDI_STATUS_NVM             (1 << 1)
82
83                 #define PDI_RESET_KEY              0x59
84                 #define PDI_NVMENABLE_KEY          (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF}
85
86                 #define PDI_DATASIZE_1BYTE         0
87                 #define PDI_DATASIZE_2BYTES        1
88                 #define PDI_DATASIZE_3BYTES        2
89                 #define PDI_DATASIZE_4BYTES        3
90
91                 #define PDI_POINTER_INDIRECT       0
92                 #define PDI_POINTER_INDIRECT_PI    1
93                 #define PDI_POINTER_DIRECT         2
94                 /** @} */
95
96                 /** \name TPI Related Constants
97                  * @{
98                  */
99                 #define TPI_CMD_SLD(PointerAccess) (0x20 | PointerAccess)
100                 #define TPI_CMD_SST(PointerAccess) (0x60 | PointerAccess)
101                 #define TPI_CMD_SSTPR              0x68
102                 #define TPI_CMD_SIN(Address)       (0x10 | ((Address & 0x30) << 1) | (Address & 0x0F))
103                 #define TPI_CMD_SOUT(Address)      (0x90 | ((Address & 0x30) << 1) | (Address & 0x0F))
104                 #define TPI_CMD_SLDCS(TPIReg)      (0x80 | TPIReg)
105                 #define TPI_CMD_SSTCS(TPIReg)      (0xC0 | TPIReg)
106                 #define TPI_CMD_SKEY               0xE0
107
108                 #define TPI_REG_STATUS             0x00
109                 #define TPI_REG_CTRL               0x02
110                 #define TPI_REG_ID                 0x0F
111
112                 #define TPI_STATUS_NVM             (1 << 1)
113
114                 #define TPI_NVMENABLE_KEY          (uint8_t[]){0x12, 0x89, 0xAB, 0x45, 0xCD, 0xD8, 0x88, 0xFF}
115
116                 #define TPI_POINTER_INDIRECT       0
117                 #define TPI_POINTER_INDIRECT_PI    4
118                 /** @} */
119
120         /* Function Prototypes: */
121                 void    XPROGTarget_EnableTargetPDI(void);
122                 void    XPROGTarget_EnableTargetTPI(void);
123                 void    XPROGTarget_DisableTargetPDI(void);
124                 void    XPROGTarget_DisableTargetTPI(void);
125                 void    XPROGTarget_SendByte(const uint8_t Byte);
126                 uint8_t XPROGTarget_ReceiveByte(void);
127                 void    XPROGTarget_SendIdle(void);
128                 bool    XPROGTarget_WaitWhileNVMBusBusy(void);
129
130                 #if (defined(INCLUDE_FROM_XPROGTARGET_C) && defined(ENABLE_XPROG_PROTOCOL))
131                         static void XPROGTarget_SetTxMode(void);
132                         static void XPROGTarget_SetRxMode(void);
133                 #endif
134
135 #endif
136