@@ -113,7 +113,6 @@ void WiFiDrv::wifiDriverInit()
113
113
114
114
void WiFiDrv::wifiDriverDeinit ()
115
115
{
116
- SpiDrv::end ();
117
116
}
118
117
119
118
int8_t WiFiDrv::wifiSetNetwork (const char * ssid, uint8_t ssid_len)
@@ -1633,5 +1632,141 @@ PreferenceType WiFiDrv::prefGetType(const char * key) {
1633
1632
return type;
1634
1633
}
1635
1634
1635
+ int WiFiDrv::bleBegin () {
1636
+ WAIT_FOR_SLAVE_SELECT ();
1637
+
1638
+ SpiDrv::sendCmd (BLE_BEGIN, PARAM_NUMS_0);
1639
+
1640
+ SpiDrv::spiSlaveDeselect ();
1641
+ // Wait the reply elaboration
1642
+ SpiDrv::waitForSlaveReady ();
1643
+ SpiDrv::spiSlaveSelect ();
1644
+
1645
+ uint8_t len = 1 ;
1646
+ uint8_t result = 0 ;
1647
+ SpiDrv::waitResponseCmd (BLE_BEGIN, PARAM_NUMS_1, (uint8_t *)&result, &len);
1648
+ SpiDrv::spiSlaveDeselect ();
1649
+
1650
+ return result == 0 ;
1651
+ }
1652
+
1653
+ void WiFiDrv::bleEnd () {
1654
+ WAIT_FOR_SLAVE_SELECT ();
1655
+
1656
+ SpiDrv::sendCmd (BLE_END, PARAM_NUMS_0);
1657
+
1658
+ SpiDrv::spiSlaveDeselect ();
1659
+ // Wait the reply elaboration
1660
+ SpiDrv::waitForSlaveReady ();
1661
+ SpiDrv::spiSlaveSelect ();
1662
+
1663
+ uint8_t len = 1 ;
1664
+ uint8_t result = 0 ;
1665
+ SpiDrv::waitResponseCmd (BLE_END, PARAM_NUMS_1, (uint8_t *)&result, &len);
1666
+ SpiDrv::spiSlaveDeselect ();
1667
+ }
1668
+
1669
+ int WiFiDrv::bleAvailable () {
1670
+ WAIT_FOR_SLAVE_SELECT ();
1671
+ uint16_t result = 0 ;
1672
+
1673
+ SpiDrv::sendCmd (BLE_AVAILABLE, PARAM_NUMS_0);
1674
+
1675
+ SpiDrv::spiSlaveDeselect ();
1676
+ // Wait the reply elaboration
1677
+ SpiDrv::waitForSlaveReady ();
1678
+ SpiDrv::spiSlaveSelect ();
1679
+
1680
+ uint8_t len = 2 ;
1681
+ SpiDrv::waitResponseCmd (BLE_AVAILABLE, PARAM_NUMS_1, (uint8_t *)&result, &len);
1682
+ SpiDrv::spiSlaveDeselect ();
1683
+
1684
+ return result;
1685
+ }
1686
+
1687
+ int WiFiDrv::bleRead (uint8_t data[], size_t length) {
1688
+ WAIT_FOR_SLAVE_SELECT ();
1689
+
1690
+ SpiDrv::sendCmd (BLE_READ, PARAM_NUMS_1);
1691
+
1692
+ int commandSize = 7 ; // 4 for the normal command length + 3 for the parameter
1693
+ uint16_t param = length; // TODO check length doesn't exceed 2^16
1694
+ SpiDrv::sendParam ((uint8_t *)¶m, sizeof (param), LAST_PARAM);
1695
+
1696
+ // pad to multiple of 4
1697
+ while (commandSize % 4 != 0 ) {
1698
+ SpiDrv::readChar ();
1699
+ commandSize++;
1700
+ }
1701
+
1702
+ SpiDrv::spiSlaveDeselect ();
1703
+ // Wait the reply elaboration
1704
+ SpiDrv::waitForSlaveReady ();
1705
+ SpiDrv::spiSlaveSelect ();
1706
+
1707
+ uint16_t res_len = 0 ;
1708
+ SpiDrv::waitResponseData16 (BLE_READ, data, (uint16_t *)&res_len);
1709
+
1710
+ SpiDrv::spiSlaveDeselect ();
1711
+
1712
+ return res_len;
1713
+ }
1714
+
1715
+ int WiFiDrv::blePeek (uint8_t data[], size_t length) {
1716
+ WAIT_FOR_SLAVE_SELECT ();
1717
+
1718
+ SpiDrv::sendCmd (BLE_PEEK, PARAM_NUMS_1);
1719
+
1720
+ int commandSize = 7 ; // 4 for the normal command length + 3 for the parameter
1721
+ uint16_t param = length; // TODO check length doesn't exceed 2^16
1722
+ SpiDrv::sendParam ((uint8_t *)¶m, sizeof (param), LAST_PARAM);
1723
+
1724
+ // pad to multiple of 4
1725
+ while (commandSize % 4 != 0 ) {
1726
+ SpiDrv::readChar ();
1727
+ commandSize++;
1728
+ }
1729
+
1730
+ SpiDrv::spiSlaveDeselect ();
1731
+ // Wait the reply elaboration
1732
+ SpiDrv::waitForSlaveReady ();
1733
+ SpiDrv::spiSlaveSelect ();
1734
+
1735
+ uint16_t res_len = 0 ;
1736
+ SpiDrv::waitResponseData16 (BLE_READ, data, (uint16_t *)&res_len);
1737
+
1738
+ SpiDrv::spiSlaveDeselect ();
1739
+
1740
+ return res_len;
1741
+ }
1742
+
1743
+ size_t WiFiDrv::bleWrite (const uint8_t * data, size_t len) {
1744
+ WAIT_FOR_SLAVE_SELECT ();
1745
+
1746
+ int commandSize = 4 ;
1747
+ SpiDrv::sendCmd (BLE_WRITE, PARAM_NUMS_1);
1748
+
1749
+ SpiDrv::sendBuffer ((uint8_t *)data, len, LAST_PARAM);
1750
+ commandSize += len+2 ;
1751
+
1752
+ // pad to multiple of 4
1753
+ while (commandSize % 4 != 0 ) {
1754
+ SpiDrv::readChar ();
1755
+ commandSize++;
1756
+ }
1757
+
1758
+ SpiDrv::spiSlaveDeselect ();
1759
+ // Wait the reply elaboration
1760
+ SpiDrv::waitForSlaveReady ();
1761
+ SpiDrv::spiSlaveSelect ();
1762
+
1763
+ uint8_t res_len = 1 ;
1764
+ uint16_t res = 0 ;
1765
+ SpiDrv::waitResponseCmd (PREFERENCES_PUT, PARAM_NUMS_1, (uint8_t *)&res, &res_len);
1766
+ SpiDrv::spiSlaveDeselect ();
1767
+
1768
+ return res;
1769
+ }
1770
+
1636
1771
1637
1772
WiFiDrv wiFiDrv;
0 commit comments