Simple firmware to test the I/O capabilities of a Nucleo 64 board

Dependencies:   mbed

Committer:
hieuvt6
Date:
Mon Mar 14 02:30:27 2016 +0000
Revision:
0:43a77ff47221
Child:
1:69c43e344369
Simple program to test the I/O capabilities of a Nucleo 64 board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hieuvt6 0:43a77ff47221 1 #include "mbed.h"
hieuvt6 0:43a77ff47221 2
hieuvt6 0:43a77ff47221 3 #define DEBUG_0_PRINT_OUT_ENABLE 1
hieuvt6 0:43a77ff47221 4 #if DEBUG_0_PRINT_OUT_ENABLE
hieuvt6 0:43a77ff47221 5 #define DEBUG_0(...) { printf(__VA_ARGS__); }
hieuvt6 0:43a77ff47221 6 #else
hieuvt6 0:43a77ff47221 7 #define DEBUG_0(...) /* nothing */
hieuvt6 0:43a77ff47221 8 #endif /* #if DEBUG_0_PRINT_OUT_ENABLE */
hieuvt6 0:43a77ff47221 9
hieuvt6 0:43a77ff47221 10 #define LED_ON 1 // LED is ACTIVE HIGH. It turns ON when the control pin is HIGH
hieuvt6 0:43a77ff47221 11 #define LED_OFF 0 // LED is ACTIVE HIGH. It turns OFF when the control pin is LOW
hieuvt6 0:43a77ff47221 12 #define BUTTON_PRESSED_LED_STATE LED_ON
hieuvt6 0:43a77ff47221 13 #define BUTTON_RELEASED_LED_STATE LED_OFF
hieuvt6 0:43a77ff47221 14
hieuvt6 0:43a77ff47221 15 DigitalOut led1(LED1);
hieuvt6 0:43a77ff47221 16 InterruptIn userButton(USER_BUTTON);
hieuvt6 0:43a77ff47221 17
hieuvt6 0:43a77ff47221 18 void
hieuvt6 0:43a77ff47221 19 buttonPressedCallback(void)
hieuvt6 0:43a77ff47221 20 {
hieuvt6 0:43a77ff47221 21 led1 = BUTTON_PRESSED_LED_STATE;
hieuvt6 0:43a77ff47221 22 DEBUG_0("button pressed\n");
hieuvt6 0:43a77ff47221 23 }
hieuvt6 0:43a77ff47221 24
hieuvt6 0:43a77ff47221 25 void
hieuvt6 0:43a77ff47221 26 buttonReleasedCallback(void)
hieuvt6 0:43a77ff47221 27 {
hieuvt6 0:43a77ff47221 28 led1 = BUTTON_RELEASED_LED_STATE;
hieuvt6 0:43a77ff47221 29 DEBUG_0("button released\n");
hieuvt6 0:43a77ff47221 30 }
hieuvt6 0:43a77ff47221 31
hieuvt6 0:43a77ff47221 32 void
hieuvt6 0:43a77ff47221 33 initBoard(void)
hieuvt6 0:43a77ff47221 34 {
hieuvt6 0:43a77ff47221 35 // Init LED to turn ON by default
hieuvt6 0:43a77ff47221 36 led1 = BUTTON_RELEASED_LED_STATE;
hieuvt6 0:43a77ff47221 37 // Init button pressed and released behavior
hieuvt6 0:43a77ff47221 38 userButton.rise(buttonReleasedCallback); // Button is ACTIVE LOW. Released the button pull input pin HIGH, triggering the Rising Edge interrupt.
hieuvt6 0:43a77ff47221 39 userButton.fall(buttonPressedCallback); // Button is ACTIVE LOW. Pressed the button pull input pin LOW, triggering the Falling Edge interrupt.
hieuvt6 0:43a77ff47221 40 userButton.enable_irq();
hieuvt6 0:43a77ff47221 41 }
hieuvt6 0:43a77ff47221 42
hieuvt6 0:43a77ff47221 43 int
hieuvt6 0:43a77ff47221 44 main()
hieuvt6 0:43a77ff47221 45 {
hieuvt6 0:43a77ff47221 46 initBoard();
hieuvt6 0:43a77ff47221 47 led1 = LED_ON;
hieuvt6 0:43a77ff47221 48 wait_ms(1000);
hieuvt6 0:43a77ff47221 49 led1 = LED_OFF;
hieuvt6 0:43a77ff47221 50 wait_ms(1000);
hieuvt6 0:43a77ff47221 51 while(1) {
hieuvt6 0:43a77ff47221 52 }
hieuvt6 0:43a77ff47221 53 }