Files @ 7e79a737e34d
Branch filter:

Location: therm/gpio.c - annotation

Ethan Zonca
Cleanup
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
ab7abb62e433
#include "gpio.h"
#include "config.h"
#include "stm32f0xx_hal_conf.h"
#include <inttypes.h>

// Increase on each press, and increase at a fast rate after duration elapsed of continuously holding down... somehow...
uint32_t change_time_reset = 0;

void user_input(uint16_t* to_modify)
{
    if(CHANGE_ELAPSED) {
        if(!HAL_GPIO_ReadPin(SW_UP) ) {
            CHANGE_RESET;
            (*to_modify)++;
        }
        else if(!HAL_GPIO_ReadPin(SW_DOWN) && (*to_modify) > 0) {
            CHANGE_RESET;
            (*to_modify)--;
        }
    }
}


void init_gpio(void) {

  GPIO_InitTypeDef GPIO_InitStruct;

    /* GPIO Ports Clock Enable */
  __GPIOF_CLK_ENABLE();
  __GPIOA_CLK_ENABLE();
  __GPIOB_CLK_ENABLE();
  __SPI1_CLK_ENABLE();

   
  //////////////////
  // PORT F       //
  //////////////////  
  
  // PORTF OUTPUT
  // Configure GPIO pin : PF0 [Power LED]
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);

  // PORTF UNUSED
  // Configure GPIO pin : PF1
  GPIO_InitStruct.Pin = GPIO_PIN_1;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);

  
  //////////////////
  // PORT A       //
  //////////////////
  
  // PORT A OUTPUT
  // Configure GPIO pins : (SSR+ CS_OLED RES D/C CS_MAX)
  GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_15;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
  // PORTA INPUT
  // Configure GPIO pin : PA15 
//  GPIO_InitStruct.Pin = GPIO_PIN_15;
//  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
//  GPIO_InitStruct.Pull = GPIO_PULLUP;
//  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  // PORTA UNUSED
  // Configure GPIO pins : PA0 PA8
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_8;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
  // USART1 [PORTA]
  // Configure GPIO pins : PA9 PA10
  GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  // SPI1 [PORTA]
  // Configure GPIO pin : PA, MOSI, SCK 
  GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_5;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
  // Configure GPIO pin: PA, MISO
  GPIO_InitStruct.Pin = GPIO_PIN_6;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  // USB [PORTA]

  /** USB GPIO Configuration  
  PA11   ------> USB_DM
  PA12   ------> USB_DP
  */  
  // Configure GPIO pin : PA, D+, D-
  GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF2_USB; // Can also be AF5
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  
  //////////////////
  // PORT B       //
  //////////////////
  
  // PORT B UNUSED
  // Configure GPIO pins : PB0 PB1 PB8 
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  // PORT B INPUT
  // Configure GPIO pins : PB3 PB4 PB5 PB6 PB7
  GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6 
                          |GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);  
  
  
  // Enable DMA clocks (Is AHB even the right thing???)
  //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); // EMZ TODO get the right ones


}

// vim:softtabstop=4 shiftwidth=4 expandtab