Changeset - a48d9ffdc5db
[Not reviewed]
default
0 2 0
Ethan Zonca - 10 years ago 2014-07-03 13:04:24
ezonca@sealandaire.com
Oled driver updates and pin assignment fixes
2 files changed with 36 insertions and 54 deletions:
0 comments (0 inline, 0 general)
libraries/oleddrv/bsp.h
Show inline comments
 
@@ -4,90 +4,65 @@
 
/**
 
  IO Connection map
 
 
       SSD1303
 
  Vcc   1  2  Gnd
 
D1/Data 3  4  D0/Clk
 
    D3  5  6  D2
 
    D5  7  8  D4
 
    D7  9 10  D6
 
    WR 11 12  RD
 
   RES 13 14  A0  (1-data,0-command)
 
   CS  15 16  C86 (1-8080, 0-SPI)
 
 
       STM32
 
  D0/Clk    PB13/SPI2 Clk
 
  D1/Data   PB15/SPI2 MOSI
 
  RES       PB12
 
  A0        PB14
 
  CS        Gnd
 
  D2~D7     (Float)
 
  WR        (Float)
 
  RD        (Float)
 
 */
 
 
#define   SSD_Clk         GPIOB,GPIO_Pin_13
 
#define   SSD_Data        GPIOB,GPIO_Pin_15
 
#define   SSD_Reset       GPIOD,GPIO_Pin_12
 
#define   SSD_A0          GPIOD,GPIO_Pin_14
 
#define   SSD_CS          //GPIOG,GPIO_Pin_2
 
#define   SSD_Clk         GPIOA,GPIO_Pin_5
 
#define   SSD_Data        GPIOA,GPIO_Pin_7
 
#define   SSD_Reset       GPIOB,GPIO_Pin_2
 
#define   SSD_A0          GPIOB,GPIO_Pin_10
 
#define   SSD_CS          GPIOB,GPIO_Pin_1
 
 
#define   SSD_Clk_Low()     GPIOB->BRR = GPIO_Pin_13
 
#define   SSD_Clk_High()    GPIOB->BSRR = GPIO_Pin_13
 
#define   SSD_Data_Low()    GPIOB->BRR = GPIO_Pin_15
 
#define   SSD_Data_High()   GPIOB->BSRR = GPIO_Pin_15
 
#define   SSD_Reset_Low()   GPIOB->BRR = GPIO_Pin_12
 
#define   SSD_Reset_High()  GPIOB->BSRR = GPIO_Pin_12
 
#define   SSD_A0_Low()      GPIOB->BRR = GPIO_Pin_14
 
#define   SSD_A0_High()     GPIOB->BSRR = GPIO_Pin_14
 
#define   SSD_CS_Low()      //GPIOG->BRR = GPIO_Pin_2
 
#define   SSD_CS_High()     //GPIOG->BSRR = GPIO_Pin_2
 
#define   SSD_Clk_Low()     GPIOA->BRR = GPIO_Pin_5
 
#define   SSD_Clk_High()    GPIOA->ODR |= GPIO_Pin_5
 
#define   SSD_Data_Low()    GPIOA->BRR = GPIO_Pin_7
 
#define   SSD_Data_High()   GPIOA->ODR |= GPIO_Pin_7
 
#define   SSD_Reset_Low()   GPIOB->BRR = GPIO_Pin_2
 
#define   SSD_Reset_High()  GPIOB->ODR |= GPIO_Pin_2
 
#define   SSD_A0_Low()      GPIOB->BRR = GPIO_Pin_10
 
#define   SSD_A0_High()     GPIOB->ODR |= GPIO_Pin_10
 
#define   SSD_CS_Low()      GPIOB->BRR = GPIO_Pin_1
 
#define   SSD_CS_High()     GPIOB->ODR |= GPIO_Pin_1
 
 
#define   SPI_SendByte(data)  SPI2->DR = (data)
 
#define   SPI_Wait()           while(!(SPI2->SR&SPI_I2S_FLAG_TXE));while(SPI2->SR&SPI_I2S_FLAG_BSY);
 
#define   SPI_SendByte(data)  SPI1->DR = (data)
 
#define   SPI_Wait()           while(!(SPI1->SR&SPI_I2S_FLAG_TXE));while(SPI1->SR&SPI_I2S_FLAG_BSY);
 
 
#define   SSD1303_FPS                   50
 
 
 
 
#define   IsLedOn()       (!(GPIOA->ODR & GPIO_Pin_8))
 
#define   LED_ON()        GPIOA->BRR = GPIO_Pin_8
 
#define   LED_OFF()       GPIOA->BSRR = GPIO_Pin_8
 
