/*
 * lcdio.c
 *
 *  Created on: Aug 5, 2023
 *      Author: leo
 */

#include <stdint.h>

#define FSMC_NOR_PSRAM_REGION1 ((void*)0x60000000)
#define FSMC_NOR_PSRAM_REG     ((void*)0x60020000)

static volatile uint16_t *LCD_REG = (uint16_t*)FSMC_NOR_PSRAM_REGION1;
static volatile uint16_t *LCD_RAM = (uint16_t*)FSMC_NOR_PSRAM_REG;

uint16_t LCD_IO_ReadData(uint16_t RegValue){
	*LCD_REG = RegValue;

	return *LCD_RAM;
}

uint32_t LCD_IO_ReadData_m(uint16_t RegValue, uint8_t ReadSize) {
  volatile uint32_t data;
  *LCD_REG = RegValue;
  data = *LCD_RAM;

  while (--ReadSize) {
    data <<= 8;
    data |= (*LCD_RAM & 0xFF);
  }
  return data;
}

void LCD_IO_WriteReg(uint16_t Reg) {
  *LCD_REG = Reg;
}

void LCD_IO_WriteData(uint16_t RegValue) {
  *LCD_RAM = RegValue;
}

uint16_t* LCD_IO_getDataPt(void){
	return LCD_RAM;
}
