Subversion Repositories NaviCtrl

Rev

Rev 313 | 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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
275 killagreg 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.
1 ingob 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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
275 killagreg 17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
1 ingob 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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
275 killagreg 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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
275 killagreg 33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
1 ingob 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.
275 killagreg 37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
1 ingob 38
// +     for non-commercial use (directly or indirectly)
275 killagreg 39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
1 ingob 40
// +     with our written permission
275 killagreg 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
275 killagreg 55
// +  POSSIBILITY OF SUCH DAMAGE.
1 ingob 56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
275 killagreg 57
#include <stdio.h>
112 killagreg 58
#include <string.h>
41 ingob 59
#include "91x_lib.h"
136 killagreg 60
#include "config.h"
112 killagreg 61
#include "main.h"
41 ingob 62
#include "uart1.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"
275 killagreg 71
#include "usb.h"
111 killagreg 72
 
201 killagreg 73
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
74
u32 USB_AboTimeOut = 0;
111 killagreg 75
 
275 killagreg 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];
81
fifo_t USB_rx_fifo;
82
 
111 killagreg 83
// the tx buffer
84
#define USB_TX_BUFFER_LEN  150
85
u8 USB_tbuffer[USB_TX_BUFFER_LEN];
86
Buffer_t USB_tx_buffer;
87
 
88
// the rx buffer
89
#define USB_RX_BUFFER_LEN  150
90
u8 USB_rbuffer[USB_RX_BUFFER_LEN];
91
Buffer_t USB_rx_buffer;
92
 
112 killagreg 93
u8 USB_Request_VersionInfo      = FALSE;
94
u8 USB_Request_SendFollowMe     = FALSE;
95
u8 USB_Request_ExternalControl= FALSE;
96
u8 USB_Request_Display          = FALSE;
97
u8 USB_Request_Display1         = FALSE;
98
u8 USB_Request_DebugData        = FALSE;
99
u8 USB_Request_DebugLabel       = 255;
100
u8 USB_Request_NaviData         = FALSE;
101
u8 USB_Request_ErrorMessage     = FALSE;
102
u8 USB_Request_Data3D           = FALSE;
103
u8 USB_Request_Echo                 = FALSE;
201 killagreg 104
u8 USB_DisplayKeys = 0;
275 killagreg 105
u8 USB_DisplayLine                      = 0;
112 killagreg 106
u8 USB_ConfirmFrame = 0;
107
 
108
u32 USB_DebugData_Timer = 0;
109
u32 USB_DebugData_Interval = 0; // in ms
110
u32 USB_NaviData_Timer = 0;
111
u32 USB_NaviData_Interval = 0;  // in ms
275 killagreg 112
u32 USB_Data3D_Timer = 0;
201 killagreg 113
u32 USB_Data3D_Interval = 0;    // in ms
114
u32 USB_Display_Timer = 0;
115
u32 USB_Display_Interval = 0;   // in ms
112 killagreg 116
 
1 ingob 117
//-----------------------------------------------------------------
118
void USB_ConfigInit(void)
119
{
41 ingob 120
        GPIO_InitTypeDef GPIO_InitStructure;
275 killagreg 121
 
110 killagreg 122
        UART1_PutString("\r\n USB init...");
41 ingob 123
        #ifdef MCLK96MHZ
124
        //USB clock = MCLK/2 = 48MHz
125
        SCU_USBCLKConfig(SCU_USBCLK_MCLK2);
126
        #else
127
        //USB clock = MCLK = 48MHz
128
        SCU_USBCLKConfig(SCU_USBCLK_MCLK);
129
        #endif
130
        //Enable USB clock
131
        SCU_AHBPeriphClockConfig(__USB,ENABLE);
132
        SCU_AHBPeriphReset(__USB,DISABLE);
133
        SCU_AHBPeriphClockConfig(__USB48M,ENABLE);
1 ingob 134
 
41 ingob 135
        //Configure GPIO0 (D+ Pull-Up on P0.1)
136
        SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE);
