my_app.c
/**
******************************************************************************
* @file my_defines.h
* @author river
* @version V1.0
* @date 2020-12-12
* @brief This file contains all the functions prototypes.
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "my_defines.h"
/**
* @brief Fills each GPIO_InitStruct member with its default value.
* @param GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will
* be initialized.
* @retval None
*/
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
{
/* Reset GPIO init structure parameters values */
GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;
}
/**
* @brief Reads the specified input port pin.
* @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
* @param GPIO_Pin: specifies the port bit to read.
* This parameter can be GPIO_Pin_x where x can be (0..15).
* @retval The input port pin value.
*/
my_uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, my_uint16_t GPIO_Pin)
{
my_uint8_t bitstatus = 0x00;
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
if ((GPIOx->IDR & GPIO_Pin) != (my_uint32_t)Bit_RESET)
{
bitstatus = (my_uint8_t)Bit_SET;
}
else
{
bitstatus = (my_uint8_t)Bit_RESET;
}
return bitstatus;
}
/******************* (C) COPYRIGHT 2020 MY *****END OF FILE****/
my_defines.h
/**
******************************************************************************
* @file my_defines.h
* @author river
* @version V1.0
* @date 2020-12-12
* @brief This file contains all the functions prototypes.
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MY_DEFINES_H__
#define __MY_DEFINES_H__
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define __IO volatile /*!< defines 'read / write' permissions */
/* define datatype,modify by different system----------------------------------*/
#define my_int8_t char
#define my_uint8_t unsigned char
#define my_int16_t short
#define my_uint16_t unsigned short
#define my_int32_t int
#define my_uint32_t unsigned int
#define my_int64_t long long
#define my_uint64_t unsigned long long
#define my_double_t double
#define my_null NULL
#define my_sizeof sizeof
/* define funtions,modify by different system-----------------------------------*/
#define my_memcpy memcpy
#define my_memset memset
#define my_memcmp memcmp
#define my_strlen strlen
#define my_sprintf sprintf
#define my_printf printf
#define my_snprintf snprintf
#define my_strcpy strcpy
#define my_strncpy strncpy
#define my_strcmp strcmp
#define my_strchr strchr
#define my_strstr strstr
#define my_strtoul strtoul
#define MY_FUNTION
/* user macro defines------------------------------------------------------------------*/
#define MY_DEV_NAME_MAX ((my_uint16_t)16) /*!< Pin 0 selected */
#define MY_MQTT_VERSION ((my_uint8_t)3) /*!< Pin 0 selected */
/* user enum define------------------------------------------------------------------*/
/**
* @brief Output Maximum frequency selection
*/
typedef enum
{
GPIO_Speed_10MHz = 1,
GPIO_Speed_2MHz,
GPIO_Speed_50MHz
} GPIOSpeed_TypeDef;
/**
* @brief Configuration Mode enumeration
*/
typedef enum
{
GPIO_Mode_AIN = 0x0,
GPIO_Mode_IN_FLOATING = 0x04,
GPIO_Mode_IPD = 0x28,
GPIO_Mode_IPU = 0x48,
GPIO_Mode_Out_OD = 0x14,
GPIO_Mode_Out_PP = 0x10,
GPIO_Mode_AF_OD = 0x1C,
GPIO_Mode_AF_PP = 0x18
} GPIOMode_TypeDef;
/* user struct define------------------------------------------------------------------*/
/**
* @brief GPIO Init struct definition
*/
typedef struct
{
my_uint16_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.*/
GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.*/
GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.*/
} GPIO_InitTypeDef;
/**
* @brief General Purpose I/O
*/
typedef struct
{
__IO my_uint32_t CRL;
__IO my_uint32_t CRH;
__IO my_uint32_t IDR;
__IO my_uint32_t ODR;
__IO my_uint32_t BSRR;
__IO my_uint32_t BRR;
__IO my_uint32_t LCKR;
} GPIO_TypeDef;
/* user functions define------------------------------------------------------------------*/
/** @defgroup GPIO_Exported_Functions
* @{
*/
MY_FUNTION void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
MY_FUNTION my_uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, my_uint16_t GPIO_Pin);
#ifdef __cplusplus
}
#endif
#endif /* __MY_DEFINES_H__ */
/******************* (C) COPYRIGHT 2020 MY *****END OF FILE****/