#define   ToggleLED()     if(GPIOA->ODR & GPIO_Pin_8){GPIOA->BRR = GPIO_Pin_8;}\
 
                          else{GPIOA->BSRR = GPIO_Pin_8;}
 
 
#define   IsCHG()         (!(GPIOB->IDR & GPIO_Pin_5))
 
#define   IsPGOOD()       (!(GPIOB->IDR & GPIO_Pin_4))
 
 
#define   GSel1_High()    GPIOB->BSRR = GPIO_Pin_9
 
#define   GSel1_Low()     GPIOB->BRR = GPIO_Pin_9
 
#define   GSel2_High()    GPIOB->BSRR = GPIO_Pin_8
 
#define   GSel2_Low()     GPIOB->BRR = GPIO_Pin_8
 
 
#define   MMA_SLEEP()     GPIOB->BRR = GPIO_Pin_11
 
#define   MMA_WAKEUP()    GPIOB->BSRR = GPIO_Pin_11
 
#define   Is_MMA_WAKEUP() (GPIOB->ODR & GPIO_Pin_11)
 
 
#define   AD_CH_BAT       ADC_Channel_4
 
#define   AD_CH_X         ADC_Channel_1
 
#define   AD_CH_Y         ADC_Channel_2
 
#define   AD_CH_Z         ADC_Channel_3
 
#define   AD_CH_CHG       ADC_Channel_9
 
#define   AD_CH_REF       ADC_Channel_17
 
 
#define   DMA_SSD_1303    DMA1_Channel5
 
#define   DMA_Handler_SSD_1303    DMA1_Channel5_IRQHandler
 
#define   DMA_ADC         DMA1_Channel1
 
 
 
#define   Is_Enc_Key_Down()    (!(GPIOA->IDR & GPIO_Pin_0))
 
 
typedef   struct  _ADResult_t
 
{
 
  uint16_t   ADRef;    // ADC1 
 
  uint16_t   ADBat;    // ADC2
 
  uint16_t   ADX;      // ADC1
 
  uint16_t   ADY;      // ADC2
 
  uint16_t   ADZ;      // ADC1
 
  uint16_t   ADChg;    // ADC2
 
}ADResult_t;
 
 
#endif
ssd1306.c
Show inline comments
 
@@ -62,49 +62,50 @@ void WriteCommand(unsigned char command)
 
* Function Name  : WriteData
 
* Description    : Write data to the SSD1303
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void WriteData(unsigned char data)
 
{
 
  SSD_A0_High();
 
  SPI_SendByte(data);
 
  SPI_Wait();
 
}
 
 
/*******************************************************************************
 
* Function Name  : SSD1303_Init
 
* Description    : Initialize the SSD1303
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void SSD1303_Init(void)
 
{
 
  /* Generate a reset */
 
  SSD_Reset_Low();
 
  for(u32 i=5000;--i;);//—” ±5uS“‘…œ
 
  uint32_t i ;
 
  for(i=5000;--i;);
 
  SSD_Reset_High();
 
  
 
  /*************************************************
 
  // SSD1303 Initialization Command
 
  *************************************************/
 
  // Lower Column Address
 
  WriteCommand(0x00); /* Set Lower Column Address */
 
  // High Column Address
 
  WriteCommand(0x10); /* Set Higher Column Address*/
 
  // Display Start Line
 
  WriteCommand(0x40); /* Set Display Start Line */
 
#ifdef    DEBUG_BOARD
 
  curContrast = lastContrast = 0x30;
 
#else
 
  curContrast = lastContrast = 0xCF;
 
#endif
 
  // Contrast Control Register
 
  WriteCommand(0x81); /* Set Contrast Control */
 
  WriteCommand(lastContrast); /* 0 ~ 255 0x1f*/
 
  
 
  // Re-map
 
  WriteCommand(0xA1); /* [A0]:column address 0 is map 
 
  to SEG0 , [A1]: columnaddress 131 is map to SEG0*/ 
 
  // Entire Display ON/OFF
 
