17
17
#define NOT_A_TOUCH_PIN 255
18
18
19
19
#if defined(ARDUINO_UNOR4_MINIMA)
20
- #define LOVE_PORT 2
21
- #define LOVE_PIN 4
20
+ // On Minima, LOVE lives at P204
21
+ #define LOVE_GPIO_PORT 2
22
+ #define LOVE_GPIO_PIN 4
22
23
#elif defined(ARDUINO_UNOR4_WIFI)
23
- #define LOVE_PORT 1
24
- #define LOVE_PIN 13
24
+ // On WiFi, LOVE lives at P113
25
+ #define LOVE_GPIO_PORT 1
26
+ #define LOVE_GPIO_PIN 13
25
27
#endif
26
-
27
28
// Forward declarations for internal functions used in ISRs:
28
29
29
30
typedef void (*fn_callback_ptr_t )();
@@ -85,13 +86,13 @@ void CTSUWR_handler() {
85
86
// Write ISR: typically triggers a state change.
86
87
}
87
88
88
- void CTSURD_handler () {
89
+ void CTSURD_handler () {
89
90
IRQn_Type irq = R_FSP_CurrentIrqGet ();
90
91
R_BSP_IrqStatusClear (irq);
91
92
// Read ISR: retrieve measurement counters into the results array.
92
- }
93
+ }
93
94
94
- void CTSUFN_handler () {
95
+ void CTSUFN_handler () {
95
96
IRQn_Type irq = R_FSP_CurrentIrqGet ();
96
97
R_BSP_IrqStatusClear (irq);
97
98
ctsu_done = true ;
@@ -102,7 +103,7 @@ void CTSUWR_handler() {
102
103
// Restart measurement cycle if in free-running mode.
103
104
startCTSUmeasure ();
104
105
}
105
- }
106
+ }
106
107
107
108
// ------------------------------
108
109
// Low-level Hardware Initialization
@@ -176,7 +177,6 @@ void initDTC() {
176
177
// Non-Template Class Member Functions
177
178
// ------------------------------
178
179
179
-
180
180
CapacitiveTouch::CapacitiveTouch (uint8_t pin) : _pin(pin), _threshold(500 ), _sensorIndex(0 ) {
181
181
CapTouchPinMapping mapping;
182
182
if (lookupMapping (pin, mapping)) {
@@ -251,14 +251,21 @@ bool CapacitiveTouch::setTouchMode(uint8_t pin) {
251
251
return false ;
252
252
}
253
253
254
- // Configure the pin's peripheral function.
255
- if (pin == NUM_ARDUINO_PINS - 1 ) { // Special case for LOVE pin.
256
- R_PFS-> PORT [LOVE_PORT]. PIN [LOVE_PIN]. PmnPFS =
257
- ( 1 << R_PFS_PORT_PIN_PmnPFS_PMR_Pos) | ( 12 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos);
258
- } else {
259
- R_IOPORT_PinCfg (&g_ioport_ctrl, g_pin_cfg[pin]. pin ,
260
- ( uint32_t )(IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_CTSU) );
254
+
255
+ if (pin == LOVE_BUTTON ) {
256
+ // configure the physical PFS for LOVE_GPIO_[PORT| PIN]
257
+ R_PFS-> PORT [LOVE_GPIO_PORT]
258
+ . PIN [LOVE_GPIO_PIN]
259
+ . PmnPFS = ( 1 << R_PFS_PORT_PIN_PmnPFS_PMR_Pos)
260
+ | ( 12 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos );
261
261
}
262
+ else {
263
+ // all the other CTSU-capable pins
264
+ R_IOPORT_PinCfg (&g_ioport_ctrl,
265
+ g_pin_cfg[pin].pin ,
266
+ IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_CTSU);
267
+ }
268
+
262
269
263
270
// Reinitialize CTSU hardware.
264
271
initCTSU ();
@@ -295,7 +302,7 @@ bool CapacitiveTouch::setTouchMode(uint8_t pin) {
295
302
return true ;
296
303
}
297
304
298
- void CapacitiveTouch::startTouchMeasurement (bool fr) {
305
+ void CapacitiveTouch::startTouchMeasurement (bool fr) {
299
306
free_running = fr;
300
307
if (ctsu_done || ((R_CTSU->CTSUST & 7 ) == 0 )) {
301
308
ctsu_done = false ;
@@ -307,6 +314,6 @@ bool CapacitiveTouch::setTouchMode(uint8_t pin) {
307
314
}
308
315
}
309
316
310
- bool CapacitiveTouch::touchMeasurementReady () {
317
+ bool CapacitiveTouch::touchMeasurementReady () {
311
318
return (free_running || ctsu_done);
312
- }
319
+ }
0 commit comments