Add initial AVR PROGMEM abstraction in hal::progmem
parent
9efb127acb
commit
a9937b94e2
|
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __AVR__
|
||||
#include <avr/progmem.h>
|
||||
#else
|
||||
#define PROGMEM // ignored
|
||||
#endif
|
||||
|
||||
namespace hal {
|
||||
|
||||
/// AVR PROGMEM handling
|
||||
namespace progmem {
|
||||
|
||||
/// read a 16bit word from PROGMEM
|
||||
static inline uint16_t pgm_read_word(const uint16_t* addr)
|
||||
{
|
||||
#ifndef __AVR__
|
||||
return *addr;
|
||||
#else
|
||||
return (uint16_t)::pgm_read_word(addr);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace progmem
|
||||
} // namespace hal
|
||||
|
|
@ -1 +1,2 @@
|
|||
add_subdirectory(circular_buffer)
|
||||
add_subdirectory(progmem)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
# define the test executable
|
||||
add_executable(progmem_tests test_progmem.cpp)
|
||||
|
||||
# define required search paths
|
||||
target_include_directories(progmem_tests PUBLIC ${CMAKE_SOURCE_DIR}/src/hal)
|
||||
|
||||
# tell build system about the test case
|
||||
add_catch_test(progmem_tests)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "progmem.h"
|
||||
|
||||
using Catch::Matchers::Equals;
|
||||
using hal::progmem::pgm_read_word;
|
||||
|
||||
TEST_CASE("progmem::basic", "[progmem]") {
|
||||
|
||||
// create a PROGMEM array
|
||||
const uint16_t arr[2] PROGMEM = {0, 1};
|
||||
|
||||
// ensure it can be read correctly
|
||||
REQUIRE(0 == pgm_read_word(&arr[0]));
|
||||
REQUIRE(1 == pgm_read_word(&arr[1]));
|
||||
}
|
||||
Loading…
Reference in New Issue