@@ -1600,5 +1600,141 @@ PreferenceType WiFiDrv::prefGetType(const char * key) {
1600
1600
return type;
1601
1601
}
1602
1602
1603
+ int WiFiDrv::bleBegin () {
1604
+ WAIT_FOR_SLAVE_SELECT ();
1605
+
1606
+ SpiDrv::sendCmd (BLE_BEGIN, PARAM_NUMS_0);
1607
+
1608
+ SpiDrv::spiSlaveDeselect ();
1609
+ // Wait the reply elaboration
1610
+ SpiDrv::waitForSlaveReady ();
1611
+ SpiDrv::spiSlaveSelect ();
1612
+
1613
+ uint8_t len = 1 ;
1614
+ uint8_t result = 0 ;
1615
+ SpiDrv::waitResponseCmd (BLE_BEGIN, PARAM_NUMS_1, (uint8_t *)&result, &len);
1616
+ SpiDrv::spiSlaveDeselect ();
1617
+
1618
+ return result == 0 ;
1619
+ }
1620
+
1621
+ void WiFiDrv::bleEnd () {
1622
+ WAIT_FOR_SLAVE_SELECT ();
1623
+
1624
+ SpiDrv::sendCmd (BLE_END, PARAM_NUMS_0);
1625
+
1626
+ SpiDrv::spiSlaveDeselect ();
1627
+ // Wait the reply elaboration
1628
+ SpiDrv::waitForSlaveReady ();
1629
+ SpiDrv::spiSlaveSelect ();
1630
+
1631
+ uint8_t len = 1 ;
1632
+ uint8_t result = 0 ;
1633
+ SpiDrv::waitResponseCmd (BLE_END, PARAM_NUMS_1, (uint8_t *)&result, &len);
1634
+ SpiDrv::spiSlaveDeselect ();
1635
+ }
1636
+
1637
+ int WiFiDrv::bleAvailable () {
1638
+ WAIT_FOR_SLAVE_SELECT ();
1639
+ uint16_t result = 0 ;
1640
+
1641
+ SpiDrv::sendCmd (BLE_AVAILABLE, PARAM_NUMS_0);
1642
+
1643
+ SpiDrv::spiSlaveDeselect ();
1644
+ // Wait the reply elaboration
1645
+ SpiDrv::waitForSlaveReady ();
1646
+ SpiDrv::spiSlaveSelect ();
1647
+
1648
+ uint8_t len = 2 ;
1649
+ SpiDrv::waitResponseCmd (BLE_AVAILABLE, PARAM_NUMS_1, (uint8_t *)&result, &len);
1650
+ SpiDrv::spiSlaveDeselect ();
1651
+
1652
+ return result;
1653
+ }
1654
+
1655
+ int WiFiDrv::bleRead (uint8_t data[], size_t length) {
1656
+ WAIT_FOR_SLAVE_SELECT ();
1657
+
1658
+ SpiDrv::sendCmd (BLE_READ, PARAM_NUMS_1);
1659
+
1660
+ int commandSize = 7 ; // 4 for the normal command length + 3 for the parameter
1661
+ uint16_t param = length; // TODO check length doesn't exceed 2^16
1662
+ SpiDrv::sendParam ((uint8_t *)¶m, sizeof (param), LAST_PARAM);
1663
+
1664
+ // pad to multiple of 4
1665
+ while (commandSize % 4 != 0 ) {
1666
+ SpiDrv::readChar ();
1667
+ commandSize++;
1668
+ }
1669
+
1670
+ SpiDrv::spiSlaveDeselect ();
1671
+ // Wait the reply elaboration
1672
+ SpiDrv::waitForSlaveReady ();
1673
+ SpiDrv::spiSlaveSelect ();
1674
+
1675
+ uint16_t res_len = 0 ;
1676
+ SpiDrv::waitResponseData16 (BLE_READ, data, (uint16_t *)&res_len);
1677
+
1678
+ SpiDrv::spiSlaveDeselect ();
1679
+
1680
+ return res_len;
1681
+ }
1682
+
1683
+ int WiFiDrv::blePeek (uint8_t data[], size_t length) {
1684
+ WAIT_FOR_SLAVE_SELECT ();
1685
+
1686
+ SpiDrv::sendCmd (BLE_PEEK, PARAM_NUMS_1);
1687
+
1688
+ int commandSize = 7 ; // 4 for the normal command length + 3 for the parameter
1689
+ uint16_t param = length; // TODO check length doesn't exceed 2^16
1690
+ SpiDrv::sendParam ((uint8_t *)¶m, sizeof (param), LAST_PARAM);
1691
+
1692
+ // pad to multiple of 4
1693
+ while (commandSize % 4 != 0 ) {
1694
+ SpiDrv::readChar ();
1695
+ commandSize++;
1696
+ }
1697
+
1698
+ SpiDrv::spiSlaveDeselect ();
1699
+ // Wait the reply elaboration
1700
+ SpiDrv::waitForSlaveReady ();
1701
+ SpiDrv::spiSlaveSelect ();
1702
+
1703
+ uint16_t res_len = 0 ;
1704
+ SpiDrv::waitResponseData16 (BLE_READ, data, (uint16_t *)&res_len);
1705
+
1706
+ SpiDrv::spiSlaveDeselect ();
1707
+
1708
+ return res_len;
1709
+ }
1710
+
1711
+ size_t WiFiDrv::bleWrite (const uint8_t * data, size_t len) {
1712
+ WAIT_FOR_SLAVE_SELECT ();
1713
+
1714
+ int commandSize = 4 ;
1715
+ SpiDrv::sendCmd (BLE_WRITE, PARAM_NUMS_1);
1716
+
1717
+ SpiDrv::sendBuffer ((uint8_t *)data, len, LAST_PARAM);
1718
+ commandSize += len+2 ;
1719
+
1720
+ // pad to multiple of 4
1721
+ while (commandSize % 4 != 0 ) {
1722
+ SpiDrv::readChar ();
1723
+ commandSize++;
1724
+ }
1725
+
1726
+ SpiDrv::spiSlaveDeselect ();
1727
+ // Wait the reply elaboration
1728
+ SpiDrv::waitForSlaveReady ();
1729
+ SpiDrv::spiSlaveSelect ();
1730
+
1731
+ uint8_t res_len = 1 ;
1732
+ uint16_t res = 0 ;
1733
+ SpiDrv::waitResponseCmd (PREFERENCES_PUT, PARAM_NUMS_1, (uint8_t *)&res, &res_len);
1734
+ SpiDrv::spiSlaveDeselect ();
1735
+
1736
+ return res;
1737
+ }
1738
+
1603
1739
1604
1740
WiFiDrv wiFiDrv;
0 commit comments