Quellcode durchsuchen

get v-usb working on actual hardware

Thomas B vor 2 Wochen
Ursprung
Commit
d50da00006
4 geänderte Dateien mit 20 neuen und 7 gelöschten Zeilen
  1. 2
    2
      sensor/Makefile
  2. 10
    4
      sensor/include/usbconfig.h
  3. 7
    1
      sensor/src/main.c
  4. 1
    0
      sensor/src/usb.c

+ 2
- 2
sensor/Makefile Datei anzeigen

@@ -61,7 +61,7 @@ MCU = attiny85
61 61
 #         F_CPU = 16000000
62 62
 #         F_CPU = 18432000
63 63
 #         F_CPU = 20000000
64
-F_CPU = 16000000
64
+F_CPU = 16500000
65 65
 
66 66
 
67 67
 # Output format. (can be srec, ihex, binary)
@@ -114,7 +114,7 @@ DEBUG = dwarf-2
114 114
 #     Each directory must be seperated by a space.
115 115
 #     Use forward slashes for directory separators.
116 116
 #     For a directory that has spaces, enclose it in quotes.
117
-EXTRAINCDIRS = include v-usb/usbdrv
117
+EXTRAINCDIRS = include v-usb/usbdrv v-usb/libs-device
118 118
 
119 119
 
120 120
 # Compiler flag to set the C Standard level.

+ 10
- 4
sensor/include/usbconfig.h Datei anzeigen

@@ -29,11 +29,11 @@ section at the end of this file).
29 29
 /* This is the port where the USB bus is connected. When you configure it to
30 30
  * "B", the registers PORTB, PINB and DDRB will be used.
31 31
  */
32
-#define USB_CFG_DMINUS_BIT      4
32
+#define USB_CFG_DMINUS_BIT      3
33 33
 /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
34 34
  * This may be any bit in the port.
35 35
  */
36
-#define USB_CFG_DPLUS_BIT       3
36
+#define USB_CFG_DPLUS_BIT       4
37 37
 /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
38 38
  * This may be any bit in the port. Please note that D+ must also be connected
39 39
  * to interrupt pin INT0! [You can also use other interrupts, see section
@@ -163,6 +163,11 @@ section at the end of this file).
163 163
  * (besides debugging) is to flash a status LED on each packet.
164 164
  */
165 165
 /* #define USB_RESET_HOOK(resetStarts)     if(!resetStarts){hadUsbReset();} */
166
+#ifndef __ASSEMBLER__
167
+#include <avr/interrupt.h>  // for sei()
168
+#include "osccal.h" // for calibrateOscillator()
169
+#endif
170
+#define USB_RESET_HOOK(resetStarts)  if(!resetStarts){cli(); calibrateOscillator(); sei();}
166 171
 /* This macro is a hook if you need to know when an USB RESET occurs. It has
167 172
  * one parameter which distinguishes between the start of RESET state and its
168 173
  * end.
@@ -171,7 +176,7 @@ section at the end of this file).
171 176
 /* This macro (if defined) is executed when a USB SET_ADDRESS request was
172 177
  * received.
173 178
  */
174
-#define USB_COUNT_SOF                   0
179
+#define USB_COUNT_SOF                   1
175 180
 /* define this macro to 1 if you need the global variable "usbSofCount" which
176 181
  * counts SOF packets. This feature requires that the hardware interrupt is
177 182
  * connected to D- instead of D+.
@@ -203,7 +208,7 @@ section at the end of this file).
203 208
  * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
204 209
  * for each control- and out-endpoint to check for duplicate packets.
205 210
  */
206
-#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH   0
211
+#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH   1
207 212
 /* define this macro to 1 if you want the function usbMeasureFrameLength()
208 213
  * compiled in. This function can be used to calibrate the AVR's RC oscillator.
209 214
  */
@@ -382,5 +387,6 @@ section at the end of this file).
382 387
 #define USB_INTR_ENABLE_BIT     PCIE  // Bit position in global interrupt enable register
383 388
 #define USB_INTR_PENDING        GIFR  // Register to read interrupt flag
384 389
 #define USB_INTR_PENDING_BIT    PCIF  // Bit position in register to read interrupt flag
390
+#define USB_INTR_VECTOR         PCINT0_vect
385 391
 
386 392
 #endif /* __usbconfig_h_included__ */

+ 7
- 1
sensor/src/main.c Datei anzeigen

@@ -28,6 +28,10 @@ int __attribute__((noreturn)) main(void) {
28 28
     wdt_enable(WDTO_1S);
29 29
     wdt_reset();
30 30
 
31
+    // status LED
32
+    DDRB |= (1 << DDB1); // output
33
+    PORTB |= (1 << PB1); // turn on
34
+
31 35
     adcInit();
32 36
     usbInit();
33 37
 
@@ -36,8 +40,10 @@ int __attribute__((noreturn)) main(void) {
36 40
     _delay_ms(255); // fake USB disconnect for > 250 ms
37 41
     usbDeviceConnect();
38 42
 
39
-    sei();
43
+    PORTB &= ~(1 << PB1); // turn status LED off
40 44
 
45
+    // enable interrupts and enter main loop for USB polling
46
+    sei();
41 47
     while (1) {
42 48
         wdt_reset();
43 49
         usbPoll();

+ 1
- 0
sensor/src/usb.c Datei anzeigen

@@ -17,6 +17,7 @@
17 17
  */
18 18
 
19 19
 #include "usbdrv.h"
20
+#include "osccal.c" // missing usbdrv include, so include here
20 21
 
21 22
 usbMsgLen_t usbFunctionSetup(uchar data[8]) {
22 23
     return 0;   /* default for not implemented requests: return no data back to host */

Laden…
Abbrechen
Speichern