mirror of
https://github.com/esphome/esphome.git
synced 2026-05-28 13:37:24 +08:00
[core] Fix PROGMEM_STRING_TABLE placement on ESP8266 without flash log strings (#16373)
This commit is contained in:
+14
-2
@@ -25,6 +25,16 @@
|
|||||||
#define ESPHOME_strncasecmp_P strncasecmp_P
|
#define ESPHOME_strncasecmp_P strncasecmp_P
|
||||||
// Type for pointers to PROGMEM strings (for use with ESPHOME_F return values)
|
// Type for pointers to PROGMEM strings (for use with ESPHOME_F return values)
|
||||||
using ProgmemStr = const __FlashStringHelper *;
|
using ProgmemStr = const __FlashStringHelper *;
|
||||||
|
// Storage class for PROGMEM_STRING_TABLE data. Mirrors the logger's choice of
|
||||||
|
// LOG_STR_ARG: when LOG_STR_ARG treats the LogString as PROGMEM (PGM_P), the
|
||||||
|
// table data must actually be in flash; when LOG_STR_ARG treats it as a plain
|
||||||
|
// const char* (assumes RAM), the table data must live in RAM or non-logger
|
||||||
|
// consumers (ArduinoJson, Print, MQTT publish) crash on unaligned flash reads.
|
||||||
|
#ifdef USE_STORE_LOG_STR_IN_FLASH
|
||||||
|
#define ESPHOME_PROGMEM_STRING_TABLE_STORAGE PROGMEM
|
||||||
|
#else
|
||||||
|
#define ESPHOME_PROGMEM_STRING_TABLE_STORAGE
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#define ESPHOME_F(string_literal) (string_literal)
|
#define ESPHOME_F(string_literal) (string_literal)
|
||||||
#define ESPHOME_PGM_P const char *
|
#define ESPHOME_PGM_P const char *
|
||||||
@@ -38,6 +48,8 @@ using ProgmemStr = const __FlashStringHelper *;
|
|||||||
#define ESPHOME_strncasecmp_P strncasecmp
|
#define ESPHOME_strncasecmp_P strncasecmp
|
||||||
// Type for pointers to strings (no PROGMEM on non-ESP8266 platforms)
|
// Type for pointers to strings (no PROGMEM on non-ESP8266 platforms)
|
||||||
using ProgmemStr = const char *;
|
using ProgmemStr = const char *;
|
||||||
|
// No-op on non-ESP8266 platforms where PROGMEM itself is a no-op.
|
||||||
|
#define ESPHOME_PROGMEM_STRING_TABLE_STORAGE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
@@ -100,8 +112,8 @@ struct LogString;
|
|||||||
static constexpr size_t COUNT = Table::COUNT; \
|
static constexpr size_t COUNT = Table::COUNT; \
|
||||||
static constexpr uint8_t LAST_INDEX = COUNT - 1; \
|
static constexpr uint8_t LAST_INDEX = COUNT - 1; \
|
||||||
static constexpr size_t BLOB_SIZE = Table::BLOB_SIZE; \
|
static constexpr size_t BLOB_SIZE = Table::BLOB_SIZE; \
|
||||||
static constexpr auto BLOB PROGMEM = Table::make_blob(); \
|
static constexpr auto BLOB ESPHOME_PROGMEM_STRING_TABLE_STORAGE = Table::make_blob(); \
|
||||||
static constexpr auto OFFSETS PROGMEM = Table::make_offsets(); \
|
static constexpr auto OFFSETS ESPHOME_PROGMEM_STRING_TABLE_STORAGE = Table::make_offsets(); \
|
||||||
static const char *get_(uint8_t idx, uint8_t fallback) { \
|
static const char *get_(uint8_t idx, uint8_t fallback) { \
|
||||||
if (idx >= COUNT) \
|
if (idx >= COUNT) \
|
||||||
idx = fallback; \
|
idx = fallback; \
|
||||||
|
|||||||
Reference in New Issue
Block a user