Changeset - 4e72955028d8
[Not reviewed]
default
0 2 0
Ethan Zonca - 10 years ago 2014-07-10 19:47:46
ez@ethanzonca.com
Added LED defs
2 files changed with 9 insertions and 14 deletions:
0 comments (0 inline, 0 general)
libraries/oleddrv/bsp.h
Show inline comments
 
#ifndef BSP_H
 
#define BSP_H
 
 
/**
 
  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         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
 
 
// 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_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)
 
 
#define   DMA_SSD_1303    DMA1_Channel5
 
#define   DMA_Handler_SSD_1303    DMA1_Channel5_IRQHandler
 
 
 
#define   Is_Enc_Key_Down()    (!(GPIOA->IDR & GPIO_Pin_0))
 
 
#endif
main.c
Show inline comments
 
#include "main.h"
 
#include "stm32l100c_discovery.h"
 
#include "ssd1306.h"
 
 
#define LED_POWER GPIOB,  GPIO_Pin_9
 
#define LED_STAT  GPIOA,  GPIO_Pin_15
 
 
static __IO uint32_t TimingDelay;
 
uint8_t BlinkSpeed = 0;
 
 
void init_gpio();
 
void init_spi();
 
 
/* Main */
 
int main(void)
 
{
 
 
   // Hopefully init clocks
 
   SystemInit();
 
   RCC_ClocksTypeDef RCC_Clocks;
 
  
 
  /* Configure LED3 and LED4 on STM32L100C-Discovery */
 
  STM_EVAL_LEDInit(LED3);
 
  STM_EVAL_LEDInit(LED4);
 
  
 
 
//  RCC_Configuration();
 
  /* Initialize User_Button on STM32L100C-Discovery */
 
  //STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
 
  
 
  /* SysTick end of count event each 1ms */
 
  RCC_GetClocksFreq(&RCC_Clocks);
 
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
 
 
 /* Initiate Blink Speed variable */ 
 
  BlinkSpeed = 1;
 
 
//  while(1) {
 
//	  ITM_SendChar('!');
 
//  } 
 
 
 
  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);
 
 
  while(1)
 
  {  
 
      /* Turn on LD4 Blue LED during 1s each time User button is pressed */
 
      STM_EVAL_LEDOn(LED4);
 
      //STM_EVAL_LEDOn(LED3);
 
      
 
      /* wait for 1s */
 
      Delay(300);
 
      
 
      /* Turn off LD4 Blue LED after 1s each time User button is pressed */
 
      STM_EVAL_LEDOff(LED4);
 
      Delay(300);
 
  }
 
}
 
 
/**
 
  * @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;
 
 
  while(TimingDelay != 0);
 
}
 
 
/**
 
  * @brief  Decrements the TimingDelay variable.
 
  * @param  None
 
  * @retval None
 
  */
 
void TimingDelay_Decrement(void)
 
{
 
  if (TimingDelay != 0x00)
 
  { 
 
    TimingDelay--;
 
  }
 
}
 
 
 
 
void init_spi(void) {
 
	SPI_InitTypeDef  SPI_InitStructure;
 
0 comments (0 inline, 0 general)