137
        SCU_APBPeriphReset(__GPIO0,DISABLE);
1 ingob 138
 
41 ingob 139
        // GPIO_DeInit(P0.1);
140
        GPIO_StructInit(&GPIO_InitStructure);
141
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
142
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
143
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
196 killagreg 144
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
41 ingob 145
        GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
146
        GPIO_Init (GPIO0, &GPIO_InitStructure);
1 ingob 147
 
275 killagreg 148
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
149
        fifo_init(&USB_rx_fifo, USB_rxfifobuffer, USB_RX_FIFO_LEN, NO_ITLine, USBLP_ITLine);
150
 
112 killagreg 151
        // initialize txd buffer
152
        Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN);
275 killagreg 153
 
111 killagreg 154
        // initialize rxd buffer
112 killagreg 155
        Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN);
111 killagreg 156
 
136 killagreg 157
        VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB);
41 ingob 158
        VIC_ITCmd(USBLP_ITLine, ENABLE);
275 killagreg 159
 
41 ingob 160
        USB_Init();
275 killagreg 161
 
162
        UART1_PutString("ok");
1 ingob 163
}
164
 
112 killagreg 165
 
166
/**************************************************************/
167
/* Process incomming data from debug uart                     */
168
/**************************************************************/
169
void USB_ProcessRxData(void)
170
{
275 killagreg 171
        u8 c;
112 killagreg 172
        SerialMsg_t SerialMsg;
280 killagreg 173
 
112 killagreg 174
        // if data in the rxd buffer are not locked immediately return
275 killagreg 175
        // if rx buffer is not locked
176
        if(USB_rx_buffer.Locked == FALSE)
177
        {
178
                //collect data from primary rx fifo
179
                while(fifo_get(&USB_rx_fifo, &c))
180
                {
181
                        // break if complete frame has been collected
182
                        if(MKProtocol_CollectSerialFrame(&USB_rx_buffer, c)) break;
183
                }
184
        }
185
        if(USB_rx_buffer.Locked == FALSE) return;
112 killagreg 186
 
190 killagreg 187
        MKProtocol_DecodeSerialFrameHeader(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
188
        MKProtocol_DecodeSerialFrameData(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
114 killagreg 189
 
190 killagreg 190
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
191
        switch(SerialMsg.Address) // check for Slave Address
112 killagreg 192
        {
193
                case NC_ADDRESS:  // own Slave Address
190 killagreg 194
                switch(SerialMsg.CmdID)
112 killagreg 195
                {
275 killagreg 196
                        case 'z': // connection checker
197
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
198
                                USB_Request_Echo = TRUE;
199
                                break;
200
 
112 killagreg 201
                        case 'e': // request for the text of the error status
202
                                USB_Request_ErrorMessage = TRUE;
203
                                break;
204
 
205
                        default:
206
                                // unsupported command recieved
207
                                break;
208
                } // case NC_ADDRESS
209
                // "break;" is missing here to fall thru to the common commands
210
 
211
                default:  // and any other Slave Address
212
 
190 killagreg 213
                switch(SerialMsg.CmdID) // check CmdID
112 killagreg 214
                {
215
                        case 'a':// request for the labels of the analog debug outputs
216
                                USB_Request_DebugLabel = SerialMsg.pData[0];
217
                                if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31;
218
                                break;
201 killagreg 219
                        /*
112 killagreg 220
                        case 'b': // submit extern control
221
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
222
                                USB_ConfirmFrame = ExternControl.Frame;
223
                                break;
201 killagreg 224
                        */
112 killagreg 225
                        case 'd': // request for debug data;
226
                                USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
275 killagreg 227
                                if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE;
201 killagreg 228
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
112 killagreg 229
                                break;
230
 
231
                        case 'c': // request for 3D data;
232
                                USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
275 killagreg 233
                                if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE;
201 killagreg 234
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
112 killagreg 235
                                break;
275 killagreg 236
 
112 killagreg 237
                        case 'h':// reqest for display line
275 killagreg 238
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
239
                                {
240
                                        USB_DisplayLine = 2;
241
                                        USB_Display_Interval = 0;
242
                                }
243
                                else
244
                                {
245
                                        USB_DisplayKeys |= ~SerialMsg.pData[0];
246
                                        USB_Display_Interval = (u32) SerialMsg.pData[1] * 10;
247
                                        USB_DisplayLine = 4;
248
                                        USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
249
                                }
112 killagreg 250
                                USB_Request_Display = TRUE;
251
                                break;
252
 
253
                        case 'l':// reqest for display columns
254
                                MenuItem = SerialMsg.pData[0];
255
                                USB_Request_Display1 = TRUE;
256
                                break;
257
 
258
                        case 'o': // request for navigation information
259
                                USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
275 killagreg 260
                                if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE;
201 killagreg 261
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
112 killagreg 262
                                break;
263
 
264
                        case 'v': // request for version info
265
                                USB_Request_VersionInfo = TRUE;
266
                                break;
267
                        default:
268
                                // unsupported command recieved
269
                                break;
270
                }
271
                break; // default:
272
        }
273
        Buffer_Clear(&USB_rx_buffer);
274
}
275
 
276
 
1 ingob 277
//-----------------------------------------------------------------
111 killagreg 278
void USB_CableConfig(FunctionalState NewState)
1 ingob 279
{
41 ingob 280
        if (NewState == ENABLE)
281
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET);
282
        else
283
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET);
1 ingob 284
}
275 killagreg 285
//-----------------------------------------------------------------
286
void USB_EnterLowPowerMode(void)
287
{
288
  /* Set the device state to suspend */
289
  bDeviceState = SUSPENDED;
290
}
291
//-----------------------------------------------------------------
292
void USB_LeaveLowPowerMode(void)
293
{
294
  DEVICE_INFO *pInfo = &Device_Info;
1 ingob 295
 
275 killagreg 296
  /* Set the device state to the correct state */
297
  if (pInfo->Current_Configuration != 0)
298
  {
299
    /* Device configured */
300
    bDeviceState = CONFIGURED;
301
  }
302
  else
303
  {
304
    bDeviceState = ATTACHED;
305
  }
306
}
307
 
