Skip to content

Commit c59cbd4

Browse files
committed
Implement digitalRead API for Nano RPI2040 Connect board.
1 parent 544998b commit c59cbd4

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/utility/wifi_drv.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,34 @@ void WiFiDrv::pinMode(uint8_t pin, uint8_t mode)
10621062

10631063
PinStatus WiFiDrv::digitalRead(uint8_t pin)
10641064
{
1065-
#warning "This needs to be implemented!!!"
1065+
WAIT_FOR_SLAVE_SELECT();
1066+
// Send Command
1067+
SpiDrv::sendCmd(GET_DIGITAL_READ, PARAM_NUMS_1);
1068+
SpiDrv::sendParam((uint8_t*)&pin, 1, LAST_PARAM);
1069+
1070+
// pad to multiple of 4
1071+
SpiDrv::readChar();
1072+
SpiDrv::readChar();
1073+
1074+
SpiDrv::spiSlaveDeselect();
1075+
//Wait the reply elaboration
1076+
SpiDrv::waitForSlaveReady();
1077+
SpiDrv::spiSlaveSelect();
1078+
1079+
// Wait for reply
1080+
uint8_t _data = 0;
1081+
uint8_t _dataLen = 0;
1082+
if (!SpiDrv::waitResponseCmd(GET_DIGITAL_READ, PARAM_NUMS_1, &_data, &_dataLen))
1083+
{
1084+
WARN("error waitResponse");
1085+
_data = WL_FAILURE;
1086+
}
1087+
SpiDrv::spiSlaveDeselect();
1088+
1089+
if (_data == 1)
1090+
return HIGH;
1091+
else
1092+
return LOW;
10661093
}
10671094

10681095
void WiFiDrv::digitalWrite(uint8_t pin, uint8_t value)

src/utility/wifi_spi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ enum {
102102
SET_PIN_MODE = 0x50,
103103
SET_DIGITAL_WRITE = 0x51,
104104
SET_ANALOG_WRITE = 0x52,
105+
GET_DIGITAL_READ = 0x53,
105106

106107
// regular format commands
107108
WRITE_FILE = 0x60,

0 commit comments

Comments
 (0)