Browse Source

get v-usb working on actual hardware

Thomas B 3 months ago
parent
commit
d50da00006
4 changed files with 20 additions and 7 deletions
  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 View File

61
 #         F_CPU = 16000000
61
 #         F_CPU = 16000000
62
 #         F_CPU = 18432000
62
 #         F_CPU = 18432000
63
 #         F_CPU = 20000000
63
 #         F_CPU = 20000000
64
-F_CPU = 16000000
64
+F_CPU = 16500000
65
 
65
 
66
 
66
 
67
 # Output format. (can be srec, ihex, binary)
67
 # Output format. (can be srec, ihex, binary)
114
 #     Each directory must be seperated by a space.
114
 #     Each directory must be seperated by a space.
115
 #     Use forward slashes for directory separators.
115
 #     Use forward slashes for directory separators.
116
 #     For a directory that has spaces, enclose it in quotes.
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
 # Compiler flag to set the C Standard level.
120
 # Compiler flag to set the C Standard level.

+ 10
- 4
sensor/include/usbconfig.h View File

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

+ 7
- 1
sensor/src/main.c View File

28
     wdt_enable(WDTO_1S);
28
     wdt_enable(WDTO_1S);
29
     wdt_reset();
29
     wdt_reset();
30
 
30
 
31
+    // status LED
32
+    DDRB |= (1 << DDB1); // output
33
+    PORTB |= (1 << PB1); // turn on
34
+
31
     adcInit();
35
     adcInit();
32
     usbInit();
36
     usbInit();
33
 
37
 
36
     _delay_ms(255); // fake USB disconnect for > 250 ms
40
     _delay_ms(255); // fake USB disconnect for > 250 ms
37
     usbDeviceConnect();
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
     while (1) {
47
     while (1) {
42
         wdt_reset();
48
         wdt_reset();
43
         usbPoll();
49
         usbPoll();

+ 1
- 0
sensor/src/usb.c View File

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

Loading…
Cancel
Save