Rev 110 | Rev 112 | Go to most recent revision | 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 |
||
6 | // + Nur für den privaten Gebrauch |
||
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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
28 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
||
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 |
||
43 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
||
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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
41 | ingob | 57 | #include "91x_lib.h" |
58 | #include "uart1.h" |
||
59 | #include "usb.h" |
||
111 | killagreg | 60 | #include "mkprotocol.h" |
61 | |||
62 | |||
63 | // the tx buffer |
||
64 | #define USB_TX_BUFFER_LEN 150 |
||
65 | u8 USB_tbuffer[USB_TX_BUFFER_LEN]; |
||
66 | Buffer_t USB_tx_buffer; |
||
67 | |||
68 | // the rx buffer |
||
69 | #define USB_RX_BUFFER_LEN 150 |
||
70 | u8 USB_rbuffer[USB_RX_BUFFER_LEN]; |
||
71 | Buffer_t USB_rx_buffer; |
||
72 | |||
73 | |||
1 | ingob | 74 | //----------------------------------------------------------------- |
75 | void USB_ConfigInit(void) |
||
76 | { |
||
41 | ingob | 77 | GPIO_InitTypeDef GPIO_InitStructure; |
1 | ingob | 78 | |
110 | killagreg | 79 | UART1_PutString("\r\n USB init..."); |
41 | ingob | 80 | #ifdef MCLK96MHZ |
81 | //USB clock = MCLK/2 = 48MHz |
||
82 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
||
83 | #else |
||
84 | //USB clock = MCLK = 48MHz |
||
85 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
||
86 | #endif |
||
87 | //Enable USB clock |
||
88 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
||
89 | SCU_AHBPeriphReset(__USB,DISABLE); |
||
90 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
||
1 | ingob | 91 | |
41 | ingob | 92 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
93 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
||
94 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
||
1 | ingob | 95 | |
41 | ingob | 96 | // GPIO_DeInit(P0.1); |
97 | GPIO_StructInit(&GPIO_InitStructure); |
||
98 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
||
99 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
||
100 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
||
101 | GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable; |
||
102 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
||
103 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
||
1 | ingob | 104 | |
111 | killagreg | 105 | // initialize txd buffer |
106 | USB_tx_buffer.pData = USB_tbuffer; |
||
107 | USB_tx_buffer.Size = USB_TX_BUFFER_LEN; |
||
108 | USB_tx_buffer.Position = 0; |
||
109 | USB_tx_buffer.Locked = FALSE; |
||
110 | |||
111 | // initialize rxd buffer |
||
112 | USB_rx_buffer.pData = USB_rbuffer; |
||
113 | USB_rx_buffer.Size = USB_RX_BUFFER_LEN; |
||
114 | USB_rx_buffer.Position = 0; |
||
115 | USB_rx_buffer.Locked = FALSE; |
||
116 | |||
117 | |||
41 | ingob | 118 | PowerOff(); |
119 | Virtual_Com_Port_Reset(); |
||
1 | ingob | 120 | |
41 | ingob | 121 | VIC_Config(USBLP_ITLine, VIC_IRQ, 2); |
122 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
||
1 | ingob | 123 | |
41 | ingob | 124 | USB_Init(); |
1 | ingob | 125 | |
110 | killagreg | 126 | UART1_PutString("ok"); |
1 | ingob | 127 | } |
128 | |||
129 | //----------------------------------------------------------------- |
||
111 | killagreg | 130 | void USB_CableConfig(FunctionalState NewState) |
1 | ingob | 131 | { |
41 | ingob | 132 | if (NewState == ENABLE) |
133 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
||
134 | else |
||
135 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
||
1 | ingob | 136 | } |
137 | |||
138 | //----------------------------------------------------------------- |
||
111 | killagreg | 139 | void USB_PutString(u8 *string) |
1 | ingob | 140 | { |
41 | ingob | 141 | u8 i = 0; |
142 | u16 timeout = 0; |
||
143 | |||
111 | killagreg | 144 | while (string[i++] != 0){} // get string len |
41 | ingob | 145 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
111 | killagreg | 146 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
41 | ingob | 147 | SetEPTxCount(ENDP1,i); |
148 | SetEPTxValid(ENDP1); |
||
1 | ingob | 149 | } |
150 | |||
151 | //----------------------------------------------------------------- |
||
111 | killagreg | 152 | void USB_PutChar(u8 c) |
1 | ingob | 153 | { |
41 | ingob | 154 | u16 timeout = 0; |
155 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
||
111 | killagreg | 156 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
41 | ingob | 157 | SetEPTxCount(ENDP1,2); |
158 | SetEPTxValid(ENDP1); |
||
159 | } |
||
160 | |||
1 | ingob | 161 | //----------------------------------------------------------------- |
111 | killagreg | 162 | void USB_SendData(u8 *pdata, u16 count) |
1 | ingob | 163 | { |
41 | ingob | 164 | u8 i; |
165 | count++; |
||
166 | |||
167 | for (i=0;i< (count/64)+1;i++) |
||
168 | { |
||
169 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK); |
||
170 | if (i < (count/64)) |
||
171 | { |
||
111 | killagreg | 172 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
41 | ingob | 173 | SetEPTxCount(ENDP1,64); |
174 | } |
||
175 | else |
||
176 | { |
||
111 | killagreg | 177 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
41 | ingob | 178 | SetEPTxCount(ENDP1, count % 64); |
179 | } |
||
180 | SetEPTxValid(ENDP1); |
||
1 | ingob | 181 | } |
182 | } |
||
183 |