HXC Client Shield Repository.

Dependencies:   mbed

Committer:
kashish_mbed
Date:
Mon Mar 29 15:37:08 2021 +0000
Revision:
0:bacc6e701fb4
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kashish_mbed 0:bacc6e701fb4 1 /*
kashish_mbed 0:bacc6e701fb4 2 / _____) _ | |
kashish_mbed 0:bacc6e701fb4 3 ( (____ _____ ____ _| |_ _____ ____| |__
kashish_mbed 0:bacc6e701fb4 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
kashish_mbed 0:bacc6e701fb4 5 _____) ) ____| | | || |_| ____( (___| | | |
kashish_mbed 0:bacc6e701fb4 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
kashish_mbed 0:bacc6e701fb4 7 (C)2013 Semtech
kashish_mbed 0:bacc6e701fb4 8
kashish_mbed 0:bacc6e701fb4 9 Description: Bleeper board GPIO driver implementation
kashish_mbed 0:bacc6e701fb4 10
kashish_mbed 0:bacc6e701fb4 11 License: Revised BSD License, see LICENSE.TXT file include in the project
kashish_mbed 0:bacc6e701fb4 12
kashish_mbed 0:bacc6e701fb4 13 Maintainer: Miguel Luis and Gregory Cristian
kashish_mbed 0:bacc6e701fb4 14 */
kashish_mbed 0:bacc6e701fb4 15 /******************************************************************************
kashish_mbed 0:bacc6e701fb4 16 * @file hw_gpio.c
kashish_mbed 0:bacc6e701fb4 17 * @author MCD Application Team
kashish_mbed 0:bacc6e701fb4 18 * @version V1.1.4
kashish_mbed 0:bacc6e701fb4 19 * @date 08-January-2018
kashish_mbed 0:bacc6e701fb4 20 * @brief driver for GPIO
kashish_mbed 0:bacc6e701fb4 21 ******************************************************************************
kashish_mbed 0:bacc6e701fb4 22 * @attention
kashish_mbed 0:bacc6e701fb4 23 *
kashish_mbed 0:bacc6e701fb4 24 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
kashish_mbed 0:bacc6e701fb4 25 * All rights reserved.</center></h2>
kashish_mbed 0:bacc6e701fb4 26 *
kashish_mbed 0:bacc6e701fb4 27 * Redistribution and use in source and binary forms, with or without
kashish_mbed 0:bacc6e701fb4 28 * modification, are permitted, provided that the following conditions are met:
kashish_mbed 0:bacc6e701fb4 29 *
kashish_mbed 0:bacc6e701fb4 30 * 1. Redistribution of source code must retain the above copyright notice,
kashish_mbed 0:bacc6e701fb4 31 * this list of conditions and the following disclaimer.
kashish_mbed 0:bacc6e701fb4 32 * 2. Redistributions in binary form must reproduce the above copyright notice,
kashish_mbed 0:bacc6e701fb4 33 * this list of conditions and the following disclaimer in the documentation
kashish_mbed 0:bacc6e701fb4 34 * and/or other materials provided with the distribution.
kashish_mbed 0:bacc6e701fb4 35 * 3. Neither the name of STMicroelectronics nor the names of other
kashish_mbed 0:bacc6e701fb4 36 * contributors to this software may be used to endorse or promote products
kashish_mbed 0:bacc6e701fb4 37 * derived from this software without specific written permission.
kashish_mbed 0:bacc6e701fb4 38 * 4. This software, including modifications and/or derivative works of this
kashish_mbed 0:bacc6e701fb4 39 * software, must execute solely and exclusively on microcontroller or
kashish_mbed 0:bacc6e701fb4 40 * microprocessor devices manufactured by or for STMicroelectronics.
kashish_mbed 0:bacc6e701fb4 41 * 5. Redistribution and use of this software other than as permitted under
kashish_mbed 0:bacc6e701fb4 42 * this license is void and will automatically terminate your rights under
kashish_mbed 0:bacc6e701fb4 43 * this license.
kashish_mbed 0:bacc6e701fb4 44 *
kashish_mbed 0:bacc6e701fb4 45 * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
kashish_mbed 0:bacc6e701fb4 46 * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
kashish_mbed 0:bacc6e701fb4 47 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
kashish_mbed 0:bacc6e701fb4 48 * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
kashish_mbed 0:bacc6e701fb4 49 * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
kashish_mbed 0:bacc6e701fb4 50 * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
kashish_mbed 0:bacc6e701fb4 51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
kashish_mbed 0:bacc6e701fb4 52 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
kashish_mbed 0:bacc6e701fb4 53 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
kashish_mbed 0:bacc6e701fb4 54 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
kashish_mbed 0:bacc6e701fb4 55 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
kashish_mbed 0:bacc6e701fb4 56 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
kashish_mbed 0:bacc6e701fb4 57 *
kashish_mbed 0:bacc6e701fb4 58 ******************************************************************************
kashish_mbed 0:bacc6e701fb4 59 */
kashish_mbed 0:bacc6e701fb4 60
kashish_mbed 0:bacc6e701fb4 61 /* Includes ------------------------------------------------------------------*/
kashish_mbed 0:bacc6e701fb4 62 #include "hw.h"
kashish_mbed 0:bacc6e701fb4 63
kashish_mbed 0:bacc6e701fb4 64 /* Private typedef -----------------------------------------------------------*/
kashish_mbed 0:bacc6e701fb4 65 /* Private define ------------------------------------------------------------*/
kashish_mbed 0:bacc6e701fb4 66 /* Private macro -------------------------------------------------------------*/
kashish_mbed 0:bacc6e701fb4 67 /* Private variables ---------------------------------------------------------*/
kashish_mbed 0:bacc6e701fb4 68 static GpioIrqHandler *GpioIrq[16] = { NULL };
kashish_mbed 0:bacc6e701fb4 69
kashish_mbed 0:bacc6e701fb4 70 /* Private function prototypes -----------------------------------------------*/
kashish_mbed 0:bacc6e701fb4 71
kashish_mbed 0:bacc6e701fb4 72 static uint8_t HW_GPIO_GetBitPos(uint16_t GPIO_Pin);
kashish_mbed 0:bacc6e701fb4 73 static IRQn_Type MSP_GetIRQn( uint16_t gpioPin);
kashish_mbed 0:bacc6e701fb4 74
kashish_mbed 0:bacc6e701fb4 75 /* Exported functions ---------------------------------------------------------*/
kashish_mbed 0:bacc6e701fb4 76 /*!
kashish_mbed 0:bacc6e701fb4 77 * @brief Initializes the given GPIO object
kashish_mbed 0:bacc6e701fb4 78 *
kashish_mbed 0:bacc6e701fb4 79 * @param GPIOx: where x can be (A..E and H)
kashish_mbed 0:bacc6e701fb4 80 * @param GPIO_Pin: specifies the port bit to be written.
kashish_mbed 0:bacc6e701fb4 81 * This parameter can be one of GPIO_PIN_x where x can be (0..15).
kashish_mbed 0:bacc6e701fb4 82 * All port bits are not necessarily available on all GPIOs.
kashish_mbed 0:bacc6e701fb4 83 * @param [IN] initStruct GPIO_InitTypeDef intit structure
kashish_mbed 0:bacc6e701fb4 84 * @retval none
kashish_mbed 0:bacc6e701fb4 85 */
kashish_mbed 0:bacc6e701fb4 86 void HW_GPIO_Init( GPIO_TypeDef* port, uint16_t GPIO_Pin, GPIO_InitTypeDef* initStruct)
kashish_mbed 0:bacc6e701fb4 87 {
kashish_mbed 0:bacc6e701fb4 88
kashish_mbed 0:bacc6e701fb4 89 RCC_GPIO_CLK_ENABLE( (uint32_t) port);
kashish_mbed 0:bacc6e701fb4 90
kashish_mbed 0:bacc6e701fb4 91 initStruct->Pin = GPIO_Pin ;
kashish_mbed 0:bacc6e701fb4 92
kashish_mbed 0:bacc6e701fb4 93 HAL_GPIO_Init( port, initStruct );
kashish_mbed 0:bacc6e701fb4 94 }
kashish_mbed 0:bacc6e701fb4 95
kashish_mbed 0:bacc6e701fb4 96 /*!
kashish_mbed 0:bacc6e701fb4 97 * @brief Records the interrupt handler for the GPIO object
kashish_mbed 0:bacc6e701fb4 98 *
kashish_mbed 0:bacc6e701fb4 99 * @param GPIOx: where x can be (A..E and H)
kashish_mbed 0:bacc6e701fb4 100 * @param GPIO_Pin: specifies the port bit to be written.
kashish_mbed 0:bacc6e701fb4 101 * This parameter can be one of GPIO_PIN_x where x can be (0..15).
kashish_mbed 0:bacc6e701fb4 102 * All port bits are not necessarily available on all GPIOs.
kashish_mbed 0:bacc6e701fb4 103 * @param [IN] prio NVIC priority (0 is highest)
kashish_mbed 0:bacc6e701fb4 104 * @param [IN] irqHandler points to the function to execute
kashish_mbed 0:bacc6e701fb4 105 * @retval none
kashish_mbed 0:bacc6e701fb4 106 */
kashish_mbed 0:bacc6e701fb4 107 void HW_GPIO_SetIrq( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t prio, GpioIrqHandler *irqHandler )
kashish_mbed 0:bacc6e701fb4 108 {
kashish_mbed 0:bacc6e701fb4 109 IRQn_Type IRQnb;
kashish_mbed 0:bacc6e701fb4 110
kashish_mbed 0:bacc6e701fb4 111 uint32_t BitPos = HW_GPIO_GetBitPos( GPIO_Pin ) ;
kashish_mbed 0:bacc6e701fb4 112
kashish_mbed 0:bacc6e701fb4 113 if ( irqHandler != NULL)
kashish_mbed 0:bacc6e701fb4 114 {
kashish_mbed 0:bacc6e701fb4 115 GpioIrq[ BitPos ] = irqHandler;
kashish_mbed 0:bacc6e701fb4 116
kashish_mbed 0:bacc6e701fb4 117 IRQnb = MSP_GetIRQn( GPIO_Pin );
kashish_mbed 0:bacc6e701fb4 118
kashish_mbed 0:bacc6e701fb4 119 HAL_NVIC_SetPriority( IRQnb , prio, 0);
kashish_mbed 0:bacc6e701fb4 120
kashish_mbed 0:bacc6e701fb4 121 HAL_NVIC_EnableIRQ( IRQnb );
kashish_mbed 0:bacc6e701fb4 122 }
kashish_mbed 0:bacc6e701fb4 123 else
kashish_mbed 0:bacc6e701fb4 124 {
kashish_mbed 0:bacc6e701fb4 125 GpioIrq[ BitPos ] = NULL;
kashish_mbed 0:bacc6e701fb4 126 }
kashish_mbed 0:bacc6e701fb4 127 }
kashish_mbed 0:bacc6e701fb4 128
kashish_mbed 0:bacc6e701fb4 129 /*!
kashish_mbed 0:bacc6e701fb4 130 * @brief Execute the interrupt from the object
kashish_mbed 0:bacc6e701fb4 131 *
kashish_mbed 0:bacc6e701fb4 132 * @param GPIO_Pin: specifies the port bit to be written.
kashish_mbed 0:bacc6e701fb4 133 * This parameter can be one of GPIO_PIN_x where x can be (0..15).
kashish_mbed 0:bacc6e701fb4 134 * All port bits are not necessarily available on all GPIOs.
kashish_mbed 0:bacc6e701fb4 135 * @retval none
kashish_mbed 0:bacc6e701fb4 136 */
kashish_mbed 0:bacc6e701fb4 137 void HW_GPIO_IrqHandler( uint16_t GPIO_Pin )
kashish_mbed 0:bacc6e701fb4 138 {
kashish_mbed 0:bacc6e701fb4 139 uint32_t BitPos = HW_GPIO_GetBitPos( GPIO_Pin );
kashish_mbed 0:bacc6e701fb4 140
kashish_mbed 0:bacc6e701fb4 141 if ( GpioIrq[ BitPos ] != NULL)
kashish_mbed 0:bacc6e701fb4 142 {
kashish_mbed 0:bacc6e701fb4 143 GpioIrq[ BitPos ] ( );
kashish_mbed 0:bacc6e701fb4 144 }
kashish_mbed 0:bacc6e701fb4 145 }
kashish_mbed 0:bacc6e701fb4 146
kashish_mbed 0:bacc6e701fb4 147 /*!
kashish_mbed 0:bacc6e701fb4 148 * @brief Writes the given value to the GPIO output
kashish_mbed 0:bacc6e701fb4 149 *
kashish_mbed 0:bacc6e701fb4 150 * @param GPIO_Pin: specifies the port bit to be written.
kashish_mbed 0:bacc6e701fb4 151 * This parameter can be one of GPIO_PIN_x where x can be (0..15).
kashish_mbed 0:bacc6e701fb4 152 * All port bits are not necessarily available on all GPIOs.
kashish_mbed 0:bacc6e701fb4 153 * @param [IN] value New GPIO output value
kashish_mbed 0:bacc6e701fb4 154 * @retval none
kashish_mbed 0:bacc6e701fb4 155 */
kashish_mbed 0:bacc6e701fb4 156 void HW_GPIO_Write( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t value )
kashish_mbed 0:bacc6e701fb4 157 {
kashish_mbed 0:bacc6e701fb4 158 HAL_GPIO_WritePin( GPIOx, GPIO_Pin , (GPIO_PinState) value );
kashish_mbed 0:bacc6e701fb4 159 }
kashish_mbed 0:bacc6e701fb4 160
kashish_mbed 0:bacc6e701fb4 161 /*!
kashish_mbed 0:bacc6e701fb4 162 * @brief Reads the current GPIO input value
kashish_mbed 0:bacc6e701fb4 163 *
kashish_mbed 0:bacc6e701fb4 164 * @param GPIOx: where x can be (A..E and H)
kashish_mbed 0:bacc6e701fb4 165 * @param GPIO_Pin: specifies the port bit to be written.
kashish_mbed 0:bacc6e701fb4 166 * This parameter can be one of GPIO_PIN_x where x can be (0..15).
kashish_mbed 0:bacc6e701fb4 167 * All port bits are not necessarily available on all GPIOs.
kashish_mbed 0:bacc6e701fb4 168 * @retval value Current GPIO input value
kashish_mbed 0:bacc6e701fb4 169 */
kashish_mbed 0:bacc6e701fb4 170 uint32_t HW_GPIO_Read( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin )
kashish_mbed 0:bacc6e701fb4 171 {
kashish_mbed 0:bacc6e701fb4 172 return HAL_GPIO_ReadPin( GPIOx, GPIO_Pin);
kashish_mbed 0:bacc6e701fb4 173 }
kashish_mbed 0:bacc6e701fb4 174
kashish_mbed 0:bacc6e701fb4 175 /* Private functions ---------------------------------------------------------*/
kashish_mbed 0:bacc6e701fb4 176
kashish_mbed 0:bacc6e701fb4 177 /*!
kashish_mbed 0:bacc6e701fb4 178 * @brief Get the position of the bit set in the GPIO_Pin
kashish_mbed 0:bacc6e701fb4 179 * @param GPIO_Pin: specifies the port bit to be written.
kashish_mbed 0:bacc6e701fb4 180 * This parameter can be one of GPIO_PIN_x where x can be (0..15).
kashish_mbed 0:bacc6e701fb4 181 * All port bits are not necessarily available on all GPIOs.
kashish_mbed 0:bacc6e701fb4 182 * @retval the position of the bit
kashish_mbed 0:bacc6e701fb4 183 */
kashish_mbed 0:bacc6e701fb4 184 static uint8_t HW_GPIO_GetBitPos(uint16_t GPIO_Pin)
kashish_mbed 0:bacc6e701fb4 185 {
kashish_mbed 0:bacc6e701fb4 186 uint8_t PinPos=0;
kashish_mbed 0:bacc6e701fb4 187
kashish_mbed 0:bacc6e701fb4 188 if ( ( GPIO_Pin & 0xFF00 ) != 0) { PinPos |= 0x8; }
kashish_mbed 0:bacc6e701fb4 189 if ( ( GPIO_Pin & 0xF0F0 ) != 0) { PinPos |= 0x4; }
kashish_mbed 0:bacc6e701fb4 190 if ( ( GPIO_Pin & 0xCCCC ) != 0) { PinPos |= 0x2; }
kashish_mbed 0:bacc6e701fb4 191 if ( ( GPIO_Pin & 0xAAAA ) != 0) { PinPos |= 0x1; }
kashish_mbed 0:bacc6e701fb4 192
kashish_mbed 0:bacc6e701fb4 193 return PinPos;
kashish_mbed 0:bacc6e701fb4 194 }
kashish_mbed 0:bacc6e701fb4 195
kashish_mbed 0:bacc6e701fb4 196
kashish_mbed 0:bacc6e701fb4 197 /*!
kashish_mbed 0:bacc6e701fb4 198 * GPIO IRQ handler function prototype
kashish_mbed 0:bacc6e701fb4 199 */
kashish_mbed 0:bacc6e701fb4 200 static IRQn_Type MSP_GetIRQn(uint16_t GPIO_Pin)
kashish_mbed 0:bacc6e701fb4 201 {
kashish_mbed 0:bacc6e701fb4 202 switch (GPIO_Pin)
kashish_mbed 0:bacc6e701fb4 203 {
kashish_mbed 0:bacc6e701fb4 204 case GPIO_PIN_0:
kashish_mbed 0:bacc6e701fb4 205 case GPIO_PIN_1: return EXTI0_1_IRQn;
kashish_mbed 0:bacc6e701fb4 206 case GPIO_PIN_2:
kashish_mbed 0:bacc6e701fb4 207 case GPIO_PIN_3: return EXTI2_3_IRQn;
kashish_mbed 0:bacc6e701fb4 208 case GPIO_PIN_4:
kashish_mbed 0:bacc6e701fb4 209 case GPIO_PIN_5:
kashish_mbed 0:bacc6e701fb4 210 case GPIO_PIN_6:
kashish_mbed 0:bacc6e701fb4 211 case GPIO_PIN_7:
kashish_mbed 0:bacc6e701fb4 212 case GPIO_PIN_8:
kashish_mbed 0:bacc6e701fb4 213 case GPIO_PIN_9:
kashish_mbed 0:bacc6e701fb4 214 case GPIO_PIN_10:
kashish_mbed 0:bacc6e701fb4 215 case GPIO_PIN_11:
kashish_mbed 0:bacc6e701fb4 216 case GPIO_PIN_12:
kashish_mbed 0:bacc6e701fb4 217 case GPIO_PIN_13:
kashish_mbed 0:bacc6e701fb4 218 case GPIO_PIN_14:
kashish_mbed 0:bacc6e701fb4 219 case GPIO_PIN_15:
kashish_mbed 0:bacc6e701fb4 220 default: return EXTI4_15_IRQn;
kashish_mbed 0:bacc6e701fb4 221 }
kashish_mbed 0:bacc6e701fb4 222 }
kashish_mbed 0:bacc6e701fb4 223
kashish_mbed 0:bacc6e701fb4 224 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
kashish_mbed 0:bacc6e701fb4 225