@@ -202,49 +203,50 @@ unsigned char SSD1303_SetContrast(unsign
 
 
/*******************************************************************************
 
* Function Name  : SSD1303_GetContrast
 
* Description    : Get the SSD1303 contrast
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned char SSD1303_GetContrast()
 
{
 
  return lastContrast;
 
}
 
 
/*******************************************************************************
 
* Function Name  : SSD1303_OFF
 
* Description    : Turn off the SSD1303 controller
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long SSD1303_OFF(void)
 
{
 
  if(iS_SSD_On){
 
#ifdef  DEBUG_UI
 
    for(u32 i=0;i<SSD1303_COLUMN_NUMBER*SSD1303_PAGE_NUMBER;i++){
 
    uint32_t i = 0;
 
    for(i=0;i<SSD1303_COLUMN_NUMBER*SSD1303_PAGE_NUMBER;i++){
 
      SSD1303_Buffer[i] = 0;
 
    }
 
#else
 
    // Turn off the display
 
    WriteCommand(0xae);
 
    
 
    // Set Charge pump
 
    WriteCommand(0x8D); /* Set Charge pump */
 
    WriteCommand(0x10); /* 0x14=ON, 0x10=Off */
 
#endif
 
    iS_SSD_On = 0;
 
  }
 
  return iS_SSD_On;
 
}
 
 
 
