Subversion Repositories NaviCtrl

Rev

Rev 261 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
171 ingob 6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
1 ingob 7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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. 
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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"
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171 ingob 28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
1 ingob 29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
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
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 
38
// +     for non-commercial use (directly or indirectly)
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
40
// +     with our written permission
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
42
// +     clearly linked as origin 
171 ingob 43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
1 ingob 44
//
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
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
55
// +  POSSIBILITY OF SUCH DAMAGE. 
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
112 killagreg 57
#include <string.h>
41 ingob 58
#include "91x_lib.h"
136 killagreg 59
#include "config.h"
112 killagreg 60
#include "main.h"
41 ingob 61
#include "uart1.h"
62
#include "usb.h"
111 killagreg 63
#include "mkprotocol.h"
112 killagreg 64
#include "waypoints.h"
65
#include "gps.h"
119 killagreg 66
#include "timer1.h"
112 killagreg 67
#include "uart0.h"
68
#include "uart1.h"
69
#include "uart2.h"
70
#include "menu.h"
111 killagreg 71
 
201 killagreg 72
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
73
u32 USB_AboTimeOut = 0;
111 killagreg 74
 
75
// the tx buffer
76
#define USB_TX_BUFFER_LEN  150
77
u8 USB_tbuffer[USB_TX_BUFFER_LEN];
78
Buffer_t USB_tx_buffer;
79
 
80
// the rx buffer
81
#define USB_RX_BUFFER_LEN  150
82
u8 USB_rbuffer[USB_RX_BUFFER_LEN];
83
Buffer_t USB_rx_buffer;
84
 
112 killagreg 85
u8 USB_Request_VersionInfo      = FALSE;
86
u8 USB_Request_SendFollowMe     = FALSE;
87
u8 USB_Request_ExternalControl= FALSE;
88
u8 USB_Request_Display          = FALSE;
89
u8 USB_Request_Display1         = FALSE;
90
u8 USB_Request_DebugData        = FALSE;
91
u8 USB_Request_DebugLabel       = 255;
92
u8 USB_Request_NaviData         = FALSE;
93
u8 USB_Request_ErrorMessage     = FALSE;
94
u8 USB_Request_NewWaypoint      = FALSE;
95
u8 USB_Request_ReadWaypoint     = 255;
96
u8 USB_Request_Data3D           = FALSE;
97
u8 USB_Request_Echo                 = FALSE;
111 killagreg 98
 
201 killagreg 99
u8 USB_DisplayKeys = 0;
112 killagreg 100
u8 USB_ConfirmFrame = 0;
101
 
102
u32 USB_DebugData_Timer = 0;
103
u32 USB_DebugData_Interval = 0; // in ms
104
u32 USB_NaviData_Timer = 0;
105
u32 USB_NaviData_Interval = 0;  // in ms
201 killagreg 106
u32 USB_Data3D_Timer = 0;              
107
u32 USB_Data3D_Interval = 0;    // in ms
108
u32 USB_Display_Timer = 0;
109
u32 USB_Display_Interval = 0;   // in ms
112 killagreg 110
 
1 ingob 111
//-----------------------------------------------------------------
112
void USB_ConfigInit(void)
113
{
41 ingob 114
        GPIO_InitTypeDef GPIO_InitStructure;
1 ingob 115
 
110 killagreg 116
        UART1_PutString("\r\n USB init...");
41 ingob 117
        #ifdef MCLK96MHZ
118
        //USB clock = MCLK/2 = 48MHz
119
        SCU_USBCLKConfig(SCU_USBCLK_MCLK2);
120
        #else
121
        //USB clock = MCLK = 48MHz
122
        SCU_USBCLKConfig(SCU_USBCLK_MCLK);
123
        #endif
124
        //Enable USB clock
125
        SCU_AHBPeriphClockConfig(__USB,ENABLE);
126
        SCU_AHBPeriphReset(__USB,DISABLE);
127
        SCU_AHBPeriphClockConfig(__USB48M,ENABLE);
1 ingob 128
 
41 ingob 129
        //Configure GPIO0 (D+ Pull-Up on P0.1)
130
        SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE);
131
        SCU_APBPeriphReset(__GPIO0,DISABLE);
1 ingob 132
 
41 ingob 133
        // GPIO_DeInit(P0.1);
134
        GPIO_StructInit(&GPIO_InitStructure);
