-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathBalboa32U4Buttons.h
77 lines (65 loc) · 2.27 KB
/
Balboa32U4Buttons.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright Pololu Corporation. For more information, see http://www.pololu.com/
/** \file Balboa32U4Buttons.h **/
#pragma once
#include <Pushbutton.h>
#include <FastGPIO.h>
#include <USBPause.h>
#include <util/delay.h>
/*! The pin number for the pin connected to button A on the Balboa 32U4. */
#define BALBOA_32U4_BUTTON_A 14
/*! The pin number for the pin connected to button B on the Balboa 32U4. */
#define BALBOA_32U4_BUTTON_B IO_D5
/*! The pin number for the pin conencted to button C on the Balboa 32U4. */
#define BALBOA_32U4_BUTTON_C 17
/*! \brief Interfaces with button A on the Balboa 32U4. */
class Balboa32U4ButtonA : public Pushbutton
{
public:
Balboa32U4ButtonA() : Pushbutton(BALBOA_32U4_BUTTON_A)
{
}
};
/*! \brief Interfaces with button B on the Balboa 32U4.
*
* The pin used for button B is also used for the TX LED.
*
* This class temporarily disables USB interrupts because the Arduino core code
* has USB interrupts enabled that sometimes write to the pin this button is on.
*
* This class temporarily sets the pin to be an input without a pull-up
* resistor. The pull-up resistor is not needed because of the resistors on the
* board. */
class Balboa32U4ButtonB : public PushbuttonBase
{
public:
virtual bool isPressed()
{
USBPause usbPause;
FastGPIO::PinLoan<BALBOA_32U4_BUTTON_B> loan;
FastGPIO::Pin<BALBOA_32U4_BUTTON_B>::setInputPulledUp();
_delay_us(3);
return !FastGPIO::Pin<BALBOA_32U4_BUTTON_B>::isInputHigh();
}
};
/*! \brief Interfaces with button C on the Balboa 32U4.
*
* The pin used for button C is also used for the RX LED.
*
* This class temporarily disables USB interrupts because the Arduino core code
* has USB interrupts enabled that sometimes write to the pin this button is on.
*
* This class temporarily sets the pin to be an input without a pull-up
* resistor. The pull-up resistor is not needed because of the resistors on the
* board. */
class Balboa32U4ButtonC : public PushbuttonBase
{
public:
virtual bool isPressed()
{
USBPause usbPause;
FastGPIO::PinLoan<BALBOA_32U4_BUTTON_C> loan;
FastGPIO::Pin<BALBOA_32U4_BUTTON_C>::setInputPulledUp();
_delay_us(3);
return !FastGPIO::Pin<BALBOA_32U4_BUTTON_C>::isInputHigh();
}
};