2
2
#include < math.h>
3
3
#include < stdio.h>
4
4
#include < stdint.h>
5
- #ifdef __AVR__
6
- #include < avr/io.h>
7
- #endif
8
- #if ARDUINO > 22
9
- #include " Arduino.h"
10
- #else
11
- #include " WProgram.h"
12
- #include " pins_arduino.h"
13
- #endif
14
5
15
6
static byte enter_config[]={0x01 ,0x43 ,0x00 ,0x01 ,0x00 };
16
7
static byte set_mode[]={0x01 ,0x44 ,0x00 ,0x01 ,0x03 ,0x00 ,0x00 ,0x00 ,0x00 };
@@ -57,6 +48,9 @@ byte PS2X::Analog(byte button) {
57
48
/* ***************************************************************************************/
58
49
unsigned char PS2X::_gamepad_shiftinout (char byte) {
59
50
unsigned char tmp = 0 ;
51
+ #ifdef ENERGIA
52
+ noInterrupts ();
53
+ #endif
60
54
for (unsigned char i=0 ;i<8 ;i++) {
61
55
if (CHK (byte,i)) CMD_SET ();
62
56
else CMD_CLR ();
@@ -73,6 +67,9 @@ unsigned char PS2X::_gamepad_shiftinout (char byte) {
73
67
#endif
74
68
}
75
69
CMD_SET ();
70
+ #ifdef ENERGIA
71
+ interrupts ();
72
+ #endif
76
73
delayMicroseconds (CTRL_BYTE_DELAY);
77
74
return tmp;
78
75
}
@@ -152,7 +149,7 @@ boolean PS2X::read_gamepad(boolean motor1, byte motor2) {
152
149
153
150
last_buttons = buttons; // store the previous buttons states
154
151
155
- #if defined(__AVR__)
152
+ #if defined(__AVR__) || defined(ENERGIA)
156
153
buttons = *(uint16_t *)(PS2data+3 ); // store as one value for multiple functions
157
154
#else
158
155
buttons = (uint16_t )(PS2data[4 ] << 8 ) + PS2data[3 ]; // store as one value for multiple functions
@@ -171,7 +168,12 @@ byte PS2X::config_gamepad(uint8_t clk, uint8_t cmd, uint8_t att, uint8_t dat, bo
171
168
172
169
byte temp[sizeof (type_read)];
173
170
174
- #ifdef __AVR__
171
+ #if defined(ENERGIA)
172
+ _clk_pin = clk;
173
+ _cmd_pin = cmd;
174
+ _att_pin = att;
175
+ _dat_pin = dat;
176
+ #elif defined(__AVR__)
175
177
_clk_mask = digitalPinToBitMask (clk);
176
178
_clk_oreg = portOutputRegister (digitalPinToPort (clk));
177
179
_cmd_mask = digitalPinToBitMask (cmd);
@@ -180,8 +182,7 @@ byte PS2X::config_gamepad(uint8_t clk, uint8_t cmd, uint8_t att, uint8_t dat, bo
180
182
_att_oreg = portOutputRegister (digitalPinToPort (att));
181
183
_dat_mask = digitalPinToBitMask (dat);
182
184
_dat_ireg = portInputRegister (digitalPinToPort (dat));
183
- #else
184
- #ifdef ESP8266
185
+ #elif defined(ESP8266)
185
186
_clk_pin = clk;
186
187
_cmd_pin = cmd;
187
188
_att_pin = att;
@@ -205,13 +206,12 @@ byte PS2X::config_gamepad(uint8_t clk, uint8_t cmd, uint8_t att, uint8_t dat, bo
205
206
206
207
_dat_mask = digitalPinToBitMask (dat);
207
208
_dat_lport = portInputRegister (digitalPinToPort (dat));
208
- #endif
209
209
#endif
210
210
211
211
pinMode (clk, OUTPUT); // configure ports
212
212
pinMode (att, OUTPUT);
213
213
pinMode (cmd, OUTPUT);
214
- #ifdef ESP8266
214
+ #if defined( ESP8266) || defined(ENERGIA)
215
215
pinMode (dat, INPUT_PULLUP); // enable pull-up
216
216
#else
217
217
pinMode (dat, INPUT);
@@ -386,7 +386,7 @@ bool PS2X::enablePressures() {
386
386
return false ;
387
387
388
388
en_Pressures = true ;
389
- return true ;
389
+ return true ;
390
390
}
391
391
392
392
/* ***************************************************************************************/
@@ -401,7 +401,7 @@ void PS2X::reconfig_gamepad(){
401
401
}
402
402
403
403
/* ***************************************************************************************/
404
- #ifdef __AVR__
404
+ #if defined( __AVR__)
405
405
inline void PS2X::CLK_SET (void ) {
406
406
register uint8_t old_sreg = SREG;
407
407
cli ();
@@ -448,9 +448,8 @@ inline bool PS2X::DAT_CHK(void) {
448
448
return (*_dat_ireg & _dat_mask) ? true : false ;
449
449
}
450
450
451
- #else
452
- #ifdef ESP8266
453
- // Let's just use digitalWrite() on ESP8266.
451
+ #elif defined(ESP8266) || defined(ENERGIA)
452
+ // Let's just use digitalWrite() on ESP8266 and Launchpad
454
453
inline void PS2X::CLK_SET (void ) {
455
454
digitalWrite (_clk_pin, HIGH);
456
455
}
@@ -478,6 +477,7 @@ inline void PS2X::ATT_CLR(void) {
478
477
inline bool PS2X::DAT_CHK (void ) {
479
478
return digitalRead (_dat_pin) ? true : false ;
480
479
}
480
+
481
481
#else
482
482
// On pic32, use the set/clr registers to make them atomic...
483
483
inline void PS2X::CLK_SET (void ) {
@@ -509,4 +509,3 @@ inline bool PS2X::DAT_CHK(void) {
509
509
}
510
510
511
511
#endif
512
- #endif
0 commit comments