135
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
136
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
137
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
196 killagreg 138
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
41 ingob 139
        GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
140
        GPIO_Init (GPIO0, &GPIO_InitStructure);
1 ingob 141
 
112 killagreg 142
        // initialize txd buffer
143
        Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN);
111 killagreg 144
 
145
        // initialize rxd buffer
112 killagreg 146
        Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN);
111 killagreg 147
 
41 ingob 148
        PowerOff();
149
        Virtual_Com_Port_Reset();
1 ingob 150
 
136 killagreg 151
        VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB);
41 ingob 152
        VIC_ITCmd(USBLP_ITLine, ENABLE);
1 ingob 153
 
41 ingob 154
        USB_Init();
1 ingob 155
 
110 killagreg 156
        UART1_PutString("ok");  
1 ingob 157
}
158
 
112 killagreg 159
 
160
/**************************************************************/
161
/* Process incomming data from debug uart                     */
162
/**************************************************************/
163
void USB_ProcessRxData(void)
164
{
165
        SerialMsg_t SerialMsg;
114 killagreg 166
        Waypoint_t * pWaypoint = NULL;
112 killagreg 167
        // if data in the rxd buffer are not locked immediately return
168
        if((USB_rx_buffer.Locked == FALSE) || (DebugUART != UART1) ) return;
169
 
190 killagreg 170
        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
114 killagreg 172
 
190 killagreg 173
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
174
        switch(SerialMsg.Address) // check for Slave Address
112 killagreg 175
        {
176
                case NC_ADDRESS:  // own Slave Address
190 killagreg 177
                switch(SerialMsg.CmdID)
112 killagreg 178
                {
179
                        case 'e': // request for the text of the error status
180
                                USB_Request_ErrorMessage = TRUE;
181
                                break;
182
 
183
                        case 's'://  new target position
184
                                pWaypoint = (Waypoint_t*)SerialMsg.pData;
185
                                BeepTime = 300;
186
                                if(pWaypoint->Position.Status == NEWDATA)
187
                                {
188
                                        WPList_Clear(); // empty WPList
189
                                        WPList_Append(pWaypoint);
190
                                        GPS_pWaypoint = WPList_Begin();
191
                                }
192
                                break;
193
                   /*
194
                        case 'u': // redirect debug uart
195
                                switch(SerialMsg.pData[0])
196
                                {
197
                                        case UART_FLIGHTCTRL:
198
                                                UART2_Init();                           // initialize UART2 to FC pins
199
                                                DebugUART = UART2;
200
                                                break;
201
                                        case UART_MK3MAG:
199 killagreg 202
                                                if(FC.Flags & FCFLAG_MOTOR_RUN) break; // not if the motors are running
112 killagreg 203
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
204
                                                GPSData.Status = INVALID;
205
                                                DebugUART = UART0;
206
                                                break;
207
                                        case UART_MKGPS:
199 killagreg 208
                                                if(FC.Flags & FCFLAG_MOTOR_RUN) break; // not if the motors are running
112 killagreg 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
217
                                pWaypoint = (Waypoint_t*)SerialMsg.pData;
218
                                if(pWaypoint->Position.Status == INVALID)
219
                                {  // clear WP List
220
                                        WPList_Clear();
221
                                        GPS_pWaypoint = WPList_Begin();
222
                                        //UART1_PutString("\r\nClear WP List\r\n");
223
                                }
224
                                else if (pWaypoint->Position.Status == NEWDATA)
225
                                {  // app current WP to the list
226
                                        WPList_Append(pWaypoint);
227
                                        BeepTime = 500;
228
                                        //UART1_PutString("\r\nAdd WP to List\r\n");
229
                                }
230
                                USB_Request_NewWaypoint = TRUE;
231
                                break;
232
 
233
                        case 'x'://  Read Waypoint from List
234
                                USB_Request_ReadWaypoint = SerialMsg.pData[0];
235
                                break;
236
 
237
                        default:
238
                                // unsupported command recieved
239
                                break;
240
                } // case NC_ADDRESS
241
                // "break;" is missing here to fall thru to the common commands
242
 
243
                default:  // and any other Slave Address
244
 
190 killagreg 245
                switch(SerialMsg.CmdID) // check CmdID
112 killagreg 246
                {
247
                        case 'a':// request for the labels of the analog debug outputs
248
                                USB_Request_DebugLabel = SerialMsg.pData[0];
249
                                if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31;
250
                                break;
201 killagreg 251
                        /*
112 killagreg 252
                        case 'b': // submit extern control
253
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
254
                                USB_ConfirmFrame = ExternControl.Frame;
255
                                break;
201 killagreg 256
                        */
112 killagreg 257
                        case 'd': // request for debug data;
258
                                USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
201 killagreg 259
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
112 killagreg 260
                                if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE;
261
                                break;
262
 
263
                        case 'c': // request for 3D data;
264
                                USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
201 killagreg 265
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
112 killagreg 266
                                if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE;
267
                                break;
201 killagreg 268
                        /*
112 killagreg 269
                        case 'g':// request for external control data
270
                                USB_Request_ExternalControl = TRUE;
271
                                break;
201 killagreg 272
                        */
112 killagreg 273
                        case 'h':// reqest for display line
201 killagreg 274
                                USB_DisplayKeys |= ~SerialMsg.pData[0];
275
                                USB_Display_Interval = (u32) SerialMsg.pData[1] * 10;
276
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
112 killagreg 277
                                USB_Request_Display = TRUE;
278
                                break;
279
 
280
                        case 'l':// reqest for display columns
281
                                MenuItem = SerialMsg.pData[0];
282
                                USB_Request_Display1 = TRUE;
283
                                break;
284
 
285
                        case 'o': // request for navigation information
286
                                USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
201 killagreg 287
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
112 killagreg 288
                                if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE;
289
                                break;
290
 
291
                        case 'v': // request for version info
292
                                USB_Request_VersionInfo = TRUE;
293
                                break;
294
                        default:
295
                                // unsupported command recieved
296
                                break;
297
                }
298
                break; // default:
299
        }
300
        Buffer_Clear(&USB_rx_buffer);
301
}
302
 
