AirDemo2
Dependencies: BLE_API mbed nRF51822
main.cpp@0:a90a8367fa4c, 2016-05-19 (annotated)
- Committer:
- AndreaP
- Date:
- Thu May 19 11:35:40 2016 +0000
- Revision:
- 0:a90a8367fa4c
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AndreaP | 0:a90a8367fa4c | 1 | #include "mbed.h" |
AndreaP | 0:a90a8367fa4c | 2 | #include "nRF5xGap.h" |
AndreaP | 0:a90a8367fa4c | 3 | #include "InterruptManager.h" |
AndreaP | 0:a90a8367fa4c | 4 | #include "nrf_gpio.h" |
AndreaP | 0:a90a8367fa4c | 5 | |
AndreaP | 0:a90a8367fa4c | 6 | DigitalOut greenLed(P0_21); |
AndreaP | 0:a90a8367fa4c | 7 | DigitalOut blueLed(P0_22); |
AndreaP | 0:a90a8367fa4c | 8 | DigitalOut redLed(P0_23); |
AndreaP | 0:a90a8367fa4c | 9 | |
AndreaP | 0:a90a8367fa4c | 10 | #define LED_ON 0 |
AndreaP | 0:a90a8367fa4c | 11 | #define LED_OFF 1 |
AndreaP | 0:a90a8367fa4c | 12 | |
AndreaP | 0:a90a8367fa4c | 13 | #define BTN_PRESSED 0 |
AndreaP | 0:a90a8367fa4c | 14 | #define BTN_RELEASED 1 |
AndreaP | 0:a90a8367fa4c | 15 | |
AndreaP | 0:a90a8367fa4c | 16 | /* |
AndreaP | 0:a90a8367fa4c | 17 | void RTC1_IRQHandler(void) |
AndreaP | 0:a90a8367fa4c | 18 | { |
AndreaP | 0:a90a8367fa4c | 19 | if(NRF_RTC1->EVENTS_COMPARE[0] != 0) { |
AndreaP | 0:a90a8367fa4c | 20 | NRF_RTC1->EVENTS_COMPARE[0] = 0; |
AndreaP | 0:a90a8367fa4c | 21 | |
AndreaP | 0:a90a8367fa4c | 22 | NRF_RTC1->TASKS_CLEAR = 1; |
AndreaP | 0:a90a8367fa4c | 23 | } |
AndreaP | 0:a90a8367fa4c | 24 | |
AndreaP | 0:a90a8367fa4c | 25 | } |
AndreaP | 0:a90a8367fa4c | 26 | void rtc_handler(void) |
AndreaP | 0:a90a8367fa4c | 27 | { |
AndreaP | 0:a90a8367fa4c | 28 | |
AndreaP | 0:a90a8367fa4c | 29 | } |
AndreaP | 0:a90a8367fa4c | 30 | */ |
AndreaP | 0:a90a8367fa4c | 31 | |
AndreaP | 0:a90a8367fa4c | 32 | void GPIOTE_IRQHandler(void) |
AndreaP | 0:a90a8367fa4c | 33 | { |
AndreaP | 0:a90a8367fa4c | 34 | // This handler will be run after wakeup from system ON (GPIO wakeup) |
AndreaP | 0:a90a8367fa4c | 35 | if(NRF_GPIOTE->EVENTS_PORT) |
AndreaP | 0:a90a8367fa4c | 36 | { |
AndreaP | 0:a90a8367fa4c | 37 | NRF_GPIOTE->EVENTS_PORT = 0; |
AndreaP | 0:a90a8367fa4c | 38 | blueLed = LED_ON; |
AndreaP | 0:a90a8367fa4c | 39 | printf("P2 Premuto\r\n"); |
AndreaP | 0:a90a8367fa4c | 40 | } |
AndreaP | 0:a90a8367fa4c | 41 | } |
AndreaP | 0:a90a8367fa4c | 42 | |
AndreaP | 0:a90a8367fa4c | 43 | //int RTC1_PRESCALER = 0; |
AndreaP | 0:a90a8367fa4c | 44 | //int RTC1_CC0 = 100; |
AndreaP | 0:a90a8367fa4c | 45 | |
AndreaP | 0:a90a8367fa4c | 46 | int main() { |
AndreaP | 0:a90a8367fa4c | 47 | |
AndreaP | 0:a90a8367fa4c | 48 | blueLed = LED_OFF; |
AndreaP | 0:a90a8367fa4c | 49 | greenLed = LED_OFF; |
AndreaP | 0:a90a8367fa4c | 50 | redLed = LED_OFF; |
AndreaP | 0:a90a8367fa4c | 51 | |
AndreaP | 0:a90a8367fa4c | 52 | printf("\r\nInit\r\n"); |
AndreaP | 0:a90a8367fa4c | 53 | |
AndreaP | 0:a90a8367fa4c | 54 | //NRF_POWER->SYSTEMOFF=0; //power ON |
AndreaP | 0:a90a8367fa4c | 55 | |
AndreaP | 0:a90a8367fa4c | 56 | //NRF_RTC1->INTENSET = RTC_INTENSET_COMPARE0_Msk; |
AndreaP | 0:a90a8367fa4c | 57 | //NRF_RTC1->PRESCALER = RTC1_PRESCALER; |
AndreaP | 0:a90a8367fa4c | 58 | //NRF_RTC1->CC[0] = RTC1_CC0; |
AndreaP | 0:a90a8367fa4c | 59 | |
AndreaP | 0:a90a8367fa4c | 60 | //NVIC_EnableIRQ(RTC1_IRQn); |
AndreaP | 0:a90a8367fa4c | 61 | |
AndreaP | 0:a90a8367fa4c | 62 | //InterruptManager::get()->add_handler(rtc_handler, RTC1_IRQn); |
AndreaP | 0:a90a8367fa4c | 63 | |
AndreaP | 0:a90a8367fa4c | 64 | // Configure BUTTON0 as a regular input |
AndreaP | 0:a90a8367fa4c | 65 | nrf_gpio_cfg_input(p16, NRF_GPIO_PIN_PULLUP); |
AndreaP | 0:a90a8367fa4c | 66 | |
AndreaP | 0:a90a8367fa4c | 67 | // Configure BUTTON 2 with SENSE enabled so that CPU is enabled (exit System-On low power mode) when pressing Button 2 |
AndreaP | 0:a90a8367fa4c | 68 | nrf_gpio_cfg_sense_input(p17, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); |
AndreaP | 0:a90a8367fa4c | 69 | |
AndreaP | 0:a90a8367fa4c | 70 | blueLed = LED_ON; |
AndreaP | 0:a90a8367fa4c | 71 | |
AndreaP | 0:a90a8367fa4c | 72 | NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk; |
AndreaP | 0:a90a8367fa4c | 73 | NVIC_EnableIRQ(GPIOTE_IRQn); |
AndreaP | 0:a90a8367fa4c | 74 | //InterruptManager::get()->add_handler(p1_handler, GPIOTE_IRQn); |
AndreaP | 0:a90a8367fa4c | 75 | |
AndreaP | 0:a90a8367fa4c | 76 | |
AndreaP | 0:a90a8367fa4c | 77 | while(1) |
AndreaP | 0:a90a8367fa4c | 78 | { |
AndreaP | 0:a90a8367fa4c | 79 | // If BUTTON 1 is pressed.. |
AndreaP | 0:a90a8367fa4c | 80 | if(nrf_gpio_pin_read(p16) == BTN_PRESSED) |
AndreaP | 0:a90a8367fa4c | 81 | { |
AndreaP | 0:a90a8367fa4c | 82 | printf("P1 Premuto\r\n"); |
AndreaP | 0:a90a8367fa4c | 83 | blueLed = LED_OFF; |
AndreaP | 0:a90a8367fa4c | 84 | // Enter CONSTLAT mode if desired, otherwise LOWPWR mode will be used (LOWPWR is recommended for most applications) |
AndreaP | 0:a90a8367fa4c | 85 | //NRF_POWER->TASKS_CONSTLAT = 1; |
AndreaP | 0:a90a8367fa4c | 86 | |
AndreaP | 0:a90a8367fa4c | 87 | // Enter System ON sleep mode |
AndreaP | 0:a90a8367fa4c | 88 | __WFE(); |
AndreaP | 0:a90a8367fa4c | 89 | __SEV(); |
AndreaP | 0:a90a8367fa4c | 90 | __WFE(); |
AndreaP | 0:a90a8367fa4c | 91 | } |
AndreaP | 0:a90a8367fa4c | 92 | } |
AndreaP | 0:a90a8367fa4c | 93 | } |