* [pin_remap 1/3] platform: define ARDUINO_CORE_BUILD when building core files * [pin_remap 2/3] core,libs: add pin remap hooks * platform: remove previous build options if file is missing "touch" would create the file if not present, but not delete its contents if a previous run left the file in the build dir. * platform: make debug_custom.json file customizable by board * platform: fix default debug prefix "debug.toolchain.prefix" must end with a dash, since only the tool name is appended to this string. The reason this is not a major issue is that the "debug_custom.json" file (copied in the sketch directory when debugging is enabled) forces its own prefix. And to make things more interesting, the "toolchainPrefix" entry in that file should _not_ end with a dash. * [pin_remap 3/3]: add Arduino Nano ESP32 board * fix: periman: include it by default, add include guard * fix: io_pin_remap: adjust for new perimap APIs * fix: libraries: manually handled pin remapping files Previously all libraries invoked either high-level APIs (transparently remapped, like the user sketch) or low-level ESP-IDF calls (where the remap to GPIO numbers had to be added manually). Since 3.x, some of these are mixed (for example, periman* APIs are remapped, while soc* are not). This must be handled by disabling the automatic API remapping and making sure all calls use GPIO numbers. * feat: show remapped pins in chip debug reports --------- Co-authored-by: Jan Procházka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
68 lines
2.2 KiB
C
68 lines
2.2 KiB
C
#include <string.h>
|
|
|
|
#include <esp_system.h>
|
|
#include <esp32s3/rom/cache.h>
|
|
#include <esp_heap_caps.h>
|
|
|
|
#include "double_tap.h"
|
|
|
|
#define NUM_TOKENS 3
|
|
static const uint32_t MAGIC_TOKENS[NUM_TOKENS] = {
|
|
0xf01681de, 0xbd729b29, 0xd359be7a,
|
|
};
|
|
|
|
static void *magic_area;
|
|
static uint32_t backup_area[NUM_TOKENS];
|
|
|
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
|
// Current IDF does not map external RAM to a fixed address.
|
|
// The actual VMA depends on other enabled devices, so the precise
|
|
// location must be discovered.
|
|
#include <esp_psram.h>
|
|
#include <esp_private/esp_psram_extram.h>
|
|
static uintptr_t get_extram_data_high(void) {
|
|
// get a pointer into SRAM area (only the address is useful)
|
|
void *psram_ptr = heap_caps_malloc(16, MALLOC_CAP_SPIRAM);
|
|
heap_caps_free(psram_ptr);
|
|
|
|
// keep moving backwards until leaving PSRAM area
|
|
uintptr_t psram_base_addr = (uintptr_t) psram_ptr;
|
|
psram_base_addr &= ~(CONFIG_MMU_PAGE_SIZE - 1); // align to start of page
|
|
while (esp_psram_check_ptr_addr((void *) psram_base_addr)) {
|
|
psram_base_addr -= CONFIG_MMU_PAGE_SIZE;
|
|
}
|
|
|
|
// offset is one page from start of PSRAM
|
|
return psram_base_addr + CONFIG_MMU_PAGE_SIZE + esp_psram_get_size();
|
|
}
|
|
#else
|
|
#include <soc/soc.h>
|
|
#define get_extram_data_high() ((uintptr_t) SOC_EXTRAM_DATA_HIGH)
|
|
#endif
|
|
|
|
|
|
void double_tap_init(void) {
|
|
// magic location block ends 0x20 bytes from end of PSRAM
|
|
magic_area = (void *) (get_extram_data_high() - 0x20 - sizeof(MAGIC_TOKENS));
|
|
}
|
|
|
|
void double_tap_mark() {
|
|
memcpy(backup_area, magic_area, sizeof(MAGIC_TOKENS));
|
|
memcpy(magic_area, MAGIC_TOKENS, sizeof(MAGIC_TOKENS));
|
|
Cache_WriteBack_Addr((uintptr_t) magic_area, sizeof(MAGIC_TOKENS));
|
|
}
|
|
|
|
void double_tap_invalidate() {
|
|
if (memcmp(backup_area, MAGIC_TOKENS, sizeof(MAGIC_TOKENS))) {
|
|
// different contents: restore backup
|
|
memcpy(magic_area, backup_area, sizeof(MAGIC_TOKENS));
|
|
} else {
|
|
// clear memory
|
|
memset(magic_area, 0, sizeof(MAGIC_TOKENS));
|
|
}
|
|
Cache_WriteBack_Addr((uintptr_t) magic_area, sizeof(MAGIC_TOKENS));
|
|
}
|
|
|
|
bool double_tap_check_match() {
|
|
return (memcmp(magic_area, MAGIC_TOKENS, sizeof(MAGIC_TOKENS)) == 0);
|
|
}
|