@@ -113,7 +113,6 @@ void WiFiDrv::wifiDriverInit()
113113
114114void WiFiDrv::wifiDriverDeinit ()
115115{
116- SpiDrv::end ();
117116}
118117
119118int8_t WiFiDrv::wifiSetNetwork (const char * ssid, uint8_t ssid_len)
@@ -1663,5 +1662,141 @@ PreferenceType WiFiDrv::prefGetType(const char * key) {
16631662 return type;
16641663}
16651664
1665+ int WiFiDrv::bleBegin () {
1666+ WAIT_FOR_SLAVE_SELECT ();
1667+
1668+ SpiDrv::sendCmd (BLE_BEGIN, PARAM_NUMS_0);
1669+
1670+ SpiDrv::spiSlaveDeselect ();
1671+ // Wait the reply elaboration
1672+ SpiDrv::waitForSlaveReady ();
1673+ SpiDrv::spiSlaveSelect ();
1674+
1675+ uint8_t len = 1 ;
1676+ uint8_t result = 0 ;
1677+ SpiDrv::waitResponseCmd (BLE_BEGIN, PARAM_NUMS_1, (uint8_t *)&result, &len);
1678+ SpiDrv::spiSlaveDeselect ();
1679+
1680+ return result == 0 ;
1681+ }
1682+
1683+ void WiFiDrv::bleEnd () {
1684+ WAIT_FOR_SLAVE_SELECT ();
1685+
1686+ SpiDrv::sendCmd (BLE_END, PARAM_NUMS_0);
1687+
1688+ SpiDrv::spiSlaveDeselect ();
1689+ // Wait the reply elaboration
1690+ SpiDrv::waitForSlaveReady ();
1691+ SpiDrv::spiSlaveSelect ();
1692+
1693+ uint8_t len = 1 ;
1694+ uint8_t result = 0 ;
1695+ SpiDrv::waitResponseCmd (BLE_END, PARAM_NUMS_1, (uint8_t *)&result, &len);
1696+ SpiDrv::spiSlaveDeselect ();
1697+ }
1698+
1699+ int WiFiDrv::bleAvailable () {
1700+ WAIT_FOR_SLAVE_SELECT ();
1701+ uint16_t result = 0 ;
1702+
1703+ SpiDrv::sendCmd (BLE_AVAILABLE, PARAM_NUMS_0);
1704+
1705+ SpiDrv::spiSlaveDeselect ();
1706+ // Wait the reply elaboration
1707+ SpiDrv::waitForSlaveReady ();
1708+ SpiDrv::spiSlaveSelect ();
1709+
1710+ uint8_t len = 2 ;
1711+ SpiDrv::waitResponseCmd (BLE_AVAILABLE, PARAM_NUMS_1, (uint8_t *)&result, &len);
1712+ SpiDrv::spiSlaveDeselect ();
1713+
1714+ return result;
1715+ }
1716+
1717+ int WiFiDrv::bleRead (uint8_t data[], size_t length) {
1718+ WAIT_FOR_SLAVE_SELECT ();
1719+
1720+ SpiDrv::sendCmd (BLE_READ, PARAM_NUMS_1);
1721+
1722+ int commandSize = 7 ; // 4 for the normal command length + 3 for the parameter
1723+ uint16_t param = length; // TODO check length doesn't exceed 2^16
1724+ SpiDrv::sendParam ((uint8_t *)¶m, sizeof (param), LAST_PARAM);
1725+
1726+ // pad to multiple of 4
1727+ while (commandSize % 4 != 0 ) {
1728+ SpiDrv::readChar ();
1729+ commandSize++;
1730+ }
1731+
1732+ SpiDrv::spiSlaveDeselect ();
1733+ // Wait the reply elaboration
1734+ SpiDrv::waitForSlaveReady ();
1735+ SpiDrv::spiSlaveSelect ();
1736+
1737+ uint16_t res_len = 0 ;
1738+ SpiDrv::waitResponseData16 (BLE_READ, data, (uint16_t *)&res_len);
1739+
1740+ SpiDrv::spiSlaveDeselect ();
1741+
1742+ return res_len;
1743+ }
1744+
1745+ int WiFiDrv::blePeek (uint8_t data[], size_t length) {
1746+ WAIT_FOR_SLAVE_SELECT ();
1747+
1748+ SpiDrv::sendCmd (BLE_PEEK, PARAM_NUMS_1);
1749+
1750+ int commandSize = 7 ; // 4 for the normal command length + 3 for the parameter
1751+ uint16_t param = length; // TODO check length doesn't exceed 2^16
1752+ SpiDrv::sendParam ((uint8_t *)¶m, sizeof (param), LAST_PARAM);
1753+
1754+ // pad to multiple of 4
1755+ while (commandSize % 4 != 0 ) {
1756+ SpiDrv::readChar ();
1757+ commandSize++;
1758+ }
1759+
1760+ SpiDrv::spiSlaveDeselect ();
1761+ // Wait the reply elaboration
1762+ SpiDrv::waitForSlaveReady ();
1763+ SpiDrv::spiSlaveSelect ();
1764+
1765+ uint16_t res_len = 0 ;
1766+ SpiDrv::waitResponseData16 (BLE_READ, data, (uint16_t *)&res_len);
1767+
1768+ SpiDrv::spiSlaveDeselect ();
1769+
1770+ return res_len;
1771+ }
1772+
1773+ size_t WiFiDrv::bleWrite (const uint8_t * data, size_t len) {
1774+ WAIT_FOR_SLAVE_SELECT ();
1775+
1776+ int commandSize = 4 ;
1777+ SpiDrv::sendCmd (BLE_WRITE, PARAM_NUMS_1);
1778+
1779+ SpiDrv::sendBuffer ((uint8_t *)data, len, LAST_PARAM);
1780+ commandSize += len+2 ;
1781+
1782+ // pad to multiple of 4
1783+ while (commandSize % 4 != 0 ) {
1784+ SpiDrv::readChar ();
1785+ commandSize++;
1786+ }
1787+
1788+ SpiDrv::spiSlaveDeselect ();
1789+ // Wait the reply elaboration
1790+ SpiDrv::waitForSlaveReady ();
1791+ SpiDrv::spiSlaveSelect ();
1792+
1793+ uint8_t res_len = 1 ;
1794+ uint16_t res = 0 ;
1795+ SpiDrv::waitResponseCmd (BLE_WRITE, PARAM_NUMS_1, (uint8_t *)&res, &res_len);
1796+ SpiDrv::spiSlaveDeselect ();
1797+
1798+ return res;
1799+ }
1800+
16661801
16671802WiFiDrv wiFiDrv;
0 commit comments