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