csr8311.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "hm_chipset.h"
  2. #include "hm_hci_transport_h4.h"
  3. #include "hm_config.h"
  4. static uint8_t download_commands[] = {
  5. /* 0x2819: Read build ID */
  6. // 0x00, 0xFC, 0x17, 0xc2, 0x00, 0x00, 0x09, 0x00, 0x01, 0x00, 0x19, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7. // 0x01fe: Set ANA_Freq to 26MHz
  8. 0x00, 0xFC, 0x13, 0xc2, 0x02, 0x00, 0x09, 0x00, 0x01, 0x00, 0x03, 0x70, 0x00, 0x00, 0xfe, 0x01, 0x01, 0x00, 0x08, 0x00, 0x90, 0x65,
  9. // 0x00f2: Set HCI_NOP_DISABLE
  10. 0x00, 0xFC, 0x13, 0xc2, 0x02, 0x00, 0x09, 0x00, 0x01, 0x00, 0x03, 0x70, 0x00, 0x00, 0xf2, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00,
  11. // 0x01bf: Enable RTS/CTS for BCSP (0806 -> 080e)
  12. 0x00, 0xFC, 0x13, 0xc2, 0x02, 0x00, 0x09, 0x00, 0x01, 0x00, 0x03, 0x70, 0x00, 0x00, 0xbf, 0x01, 0x01, 0x00, 0x08, 0x00, 0x0e, 0x08,
  13. // 0x01ea: Set UART baudrate to 115200
  14. 0x00, 0xFC, 0x15, 0xc2, 0x02, 0x00, 0x0a, 0x00, 0x02, 0x00, 0x03, 0x70, 0x00, 0x00, 0xea, 0x01, 0x02, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0xc2,
  15. // 0x0001: Set Bluetooth address
  16. 0x00, 0xFC, 0x19, 0xc2, 0x02, 0x00, 0x0A, 0x00, 0x03, 0x00, 0x03, 0x70, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0xf3, 0x00, 0xf5, 0xf4, 0xf2, 0x00, 0xf2, 0xf1,
  17. };
  18. static uint8_t warm_reset[] = {
  19. // WarmReset Command
  20. 0x00, 0xFC, 0x13, 0xc2, 0x02, 0x00, 0x09, 0x00, 0x03, 0x0e, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  21. };
  22. int chipset_csr_init(void)
  23. {
  24. uint8_t *p = download_commands;
  25. uint8_t *end = download_commands + ARRAY_SIZE(download_commands);
  26. uint16_t len = 0;
  27. uint8_t recv[30];
  28. chip_send_hci_reset_cmd_until_ack();
  29. rt_kprintf("SCR8311 start init\n");
  30. while (p < end) {
  31. len = 3 + p[2];
  32. chip_hci_cmd_send(p, len);
  33. chip_hci_event_read(recv, ARRAY_SIZE(recv), RT_WAITING_FOREVER);
  34. if (recv[0] != 0xFF) // Vendor Event
  35. return HM_CHIPSET_INIT_ERROR;
  36. p += len;
  37. }
  38. /* warm reset */
  39. rt_kprintf("CSR8311 start warm reset\n");
  40. chip_hci_cmd_send(warm_reset, ARRAY_SIZE(warm_reset));
  41. /* Wait 10 ms for warm reset complete. */
  42. rt_thread_mdelay(10);
  43. /* Make sure chipset is normal now. */
  44. chip_send_hci_reset_cmd_until_ack();
  45. rt_kprintf("CSR8311 init success\n");
  46. return HM_SUCCESS;
  47. }
  48. static hm_chipset_t chipset_csr = {
  49. .name = "csr",
  50. .init = chipset_csr_init,
  51. };
  52. hm_chipset_t* hm_chipset_get_instance(void)
  53. {
  54. return &chipset_csr;
  55. }