303
 
1 ingob 304
//-----------------------------------------------------------------
111 killagreg 305
void USB_CableConfig(FunctionalState NewState)
1 ingob 306
{
41 ingob 307
        if (NewState == ENABLE)
308
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET);
309
        else
310
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET);
1 ingob 311
}
312
 
313
//-----------------------------------------------------------------
111 killagreg 314
void USB_PutString(u8 *string)
1 ingob 315
{
41 ingob 316
        u8 i = 0;
317
        u16 timeout = 0;
318
 
111 killagreg 319
        while (string[i++] != 0){} // get string len
41 ingob 320
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
111 killagreg 321
        UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer
41 ingob 322
        SetEPTxCount(ENDP1,i);
323
        SetEPTxValid(ENDP1);
1 ingob 324
}
325
 
326
//-----------------------------------------------------------------
111 killagreg 327
void USB_PutChar(u8 c)
1 ingob 328
{
41 ingob 329
        u16 timeout = 0;
330
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
111 killagreg 331
        UserToPMABufferCopy(&c, ENDP1_TXADDR, 2);
41 ingob 332
        SetEPTxCount(ENDP1,2);
333
        SetEPTxValid(ENDP1);
334
}
335
 
1 ingob 336
//-----------------------------------------------------------------
111 killagreg 337
void USB_SendData(u8 *pdata, u16 count)
1 ingob 338
{
41 ingob 339
        u8 i;
340
        count++;
114 killagreg 341
        u16 timeout = 0;
41 ingob 342
 
343
        for (i=0;i< (count/64)+1;i++)  
344
        {
114 killagreg 345
                while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;}             
41 ingob 346
                if (i < (count/64))
347
                {
111 killagreg 348
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64);
41 ingob 349
                        SetEPTxCount(ENDP1,64);
350
                }
351
                else
352
                {
111 killagreg 353
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64);
41 ingob 354
                        SetEPTxCount(ENDP1, count % 64);
355
                }
356
                SetEPTxValid(ENDP1);
1 ingob 357
        }
358
}
359
 
