Rev 201 | Rev 280 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 201 | Rev 275 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
8 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
22 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
25 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + this list of conditions and the following disclaimer. |
34 | // + this list of conditions and the following disclaimer. |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + from this software without specific prior written permission. |
36 | // + from this software without specific prior written permission. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + for non-commercial use (directly or indirectly) |
38 | // + for non-commercial use (directly or indirectly) |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + with our written permission |
40 | // + with our written permission |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + clearly linked as origin |
42 | // + clearly linked as origin |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
44 | // |
44 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
Line 50... | Line 50... | ||
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 57 | #include <stdio.h> |
|
57 | #include <string.h> |
58 | #include <string.h> |
58 | #include "91x_lib.h" |
59 | #include "91x_lib.h" |
59 | #include "config.h" |
60 | #include "config.h" |
60 | #include "main.h" |
61 | #include "main.h" |
61 | #include "uart1.h" |
62 | #include "uart1.h" |
62 | #include "usb.h" |
- | |
63 | #include "mkprotocol.h" |
63 | #include "mkprotocol.h" |
64 | #include "waypoints.h" |
64 | #include "waypoints.h" |
65 | #include "gps.h" |
65 | #include "gps.h" |
66 | #include "timer1.h" |
66 | #include "timer1.h" |
67 | #include "uart0.h" |
67 | #include "uart0.h" |
68 | #include "uart1.h" |
68 | #include "uart1.h" |
69 | #include "uart2.h" |
69 | #include "uart2.h" |
70 | #include "menu.h" |
70 | #include "menu.h" |
- | 71 | #include "usb.h" |
|
Line 71... | Line 72... | ||
71 | 72 | ||
72 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
73 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
Line -... | Line 74... | ||
- | 74 | u32 USB_AboTimeOut = 0; |
|
- | 75 | ||
- | 76 | u16 Echo; // 2 bytes recieved will be sent back as echo |
|
- | 77 | ||
- | 78 | // the primary rx fifo |
|
- | 79 | #define USB_RX_FIFO_LEN 512 |
|
- | 80 | u8 USB_rxfifobuffer[USB_RX_FIFO_LEN]; |
|
73 | u32 USB_AboTimeOut = 0; |
81 | fifo_t USB_rx_fifo; |
74 | 82 | ||
75 | // the tx buffer |
83 | // the tx buffer |
76 | #define USB_TX_BUFFER_LEN 150 |
84 | #define USB_TX_BUFFER_LEN 150 |
Line 93... | Line 101... | ||
93 | u8 USB_Request_ErrorMessage = FALSE; |
101 | u8 USB_Request_ErrorMessage = FALSE; |
94 | u8 USB_Request_NewWaypoint = FALSE; |
102 | u8 USB_Request_NewWaypoint = FALSE; |
95 | u8 USB_Request_ReadWaypoint = 255; |
103 | u8 USB_Request_ReadWaypoint = 255; |
96 | u8 USB_Request_Data3D = FALSE; |
104 | u8 USB_Request_Data3D = FALSE; |
97 | u8 USB_Request_Echo = FALSE; |
105 | u8 USB_Request_Echo = FALSE; |
98 | - | ||
99 | u8 USB_DisplayKeys = 0; |
106 | u8 USB_DisplayKeys = 0; |
- | 107 | u8 USB_DisplayLine = 0; |
|
100 | u8 USB_ConfirmFrame = 0; |
108 | u8 USB_ConfirmFrame = 0; |
Line 101... | Line 109... | ||
101 | 109 | ||
102 | u32 USB_DebugData_Timer = 0; |
110 | u32 USB_DebugData_Timer = 0; |
103 | u32 USB_DebugData_Interval = 0; // in ms |
111 | u32 USB_DebugData_Interval = 0; // in ms |
104 | u32 USB_NaviData_Timer = 0; |
112 | u32 USB_NaviData_Timer = 0; |
105 | u32 USB_NaviData_Interval = 0; // in ms |
113 | u32 USB_NaviData_Interval = 0; // in ms |
106 | u32 USB_Data3D_Timer = 0; |
114 | u32 USB_Data3D_Timer = 0; |
107 | u32 USB_Data3D_Interval = 0; // in ms |
115 | u32 USB_Data3D_Interval = 0; // in ms |
108 | u32 USB_Display_Timer = 0; |
116 | u32 USB_Display_Timer = 0; |
Line 109... | Line 117... | ||
109 | u32 USB_Display_Interval = 0; // in ms |
117 | u32 USB_Display_Interval = 0; // in ms |
110 | 118 | ||
111 | //----------------------------------------------------------------- |
119 | //----------------------------------------------------------------- |
112 | void USB_ConfigInit(void) |
120 | void USB_ConfigInit(void) |
113 | { |
121 | { |
114 | GPIO_InitTypeDef GPIO_InitStructure; |
122 | GPIO_InitTypeDef GPIO_InitStructure; |
115 | 123 | ||
116 | UART1_PutString("\r\n USB init..."); |
124 | UART1_PutString("\r\n USB init..."); |
117 | #ifdef MCLK96MHZ |
125 | #ifdef MCLK96MHZ |
118 | //USB clock = MCLK/2 = 48MHz |
126 | //USB clock = MCLK/2 = 48MHz |
Line 137... | Line 145... | ||
137 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
145 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
138 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
146 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
139 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
147 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
140 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
148 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
Line -... | Line 149... | ||
- | 149 | ||
- | 150 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
|
- | 151 | fifo_init(&USB_rx_fifo, USB_rxfifobuffer, USB_RX_FIFO_LEN, NO_ITLine, USBLP_ITLine); |
|
141 | 152 | ||
142 | // initialize txd buffer |
153 | // initialize txd buffer |
143 | Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); |
154 | Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); |
144 | 155 | ||
145 | // initialize rxd buffer |
156 | // initialize rxd buffer |
Line 146... | Line -... | ||
146 | Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); |
- | |
147 | - | ||
148 | PowerOff(); |
- | |
149 | Virtual_Com_Port_Reset(); |
157 | Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); |
150 | 158 | ||
151 | VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB); |
159 | VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB); |
152 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
160 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
153 | 161 | ||
154 | USB_Init(); |
162 | USB_Init(); |
155 | 163 | ||
Line 156... | Line 164... | ||
156 | UART1_PutString("ok"); |
164 | UART1_PutString("ok"); |
157 | } |
165 | } |
158 | 166 | ||
159 | 167 | ||
160 | /**************************************************************/ |
168 | /**************************************************************/ |
- | 169 | /* Process incomming data from debug uart */ |
|
161 | /* Process incomming data from debug uart */ |
170 | /**************************************************************/ |
162 | /**************************************************************/ |
171 | void USB_ProcessRxData(void) |
163 | void USB_ProcessRxData(void) |
172 | { |
- | 173 | u8 c; |
|
- | 174 | SerialMsg_t SerialMsg; |
|
- | 175 | Waypoint_t * pWaypoint = NULL; |
|
- | 176 | // if data in the rxd buffer are not locked immediately return |
|
- | 177 | // if rx buffer is not locked |
|
- | 178 | if(USB_rx_buffer.Locked == FALSE) |
|
- | 179 | { |
|
- | 180 | //collect data from primary rx fifo |
|
- | 181 | while(fifo_get(&USB_rx_fifo, &c)) |
|
- | 182 | { |
|
164 | { |
183 | // break if complete frame has been collected |
Line 165... | Line 184... | ||
165 | SerialMsg_t SerialMsg; |
184 | if(MKProtocol_CollectSerialFrame(&USB_rx_buffer, c)) break; |
166 | Waypoint_t * pWaypoint = NULL; |
185 | } |
Line 167... | Line 186... | ||
167 | // if data in the rxd buffer are not locked immediately return |
186 | } |
168 | if((USB_rx_buffer.Locked == FALSE) || (DebugUART != UART1) ) return; |
187 | if(USB_rx_buffer.Locked == FALSE) return; |
169 | 188 | ||
170 | MKProtocol_DecodeSerialFrameHeader(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
189 | MKProtocol_DecodeSerialFrameHeader(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
171 | MKProtocol_DecodeSerialFrameData(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
190 | MKProtocol_DecodeSerialFrameData(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
172 | 191 | ||
- | 192 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
|
- | 193 | switch(SerialMsg.Address) // check for Slave Address |
|
- | 194 | { |
|
- | 195 | case NC_ADDRESS: // own Slave Address |
|
- | 196 | switch(SerialMsg.CmdID) |
|
173 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
197 | { |
174 | switch(SerialMsg.Address) // check for Slave Address |
198 | case 'z': // connection checker |
175 | { |
199 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
Line 176... | Line 200... | ||
176 | case NC_ADDRESS: // own Slave Address |
200 | USB_Request_Echo = TRUE; |
Line 188... | Line 212... | ||
188 | WPList_Clear(); // empty WPList |
212 | WPList_Clear(); // empty WPList |
189 | WPList_Append(pWaypoint); |
213 | WPList_Append(pWaypoint); |
190 | GPS_pWaypoint = WPList_Begin(); |
214 | GPS_pWaypoint = WPList_Begin(); |
191 | } |
215 | } |
192 | break; |
216 | break; |
193 | /* |
- | |
194 | case 'u': // redirect debug uart |
- | |
195 | switch(SerialMsg.pData[0]) |
- | |
196 | { |
217 | |
197 | case UART_FLIGHTCTRL: |
- | |
198 | UART2_Init(); // initialize UART2 to FC pins |
- | |
199 | DebugUART = UART2; |
- | |
200 | break; |
- | |
201 | case UART_MK3MAG: |
- | |
202 | if(FC.Flags & FCFLAG_MOTOR_RUN) break; // not if the motors are running |
- | |
203 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
- | |
204 | GPSData.Status = INVALID; |
- | |
205 | DebugUART = UART0; |
- | |
206 | break; |
- | |
207 | case UART_MKGPS: |
- | |
208 | if(FC.Flags & FCFLAG_MOTOR_RUN) break; // not if the motors are running |
- | |
209 | UART0_Connect_to_MKGPS(); // connect UART0 to MKGPS pins |
- | |
210 | GPSData.Status = INVALID; |
- | |
211 | DebugUART = UART0; |
- | |
212 | break; |
- | |
213 | } |
- | |
214 | break; |
- | |
215 | */ |
- | |
216 | case 'w':// Append Waypoint to List |
218 | case 'w':// Append Waypoint to List |
- | 219 | { |
|
217 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
220 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
- | 221 | ||
218 | if(pWaypoint->Position.Status == INVALID) |
222 | if((pWaypoint->Position.Status == INVALID) && (pWaypoint->Index == 0)) |
219 | { // clear WP List |
223 | { |
220 | WPList_Clear(); |
224 | WPList_Clear(); |
221 | GPS_pWaypoint = WPList_Begin(); |
225 | GPS_pWaypoint = WPList_Begin(); |
222 | //UART1_PutString("\r\nClear WP List\r\n"); |
226 | USB_Request_NewWaypoint = TRUE; // return new WP number |
223 | } |
227 | } |
224 | else if (pWaypoint->Position.Status == NEWDATA) |
228 | else |
225 | { // app current WP to the list |
229 | { // app current WP to the list |
- | 230 | if (pWaypoint->Index == (WPList_GetCount() + 1)) |
|
- | 231 | { |
|
226 | WPList_Append(pWaypoint); |
232 | WPList_Append(pWaypoint); |
227 | BeepTime = 500; |
233 | BeepTime = 500; |
228 | //UART1_PutString("\r\nAdd WP to List\r\n"); |
234 | USB_Request_NewWaypoint = TRUE; // return new WP number |
- | 235 | } |
|
- | 236 | } |
|
229 | } |
237 | } |
230 | USB_Request_NewWaypoint = TRUE; |
- | |
231 | break; |
238 | break; |
Line 232... | Line 239... | ||
232 | 239 | ||
233 | case 'x':// Read Waypoint from List |
240 | case 'x':// Read Waypoint from List |
234 | USB_Request_ReadWaypoint = SerialMsg.pData[0]; |
241 | USB_Request_ReadWaypoint = SerialMsg.pData[0]; |
Line 254... | Line 261... | ||
254 | USB_ConfirmFrame = ExternControl.Frame; |
261 | USB_ConfirmFrame = ExternControl.Frame; |
255 | break; |
262 | break; |
256 | */ |
263 | */ |
257 | case 'd': // request for debug data; |
264 | case 'd': // request for debug data; |
258 | USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
265 | USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
259 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
- | |
260 | if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE; |
266 | if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE; |
- | 267 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
|
261 | break; |
268 | break; |
Line 262... | Line 269... | ||
262 | 269 | ||
263 | case 'c': // request for 3D data; |
270 | case 'c': // request for 3D data; |
264 | USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
- | |
265 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
271 | USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
- | 272 | if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE; |
|
266 | if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE; |
273 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
267 | break; |
- | |
268 | /* |
- | |
269 | case 'g':// request for external control data |
- | |
270 | USB_Request_ExternalControl = TRUE; |
- | |
271 | break; |
274 | break; |
272 | */ |
275 | |
- | 276 | case 'h':// reqest for display line |
|
- | 277 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
|
- | 278 | { |
|
- | 279 | USB_DisplayLine = 2; |
|
- | 280 | USB_Display_Interval = 0; |
|
- | 281 | } |
|
- | 282 | else |
|
273 | case 'h':// reqest for display line |
283 | { |
274 | USB_DisplayKeys |= ~SerialMsg.pData[0]; |
284 | USB_DisplayKeys |= ~SerialMsg.pData[0]; |
- | 285 | USB_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
|
275 | USB_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
286 | USB_DisplayLine = 4; |
- | 287 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
|
276 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
288 | } |
277 | USB_Request_Display = TRUE; |
289 | USB_Request_Display = TRUE; |
Line 278... | Line 290... | ||
278 | break; |
290 | break; |
279 | 291 | ||
280 | case 'l':// reqest for display columns |
292 | case 'l':// reqest for display columns |
281 | MenuItem = SerialMsg.pData[0]; |
293 | MenuItem = SerialMsg.pData[0]; |
Line 282... | Line 294... | ||
282 | USB_Request_Display1 = TRUE; |
294 | USB_Request_Display1 = TRUE; |
283 | break; |
295 | break; |
284 | - | ||
285 | case 'o': // request for navigation information |
296 | |
- | 297 | case 'o': // request for navigation information |
|
286 | USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
298 | USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
Line 287... | Line 299... | ||
287 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
299 | if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE; |
288 | if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE; |
300 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
289 | break; |
301 | break; |
Line 307... | Line 319... | ||
307 | if (NewState == ENABLE) |
319 | if (NewState == ENABLE) |
308 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
320 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
309 | else |
321 | else |
310 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
322 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
311 | } |
323 | } |
- | 324 | //----------------------------------------------------------------- |
|
- | 325 | void USB_EnterLowPowerMode(void) |
|
- | 326 | { |
|
- | 327 | /* Set the device state to suspend */ |
|
- | 328 | bDeviceState = SUSPENDED; |
|
- | 329 | } |
|
- | 330 | //----------------------------------------------------------------- |
|
- | 331 | void USB_LeaveLowPowerMode(void) |
|
- | 332 | { |
|
- | 333 | DEVICE_INFO *pInfo = &Device_Info; |
|
- | 334 | ||
- | 335 | /* Set the device state to the correct state */ |
|
- | 336 | if (pInfo->Current_Configuration != 0) |
|
- | 337 | { |
|
- | 338 | /* Device configured */ |
|
- | 339 | bDeviceState = CONFIGURED; |
|
- | 340 | } |
|
- | 341 | else |
|
- | 342 | { |
|
- | 343 | bDeviceState = ATTACHED; |
|
- | 344 | } |
|
- | 345 | } |
|
- | 346 | ||
Line 312... | Line 347... | ||
312 | 347 | ||
313 | //----------------------------------------------------------------- |
348 | //----------------------------------------------------------------- |
314 | void USB_PutString(u8 *string) |
349 | void USB_PutString(u8 *string) |
315 | { |
350 | { |
316 | u8 i = 0; |
351 | u8 i = 0; |
317 | u16 timeout = 0; |
352 | u16 timeout = 0; |
318 | 353 | ||
319 | while (string[i++] != 0){} // get string len |
354 | while (string[i++] != 0){} // get string len |
320 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
355 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
321 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
356 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
322 | SetEPTxCount(ENDP1,i); |
357 | SetEPTxCount(ENDP1,i); |
323 | SetEPTxValid(ENDP1); |
358 | SetEPTxValid(ENDP1); |
Line 324... | Line 359... | ||
324 | } |
359 | } |
325 | 360 | ||
326 | //----------------------------------------------------------------- |
361 | //----------------------------------------------------------------- |
327 | void USB_PutChar(u8 c) |
362 | void USB_PutChar(u8 c) |
328 | { |
363 | { |
329 | u16 timeout = 0; |
364 | u16 timeout = 0; |
330 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
365 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
331 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
366 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
332 | SetEPTxCount(ENDP1,2); |
367 | SetEPTxCount(ENDP1,2); |
333 | SetEPTxValid(ENDP1); |
368 | SetEPTxValid(ENDP1); |
334 | } |
369 | } |
335 | 370 | ||
336 | //----------------------------------------------------------------- |
371 | //----------------------------------------------------------------- |
337 | void USB_SendData(u8 *pdata, u16 count) |
372 | void USB_SendData(u8 *pdata, u16 count) |
338 | { |
373 | { |
339 | u8 i; |
374 | u8 i; |
340 | count++; |
375 | count++; |
341 | u16 timeout = 0; |
376 | u16 timeout = 0; |
342 | 377 | ||
343 | for (i=0;i< (count/64)+1;i++) |
378 | for (i=0;i< (count/64)+1;i++) |
344 | { |
379 | { |
345 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;} |
380 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;} |
346 | if (i < (count/64)) |
381 | if (i < (count/64)) |
347 | { |
382 | { |
348 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
383 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
349 | SetEPTxCount(ENDP1,64); |
384 | SetEPTxCount(ENDP1,64); |
350 | } |
385 | } |
351 | else |
386 | else |
352 | { |
387 | { |
353 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
388 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
354 | SetEPTxCount(ENDP1, count % 64); |
389 | SetEPTxCount(ENDP1, count % 64); |
355 | } |
390 | } |
356 | SetEPTxValid(ENDP1); |
391 | SetEPTxValid(ENDP1); |
Line 357... | Line 392... | ||
357 | } |
392 | } |
358 | } |
393 | } |
359 | 394 | ||
360 | /**************************************************************/ |
395 | /**************************************************************/ |
361 | /* Transmit tx buffer via usb */ |
396 | /* Transmit tx buffer via usb */ |
362 | /**************************************************************/ |
397 | /**************************************************************/ |
363 | void USB_Transmit(void) |
398 | void USB_Transmit(void) |
364 | { // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal |
399 | { // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal |
365 | // if something has to be send and the txd fifo is not full |
400 | // if something has to be send and the txd fifo is not full |
366 | u16 i; |
401 | |
367 | if(USB_tx_buffer.Locked == TRUE) |
- | |
368 | { |
402 | if(USB_tx_buffer.Locked == TRUE) |
- | 403 | { |
|
369 | if(_GetEPTxStatus(ENDP1) == EP_TX_NAK) |
404 | if(_GetEPTxStatus(ENDP1) == EP_TX_NAK) |
370 | //if(_GetEPTxStatus(ENDP1) != EP_TX_VALID) // ready to send |
405 | { |
371 | { |
406 | u16 i; |
372 | if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes) |
407 | if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes) |
373 | { |
408 | { |
374 | i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send |
409 | i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send |
375 | if(i > 64) i = 64; // limit packet size to 64 bytes |
410 | if(i > 64) i = 64; // limit packet size to 64 bytes |
376 | UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i); |
411 | UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i); |
377 | SetEPTxCount(ENDP1,i); |
412 | SetEPTxCount(ENDP1,i); |
378 | SetEPTxValid(ENDP1); |
413 | SetEPTxValid(ENDP1); |
379 | USB_tx_buffer.Position += i; |
414 | USB_tx_buffer.Position += i; |
380 | } |
415 | } |