make GPIO pins configurable (check config.h)

This commit is contained in:
Hubert Denkmair 2016-04-16 11:45:39 +02:00
parent e7d1eae903
commit f9e69bd780
6 changed files with 123 additions and 127 deletions

35
include/config.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
#ifndef BOARD
#define BOARD candleLight
#endif
#if BOARD == candleLight
#define CAN_S_Pin GPIO_PIN_13
#define CAN_S_GPIO_Port GPIOC
#define LED1_GPIO_Port GPIOA
#define LED1_Pin GPIO_PIN_0
#define LED1_Mode GPIO_MODE_OUTPUT_OD
#define LED1_Active_Low
#define LED2_GPIO_Port GPIOA
#define LED2_Pin GPIO_PIN_1
#define LED2_Mode GPIO_MODE_OUTPUT_OD
#define LED2_Active_Low
#elif BOARD == cantact
// SILENT pin not connected
#define LED1_GPIO_Port GPIOB
#define LED1_Pin GPIO_PIN_0
#define LED1_Mode GPIO_MODE_OUTPUT_PP
#define LED2_GPIO_Port GPIOB
#define LED2_Pin GPIO_PIN_1
#define LED2_Mode GPIO_MODE_OUTPUT_PP
#endif

3
include/gpio.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
void gpio_init();

View File

@ -1,59 +0,0 @@
/**
******************************************************************************
* File Name : mxconstants.h
* Description : This file contains the common defines of the application
******************************************************************************
*
* COPYRIGHT(c) 2016 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private define ------------------------------------------------------------*/
#define CAN_S_Pin GPIO_PIN_13
#define CAN_S_GPIO_Port GPIOC
#define LED1_Pin GPIO_PIN_0
#define LED1_GPIO_Port GPIOA
#define LED2_Pin GPIO_PIN_1
#define LED2_GPIO_Port GPIOA
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -40,7 +40,6 @@
extern "C" { extern "C" {
#endif #endif
#include "mxconstants.h"
/* Exported types ------------------------------------------------------------*/ /* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/

50
src/gpio.c Normal file
View File

@ -0,0 +1,50 @@
/*
* gpio.c
*
* Created on: 16.04.2016
* Author: hd
*/
#include "config.h"
#include "stm32f0xx_hal.h"
void gpio_init()
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
#ifdef CAN_S_Pin
HAL_GPIO_WritePin(CAN_S_GPIO_Port, CAN_S_Pin, GPIO_PIN_SET);
GPIO_InitStruct.Pin = CAN_S_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(CAN_S_GPIO_Port, &GPIO_InitStruct);
#endif
#ifdef LED1_Active_Low
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
#else
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
#endif
GPIO_InitStruct.Pin = LED1_Pin;
GPIO_InitStruct.Mode = LED1_Mode;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED1_GPIO_Port, &GPIO_InitStruct);
#ifdef LED2_Active_Low
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
#else
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
#endif
GPIO_InitStruct.Pin = LED2_Pin;
GPIO_InitStruct.Mode = LED2_Mode;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED2_GPIO_Port, &GPIO_InitStruct);
}

View File

@ -1,8 +1,10 @@
#include "config.h"
#include "stm32f0xx_hal.h" #include "stm32f0xx_hal.h"
#include "usbd_def.h" #include "usbd_def.h"
#include "usbd_desc.h" #include "usbd_desc.h"
#include "usbd_core.h" #include "usbd_core.h"
#include "usbd_gs_can.h" #include "usbd_gs_can.h"
#include <gpio.h>
#include <queue.h> #include <queue.h>
#include <gs_usb.h> #include <gs_usb.h>
#include <can.h> #include <can.h>
@ -11,7 +13,6 @@
#define CAN_QUEUE_SIZE 64 #define CAN_QUEUE_SIZE 64
void SystemClock_Config(void); void SystemClock_Config(void);
static void MX_GPIO_Init(void);
CAN_HandleTypeDef hCAN; CAN_HandleTypeDef hCAN;
@ -40,7 +41,8 @@ int main(void)
HAL_Init(); HAL_Init();
SystemClock_Config(); SystemClock_Config();
MX_GPIO_Init();
gpio_init();
led_init(&hLED, LED1_GPIO_Port, LED1_Pin, false, LED2_GPIO_Port, LED2_Pin, false); led_init(&hLED, LED1_GPIO_Port, LED1_Pin, false, LED2_GPIO_Port, LED2_Pin, false);
led_set_mode(&hLED, led_mode_off); led_set_mode(&hLED, led_mode_off);
@ -63,10 +65,9 @@ int main(void)
USBD_GS_CAN_SetChannel(&hUSB, 0, &hCAN); USBD_GS_CAN_SetChannel(&hUSB, 0, &hCAN);
USBD_Start(&hUSB); USBD_Start(&hUSB);
#ifdef CAN_S_GPIO_Port
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(CAN_S_GPIO_Port, CAN_S_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(CAN_S_GPIO_Port, CAN_S_Pin, GPIO_PIN_RESET);
#endif
while (1) { while (1) {
@ -120,7 +121,6 @@ int main(void)
void SystemClock_Config(void) void SystemClock_Config(void)
{ {
RCC_OscInitTypeDef RCC_OscInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit; RCC_PeriphCLKInitTypeDef PeriphClkInit;
@ -159,35 +159,3 @@ void SystemClock_Config(void)
/* SysTick_IRQn interrupt configuration */ /* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
} }
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(CAN_S_GPIO_Port, CAN_S_Pin, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, LED1_Pin|LED2_Pin, GPIO_PIN_SET);
/*Configure GPIO pin : CAN_S_Pin */
GPIO_InitStruct.Pin = CAN_S_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(CAN_S_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : LED1_Pin LED2_Pin */
GPIO_InitStruct.Pin = LED1_Pin|LED2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}