Balboa32U4 library
USBPause.h
Go to the documentation of this file.
1 // Copyright Pololu Corporation. For more information, see https://www.pololu.com/
2 
11 #pragma once
12 
13 #include <avr/io.h>
14 
26 class USBPause
27 {
29  uint8_t savedUDIEN;
30 
32  uint8_t savedUENUM;
33 
35  uint8_t savedUEIENX0;
36 
37 public:
38 
39  USBPause()
40  {
41  // Disable the general USB interrupt. This must be done
42  // first, because the general USB interrupt might change the
43  // state of the EP0 interrupt, but not the other way around.
44  savedUDIEN = UDIEN;
45  UDIEN = 0;
46 
47  // Select endpoint 0.
48  savedUENUM = UENUM;
49  UENUM = 0;
50 
51  // Disable endpoint 0 interrupts.
52  savedUEIENX0 = UEIENX;
53  UEIENX = 0;
54  }
55 
56  ~USBPause()
57  {
58  // Restore endpoint 0 interrupts.
59  UENUM = 0;
60  UEIENX = savedUEIENX0;
61 
62  // Restore endpoint selection.
63  UENUM = savedUENUM;
64 
65  // Restore general device interrupt.
66  UDIEN = savedUDIEN;
67  }
68 
69 };