Changeset - 299800126735
[Not reviewed]
default
0 3 0
Ethan Zonca - 10 years ago 2014-07-10 22:32:10
ez@ethanzonca.com
Now using GPIO library and generated gpio config, fixes for SPI, etc
3 files changed with 44 insertions and 30 deletions:
0 comments (0 inline, 0 general)
libraries/oleddrv/bsp.h
Show inline comments
 
@@ -16,44 +16,45 @@ D1/Data 3  4  D0/Clk
 
 
       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         GPIOA,GPIO_Pin_5
 
#define   SSD_Data        GPIOA,GPIO_Pin_7
 
//#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()     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   SSD_Clk_Low()     GPIO_ResetBits(GPIOA, GPIO_Pin_3)
 
//#define   SSD_Clk_High()    GPIO_SetBits(GPIOA, GPIO_Pin_5)
 
//#define   SSD_Data_Low()    GPIO_ResetBits(GPIOA, GPIO_Pin_7)
 
//#define   SSD_Data_High()   GPIO_SetBits(GPIOA, GPIO_Pin_7)
 
#define   SSD_Reset_Low()   GPIO_ResetBits(GPIOB, GPIO_Pin_2)
 
#define   SSD_Reset_High()  GPIO_SetBits(GPIOB, GPIO_Pin_2)
 
#define   SSD_A0_Low()      GPIO_ResetBits(GPIOB, GPIO_Pin_10)
 
#define   SSD_A0_High()     GPIO_SetBits(GPIOB, GPIO_Pin_10)
 
#define   SSD_CS_Low()      GPIO_ResetBits(GPIOB, GPIO_Pin_1)
 
#define   SSD_CS_High()     GPIO_SetBits(GPIOB, GPIO_Pin_1)
 
 
// Use stdperiph
 
#define   SPI_SendByte(data)  SPI_I2S_SendData(SPI1, 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   SPI_SendByte(data)  SPI_I2S_SendData(SPI1,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   GSel1_High()    GPIOB->BSRR = GPIO_Pin_9
 
#define   GSel1_Low()     GPIOB->BRR = GPIO_Pin_9
 
 
#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)
 
main.c
Show inline comments
 
@@ -21,51 +21,58 @@ int main(void)
 
  
 
  /* Configure LED3 and LED4 on STM32L100C-Discovery */
 
  STM_EVAL_LEDInit(LED3);
 
  STM_EVAL_LEDInit(LED4);
 
  
 
  /* SysTick end of count event each 1ms */
 
  RCC_GetClocksFreq(&RCC_Clocks);
 
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
 
 
 /* Initiate Blink Speed variable */ 
 
  BlinkSpeed = 1;
 
 
  GPIO_ResetBits(LED_STAT);
 
  Delay(100);
 
 
  init_gpio();
 
  init_spi();
 
  //SPI_I2S_SendData(SPI1, 0x1); 
 
 /* Init lcd driver */
 
//  SSD1303_Init();
 
//  SSD1303_DrawPoint(3,3,1);
 
//  SSD1303_DrawPoint(5,5,0);
 
 
//testme
 
//  GPIO_SetBits(LED_PWR);
 
  STM_EVAL_LEDOn(LED4);
 
  Delay(1000);
 
// GPIO_ResetBits(LED_PWR);
 
STM_EVAL_LEDOff(LED4);
 
  Delay(1000);
 
  GPIO_SetBits(LED_POWER);
 
//  GPIO_SetBits(LED_STAT);
 
//  STM_EVAL_LEDOn(LED4);
 
  Delay(500);
 
 GPIO_ResetBits(LED_POWER);
 
// GPIO_ResetBits(LED_STAT);
 
