From f6d806841a2169c6ebe2d8150ae09037e85d649e Mon Sep 17 00:00:00 2001 From: Torsten Stauder Date: Fri, 15 Oct 2021 23:43:45 +0200 Subject: [PATCH] Fixing some LPCD-issues without port-expander --- src/RfidPn5180.cpp | 24 +++++++++++++++++------- src/main.cpp | 7 +------ src/revision.h | 2 +- src/settings-lolin_d32_pro_sdmmc_pe.h | 19 ++++++++++++++++++- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/RfidPn5180.cpp b/src/RfidPn5180.cpp index 7170e1d..91fcb91 100644 --- a/src/RfidPn5180.cpp +++ b/src/RfidPn5180.cpp @@ -51,6 +51,12 @@ extern unsigned long Rfid_LastRfidCheckTimestamp; void Rfid_Init(void) { #ifdef PN5180_ENABLE_LPCD + // Check if wakeup-reason was card-detection (PN5180 only) + // This only works if RFID.IRQ is connected to a GPIO and not to a port-expander + esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); + if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT1) { + Rfid_WakeupCheck(); + } // disable pin hold from deep sleep gpio_deep_sleep_hold_dis(); gpio_hold_dis(gpio_num_t(RFID_CS)); // NSS @@ -328,22 +334,25 @@ extern unsigned long Rfid_LastRfidCheckTimestamp; // wake up from LPCD, check card is present. This works only for ISO-14443 compatible cards void Rfid_WakeupCheck(void) { #ifdef PN5180_ENABLE_LPCD + // disable pin hold from deep sleep + gpio_deep_sleep_hold_dis(); + gpio_hold_dis(gpio_num_t(RFID_CS)); // NSS + gpio_hold_dis(gpio_num_t(RFID_RST)); // RST + #if (RFID_IRQ >= 0 && RFID_IRQ <= 39) + pinMode(RFID_IRQ, INPUT); + #endif static PN5180ISO14443 nfc14443(RFID_CS, RFID_BUSY, RFID_RST); nfc14443.begin(); nfc14443.reset(); + // enable RF field nfc14443.setupRF(); if (!nfc14443.isCardPresent()) { - nfc14443.clearIRQStatus(0xffffffff); - Serial.print(F("Logic-level at PN5180's IRQ-PIN: ")); - Serial.println(Port_Read(RFID_IRQ)); - // turn on LPCD + nfc14443.reset(); uint16_t wakeupCounterInMs = 0x3FF; // needs to be in the range of 0x0 - 0xA82. max wake-up time is 2960 ms. if (nfc14443.switchToLPCD(wakeupCounterInMs)) { Log_Println((char *) FPSTR(lowPowerCardSuccess), LOGLEVEL_INFO); // configure wakeup pin for deep-sleep wake-up, use ext1 - #if (RFID_IRQ >= 0 && RFID_IRQ <= 39) - esp_sleep_enable_ext1_wakeup((1ULL << (RFID_IRQ)), ESP_EXT1_WAKEUP_ALL_LOW); - #endif + esp_sleep_enable_ext1_wakeup((1ULL << (RFID_IRQ)), ESP_EXT1_WAKEUP_ANY_HIGH); // freeze pin states in deep sleep gpio_hold_en(gpio_num_t(RFID_CS)); // CS/NSS gpio_hold_en(gpio_num_t(RFID_RST)); // RST @@ -354,6 +363,7 @@ extern unsigned long Rfid_LastRfidCheckTimestamp; Serial.println(F("switchToLPCD failed")); } } + nfc14443.end(); #endif } #endif diff --git a/src/main.cpp b/src/main.cpp index a74c69e..ecd38f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -131,12 +131,7 @@ void setup() { #ifdef RFID_READER_TYPE_PN5180 Rfid_Init(); #endif - // Check if wakeup-reason was card-detection (PN5180 only) - // This only works if RFID.IRQ is connected to a GPIO and not to a port-expander - esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); - if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT1) { - Rfid_WakeupCheck(); - } + System_Init(); memset(&gPlayProperties, 0, sizeof(gPlayProperties)); diff --git a/src/revision.h b/src/revision.h index 129cf7a..4587d87 100644 --- a/src/revision.h +++ b/src/revision.h @@ -1,4 +1,4 @@ #ifndef __REVISION_H__ #define __REVISION_H__ - constexpr const char softwareRevision[] PROGMEM = "Software-revision: 20211014-2"; + constexpr const char softwareRevision[] PROGMEM = "Software-revision: 20211015-1"; #endif \ No newline at end of file diff --git a/src/settings-lolin_d32_pro_sdmmc_pe.h b/src/settings-lolin_d32_pro_sdmmc_pe.h index 5a74cf0..ebc96f4 100644 --- a/src/settings-lolin_d32_pro_sdmmc_pe.h +++ b/src/settings-lolin_d32_pro_sdmmc_pe.h @@ -104,6 +104,23 @@ #endif #ifdef IR_CONTROL_ENABLE - // not supported by PCB! + #define IRLED_PIN 5 // GPIO where IR-receiver is connected (only tested with VS1838B) + #define IR_DEBOUNCE 200 // Interval in ms to wait at least for next signal (not used for actions volume up/down) + + // Actions available. Use your own remote control and have a look at the console for "Command=0x??". E.g. "Protocol=NEC Address=0x17F Command=0x68 Repeat gap=39750us" + // Make sure to define a hex-code not more than once as this will lead to a compile-error + // https://forum.espuino.de/t/neues-feature-fernsteuerung-per-infrarot-fernbedienung/265 + #define RC_PLAY 0x68 // command for play + #define RC_PAUSE 0x67 // command for pause + #define RC_NEXT 0x6b // command for next track of playlist + #define RC_PREVIOUS 0x6a // command for previous track of playlist + #define RC_FIRST 0x6c // command for first track of playlist + #define RC_LAST 0x6d // command for last track of playlist + #define RC_VOL_UP 0x1a // Command for volume up (one step) + #define RC_VOL_DOWN 0x1b // Command for volume down (one step) + #define RC_MUTE 0x1c // Command to mute ESPuino + #define RC_SHUTDOWN 0x2a // Command for deepsleep + #define RC_BLUETOOTH 0x72 // Command to enable/disable bluetooth + #define RC_FTP 0x65 // Command to enable FTP-server #endif #endif \ No newline at end of file