Skip to content

Commit

Permalink
Merge pull request #34 from ElectronicCats/I2Cdev_RP2040
Browse files Browse the repository at this point in the history
Fix I2C for RP2040 core
  • Loading branch information
sabas1080 authored Aug 5, 2022
2 parents 49d8e02 + 189e7a4 commit bce5870
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/LibraryBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,26 @@ jobs:
# You may add a suffix behind the fqbn with "|" to specify one board for e.g. different compile options like arduino:avr:uno|trace
#############################################################################################################
arduino-boards-fqbn:
- arduino:avr:uno
- arduino:avr:leonardo
- arduino:samd:nano_33_iot
- arduino:mbed:envie_m7
- esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
- rp2040:rp2040:generic

# Specify parameters for each board.
# Parameters can be: platform-url, examples-exclude and examples-build-properties
# With examples-exclude you may exclude specific examples for a board. Use a space separated list.
#############################################################################################################
include:
- arduino-boards-fqbn: arduino:avr:uno
sketches-exclude: MifareClassic_write_block,DetectTags,MifareClassic_read_block

- arduino-boards-fqbn: arduino:avr:leonardo

- arduino-boards-fqbn: arduino:samd:nano_33_iot

- arduino-boards-fqbn: arduino:mbed:envie_m7

- arduino-boards-fqbn: esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
platform-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json

- arduino-boards-fqbn: rp2040:rp2040:generic
platform-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

# Do not cancel all jobs / architectures if one job fails
fail-fast: false

Expand Down
43 changes: 34 additions & 9 deletions src/Electroniccats_PN7150.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,18 @@ bool Electroniccats_PN7150::hasMessage() const
uint8_t Electroniccats_PN7150::writeData(uint8_t txBuffer[], uint32_t txBufferLevel) const
{
uint32_t nmbrBytesWritten = 0;
Wire.beginTransmission((uint8_t)_I2Caddress);
nmbrBytesWritten = Wire.write(txBuffer, (int)(txBufferLevel));
Wire.beginTransmission((uint8_t)_I2Caddress); //configura transmision
nmbrBytesWritten = Wire.write(txBuffer, (size_t)(txBufferLevel)); //carga en buffer
#ifdef DEBUG2
Serial.println("[DEBUG] written bytes = 0x"+String(nmbrBytesWritten,HEX));
#endif
if (nmbrBytesWritten == txBufferLevel)
{
byte resultCode;
resultCode = Wire.endTransmission();
resultCode = Wire.endTransmission(); //envio de datos segun yo
#ifdef DEBUG2
Serial.println("[DEBUG] write data code = 0x"+String(resultCode,HEX));
#endif
return resultCode;
}
else
Expand All @@ -97,18 +103,34 @@ uint32_t Electroniccats_PN7150::readData(uint8_t rxBuffer[]) const
if (hasMessage())
{ // only try to read something if the PN7150 indicates it has something
bytesReceived = Wire.requestFrom(_I2Caddress, (uint8_t)3); // first reading the header, as this contains how long the payload will be


//Imprimir datos de bytes received, tratar de extraer con funcion read
//Leer e inyectar directo al buffer los siguientes 3
#ifdef DEBUG2
Serial.println("[DEBUG] bytesReceived = 0x"+String(bytesReceived,HEX));
#endif
rxBuffer[0] = Wire.read();
rxBuffer[1] = Wire.read();
rxBuffer[2] = Wire.read();
#ifdef DEBUG2
for(int i=0;i<3;i++){
Serial.println("[DEBUG] Byte["+String(i)+"] = 0x"+String(rxBuffer[i],HEX));
}
#endif
uint8_t payloadLength = rxBuffer[2];
if (payloadLength > 0)
{
bytesReceived += Wire.requestFrom(_I2Caddress, (uint8_t)payloadLength); // then reading the payload, if any
#ifdef DEBUG2
Serial.println("[DEBUG] payload bytes = 0x"+String(bytesReceived-3,HEX));
#endif
uint32_t index = 3;
while (index < bytesReceived)
{
rxBuffer[index] = Wire.read();
#ifdef DEBUG2
Serial.println("[DEBUG] payload["+String(index)+"] = 0x"+String(rxBuffer[index],HEX));
#endif
index++;
}
index = 0;
Expand Down Expand Up @@ -209,12 +231,12 @@ uint8_t Electroniccats_PN7150::connectNCI()
gNfcController_fw_version[0] = rxBuffer[17 + rxBuffer[8]]; //0xROM_CODE_V
gNfcController_fw_version[1] = rxBuffer[18 + rxBuffer[8]]; //0xFW_MAJOR_NO
gNfcController_fw_version[2] = rxBuffer[19 + rxBuffer[8]]; //0xFW_MINOR_NO
#ifdef SerialUSB

Serial.println("0xROM_CODE_V: " + String(gNfcController_fw_version[0], HEX));
Serial.println("FW_MAJOR_NO: " + String(gNfcController_fw_version[1], HEX));
Serial.println("0xFW_MINOR_NO: " + String(gNfcController_fw_version[2], HEX));
Serial.println("gNfcController_generation: " + String(gNfcController_generation, HEX));
#endif

return SUCCESS;
}

Expand Down Expand Up @@ -439,18 +461,21 @@ bool Electroniccats_PN7150::CardModeSend(unsigned char *pData, unsigned char Dat

bool Electroniccats_PN7150::CardModeReceive(unsigned char *pData, unsigned char *pDataSize)
{
#ifdef DEBUG2
Serial.println("[DEBUG] cardModeReceive exec");
#endif
bool status = NFC_ERROR;
uint8_t Ans[MAX_NCI_FRAME_SIZE];

(void)writeData(Ans, sizeof(Ans));
(void)writeData(Ans, 255);
getMessage(2000);

/* Is data packet ? */
if ((rxBuffer[0] == 0x00) && (rxBuffer[1] == 0x00))
{
#ifdef SerialUSB

Serial.println(rxBuffer[2]);
#endif

*pDataSize = rxBuffer[2];
memcpy(pData, &rxBuffer[3], *pDataSize);
status = NFC_SUCCESS;
Expand Down

0 comments on commit bce5870

Please sign in to comment.