#ifndef _FLASH_H_
#define _FLASH_H_
//----------------------------------------------------------------------------
///
/// \brief  Generic flash
///
///         Can be inherited for internal, spi or i2c flash.
///         See implementation files for further information.
//
/// \date   20150416
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


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


#include <stdint.h>


//---Own------------------------------

#include <lepto/lepto.h>      // address_t


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



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


class CFlash
{
   private:
      address_t m_startAddress;
      address_t m_userAddress;
      
      #if IS_ENABLED( CONFIG_BIWAK_MEMORY_MAPPED_FLASH )
      bool m_memoryMapped=false;
      #endif // ? BIWAK_MEMORY_MAPPED_FLASH

   protected:
      int m_size;
      int m_erasePageSize=1;
      int m_writePageSize=1;

   public:
      CFlash( address_t address, int size );
      ~CFlash();

      uint32_t acquireMemory(int size);
#if 0
      virtual constexpr int erasePageSize() const = 0;
      virtual void erasePage(void *page, int count=1) const = 0;
      virtual uint32_t writeData(uint32_t address, const void *data, int size) = 0;
      virtual uint32_t readData(uint32_t address, void *data, int size) = 0;
#endif
      int erasePageSize() const { return(m_erasePageSize); };
      int writePageSize() const { return(m_writePageSize); };
      virtual int erasePage(address_t address, int count=1) { return(0); };
      virtual int writeData(address_t address, const void *data, int size) = 0;
      virtual int readData(address_t address, void *data, int size) = 0;

      int erasePageCount() const;
      int availableSize() const;
      int size() const { return m_size; };
      void setSize( int size ) { m_size=size; };
      int getStartAddress() const { return( m_startAddress ); };
      int getWritePageSize() const{ return( m_writePageSize ); };
      
      #if IS_ENABLED( CONFIG_BIWAK_MEMORY_MAPPED_FLASH )
      void setMemoryMapped()
      {
            m_memoryMapped=true;
      }
      bool isMemoryMapped() const
      {
         return( m_memoryMapped );
      }
      #endif // ? BIWAK_MEMORY_MAPPED_FLASH

};


//---fin----------------------------------------------------------------------
#endif // ? ! _FLASH_H_
