BOOL A025DL02_Driver::Uninitialize()
{
    NATIVE_PROFILE_HAL_DRIVERS_DISPLAY();
    
    // Clear display content
    Clear();

    LCD_Controller_Enable(FALSE);
    
    UINT16 write[] = 
    { 
        A025DL02_I2C_ADDR_DATA(c_CMD_REG5, c_LCD_STANDBY), 
    };

    UINT16 read[ARRAYSIZE_CONST_EXPR(write)];
    
    SPI_XACTION_16 xAction = 
    {
        write,
        ARRAYSIZE_CONST_EXPR(write),
        read,
        ARRAYSIZE_CONST_EXPR(read),
        0,
        g_A025DL02_SPI_Config.SPI_mod
    };

    CPU_SPI_Xaction_Start(g_A025DL02_SPI_Config);
    CPU_SPI_Xaction_nWrite16_nRead16(xAction);
    CPU_SPI_Xaction_Stop (g_A025DL02_SPI_Config);

    return LCD_Controller_Uninitialize();
}
void A025DL02_Driver::PowerSave( BOOL On )
{
    NATIVE_PROFILE_HAL_DRIVERS_DISPLAY();
    UINT16 write[2];
    UINT16 read[ARRAYSIZE_CONST_EXPR(write)];

    if(On)
    {
        write[0] = A025DL02_I2C_ADDR_DATA(c_CMD_REG5, c_LCD_POWERSAVE);
        write[1] = A025DL02_I2C_ADDR_DATA(c_CMD_REG5, c_LCD_POWERSAVE);
    }
    else
    {
        write[0] = A025DL02_I2C_ADDR_DATA(c_CMD_REG5, c_LCD_NORMAL);
        write[1] = A025DL02_I2C_ADDR_DATA(c_CMD_REG5, c_LCD_NORMAL);
    }

    SPI_XACTION_16 xAction = 
    {
        write,
        ARRAYSIZE_CONST_EXPR(write),
        read,
        ARRAYSIZE_CONST_EXPR(read),
        0,
        g_A025DL02_SPI_Config.SPI_mod
    };

    CPU_SPI_Xaction_Start(g_A025DL02_SPI_Config);
    CPU_SPI_Xaction_nWrite16_nRead16(xAction);
    CPU_SPI_Xaction_Stop (g_A025DL02_SPI_Config);

    return;
}
BOOL CPU_SPI_nWrite16_nRead16( const SPI_CONFIGURATION& Configuration, UINT16* Write16, INT32 WriteCount, UINT16* Read16, INT32 ReadCount, INT32 ReadStartOffset )
{
    NATIVE_PROFILE_HAL_PROCESSOR_SPI();
    if(!CPU_SPI_Xaction_Start( Configuration )) return FALSE;
    SPI_XACTION_16 Transaction;
    Transaction.Read16          = Read16;
    Transaction.ReadCount       = ReadCount;
    Transaction.ReadStartOffset = ReadStartOffset;
    Transaction.Write16         = Write16;
    Transaction.WriteCount      = WriteCount;
    Transaction.SPI_mod         = Configuration.SPI_mod;
    if(!CPU_SPI_Xaction_nWrite16_nRead16( Transaction )) return FALSE;
    return CPU_SPI_Xaction_Stop( Configuration );
}
UINT16 AD7466_Driver::Read( INT32 Channel )
{
    AD7466_CONFIG* Config = &g_AD7466_Config;

    UINT16 ADC_Value;
    UINT16 Write16;

    // select the NO3 on MAX4704
    CPU_GPIO_SetPinState( Config->ADMUX_A0_GPIO_PIN, Config->ADMUX_Address[Channel].A0 );
    CPU_GPIO_SetPinState( Config->ADMUX_A1_GPIO_PIN, Config->ADMUX_Address[Channel].A1 );

    // data that is written is ignored, but reduce energy by keeping output high
    Write16 = 0xffff;

    CPU_GPIO_SetPinState( Config->ADMUX_EN_L_GPIO_PIN, FALSE );    // bring enable active (low)

    // delay 5 uSecs per RAY after enabling MUX to allow inrush current to settle and voltage to stabilize
    HAL_Time_Sleep_MicroSeconds_InterruptEnabled( 5 );

    {
        // we must ensure a radio operation ISR doesn't intervene - keep this short!
        GLOBAL_LOCK(irq);

        // W
        // R
        CPU_SPI_Xaction_Start( Config->SPI_Config );

        {
            SPI_XACTION_16 Transaction;

            Transaction.Read16          = &ADC_Value;
            Transaction.ReadCount       = 1;
            Transaction.ReadStartOffset = 1-1;
            Transaction.Write16         = &Write16;
            Transaction.WriteCount      = 1;

            CPU_SPI_Xaction_nWrite16_nRead16( Transaction );
        }

        CPU_SPI_Xaction_Stop( Config->SPI_Config );
    }

    CPU_GPIO_SetPinState( Config->ADMUX_EN_L_GPIO_PIN, TRUE );    // bring enable inactive (high)

    // scale down by 1 bit, since this is how it returns the result
    ADC_Value >>= 1;

    return ADC_Value;
}
BOOL A025DL02_Driver::Initialize()
{
    NATIVE_PROFILE_HAL_DRIVERS_DISPLAY();
    BOOL bRet = TRUE;

    // setup the LCD by SPI cmds
    {
        UINT16 write[] = 
        { 
            A025DL02_I2C_ADDR_DATA(c_CMD_REG5, c_LCD_START      ), 
            A025DL02_I2C_ADDR_DATA(c_CMD_REG4, c_REG4_SETUP_DATA), 
            A025DL02_I2C_ADDR_DATA(c_CMD_REG8, c_BL_DRV_DATA    ),
            A025DL02_I2C_ADDR_DATA(c_CMD_REG5, c_LCD_NORMAL     )
        };

        UINT16 read[ARRAYSIZE_CONST_EXPR(write)];
        
        SPI_XACTION_16 xAction = 
        {
            write,
            ARRAYSIZE_CONST_EXPR(write),
            read,
            ARRAYSIZE_CONST_EXPR(read),
            0,
            g_A025DL02_SPI_Config.SPI_mod
        };

        CPU_SPI_Xaction_Start(g_A025DL02_SPI_Config);
        CPU_SPI_Xaction_nWrite16_nRead16(xAction);
        CPU_SPI_Xaction_Stop (g_A025DL02_SPI_Config);
    }
    
    bRet = LCD_Controller_Initialize(g_LcdController_Config);

    LCD_Controller_Enable(TRUE);
    
    // Clear display content
    Clear();
    
    return bRet;
}