# HG changeset patch # User Ethan Zonca # Date 2014-07-14 22:10:53 # Node ID a50c5fa22b95037b5dfbd13b692dd856d4100bfb # Parent 3e00cf5fc57d7d6ad192e84adaf8307a822ae7cd Added GPIO reads diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -5,6 +5,15 @@ #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(); @@ -25,7 +34,6 @@ int main(void) Delay(100); init_gpio(); - init_spi(); ssd1306_Init(); ssd1306_DrawPoint(3,3,1); @@ -35,9 +43,27 @@ int main(void) 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); @@ -56,6 +82,7 @@ void Delay(__IO uint32_t nTime) while(TimingDelay != 0); } + /** * @brief Decrements the TimingDelay variable. * @param None @@ -70,7 +97,6 @@ void TimingDelay_Decrement(void) } - void init_spi(void) { SPI_InitTypeDef SPI_InitStructure; @@ -145,7 +171,7 @@ void init_gpio(void) { 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