progmem: fix for AVR

- Fix header name
- Rename pgm_read_word to read_word since pgm_read_word is a macro
  and cannot be scoped
pull/41/head
Yuri D'Elia 2021-07-03 21:36:46 +02:00 committed by DRracer
parent a9937b94e2
commit ea8b335f8d
2 changed files with 7 additions and 7 deletions

View File

@ -2,7 +2,7 @@
#include <stdint.h> #include <stdint.h>
#ifdef __AVR__ #ifdef __AVR__
#include <avr/progmem.h> #include <avr/pgmspace.h>
#else #else
#define PROGMEM // ignored #define PROGMEM // ignored
#endif #endif
@ -13,12 +13,12 @@ namespace hal {
namespace progmem { namespace progmem {
/// read a 16bit word from PROGMEM /// read a 16bit word from PROGMEM
static inline uint16_t pgm_read_word(const uint16_t* addr) static inline uint16_t read_word(const uint16_t* addr)
{ {
#ifndef __AVR__ #ifndef __AVR__
return *addr; return *addr;
#else #else
return (uint16_t)::pgm_read_word(addr); return (uint16_t)pgm_read_word(addr);
#endif #endif
} }

View File

@ -2,14 +2,14 @@
#include "progmem.h" #include "progmem.h"
using Catch::Matchers::Equals; using Catch::Matchers::Equals;
using hal::progmem::pgm_read_word; namespace pm = hal::progmem;
TEST_CASE("progmem::basic", "[progmem]") { TEST_CASE("progmem::read_word", "[progmem]") {
// create a PROGMEM array // create a PROGMEM array
const uint16_t arr[2] PROGMEM = {0, 1}; const uint16_t arr[2] PROGMEM = {0, 1};
// ensure it can be read correctly // ensure it can be read correctly
REQUIRE(0 == pgm_read_word(&arr[0])); REQUIRE(0 == pm::read_word(&arr[0]));
REQUIRE(1 == pgm_read_word(&arr[1])); REQUIRE(1 == pm::read_word(&arr[1]));
} }