Changeset - a50c5fa22b95
[Not reviewed]
default
0 1 0
Ethan Zonca - 10 years ago 2014-07-14 22:10:53
ez@ethanzonca.com
Added GPIO reads
1 file changed with 31 insertions and 5 deletions:
main.c
31
5
0 comments (0 inline, 0 general)
main.c
Show inline comments
 
@@ -2,12 +2,21 @@
 
#include "stm32l100c_discovery.h"
 
#include "ssd1306.h"
 
 
#define LED_POWER GPIOB,GPIO_Pin_9
 
#define LED_STAT  GPIOA,GPIO_Pin_15
 
 
 
// TODO: Grab buttonpresses with interrupts
 
#define SW_BTN  GPIOB, GPIO_Pin_3
 
#define SW_UP   GPIOB, GPIO_Pin_7
 
#define SW_DOWN GPIOB, GPIO_Pin_6
 
#define SW_LEFT GPIOB, GPIO_Pin_5
 
#define SW_RIGHT GPIOB, GPIO_Pin_4
 
 
 
static __IO uint32_t TimingDelay;
 
 
void init_gpio();
 
void init_spi();
 
 
int main(void)
 
@@ -22,25 +31,42 @@ int main(void)
 
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
 
 
    GPIO_ResetBits(LED_STAT);
 
    Delay(100);
 
 
    init_gpio();
 
    init_spi();
 
 
    ssd1306_Init();
 
    ssd1306_DrawPoint(3,3,1);
 
    ssd1306_DrawPoint(5,5,0);
 
 
    GPIO_SetBits(LED_POWER);
 
    Delay(500);
 
    GPIO_ResetBits(LED_POWER);
 
 
 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
 
 
    init_spi();
 
 
    while(1)
 
    {  
 
        ssd1306_DrawPoint(5,5,0);
 
   {  
 
        // TODO: Grab buttonpresses with interrupts
 
        uint8_t sw_btn = GPIO_ReadInputDataBit(SW_BTN);
 
        uint8_t sw_up = GPIO_ReadInputDataBit(SW_UP);
 
        uint8_t sw_down = GPIO_ReadInputDataBit(SW_DOWN);
 
        uint8_t sw_left = GPIO_ReadInputDataBit(SW_LEFT);
 
        uint8_t sw_right = GPIO_ReadInputDataBit(SW_RIGHT);
 
 
        SPI_I2S_SendData(SPI2,0xFA);
 
        SPI_I2S_SendData(SPI1,0xFA);
 
 
        if(!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_3)) {
 
            GPIO_ToggleBits(LED_STAT);
 
        }
 
//        ssd1306_DrawPoint(5,5,0);
 
        GPIO_SetBits(LED_POWER);
 
        Delay(150);
 
        GPIO_ResetBits(LED_POWER);
 
        Delay(150);
 
    }
 
}
 
@@ -53,12 +79,13 @@ int main(void)
 
void Delay(__IO uint32_t nTime)
 
{
 
  TimingDelay = nTime;
 
  while(TimingDelay != 0);
 
}
 
 
 
/**
 
  * @brief  Decrements the TimingDelay variable.
 
  * @param  None
 
  * @retval None
 
  */
 
void TimingDelay_Decrement(void)
 
@@ -67,13 +94,12 @@ void TimingDelay_Decrement(void)
 
  { 
 
    TimingDelay--;
 
  }
 
}
 
 
 
 
void init_spi(void)
 
{
 
    SPI_InitTypeDef  SPI_InitStructure;
 
 
    // OLED IC
 
    SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
 
@@ -142,13 +168,13 @@ void init_gpio(void) {
 
  GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 
  /*Configure GPIO pin : PB */
 
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6 
 
                          |GPIO_Pin_7;
 
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
 
  GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 
  /** SPI1 GPIO Configuration  
 
  PA5   ------> SPI1_SCK
 
  PA7   ------> SPI1_MOSI
 
  */
0 comments (0 inline, 0 general)