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


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


#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


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

   SEepromHwData
      SEepromBoardInfo                0x20
      SEepromBoardConfig
   SEepromConfig
      nodeId
 */

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

   #define BOARDINFO_LAYOUT_MAJOR     6
   #define BOARDINFO_LAYOUT_MINOR     0
   using namespace V6;

#endif


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


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


namespace V6
{

struct SEepromBoardInfo
{
   struct
   {
      char magic;                   // 0x0: 'M'; 8 Bytes
      uint8_t  boardCode;           // 0x1
      uint16_t articleId;           // 0x2
      uint8_t  boardRevision;       // 0x4
      uint8_t  boardPatch;          // 0x5
      uint8_t reserved2[2];         // 0x6...0x7
   } PHONY_PACKED main;

   struct
   {
      char magic;                   // 0x8: 'P'; 12 Bytes
      uint8_t site;                 // 0x9
      uint16_t dateYear;            // 0xA
      uint8_t dateMonth;            // 0xC
      uint8_t dateDay;              // 0xD
      uint8_t reserved2[2];         // 0xE...0xF
      uint32_t serialNumber;        // 0x10...13
   } PHONY_PACKED production;

   struct
   {
      char magic;                   // 0x14: 'A'; 8 Bytes
      uint8_t reserved1[1];         // 0x15
      uint16_t variant;             // 0x16 ... 0x17: For single-PCB-products; e.g. Miniminutnik 'Corona'
      uint16_t flags;               // 0x18 ... 0x19
      uint8_t reserved2[2];         // 0x1A ... 0x1B
   } PHONY_PACKED product;

   uint8_t reserved2[4];            // 0x1C ... 0x1F
                                    // 0x20
} PHONY_PACKED;

struct SEepromBoardConfig
{
   int flags;
   uint8_t i2cType;
   uint8_t reserved1;
   uint8_t reserved2;
   uint8_t reserved3;
} PHONY_PACKED;

struct SEepromHwData
{
   SEepromBoardInfo boardInfo;
   SEepromBoardConfig boardConfig;
   char reserved[ 0x20 - sizeof(SEepromBoardConfig) - RETAIN_HEADER_SIZE ];
} PHONY_PACKED;


struct SEepromConfigBase
{
   uint32_t nodeId;
} PHONY_PACKED;

static_assert( sizeof ( SEepromBoardInfo ) == 0x20 );

}

//---fin----------------------------------------------------------------------
#endif // ? ! CAMPO_LAYOUTS_V6_H
