Exemplo n.º 1
0
/*************************************************************************
 * Function Name: GLCD_SPI_Init
 * Parameters: Int32U Clk, Int32U Width
 * Return: none
 *
 * Description: Init SPI
 *
 *************************************************************************/
void GLCD_SPI_Init(Int32U Clk, Int32U Width)
{
GPIO_InitTypeDef GPIO_InitStructure;
  /* Enable GPIO clock and release reset*/
  RCC_AHB1PeriphClockCmd(LCD_CS_CLK | LCD_SPI_MISO_CLK | 
                         LCD_SPI_MOSI_CLK | LCD_SPI_SCLK_CLK, ENABLE);
  RCC_AHB1PeriphResetCmd(LCD_CS_CLK | LCD_SPI_MISO_CLK | 
                         LCD_SPI_MOSI_CLK | LCD_SPI_SCLK_CLK, DISABLE);

  /*LCD_CS*/
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

  GPIO_InitStructure.GPIO_Pin = LCD_CS_MASK;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(LCD_CS_PORT, &GPIO_InitStructure);
  /*LCD_SPI_SCLK*/
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

  GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCLK_MASK;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(LCD_SPI_SCLK_PORT, &GPIO_InitStructure);

  /*LCD_SPI_MOSI*/
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

  GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_MASK;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(LCD_SPI_MOSI_PORT, &GPIO_InitStructure);

  /*LCD_SPI_MISO*/
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

  GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_MASK;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(LCD_SPI_MISO_PORT, &GPIO_InitStructure);
  // Chip select
  GLCD_SPI_ChipSelect(0);
  GLCD_SPI_CLK_H();

  // Chip select
  GLCD_SPI_ChipSelect(FALSE);

  // Set data width
  GLCD_SPI_SetWordWidth(Width);

}
Exemplo n.º 2
0
/*************************************************************************
 * Function Name: GLCD_SPI_Init
 * Parameters: Int32U Clk, Int32U Width
 * Return: none
 *
 * Description: Init SSP0
 *
 *************************************************************************/
void GLCD_SPI_Init(Int32U Clk, Int32U Width)
{
  // Assign GPIO to SSP0 - SCK, MOSI, MISO
  PINSEL3_bit.P1_20 = 3;  // SCK
  PINSEL3_bit.P1_23 = 3;  // MISO
  PINSEL3_bit.P1_24 = 3;  // MOS1

  // Chip select
  LCD_CS_FDIR |= LCD_CS_MASK;

  GLCD_SPI_ChipSelect(FALSE);

  // Spi init
  PCONP_bit.PCSSP0 = 1;			// SSP0 clock enable
  SSP0CR1_bit.SSE  = 0;     // Disable module
  SSP0CR1_bit.LBM  = 0;     // Disable Loop Back Mode
  SSP0CR1_bit.MS   = 0;     // Master mode
  SSP0CR0_bit.FRF  = 0;			// SPI
  SSP0CR0_bit.CPOL = 0;
	SSP0CR0_bit.CPHA = 0;
  SSP0IMSC = 0;             // disable all interrupts
  SSP0DMACR = 0;            // disable DMA
  SSP0CR1_bit.SSE  = 1;     // Enable module
  for (Int32U i = 0; i < 8; i++ )
  {
    volatile Int32U Dummy = SSP0DR; // clear the RxFIFO
  }
  // Set SSP clock frequency
  GLCD_SPI_SetClockFreq(Clk);
  // Set data width
  GLCD_SPI_SetWordWidth(Width);

}
Exemplo n.º 3
0
/*************************************************************************
 * Function Name: GLCD_SendCmd
 * Parameters: GLCD_SendCmd Cmd, pInt8U pData, Int32U Size
 * Return: GLCD_Status_t
 *
 * Description: Send command to the Graphic LCD
 *
 *************************************************************************/
