|
15 | 15 | #include "TMC5072.h" |
16 | 16 | #include "stdio.h" |
17 | 17 |
|
| 18 | +// clang-format off |
| 19 | + |
18 | 20 | // these addresses are fixed |
19 | | -#define SERIAL_MODULE_ADDRESS 1 |
20 | | -#define SERIAL_HOST_ADDRESS 2 |
| 21 | +#define SERIAL_MODULE_ADDRESS 1 |
| 22 | +#define SERIAL_HOST_ADDRESS 2 |
21 | 23 |
|
22 | 24 | const int BUILD_VERSION = 30824; |
23 | | -const char * VersionString = "0016V308"; |
24 | | -#define ID_TMC5072 7 |
| 25 | +const char *VersionString = "0016V308"; |
| 26 | +#define ID_TMC5072 7 |
25 | 27 | #define TMC_ADDRESS_MASK 0x7F |
26 | 28 | #define TMC_ADDRESS(x) ((x) & (TMC_ADDRESS_MASK)) |
27 | | -#define CAST_Sn_TO_S32(value, n) \ |
28 | | - ((value) | (((value) & ((uint32_t)1 << ((n)-1))) ? ~(((uint32_t)1 << (n)) - 1) : 0)) |
| 29 | +#define CAST_Sn_TO_S32(value, n) ((value) | (((value) & ((uint32_t)1<<((n)-1)))? ~(((uint32_t)1<<(n))-1) : 0 )) |
29 | 30 |
|
30 | 31 | // id detection state definitions |
31 | | -#define ID_STATE_WAIT_LOW 0 // id detection waiting for first edge (currently low) |
32 | | -#define ID_STATE_WAIT_HIGH 1 // id detection waiting for second edge (currently high) |
33 | | -#define ID_STATE_DONE 2 // id detection finished successfully |
34 | | -#define ID_STATE_INVALID \ |
35 | | - 3 // id detection failed - we got an answer, but no corresponding ID (invalid ID pulse length) |
36 | | -#define ID_STATE_NO_ANSWER 4 // id detection failed - board doesn't answer |
37 | | -#define ID_STATE_TIMEOUT 5 // id detection failed - board id pulse went high but not low |
38 | | -#define ID_STATE_NOT_IN_FW \ |
39 | | - 6 // id detection detected a valid id that is not supported in this firmware |
| 32 | +#define ID_STATE_WAIT_LOW 0 // id detection waiting for first edge (currently low) |
| 33 | +#define ID_STATE_WAIT_HIGH 1 // id detection waiting for second edge (currently high) |
| 34 | +#define ID_STATE_DONE 2 // id detection finished successfully |
| 35 | +#define ID_STATE_INVALID 3 // id detection failed - we got an answer, but no corresponding ID (invalid ID pulse length) |
| 36 | +#define ID_STATE_NO_ANSWER 4 // id detection failed - board doesn't answer |
| 37 | +#define ID_STATE_TIMEOUT 5 // id detection failed - board id pulse went high but not low |
| 38 | +#define ID_STATE_NOT_IN_FW 6 // id detection detected a valid id that is not supported in this firmware |
40 | 39 |
|
41 | 40 | // todo CHECK 2: these are unused - delete? (LH) #11 |
42 | 41 | // tmcl interpreter states |
43 | | -#define TM_IDLE 0 |
44 | | -#define TM_RUN 1 |
45 | | -#define TM_STEP 2 |
46 | | -#define TM_RESET 3 // unused |
47 | | -#define TM_DOWNLOAD 4 |
48 | | -#define TM_DEBUG 5 // wie TM_IDLE, es wird jedoch der Akku nicht modifiziert bei GAP etc. |
| 42 | +#define TM_IDLE 0 |
| 43 | +#define TM_RUN 1 |
| 44 | +#define TM_STEP 2 |
| 45 | +#define TM_RESET 3 // unused |
| 46 | +#define TM_DOWNLOAD 4 |
| 47 | +#define TM_DEBUG 5 // wie TM_IDLE, es wird jedoch der Akku nicht modifiziert bei GAP etc. |
49 | 48 |
|
50 | 49 | // todo CHECK 2: these are unused - delete? (LH) #12 |
51 | | -#define TCS_IDLE 0 |
52 | | -#define TCS_CAN7 1 |
53 | | -#define TCS_CAN8 2 |
54 | | -#define TCS_UART 3 |
55 | | -#define TCS_UART_ERROR 4 |
56 | | -#define TCS_UART_II 5 |
57 | | -#define TCS_UART_II_ERROR 6 |
58 | | -#define TCS_USB 7 |
59 | | -#define TCS_USB_ERROR 8 |
60 | | -#define TCS_MEM 9 |
| 50 | +#define TCS_IDLE 0 |
| 51 | +#define TCS_CAN7 1 |
| 52 | +#define TCS_CAN8 2 |
| 53 | +#define TCS_UART 3 |
| 54 | +#define TCS_UART_ERROR 4 |
| 55 | +#define TCS_UART_II 5 |
| 56 | +#define TCS_UART_II_ERROR 6 |
| 57 | +#define TCS_USB 7 |
| 58 | +#define TCS_USB_ERROR 8 |
| 59 | +#define TCS_MEM 9 |
61 | 60 |
|
62 | 61 | // TMCL commands |
63 | | -#define TMCL_ROR 1 |
64 | | -#define TMCL_ROL 2 |
65 | | -#define TMCL_MST 3 |
66 | | -#define TMCL_MVP 4 |
67 | | -#define TMCL_SAP 5 |
68 | | -#define TMCL_GAP 6 |
69 | | -#define TMCL_STAP 7 |
70 | | -#define TMCL_RSAP 8 |
71 | | -#define TMCL_SGP 9 |
72 | | -#define TMCL_GGP 10 |
73 | | -#define TMCL_STGP 11 |
74 | | -#define TMCL_RSGP 12 |
75 | | -#define TMCL_RFS 13 |
76 | | -#define TMCL_SIO 14 |
77 | | -#define TMCL_GIO 15 |
78 | | -#define TMCL_CALC 19 |
79 | | -#define TMCL_COMP 20 |
80 | | -#define TMCL_JC 21 |
81 | | -#define TMCL_JA 22 |
82 | | -#define TMCL_CSUB 23 |
83 | | -#define TMCL_RSUB 24 |
84 | | -#define TMCL_EI 25 |
85 | | -#define TMCL_DI 26 |
86 | | -#define TMCL_WAIT 27 |
87 | | -#define TMCL_STOP 28 |
88 | | -#define TMCL_SAC 29 |
89 | | -#define TMCL_SCO 30 |
90 | | -#define TMCL_GCO 31 |
91 | | -#define TMCL_CCO 32 |
92 | | -#define TMCL_CALCX 33 |
93 | | -#define TMCL_AAP 34 |
94 | | -#define TMCL_AGP 35 |
95 | | -#define TMCL_CLE 36 |
96 | | -#define TMCL_VECT 37 |
97 | | -#define TMCL_RETI 38 |
98 | | -#define TMCL_ACO 39 |
| 62 | +#define TMCL_ROR 1 |
| 63 | +#define TMCL_ROL 2 |
| 64 | +#define TMCL_MST 3 |
| 65 | +#define TMCL_MVP 4 |
| 66 | +#define TMCL_SAP 5 |
| 67 | +#define TMCL_GAP 6 |
| 68 | +#define TMCL_STAP 7 |
| 69 | +#define TMCL_RSAP 8 |
| 70 | +#define TMCL_SGP 9 |
| 71 | +#define TMCL_GGP 10 |
| 72 | +#define TMCL_STGP 11 |
| 73 | +#define TMCL_RSGP 12 |
| 74 | +#define TMCL_RFS 13 |
| 75 | +#define TMCL_SIO 14 |
| 76 | +#define TMCL_GIO 15 |
| 77 | +#define TMCL_CALC 19 |
| 78 | +#define TMCL_COMP 20 |
| 79 | +#define TMCL_JC 21 |
| 80 | +#define TMCL_JA 22 |
| 81 | +#define TMCL_CSUB 23 |
| 82 | +#define TMCL_RSUB 24 |
| 83 | +#define TMCL_EI 25 |
| 84 | +#define TMCL_DI 26 |
| 85 | +#define TMCL_WAIT 27 |
| 86 | +#define TMCL_STOP 28 |
| 87 | +#define TMCL_SAC 29 |
| 88 | +#define TMCL_SCO 30 |
| 89 | +#define TMCL_GCO 31 |
| 90 | +#define TMCL_CCO 32 |
| 91 | +#define TMCL_CALCX 33 |
| 92 | +#define TMCL_AAP 34 |
| 93 | +#define TMCL_AGP 35 |
| 94 | +#define TMCL_CLE 36 |
| 95 | +#define TMCL_VECT 37 |
| 96 | +#define TMCL_RETI 38 |
| 97 | +#define TMCL_ACO 39 |
99 | 98 |
|
100 | | -#define TMCL_UF0 64 |
101 | | -#define TMCL_UF1 65 |
102 | | -#define TMCL_UF2 66 |
103 | | -#define TMCL_UF3 67 |
104 | | -#define TMCL_UF4 68 |
105 | | -#define TMCL_UF5 69 |
106 | | -#define TMCL_UF6 70 |
107 | | -#define TMCL_UF7 71 |
108 | | -#define TMCL_UF8 72 |
| 99 | +#define TMCL_UF0 64 |
| 100 | +#define TMCL_UF1 65 |
| 101 | +#define TMCL_UF2 66 |
| 102 | +#define TMCL_UF3 67 |
| 103 | +#define TMCL_UF4 68 |
| 104 | +#define TMCL_UF5 69 |
| 105 | +#define TMCL_UF6 70 |
| 106 | +#define TMCL_UF7 71 |
| 107 | +#define TMCL_UF8 72 |
109 | 108 |
|
110 | | -#define TMCL_ApplStop 128 |
111 | | -#define TMCL_ApplRun 129 |
112 | | -#define TMCL_ApplStep 130 |
113 | | -#define TMCL_ApplReset 131 |
114 | | -#define TMCL_DownloadStart 132 |
115 | | -#define TMCL_DownloadEnd 133 |
116 | | -#define TMCL_ReadMem 134 |
117 | | -#define TMCL_GetStatus 135 |
118 | | -#define TMCL_GetVersion 136 |
119 | | -#define TMCL_FactoryDefault 137 |
120 | | -#define TMCL_SetEvent 138 |
121 | | -#define TMCL_SetASCII 139 |
122 | | -#define TMCL_SecurityCode 140 |
123 | | -#define TMCL_Breakpoint 141 |
124 | | -#define TMCL_RamDebug 142 |
125 | | -#define TMCL_GetIds 143 |
126 | | -#define TMCL_UF_CH1 144 |
127 | | -#define TMCL_UF_CH2 145 |
128 | | -#define TMCL_writeRegisterChannel_1 146 |
129 | | -#define TMCL_writeRegisterChannel_2 147 |
130 | | -#define TMCL_readRegisterChannel_1 148 |
131 | | -#define TMCL_readRegisterChannel_2 149 |
| 109 | +#define TMCL_ApplStop 128 |
| 110 | +#define TMCL_ApplRun 129 |
| 111 | +#define TMCL_ApplStep 130 |
| 112 | +#define TMCL_ApplReset 131 |
| 113 | +#define TMCL_DownloadStart 132 |
| 114 | +#define TMCL_DownloadEnd 133 |
| 115 | +#define TMCL_ReadMem 134 |
| 116 | +#define TMCL_GetStatus 135 |
| 117 | +#define TMCL_GetVersion 136 |
| 118 | +#define TMCL_FactoryDefault 137 |
| 119 | +#define TMCL_SetEvent 138 |
| 120 | +#define TMCL_SetASCII 139 |
| 121 | +#define TMCL_SecurityCode 140 |
| 122 | +#define TMCL_Breakpoint 141 |
| 123 | +#define TMCL_RamDebug 142 |
| 124 | +#define TMCL_GetIds 143 |
| 125 | +#define TMCL_UF_CH1 144 |
| 126 | +#define TMCL_UF_CH2 145 |
| 127 | +#define TMCL_writeRegisterChannel_1 146 |
| 128 | +#define TMCL_writeRegisterChannel_2 147 |
| 129 | +#define TMCL_readRegisterChannel_1 148 |
| 130 | +#define TMCL_readRegisterChannel_2 149 |
132 | 131 |
|
133 | | -#define TMCL_BoardMeasuredSpeed 150 |
134 | | -#define TMCL_BoardError 151 |
135 | | -#define TMCL_BoardReset 152 |
| 132 | +#define TMCL_BoardMeasuredSpeed 150 |
| 133 | +#define TMCL_BoardError 151 |
| 134 | +#define TMCL_BoardReset 152 |
136 | 135 |
|
137 | | -#define TMCL_WLAN 160 |
138 | | -#define TMCL_WLAN_CMD 160 |
139 | | -#define TMCL_WLAN_IS_RTS 161 |
140 | | -#define TMCL_WLAN_CMDMODE_EN 162 |
141 | | -#define TMCL_WLAN_IS_CMDMODE 163 |
| 136 | +#define TMCL_WLAN 160 |
| 137 | +#define TMCL_WLAN_CMD 160 |
| 138 | +#define TMCL_WLAN_IS_RTS 161 |
| 139 | +#define TMCL_WLAN_CMDMODE_EN 162 |
| 140 | +#define TMCL_WLAN_IS_CMDMODE 163 |
142 | 141 |
|
143 | | -#define TMCL_MIN 170 |
144 | | -#define TMCL_MAX 171 |
145 | | -#define TMCL_OTP 172 |
| 142 | +#define TMCL_MIN 170 |
| 143 | +#define TMCL_MAX 171 |
| 144 | +#define TMCL_OTP 172 |
146 | 145 |
|
147 | | -#define TMCL_Boot 242 |
148 | | -#define TMCL_SoftwareReset 255 |
| 146 | +#define TMCL_Boot 242 |
| 147 | +#define TMCL_SoftwareReset 255 |
149 | 148 |
|
150 | 149 | // Command type variants |
151 | | -#define MVP_ABS 0 |
152 | | -#define MVP_REL 1 |
153 | | -#define MVP_PRF 2 |
| 150 | +#define MVP_ABS 0 |
| 151 | +#define MVP_REL 1 |
| 152 | +#define MVP_PRF 2 |
154 | 153 |
|
155 | 154 | // GetVersion() Format types |
156 | | -#define VERSION_FORMAT_ASCII 0 |
157 | | -#define VERSION_FORMAT_BINARY 1 |
158 | | -#define VERSION_BOOTLOADER \ |
159 | | - 2 // todo CHECK 2: implemented this way in IDE - probably means getting the bootloader version. Not implemented in firmware (LH) |
160 | | -#define VERSION_SIGNATURE \ |
161 | | - 3 // todo CHECK 2: implemented under "Signature" in IDE. Not sure what to return for that. Not implemented in firmware (LH) |
162 | | -#define VERSION_BOARD_DETECT_SRC \ |
163 | | - 4 // todo CHECK 2: This doesn't really fit under GetVersion, but its implemented there in the IDE - change or leave this way? (LH) |
164 | | -#define VERSION_BUILD 5 |
| 155 | +#define VERSION_FORMAT_ASCII 0 |
| 156 | +#define VERSION_FORMAT_BINARY 1 |
| 157 | +#define VERSION_BOOTLOADER 2 // todo CHECK 2: implemented this way in IDE - probably means getting the bootloader version. Not implemented in firmware (LH) |
| 158 | +#define VERSION_SIGNATURE 3 // todo CHECK 2: implemented under "Signature" in IDE. Not sure what to return for that. Not implemented in firmware (LH) |
| 159 | +#define VERSION_BOARD_DETECT_SRC 4 // todo CHECK 2: This doesn't really fit under GetVersion, but its implemented there in the IDE - change or leave this way? (LH) |
| 160 | +#define VERSION_BUILD 5 |
165 | 161 |
|
166 | 162 | //Statuscodes |
167 | | -#define REPLY_OK 100 |
168 | | -#define REPLY_CMD_LOADED 101 |
169 | | -#define REPLY_CHKERR 1 |
170 | | -#define REPLY_INVALID_CMD 2 |
171 | | -#define REPLY_INVALID_TYPE 3 |
172 | | -#define REPLY_INVALID_VALUE 4 |
173 | | -#define REPLY_EEPROM_LOCKED 5 |
174 | | -#define REPLY_CMD_NOT_AVAILABLE 6 |
175 | | -#define REPLY_CMD_LOAD_ERROR 7 |
176 | | -#define REPLY_WRITE_PROTECTED 8 |
177 | | -#define REPLY_MAX_EXCEEDED 9 |
178 | | -#define REPLY_DOWNLOAD_NOT_POSSIBLE 10 |
179 | | -#define REPLY_CHIP_READ_FAILED 11 |
180 | | -#define REPLY_DELAYED 128 |
181 | | -#define REPLY_ACTIVE_COMM 129 |
| 163 | +#define REPLY_OK 100 |
| 164 | +#define REPLY_CMD_LOADED 101 |
| 165 | +#define REPLY_CHKERR 1 |
| 166 | +#define REPLY_INVALID_CMD 2 |
| 167 | +#define REPLY_INVALID_TYPE 3 |
| 168 | +#define REPLY_INVALID_VALUE 4 |
| 169 | +#define REPLY_EEPROM_LOCKED 5 |
| 170 | +#define REPLY_CMD_NOT_AVAILABLE 6 |
| 171 | +#define REPLY_CMD_LOAD_ERROR 7 |
| 172 | +#define REPLY_WRITE_PROTECTED 8 |
| 173 | +#define REPLY_MAX_EXCEEDED 9 |
| 174 | +#define REPLY_DOWNLOAD_NOT_POSSIBLE 10 |
| 175 | +#define REPLY_CHIP_READ_FAILED 11 |
| 176 | +#define REPLY_DELAYED 128 |
| 177 | +#define REPLY_ACTIVE_COMM 129 |
182 | 178 |
|
183 | 179 | // TMCL communication status |
184 | | -#define TMCL_RX_ERROR_NONE 0 |
185 | | -#define TMCL_RX_ERROR_NODATA 1 |
186 | | -#define TMCL_RX_ERROR_CHECKSUM 2 |
| 180 | +#define TMCL_RX_ERROR_NONE 0 |
| 181 | +#define TMCL_RX_ERROR_NODATA 1 |
| 182 | +#define TMCL_RX_ERROR_CHECKSUM 2 |
| 183 | + |
| 184 | +// clang-format on |
187 | 185 |
|
188 | 186 | uint32_t vmax_position[2]; |
189 | 187 |
|
|
0 commit comments