#ifndef CAMPO_LAYOUTS_V5_H
#define CAMPO_LAYOUTS_V5_H
//----------------------------------------------------------------------------
///
/// \brief  Campo layouts
///
///         EEPROM layouts for various boards
//
/// \date   20211214
/// \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_V6 )
   // #error This file should not be included; Layout V6 was specified
#endif


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

   #define BOARDINFO_LAYOUT_MAJOR     5
   #define BOARDINFO_LAYOUT_MINOR     0
   using namespace V5;

#endif


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


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


namespace V5
{

struct SEepromBoardInfo
{
   struct
   {
      char magic;                   // 0x0: 'M'
      uint16_t articleId;           // 0x1
      uint8_t  boardCode;           // 0x3
      uint8_t  boardRevision;       // 0x4
      uint8_t  boardPatch;          // 0x5
   }__attribute ((packed)) main;

   struct
   {
      char magic;                   // 0x6: 'P'
      uint32_t serialNumber;        // 0x7
      uint16_t dateYear;            // 0xB
      uint8_t dateMonth;            // 0xD
      uint8_t dateDay;              // 0xE
   }__attribute ((packed)) production;

   struct
   {
      char magic;                    // 0xF: 'A'
      uint16_t variant;              // 0x10: For single-PCB-products; e.g. Miniminutnik 'Corona'
      uint8_t reserved[2];           // 0x12
   }__attribute ((packed)) product;
                                     // 0x14

} __attribute ((packed));


struct SEepromConfigBase
{
   uint8_t  magic;
   uint8_t  bom;
   uint8_t  variant;
   uint8_t  i2cType;
   uint16_t  nodeId;    // 0x00 ... 0x01
   uint16_t  reserved;  // 0x02 ... 0x03
                        // 0x04
   
   #if IS_ENABLED( CONFIG_VAGUS_USE_BOOTCOUNTER )
      unsigned int bootCounter;
   #endif

   //uint8_t custom[ 0x20 - RETAIN_HEADER_SIZE - 0x04 ];
} PHONY_PACKED;


struct SEepromHwData
{
   SEepromBoardInfo  boardInfo;
   char reserved[ 0x40 - RETAIN_HEADER_SIZE - sizeof(boardInfo) ];
   
}__attribute ((packed));


}


//---fin----------------------------------------------------------------------
#endif // ? ! CAMPO_LAYOUTS_V5_H
