#ifndef BIWAK_LCD_H
#define BIWAK_LCD_H
//----------------------------------------------------------------------------
///
/// \brief  Class for LCD Display
///
///         See implementation for further information.
///
/// \date   20230102
/// \author Maximilian Seesslen <development.seesslen.net>
///
//----------------------------------------------------------------------------


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


//---General-------------------------

#include <biwak/output.hpp>
#include <biwak/gpio.hpp>
#include <biwak/lcd.hpp>
#include <lepto/log.h>

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


//---Forward declarations-----------------------------------------------------


#if defined (MCU_PLATFORM_STM32)
   #define LCD_HANDLE_TYPE    LCD_HandleTypeDef
   #include <HALWrapper/stm32_lcd.h>
#else
   #define LCD_HANDLE_TYPE    void
#endif


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


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


class CLcd
{
    private:
      LCD_HANDLE_TYPE m_LCDHandle;
      uint32_t m_digit[0xA];

    public:

        CLcd();
        ~CLcd();

        void clear()
        {
           HAL_LCD_Clear(&m_LCDHandle);
        }
        void setContrast(uint32_t contrast)
        {
           __HAL_LCD_CONTRAST_CONFIG(&m_LCDHandle, contrast);
        }
        void setBlinkConfig(uint32_t BlinkMode, uint32_t BlinkFrequency)
        {
          __HAL_LCD_BLINK_CONFIG(&m_LCDHandle, BlinkMode, BlinkFrequency);
        }
        void defineDigit(int index, uint32_t mask)
        {
           lAssert(index<0xA);
           m_digit[index]=mask;
        }
        void writeDigit(int index, uint32_t value)
        {
           lAssert(index<0xA);
           write(m_digit[index], value);
        }
        void write( uint32_t mask, uint32_t data )
        {
           HAL_StatusTypeDef sta;
            sta=HAL_LCD_Write( &m_LCDHandle, LCD_RAM_REGISTER0, mask, data);
            lAssert( sta==HAL_OK );
            sta=HAL_LCD_UpdateDisplayRequest( &m_LCDHandle );
            lAssert( sta==HAL_OK );
        }
};


//---fin-----------------------------------------------------------------------
#endif // ? ! BIWAK_LCD_H