//  STM_EVAL_LEDOff(LED4);
 
 
  while(1)
 
  {  
 
      /* Turn on LD4 Blue LED during 1s each time User button is pressed */
 
      STM_EVAL_LEDOn(LED4);
 
      //STM_EVAL_LEDOn(LED4);
 
      GPIO_SetBits(LED_POWER);
 
      //STM_EVAL_LEDOn(LED3);
 
      
 
      /* wait for 1s */
 
      Delay(300);
 
      Delay(150);
 
      
 
      /* Turn off LD4 Blue LED after 1s each time User button is pressed */
 
      STM_EVAL_LEDOff(LED4);
 
      Delay(300);
 
      //STM_EVAL_LEDOff(LED4);
 
      GPIO_ResetBits(LED_POWER);
 
      Delay(150);
 
  }
 
}
 
 
/**
 
  * @brief  Inserts a delay time.
 
  * @param  nTime: specifies the delay time length, in 1 ms.
 
  * @retval None
 
  */
 
void Delay(__IO uint32_t nTime)
 
{
 
  TimingDelay = nTime;
 
 
@@ -120,26 +127,33 @@ void init_spi(void) {
 
void init_gpio(void) {
 
 
 GPIO_InitTypeDef GPIO_InitStruct;
 
 
  /** Configure pins as 
 
        * Analog 
 
        * Input 
 
        * Output
 
        * EVENT_OUT
 
        * EXTI
 
  */
 
 
  /*Enable or disable the AHB peripheral clock */
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOA|RCC_APB1Periph_SPI2|RCC_APB2Periph_SPI1, ENABLE);
 
  /*Enable or disable the APB peripheral clock */
 
 
 
 
  // Enable SPI clocks
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
 
 
  // Enable GPIO clocks
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOA, ENABLE);
 
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); // EMZ TODO get the right ones
 
 
  /*Configure GPIO pin : PC */
 
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;
 
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
 
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_400KHz;
 
  GPIO_Init(GPIOC, &GPIO_InitStruct);
 
 
  /*Configure GPIO pin : PB */
ssd1306.c
Show inline comments
 
@@ -72,38 +72,36 @@ void WriteData(unsigned char data)
 
}
 
 
/*******************************************************************************
 
* Function Name  : SSD1303_Init
 
* Description    : Initialize the SSD1303
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void SSD1303_Init(void)
 
{
 
 
  /* Initialize SPI2 */
 
  // TODO
 
 
  /* Generate a reset */
 
  SSD_Reset_Low();
 
  uint32_t i ;
 
  for(i=5000;--i;);
 
  for(i=5000; i>1; i--) 
 
  SSD_Reset_High();
 
  
 
  /*************************************************
 
  // SSD1303 Initialization Command
 
  *************************************************/
 
  // Lower Column Address
 
  WriteCommand(0x00); /* Set Lower Column Address */
 
  GPIO_SetBits(GPIOA,GPIO_Pin_15);
 
  // 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*/
 
@@ -113,24 +111,25 @@ void SSD1303_Init(void)
 
  to SEG0 , [A1]: columnaddress 131 is map to SEG0*/ 
 
  // Entire Display ON/OFF
 
  WriteCommand(0xA4); /* A4=ON */
 
  // Normal or Inverse Display
 
  WriteCommand(0XA6); /* Normal Display*/
 
  // Multiplex Ratio
 
  WriteCommand(0xA8); /* Set Multiplex Ratio */
 
  WriteCommand(0x3f); /* Set to 36 Mux*/
 
  // Set DC-DC
 
  WriteCommand(0xAD); /* Set DC-DC */
 
  WriteCommand(0x8B); /* 8B=ON, 8A=Off */
 
  
 
 
 
  // Display ON/OFF
 
  WriteCommand(0xAE); /* AF=ON , AE=OFF*/
 
  // Display Offset
 
  WriteCommand(0xD3); /* Set Display Offset */
 
  WriteCommand(0x00); /* No offset */
 
  // Display Clock Divide
 
  WriteCommand(0xD5); /* Set Clock Divide */
 
  WriteCommand(0x20); /* Set to 80Hz */
 
  // Area Color Mode
 
  WriteCommand(0xD8); /* Set Area Color On or Off*/
 
  WriteCommand(0x00); /* Mono Mode */
 
  // COM Pins Hardware Configuration
0 comments (0 inline, 0 general)