@@ -940,8 +940,16 @@ void HCISpiTransportClass::wait_for_aci_gap_init()
940
940
void HCISpiTransportClass::aci_gap_init ()
941
941
{
942
942
uint8_t header_master[5 ] = {0x0a , 0x00 , 0x00 , 0x00 , 0x00 };
943
- uint8_t cmd[7 ] = {0x01 , 0x8A , 0xFC , 0x03 , 0x0F , 0x00 , 0x00 }; // ACI_GAP_INIT
944
- uint8_t cmd_lp[8 ] = {0x01 , 0x8A , 0xFC , 0x04 , 0x0F , 0x00 , 0x00 , 0x00 }; // ACI_GAP_INIT for BlueNRG-LP
943
+ uint8_t cmd_lp[8 ] = {0x01 , 0x8A , 0xFC , 0x04 , 0x0F , 0x00 , 0x00 , 0x00 }; // ACI_GAP_INIT
944
+ uint8_t cmd_others[7 ] = {0x01 , 0x8A , 0xFC , 0x03 , 0x0F , 0x00 , 0x00 }; // ACI_GAP_INIT
945
+ uint8_t *cmd, cmd_size;
946
+ if (_ble_chip == BLUENRG_LP) {
947
+ cmd = cmd_lp;
948
+ cmd_size = 8 ;
949
+ } else {
950
+ cmd = cmd_others;
951
+ cmd_size = 7 ;
952
+ }
945
953
int result = 0 ;
946
954
947
955
do {
@@ -958,9 +966,9 @@ void HCISpiTransportClass::aci_gap_init()
958
966
/* device is ready */
959
967
if (header_master[0 ] == 0x02 ) {
960
968
/* Write the data */
961
- if (header_master[1 ] >= 7 ) {
969
+ if (header_master[1 ] >= cmd_size ) {
962
970
/* Write the data */
963
- _spi->transfer ((void *)cmd, 7 );
971
+ _spi->transfer ((void *)cmd, cmd_size );
964
972
} else {
965
973
result = -2 ;
966
974
}
@@ -971,46 +979,7 @@ void HCISpiTransportClass::aci_gap_init()
971
979
digitalWrite (_cs_pin, HIGH);
972
980
973
981
_spi->endTransaction ();
974
- } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) {
975
- uint32_t tickstart_data_available = millis ();
976
- result = 0 ;
977
-
978
- detachInterrupt (_spi_irq);
979
-
980
- _spi->beginTransaction (_spiSettings);
981
-
982
- digitalWrite (_cs_pin, LOW);
983
-
984
- while (!(digitalRead (_spi_irq) == 1 )) {
985
- if ((millis () - tickstart_data_available) > 1000 ) {
986
- result = -3 ;
987
- break ;
988
- }
989
- }
990
-
991
- if (result == -3 ) {
992
- digitalWrite (_cs_pin, HIGH);
993
- _spi->endTransaction ();
994
- attachInterrupt (_spi_irq, SPI_Irq_Callback, RISING);
995
- break ;
996
- }
997
-
998
- /* Write the header */
999
- _spi->transfer (header_master, 5 );
1000
-
1001
- if ((int )((((uint16_t )header_master[2 ]) << 8 ) | ((uint16_t )header_master[1 ])) >= 7 ) {
1002
- /* Write the data */
1003
- _spi->transfer ((void *)cmd, 7 );
1004
- } else {
1005
- result = -2 ;
1006
- }
1007
-
1008
- digitalWrite (_cs_pin, HIGH);
1009
-
1010
- _spi->endTransaction ();
1011
-
1012
- attachInterrupt (_spi_irq, SPI_Irq_Callback, RISING);
1013
- } else if (_ble_chip == BLUENRG_LP) {
982
+ } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) {
1014
983
uint32_t tickstart_data_available = millis ();
1015
984
result = 0 ;
1016
985
@@ -1037,9 +1006,9 @@ void HCISpiTransportClass::aci_gap_init()
1037
1006
/* Write the header */
1038
1007
_spi->transfer (header_master, 5 );
1039
1008
1040
- if ((int )((((uint16_t )header_master[2 ]) << 8 ) | ((uint16_t )header_master[1 ])) >= 8 ) {
1009
+ if ((int )((((uint16_t )header_master[2 ]) << 8 ) | ((uint16_t )header_master[1 ])) >= cmd_size ) {
1041
1010
/* Write the data */
1042
- _spi->transfer ((void *)cmd_lp, 8 );
1011
+ _spi->transfer ((void *)cmd, cmd_size );
1043
1012
} else {
1044
1013
result = -2 ;
1045
1014
}
0 commit comments