112 killagreg 360
/**************************************************************/
361
/*         Transmit tx buffer via usb                         */
362
/**************************************************************/
363
void USB_Transmit(void)
364
{   // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal
365
        // if something has to be send and the txd fifo is not full
114 killagreg 366
        u16 i;
112 killagreg 367
        if(USB_tx_buffer.Locked == TRUE)
368
        {
114 killagreg 369
                if(_GetEPTxStatus(ENDP1) == EP_TX_NAK)
370
                //if(_GetEPTxStatus(ENDP1) != EP_TX_VALID) // ready to send
112 killagreg 371
                {
372
                        if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes)
373
                        {
114 killagreg 374
                                i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send
112 killagreg 375
                                if(i > 64) i = 64; // limit packet size to 64 bytes
376
                                UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i);
114 killagreg 377
                                SetEPTxCount(ENDP1,i);
378
                                SetEPTxValid(ENDP1);   
112 killagreg 379
                        USB_tx_buffer.Position += i;
380
                        }
381
                }
382
                if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered
383
                {
384
                        Buffer_Clear(&USB_tx_buffer); // clear buffer
385
                }
386
        }
387
}
388
 
389
/**************************************************************/
390
/* Send the answers to incomming commands at the debug uart   */
391
/**************************************************************/
392
void USB_TransmitTxData(void)
393
{
394
        USB_Transmit(); // output pending bytes in tx buffer
395
        if((USB_tx_buffer.Locked == TRUE)) return;
396
 
201 killagreg 397
        if(CheckDelay(USB_AboTimeOut))
398
        {
399
                USB_DebugData_Interval = 0;
400
                USB_NaviData_Interval = 0;
401
                USB_Data3D_Interval = 0;
402
                USB_Display_Interval = 0;
403
        }
404
 
112 killagreg 405
        if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE))
406
        {
407
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16);
408
                USB_Request_DebugLabel = 0xFF;
409
        }
201 killagreg 410
        else if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE))
112 killagreg 411
        {
412
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame));
413
                USB_ConfirmFrame = 0;
414
        }
201 killagreg 415
        else if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 416
        {
417
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
418
                USB_DebugData_Timer = SetDelay(USB_DebugData_Interval);
419
                USB_Request_DebugData = FALSE;
420
        }
201 killagreg 421
        else if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 422
        {
423
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
424
                USB_Data3D_Timer = SetDelay(USB_Data3D_Interval);
425
                USB_Request_Data3D = FALSE;
426
        }
201 killagreg 427
        else if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE))
112 killagreg 428
        {
429
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
430
                USB_Request_ExternalControl = FALSE;
431
        }
201 killagreg 432
        else if( (( (USB_Display_Interval > 0) && CheckDelay(USB_Display_Timer)) || USB_Request_Display) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 433
        {
201 killagreg 434
                Menu_Update(USB_DisplayKeys);
435
                USB_DisplayKeys = 0;
436
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
112 killagreg 437
                USB_Request_Display = FALSE;
438
        }
201 killagreg 439
        else if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE))
112 killagreg 440
        {
201 killagreg 441
                Menu_Update(0);
112 killagreg 442
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
443
                USB_Request_Display1 = FALSE;
444
        }
201 killagreg 445
        else if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE))
112 killagreg 446
        {
447
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
448
                USB_Request_VersionInfo = FALSE;
449
        }
201 killagreg 450
        else if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 451
        {
452
                NaviData.Errorcode = ErrorCode;
453
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
454
                USB_NaviData_Timer = SetDelay(USB_NaviData_Interval);
455
                USB_Request_NaviData = FALSE;
456
        }
201 killagreg 457
        else if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE))
112 killagreg 458
        {
459
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
460
                USB_Request_ErrorMessage = FALSE;
461
        }
201 killagreg 462
        else if(USB_Request_NewWaypoint && (USB_tx_buffer.Locked == FALSE))
112 killagreg 463
        {
464
                u8 WPNumber = WPList_GetCount();
465
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber));
466
                USB_Request_NewWaypoint = FALSE;
467
        }
201 killagreg 468
        else if((USB_Request_ReadWaypoint != 0xFF) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 469
        {
470
                u8 WPNumber = WPList_GetCount();
471
                if (USB_Request_ReadWaypoint < WPNumber)
472
                {
473
                        MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &USB_Request_ReadWaypoint, 1, WPList_GetAt(USB_Request_ReadWaypoint), sizeof(Waypoint_t));
474
                }
475
                else
476
                {
477
                        MKProtocol_CreateSerialFrame(&USB_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber));
478
                }
479
                USB_Request_ReadWaypoint = 0xFF;
480
        }
481
        USB_Transmit(); // output pending bytes in tx buffer
482
}