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
 
@@ -22,32 +22,33 @@ D1/Data 3  4  D0/Clk
 
  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
main.c
Show inline comments
 
@@ -27,39 +27,46 @@ int main(void)
 
  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.
 
@@ -126,14 +133,21 @@ void init_gpio(void) {
 
        * 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;
ssd1306.c
Show inline comments
 
@@ -78,26 +78,24 @@ void WriteData(unsigned char data)
 
* 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;
 
@@ -119,12 +117,13 @@ void SSD1303_Init(void)
 
  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
0 comments (0 inline, 0 general)