ble_core.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /************************************************************************************************
  2. * Include *
  3. ************************************************************************************************/
  4. #include "ble_core.h"
  5. #include "stm32f4xx_gpio.h"
  6. #include "systick.h"
  7. #include "uart.h"
  8. #include <stdint.h>
  9. /************************************************************************************************
  10. * Config *
  11. ************************************************************************************************/
  12. /************************************************************************************************
  13. * Data structs *
  14. ************************************************************************************************/
  15. void ble_init(void)
  16. {
  17. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  18. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  19. GPIO_InitTypeDef GPIO_StructInit;
  20. GPIO_StructInit.GPIO_Mode = GPIO_Mode_OUT;
  21. GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
  22. GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
  23. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_UP;
  24. GPIO_StructInit.GPIO_Pin = BT_RST_PIN;
  25. GPIO_Init(BT_RST_PORT, &GPIO_StructInit);
  26. GPIO_ResetBits(BT_RST_PORT, BT_RST_PIN);
  27. ms_delay(1);
  28. GPIO_SetBits(BT_RST_PORT, BT_RST_PIN);
  29. GPIO_StructInit.GPIO_Mode = GPIO_Mode_IN;
  30. GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
  31. GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
  32. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_NOPULL;
  33. GPIO_StructInit.GPIO_Pin = BT_BUSY_IND_PIN;
  34. GPIO_Init(BT_BUSY_IND_PORT, &GPIO_StructInit);
  35. GPIO_StructInit.GPIO_Mode = GPIO_Mode_IN;
  36. GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
  37. GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
  38. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_UP;
  39. GPIO_StructInit.GPIO_Pin = BT_CONN_IND_PIN;
  40. GPIO_Init(BT_CONN_IND_PORT, &GPIO_StructInit);
  41. }
  42. uint8_t conn_sta = 0;
  43. uint8_t busy_sta = 0;
  44. void ble_send(void)
  45. {
  46. conn_sta = GPIO_ReadInputDataBit(BT_CONN_IND_PORT, BT_CONN_IND_PIN);
  47. busy_sta = GPIO_ReadInputDataBit(BT_BUSY_IND_PORT, BT_BUSY_IND_PIN);
  48. uint8_t a[5] = {0};
  49. a[0] = 0x01;
  50. a[1] = 0xFC;
  51. a[2] = 0x00;
  52. a[3] = 0x01;
  53. a[4] = 0x01;
  54. usart_send_it(&usart2_context, a, 5);
  55. }
  56. /************************************************************************************************
  57. * implements *
  58. ************************************************************************************************/