From 4e35f412e6641502bff19ce6d6dcdd2692890f6a Mon Sep 17 00:00:00 2001 From: TD-er Date: Fri, 2 Jul 2021 09:38:20 +0200 Subject: [PATCH] [Libs] Don't use "byte" as type anymore --- lib/AM2320/AM2320.cpp | 4 +- lib/Adafruit_BME680/Adafruit_BME680.cpp | 2 +- lib/Blynk/src_off/Adapters/BlynkEthernet.h | 18 +- lib/Blynk/src_off/BlynkSimpleEthernetSSL.h | 2 +- lib/ESPEasy_ESP8266Ping/src/ESP8266Ping.h | 6 +- .../src/ESP8266Ping.impl.h | 10 +- lib/HT16K33/HT16K33.cpp | 12 +- lib/HT16K33/HT16K33.h | 2 +- lib/HeatpumpIR/HitachiHeatpumpIR.cpp | 2 +- lib/HeatpumpIR/IRSenderPWM.cpp | 2 +- lib/HeatpumpIR/R51MHeatpumpIR.cpp | 2 +- lib/I2Cdevlib/I2Cdev.cpp | 22 +- lib/I2Cdevlib/I2Cdev.h | 10 +- .../examples/IRMQTTServer/IRMQTTServer.h | 4 +- lib/MFRC522/MFRC522.cpp | 374 +++++++++--------- lib/MFRC522/MFRC522.h | 122 +++--- lib/MechInputs/QEIx4.cpp | 6 +- .../TinyGPS++.cpp | 2 +- lib/RN2483-Arduino-Library/src/rn2xx3.cpp | 4 +- lib/RN2483-Arduino-Library/src/rn2xx3.h | 2 +- .../src/rn2xx3_helper.cpp | 2 +- .../src/rn2xx3_helper.h | 2 +- lib/Regexp/src/Regexp.cpp | 3 +- lib/SerialDevices/SensorSerialBuffer.cpp | 8 +- lib/SerialDevices/SensorSerialBuffer.h | 12 +- lib/SerialDevices/jkSDS011.cpp | 12 +- lib/SerialDevices/jkSDS011.h | 2 +- lib/SparkFun_VL53L1X/src/vl53l1x_class.cpp | 2 +- lib/TinyGPSPlus-1.0.2/src/TinyGPS++.cpp | 8 +- lib/esp8266-oled-ssd1306/OLEDDisplay.cpp | 16 +- lib/esp8266-oled-ssd1306/OLEDDisplay.h | 4 +- lib/esp8266-oled-ssd1306/OLEDDisplayUi.cpp | 2 +- lib/esp8266-oled-ssd1306/SH1106Brzo.h | 2 +- lib/esp8266-oled-ssd1306/SH1106Wire.h | 2 +- lib/esp8266-oled-ssd1306/SSD1306Brzo.h | 2 +- lib/esp8266-oled-ssd1306/SSD1306Wire.h | 2 +- 36 files changed, 344 insertions(+), 345 deletions(-) diff --git a/lib/AM2320/AM2320.cpp b/lib/AM2320/AM2320.cpp index 1e2016421..dad106c89 100644 --- a/lib/AM2320/AM2320.cpp +++ b/lib/AM2320/AM2320.cpp @@ -4,7 +4,7 @@ // AM2321 Temperature & Humidity Sensor library for Arduino // Сделана Тимофеевым Е.Н. из AM2320-master -unsigned int CRC16(byte *ptr, byte length) +unsigned int CRC16(uint8_t *ptr, uint8_t length) { unsigned int crc = 0xFFFF; uint8_t s = 0x00; @@ -27,7 +27,7 @@ AM2320::AM2320() int AM2320::Read() { - byte buf[8]; + uint8_t buf[8]; for(int s = 0; s < 8; s++) buf[s] = 0x00; Wire.beginTransmission(AM2320_address); diff --git a/lib/Adafruit_BME680/Adafruit_BME680.cpp b/lib/Adafruit_BME680/Adafruit_BME680.cpp index 29526ec18..faa52336d 100644 --- a/lib/Adafruit_BME680/Adafruit_BME680.cpp +++ b/lib/Adafruit_BME680/Adafruit_BME680.cpp @@ -559,7 +559,7 @@ int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, _wire->beginTransmission((uint8_t)dev_id); _wire->write((uint8_t)reg_addr); _wire->endTransmission(); - if (len != _wire->requestFrom((uint8_t)dev_id, (byte)len)) { + if (len != _wire->requestFrom((uint8_t)dev_id, (uint8_t)len)) { #ifdef BME680_DEBUG Serial.print("Failed to read "); Serial.print(len); diff --git a/lib/Blynk/src_off/Adapters/BlynkEthernet.h b/lib/Blynk/src_off/Adapters/BlynkEthernet.h index 51bdbea17..0e0da4ccf 100644 --- a/lib/Blynk/src_off/Adapters/BlynkEthernet.h +++ b/lib/Blynk/src_off/Adapters/BlynkEthernet.h @@ -54,7 +54,7 @@ public: void begin( const char* auth, const char* domain = BLYNK_DEFAULT_DOMAIN, uint16_t port = BLYNK_SERVER_PORT, - const byte mac[] = NULL) + const uint8_t mac[] = NULL) { BLYNK_LOG1(BLYNK_F("Getting IP...")); if (!Ethernet.begin(SelectMacAddress(auth, mac))) { @@ -75,7 +75,7 @@ public: uint16_t port, IPAddress local, IPAddress dns, - const byte mac[] = NULL) + const uint8_t mac[] = NULL) { BLYNK_LOG1(BLYNK_F("Using static IP")); Ethernet.begin(SelectMacAddress(auth, mac), local, dns); @@ -96,7 +96,7 @@ public: IPAddress dns, IPAddress gateway, IPAddress subnet, - const byte mac[] = NULL) + const uint8_t mac[] = NULL) { BLYNK_LOG1(BLYNK_F("Using static IP")); Ethernet.begin(SelectMacAddress(auth, mac), local, dns, gateway, subnet); @@ -113,7 +113,7 @@ public: void begin( const char* auth, IPAddress addr, uint16_t port = BLYNK_SERVER_PORT, - const byte mac[] = NULL) + const uint8_t mac[] = NULL) { BLYNK_LOG1(BLYNK_F("Getting IP...")); if (!Ethernet.begin(SelectMacAddress(auth, mac))) { @@ -133,7 +133,7 @@ public: IPAddress addr, uint16_t port, IPAddress local, - const byte mac[] = NULL) + const uint8_t mac[] = NULL) { BLYNK_LOG1(BLYNK_F("Using static IP")); Ethernet.begin(SelectMacAddress(auth, mac), local); @@ -154,7 +154,7 @@ public: IPAddress dns, IPAddress gateway, IPAddress subnet, - const byte mac[] = NULL) + const uint8_t mac[] = NULL) { BLYNK_LOG1(BLYNK_F("Using static IP")); Ethernet.begin(SelectMacAddress(auth, mac), local, dns, gateway, subnet); @@ -169,10 +169,10 @@ public: private: - byte* SelectMacAddress(const char* token, const byte mac[]) + uint8_t* SelectMacAddress(const char* token, const uint8_t mac[]) { if (mac != NULL) { - return (byte*)mac; + return (uint8_t*)mac; } macAddress[0] = 0xFE; @@ -198,7 +198,7 @@ private: } private: - byte macAddress[6]; + uint8_t macAddress[6]; }; diff --git a/lib/Blynk/src_off/BlynkSimpleEthernetSSL.h b/lib/Blynk/src_off/BlynkSimpleEthernetSSL.h index 47f8fa81b..b4eeb2863 100644 --- a/lib/Blynk/src_off/BlynkSimpleEthernetSSL.h +++ b/lib/Blynk/src_off/BlynkSimpleEthernetSSL.h @@ -37,7 +37,7 @@ unsigned long ntpGetTime() { static const char timeServer[] = "time.nist.gov"; const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message - byte packetBuffer[NTP_PACKET_SIZE]; + uint8_t packetBuffer[NTP_PACKET_SIZE]; EthernetUDP Udp; Udp.begin(8888); diff --git a/lib/ESPEasy_ESP8266Ping/src/ESP8266Ping.h b/lib/ESPEasy_ESP8266Ping/src/ESP8266Ping.h index 23e2aeaf2..c309ae6fc 100644 --- a/lib/ESPEasy_ESP8266Ping/src/ESP8266Ping.h +++ b/lib/ESPEasy_ESP8266Ping/src/ESP8266Ping.h @@ -38,8 +38,8 @@ class PingClass { public: PingClass(); - bool ping(IPAddress dest, byte count = 5); - bool ping(const char* host, byte count = 5); + bool ping(IPAddress dest, uint8_t count = 5); + bool ping(const char* host, uint8_t count = 5); int averageTime(); @@ -50,7 +50,7 @@ class PingClass { IPAddress _dest; ping_option _options; - static byte _expected_count, _errors, _success; + static uint8_t _expected_count, _errors, _success; static int _avg_time; }; diff --git a/lib/ESPEasy_ESP8266Ping/src/ESP8266Ping.impl.h b/lib/ESPEasy_ESP8266Ping/src/ESP8266Ping.impl.h index 6a550a1ba..dbc50ee25 100644 --- a/lib/ESPEasy_ESP8266Ping/src/ESP8266Ping.impl.h +++ b/lib/ESPEasy_ESP8266Ping/src/ESP8266Ping.impl.h @@ -23,7 +23,7 @@ extern "C" void esp_yield(); PingClass::PingClass() {} -bool PingClass::ping(IPAddress dest, byte count) { +bool PingClass::ping(IPAddress dest, uint8_t count) { _expected_count = count; _errors = 0; _success = 0; @@ -52,7 +52,7 @@ bool PingClass::ping(IPAddress dest, byte count) { return (_success > 0); } -bool PingClass::ping(const char* host, byte count) { +bool PingClass::ping(const char* host, uint8_t count) { IPAddress remote_addr; if (WiFi.hostByName(host, remote_addr)) @@ -106,7 +106,7 @@ void PingClass::_ping_recv_cb(void *opt, void *resp) { } } -byte PingClass::_expected_count = 0; -byte PingClass::_errors = 0; -byte PingClass::_success = 0; +uint8_t PingClass::_expected_count = 0; +uint8_t PingClass::_errors = 0; +uint8_t PingClass::_success = 0; int PingClass::_avg_time = 0; diff --git a/lib/HT16K33/HT16K33.cpp b/lib/HT16K33/HT16K33.cpp index c98f17aa0..5cd7de688 100644 --- a/lib/HT16K33/HT16K33.cpp +++ b/lib/HT16K33/HT16K33.cpp @@ -40,7 +40,7 @@ void CHT16K33::TransmitRowBuffer(void) // Display Memory Wire.beginTransmission(_addr); Wire.write(0); // start data at address 0 - for (byte i=0; i<8; i++) + for (uint8_t i=0; i<8; i++) { Wire.write(_rowBuffer[i] & 0xFF); Wire.write(_rowBuffer[i] >> 8); @@ -50,7 +50,7 @@ void CHT16K33::TransmitRowBuffer(void) void CHT16K33::ClearRowBuffer(void) { - for (byte i=0; i<8; i++) + for (uint8_t i=0; i<8; i++) _rowBuffer[i] = 0; }; @@ -129,7 +129,7 @@ uint8_t CHT16K33::ReadKeys(void) Wire.requestFrom(_addr, (uint8_t)6); if (Wire.available() == 6) { - for (byte i=0; i<3; i++) + for (uint8_t i=0; i<3; i++) { _keyBuffer[i] = Wire.read() | (Wire.read() << 8); } @@ -137,10 +137,10 @@ uint8_t CHT16K33::ReadKeys(void) // Wire.endTransmission(); } - for (byte i=0; i<3; i++) + for (uint8_t i=0; i<3; i++) { - byte mask = 1; - for (byte k=0; k<12; k++) + uint8_t mask = 1; + for (uint8_t k=0; k<12; k++) { if (_keyBuffer[i] & mask) { diff --git a/lib/HT16K33/HT16K33.h b/lib/HT16K33/HT16K33.h index 00ca8a991..d3e66b431 100644 --- a/lib/HT16K33/HT16K33.h +++ b/lib/HT16K33/HT16K33.h @@ -26,7 +26,7 @@ protected: uint8_t _addr; uint16_t _rowBuffer[8]; uint16_t _keyBuffer[3]; - byte _keydown; + uint8_t _keydown; static const uint8_t _digits[16]; }; diff --git a/lib/HeatpumpIR/HitachiHeatpumpIR.cpp b/lib/HeatpumpIR/HitachiHeatpumpIR.cpp index ad5fd40f4..33b59838a 100644 --- a/lib/HeatpumpIR/HitachiHeatpumpIR.cpp +++ b/lib/HeatpumpIR/HitachiHeatpumpIR.cpp @@ -125,7 +125,7 @@ void HitachiHeatpumpIR::sendHitachi(IRSender& IR, uint8_t powerMode, uint8_t ope //Checksum calculation int checksum = 1086; - for (byte i = 0; i < 27; i++) { + for (uint8_t i = 0; i < 27; i++) { checksum -= hitachiTemplate[i]; } hitachiTemplate[27] = checksum; diff --git a/lib/HeatpumpIR/IRSenderPWM.cpp b/lib/HeatpumpIR/IRSenderPWM.cpp index 5274ced0a..d46cff69d 100644 --- a/lib/HeatpumpIR/IRSenderPWM.cpp +++ b/lib/HeatpumpIR/IRSenderPWM.cpp @@ -14,7 +14,7 @@ #if defined(__SAM3X8E__) || defined(__SAM3X8H__) // Arduino Due uint32_t IR_USE_PWM_PINMASK; - byte IR_USE_PWM_CH; + uint8_t IR_USE_PWM_CH; #endif IRSenderPWM::IRSenderPWM(uint8_t pin) : IRSender(pin) diff --git a/lib/HeatpumpIR/R51MHeatpumpIR.cpp b/lib/HeatpumpIR/R51MHeatpumpIR.cpp index 0be76bd3e..945de53d4 100644 --- a/lib/HeatpumpIR/R51MHeatpumpIR.cpp +++ b/lib/HeatpumpIR/R51MHeatpumpIR.cpp @@ -12,7 +12,7 @@ R51MHeatpumpIR::R51MHeatpumpIR() : HeatpumpIR() void R51MHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd) { - const static byte tempMap [] PROGMEM = {0,1,3,2,6,7,5,4,12,13,9,8,10,11 }; + const static uint8_t tempMap [] PROGMEM = {0,1,3,2,6,7,5,4,12,13,9,8,10,11 }; // Sensible defaults for the heat pump mode uint8_t data[] = { 0xB2, 0x0F, 0x00 }; // The actual data is in this part diff --git a/lib/I2Cdevlib/I2Cdev.cpp b/lib/I2Cdevlib/I2Cdev.cpp index e5e9d5406..21d4e1887 100644 --- a/lib/I2Cdevlib/I2Cdev.cpp +++ b/lib/I2Cdevlib/I2Cdev.cpp @@ -746,8 +746,8 @@ uint16_t I2Cdev::readTimeout = I2CDEV_DEFAULT_READ_TIMEOUT; // added by Jeff Rowberg 2013-05-07: // Arduino Wire-style "beginTransmission" function // (takes 7-bit device address like the Wire method, NOT 8-bit: 0x68, not 0xD0/0xD1) - byte Fastwire::beginTransmission(byte device) { - byte twst, retry; + uint8_t Fastwire::beginTransmission(uint8_t device) { + uint8_t twst, retry; retry = 2; do { TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO) | (1 << TWSTA); @@ -766,8 +766,8 @@ uint16_t I2Cdev::readTimeout = I2CDEV_DEFAULT_READ_TIMEOUT; return 0; } - byte Fastwire::writeBuf(byte device, byte address, byte *data, byte num) { - byte twst, retry; + uint8_t Fastwire::writeBuf(uint8_t device, uint8_t address, uint8_t *data, uint8_t num) { + uint8_t twst, retry; retry = 2; do { @@ -793,7 +793,7 @@ uint16_t I2Cdev::readTimeout = I2CDEV_DEFAULT_READ_TIMEOUT; twst = TWSR & 0xF8; if (twst != TW_MT_DATA_ACK) return 6; - for (byte i = 0; i < num; i++) { + for (uint8_t i = 0; i < num; i++) { //Serial.print(data[i], HEX); //Serial.print(" "); TWDR = data[i]; // send data to the previously addressed device @@ -807,8 +807,8 @@ uint16_t I2Cdev::readTimeout = I2CDEV_DEFAULT_READ_TIMEOUT; return 0; } - byte Fastwire::write(byte value) { - byte twst; + uint8_t Fastwire::write(uint8_t value) { + uint8_t twst; //Serial.println(value, HEX); TWDR = value; // send data TWCR = (1 << TWINT) | (1 << TWEN); @@ -818,8 +818,8 @@ uint16_t I2Cdev::readTimeout = I2CDEV_DEFAULT_READ_TIMEOUT; return 0; } - byte Fastwire::readBuf(byte device, byte address, byte *data, byte num) { - byte twst, retry; + uint8_t Fastwire::readBuf(uint8_t device, uint8_t address, uint8_t *data, uint8_t num) { + uint8_t twst, retry; retry = 2; do { @@ -885,7 +885,7 @@ uint16_t I2Cdev::readTimeout = I2CDEV_DEFAULT_READ_TIMEOUT; TWCR = 0; } - byte Fastwire::stop() { + uint8_t Fastwire::stop() { TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO); if (!waitInt()) return 1; return 0; @@ -1000,7 +1000,7 @@ uint16_t I2Cdev::readTimeout = I2CDEV_DEFAULT_READ_TIMEOUT; twi_Write_Vars *ptwv = 0; static void (*fNextInterruptFunction)(void) = 0; - void twi_Finish(byte bRetVal) { + void twi_Finish(uint8_t bRetVal) { if (ptwv) { free(ptwv); ptwv = 0; diff --git a/lib/I2Cdevlib/I2Cdev.h b/lib/I2Cdevlib/I2Cdev.h index 4c0a2e7a2..007281de6 100644 --- a/lib/I2Cdevlib/I2Cdev.h +++ b/lib/I2Cdevlib/I2Cdev.h @@ -156,12 +156,12 @@ class I2Cdev { public: static void setup(int khz, boolean pullup); - static byte beginTransmission(byte device); - static byte write(byte value); - static byte writeBuf(byte device, byte address, byte *data, byte num); - static byte readBuf(byte device, byte address, byte *data, byte num); + static uint8_t beginTransmission(uint8_t device); + static uint8_t write(uint8_t value); + static uint8_t writeBuf(uint8_t device, uint8_t address, uint8_t *data, uint8_t num); + static uint8_t readBuf(uint8_t device, uint8_t address, uint8_t *data, uint8_t num); static void reset(); - static byte stop(); + static uint8_t stop(); }; #endif diff --git a/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.h b/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.h index e1094aae0..a270f669a 100644 --- a/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.h +++ b/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.h @@ -362,7 +362,7 @@ const char* kMqttTopics[] = { KEY_JSON}; // KEY_JSON needs to be the last one. -void mqttCallback(char* topic, byte* payload, unsigned int length); +void mqttCallback(char* topic, uint8_t* payload, unsigned int length); String listOfCommandTopics(void); void handleSendMqttDiscovery(void); void subscribing(const String topic_name); @@ -371,7 +371,7 @@ void mqttLog(const char* str); bool mountSpiffs(void); bool reconnect(void); void receivingMQTT(String const topic_name, String const callback_str); -void callback(char* topic, byte* payload, unsigned int length); +void callback(char* topic, uint8_t* payload, unsigned int length); void sendMQTTDiscovery(const char *topic); void doBroadcast(TimerMs *timer, const uint32_t interval, IRac *climates[], const bool retain, diff --git a/lib/MFRC522/MFRC522.cpp b/lib/MFRC522/MFRC522.cpp index a4f70e6dd..e06ae4b97 100644 --- a/lib/MFRC522/MFRC522.cpp +++ b/lib/MFRC522/MFRC522.cpp @@ -20,7 +20,7 @@ MFRC522::MFRC522(): MFRC522(SS, UINT8_MAX) { // SS is defined in pins_arduino.h, * Constructor. * Prepares the output pins. */ -MFRC522::MFRC522( byte resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low). If there is no connection from the CPU to NRSTPD, set this to UINT8_MAX. In this case, only soft reset will be used in PCD_Init(). +MFRC522::MFRC522( uint8_t resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low). If there is no connection from the CPU to NRSTPD, set this to UINT8_MAX. In this case, only soft reset will be used in PCD_Init(). ): MFRC522(SS, resetPowerDownPin) { // SS is defined in pins_arduino.h } // End constructor @@ -28,8 +28,8 @@ MFRC522::MFRC522( byte resetPowerDownPin ///< Arduino pin connected to MFRC522's * Constructor. * Prepares the output pins. */ -MFRC522::MFRC522( byte chipSelectPin, ///< Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low) - byte resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low). If there is no connection from the CPU to NRSTPD, set this to UINT8_MAX. In this case, only soft reset will be used in PCD_Init(). +MFRC522::MFRC522( uint8_t chipSelectPin, ///< Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low) + uint8_t resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low). If there is no connection from the CPU to NRSTPD, set this to UINT8_MAX. In this case, only soft reset will be used in PCD_Init(). ) { _chipSelectPin = chipSelectPin; _resetPowerDownPin = resetPowerDownPin; @@ -44,7 +44,7 @@ MFRC522::MFRC522( byte chipSelectPin, ///< Arduino pin connected to MFRC522's S * The interface is described in the datasheet section 8.1.2. */ void MFRC522::PCD_WriteRegister( PCD_Register reg, ///< The register to write to. One of the PCD_Register enums. - byte value ///< The value to write. + uint8_t value ///< The value to write. ) { SPI.beginTransaction(SPISettings(MFRC522_SPICLOCK, MSBFIRST, SPI_MODE0)); // Set the settings to work with SPI bus digitalWrite(_chipSelectPin, LOW); // Select slave @@ -59,13 +59,13 @@ void MFRC522::PCD_WriteRegister( PCD_Register reg, ///< The register to write to * The interface is described in the datasheet section 8.1.2. */ void MFRC522::PCD_WriteRegister( PCD_Register reg, ///< The register to write to. One of the PCD_Register enums. - byte count, ///< The number of bytes to write to the register - byte *values ///< The values to write. Byte array. + uint8_t count, ///< The number of bytes to write to the register + uint8_t *values ///< The values to write. Byte array. ) { SPI.beginTransaction(SPISettings(MFRC522_SPICLOCK, MSBFIRST, SPI_MODE0)); // Set the settings to work with SPI bus digitalWrite(_chipSelectPin, LOW); // Select slave SPI.transfer(reg); // MSB == 0 is for writing. LSB is not used in address. Datasheet section 8.1.2.3. - for (byte index = 0; index < count; index++) { + for (uint8_t index = 0; index < count; index++) { SPI.transfer(values[index]); } digitalWrite(_chipSelectPin, HIGH); // Release slave again @@ -76,9 +76,9 @@ void MFRC522::PCD_WriteRegister( PCD_Register reg, ///< The register to write to * Reads a byte from the specified register in the MFRC522 chip. * The interface is described in the datasheet section 8.1.2. */ -byte MFRC522::PCD_ReadRegister( PCD_Register reg ///< The register to read from. One of the PCD_Register enums. +uint8_t MFRC522::PCD_ReadRegister( PCD_Register reg ///< The register to read from. One of the PCD_Register enums. ) { - byte value; + uint8_t value; SPI.beginTransaction(SPISettings(MFRC522_SPICLOCK, MSBFIRST, SPI_MODE0)); // Set the settings to work with SPI bus digitalWrite(_chipSelectPin, LOW); // Select slave SPI.transfer(0x80 | reg); // MSB == 1 is for reading. LSB is not used in address. Datasheet section 8.1.2.3. @@ -93,25 +93,25 @@ byte MFRC522::PCD_ReadRegister( PCD_Register reg ///< The register to read from. * The interface is described in the datasheet section 8.1.2. */ void MFRC522::PCD_ReadRegister( PCD_Register reg, ///< The register to read from. One of the PCD_Register enums. - byte count, ///< The number of bytes to read - byte *values, ///< Byte array to store the values in. - byte rxAlign ///< Only bit positions rxAlign..7 in values[0] are updated. + uint8_t count, ///< The number of bytes to read + uint8_t *values, ///< Byte array to store the values in. + uint8_t rxAlign ///< Only bit positions rxAlign..7 in values[0] are updated. ) { if (count == 0) { return; } //Serial.print(F("Reading ")); Serial.print(count); Serial.println(F(" bytes from register.")); - byte address = 0x80 | reg; // MSB == 1 is for reading. LSB is not used in address. Datasheet section 8.1.2.3. - byte index = 0; // Index in values array. + uint8_t address = 0x80 | reg; // MSB == 1 is for reading. LSB is not used in address. Datasheet section 8.1.2.3. + uint8_t index = 0; // Index in values array. SPI.beginTransaction(SPISettings(MFRC522_SPICLOCK, MSBFIRST, SPI_MODE0)); // Set the settings to work with SPI bus digitalWrite(_chipSelectPin, LOW); // Select slave count--; // One read is performed outside of the loop SPI.transfer(address); // Tell MFRC522 which address we want to read if (rxAlign) { // Only update bit positions rxAlign..7 in values[0] // Create bit mask for bit positions rxAlign..7 - byte mask = (0xFF << rxAlign) & 0xFF; + uint8_t mask = (0xFF << rxAlign) & 0xFF; // Read value and tell that we want to read the same address again. - byte value = SPI.transfer(address); + uint8_t value = SPI.transfer(address); // Apply mask to both current value of values[0] and the new data in value. values[0] = (values[0] & ~mask) | (value & mask); index++; @@ -129,9 +129,9 @@ void MFRC522::PCD_ReadRegister( PCD_Register reg, ///< The register to read from * Sets the bits given in mask in register reg. */ void MFRC522::PCD_SetRegisterBitMask( PCD_Register reg, ///< The register to update. One of the PCD_Register enums. - byte mask ///< The bits to set. + uint8_t mask ///< The bits to set. ) { - byte tmp; + uint8_t tmp; tmp = PCD_ReadRegister(reg); PCD_WriteRegister(reg, tmp | mask); // set bit mask } // End PCD_SetRegisterBitMask() @@ -140,9 +140,9 @@ void MFRC522::PCD_SetRegisterBitMask( PCD_Register reg, ///< The register to upd * Clears the bits given in mask from register reg. */ void MFRC522::PCD_ClearRegisterBitMask( PCD_Register reg, ///< The register to update. One of the PCD_Register enums. - byte mask ///< The bits to clear. + uint8_t mask ///< The bits to clear. ) { - byte tmp; + uint8_t tmp; tmp = PCD_ReadRegister(reg); PCD_WriteRegister(reg, tmp & (~mask)); // clear bit mask } // End PCD_ClearRegisterBitMask() @@ -153,9 +153,9 @@ void MFRC522::PCD_ClearRegisterBitMask( PCD_Register reg, ///< The register to u * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::PCD_CalculateCRC( byte *data, ///< In: Pointer to the data to transfer to the FIFO for CRC calculation. - byte length, ///< In: The number of bytes to transfer. - byte *result ///< Out: Pointer to result buffer. Result is written to result[0..1], low byte first. +MFRC522::StatusCode MFRC522::PCD_CalculateCRC( uint8_t *data, ///< In: Pointer to the data to transfer to the FIFO for CRC calculation. + uint8_t length, ///< In: The number of bytes to transfer. + uint8_t *result ///< Out: Pointer to result buffer. Result is written to result[0..1], low uint8_t first. ) { PCD_WriteRegister(CommandReg, PCD_Idle); // Stop any active command. PCD_WriteRegister(DivIrqReg, 0x04); // Clear the CRCIRq interrupt request bit @@ -169,7 +169,7 @@ MFRC522::StatusCode MFRC522::PCD_CalculateCRC( byte *data, ///< In: Pointer to // Wait for the CRC calculation to complete. Each iteration of the while-loop takes 17.73us. for (uint16_t i = 5000; i > 0; i--) { // DivIrqReg[7..0] bits are: Set2 reserved reserved MfinActIRq reserved CRCIRq reserved reserved - byte n = PCD_ReadRegister(DivIrqReg); + uint8_t n = PCD_ReadRegister(DivIrqReg); if (n & 0x04) { // CRCIRq bit set - calculation done PCD_WriteRegister(CommandReg, PCD_Idle); // Stop calculating CRC for new content in the FIFO. // Transfer the result from the registers to the result buffer @@ -239,7 +239,7 @@ void MFRC522::PCD_Init() { /** * Initializes the MFRC522 chip. */ -void MFRC522::PCD_Init( byte resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low) +void MFRC522::PCD_Init( uint8_t resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low) ) { PCD_Init(SS, resetPowerDownPin); // SS is defined in pins_arduino.h } // End PCD_Init() @@ -247,8 +247,8 @@ void MFRC522::PCD_Init( byte resetPowerDownPin ///< Arduino pin connected to MFR /** * Initializes the MFRC522 chip. */ -void MFRC522::PCD_Init( byte chipSelectPin, ///< Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low) - byte resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low) +void MFRC522::PCD_Init( uint8_t chipSelectPin, ///< Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low) + uint8_t resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low) ) { _chipSelectPin = chipSelectPin; _resetPowerDownPin = resetPowerDownPin; @@ -276,7 +276,7 @@ void MFRC522::PCD_Reset() { * After a reset these pins are disabled. */ void MFRC522::PCD_AntennaOn() { - byte value = PCD_ReadRegister(TxControlReg); + uint8_t value = PCD_ReadRegister(TxControlReg); if ((value & 0x03) != 0x03) { PCD_WriteRegister(TxControlReg, value | 0x03); } @@ -296,7 +296,7 @@ void MFRC522::PCD_AntennaOff() { * * @return Value of the RxGain, scrubbed to the 3 bits used. */ -byte MFRC522::PCD_GetAntennaGain() { +uint8_t MFRC522::PCD_GetAntennaGain() { return PCD_ReadRegister(RFCfgReg) & (0x07<<4); } // End PCD_GetAntennaGain() @@ -305,7 +305,7 @@ byte MFRC522::PCD_GetAntennaGain() { * See 9.3.3.6 / table 98 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf * NOTE: Given mask is scrubbed with (0x07<<4)=01110000b as RCFfgReg may use reserved bits. */ -void MFRC522::PCD_SetAntennaGain(byte mask) { +void MFRC522::PCD_SetAntennaGain(uint8_t mask) { if (PCD_GetAntennaGain() != mask) { // only bother if there is a change PCD_ClearRegisterBitMask(RFCfgReg, (0x07<<4)); // clear needed to allow 000 pattern PCD_SetRegisterBitMask(RFCfgReg, mask & (0x07<<4)); // only set RxGain[2:0] bits @@ -324,7 +324,7 @@ bool MFRC522::PCD_PerformSelfTest() { PCD_Reset(); // 2. Clear the internal buffer by writing 25 bytes of 00h - byte ZEROES[25] = {0x00}; + uint8_t ZEROES[25] = {0x00}; PCD_WriteRegister(FIFOLevelReg, 0x80); // flush the FIFO buffer PCD_WriteRegister(FIFODataReg, 25, ZEROES); // write 25 bytes of 00h to FIFO PCD_WriteRegister(CommandReg, PCD_Mem); // transfer to internal buffer @@ -339,7 +339,7 @@ bool MFRC522::PCD_PerformSelfTest() { PCD_WriteRegister(CommandReg, PCD_CalcCRC); // 6. Wait for self-test to complete - byte n; + uint8_t n; for (uint8_t i = 0; i < 0xFF; i++) { // The datasheet does not specify exact completion condition except // that FIFO buffer should contain 64 bytes. @@ -356,7 +356,7 @@ bool MFRC522::PCD_PerformSelfTest() { PCD_WriteRegister(CommandReg, PCD_Idle); // Stop calculating CRC for new content in the FIFO. // 7. Read out resulting 64 bytes from the FIFO buffer. - byte result[64]; + uint8_t result[64]; PCD_ReadRegister(FIFODataReg, 64, result, 0); // Auto self-test done @@ -364,10 +364,10 @@ bool MFRC522::PCD_PerformSelfTest() { PCD_WriteRegister(AutoTestReg, 0x00); // Determine firmware version (see section 9.3.4.8 in spec) - byte version = PCD_ReadRegister(VersionReg); + uint8_t version = PCD_ReadRegister(VersionReg); // Pick the appropriate reference values - const byte *reference; + const uint8_t *reference; switch (version) { case 0x88: // Fudan Semiconductor FM17522 clone reference = FM17522_firmware_reference; @@ -405,13 +405,13 @@ bool MFRC522::PCD_PerformSelfTest() { //For more details about power control, refer to the datasheet - page 33 (8.6) void MFRC522::PCD_SoftPowerDown(){//Note : Only soft power down mode is available throught software - byte val = PCD_ReadRegister(CommandReg); // Read state of the command register + uint8_t val = PCD_ReadRegister(CommandReg); // Read state of the command register val |= (1<<4);// set PowerDown bit ( bit 4 ) to 1 PCD_WriteRegister(CommandReg, val);//write new value to the command register } void MFRC522::PCD_SoftPowerUp(){ - byte val = PCD_ReadRegister(CommandReg); // Read state of the command register + uint8_t val = PCD_ReadRegister(CommandReg); // Read state of the command register val &= ~(1<<4);// set PowerDown bit ( bit 4 ) to 0 PCD_WriteRegister(CommandReg, val);//write new value to the command register // wait until PowerDown bit is cleared (this indicates end of wake up procedure) @@ -435,15 +435,15 @@ void MFRC522::PCD_SoftPowerUp(){ * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::PCD_TransceiveData( byte *sendData, ///< Pointer to the data to transfer to the FIFO. - byte sendLen, ///< Number of bytes to transfer to the FIFO. - byte *backData, ///< nullptr or pointer to buffer if data should be read back after executing the command. - byte *backLen, ///< In: Max number of bytes to write to *backData. Out: The number of bytes returned. - byte *validBits, ///< In/Out: The number of valid bits in the last byte. 0 for 8 valid bits. Default nullptr. - byte rxAlign, ///< In: Defines the bit position in backData[0] for the first bit received. Default 0. +MFRC522::StatusCode MFRC522::PCD_TransceiveData( uint8_t *sendData, ///< Pointer to the data to transfer to the FIFO. + uint8_t sendLen, ///< Number of bytes to transfer to the FIFO. + uint8_t *backData, ///< nullptr or pointer to buffer if data should be read back after executing the command. + uint8_t *backLen, ///< In: Max number of bytes to write to *backData. Out: The number of bytes returned. + uint8_t *validBits, ///< In/Out: The number of valid bits in the last uint8_t. 0 for 8 valid bits. Default nullptr. + uint8_t rxAlign, ///< In: Defines the bit position in backData[0] for the first bit received. Default 0. bool checkCRC ///< In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated. ) { - byte waitIRq = 0x30; // RxIRq and IdleIRq + uint8_t waitIRq = 0x30; // RxIRq and IdleIRq return PCD_CommunicateWithPICC(PCD_Transceive, waitIRq, sendData, sendLen, backData, backLen, validBits, rxAlign, checkCRC); } // End PCD_TransceiveData() @@ -453,19 +453,19 @@ MFRC522::StatusCode MFRC522::PCD_TransceiveData( byte *sendData, ///< Pointer t * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::PCD_CommunicateWithPICC( byte command, ///< The command to execute. One of the PCD_Command enums. - byte waitIRq, ///< The bits in the ComIrqReg register that signals successful completion of the command. - byte *sendData, ///< Pointer to the data to transfer to the FIFO. - byte sendLen, ///< Number of bytes to transfer to the FIFO. - byte *backData, ///< nullptr or pointer to buffer if data should be read back after executing the command. - byte *backLen, ///< In: Max number of bytes to write to *backData. Out: The number of bytes returned. - byte *validBits, ///< In/Out: The number of valid bits in the last byte. 0 for 8 valid bits. - byte rxAlign, ///< In: Defines the bit position in backData[0] for the first bit received. Default 0. +MFRC522::StatusCode MFRC522::PCD_CommunicateWithPICC( uint8_t command, ///< The command to execute. One of the PCD_Command enums. + uint8_t waitIRq, ///< The bits in the ComIrqReg register that signals successful completion of the command. + uint8_t *sendData, ///< Pointer to the data to transfer to the FIFO. + uint8_t sendLen, ///< Number of bytes to transfer to the FIFO. + uint8_t *backData, ///< nullptr or pointer to buffer if data should be read back after executing the command. + uint8_t *backLen, ///< In: Max number of bytes to write to *backData. Out: The number of bytes returned. + uint8_t *validBits, ///< In/Out: The number of valid bits in the last uint8_t. 0 for 8 valid bits. + uint8_t rxAlign, ///< In: Defines the bit position in backData[0] for the first bit received. Default 0. bool checkCRC ///< In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated. ) { // Prepare values for BitFramingReg - byte txLastBits = validBits ? *validBits : 0; - byte bitFraming = (rxAlign << 4) + txLastBits; // RxAlign = BitFramingReg[6..4]. TxLastBits = BitFramingReg[2..0] + uint8_t txLastBits = validBits ? *validBits : 0; + uint8_t bitFraming = (rxAlign << 4) + txLastBits; // RxAlign = BitFramingReg[6..4]. TxLastBits = BitFramingReg[2..0] PCD_WriteRegister(CommandReg, PCD_Idle); // Stop any active command. PCD_WriteRegister(ComIrqReg, 0x7F); // Clear all seven interrupt request bits @@ -483,7 +483,7 @@ MFRC522::StatusCode MFRC522::PCD_CommunicateWithPICC( byte command, ///< The co // TODO check/modify for other architectures than Arduino Uno 16bit uint16_t i; for (i = 2000; i > 0; i--) { - byte n = PCD_ReadRegister(ComIrqReg); // ComIrqReg[7..0] bits are: Set1 TxIRq RxIRq IdleIRq HiAlertIRq LoAlertIRq ErrIRq TimerIRq + uint8_t n = PCD_ReadRegister(ComIrqReg); // ComIrqReg[7..0] bits are: Set1 TxIRq RxIRq IdleIRq HiAlertIRq LoAlertIRq ErrIRq TimerIRq if (n & waitIRq) { // One of the interrupts that signal success has been set. break; } @@ -497,22 +497,22 @@ MFRC522::StatusCode MFRC522::PCD_CommunicateWithPICC( byte command, ///< The co } // Stop now if any errors except collisions were detected. - byte errorRegValue = PCD_ReadRegister(ErrorReg); // ErrorReg[7..0] bits are: WrErr TempErr reserved BufferOvfl CollErr CRCErr ParityErr ProtocolErr + uint8_t errorRegValue = PCD_ReadRegister(ErrorReg); // ErrorReg[7..0] bits are: WrErr TempErr reserved BufferOvfl CollErr CRCErr ParityErr ProtocolErr if (errorRegValue & 0x13) { // BufferOvfl ParityErr ProtocolErr return STATUS_ERROR; } - byte _validBits = 0; + uint8_t _validBits = 0; // If the caller wants data back, get it from the MFRC522. if (backData && backLen) { - byte n = PCD_ReadRegister(FIFOLevelReg); // Number of bytes in the FIFO + uint8_t n = PCD_ReadRegister(FIFOLevelReg); // Number of bytes in the FIFO if (n > *backLen) { return STATUS_NO_ROOM; } *backLen = n; // Number of bytes returned PCD_ReadRegister(FIFODataReg, n, backData, rxAlign); // Get received data from FIFO - _validBits = PCD_ReadRegister(ControlReg) & 0x07; // RxLastBits[2:0] indicates the number of valid bits in the last received byte. If this value is 000b, the whole byte is valid. + _validBits = PCD_ReadRegister(ControlReg) & 0x07; // RxLastBits[2:0] indicates the number of valid bits in the last received uint8_t. If this value is 000b, the whole uint8_t is valid. if (validBits) { *validBits = _validBits; } @@ -534,7 +534,7 @@ MFRC522::StatusCode MFRC522::PCD_CommunicateWithPICC( byte command, ///< The co return STATUS_CRC_WRONG; } // Verify CRC_A - do our own calculation and store the control in controlBuffer. - byte controlBuffer[2]; + uint8_t controlBuffer[2]; MFRC522::StatusCode status = PCD_CalculateCRC(&backData[0], *backLen - 2, &controlBuffer[0]); if (status != STATUS_OK) { return status; @@ -553,8 +553,8 @@ MFRC522::StatusCode MFRC522::PCD_CommunicateWithPICC( byte command, ///< The co * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::PICC_RequestA( byte *bufferATQA, ///< The buffer to store the ATQA (Answer to request) in - byte *bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK. +MFRC522::StatusCode MFRC522::PICC_RequestA( uint8_t *bufferATQA, ///< The buffer to store the ATQA (Answer to request) in + uint8_t *bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK. ) { return PICC_REQA_or_WUPA(PICC_CMD_REQA, bufferATQA, bufferSize); } // End PICC_RequestA() @@ -565,8 +565,8 @@ MFRC522::StatusCode MFRC522::PICC_RequestA( byte *bufferATQA, ///< The buffer to * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::PICC_WakeupA( byte *bufferATQA, ///< The buffer to store the ATQA (Answer to request) in - byte *bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK. +MFRC522::StatusCode MFRC522::PICC_WakeupA( uint8_t *bufferATQA, ///< The buffer to store the ATQA (Answer to request) in + uint8_t *bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK. ) { return PICC_REQA_or_WUPA(PICC_CMD_WUPA, bufferATQA, bufferSize); } // End PICC_WakeupA() @@ -577,18 +577,18 @@ MFRC522::StatusCode MFRC522::PICC_WakeupA( byte *bufferATQA, ///< The buffer to * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::PICC_REQA_or_WUPA( byte command, ///< The command to send - PICC_CMD_REQA or PICC_CMD_WUPA - byte *bufferATQA, ///< The buffer to store the ATQA (Answer to request) in - byte *bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK. +MFRC522::StatusCode MFRC522::PICC_REQA_or_WUPA( uint8_t command, ///< The command to send - PICC_CMD_REQA or PICC_CMD_WUPA + uint8_t *bufferATQA, ///< The buffer to store the ATQA (Answer to request) in + uint8_t *bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK. ) { - byte validBits; + uint8_t validBits; MFRC522::StatusCode status; if (bufferATQA == nullptr || *bufferSize < 2) { // The ATQA response is 2 bytes long. return STATUS_NO_ROOM; } PCD_ClearRegisterBitMask(CollReg, 0x80); // ValuesAfterColl=1 => Bits received after collision are cleared. - validBits = 7; // For REQA and WUPA we need the short frame format - transmit only 7 bits of the last (and only) byte. TxLastBits = BitFramingReg[2..0] + validBits = 7; // For REQA and WUPA we need the short frame format - transmit only 7 bits of the last (and only) uint8_t. TxLastBits = BitFramingReg[2..0] status = PCD_TransceiveData(&command, 1, bufferATQA, bufferSize, &validBits); if (status != STATUS_OK) { return status; @@ -617,24 +617,24 @@ MFRC522::StatusCode MFRC522::PICC_REQA_or_WUPA( byte command, ///< The command * @return STATUS_OK on success, STATUS_??? otherwise. */ MFRC522::StatusCode MFRC522::PICC_Select( Uid *uid, ///< Pointer to Uid struct. Normally output, but can also be used to supply a known UID. - byte validBits ///< The number of known UID bits supplied in *uid. Normally 0. If set you must also supply uid->size. + uint8_t validBits ///< The number of known UID bits supplied in *uid. Normally 0. If set you must also supply uid->size. ) { bool uidComplete; bool selectDone; bool useCascadeTag; - byte cascadeLevel = 1; + uint8_t cascadeLevel = 1; MFRC522::StatusCode result; - byte count; - byte checkBit; - byte index; - byte uidIndex; // The first index in uid->uidByte[] that is used in the current Cascade Level. + uint8_t count; + uint8_t checkBit; + uint8_t index; + uint8_t uidIndex; // The first index in uid->uidByte[] that is used in the current Cascade Level. int8_t currentLevelKnownBits; // The number of known UID bits in the current Cascade Level. - byte buffer[9]; // The SELECT/ANTICOLLISION commands uses a 7 byte standard frame + 2 bytes CRC_A - byte bufferUsed; // The number of bytes used in the buffer, ie the number of bytes to transfer to the FIFO. - byte rxAlign; // Used in BitFramingReg. Defines the bit position for the first bit received. - byte txLastBits; // Used in BitFramingReg. The number of valid bits in the last transmitted byte. - byte *responseBuffer; - byte responseLength; + uint8_t buffer[9]; // The SELECT/ANTICOLLISION commands uses a 7 uint8_t standard frame + 2 bytes CRC_A + uint8_t bufferUsed; // The number of bytes used in the buffer, ie the number of bytes to transfer to the FIFO. + uint8_t rxAlign; // Used in BitFramingReg. Defines the bit position for the first bit received. + uint8_t txLastBits; // Used in BitFramingReg. The number of valid bits in the last transmitted uint8_t. + uint8_t *responseBuffer; + uint8_t responseLength; // Description of buffer structure: // Byte 0: SEL Indicates the Cascade Level: PICC_CMD_SEL_CL1, PICC_CMD_SEL_CL2 or PICC_CMD_SEL_CL3 @@ -704,9 +704,9 @@ MFRC522::StatusCode MFRC522::PICC_Select( Uid *uid, ///< Pointer to Uid struct if (useCascadeTag) { buffer[index++] = PICC_CMD_CT; } - byte bytesToCopy = currentLevelKnownBits / 8 + (currentLevelKnownBits % 8 ? 1 : 0); // The number of bytes needed to represent the known bits for this level. + uint8_t bytesToCopy = currentLevelKnownBits / 8 + (currentLevelKnownBits % 8 ? 1 : 0); // The number of bytes needed to represent the known bits for this level. if (bytesToCopy) { - byte maxBytes = useCascadeTag ? 3 : 4; // Max 4 bytes in each Cascade Level. Only 3 left if we use the Cascade Tag + uint8_t maxBytes = useCascadeTag ? 3 : 4; // Max 4 bytes in each Cascade Level. Only 3 left if we use the Cascade Tag if (bytesToCopy > maxBytes) { bytesToCopy = maxBytes; } @@ -758,11 +758,11 @@ MFRC522::StatusCode MFRC522::PICC_Select( Uid *uid, ///< Pointer to Uid struct // Transmit the buffer and receive the response. result = PCD_TransceiveData(buffer, bufferUsed, responseBuffer, &responseLength, &txLastBits, rxAlign); if (result == STATUS_COLLISION) { // More than one PICC in the field => collision. - byte valueOfCollReg = PCD_ReadRegister(CollReg); // CollReg[7..0] bits are: ValuesAfterColl reserved CollPosNotValid CollPos[4:0] + uint8_t valueOfCollReg = PCD_ReadRegister(CollReg); // CollReg[7..0] bits are: ValuesAfterColl reserved CollPosNotValid CollPos[4:0] if (valueOfCollReg & 0x20) { // CollPosNotValid return STATUS_COLLISION; // Without a valid collision position we cannot continue } - byte collisionPos = valueOfCollReg & 0x1F; // Values 0-31, 0 means bit 32. + uint8_t collisionPos = valueOfCollReg & 0x1F; // Values 0-31, 0 means bit 32. if (collisionPos == 0) { collisionPos = 32; } @@ -835,7 +835,7 @@ MFRC522::StatusCode MFRC522::PICC_Select( Uid *uid, ///< Pointer to Uid struct */ MFRC522::StatusCode MFRC522::PICC_HaltA() { MFRC522::StatusCode result; - byte buffer[4]; + uint8_t buffer[4]; // Build command buffer buffer[0] = PICC_CMD_HLTA; @@ -877,25 +877,25 @@ MFRC522::StatusCode MFRC522::PICC_HaltA() { * * @return STATUS_OK on success, STATUS_??? otherwise. Probably STATUS_TIMEOUT if you supply the wrong key. */ -MFRC522::StatusCode MFRC522::PCD_Authenticate(byte command, ///< PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B - byte blockAddr, ///< The block number. See numbering in the comments in the .h file. +MFRC522::StatusCode MFRC522::PCD_Authenticate(uint8_t command, ///< PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B + uint8_t blockAddr, ///< The block number. See numbering in the comments in the .h file. MIFARE_Key *key, ///< Pointer to the Crypteo1 key to use (6 bytes) Uid *uid ///< Pointer to Uid struct. The first 4 bytes of the UID is used. ) { - byte waitIRq = 0x10; // IdleIRq + uint8_t waitIRq = 0x10; // IdleIRq // Build command buffer - byte sendData[12]; + uint8_t sendData[12]; sendData[0] = command; sendData[1] = blockAddr; - for (byte i = 0; i < MF_KEY_SIZE; i++) { // 6 key bytes + for (uint8_t i = 0; i < MF_KEY_SIZE; i++) { // 6 key bytes sendData[2+i] = key->keyByte[i]; } // Use the last uid bytes as specified in http://cache.nxp.com/documents/application_note/AN10927.pdf // section 3.2.5 "MIFARE Classic Authentication". // The only missed case is the MF1Sxxxx shortcut activation, - // but it requires cascade tag (CT) byte, that is not part of uid. - for (byte i = 0; i < 4; i++) { // The last 4 bytes of the UID + // but it requires cascade tag (CT) uint8_t, that is not part of uid. + for (uint8_t i = 0; i < 4; i++) { // The last 4 bytes of the UID sendData[8+i] = uid->uidByte[i+uid->size-4]; } @@ -928,9 +928,9 @@ void MFRC522::PCD_StopCrypto1() { * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::MIFARE_Read( byte blockAddr, ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The first page to return data from. - byte *buffer, ///< The buffer to store the data in - byte *bufferSize ///< Buffer size, at least 18 bytes. Also number of bytes returned if STATUS_OK. +MFRC522::StatusCode MFRC522::MIFARE_Read( uint8_t blockAddr, ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The first page to return data from. + uint8_t *buffer, ///< The buffer to store the data in + uint8_t *bufferSize ///< Buffer size, at least 18 bytes. Also number of bytes returned if STATUS_OK. ) { MFRC522::StatusCode result; @@ -963,9 +963,9 @@ MFRC522::StatusCode MFRC522::MIFARE_Read( byte blockAddr, ///< MIFARE Classic: * * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::MIFARE_Write( byte blockAddr, ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The page (2-15) to write to. - byte *buffer, ///< The 16 bytes to write to the PICC - byte bufferSize ///< Buffer size, must be at least 16 bytes. Exactly 16 bytes are written. +MFRC522::StatusCode MFRC522::MIFARE_Write( uint8_t blockAddr, ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The page (2-15) to write to. + uint8_t *buffer, ///< The 16 bytes to write to the PICC + uint8_t bufferSize ///< Buffer size, must be at least 16 bytes. Exactly 16 bytes are written. ) { MFRC522::StatusCode result; @@ -976,7 +976,7 @@ MFRC522::StatusCode MFRC522::MIFARE_Write( byte blockAddr, ///< MIFARE Classic: // Mifare Classic protocol requires two communications to perform a write. // Step 1: Tell the PICC we want to write to block blockAddr. - byte cmdBuffer[2]; + uint8_t cmdBuffer[2]; cmdBuffer[0] = PICC_CMD_MF_WRITE; cmdBuffer[1] = blockAddr; result = PCD_MIFARE_Transceive(cmdBuffer, 2); // Adds CRC_A and checks that the response is MF_ACK. @@ -994,13 +994,13 @@ MFRC522::StatusCode MFRC522::MIFARE_Write( byte blockAddr, ///< MIFARE Classic: } // End MIFARE_Write() /** - * Writes a 4 byte page to the active MIFARE Ultralight PICC. + * Writes a 4 uint8_t page to the active MIFARE Ultralight PICC. * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::MIFARE_Ultralight_Write( byte page, ///< The page (2-15) to write to. - byte *buffer, ///< The 4 bytes to write to the PICC - byte bufferSize ///< Buffer size, must be at least 4 bytes. Exactly 4 bytes are written. +MFRC522::StatusCode MFRC522::MIFARE_Ultralight_Write( uint8_t page, ///< The page (2-15) to write to. + uint8_t *buffer, ///< The 4 bytes to write to the PICC + uint8_t bufferSize ///< Buffer size, must be at least 4 bytes. Exactly 4 bytes are written. ) { MFRC522::StatusCode result; @@ -1010,7 +1010,7 @@ MFRC522::StatusCode MFRC522::MIFARE_Ultralight_Write( byte page, ///< The page } // Build commmand buffer - byte cmdBuffer[6]; + uint8_t cmdBuffer[6]; cmdBuffer[0] = PICC_CMD_UL_WRITE; cmdBuffer[1] = page; memcpy(&cmdBuffer[2], buffer, 4); @@ -1031,7 +1031,7 @@ MFRC522::StatusCode MFRC522::MIFARE_Ultralight_Write( byte page, ///< The page * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::MIFARE_Decrement( byte blockAddr, ///< The block (0-0xff) number. +MFRC522::StatusCode MFRC522::MIFARE_Decrement( uint8_t blockAddr, ///< The block (0-0xff) number. int32_t delta ///< This number is subtracted from the value of block blockAddr. ) { return MIFARE_TwoStepHelper(PICC_CMD_MF_DECREMENT, blockAddr, delta); @@ -1045,7 +1045,7 @@ MFRC522::StatusCode MFRC522::MIFARE_Decrement( byte blockAddr, ///< The block (0 * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::MIFARE_Increment( byte blockAddr, ///< The block (0-0xff) number. +MFRC522::StatusCode MFRC522::MIFARE_Increment( uint8_t blockAddr, ///< The block (0-0xff) number. int32_t delta ///< This number is added to the value of block blockAddr. ) { return MIFARE_TwoStepHelper(PICC_CMD_MF_INCREMENT, blockAddr, delta); @@ -1059,7 +1059,7 @@ MFRC522::StatusCode MFRC522::MIFARE_Increment( byte blockAddr, ///< The block (0 * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::MIFARE_Restore( byte blockAddr ///< The block (0-0xff) number. +MFRC522::StatusCode MFRC522::MIFARE_Restore( uint8_t blockAddr ///< The block (0-0xff) number. ) { // The datasheet describes Restore as a two step operation, but does not explain what data to transfer in step 2. // Doing only a single step does not work, so I chose to transfer 0L in step two. @@ -1071,12 +1071,12 @@ MFRC522::StatusCode MFRC522::MIFARE_Restore( byte blockAddr ///< The block (0-0x * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::MIFARE_TwoStepHelper( byte command, ///< The command to use - byte blockAddr, ///< The block (0-0xff) number. +MFRC522::StatusCode MFRC522::MIFARE_TwoStepHelper( uint8_t command, ///< The command to use + uint8_t blockAddr, ///< The block (0-0xff) number. int32_t data ///< The data to transfer in step 2 ) { MFRC522::StatusCode result; - byte cmdBuffer[2]; // We only need room for 2 bytes. + uint8_t cmdBuffer[2]; // We only need room for 2 bytes. // Step 1: Tell the PICC the command and block address cmdBuffer[0] = command; @@ -1087,7 +1087,7 @@ MFRC522::StatusCode MFRC522::MIFARE_TwoStepHelper( byte command, ///< The comman } // Step 2: Transfer the data - result = PCD_MIFARE_Transceive( (byte *)&data, 4, true); // Adds CRC_A and accept timeout as success. + result = PCD_MIFARE_Transceive( (uint8_t *)&data, 4, true); // Adds CRC_A and accept timeout as success. if (result != STATUS_OK) { return result; } @@ -1102,10 +1102,10 @@ MFRC522::StatusCode MFRC522::MIFARE_TwoStepHelper( byte command, ///< The comman * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::MIFARE_Transfer( byte blockAddr ///< The block (0-0xff) number. +MFRC522::StatusCode MFRC522::MIFARE_Transfer( uint8_t blockAddr ///< The block (0-0xff) number. ) { MFRC522::StatusCode result; - byte cmdBuffer[2]; // We only need room for 2 bytes. + uint8_t cmdBuffer[2]; // We only need room for 2 bytes. // Tell the PICC we want to transfer the result into block blockAddr. cmdBuffer[0] = PICC_CMD_MF_TRANSFER; @@ -1128,10 +1128,10 @@ MFRC522::StatusCode MFRC522::MIFARE_Transfer( byte blockAddr ///< The block (0-0 * @param[out] value Current value of the Value Block. * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::MIFARE_GetValue(byte blockAddr, int32_t *value) { +MFRC522::StatusCode MFRC522::MIFARE_GetValue(uint8_t blockAddr, int32_t *value) { MFRC522::StatusCode status; - byte buffer[18]; - byte size = sizeof(buffer); + uint8_t buffer[18]; + uint8_t size = sizeof(buffer); // Read the block status = MIFARE_Read(blockAddr, buffer, &size); @@ -1153,8 +1153,8 @@ MFRC522::StatusCode MFRC522::MIFARE_GetValue(byte blockAddr, int32_t *value) { * @param[in] value New value of the Value Block. * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::MIFARE_SetValue(byte blockAddr, int32_t value) { - byte buffer[18]; +MFRC522::StatusCode MFRC522::MIFARE_SetValue(uint8_t blockAddr, int32_t value) { + uint8_t buffer[18]; // Translate the int32_t into 4 bytes; repeated 2x in value block buffer[0] = buffer[ 8] = (value & 0xFF); @@ -1183,17 +1183,17 @@ MFRC522::StatusCode MFRC522::MIFARE_SetValue(byte blockAddr, int32_t value) { * @param[in] pACK result success???. * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::PCD_NTAG216_AUTH(byte* passWord, byte pACK[]) //Authenticate with 32bit password +MFRC522::StatusCode MFRC522::PCD_NTAG216_AUTH(uint8_t* passWord, uint8_t pACK[]) //Authenticate with 32bit password { // TODO: Fix cmdBuffer length and rxlength. They really should match. // (Better still, rxlength should not even be necessary.) MFRC522::StatusCode result; - byte cmdBuffer[18]; // We need room for 16 bytes data and 2 bytes CRC_A. + uint8_t cmdBuffer[18]; // We need room for 16 bytes data and 2 bytes CRC_A. cmdBuffer[0] = 0x1B; //Comando de autentificacion - for (byte i = 0; i<4; i++) + for (uint8_t i = 0; i<4; i++) cmdBuffer[i+1] = passWord[i]; result = PCD_CalculateCRC(cmdBuffer, 5, &cmdBuffer[5]); @@ -1203,10 +1203,10 @@ MFRC522::StatusCode MFRC522::PCD_NTAG216_AUTH(byte* passWord, byte pACK[]) //Aut } // Transceive the data, store the reply in cmdBuffer[] - byte waitIRq = 0x30; // RxIRq and IdleIRq -// byte cmdBufferSize = sizeof(cmdBuffer); - byte validBits = 0; - byte rxlength = 5; + uint8_t waitIRq = 0x30; // RxIRq and IdleIRq +// uint8_t cmdBufferSize = sizeof(cmdBuffer); + uint8_t validBits = 0; + uint8_t rxlength = 5; result = PCD_CommunicateWithPICC(PCD_Transceive, waitIRq, cmdBuffer, 7, cmdBuffer, &rxlength, &validBits); pACK[0] = cmdBuffer[0]; @@ -1230,12 +1230,12 @@ MFRC522::StatusCode MFRC522::PCD_NTAG216_AUTH(byte* passWord, byte pACK[]) //Aut * * @return STATUS_OK on success, STATUS_??? otherwise. */ -MFRC522::StatusCode MFRC522::PCD_MIFARE_Transceive( byte *sendData, ///< Pointer to the data to transfer to the FIFO. Do NOT include the CRC_A. - byte sendLen, ///< Number of bytes in sendData. +MFRC522::StatusCode MFRC522::PCD_MIFARE_Transceive( uint8_t *sendData, ///< Pointer to the data to transfer to the FIFO. Do NOT include the CRC_A. + uint8_t sendLen, ///< Number of bytes in sendData. bool acceptTimeout ///< True => A timeout is also success ) { MFRC522::StatusCode result; - byte cmdBuffer[18]; // We need room for 16 bytes data and 2 bytes CRC_A. + uint8_t cmdBuffer[18]; // We need room for 16 bytes data and 2 bytes CRC_A. // Sanity check if (sendData == nullptr || sendLen > 16) { @@ -1251,9 +1251,9 @@ MFRC522::StatusCode MFRC522::PCD_MIFARE_Transceive( byte *sendData, ///< Pointe sendLen += 2; // Transceive the data, store the reply in cmdBuffer[] - byte waitIRq = 0x30; // RxIRq and IdleIRq - byte cmdBufferSize = sizeof(cmdBuffer); - byte validBits = 0; + uint8_t waitIRq = 0x30; // RxIRq and IdleIRq + uint8_t cmdBufferSize = sizeof(cmdBuffer); + uint8_t validBits = 0; result = PCD_CommunicateWithPICC(PCD_Transceive, waitIRq, cmdBuffer, sendLen, cmdBuffer, &cmdBufferSize, &validBits); if (acceptTimeout && result == STATUS_TIMEOUT) { return STATUS_OK; @@ -1297,7 +1297,7 @@ const __FlashStringHelper *MFRC522::GetStatusCodeName(MFRC522::StatusCode code / * * @return PICC_Type */ -MFRC522::PICC_Type MFRC522::PICC_GetType(byte sak ///< The SAK byte returned from PICC_Select(). +MFRC522::PICC_Type MFRC522::PICC_GetType(uint8_t sak ///< The SAK uint8_t returned from PICC_Select(). ) { // http://www.nxp.com/documents/application_note/AN10833.pdf // 3.2 Coding of Select Acknowledge (SAK) @@ -1348,7 +1348,7 @@ const __FlashStringHelper *MFRC522::PICC_GetTypeName(PICC_Type piccType ///< One */ void MFRC522::PCD_DumpVersionToSerial() { // Get the MFRC522 firmware version - byte v = PCD_ReadRegister(VersionReg); + uint8_t v = PCD_ReadRegister(VersionReg); Serial.print(F("Firmware Version: 0x")); Serial.print(v, HEX); // Lookup which version @@ -1384,7 +1384,7 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro case PICC_TYPE_MIFARE_1K: case PICC_TYPE_MIFARE_4K: // All keys are set to FFFFFFFFFFFFh at chip delivery from the factory. - for (byte i = 0; i < 6; i++) { + for (uint8_t i = 0; i < 6; i++) { key.keyByte[i] = 0xFF; } PICC_DumpMifareClassicToSerial(uid, piccType, &key); @@ -1419,7 +1419,7 @@ void MFRC522::PICC_DumpDetailsToSerial(Uid *uid ///< Pointer to Uid struct retur ) { // UID Serial.print(F("Card UID:")); - for (byte i = 0; i < uid->size; i++) { + for (uint8_t i = 0; i < uid->size; i++) { if(uid->uidByte[i] < 0x10) Serial.print(F(" 0")); else @@ -1448,7 +1448,7 @@ void MFRC522::PICC_DumpMifareClassicToSerial( Uid *uid, ///< Pointer to Uid st PICC_Type piccType, ///< One of the PICC_Type enums. MIFARE_Key *key ///< Key A used for all sectors. ) { - byte no_of_sectors = 0; + uint8_t no_of_sectors = 0; switch (piccType) { case PICC_TYPE_MIFARE_MINI: // Has 5 sectors * 4 blocks/sector * 16 bytes/block = 320 bytes. @@ -1487,11 +1487,11 @@ void MFRC522::PICC_DumpMifareClassicToSerial( Uid *uid, ///< Pointer to Uid st */ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to Uid struct returned from a successful PICC_Select(). MIFARE_Key *key, ///< Key A for the sector. - byte sector ///< The sector to dump, 0..39. + uint8_t sector ///< The sector to dump, 0..39. ) { MFRC522::StatusCode status; - byte firstBlock; // Address of lowest address to dump actually last block dumped) - byte no_of_blocks; // Number of blocks in sector + uint8_t firstBlock; // Address of lowest address to dump actually last block dumped) + uint8_t no_of_blocks; // Number of blocks in sector bool isSectorTrailer; // Set to true while handling the "last" (ie highest address) in the sector. // The access bits are stored in a peculiar fashion. @@ -1502,11 +1502,11 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U // g[0] Access bits for block 0 (for sectors 0-31) or blocks 0-4 (for sectors 32-39) // Each group has access bits [C1 C2 C3]. In this code C1 is MSB and C3 is LSB. // The four CX bits are stored together in a nible cx and an inverted nible cx_. - byte c1, c2, c3; // Nibbles - byte c1_, c2_, c3_; // Inverted nibbles + uint8_t c1, c2, c3; // Nibbles + uint8_t c1_, c2_, c3_; // Inverted nibbles bool invertedError; // True if one of the inverted nibbles did not match - byte g[4]; // Access bits for each of the four groups. - byte group; // 0-3 - active group for access bits + uint8_t g[4]; // Access bits for each of the four groups. + uint8_t group; // 0-3 - active group for access bits bool firstInGroup; // True for the first block dumped in the group // Determine position and size of sector. @@ -1523,9 +1523,9 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U } // Dump blocks, highest address first. - byte byteCount; - byte buffer[18]; - byte blockAddr; + uint8_t byteCount; + uint8_t buffer[18]; + uint8_t blockAddr; isSectorTrailer = true; invertedError = false; // Avoid "unused variable" warning. for (int8_t blockOffset = no_of_blocks - 1; blockOffset >= 0; blockOffset--) { @@ -1571,7 +1571,7 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U continue; } // Dump data - for (byte index = 0; index < 16; index++) { + for (uint8_t index = 0; index < 16; index++) { if(buffer[index] < 0x10) Serial.print(F(" 0")); else @@ -1635,13 +1635,13 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U */ void MFRC522::PICC_DumpMifareUltralightToSerial() { MFRC522::StatusCode status; - byte byteCount; - byte buffer[18]; - byte i; + uint8_t byteCount; + uint8_t buffer[18]; + uint8_t i; Serial.println(F("Page 0 1 2 3")); // Try the mpages of the original Ultralight. Ultralight C has more pages. - for (byte page = 0; page < 16; page +=4) { // Read returns data for 4 pages at a time. + for (uint8_t page = 0; page < 16; page +=4) { // Read returns data for 4 pages at a time. // Read pages byteCount = sizeof(buffer); status = MIFARE_Read(page, buffer, &byteCount); @@ -1651,7 +1651,7 @@ void MFRC522::PICC_DumpMifareUltralightToSerial() { break; } // Dump data - for (byte offset = 0; offset < 4; offset++) { + for (uint8_t offset = 0; offset < 4; offset++) { i = page + offset; if(i < 10) Serial.print(F(" ")); // Pad with spaces @@ -1659,7 +1659,7 @@ void MFRC522::PICC_DumpMifareUltralightToSerial() { Serial.print(F(" ")); // Pad with spaces Serial.print(i); Serial.print(F(" ")); - for (byte index = 0; index < 4; index++) { + for (uint8_t index = 0; index < 4; index++) { i = 4 * offset + index; if(buffer[i] < 0x10) Serial.print(F(" 0")); @@ -1675,15 +1675,15 @@ void MFRC522::PICC_DumpMifareUltralightToSerial() { /** * Calculates the bit pattern needed for the specified access bits. In the [C1 C2 C3] tuples C1 is MSB (=4) and C3 is LSB (=1). */ -void MFRC522::MIFARE_SetAccessBits( byte *accessBitBuffer, ///< Pointer to byte 6, 7 and 8 in the sector trailer. Bytes [0..2] will be set. - byte g0, ///< Access bits [C1 C2 C3] for block 0 (for sectors 0-31) or blocks 0-4 (for sectors 32-39) - byte g1, ///< Access bits C1 C2 C3] for block 1 (for sectors 0-31) or blocks 5-9 (for sectors 32-39) - byte g2, ///< Access bits C1 C2 C3] for block 2 (for sectors 0-31) or blocks 10-14 (for sectors 32-39) - byte g3 ///< Access bits C1 C2 C3] for the sector trailer, block 3 (for sectors 0-31) or block 15 (for sectors 32-39) +void MFRC522::MIFARE_SetAccessBits( uint8_t *accessBitBuffer, ///< Pointer to uint8_t 6, 7 and 8 in the sector trailer. Bytes [0..2] will be set. + uint8_t g0, ///< Access bits [C1 C2 C3] for block 0 (for sectors 0-31) or blocks 0-4 (for sectors 32-39) + uint8_t g1, ///< Access bits C1 C2 C3] for block 1 (for sectors 0-31) or blocks 5-9 (for sectors 32-39) + uint8_t g2, ///< Access bits C1 C2 C3] for block 2 (for sectors 0-31) or blocks 10-14 (for sectors 32-39) + uint8_t g3 ///< Access bits C1 C2 C3] for the sector trailer, block 3 (for sectors 0-31) or block 15 (for sectors 32-39) ) { - byte c1 = ((g3 & 4) << 1) | ((g2 & 4) << 0) | ((g1 & 4) >> 1) | ((g0 & 4) >> 2); - byte c2 = ((g3 & 2) << 2) | ((g2 & 2) << 1) | ((g1 & 2) << 0) | ((g0 & 2) >> 1); - byte c3 = ((g3 & 1) << 3) | ((g2 & 1) << 2) | ((g1 & 1) << 1) | ((g0 & 1) << 0); + uint8_t c1 = ((g3 & 4) << 1) | ((g2 & 4) << 0) | ((g1 & 4) >> 1) | ((g0 & 4) >> 2); + uint8_t c2 = ((g3 & 2) << 2) | ((g2 & 2) << 1) | ((g1 & 2) << 0) | ((g0 & 2) >> 1); + uint8_t c3 = ((g3 & 1) << 3) | ((g2 & 1) << 2) | ((g1 & 1) << 1) | ((g0 & 1) << 0); accessBitBuffer[0] = (~c2 & 0xF) << 4 | (~c1 & 0xF); accessBitBuffer[1] = c1 << 4 | (~c3 & 0xF); @@ -1713,12 +1713,12 @@ bool MFRC522::MIFARE_OpenUidBackdoor(bool logErrors) { PICC_HaltA(); // 50 00 57 CD - byte cmd = 0x40; - byte validBits = 7; /* Our command is only 7 bits. After receiving card response, + uint8_t cmd = 0x40; + uint8_t validBits = 7; /* Our command is only 7 bits. After receiving card response, this will contain amount of valid response bits. */ - byte response[32]; // Card's response is written here - byte received; - MFRC522::StatusCode status = PCD_TransceiveData(&cmd, (byte)1, response, &received, &validBits, (byte)0, false); // 40 + uint8_t response[32]; // Card's response is written here + uint8_t received; + MFRC522::StatusCode status = PCD_TransceiveData(&cmd, (uint8_t)1, response, &received, &validBits, (uint8_t)0, false); // 40 if(status != STATUS_OK) { if(logErrors) { Serial.println(F("Card did not respond to 0x40 after HALT command. Are you sure it is a UID changeable one?")); @@ -1740,7 +1740,7 @@ bool MFRC522::MIFARE_OpenUidBackdoor(bool logErrors) { cmd = 0x43; validBits = 8; - status = PCD_TransceiveData(&cmd, (byte)1, response, &received, &validBits, (byte)0, false); // 43 + status = PCD_TransceiveData(&cmd, (uint8_t)1, response, &received, &validBits, (uint8_t)0, false); // 43 if(status != STATUS_OK) { if(logErrors) { Serial.println(F("Error in communication at command 0x43, after successfully executing 0x40")); @@ -1772,9 +1772,9 @@ bool MFRC522::MIFARE_OpenUidBackdoor(bool logErrors) { * It assumes a default KEY A of 0xFFFFFFFFFFFF. * Make sure to have selected the card before this function is called. */ -bool MFRC522::MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors) { +bool MFRC522::MIFARE_SetUid(uint8_t *newUid, uint8_t uidSize, bool logErrors) { - // UID + BCC byte can not be larger than 16 together + // UID + BCC uint8_t can not be larger than 16 together if (!newUid || !uidSize || uidSize > 15) { if (logErrors) { Serial.println(F("New UID buffer empty, size 0, or size > 15 given")); @@ -1784,15 +1784,15 @@ bool MFRC522::MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors) { // Authenticate for reading MIFARE_Key key = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - MFRC522::StatusCode status = PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, (byte)1, &key, &uid); + MFRC522::StatusCode status = PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, (uint8_t)1, &key, &uid); if (status != STATUS_OK) { if (status == STATUS_TIMEOUT) { // We get a read timeout if no card is selected yet, so let's select one // Wake the card up again if sleeping -// byte atqa_answer[2]; -// byte atqa_size = 2; +// uint8_t atqa_answer[2]; +// uint8_t atqa_size = 2; // PICC_WakeupA(atqa_answer, &atqa_size); if (!PICC_IsNewCardPresent() || !PICC_ReadCardSerial()) { @@ -1800,7 +1800,7 @@ bool MFRC522::MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors) { return false; } - status = PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, (byte)1, &key, &uid); + status = PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, (uint8_t)1, &key, &uid); if (status != STATUS_OK) { // We tried, time to give up if (logErrors) { @@ -1820,9 +1820,9 @@ bool MFRC522::MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors) { } // Read block 0 - byte block0_buffer[18]; - byte byteCount = sizeof(block0_buffer); - status = MIFARE_Read((byte)0, block0_buffer, &byteCount); + uint8_t block0_buffer[18]; + uint8_t byteCount = sizeof(block0_buffer); + status = MIFARE_Read((uint8_t)0, block0_buffer, &byteCount); if (status != STATUS_OK) { if (logErrors) { Serial.print(F("MIFARE_Read() failed: ")); @@ -1832,14 +1832,14 @@ bool MFRC522::MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors) { return false; } - // Write new UID to the data we just read, and calculate BCC byte - byte bcc = 0; + // Write new UID to the data we just read, and calculate BCC uint8_t + uint8_t bcc = 0; for (uint8_t i = 0; i < uidSize; i++) { block0_buffer[i] = newUid[i]; bcc ^= newUid[i]; } - // Write BCC byte to buffer + // Write BCC uint8_t to buffer block0_buffer[uidSize] = bcc; // Stop encrypted traffic so we can send raw bytes @@ -1854,7 +1854,7 @@ bool MFRC522::MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors) { } // Write modified block 0 back to card - status = MIFARE_Write((byte)0, block0_buffer, (byte)16); + status = MIFARE_Write((uint8_t)0, block0_buffer, (uint8_t)16); if (status != STATUS_OK) { if (logErrors) { Serial.print(F("MIFARE_Write() failed: ")); @@ -1864,8 +1864,8 @@ bool MFRC522::MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors) { } // Wake the card up again - byte atqa_answer[2]; - byte atqa_size = 2; + uint8_t atqa_answer[2]; + uint8_t atqa_size = 2; PICC_WakeupA(atqa_answer, &atqa_size); return true; @@ -1877,10 +1877,10 @@ bool MFRC522::MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors) { bool MFRC522::MIFARE_UnbrickUidSector(bool logErrors) { MIFARE_OpenUidBackdoor(logErrors); - byte block0_buffer[] = {0x01, 0x02, 0x03, 0x04, 0x04, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t block0_buffer[] = {0x01, 0x02, 0x03, 0x04, 0x04, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Write modified block 0 back to card - MFRC522::StatusCode status = MIFARE_Write((byte)0, block0_buffer, (byte)16); + MFRC522::StatusCode status = MIFARE_Write((uint8_t)0, block0_buffer, (uint8_t)16); if (status != STATUS_OK) { if (logErrors) { Serial.print(F("MIFARE_Write() failed: ")); @@ -1902,8 +1902,8 @@ bool MFRC522::MIFARE_UnbrickUidSector(bool logErrors) { * @return bool */ bool MFRC522::PICC_IsNewCardPresent() { - byte bufferATQA[2]; - byte bufferSize = sizeof(bufferATQA); + uint8_t bufferATQA[2]; + uint8_t bufferSize = sizeof(bufferATQA); // Reset baud rates PCD_WriteRegister(TxModeReg, 0x00); diff --git a/lib/MFRC522/MFRC522.h b/lib/MFRC522/MFRC522.h index 597c4a5d5..2c8ea5b73 100644 --- a/lib/MFRC522/MFRC522.h +++ b/lib/MFRC522/MFRC522.h @@ -28,7 +28,7 @@ // // Version 0.0 (0x90) // Philips Semiconductors; Preliminary Specification Revision 2.0 - 01 August 2005; 16.1 self-test -const byte MFRC522_firmware_referenceV0_0[] PROGMEM = { +const uint8_t MFRC522_firmware_referenceV0_0[] PROGMEM = { 0x00, 0x87, 0x98, 0x0f, 0x49, 0xFF, 0x07, 0x19, 0xBF, 0x22, 0x30, 0x49, 0x59, 0x63, 0xAD, 0xCA, 0x7F, 0xE3, 0x4E, 0x03, 0x5C, 0x4E, 0x49, 0x50, @@ -40,7 +40,7 @@ const byte MFRC522_firmware_referenceV0_0[] PROGMEM = { }; // Version 1.0 (0x91) // NXP Semiconductors; Rev. 3.8 - 17 September 2014; 16.1.1 self-test -const byte MFRC522_firmware_referenceV1_0[] PROGMEM = { +const uint8_t MFRC522_firmware_referenceV1_0[] PROGMEM = { 0x00, 0xC6, 0x37, 0xD5, 0x32, 0xB7, 0x57, 0x5C, 0xC2, 0xD8, 0x7C, 0x4D, 0xD9, 0x70, 0xC7, 0x73, 0x10, 0xE6, 0xD2, 0xAA, 0x5E, 0xA1, 0x3E, 0x5A, @@ -52,7 +52,7 @@ const byte MFRC522_firmware_referenceV1_0[] PROGMEM = { }; // Version 2.0 (0x92) // NXP Semiconductors; Rev. 3.8 - 17 September 2014; 16.1.1 self-test -const byte MFRC522_firmware_referenceV2_0[] PROGMEM = { +const uint8_t MFRC522_firmware_referenceV2_0[] PROGMEM = { 0x00, 0xEB, 0x66, 0xBA, 0x57, 0xBF, 0x23, 0x95, 0xD0, 0xE3, 0x0D, 0x3D, 0x27, 0x89, 0x5C, 0xDE, 0x9D, 0x3B, 0xA7, 0x00, 0x21, 0x5B, 0x89, 0x82, @@ -64,7 +64,7 @@ const byte MFRC522_firmware_referenceV2_0[] PROGMEM = { }; // Clone // Fudan Semiconductor FM17522 (0x88) -const byte FM17522_firmware_reference[] PROGMEM = { +const uint8_t FM17522_firmware_reference[] PROGMEM = { 0x00, 0xD6, 0x78, 0x8C, 0xE2, 0xAA, 0x0C, 0x18, 0x2A, 0xB8, 0x7A, 0x7F, 0xD3, 0x6A, 0xCF, 0x0B, 0xB1, 0x37, 0x63, 0x4B, 0x69, 0xAE, 0x91, 0xC7, @@ -78,13 +78,13 @@ const byte FM17522_firmware_reference[] PROGMEM = { class MFRC522 { public: // Size of the MFRC522 FIFO - static constexpr byte FIFO_SIZE = 64; // The FIFO is 64 bytes. + static constexpr uint8_t FIFO_SIZE = 64; // The FIFO is 64 bytes. // Default value for unused pin static constexpr uint8_t UNUSED_PIN = UINT8_MAX; // MFRC522 registers. Described in chapter 9 of the datasheet. - // When using SPI all addresses are shifted one bit left in the "SPI address byte" (section 8.1.2.3) - enum PCD_Register : byte { + // When using SPI all addresses are shifted one bit left in the "SPI address uint8_t" (section 8.1.2.3) + enum PCD_Register : uint8_t { // Page 0: Command and status // 0x00 // reserved for future use CommandReg = 0x01 << 1, // starts and stops command execution @@ -95,7 +95,7 @@ public: ErrorReg = 0x06 << 1, // error bits showing the error status of the last command executed Status1Reg = 0x07 << 1, // communication status bits Status2Reg = 0x08 << 1, // receiver and transmitter status bits - FIFODataReg = 0x09 << 1, // input and output of 64 byte FIFO buffer + FIFODataReg = 0x09 << 1, // input and output of 64 uint8_t FIFO buffer FIFOLevelReg = 0x0A << 1, // number of bytes stored in the FIFO buffer WaterLevelReg = 0x0B << 1, // level for FIFO underflow and overflow warning ControlReg = 0x0C << 1, // miscellaneous control registers @@ -159,10 +159,10 @@ public: }; // MFRC522 commands. Described in chapter 10 of the datasheet. - enum PCD_Command : byte { + enum PCD_Command : uint8_t { PCD_Idle = 0x00, // no action, cancels current command execution PCD_Mem = 0x01, // stores 25 bytes into the internal buffer - PCD_GenerateRandomID = 0x02, // generates a 10-byte random ID number + PCD_GenerateRandomID = 0x02, // generates a 10-uint8_t random ID number PCD_CalcCRC = 0x03, // activates the CRC coprocessor or performs a self-test PCD_Transmit = 0x04, // transmits data from the FIFO buffer PCD_NoCmdChange = 0x07, // no command change, can be used to modify the CommandReg register bits without affecting the command, for example, the PowerDown bit @@ -174,7 +174,7 @@ public: // MFRC522 RxGain[2:0] masks, defines the receiver's signal voltage gain factor (on the PCD). // Described in 9.3.3.6 / table 98 of the datasheet at http://www.nxp.com/documents/data_sheet/MFRC522.pdf - enum PCD_RxGain : byte { + enum PCD_RxGain : uint8_t { RxGain_18dB = 0x00 << 4, // 000b - 18 dB, minimum RxGain_23dB = 0x01 << 4, // 001b - 23 dB RxGain_18dB_2 = 0x02 << 4, // 010b - 18 dB, it seems 010b is a duplicate for 000b @@ -189,7 +189,7 @@ public: }; // Commands sent to the PICC. - enum PICC_Command : byte { + enum PICC_Command : uint8_t { // The commands used by the PCD to manage communication with several PICCs (ISO 14443-3, Type A, section 6.4) PICC_CMD_REQA = 0x26, // REQuest command, Type A. Invites PICCs in state IDLE to go to READY and prepare for anticollision or selection. 7 bit frame. PICC_CMD_WUPA = 0x52, // Wake-UP command, Type A. Invites PICCs in state IDLE and HALT to go to READY(*) and prepare for anticollision or selection. 7 bit frame. @@ -204,15 +204,15 @@ public: // The read/write commands can also be used for MIFARE Ultralight. PICC_CMD_MF_AUTH_KEY_A = 0x60, // Perform authentication with Key A PICC_CMD_MF_AUTH_KEY_B = 0x61, // Perform authentication with Key B - PICC_CMD_MF_READ = 0x30, // Reads one 16 byte block from the authenticated sector of the PICC. Also used for MIFARE Ultralight. - PICC_CMD_MF_WRITE = 0xA0, // Writes one 16 byte block to the authenticated sector of the PICC. Called "COMPATIBILITY WRITE" for MIFARE Ultralight. + PICC_CMD_MF_READ = 0x30, // Reads one 16 uint8_t block from the authenticated sector of the PICC. Also used for MIFARE Ultralight. + PICC_CMD_MF_WRITE = 0xA0, // Writes one 16 uint8_t block to the authenticated sector of the PICC. Called "COMPATIBILITY WRITE" for MIFARE Ultralight. PICC_CMD_MF_DECREMENT = 0xC0, // Decrements the contents of a block and stores the result in the internal data register. PICC_CMD_MF_INCREMENT = 0xC1, // Increments the contents of a block and stores the result in the internal data register. PICC_CMD_MF_RESTORE = 0xC2, // Reads the contents of a block into the internal data register. PICC_CMD_MF_TRANSFER = 0xB0, // Writes the contents of the internal data register to a block. // The commands used for MIFARE Ultralight (from http://www.nxp.com/documents/data_sheet/MF0ICU1.pdf, Section 8.6) // The PICC_CMD_MF_READ and PICC_CMD_MF_WRITE can also be used for MIFARE Ultralight. - PICC_CMD_UL_WRITE = 0xA2 // Writes one 4 byte page to the PICC. + PICC_CMD_UL_WRITE = 0xA2 // Writes one 4 uint8_t page to the PICC. }; // MIFARE constants that does not fit anywhere else @@ -223,7 +223,7 @@ public: // PICC types we can detect. Remember to update PICC_GetTypeName() if you add more. // last value set to 0xff, then compiler uses less ram, it seems some optimisations are triggered - enum PICC_Type : byte { + enum PICC_Type : uint8_t { PICC_TYPE_UNKNOWN , PICC_TYPE_ISO_14443_4 , // PICC compliant with ISO/IEC 14443-4 PICC_TYPE_ISO_18092 , // PICC compliant with ISO/IEC 18092 (NFC) @@ -239,7 +239,7 @@ public: // Return codes from the functions in this class. Remember to update GetStatusCodeName() if you add more. // last value set to 0xff, then compiler uses less ram, it seems some optimisations are triggered - enum StatusCode : byte { + enum StatusCode : uint8_t { STATUS_OK , // Success STATUS_ERROR , // Error in communication STATUS_COLLISION , // Collission detected @@ -253,14 +253,14 @@ public: // A struct used for passing the UID of a PICC. typedef struct { - byte size; // Number of bytes in the UID. 4, 7 or 10. - byte uidByte[10]; - byte sak; // The SAK (Select acknowledge) byte returned from the PICC after successful selection. + uint8_t size; // Number of bytes in the UID. 4, 7 or 10. + uint8_t uidByte[10]; + uint8_t sak; // The SAK (Select acknowledge) uint8_t returned from the PICC after successful selection. } Uid; // A struct used for passing a MIFARE Crypto1 key typedef struct { - byte keyByte[MF_KEY_SIZE]; + uint8_t keyByte[MF_KEY_SIZE]; } MIFARE_Key; // Member variables @@ -270,31 +270,31 @@ public: // Functions for setting up the Arduino ///////////////////////////////////////////////////////////////////////////////////// MFRC522(); - MFRC522(byte resetPowerDownPin); - MFRC522(byte chipSelectPin, byte resetPowerDownPin); + MFRC522(uint8_t resetPowerDownPin); + MFRC522(uint8_t chipSelectPin, uint8_t resetPowerDownPin); ///////////////////////////////////////////////////////////////////////////////////// // Basic interface functions for communicating with the MFRC522 ///////////////////////////////////////////////////////////////////////////////////// - void PCD_WriteRegister(PCD_Register reg, byte value); - void PCD_WriteRegister(PCD_Register reg, byte count, byte *values); - byte PCD_ReadRegister(PCD_Register reg); - void PCD_ReadRegister(PCD_Register reg, byte count, byte *values, byte rxAlign = 0); - void PCD_SetRegisterBitMask(PCD_Register reg, byte mask); - void PCD_ClearRegisterBitMask(PCD_Register reg, byte mask); - StatusCode PCD_CalculateCRC(byte *data, byte length, byte *result); + void PCD_WriteRegister(PCD_Register reg, uint8_t value); + void PCD_WriteRegister(PCD_Register reg, uint8_t count, uint8_t *values); + uint8_t PCD_ReadRegister(PCD_Register reg); + void PCD_ReadRegister(PCD_Register reg, uint8_t count, uint8_t *values, uint8_t rxAlign = 0); + void PCD_SetRegisterBitMask(PCD_Register reg, uint8_t mask); + void PCD_ClearRegisterBitMask(PCD_Register reg, uint8_t mask); + StatusCode PCD_CalculateCRC(uint8_t *data, uint8_t length, uint8_t *result); ///////////////////////////////////////////////////////////////////////////////////// // Functions for manipulating the MFRC522 ///////////////////////////////////////////////////////////////////////////////////// void PCD_Init(); - void PCD_Init(byte resetPowerDownPin); - void PCD_Init(byte chipSelectPin, byte resetPowerDownPin); + void PCD_Init(uint8_t resetPowerDownPin); + void PCD_Init(uint8_t chipSelectPin, uint8_t resetPowerDownPin); void PCD_Reset(); void PCD_AntennaOn(); void PCD_AntennaOff(); - byte PCD_GetAntennaGain(); - void PCD_SetAntennaGain(byte mask); + uint8_t PCD_GetAntennaGain(); + void PCD_SetAntennaGain(uint8_t mask); bool PCD_PerformSelfTest(); ///////////////////////////////////////////////////////////////////////////////////// @@ -306,40 +306,40 @@ public: ///////////////////////////////////////////////////////////////////////////////////// // Functions for communicating with PICCs ///////////////////////////////////////////////////////////////////////////////////// - StatusCode PCD_TransceiveData(byte *sendData, byte sendLen, byte *backData, byte *backLen, byte *validBits = nullptr, byte rxAlign = 0, bool checkCRC = false); - StatusCode PCD_CommunicateWithPICC(byte command, byte waitIRq, byte *sendData, byte sendLen, byte *backData = nullptr, byte *backLen = nullptr, byte *validBits = nullptr, byte rxAlign = 0, bool checkCRC = false); - StatusCode PICC_RequestA(byte *bufferATQA, byte *bufferSize); - StatusCode PICC_WakeupA(byte *bufferATQA, byte *bufferSize); - StatusCode PICC_REQA_or_WUPA(byte command, byte *bufferATQA, byte *bufferSize); - virtual StatusCode PICC_Select(Uid *uid, byte validBits = 0); + StatusCode PCD_TransceiveData(uint8_t *sendData, uint8_t sendLen, uint8_t *backData, uint8_t *backLen, uint8_t *validBits = nullptr, uint8_t rxAlign = 0, bool checkCRC = false); + StatusCode PCD_CommunicateWithPICC(uint8_t command, uint8_t waitIRq, uint8_t *sendData, uint8_t sendLen, uint8_t *backData = nullptr, uint8_t *backLen = nullptr, uint8_t *validBits = nullptr, uint8_t rxAlign = 0, bool checkCRC = false); + StatusCode PICC_RequestA(uint8_t *bufferATQA, uint8_t *bufferSize); + StatusCode PICC_WakeupA(uint8_t *bufferATQA, uint8_t *bufferSize); + StatusCode PICC_REQA_or_WUPA(uint8_t command, uint8_t *bufferATQA, uint8_t *bufferSize); + virtual StatusCode PICC_Select(Uid *uid, uint8_t validBits = 0); StatusCode PICC_HaltA(); ///////////////////////////////////////////////////////////////////////////////////// // Functions for communicating with MIFARE PICCs ///////////////////////////////////////////////////////////////////////////////////// - StatusCode PCD_Authenticate(byte command, byte blockAddr, MIFARE_Key *key, Uid *uid); + StatusCode PCD_Authenticate(uint8_t command, uint8_t blockAddr, MIFARE_Key *key, Uid *uid); void PCD_StopCrypto1(); - StatusCode MIFARE_Read(byte blockAddr, byte *buffer, byte *bufferSize); - StatusCode MIFARE_Write(byte blockAddr, byte *buffer, byte bufferSize); - StatusCode MIFARE_Ultralight_Write(byte page, byte *buffer, byte bufferSize); - StatusCode MIFARE_Decrement(byte blockAddr, int32_t delta); - StatusCode MIFARE_Increment(byte blockAddr, int32_t delta); - StatusCode MIFARE_Restore(byte blockAddr); - StatusCode MIFARE_Transfer(byte blockAddr); - StatusCode MIFARE_GetValue(byte blockAddr, int32_t *value); - StatusCode MIFARE_SetValue(byte blockAddr, int32_t value); - StatusCode PCD_NTAG216_AUTH(byte *passWord, byte pACK[]); + StatusCode MIFARE_Read(uint8_t blockAddr, uint8_t *buffer, uint8_t *bufferSize); + StatusCode MIFARE_Write(uint8_t blockAddr, uint8_t *buffer, uint8_t bufferSize); + StatusCode MIFARE_Ultralight_Write(uint8_t page, uint8_t *buffer, uint8_t bufferSize); + StatusCode MIFARE_Decrement(uint8_t blockAddr, int32_t delta); + StatusCode MIFARE_Increment(uint8_t blockAddr, int32_t delta); + StatusCode MIFARE_Restore(uint8_t blockAddr); + StatusCode MIFARE_Transfer(uint8_t blockAddr); + StatusCode MIFARE_GetValue(uint8_t blockAddr, int32_t *value); + StatusCode MIFARE_SetValue(uint8_t blockAddr, int32_t value); + StatusCode PCD_NTAG216_AUTH(uint8_t *passWord, uint8_t pACK[]); ///////////////////////////////////////////////////////////////////////////////////// // Support functions ///////////////////////////////////////////////////////////////////////////////////// - StatusCode PCD_MIFARE_Transceive(byte *sendData, byte sendLen, bool acceptTimeout = false); + StatusCode PCD_MIFARE_Transceive(uint8_t *sendData, uint8_t sendLen, bool acceptTimeout = false); // old function used too much memory, now name moved to flash; if you need char, copy from flash to memory - //const char *GetStatusCodeName(byte code); + //const char *GetStatusCodeName(uint8_t code); static const __FlashStringHelper *GetStatusCodeName(StatusCode code); - static PICC_Type PICC_GetType(byte sak); + static PICC_Type PICC_GetType(uint8_t sak); // old function used too much memory, now name moved to flash; if you need char, copy from flash to memory - //const char *PICC_GetTypeName(byte type); + //const char *PICC_GetTypeName(uint8_t type); static const __FlashStringHelper *PICC_GetTypeName(PICC_Type type); // Support functions for debuging @@ -347,13 +347,13 @@ public: void PICC_DumpToSerial(Uid *uid); void PICC_DumpDetailsToSerial(Uid *uid); void PICC_DumpMifareClassicToSerial(Uid *uid, PICC_Type piccType, MIFARE_Key *key); - void PICC_DumpMifareClassicSectorToSerial(Uid *uid, MIFARE_Key *key, byte sector); + void PICC_DumpMifareClassicSectorToSerial(Uid *uid, MIFARE_Key *key, uint8_t sector); void PICC_DumpMifareUltralightToSerial(); // Advanced functions for MIFARE - void MIFARE_SetAccessBits(byte *accessBitBuffer, byte g0, byte g1, byte g2, byte g3); + void MIFARE_SetAccessBits(uint8_t *accessBitBuffer, uint8_t g0, uint8_t g1, uint8_t g2, uint8_t g3); bool MIFARE_OpenUidBackdoor(bool logErrors); - bool MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors); + bool MIFARE_SetUid(uint8_t *newUid, uint8_t uidSize, bool logErrors); bool MIFARE_UnbrickUidSector(bool logErrors); ///////////////////////////////////////////////////////////////////////////////////// @@ -363,9 +363,9 @@ public: virtual bool PICC_ReadCardSerial(); protected: - byte _chipSelectPin; // Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low) - byte _resetPowerDownPin; // Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low) - StatusCode MIFARE_TwoStepHelper(byte command, byte blockAddr, int32_t data); + uint8_t _chipSelectPin; // Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low) + uint8_t _resetPowerDownPin; // Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low) + StatusCode MIFARE_TwoStepHelper(uint8_t command, uint8_t blockAddr, int32_t data); }; #endif diff --git a/lib/MechInputs/QEIx4.cpp b/lib/MechInputs/QEIx4.cpp index b62eb113b..bb260f53e 100644 --- a/lib/MechInputs/QEIx4.cpp +++ b/lib/MechInputs/QEIx4.cpp @@ -110,7 +110,7 @@ QEIx4* QEIx4::__instance[4] = { 0 }; QEIx4::QEIx4() { - for (byte i=0; i<4; i++) + for (uint8_t i=0; i<4; i++) if (__instance[i] == 0) { __instance[i] = this; @@ -130,7 +130,7 @@ QEIx4::QEIx4() QEIx4::~QEIx4() { - for (byte i=0; i<4; i++) + for (uint8_t i=0; i<4; i++) if (__instance[i] == this) { __instance[i] = 0; @@ -229,7 +229,7 @@ void ICACHE_RAM_ATTR QEIx4::processStateMachine() void ICACHE_RAM_ATTR QEIx4::ISR() { - for (byte i=0; i<4; i++) + for (uint8_t i=0; i<4; i++) if (__instance[i]) { __instance[i]->processStateMachine(); diff --git a/lib/RN2483-Arduino-Library/examples/TheThingsUno-GPSshield-TTN-Mapper-binary/TinyGPS++.cpp b/lib/RN2483-Arduino-Library/examples/TheThingsUno-GPSshield-TTN-Mapper-binary/TinyGPS++.cpp index ec234670b..57ff618cb 100644 --- a/lib/RN2483-Arduino-Library/examples/TheThingsUno-GPSshield-TTN-Mapper-binary/TinyGPS++.cpp +++ b/lib/RN2483-Arduino-Library/examples/TheThingsUno-GPSshield-TTN-Mapper-binary/TinyGPS++.cpp @@ -159,7 +159,7 @@ bool TinyGPSPlus::endOfTermHandler() // If it's the checksum term, and the checksum checks out, commit if (isChecksumTerm) { - byte checksum = 16 * fromHex(term[0]) + fromHex(term[1]); + uint8_t checksum = 16 * fromHex(term[0]) + fromHex(term[1]); if (checksum == parity) { passedChecksumCount++; diff --git a/lib/RN2483-Arduino-Library/src/rn2xx3.cpp b/lib/RN2483-Arduino-Library/src/rn2xx3.cpp index 57014aa88..fb3a07a11 100644 --- a/lib/RN2483-Arduino-Library/src/rn2xx3.cpp +++ b/lib/RN2483-Arduino-Library/src/rn2xx3.cpp @@ -43,7 +43,7 @@ bool rn2xx3::autobaud() { delay(1000); } - _rn2xx3_handler._serial.write((byte)0x00); + _rn2xx3_handler._serial.write((uint8_t)0x00); _rn2xx3_handler._serial.write(0x55); _rn2xx3_handler._serial.println(); @@ -127,7 +127,7 @@ RN2xx3_datatypes::TX_return_type rn2xx3::tx(const String& data, uint8_t port) return txUncnf(data, port); // we are unsure which mode we're in. Better not to wait for acks. } -RN2xx3_datatypes::TX_return_type rn2xx3::txBytes(const byte *data, uint8_t size, uint8_t port) +RN2xx3_datatypes::TX_return_type rn2xx3::txBytes(const uint8_t *data, uint8_t size, uint8_t port) { const String dataToTx = rn2xx3_helper::base16encode(data, size); return txCommand(F("mac tx uncnf "), dataToTx, false, port); diff --git a/lib/RN2483-Arduino-Library/src/rn2xx3.h b/lib/RN2483-Arduino-Library/src/rn2xx3.h index 11131afa6..808bcdf65 100644 --- a/lib/RN2483-Arduino-Library/src/rn2xx3.h +++ b/lib/RN2483-Arduino-Library/src/rn2xx3.h @@ -161,7 +161,7 @@ public: * This method expects a raw byte array as first parameter. * The second parameter is the count of the bytes to send. */ - RN2xx3_datatypes::TX_return_type txBytes(const byte *, + RN2xx3_datatypes::TX_return_type txBytes(const uint8_t *, uint8_t size, uint8_t port = 1); diff --git a/lib/RN2483-Arduino-Library/src/rn2xx3_helper.cpp b/lib/RN2483-Arduino-Library/src/rn2xx3_helper.cpp index 647eba8dc..91caa4536 100644 --- a/lib/RN2483-Arduino-Library/src/rn2xx3_helper.cpp +++ b/lib/RN2483-Arduino-Library/src/rn2xx3_helper.cpp @@ -86,7 +86,7 @@ String rn2xx3_helper::base16encode(const String& input_c) return output; } -String rn2xx3_helper::base16encode(const byte *data, uint8_t size) +String rn2xx3_helper::base16encode(const uint8_t *data, uint8_t size) { String dataToTx; diff --git a/lib/RN2483-Arduino-Library/src/rn2xx3_helper.h b/lib/RN2483-Arduino-Library/src/rn2xx3_helper.h index c93a3e71d..6f66236cd 100644 --- a/lib/RN2483-Arduino-Library/src/rn2xx3_helper.h +++ b/lib/RN2483-Arduino-Library/src/rn2xx3_helper.h @@ -31,7 +31,7 @@ public: * Encode binary data to a HEX string as needed when passed * to the RN2xx3 module. */ - static String base16encode(const byte *data, uint8_t size); + static String base16encode(const uint8_t *data, uint8_t size); }; diff --git a/lib/Regexp/src/Regexp.cpp b/lib/Regexp/src/Regexp.cpp index 472997050..a813690fa 100644 --- a/lib/Regexp/src/Regexp.cpp +++ b/lib/Regexp/src/Regexp.cpp @@ -257,10 +257,9 @@ PATTERNS // for throwing errors static jmp_buf regexp_error_return; -typedef unsigned char byte; // error codes raised during regexp processing -static byte error (const char err) +static uint8_t error (const char err) { // does not return longjmp (regexp_error_return, err); diff --git a/lib/SerialDevices/SensorSerialBuffer.cpp b/lib/SerialDevices/SensorSerialBuffer.cpp index f69b6ed42..e6a6c0651 100644 --- a/lib/SerialDevices/SensorSerialBuffer.cpp +++ b/lib/SerialDevices/SensorSerialBuffer.cpp @@ -34,23 +34,23 @@ CSensorSerialBuffer::CSensorSerialBuffer() void CSensorSerialBuffer::Clear () { - for (byte i=0; irequestFrom(((uint8_t)(((DeviceAddr) >> 1) & 0x7F)), (byte)NumByteToRead); + dev_i2c->requestFrom(((uint8_t)(((DeviceAddr) >> 1) & 0x7F)), (uint8_t)NumByteToRead); int i = 0; while (dev_i2c->available()) diff --git a/lib/TinyGPSPlus-1.0.2/src/TinyGPS++.cpp b/lib/TinyGPSPlus-1.0.2/src/TinyGPS++.cpp index ed4485c42..61d286f75 100644 --- a/lib/TinyGPSPlus-1.0.2/src/TinyGPS++.cpp +++ b/lib/TinyGPSPlus-1.0.2/src/TinyGPS++.cpp @@ -172,7 +172,7 @@ bool TinyGPSPlus::endOfTermHandler() // If it's the checksum term, and the checksum checks out, commit if (isChecksumTerm) { - byte checksum = 16 * fromHex(term[0]) + fromHex(term[1]); + uint8_t checksum = 16 * fromHex(term[0]) + fromHex(term[1]); if (checksum == parity) { passedChecksumCount++; @@ -447,7 +447,7 @@ void TinyGPSSatellites::commit() satsTracked = 0; satsVisible = 0; bestSNR = 0; - for (byte i = 0; i < _GPS_MAX_ARRAY_LENGTH; ++i) { + for (uint8_t i = 0; i < _GPS_MAX_ARRAY_LENGTH; ++i) { if (id[i] != 0) { if (snr[i] != 0) { ++satsTracked; @@ -531,7 +531,7 @@ void TinyGPSSatellites::setSatId(const char *term) ++pos; uint32_t value = atol(term); if (id[pos] != value) { - id[pos] = static_cast(value); + id[pos] = static_cast(value); snr[pos] = 0; } } @@ -551,7 +551,7 @@ void TinyGPSSatellites::setMessageSeqNr(const char *term, uint8_t sentenceSystem int32_t seqNr = atol(term); int32_t newPos = (seqNr - 1) * 4 + (sentenceSystem * _GPS_MAX_NR_ACTIVE_SATELLITES); if (newPos >= 0 && newPos < _GPS_MAX_ARRAY_LENGTH) { - for (byte i = newPos; i < (newPos + 4) && i < _GPS_MAX_ARRAY_LENGTH; ++i) { + for (uint8_t i = newPos; i < (newPos + 4) && i < _GPS_MAX_ARRAY_LENGTH; ++i) { id[i] = 0; snr[i] = 0; } diff --git a/lib/esp8266-oled-ssd1306/OLEDDisplay.cpp b/lib/esp8266-oled-ssd1306/OLEDDisplay.cpp index 3caecc5b2..600286e36 100644 --- a/lib/esp8266-oled-ssd1306/OLEDDisplay.cpp +++ b/lib/esp8266-oled-ssd1306/OLEDDisplay.cpp @@ -409,15 +409,15 @@ void OLEDDisplay::drawStringInternal(int16_t xMove, int16_t yMove, char* text, u int16_t xPos = xMove + cursorX; int16_t yPos = yMove + cursorY; - byte code = text[j]; + uint8_t code = text[j]; if (code >= firstChar) { - byte charCode = code - firstChar; + uint8_t charCode = code - firstChar; // 4 Bytes per char code - byte msbJumpToChar = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES ); // MSB \ JumpAddress - byte lsbJumpToChar = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES + JUMPTABLE_LSB); // LSB / - byte charByteSize = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES + JUMPTABLE_SIZE); // Size - byte currentCharWidth = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES + JUMPTABLE_WIDTH); // Width + uint8_t msbJumpToChar = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES ); // MSB \ JumpAddress + uint8_t lsbJumpToChar = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES + JUMPTABLE_LSB); // LSB / + uint8_t charByteSize = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES + JUMPTABLE_SIZE); // Size + uint8_t currentCharWidth = pgm_read_byte( fontData + JUMPTABLE_START + charCode * JUMPTABLE_BYTES + JUMPTABLE_WIDTH); // Width // Test if the char is drawable if (!(msbJumpToChar == 255 && lsbJumpToChar == 255)) { @@ -740,7 +740,7 @@ void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t widt yOffset = initYOffset; } - byte currentByte = pgm_read_byte(data + offset + i); + uint8_t currentByte = pgm_read_byte(data + offset + i); int16_t xPos = xMove + (i / rasterHeight); int16_t yPos = ((yMove >> 3) + (i % rasterHeight)) * this->width(); @@ -787,7 +787,7 @@ void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t widt } // Code form http://playground.arduino.cc/Main/Utf8ascii -uint8_t OLEDDisplay::utf8ascii(byte ascii) { +uint8_t OLEDDisplay::utf8ascii(uint8_t ascii) { static uint8_t LASTCHAR; if ( ascii < 128 ) { // Standard ASCII-set 0..0x7F handling diff --git a/lib/esp8266-oled-ssd1306/OLEDDisplay.h b/lib/esp8266-oled-ssd1306/OLEDDisplay.h index 87a70195f..88955f6df 100644 --- a/lib/esp8266-oled-ssd1306/OLEDDisplay.h +++ b/lib/esp8266-oled-ssd1306/OLEDDisplay.h @@ -164,7 +164,7 @@ class OLEDDisplay : public Print { void drawVerticalLine(int16_t x, int16_t y, int16_t length); // Draws a rounded progress bar with the outer dimensions given by width and height. Progress is - // a unsigned byte value between 0 and 100 + // a unsigned uint8_t value between 0 and 100 void drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t progress); // Draw a bitmap in the internal image format @@ -277,7 +277,7 @@ class OLEDDisplay : public Print { // converts utf8 characters to extended ascii static char* utf8ascii(String s); - static byte utf8ascii(byte ascii); + static uint8_t utf8ascii(uint8_t ascii); void inline drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const char *data, uint16_t offset, uint16_t bytesInData) __attribute__((always_inline)); diff --git a/lib/esp8266-oled-ssd1306/OLEDDisplayUi.cpp b/lib/esp8266-oled-ssd1306/OLEDDisplayUi.cpp index 976bbac42..85d1e9944 100644 --- a/lib/esp8266-oled-ssd1306/OLEDDisplayUi.cpp +++ b/lib/esp8266-oled-ssd1306/OLEDDisplayUi.cpp @@ -363,7 +363,7 @@ void OLEDDisplayUi::drawIndicator() { uint16_t frameStartPos = (12 * frameCount / 2); const char *image; uint16_t x = 0, y = 0; - for (byte i = 0; i < this->frameCount; i++) { + for (uint8_t i = 0; i < this->frameCount; i++) { switch (this->indicatorPosition){ case TOP: diff --git a/lib/esp8266-oled-ssd1306/SH1106Brzo.h b/lib/esp8266-oled-ssd1306/SH1106Brzo.h index 385630b32..4acdfd86e 100644 --- a/lib/esp8266-oled-ssd1306/SH1106Brzo.h +++ b/lib/esp8266-oled-ssd1306/SH1106Brzo.h @@ -85,7 +85,7 @@ class SH1106Brzo : public OLEDDisplay { // holdes true for all values of pos if (minBoundY == ~0) return; - byte k = 0; + uint8_t k = 0; uint8_t sendBuffer[17]; sendBuffer[0] = 0x40; diff --git a/lib/esp8266-oled-ssd1306/SH1106Wire.h b/lib/esp8266-oled-ssd1306/SH1106Wire.h index 3aeb5caf8..25650e8cc 100644 --- a/lib/esp8266-oled-ssd1306/SH1106Wire.h +++ b/lib/esp8266-oled-ssd1306/SH1106Wire.h @@ -90,7 +90,7 @@ class SH1106Wire : public OLEDDisplay { uint8_t minBoundXp2H = (minBoundX + 2) & 0x0F; uint8_t minBoundXp2L = 0x10 | ((minBoundX + 2) >> 4 ); - byte k = 0; + uint8_t k = 0; for (y = minBoundY; y <= maxBoundY; y++) { sendCommand(0xB0 + y); sendCommand(minBoundXp2H); diff --git a/lib/esp8266-oled-ssd1306/SSD1306Brzo.h b/lib/esp8266-oled-ssd1306/SSD1306Brzo.h index 3b99d82d2..35708d205 100644 --- a/lib/esp8266-oled-ssd1306/SSD1306Brzo.h +++ b/lib/esp8266-oled-ssd1306/SSD1306Brzo.h @@ -94,7 +94,7 @@ class SSD1306Brzo : public OLEDDisplay { sendCommand(minBoundY); sendCommand(maxBoundY); - byte k = 0; + uint8_t k = 0; uint8_t sendBuffer[17]; sendBuffer[0] = 0x40; brzo_i2c_start_transaction(this->_address, BRZO_I2C_SPEED); diff --git a/lib/esp8266-oled-ssd1306/SSD1306Wire.h b/lib/esp8266-oled-ssd1306/SSD1306Wire.h index 383a8c8f6..95421f0c7 100644 --- a/lib/esp8266-oled-ssd1306/SSD1306Wire.h +++ b/lib/esp8266-oled-ssd1306/SSD1306Wire.h @@ -89,7 +89,7 @@ class SSD1306Wire : public OLEDDisplay { sendCommand(minBoundY); sendCommand(maxBoundY); - byte k = 0; + uint8_t k = 0; for (y = minBoundY; y <= maxBoundY; y++) { for (x = minBoundX; x <= maxBoundX; x++) { if (k == 0) {