2013-02-18 15:32:11 +00:00
|
|
|
#include "test_env.h"
|
|
|
|
|
|
|
|
DigitalOut myled(LED1);
|
|
|
|
DigitalOut led2(LED2);
|
|
|
|
|
|
|
|
volatile int checks = 0;
|
|
|
|
void in_handler() {
|
|
|
|
checks++;
|
|
|
|
led2 = !led2;
|
|
|
|
}
|
|
|
|
|
2013-02-26 14:57:42 +00:00
|
|
|
#if defined(TARGET_KL25Z)
|
2013-07-29 15:20:05 +00:00
|
|
|
#define PIN_OUT PTC6
|
|
|
|
#define PIN_IN PTA5
|
2013-02-26 14:57:42 +00:00
|
|
|
|
2013-06-27 21:20:47 +00:00
|
|
|
#elif defined(TARGET_KL05Z)
|
|
|
|
#define PIN_OUT PTB11
|
|
|
|
#define PIN_IN PTB1
|
|
|
|
|
2013-04-17 15:32:49 +00:00
|
|
|
#elif defined(TARGET_LPC812)
|
|
|
|
#define PIN_OUT D10
|
|
|
|
#define PIN_IN D11
|
|
|
|
|
2013-07-24 15:42:18 +00:00
|
|
|
#elif defined(TARGET_LPC1114)
|
|
|
|
#define PIN_OUT dp1
|
|
|
|
#define PIN_IN dp2
|
|
|
|
|
2014-06-19 16:14:29 +00:00
|
|
|
#elif defined(TARGET_LPC1549)
|
|
|
|
// TARGET_FF_ARDUINO cannot be used, because D0 is used as USBRX (USB serial
|
|
|
|
// port pin), D1 is used as USBTX
|
|
|
|
#define PIN_OUT D2
|
|
|
|
#define PIN_IN D7
|
|
|
|
|
2013-08-08 11:57:02 +00:00
|
|
|
#elif defined(TARGET_LPC4088)
|
|
|
|
#define PIN_IN (p11)
|
|
|
|
#define PIN_OUT (p12)
|
|
|
|
|
2014-05-14 13:54:11 +00:00
|
|
|
#elif defined(TARGET_NUCLEO_F103RB) || \
|
|
|
|
defined(TARGET_NUCLEO_L152RE) || \
|
|
|
|
defined(TARGET_NUCLEO_F302R8) || \
|
|
|
|
defined(TARGET_NUCLEO_F030R8) || \
|
|
|
|
defined(TARGET_NUCLEO_F401RE) || \
|
2014-06-23 14:56:25 +00:00
|
|
|
defined(TARGET_NUCLEO_F411RE) || \
|
|
|
|
defined(TARGET_NUCLEO_F072RB) || \
|
|
|
|
defined(TARGET_NUCLEO_F334R8) || \
|
2014-05-14 13:54:11 +00:00
|
|
|
defined(TARGET_NUCLEO_L053R8)
|
|
|
|
#define PIN_IN PB_8
|
|
|
|
#define PIN_OUT PC_6
|
2014-03-11 11:58:33 +00:00
|
|
|
|
2014-04-07 15:56:13 +00:00
|
|
|
#elif defined(TARGET_FF_ARDUINO)
|
|
|
|
#define PIN_OUT D0
|
|
|
|
#define PIN_IN D7
|
|
|
|
|
2013-02-26 14:57:42 +00:00
|
|
|
#else
|
2013-02-18 15:32:11 +00:00
|
|
|
#define PIN_IN (p5)
|
|
|
|
#define PIN_OUT (p25)
|
|
|
|
|
2013-02-26 14:57:42 +00:00
|
|
|
#endif
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
DigitalOut out(PIN_OUT);
|
|
|
|
InterruptIn in(PIN_IN);
|
|
|
|
|
|
|
|
void flipper() {
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
out = 1; myled = 1; wait(0.2);
|
2013-06-27 21:20:47 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
out = 0; myled = 0; wait(0.2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
out = 0; myled = 0;
|
|
|
|
//Test falling edges first
|
|
|
|
in.rise(NULL);
|
|
|
|
in.fall(in_handler);
|
|
|
|
flipper();
|
2013-06-27 21:20:47 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
if(checks != 5) {
|
2014-01-08 10:14:19 +00:00
|
|
|
printf("falling edges test failed: %d\n",checks);
|
2013-02-18 15:32:11 +00:00
|
|
|
notify_completion(false);
|
|
|
|
}
|
2013-06-27 21:20:47 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
//Now test rising edges
|
|
|
|
in.rise(in_handler);
|
|
|
|
in.fall(NULL);
|
|
|
|
flipper();
|
2013-06-27 21:20:47 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
if (checks != 10) {
|
2014-01-08 10:14:19 +00:00
|
|
|
printf("raising edges test failed: %d\n",checks);
|
2013-02-18 15:32:11 +00:00
|
|
|
notify_completion(false);
|
|
|
|
}
|
2013-06-27 21:20:47 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
//Finally test both
|
|
|
|
in.rise(in_handler);
|
|
|
|
in.fall(in_handler);
|
|
|
|
flipper();
|
2013-06-27 21:20:47 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
if (checks != 20) {
|
|
|
|
printf("Simultaneous rising and falling edges failed\n");
|
|
|
|
notify_completion(false);
|
|
|
|
}
|
2013-06-27 21:20:47 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
notify_completion(true);
|
|
|
|
return 0;
|
|
|
|
}
|