BLE_BlueNRG for Nucleo board
Dependents: Nucleo_BLE_HeartRate Nucleo_BLE_UART Nucleo_BLE_UART
Warning: Deprecated!
Supported drivers and applications can be found at this link.
Revision 2:905715088a9b, committed 2014-12-24
- Comitter:
- sjallouli
- Date:
- Wed Dec 24 18:01:41 2014 +0000
- Parent:
- 1:be1cb4be316f
- Commit message:
- Add USER_BUTTON interrupt configuration
Changed in this revision
hci/src/bluenrg_shield_bsp.c | Show annotated file Show diff for this revision Revisions of this file |
diff -r be1cb4be316f -r 905715088a9b hci/src/bluenrg_shield_bsp.c --- a/hci/src/bluenrg_shield_bsp.c Fri Dec 19 19:28:15 2014 +0000 +++ b/hci/src/bluenrg_shield_bsp.c Wed Dec 24 18:01:41 2014 +0000 @@ -41,12 +41,23 @@ #include "wait_api.h" #include "pinmap.h" #include "bluenrg_shield_bsp.h" +//#include "Utils.h" spi_t __spi; gpio_irq_t irq_exti; -gpio_t gpio_pin_A0, gpio_pin_CS, gpio_pin_MOSI, gpio_pin_MISO, gpio_pin_SCLK, gpio_pin_RESET; +gpio_t gpio_pin_A0; + +gpio_irq_t irq_exti_UB; +gpio_t gpio_pin_UB; + +gpio_t gpio_pin_CS; +gpio_t gpio_pin_MOSI; +gpio_t gpio_pin_MISO; +gpio_t gpio_pin_SCLK; +gpio_t gpio_pin_RESET; + void EXTI_irq_handler(uint32_t id, gpio_irq_event event); - + /** @addtogroup BlueNRG_Shield * @{ */ @@ -56,39 +67,51 @@ * @{ */ - + /* * mbed EXTI IRQ Handler * */ +bool user_button_pressed = false; +void USER_BUTTON_EXTI_irq_handler(uint32_t id, gpio_irq_event event) +{ + user_button_pressed = true; +} + void EXTI_irq_handler(uint32_t id, gpio_irq_event event) { - tHciDataPacket * hciReadPacket = NULL; + tHciDataPacket * hciReadPacket = NULL; uint8_t data_len; - //Check id of the IRQ - if(id == (uint32_t)BNRG_SPI_INSTANCE) { - - while (gpio_read(&gpio_pin_A0) == 1) { - if (list_is_empty (&hciReadPktPool) == FALSE){ + if(id == (uint32_t)BNRG_SPI_INSTANCE) //Check id of the IRQ + { + while (gpio_read(&gpio_pin_A0) == 1) + { + if (list_is_empty (&hciReadPktPool) == FALSE) + { /* enqueueing a packet for read */ list_remove_head (&hciReadPktPool, (tListNode **)&hciReadPacket); data_len = BlueNRG_SPI_Read_All(hciReadPacket->dataBuff, HCI_PACKET_SIZE); - if(data_len > 0){ - /* Packet will be inserted to the correct queue */ - HCI_Input(hciReadPacket); - } else { - /* Insert the packet back into the pool */ - list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket); + if(data_len > 0) + { + HCI_Input(hciReadPacket);/* Packet will be inserted to the correct queue */ + } + else + { + list_insert_head(&hciReadPktPool, (tListNode *)hciReadPacket);/* Insert the packet back into the pool */ } - - } else{ + } + else + { /* TODO: HCI Read Packet Pool is empty, wait for a free packet */ } - } } + else if(id == (uint32_t)BNRG_SPI_INSTANCE + 1) //Check id of the IRQ + { + user_button_pressed = true; + } } /** @@ -103,37 +126,32 @@ * @retval None */ void BNRG_SPI_Init(void) -{ +{ int ret; - spi_init(&__spi, D11, D12, D13, NC); - //spi_format(&__spi, 8, 0, 0); - //spi_frequency(&__spi, 1000000); - - /*Init IRQ for EXTI Interrupt*/ - //gpio_init(&gpio_pin_A0, A0);//PA_0 in Nucleo - ret = gpio_irq_init(&irq_exti, A0, EXTI_irq_handler,(uint32_t)BNRG_SPI_INSTANCE); - gpio_irq_set(&irq_exti, IRQ_RISE, 1);//Set mode to IRQ_RISE - gpio_init_in(&gpio_pin_A0, A0);//PA_0 in Nucleo//Configure the GPIO Pin as Input pin and PullDefault - //gpio_irq_enable(&irq_exti);//IRQ already enabled in IRQ init call above. + spi_init(&__spi, D11, D12, D13, NC); + +#if 1 + ret = gpio_irq_init(&irq_exti_UB, USER_BUTTON, USER_BUTTON_EXTI_irq_handler,(uint32_t)(BNRG_SPI_INSTANCE+1)); + gpio_irq_set (&irq_exti_UB, IRQ_FALL, 1);//Set mode to IRQ_RISE + gpio_init_in(&gpio_pin_UB, USER_BUTTON);//User Button in Nucleo//Configure the GPIO Pin as Input pin and PullDefault +#endif - /* Reset Pin Config */ - gpio_init(&gpio_pin_RESET, D7);//PA_8 in Nucleo - gpio_mode(&gpio_pin_RESET, PullNone); - gpio_dir(&gpio_pin_RESET, PIN_OUTPUT); - gpio_write(&gpio_pin_RESET, 1); + /*Init IRQ for EXTI Interrupt*/ + ret = gpio_irq_init(&irq_exti, A0, EXTI_irq_handler,(uint32_t)BNRG_SPI_INSTANCE); + gpio_irq_set (&irq_exti, IRQ_RISE, 1);//Set mode to IRQ_RISE + gpio_init_in(&gpio_pin_A0, A0);//PA_0 in Nucleo//Configure the GPIO Pin as Input pin and PullDefault + + /* Reset Pin Config */ + gpio_init (&gpio_pin_RESET, D7);//PA_8 in Nucleo + gpio_mode (&gpio_pin_RESET, PullNone); + gpio_dir (&gpio_pin_RESET, PIN_OUTPUT); + gpio_write(&gpio_pin_RESET, 1); - /* SCLK - PA_5 - Not needed to configure if correct PinName is given to spi_init, in this case PB_3 for L0*/ - /*gpio_init(&gpio_pin_SCLK, PB_3); //PA_5 is not USED????!!!! Since configuring PA_5 does not work! - gpio_mode(&gpio_pin_SCLK, PullUp); - //gpio_dir(&gpio_pin_SCLK, PIN_INPUT); //just 2 options of PIN_INPUT and PIN_OUTPUT does not suffice to configure Pin. - pin_function(PB_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, 0));*/ - - /* NSS/CSN/CS - PA_1*/ - gpio_init(&gpio_pin_CS, A1);//PA_1 in Nucleo - gpio_mode(&gpio_pin_CS, PullNone); - gpio_dir(&gpio_pin_CS, PIN_OUTPUT); - gpio_write(&gpio_pin_CS, 1); - + /* NSS/CSN/CS - PA_1*/ + gpio_init (&gpio_pin_CS, A1);//PA_1 in Nucleo + gpio_mode (&gpio_pin_CS, PullNone); + gpio_dir (&gpio_pin_CS, PIN_OUTPUT); + gpio_write(&gpio_pin_CS, 1); } /** @@ -311,10 +329,11 @@ */ void BlueNRG_RST(void) { - gpio_write(&gpio_pin_RESET, 0); - wait_us(5); - gpio_write(&gpio_pin_RESET, 1); - wait_us(5); + gpio_write(&gpio_pin_RESET, 0); + wait_us(5); + + gpio_write(&gpio_pin_RESET, 1); + wait_us(5); } /**