GLCD_Status_t GLCD_SendCmd (GLCD_Cmd_t Cmd, pInt8U pData, Int32U Size)
{
static Boolean Write2_DRAM = FALSE; // write to DRAM mode
static Int32U ResRatio;             // Hold resistor ratio init by VOLCTR
                                    // and used by SETCON adapted command
// Pointer to current set of commands
pGLCD_CmdCtrl_t pGLCD_CmdCtrl = (pGLCD_CmdCtrl_t)(((Glcd_Iss==GLCD_ISS_0)?
                                GLCD_Cmd_Iss0:GLCD_Cmd_Iss1) + Cmd);
pDATCTR_Data_t pDATCTR_Data;
Int8U ColourSch;
pASCSET_Data_t pASCSET_Data;
MADCTR_Data_t DataMode = {0};
Int32U Contrast;

  if(Write2_DRAM)
  {
    // Select LCD
    GLCD_SPI_ChipSelect(1);
    if(Cmd != RAMWR)
    {
      Write2_DRAM = FALSE;
      if(PixelHold & WAITED_PIXEL)
      {
        // Flush pixel
        GLCD_SPI_TranserByte(PixelHold);
      }
      // Release CS
      GLCD_SPI_ChipSelect(0);
    }
    else
    {
      // pixels collection
      Int32U Pixel;
      while(Size > 1)
      {
        Pixel  =  *pData++;
        Pixel |= (*pData++)<<8;
		
        PixelHold |= WAITED_PIXEL;
        if(!OddPixel)
        {
          // Get even pixel
          PixelHold |= PIXEL_CONV(Pixel,0);
        }
        else
        {
          // Apply odd pixel
          PixelHold |= PIXEL_CONV(Pixel,1);
          // and send together both pixels
		
          GLCD_SPI_SendBlock((pInt8U)&PixelHold,3);
          PixelHold = 0;
        }
        // update the even/odd flag
        OddPixel ^= 1;
        // update the counter of the remaining bytes
        Size -= 2;
      }
      // Release CS
      GLCD_SPI_ChipSelect(0);
      return(GLCD_OK);
    }
  }

	// sanitary check of command
	if(pGLCD_CmdCtrl->Cmd == GLCD_INV_CMD)
	{
		return(GLCD_UNSUPPORTED);
	}
	
	// Implement adapted commands
	if(Glcd_Iss==GLCD_ISS_0)
	{
		switch(Cmd)
		{
		case PTIN:
			// PTLAR + PTIN
			GLCD_SendCmd(PTLAR,pData,0);
			GLCD_SendCmd(PTLON,NULL,0);
			return(GLCD_OK);
		case DATCTR:
      pDATCTR_Data = (pDATCTR_Data_t)pData;
			// MADCTR + COLMOD
			// Data reconstruction
      DataMode.MY = pDATCTR_Data->MY;
			DataMode.MX = pDATCTR_Data->MX;
			DataMode.MV = pDATCTR_Data->MV;
			DataMode.ML = pDATCTR_Data->ML;
			DataMode.RGB = !pDATCTR_Data->RGB;
			GLCD_SendCmd(MADCTR,(pInt8U)&DataMode,0);
      // 4K colors Type A
			ColourSch = 3;			
			return(GLCD_SendCmd(COLMOD,&ColourSch,0));
		}
	}
	else
	{
    switch(Cmd)
		{
    case SCRLAR:
			pASCSET_Data = (pASCSET_Data_t)pData;
			pASCSET_Data->Smd = 0;	// Center screen scroll mode
			GLCD_SendCmd(ASCSET,pData,0);
			return(GLCD_OK);
    case DATCTR:
      pDATCTR_Data = (pDATCTR_Data_t)pData;
      pDATCTR_Data->ML  = 0;
			pDATCTR_Data->MX = !pDATCTR_Data->MX;
      // 4K colors Type A
      pDATCTR_Data->GS  = 2;
      break;
    case SETCON:
      Contrast = *pData | (ResRatio << 8);
      return(GLCD_SendCmd(VOLCTR,(pInt8U)&Contrast,0));
    case VOLCTR:
      ResRatio = *(pData+1);
      break;
		}
	}

  if(pGLCD_CmdCtrl->Param != (Int32U)-1)
  {
    // Command with fixed size of parameters
    Size = pGLCD_CmdCtrl->Param;
  }

  // Select LCD
  GLCD_SPI_ChipSelect(1);

  GLCD_SPI_TranserByte(pGLCD_CmdCtrl->Cmd);
  if(Cmd == RAMWR)
  {
    // enter in write to DRAM mode
    OddPixel = FALSE;
    PixelHold = 0;
    Write2_DRAM = TRUE;
    return(GLCD_SendCmd(RAMWR,pData,Size));
  }

  // Send/Receive parameters
  if(pGLCD_CmdCtrl->Dir == GLCD_READ)
  {
    if(pGLCD_CmdCtrl->Pulse)
    {
      if(Size)
      {
        *pData++ = GLCD_SPI_TranserByte(0xFFFF);
        --Size;
      }
    }
    GLCD_SPI_SetWordWidth(8);
  }

  if(pGLCD_CmdCtrl->Dir == GLCD_READ)
  {
    GLCD_SPI_ReceiveBlock(pData,Size);
  }
  else
  {
    GLCD_SPI_SendBlock(pData,Size);
  }

  // Release CS
  GLCD_SPI_ChipSelect(0);
  if(pGLCD_CmdCtrl->Dir == GLCD_READ)
  {
    GLCD_SPI_SetWordWidth(9);
  }
  return(GLCD_OK);
}