/*******************************************************************************
 
* Function Name  : SSD1303_ON
 
* Description    : Turn on the SSD1303 controller
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long SSD1303_ON(void)
 
@@ -278,60 +280,60 @@ unsigned long SSD1303_IsOn(void)
 
{
 
  return iS_SSD_On;
 
}
 
 
/*******************************************************************************
 
* Function Name  : OnPageTransferDone
 
* Description    : Called when each page transfer done
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void  OnPageTransferDone(void)
 
{
 
  if(pageIndex == SSD1303_PAGE_NUMBER){
 
    pageIndex = 0;
 
    return;
 
  }
 
#ifdef    DEBUG_BOARD
 
  WriteCommand(0xb0 + pageIndex);
 
  if(pageIndex == 0){
 
    WriteCommand(0x00);
 
    WriteCommand(0x10);
 
  }
 
  SSD_A0_High();
 
  DMA1_Channel5->CCR &= ((u32)0xFFFFFFFE);
 
  DMA1_Channel5->CCR &= ((uint32_t)0xFFFFFFFE);
 
  DMA1_Channel5->CNDTR = SSD1303_COLUMN_NUMBER+SSD1303_COLUMN_MARGIN_START + SSD1303_COLUMN_MARGIN_END;
 
  DMA1_Channel5->CMAR = (u32)(SSD1303_Buffer+SSD1303_COLUMN_NUMBER*pageIndex - SSD1303_COLUMN_MARGIN_START);
 
  DMA_SSD_1303->CCR |= ((u32)0x00000001);
 
  DMA1_Channel5->CMAR = (uint32_t)(SSD1303_Buffer+SSD1303_COLUMN_NUMBER*pageIndex - SSD1303_COLUMN_MARGIN_START);
 
  DMA_SSD_1303->CCR |= ((uint32_t)0x00000001);
 
  pageIndex++;
 
#else
 
  SSD_A0_High();
 
  DMA_SSD_1303->CCR &= ((u32)0xFFFFFFFE);
 
  DMA_SSD_1303->CCR &= ((uint32_t)0xFFFFFFFE);
 
  DMA_SSD_1303->CNDTR = SSD1303_COLUMN_NUMBER*SSD1303_PAGE_NUMBER;//+SSD1303_COLUMN_MARGIN_START + SSD1303_COLUMN_MARGIN_END;
 
  DMA_SSD_1303->CMAR = (u32)(SSD1303_Buffer);//+SSD1303_COLUMN_NUMBER*pageIndex);
 
  DMA_SSD_1303->CMAR = (uint32_t)(SSD1303_Buffer);//+SSD1303_COLUMN_NUMBER*pageIndex);
 
  //DMA_Cmd(DMA_SSD_1303, ENABLE);
 
  DMA_SSD_1303->CCR |= ((u32)0x00000001);
 
  DMA_SSD_1303->CCR |= ((uint32_t)0x00000001);
 
//  pageIndex++;
 
  pageIndex = SSD1303_PAGE_NUMBER;
 
#endif
 
}
 
 
/*******************************************************************************
 
* Function Name  : DMA1_Channel5_IRQHandler
 
* Description    : This function handles DMA1 Channel 5 interrupt request.
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void DMA_Handler_SSD_1303(void) //DMA1_Channel5_IRQHandler(void)
 
{
 
  if(DMA_GetITStatus(DMA1_IT_TC5)){
 
    DMA_ClearITPendingBit(DMA1_IT_GL5);
 
    OnPageTransferDone();
 
  }
 
}
 
 
/*******************************************************************************
 
* Function Name  : StartPageTransfer
 
* Description    : Start a new page transfer
 
* Input          : None
 
@@ -368,69 +370,73 @@ void StartPageTransfer(void)
 
* Function Name  : SSD1303_DrawBlock
 
* Description    : Draw a block with specify data to SSD1303
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long SSD1303_DrawBlock(
 
  Pos_t x,
 
  Pos_t y,
 
  Pos_t cx,
 
  Pos_t cy,
 
  const unsigned char* data)
 
{
 
  if(x >= SSD1303_X_PIXEL)return 0;
 
  if(y >= SSD1303_Y_PIXEL)return 0;
 
  if(x+cx > SSD1303_X_PIXEL ) cx = SSD1303_X_PIXEL - x ;
 
  if(y+cy > SSD1303_Y_PIXEL ) cy = SSD1303_Y_PIXEL - y ;
 
  unsigned char* pStart = SSD1303_Buffer + (y/8)*SSD1303_COLUMN_NUMBER + x;
 
  unsigned char offset1 = y%8;
 
  unsigned char offset2 = (cy+y)%8;
 
  if(data){
 
    unsigned char mask1 = (1<<offset1)-1;
 
    unsigned char mask2 = ~((1<<offset2)-1);
 
    cy = (cy+offset1)/8;
 
    for(Pos_t i=0;i<cx;i++){
 
   
 
    Pos_t i = 0;
 
    for(i=0;i<cx;i++){
 
      Pos_t j = 0;
 
      unsigned short tmp = *pStart & mask1;
 
      for(;j<cy;j++){
 
        tmp |= (((unsigned short)data[j*cx])<<offset1);
 
        *(pStart + j*SSD1303_COLUMN_NUMBER) = tmp;
 
        tmp>>=8;
 
      }
 
      if(offset2){
 
        tmp |= ((((unsigned short)data[j*cx])<<offset1) & (~mask2))
 
            | *(pStart + j*SSD1303_COLUMN_NUMBER) & mask2;
 
        *(pStart + j*SSD1303_COLUMN_NUMBER) = tmp;
 
      }
 
      data++;
 
      pStart++;
 
    }
 
  }else{
 
    unsigned char mask1 = ~((1<<offset1)-1);
 
    unsigned char mask2 = ((1<<offset2)-1);
 
    cy = (cy+offset1)/8;
 
    for(Pos_t i=0;i<cx;i++){
 
 
    Pos_t i = 0;
 
    for(i=0;i<cx;i++){
 
      Pos_t j = 1;
 
      *pStart ^= mask1;
 
      for(;j<cy;j++){
 
        *(pStart + j*SSD1303_COLUMN_NUMBER) ^= 0xFF;
 
      }
 
      if(offset2){
 
        *(pStart + j*SSD1303_COLUMN_NUMBER) ^= mask2;
 
      }
 
      pStart++;
 
    }
 
  }
 
  
 
  
 
//  if(!offset){
 
//    for(Pos_t i=0;i<cx;i++){
 
//      unsigned char tmp;
 
//      Pos_t j = 0;
 
//      for(;j<cy/8;j++){
 
//        tmp = data[i+j*cx];
 
//        *(pStart + j*SSD1303_COLUMN_NUMBER + i + x) = tmp;
 
//      }
 
//      if(cy&0x7){
 
//        unsigned char mask1 = (1<<(cy&7)) - 1;
 
//        unsigned char mask2 = 0xFF - mask1;
 
@@ -491,37 +497,38 @@ unsigned long SSD1303_DrawPoint(
 
* Description    : Read a point from SSD1303
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long SSD1303_ReadPoint(
 
  Pos_t x,
 
  Pos_t y)
 
{
 
  unsigned char* pStart = SSD1303_Buffer + (y/8)*SSD1303_COLUMN_NUMBER + x;
 
  unsigned char mask = 1<<(y%8);
 
  return *pStart&mask ? 1 : 0;
 
}
 
 
/*******************************************************************************
 
* Function Name  : SSD1303_ClearScreen
 
* Description    : Clear the screen contents
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void  SSD1303_FillScreen(Color_t color)
 
{
 
  unsigned char mask = color ? 0xFF : 0;
 
  for(unsigned long i=0;i<SSD1303_COLUMN_NUMBER*SSD1303_PAGE_NUMBER;i++){
 
  unsigned long i = 0;
 
  for(i=0;i<SSD1303_COLUMN_NUMBER*SSD1303_PAGE_NUMBER;i++){
 
    SSD1303_Buffer[i] = mask;
 
  }
 
}
 
 
const DeviceProp  SSD1303_Prop =
 
{
 
  .pfnDrawBlok = SSD1303_DrawBlock,
 
  .pfnDrawPoint = SSD1303_DrawPoint,
 
  .xPixel = 128,
 
  .yPixel = 64,
 
};
 
0 comments (0 inline, 0 general)