Rev 23 | 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
57 | #include "main.h" |
||
58 | |||
59 | //----------------------------------------------------------------- |
||
60 | void USB_ConfigInit(void) |
||
61 | { |
||
62 | GPIO_InitTypeDef GPIO_InitStructure; |
||
63 | |||
64 | SerialPutString("USB init..."); |
||
65 | |||
66 | //USB clock = MCLK= 48MHz |
||
67 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
||
68 | //Enable USB clock |
||
69 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
||
70 | SCU_AHBPeriphReset(__USB,DISABLE); |
||
71 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
||
72 | |||
73 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
||
74 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
||
75 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
||
76 | |||
77 | // GPIO_DeInit(GPIO0); |
||
78 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
||
79 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
||
80 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
||
81 | GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable; |
||
82 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
||
83 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
||
84 | |||
85 | PowerOff(); |
||
86 | Virtual_Com_Port_Reset(); |
||
87 | |||
88 | VIC_Config(USBLP_ITLine, VIC_IRQ, 2); |
||
89 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
||
90 | |||
91 | USB_Init(); |
||
92 | |||
93 | SerialPutString("ok\n\r"); |
||
94 | |||
95 | } |
||
96 | |||
97 | //----------------------------------------------------------------- |
||
98 | void USB_Cable_Config (FunctionalState NewState) |
||
99 | { |
||
100 | if (NewState == ENABLE) |
||
101 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
||
102 | else |
||
103 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
||
104 | } |
||
105 | |||
106 | //----------------------------------------------------------------- |
||
107 | void USB_Send_String(u8 *StrPtr) |
||
108 | { |
||
109 | u8 i = 0; |
||
110 | u16 timeout = 0; |
||
111 | |||
112 | while (StrPtr[i++] !=0){} |
||
113 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
||
114 | UserToPMABufferCopy(StrPtr, ENDP1_TXADDR, ++i); |
||
115 | SetEPTxCount(ENDP1,i); |
||
116 | SetEPTxValid(ENDP1); |
||
117 | } |
||
118 | |||
119 | //----------------------------------------------------------------- |
||
120 | void USB_Send_Char(u8 ch) |
||
121 | { |
||
122 | u16 timeout = 0; |
||
123 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
||
124 | UserToPMABufferCopy(&ch, ENDP1_TXADDR, 2); |
||
125 | SetEPTxCount(ENDP1,2); |
||
126 | SetEPTxValid(ENDP1); |
||
127 | } |
||
128 | //----------------------------------------------------------------- |
||
129 | void USB_Send_Data(u8 *data, u16 count) |
||
130 | { |
||
131 | u16 timeout = 0; |
||
132 | u8 i; |
||
133 | |||
134 | |||
135 | count++; |
||
136 | |||
137 | for (i=0;i< (count/64)+1;i++) |
||
138 | { |
||
139 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK); |
||
140 | if (i < (count/64)) |
||
141 | { UserToPMABufferCopy(&data[i*64], ENDP1_TXADDR, 64); |
||
142 | SetEPTxCount(ENDP1,64); |
||
143 | } |
||
144 | else |
||
145 | { UserToPMABufferCopy(&data[i*64], ENDP1_TXADDR, count % 64); |
||
146 | SetEPTxCount(ENDP1, count % 64); |
||
147 | } |
||
148 | |||
149 | SetEPTxValid(ENDP1); |
||
150 | } |
||
151 | } |
||
152 |