308
 
1 ingob 309
//-----------------------------------------------------------------
111 killagreg 310
void USB_PutString(u8 *string)
1 ingob 311
{
41 ingob 312
        u8 i = 0;
313
        u16 timeout = 0;
275 killagreg 314
 
111 killagreg 315
        while (string[i++] != 0){} // get string len
41 ingob 316
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
111 killagreg 317
        UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer
41 ingob 318
        SetEPTxCount(ENDP1,i);
319
        SetEPTxValid(ENDP1);
275 killagreg 320
}
1 ingob 321
 
322
//-----------------------------------------------------------------
111 killagreg 323
void USB_PutChar(u8 c)
1 ingob 324
{
41 ingob 325
        u16 timeout = 0;
326
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
111 killagreg 327
        UserToPMABufferCopy(&c, ENDP1_TXADDR, 2);
41 ingob 328
        SetEPTxCount(ENDP1,2);
329
        SetEPTxValid(ENDP1);
330
}
275 killagreg 331
 
1 ingob 332
//-----------------------------------------------------------------
111 killagreg 333
void USB_SendData(u8 *pdata, u16 count)
1 ingob 334
{
41 ingob 335
        u8 i;
336
        count++;
114 killagreg 337
        u16 timeout = 0;
275 killagreg 338
 
339
        for (i=0;i< (count/64)+1;i++)
41 ingob 340
        {
275 killagreg 341
                while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;}
342
                if (i < (count/64))
343
                {
111 killagreg 344
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64);
41 ingob 345
                        SetEPTxCount(ENDP1,64);
346
                }
275 killagreg 347
                else
348
                {
111 killagreg 349
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64);
41 ingob 350
                        SetEPTxCount(ENDP1, count % 64);
