1+ // SPDX-FileCopyrightText: 2017 John Edgar Park for Adafruit Industries
2+ //
3+ // SPDX-License-Identifier: MIT
4+
15/* ********************************************************************
26AtariFruit 2600 Joystick
37by John Park for Adafruit
1216 http://subethasoftware.com/2013/01/04/teensy-2-0-icade-source-code/
1317
1418*********************************************************************/
15- #include < bluefruit.h>
19+ #include < bluefruit.h>
1620
17- BLEDis bledis;
18- BLEHidAdafruit blehid;
21+ BLEDis bledis;
22+ BLEHidAdafruit blehid;
1923
2024#define VERSION " 0.1"
2125#define LED_ON
@@ -73,15 +77,15 @@ See: http://old.pinouts.ru/Inputs/JoystickAtari2600_pinout.shtml
7377// #define DI_PIN_START 1 // First I/O pin.
7478// #define DI_PIN_END 20 // Last I/O pin.
7579
76- byte myPins[DI_PIN_COUNT] = {UP_PIN, DOWN_PIN, LEFT_PIN, RIGHT_PIN, BTN1_PIN,
80+ byte myPins[DI_PIN_COUNT] = {UP_PIN, DOWN_PIN, LEFT_PIN, RIGHT_PIN, BTN1_PIN,
7781 BTN2_PIN, BTN3_PIN, BTN4_PIN,
7882 BTN5_PIN, BTN6_PIN, BTN7_PIN, BTN8_PIN};
7983
80- char iCadeKeymap[][DI_PIN_COUNT] = {UP_KEYS, DOWN_KEYS, LEFT_KEYS, RIGHT_KEYS,
84+ char iCadeKeymap[][DI_PIN_COUNT] = {UP_KEYS, DOWN_KEYS, LEFT_KEYS, RIGHT_KEYS,
8185 BTN1_KEYS, BTN2_KEYS, BTN3_KEYS, BTN4_KEYS,
8286 BTN5_KEYS, BTN6_KEYS, BTN7_KEYS, BTN8_KEYS};
8387
84- char iCadeDesc[][DI_PIN_COUNT] = {" Up" , " Down" , " Left" , " Right" , " Btn1" ,
88+ char iCadeDesc[][DI_PIN_COUNT] = {" Up" , " Down" , " Left" , " Right" , " Btn1" ,
8589 " Btn2" , " Btn3" , " Btn4" ,
8690 " Btn5" , " Btn6" , " Btn7" , " Btn8" };
8791
@@ -114,36 +118,36 @@ void setup()
114118
115119 // Initialize the serial port.
116120 Serial.begin (115200 );
117- Serial.println ();
118- Serial.println (" Go to your phone's Bluetooth settings to pair your device" );
119- Serial.println (" then open an application that accepts keyboard input" );
120- Bluefruit.begin ();
121- // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
122- Bluefruit.setTxPower (4 );
123- Bluefruit.setName (" AtariFruitJoystick" );
124-
125- // Configure and Start Device Information Service
126- bledis.setManufacturer (" Adafruit Industries" );
127- bledis.setModel (" Atari Fruit Joystick 52" );
128- bledis.begin ();
129-
130- /* Start BLE HID
131- * Note: Apple requires BLE device must have min connection interval >= 20m
132- * ( The smaller the connection interval the faster we could send data).
133- * However for HID and MIDI device, Apple could accept min connection interval
134- * up to 11.25 ms. Therefore BLEHidAdafruit::begin() will try to set the min and max
135- * connection interval to 11.25 ms and 15 ms respectively for best performance.
136- */
137- blehid.begin ();
138-
139- /* Set connection interval (min, max) to your perferred value.
140- * Note: It is already set by BLEHidAdafruit::begin() to 11.25ms - 15ms
141- * min = 9*1.25=11.25 ms, max = 12*1.25= 15 ms
142- */
143- /* Bluefruit.setConnInterval(9, 12); */
144-
145- // Set up and start advertising
146- startAdv ();
121+ Serial.println ();
122+ Serial.println (" Go to your phone's Bluetooth settings to pair your device" );
123+ Serial.println (" then open an application that accepts keyboard input" );
124+ Bluefruit.begin ();
125+ // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
126+ Bluefruit.setTxPower (4 );
127+ Bluefruit.setName (" AtariFruitJoystick" );
128+
129+ // Configure and Start Device Information Service
130+ bledis.setManufacturer (" Adafruit Industries" );
131+ bledis.setModel (" Atari Fruit Joystick 52" );
132+ bledis.begin ();
133+
134+ /* Start BLE HID
135+ * Note: Apple requires BLE device must have min connection interval >= 20m
136+ * ( The smaller the connection interval the faster we could send data).
137+ * However for HID and MIDI device, Apple could accept min connection interval
138+ * up to 11.25 ms. Therefore BLEHidAdafruit::begin() will try to set the min and max
139+ * connection interval to 11.25 ms and 15 ms respectively for best performance.
140+ */
141+ blehid.begin ();
142+
143+ /* Set connection interval (min, max) to your perferred value.
144+ * Note: It is already set by BLEHidAdafruit::begin() to 11.25ms - 15ms
145+ * min = 9*1.25=11.25 ms, max = 12*1.25= 15 ms
146+ */
147+ /* Bluefruit.setConnInterval(9, 12); */
148+
149+ // Set up and start advertising
150+ startAdv ();
147151
148152 // Docs say this isn't necessary for Uno.
149153 // while(!Serial) { }
@@ -184,37 +188,37 @@ void setup()
184188
185189 Serial.println (" Ready." );
186190
187- }
188-
189-
190- void startAdv (void )
191- {
192- // Advertising packet
193- Bluefruit.Advertising .addFlags (BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
194- Bluefruit.Advertising .addTxPower ();
195- Bluefruit.Advertising .addAppearance (BLE_APPEARANCE_HID_KEYBOARD);
196-
197- // Include BLE HID service
198- Bluefruit.Advertising .addService (blehid);
199-
200- // There is enough room for the dev name in the advertising packet
201- Bluefruit.Advertising .addName ();
202-
203- /* Start Advertising
204- * - Enable auto advertising if disconnected
205- * - Interval: fast mode = 20 ms, slow mode = 152.5 ms
206- * - Timeout for fast mode is 30 seconds
207- * - Start(timeout) with timeout = 0 will advertise forever (until connected)
208- *
209- * For recommended advertising interval
210- * https://developer.apple.com/library/content/qa/qa1931/_index.html
211- */
212- Bluefruit.Advertising .restartOnDisconnect (true );
213- Bluefruit.Advertising .setInterval (32 , 244 ); // in unit of 0.625 ms
214- Bluefruit.Advertising .setFastTimeout (30 ); // number of seconds in fast mode
215- Bluefruit.Advertising .start (0 ); // 0 = Don't stop advertising after n seconds
216191}
217-
192+
193+
194+ void startAdv (void )
195+ {
196+ // Advertising packet
197+ Bluefruit.Advertising .addFlags (BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
198+ Bluefruit.Advertising .addTxPower ();
199+ Bluefruit.Advertising .addAppearance (BLE_APPEARANCE_HID_KEYBOARD);
200+
201+ // Include BLE HID service
202+ Bluefruit.Advertising .addService (blehid);
203+
204+ // There is enough room for the dev name in the advertising packet
205+ Bluefruit.Advertising .addName ();
206+
207+ /* Start Advertising
208+ * - Enable auto advertising if disconnected
209+ * - Interval: fast mode = 20 ms, slow mode = 152.5 ms
210+ * - Timeout for fast mode is 30 seconds
211+ * - Start(timeout) with timeout = 0 will advertise forever (until connected)
212+ *
213+ * For recommended advertising interval
214+ * https://developer.apple.com/library/content/qa/qa1931/_index.html
215+ */
216+ Bluefruit.Advertising .restartOnDisconnect (true );
217+ Bluefruit.Advertising .setInterval (32 , 244 ); // in unit of 0.625 ms
218+ Bluefruit.Advertising .setFastTimeout (30 ); // number of seconds in fast mode
219+ Bluefruit.Advertising .start (0 ); // 0 = Don't stop advertising after n seconds
220+ }
221+
218222
219223void loop ()
220224{
@@ -263,7 +267,7 @@ void loop()
263267
264268 // In pin status has changed from our last toggle...
265269 if (status != digitalStatus[thisPin])
266- {
270+ {
267271 blehid.keyRelease ();
268272 // Remember when it changed, starting debounce mode.
269273 // If not currently in debounce mode,
@@ -288,7 +292,7 @@ void loop()
288292 Serial.print (iCadeDesc[thisPin]);
289293 Serial.print (" pressed (sending " );
290294 Serial.print (iCadeKeymap[thisPin][0 ]);
291- Serial.println (" to iCade)." );
295+ Serial.println (" to iCade)." );
292296 blehid.keyPress (iCadeKeymap[thisPin][0 ]);
293297 // Keyboard.print(iCadeKeymap[thisPin][0]);
294298 // digitalCounter[thisPin]++;
@@ -301,7 +305,7 @@ void loop()
301305 Serial.print (iCadeDesc[thisPin]);
302306 Serial.print (" released (sending " );
303307 Serial.print (iCadeKeymap[thisPin][1 ]);
304- Serial.println (" to iCade)." );
308+ Serial.println (" to iCade)." );
305309 blehid.keyPress (iCadeKeymap[thisPin][1 ]);
306310 // Keyboard.print(iCadeKeymap[thisPin][1]);
307311 if (pinsOn>0 ) pinsOn--;
@@ -320,9 +324,9 @@ void loop()
320324 // If we were debouncing, we are no longer debouncing.
321325 digitalDebounceTime[thisPin] = 0 ;
322326 }
323- } // End of (int thisPin=0; thisPin < DI_PIN_COUNT; thisPin++ )
324-
325- // Request CPU to enter low-power mode until an event/interrupt occurs
327+ } // End of (int thisPin=0; thisPin < DI_PIN_COUNT; thisPin++ )
328+
329+ // Request CPU to enter low-power mode until an event/interrupt occurs
326330 waitForEvent ();
327331}
328332
@@ -373,24 +377,24 @@ void showDigitalInputStatus()
373377 Serial.println (" " );
374378}
375379
376- /* *
377- * RTOS Idle callback is automatically invoked by FreeRTOS
378- * when there are no active threads. E.g when loop() calls delay() and
379- * there is no bluetooth or hw event. This is the ideal place to handle
380- * background data.
381- *
382- * NOTE: FreeRTOS is configured as tickless idle mode. After this callback
383- * is executed, if there is time, freeRTOS kernel will go into low power mode.
384- * Therefore waitForEvent() should not be called in this callback.
385- * http://www.freertos.org/low-power-tickless-rtos.html
386- *
387- * WARNING: This function MUST NOT call any blocking FreeRTOS API
388- * such as delay(), xSemaphoreTake() etc ... for more information
389- * http://www.freertos.org/a00016.html
390- */
391- void rtos_idle_callback (void )
392- {
393- // Don't call any other FreeRTOS blocking API()
394- // Perform background task(s) here
380+ /* *
381+ * RTOS Idle callback is automatically invoked by FreeRTOS
382+ * when there are no active threads. E.g when loop() calls delay() and
383+ * there is no bluetooth or hw event. This is the ideal place to handle
384+ * background data.
385+ *
386+ * NOTE: FreeRTOS is configured as tickless idle mode. After this callback
387+ * is executed, if there is time, freeRTOS kernel will go into low power mode.
388+ * Therefore waitForEvent() should not be called in this callback.
389+ * http://www.freertos.org/low-power-tickless-rtos.html
390+ *
391+ * WARNING: This function MUST NOT call any blocking FreeRTOS API
392+ * such as delay(), xSemaphoreTake() etc ... for more information
393+ * http://www.freertos.org/a00016.html
394+ */
395+ void rtos_idle_callback (void )
396+ {
397+ // Don't call any other FreeRTOS blocking API()
398+ // Perform background task(s) here
395399}
396- // End of file.
400+ // End of file.
0 commit comments