mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Sep 04 09:30:10 2015 +0100
Revision:
619:034e698bc035
Synchronized with git revision 92d1bfad30082571776c810a56fd471d30514ccf

Full URL: https://github.com/mbedmicro/mbed/commit/92d1bfad30082571776c810a56fd471d30514ccf/

Change directory structure and move files.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 619:034e698bc035 1 #include "W7500x.h"
mbed_official 619:034e698bc035 2 #include "W7500x_gpio.h"
mbed_official 619:034e698bc035 3
mbed_official 619:034e698bc035 4 void HAL_GPIO_DeInit(GPIO_TypeDef* GPIOx)
mbed_official 619:034e698bc035 5 {
mbed_official 619:034e698bc035 6 uint32_t i, loop =16;
mbed_official 619:034e698bc035 7 P_Port_Def *px_pcr;
mbed_official 619:034e698bc035 8 P_Port_Def *px_afsr;
mbed_official 619:034e698bc035 9
mbed_official 619:034e698bc035 10 /* Check the parameters */
mbed_official 619:034e698bc035 11 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
mbed_official 619:034e698bc035 12
mbed_official 619:034e698bc035 13 /* DeInit GPIOx Registers */
mbed_official 619:034e698bc035 14 GPIOx->DATA = 0x0000;
mbed_official 619:034e698bc035 15 GPIOx->DATAOUT = 0x0000;
mbed_official 619:034e698bc035 16 //GPIOx->OUTENSET = 0x0000;
mbed_official 619:034e698bc035 17 GPIOx->OUTENCLR = 0xFFFF;
mbed_official 619:034e698bc035 18 //GPIOx->INTENSET = 0x0000;
mbed_official 619:034e698bc035 19 GPIOx->INTENCLR = 0xFFFF;
mbed_official 619:034e698bc035 20 //GPIOx->INTTYPESET = 0x0000;
mbed_official 619:034e698bc035 21 GPIOx->INTTYPECLR = 0xFFFF;
mbed_official 619:034e698bc035 22 //GPIOx->INTPOLSET = 0x0000;
mbed_official 619:034e698bc035 23 GPIOx->INTPOLCLR = 0xFFFF;
mbed_official 619:034e698bc035 24
mbed_official 619:034e698bc035 25
mbed_official 619:034e698bc035 26 /* DeInit GPIOx
mbed_official 619:034e698bc035 27 * Pad Control Register
mbed_official 619:034e698bc035 28 * Pad Extern interrupt Enable Register
mbed_official 619:034e698bc035 29 * Pad Alternate Function Select Register
mbed_official 619:034e698bc035 30 */
mbed_official 619:034e698bc035 31 if (GPIOx == GPIOA)
mbed_official 619:034e698bc035 32 {
mbed_official 619:034e698bc035 33 px_pcr = PA_PCR;
mbed_official 619:034e698bc035 34 px_afsr = PA_AFSR;
mbed_official 619:034e698bc035 35 }
mbed_official 619:034e698bc035 36 else if (GPIOx == GPIOB)
mbed_official 619:034e698bc035 37 {
mbed_official 619:034e698bc035 38 px_pcr = PB_PCR;
mbed_official 619:034e698bc035 39 px_afsr = PB_AFSR;
mbed_official 619:034e698bc035 40 }
mbed_official 619:034e698bc035 41 else if (GPIOx == GPIOC)
mbed_official 619:034e698bc035 42 {
mbed_official 619:034e698bc035 43 px_pcr = PC_PCR;
mbed_official 619:034e698bc035 44 px_afsr = PC_AFSR;
mbed_official 619:034e698bc035 45 }
mbed_official 619:034e698bc035 46 else // if (GPIOx == GPIOD)
mbed_official 619:034e698bc035 47 {
mbed_official 619:034e698bc035 48 px_pcr = (P_Port_Def*)PD_PCR;
mbed_official 619:034e698bc035 49 px_afsr = (P_Port_Def*)PD_AFSR;
mbed_official 619:034e698bc035 50 loop = 5;
mbed_official 619:034e698bc035 51 }
mbed_official 619:034e698bc035 52
mbed_official 619:034e698bc035 53 for(i=0; i<loop; i++)
mbed_official 619:034e698bc035 54 {
mbed_official 619:034e698bc035 55 px_pcr->Port[i] = 0x60;
mbed_official 619:034e698bc035 56 px_afsr->Port[i] = PAD_AF0;
mbed_official 619:034e698bc035 57
mbed_official 619:034e698bc035 58 }
mbed_official 619:034e698bc035 59 }
mbed_official 619:034e698bc035 60
mbed_official 619:034e698bc035 61 void HAL_GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
mbed_official 619:034e698bc035 62 {
mbed_official 619:034e698bc035 63 uint32_t pinpos = 0x00, pos = 0x00, currentpin = 0x00, loop = 16;
mbed_official 619:034e698bc035 64 P_Port_Def *px_pcr;
mbed_official 619:034e698bc035 65
mbed_official 619:034e698bc035 66 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
mbed_official 619:034e698bc035 67 assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
mbed_official 619:034e698bc035 68 // assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
mbed_official 619:034e698bc035 69
mbed_official 619:034e698bc035 70 if (GPIOx == GPIOA) px_pcr = PA_PCR;
mbed_official 619:034e698bc035 71 else if (GPIOx == GPIOB) px_pcr = PB_PCR;
mbed_official 619:034e698bc035 72 else if (GPIOx == GPIOC) px_pcr = PC_PCR;
mbed_official 619:034e698bc035 73 else
mbed_official 619:034e698bc035 74 {
mbed_official 619:034e698bc035 75 px_pcr = (P_Port_Def*)PD_PCR;
mbed_official 619:034e698bc035 76 loop = 5;
mbed_official 619:034e698bc035 77 }
mbed_official 619:034e698bc035 78
mbed_official 619:034e698bc035 79 for(pinpos = 0x00; pinpos < loop; pinpos++)
mbed_official 619:034e698bc035 80 {
mbed_official 619:034e698bc035 81 pos = ((uint32_t)0x01) << pinpos;
mbed_official 619:034e698bc035 82
mbed_official 619:034e698bc035 83 currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
mbed_official 619:034e698bc035 84
mbed_official 619:034e698bc035 85 if(currentpin == pos)
mbed_official 619:034e698bc035 86 {
mbed_official 619:034e698bc035 87 if(GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT)
mbed_official 619:034e698bc035 88 {
mbed_official 619:034e698bc035 89 GPIOx->OUTENSET |= pos;
mbed_official 619:034e698bc035 90 }
mbed_official 619:034e698bc035 91 else // GPIO_Mode_In
mbed_official 619:034e698bc035 92 {
mbed_official 619:034e698bc035 93 GPIOx->OUTENCLR = pos;
mbed_official 619:034e698bc035 94 }
mbed_official 619:034e698bc035 95
mbed_official 619:034e698bc035 96 // Configure pull-up pull-down bits
mbed_official 619:034e698bc035 97 if(GPIO_InitStruct->GPIO_Pad & Px_PCR_PUPD_UP)
mbed_official 619:034e698bc035 98 {
mbed_official 619:034e698bc035 99 px_pcr->Port[pinpos] &= ~(Px_PCR_PUPD_UP | Px_PCR_PUPD_DOWN);
mbed_official 619:034e698bc035 100 px_pcr->Port[pinpos] |= Px_PCR_PUPD_UP;
mbed_official 619:034e698bc035 101 }
mbed_official 619:034e698bc035 102 else
mbed_official 619:034e698bc035 103 {
mbed_official 619:034e698bc035 104 px_pcr->Port[pinpos] &= ~(Px_PCR_PUPD_UP | Px_PCR_PUPD_DOWN);
mbed_official 619:034e698bc035 105 px_pcr->Port[pinpos] |= Px_PCR_PUPD_DOWN;
mbed_official 619:034e698bc035 106 }
mbed_official 619:034e698bc035 107
mbed_official 619:034e698bc035 108 // Configure Driving stregnth selections bit
mbed_official 619:034e698bc035 109 if(GPIO_InitStruct->GPIO_Pad & Px_PCR_DS_HIGH)
mbed_official 619:034e698bc035 110 {
mbed_official 619:034e698bc035 111 px_pcr->Port[pinpos] |= Px_PCR_DS_HIGH;
mbed_official 619:034e698bc035 112 }
mbed_official 619:034e698bc035 113 else
mbed_official 619:034e698bc035 114 {
mbed_official 619:034e698bc035 115 px_pcr->Port[pinpos] &= ~(Px_PCR_DS_HIGH);
mbed_official 619:034e698bc035 116 }
mbed_official 619:034e698bc035 117
mbed_official 619:034e698bc035 118 // Configure Open Drain selections bit
mbed_official 619:034e698bc035 119 if(GPIO_InitStruct->GPIO_Pad & Px_PCR_OD)
mbed_official 619:034e698bc035 120 {
mbed_official 619:034e698bc035 121 px_pcr->Port[pinpos] |= Px_PCR_OD;
mbed_official 619:034e698bc035 122 }
mbed_official 619:034e698bc035 123 else
mbed_official 619:034e698bc035 124 {
mbed_official 619:034e698bc035 125 px_pcr->Port[pinpos] &= ~(Px_PCR_OD);
mbed_official 619:034e698bc035 126 }
mbed_official 619:034e698bc035 127
mbed_official 619:034e698bc035 128 // Configure Input buffer enable selection bit
mbed_official 619:034e698bc035 129 if(GPIO_InitStruct->GPIO_Pad & Px_PCR_IE)
mbed_official 619:034e698bc035 130 {
mbed_official 619:034e698bc035 131 px_pcr->Port[pinpos] |= Px_PCR_IE;
mbed_official 619:034e698bc035 132 }
mbed_official 619:034e698bc035 133 else
mbed_official 619:034e698bc035 134 {
mbed_official 619:034e698bc035 135 px_pcr->Port[pinpos] &= ~(Px_PCR_IE);
mbed_official 619:034e698bc035 136 }
mbed_official 619:034e698bc035 137
mbed_official 619:034e698bc035 138 // Configure input type (CMOS input or Summit trigger input) select bit
mbed_official 619:034e698bc035 139 if(GPIO_InitStruct->GPIO_Pad & Px_PCR_CS_SUMMIT)
mbed_official 619:034e698bc035 140 {
mbed_official 619:034e698bc035 141 px_pcr->Port[pinpos] |= Px_PCR_CS_SUMMIT;
mbed_official 619:034e698bc035 142 }
mbed_official 619:034e698bc035 143 else
mbed_official 619:034e698bc035 144 {
mbed_official 619:034e698bc035 145 px_pcr->Port[pinpos] &= ~(Px_PCR_CS_SUMMIT);
mbed_official 619:034e698bc035 146 }
mbed_official 619:034e698bc035 147 }
mbed_official 619:034e698bc035 148 }
mbed_official 619:034e698bc035 149 }
mbed_official 619:034e698bc035 150
mbed_official 619:034e698bc035 151 void HAL_GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
mbed_official 619:034e698bc035 152 {
mbed_official 619:034e698bc035 153 GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
mbed_official 619:034e698bc035 154 GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
mbed_official 619:034e698bc035 155 GPIO_InitStruct->GPIO_Pad = (GPIOPad_TypeDef)(GPIO_PuPd_UP);
mbed_official 619:034e698bc035 156 }
mbed_official 619:034e698bc035 157
mbed_official 619:034e698bc035 158
mbed_official 619:034e698bc035 159 uint8_t HAL_GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
mbed_official 619:034e698bc035 160 {
mbed_official 619:034e698bc035 161 uint8_t bitstatus = 0x00;
mbed_official 619:034e698bc035 162
mbed_official 619:034e698bc035 163 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
mbed_official 619:034e698bc035 164 assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
mbed_official 619:034e698bc035 165
mbed_official 619:034e698bc035 166 if((GPIOx->DATA & GPIO_Pin) != (uint32_t)Bit_RESET)
mbed_official 619:034e698bc035 167 {
mbed_official 619:034e698bc035 168 bitstatus = (uint8_t)Bit_SET;
mbed_official 619:034e698bc035 169 }
mbed_official 619:034e698bc035 170 else
mbed_official 619:034e698bc035 171 {
mbed_official 619:034e698bc035 172 bitstatus = (uint8_t)Bit_RESET;
mbed_official 619:034e698bc035 173 }
mbed_official 619:034e698bc035 174
mbed_official 619:034e698bc035 175 return bitstatus;
mbed_official 619:034e698bc035 176 }
mbed_official 619:034e698bc035 177
mbed_official 619:034e698bc035 178 uint16_t HAL_GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
mbed_official 619:034e698bc035 179 {
mbed_official 619:034e698bc035 180 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
mbed_official 619:034e698bc035 181 return ((uint16_t)GPIOx->DATA);
mbed_official 619:034e698bc035 182 }
mbed_official 619:034e698bc035 183
mbed_official 619:034e698bc035 184 uint8_t HAL_GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
mbed_official 619:034e698bc035 185 {
mbed_official 619:034e698bc035 186 uint8_t bitstatus = 0x00;
mbed_official 619:034e698bc035 187
mbed_official 619:034e698bc035 188
mbed_official 619:034e698bc035 189
mbed_official 619:034e698bc035 190 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
mbed_official 619:034e698bc035 191 assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
mbed_official 619:034e698bc035 192
mbed_official 619:034e698bc035 193 if((GPIOx->DATAOUT & GPIO_Pin) != (uint32_t)Bit_RESET)
mbed_official 619:034e698bc035 194 {
mbed_official 619:034e698bc035 195 bitstatus = (uint8_t)Bit_SET;
mbed_official 619:034e698bc035 196 }
mbed_official 619:034e698bc035 197 else
mbed_official 619:034e698bc035 198 {
mbed_official 619:034e698bc035 199 bitstatus = (uint8_t)Bit_RESET;
mbed_official 619:034e698bc035 200 }
mbed_official 619:034e698bc035 201
mbed_official 619:034e698bc035 202 return bitstatus;
mbed_official 619:034e698bc035 203 }
mbed_official 619:034e698bc035 204 uint16_t HAL_GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
mbed_official 619:034e698bc035 205 {
mbed_official 619:034e698bc035 206 /* Check the parameters */
mbed_official 619:034e698bc035 207 assert_param(IS_GPIO_ALLPERIPH(GPIOx));
mbed_official 619:034e698bc035 208 return ((uint16_t)GPIOx->DATAOUT);
mbed_official 619:034e698bc035 209 }
mbed_official 619:034e698bc035 210
mbed_official 619:034e698bc035 211 void HAL_GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
mbed_official 619:034e698bc035 212 {
mbed_official 619:034e698bc035 213 /* Check the parameters */
mbed_official 619:034e698bc035 214 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
mbed_official 619:034e698bc035 215 assert_param(IS_GPIO_PIN(GPIO_Pin));
mbed_official 619:034e698bc035 216
mbed_official 619:034e698bc035 217 (GPIOx->LB_MASKED[(uint8_t)(GPIO_Pin)]) = GPIO_Pin;
mbed_official 619:034e698bc035 218 (GPIOx->UB_MASKED[(uint8_t)((GPIO_Pin)>>8)]) = GPIO_Pin;
mbed_official 619:034e698bc035 219 }
mbed_official 619:034e698bc035 220
mbed_official 619:034e698bc035 221 void HAL_GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
mbed_official 619:034e698bc035 222 {
mbed_official 619:034e698bc035 223 /* Check the parameters */
mbed_official 619:034e698bc035 224 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
mbed_official 619:034e698bc035 225 assert_param(IS_GPIO_PIN(GPIO_Pin));
mbed_official 619:034e698bc035 226
mbed_official 619:034e698bc035 227 (GPIOx->LB_MASKED[(uint8_t)(GPIO_Pin)]) = ~(GPIO_Pin);
mbed_official 619:034e698bc035 228 (GPIOx->UB_MASKED[(uint8_t)(GPIO_Pin>>8)]) = ~(GPIO_Pin);
mbed_official 619:034e698bc035 229 }
mbed_official 619:034e698bc035 230
mbed_official 619:034e698bc035 231 void HAL_GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
mbed_official 619:034e698bc035 232 {
mbed_official 619:034e698bc035 233 /* Check the parameters */
mbed_official 619:034e698bc035 234 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
mbed_official 619:034e698bc035 235 assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
mbed_official 619:034e698bc035 236 assert_param(IS_GPIO_BIT_ACTION(BitVal));
mbed_official 619:034e698bc035 237
mbed_official 619:034e698bc035 238 (GPIOx->LB_MASKED[(uint8_t)(GPIO_Pin)]) = BitVal;
mbed_official 619:034e698bc035 239 (GPIOx->UB_MASKED[(uint8_t)((GPIO_Pin)>>8)]) = BitVal;
mbed_official 619:034e698bc035 240 }
mbed_official 619:034e698bc035 241
mbed_official 619:034e698bc035 242 void HAL_GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
mbed_official 619:034e698bc035 243 {
mbed_official 619:034e698bc035 244 /* Check the parameters */
mbed_official 619:034e698bc035 245 assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
mbed_official 619:034e698bc035 246
mbed_official 619:034e698bc035 247 GPIOx->DATAOUT = PortVal;
mbed_official 619:034e698bc035 248 }
mbed_official 619:034e698bc035 249
mbed_official 619:034e698bc035 250 void HAL_PAD_AFConfig(PAD_Type Px, uint16_t GPIO_Pin, PAD_AF_TypeDef P_AF)
mbed_official 619:034e698bc035 251 {
mbed_official 619:034e698bc035 252 int i;
mbed_official 619:034e698bc035 253 uint16_t idx =0x1;
mbed_official 619:034e698bc035 254 assert_param(IS_PAD_Type(Px));
mbed_official 619:034e698bc035 255
mbed_official 619:034e698bc035 256 for(i=0;i<16;i++)
mbed_official 619:034e698bc035 257 {
mbed_official 619:034e698bc035 258 if(GPIO_Pin & (idx<<i))
mbed_official 619:034e698bc035 259 {
mbed_official 619:034e698bc035 260 if(Px == PAD_PA)
mbed_official 619:034e698bc035 261 {
mbed_official 619:034e698bc035 262 assert_param(IS_PA_NUM(i));
mbed_official 619:034e698bc035 263 PA_AFSR->Port[i] &= ~(0x03ul);
mbed_official 619:034e698bc035 264 PA_AFSR->Port[i] |= P_AF;
mbed_official 619:034e698bc035 265 }
mbed_official 619:034e698bc035 266 else if(Px == PAD_PB)
mbed_official 619:034e698bc035 267 {
mbed_official 619:034e698bc035 268 assert_param(IS_PB_NUM(i));
mbed_official 619:034e698bc035 269 PB_AFSR->Port[i] &= ~(0x03ul);
mbed_official 619:034e698bc035 270 PB_AFSR->Port[i] |= P_AF;
mbed_official 619:034e698bc035 271 }
mbed_official 619:034e698bc035 272 else if(Px == PAD_PC)
mbed_official 619:034e698bc035 273 {
mbed_official 619:034e698bc035 274 assert_param(IS_PC_NUM(i));
mbed_official 619:034e698bc035 275 PC_AFSR->Port[i] &= ~(0x03ul);
mbed_official 619:034e698bc035 276 PC_AFSR->Port[i] |= P_AF;
mbed_official 619:034e698bc035 277 }
mbed_official 619:034e698bc035 278 else
mbed_official 619:034e698bc035 279 {
mbed_official 619:034e698bc035 280 assert_param(IS_PD_NUM(i));
mbed_official 619:034e698bc035 281 PD_AFSR->Port[i] &= ~(0x03ul);
mbed_official 619:034e698bc035 282 PD_AFSR->Port[i] |= P_AF;
mbed_official 619:034e698bc035 283 }
mbed_official 619:034e698bc035 284 }
mbed_official 619:034e698bc035 285 }
mbed_official 619:034e698bc035 286 }
mbed_official 619:034e698bc035 287
mbed_official 619:034e698bc035 288 void GPIO_OutEnClr(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
mbed_official 619:034e698bc035 289 {
mbed_official 619:034e698bc035 290 GPIOx->OUTENCLR = GPIO_Pin;
mbed_official 619:034e698bc035 291 }
mbed_official 619:034e698bc035 292
mbed_official 619:034e698bc035 293 void GPIO_OutEnSet(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
mbed_official 619:034e698bc035 294 {
mbed_official 619:034e698bc035 295 GPIOx->OUTENSET = GPIO_Pin;
mbed_official 619:034e698bc035 296 }
mbed_official 619:034e698bc035 297