#ifndef CAMPO_LAYOUTS_V7_H
#define CAMPO_LAYOUTS_V7_H
//----------------------------------------------------------------------------
///
/// \brief  Campo layouts
///
///         EEPROM layouts for various boards
//
/// \date   20250111
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


// hwdata_gen does include all headers
#if 0

#if defined CAMPO_LAYOUTS_V6_H
   #error Layout V6 was already included
#endif

#if defined CAMPO_LAYOUTS_V5_H
#error Layout V5 was already included
#endif

#endif

#include <stdint.h>
#include <lepto/lepto.h>
#include <biwak/retain.h>


//---Defines------------------------------------------------------------------


#if IS_ENABLED( CONFIG_VAGUS_HWINFO_V5 )
   // #error This file should not be included; Layout V5 was specified
#endif

#if IS_ENABLED( CONFIG_VAGUS_HWINFO_V6 )
   //#error This file should not be included; Layout V6 was specified
#endif


/**
   [SEepromHwData                  ]    0x20
   [...SEepromHwData] [RetainHeader]    0x20
   [SEepromConfig 1 ] [RetainHeader]    0x20
   [SEepromConfig 2 ] [RetainHeader]    0x20

   SEepromHwData
      SEepromBoardInfo                0x20
      SEepromBoardConfig              0x20-0xC=0x14
   SEepromConfig
      nodeId
 */

namespace V7{};
#if ! defined( BOARDINFO_LAYOUT_MINOR )

   #define BOARDINFO_LAYOUT_MAJOR     7
   #define BOARDINFO_LAYOUT_MINOR     0
   using namespace V7;

#endif


//---Declaration--------------------------------------------------------------


#undef PHONY_PACKED
// #define PHONY_PACKED __attribute ((packed))
#define PHONY_PACKED


namespace V7
{

struct SEepromHwData
{
   char magic;                      // 0x0..0x0: 'M\0'
   char reserved1;                  // 0x1
   char reserved2;                  // 0x2
   char reserved3;                  // 0x3
   
   struct
   {
      struct // 2 x int32
      {
         // LPB-Code is following 32bit
         uint16_t articleId;           // 0x4..0x5
         uint8_t  boardCode;           // 0x6
         uint8_t  boardRevision;       // 0x7
         uint8_t  boardSubRevision;    // 0x8   // not usefull
         uint8_t  boardPatch;          // 0x9
         uint8_t  reserved_m1;         // 0xA
         uint8_t  reserved_m2;         // 0xB
      } PHONY_PACKED main;
   
      struct // 2 x int32
      {
         uint32_t serialNumber;        // 0x10...13
         uint16_t dateYear;            // 0xC..0xD
         uint8_t dateMonth;            // 0xE
         uint8_t dateDay;              // 0xF
      } PHONY_PACKED production;
   } boardInfo;
   
   struct
   {
      struct // 4 x int32
      {
         uint32_t variant;             // 0x14 ... 0x17: For single-PCB-products; e.g. Miniminutnik 'Corona'
         uint32_t flags;               // 0x18 ... 0x1B
         uint32_t issues;              // 0x1C ... 0x1F
         uint16_t defaultNodeId;        // 0x20    // not usefull
         uint8_t itemCount;            // 0x21
         uint8_t patch;                // 0x22
      } PHONY_PACKED config;
      
      struct // 4 x int32
      {
         uint32_t value[ 4 ];          // 0x24 ... 0x33
                                       // 0x34
      } PHONY_PACKED calib;
   } boardConfig;
   
   uint8_t reserved4[ 0x40 - RETAIN_HEADER_SIZE - 0x34 ];
} PHONY_PACKED;


struct SEepromConfigBase
{
   unsigned int nodeId;    // 0x00 ... 0x03
                           // 0x04
   //uint8_t custom[ 0x20 - RETAIN_HEADER_SIZE - 0x04 ];
} PHONY_PACKED;


static_assert( sizeof ( SEepromHwData ) == 0x40 - RETAIN_HEADER_SIZE );
static_assert( sizeof ( SEepromConfigBase ) <= 0x20 - RETAIN_HEADER_SIZE );
static_assert( ( sizeof ( SEepromConfigBase ) & 3 ) == 0 );

}

//---fin----------------------------------------------------------------------
#endif // ? ! CAMPO_LAYOUTS_V7_H