351
                }
352
                SetEPTxValid(ENDP1);
1 ingob 353
        }
275 killagreg 354
}
1 ingob 355
 
112 killagreg 356
/**************************************************************/
357
/*         Transmit tx buffer via usb                         */
358
/**************************************************************/
359
void USB_Transmit(void)
360
{   // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal
361
        // if something has to be send and the txd fifo is not full
275 killagreg 362
 
112 killagreg 363
        if(USB_tx_buffer.Locked == TRUE)
364
        {
114 killagreg 365
                if(_GetEPTxStatus(ENDP1) == EP_TX_NAK)
112 killagreg 366
                {
275 killagreg 367
                        u16 i;
112 killagreg 368
                        if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes)
369
                        {
114 killagreg 370
                                i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send
112 killagreg 371
                                if(i > 64) i = 64; // limit packet size to 64 bytes
372
                                UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i);
114 killagreg 373
                                SetEPTxCount(ENDP1,i);
275 killagreg 374
                                SetEPTxValid(ENDP1);
112 killagreg 375
                        USB_tx_buffer.Position += i;
376
                        }
377
                }
378
                if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered
379
                {
380
                        Buffer_Clear(&USB_tx_buffer); // clear buffer
381
                }
382
        }
383
}
384
 
385
/**************************************************************/
386
/* Send the answers to incomming commands at the debug uart   */
387
/**************************************************************/
388
void USB_TransmitTxData(void)
389
{
390
        USB_Transmit(); // output pending bytes in tx buffer
391
        if((USB_tx_buffer.Locked == TRUE)) return;
392
 
201 killagreg 393
        if(CheckDelay(USB_AboTimeOut))
394
        {
395
                USB_DebugData_Interval = 0;
396
                USB_NaviData_Interval = 0;
397
                USB_Data3D_Interval = 0;
398
                USB_Display_Interval = 0;
399
        }
400
 
112 killagreg 401
        if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE))
402
        {
403
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16);
404
                USB_Request_DebugLabel = 0xFF;
405
        }
201 killagreg 406
        else if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE))
112 killagreg 407
        {
408
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame));
409
                USB_ConfirmFrame = 0;
410
        }
201 killagreg 411
        else if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 412
        {
413
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
414
                USB_DebugData_Timer = SetDelay(USB_DebugData_Interval);
415
                USB_Request_DebugData = FALSE;
416
        }
201 killagreg 417
        else if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 418
        {
419
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
420
                USB_Data3D_Timer = SetDelay(USB_Data3D_Interval);
421
                USB_Request_Data3D = FALSE;
422
        }
201 killagreg 423
        else if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE))
112 killagreg 424
        {
425
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
426
                USB_Request_ExternalControl = FALSE;
427
        }
201 killagreg 428
        else if( (( (USB_Display_Interval > 0) && CheckDelay(USB_Display_Timer)) || USB_Request_Display) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 429
        {
201 killagreg 430
                Menu_Update(USB_DisplayKeys);
431
                USB_DisplayKeys = 0;
432
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
112 killagreg 433
                USB_Request_Display = FALSE;
434
        }
201 killagreg 435
        else if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE))
112 killagreg 436
        {
201 killagreg 437
                Menu_Update(0);
112 killagreg 438
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
439
                USB_Request_Display1 = FALSE;
440
        }
201 killagreg 441
        else if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE))
112 killagreg 442
        {
443
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
444
                USB_Request_VersionInfo = FALSE;
445
        }
201 killagreg 446
        else if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 447
        {
448
                NaviData.Errorcode = ErrorCode;
449
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
450
                USB_NaviData_Timer = SetDelay(USB_NaviData_Interval);
451
                USB_Request_NaviData = FALSE;
452
        }
201 killagreg 453
        else if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE))
112 killagreg 454
        {
455
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
456
                USB_Request_ErrorMessage = FALSE;
457
        }
458
        USB_Transmit(); // output pending bytes in tx buffer
459
}