From 03e9d52e7de1bf5cd75edd9227f6be0173074772 Mon Sep 17 00:00:00 2001 From: kkloesener Date: Thu, 25 Mar 2021 13:56:50 +0100 Subject: [PATCH] rework actual codebase for rfid via i2c --- src/main.cpp | 11 ++++++----- src/settings-espa1s.h | 24 +++++++++++++++--------- src/settings.h | 16 ++++++++-------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2e840de..cbcb030 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -266,7 +266,7 @@ TaskHandle_t fileStorageTaskHandle; static TwoWire i2cBusTwo = TwoWire(1); #endif #ifdef RFID_READER_TYPE_MFRC522_I2C - static MFRC522 mfrc522(MFRC522_ADDR, MFRC522_RST_PIN, i2cBusTwo); + static MFRC522 mfrc522(MFRC522_ADDR, MFRC522_RST_PIN, &i2cBusTwo); #endif #ifdef PORT_EXPANDER_ENABLE @@ -276,7 +276,7 @@ TaskHandle_t fileStorageTaskHandle; #if (HAL == 2) #include "AC101.h" static TwoWire i2cBusOne = TwoWire(0); - static AC101 ac(i2cBusOne); + static AC101 ac(&i2cBusOne); #endif #ifdef RFID_READER_TYPE_MFRC522_SPI static MFRC522 mfrc522(RFID_CS, RST_PIN); @@ -1852,8 +1852,7 @@ void rfidScanner(void *parameter) { if (!mfrc522.PICC_ReadCardSerial()) { continue; } - - //mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); +// mfrc522.PICC_DumpToSerial(); mfrc522.PICC_HaltA(); mfrc522.PCD_StopCrypto1(); @@ -4746,7 +4745,8 @@ void setup() { loggerNl(serialDebug, (char *) FPSTR(rfidScannerReady), LOGLEVEL_DEBUG); #endif - #ifdef RFID_READER_TYPE_MFRC522_SPI + // Init RC522 Card-Reader + #if defined(RFID_READER_TYPE_MFRC522_I2C) || defined(RFID_READER_TYPE_MFRC522_SPI) mfrc522.PCD_Init(); mfrc522.PCD_SetAntennaGain(rfidGain); delay(50); @@ -5061,6 +5061,7 @@ void setup() { #ifdef BUTTON_5_ENABLE pinMode(BUTTON_5, INPUT_PULLUP); #endif + unsigned long currentTimestamp = millis(); // Init rotary encoder diff --git a/src/settings-espa1s.h b/src/settings-espa1s.h index cc119d3..ecadca6 100644 --- a/src/settings-espa1s.h +++ b/src/settings-espa1s.h @@ -22,14 +22,18 @@ #endif // RFID (via SPI; currently not supported) - #define RST_PIN 99 // Not necessary but has to be set anyway; so let's use a dummy-number - #define RFID_CS 21 // GPIO for chip select (RFID) - #define RFID_MOSI 23 // GPIO for master out slave in (RFID) - #define RFID_MISO 19 // GPIO for master in slave out (RFID) - #define RFID_SCK 18 // GPIO for clock-signal (RFID) + #if defined(RFID_READER_TYPE_MFRC522_SPI) + #define RST_PIN 99 // Not necessary but has to be set anyway; so let's use a dummy-number + #define RFID_CS 21 // GPIO for chip select (RFID) + #define RFID_MOSI 23 // GPIO for master out slave in (RFID) + #define RFID_MISO 19 // GPIO for master in slave out (RFID) + #define RFID_SCK 18 // GPIO for clock-signal (RFID) + #endif // RFID (via I2C) - #define MFRC522_RST_PIN 12 // needed for i2c-comm MTDI on JTAG + #if defined(RFID_READER_TYPE_MFRC522_I2C) + #define MFRC522_RST_PIN 12 // needed for initialisation -> MTDI on JTAG header + #endif // I2C-configuration (necessary for RC522 [only via i2c - not spi!] or port-expander) #if defined(RFID_READER_TYPE_MFRC522_I2C) || defined(PORT_EXPANDER_ENABLE) @@ -59,7 +63,7 @@ // Control-buttons (set to 99 to DISABLE; 0->39 for GPIO; 100->115 for port-expander) #define NEXT_BUTTON 199 // Button 0: GPIO to detect next - #define PREVIOUS_BUTTON 198 // Button 1: GPIO to detect previous (Important: as of 19.11.2020 changed from 33 to 2; make sure to change in SD-MMC-mode) + #define PREVIOUS_BUTTON 198 // Button 1: GPIO to detect previous #define PAUSEPLAY_BUTTON 36 // Button 2: GPIO to detect pause/play #define BUTTON_4 99 // Button 4: unnamed optional button #define BUTTON_5 99 // Button 5: unnamed optional button @@ -67,13 +71,15 @@ // Wake-up button => this also is the interrupt-pin if port-expander is enabled! // Please note: only RTC-GPIOs (0, 4, 12, 13, 14, 15, 25, 26, 27, 32, 33, 34, 35, 36, 39, 99) can be used! Set to 99 to DISABLE. // Please note #2: this button can be used as interrupt-pin for port-expander. If so, all pins connected to port-expander can wake up ESPuino. - #define WAKEUP_BUTTON DREHENCODER_BUTTON // Defines the button that is used to wake up ESPuino from deepsleep. + #define WAKEUP_BUTTON PAUSEPLAY_BUTTON // Defines the button that is used to wake up ESPuino from deepsleep. // Power-control #define POWER 19 // GPIO used to drive transistor-circuit, that switches off peripheral devices while ESP32-deepsleep // (optional) Neopixel - #define LED_PIN 23 // GPIO for Neopixel-signaling + #if defined(NEOPIXEL_ENABLE) + #define LED_PIN 23 // GPIO for Neopixel-signaling + #endif // (optinal) Headphone-detection #ifdef HEADPHONE_ADJUST_ENABLE diff --git a/src/settings.h b/src/settings.h index 26744d8..cc79957 100644 --- a/src/settings.h +++ b/src/settings.h @@ -25,30 +25,30 @@ //########################## MODULES ################################# //#define PORT_EXPANDER_ENABLE // When enabled, buttons can be connected via port-expander PCA9555 #define MDNS_ENABLE // When enabled, you don't have to handle with ESPuino's IP-address. If hostname is set to "ESPuino", you can reach it via ESPuino.local - #define MQTT_ENABLE // Make sure to configure mqtt-server and (optionally) username+pwd + //#define MQTT_ENABLE // Make sure to configure mqtt-server and (optionally) username+pwd #define FTP_ENABLE // Enables FTP-server; DON'T FORGET TO ACTIVATE AFTER BOOT BY PRESSING PAUSE + NEXT-BUTTONS (IN PARALLEL)! - #define NEOPIXEL_ENABLE // Don't forget configuration of NUM_LEDS if enabled + //#define NEOPIXEL_ENABLE // Don't forget configuration of NUM_LEDS if enabled //#define NEOPIXEL_REVERSE_ROTATION // Some Neopixels are adressed/soldered counter-clockwise. This can be configured here. #define LANGUAGE 1 // 1 = deutsch; 2 = english //#define STATIC_IP_ENABLE // Enables static IP-configuration (change static ip-section accordingly) //#define HEADPHONE_ADJUST_ENABLE // Used to adjust (lower) volume for optional headphone-pcb (refer maxVolumeSpeaker / maxVolumeHeadphone) #define SHUTDOWN_IF_SD_BOOT_FAILS // Will put ESP to deepsleep if boot fails due to SD. Really recommend this if there's in battery-mode no other way to restart ESP! Interval adjustable via deepsleepTimeAfterBootFails. - #define MEASURE_BATTERY_VOLTAGE // Enables battery-measurement via GPIO (ADC) and voltage-divider + //#define MEASURE_BATTERY_VOLTAGE // Enables battery-measurement via GPIO (ADC) and voltage-divider //#define PLAY_LAST_RFID_AFTER_REBOOT // When restarting ESPuino, the last RFID that was active before, is recalled and played //#define USE_LAST_VOLUME_AFTER_REBOOT // Remembers the volume used at last shutdown after reboot - #define USEROTARY_ENABLE // If rotary-encoder is used (don't forget to review WAKEUP_BUTTON if you disable this feature!) + //#define USEROTARY_ENABLE // If rotary-encoder is used (don't forget to review WAKEUP_BUTTON if you disable this feature!) #define BLUETOOTH_ENABLE // If enabled and bluetooth-mode is active, you can stream to your ESPuino via bluetooth (a2dp-sink). //#define IR_CONTROL_ENABLE // Enables remote control //################## select SD card mode ############################# //#define SD_MMC_1BIT_MODE // run SD card in SD-MMC 1Bit mode - //#define SINGLE_SPI_ENABLE // If only one SPI-instance should be used instead of two (not yet working!) (Works on ESP32-A1S with RFID via I2C) + //#define SINGLE_SPI_ENABLE // If only one SPI-instance should be used instead of two (not yet working!) //################## select RFID reader ############################## - #define RFID_READER_TYPE_MFRC522_SPI // use MFRC522 via SPI - //#define RFID_READER_TYPE_MFRC522_I2C // use MFRC522 via I2C + //#define RFID_READER_TYPE_MFRC522_SPI // use MFRC522 via SPI + #define RFID_READER_TYPE_MFRC522_I2C // use MFRC522 via I2C //#define RFID_READER_TYPE_PN5180 // use PN5180 #ifdef RFID_READER_TYPE_MFRC522_I2C @@ -59,7 +59,7 @@ //#define PN5180_ENABLE_LPCD // Wakes up ESPuino if RFID-tag was applied while deepsleep is active. #endif - #ifdef RFID_READER_TYPE_MFRC522_SPI + #if defined(RFID_READER_TYPE_MFRC522_I2C) || defined(RFID_READER_TYPE_MFRC522_SPI) uint8_t rfidGain = 0x07 << 4; // Sensitivity of RC522. For possible values see reference: https://forum.espuino.de/uploads/default/original/1X/9de5f8d35cbc123c1378cad1beceb3f51035cec0.png #endif