Subversion Repositories LedShow

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 9
Line 88... Line 88...
88
 
88
 
89
  @endverbatim
89
  @endverbatim
90
  ******************************************************************************
90
  ******************************************************************************
91
  * @attention
91
  * @attention
92
  *
92
  *
93
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
93
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
-
 
94
  * All rights reserved.</center></h2>
94
  *
95
  *
95
  * Redistribution and use in source and binary forms, with or without modification,
96
  * This software component is licensed by ST under BSD 3-Clause license,
96
  * are permitted provided that the following conditions are met:
97
  * the "License"; You may not use this file except in compliance with the
97
  *   1. Redistributions of source code must retain the above copyright notice,
-
 
98
  *      this list of conditions and the following disclaimer.
-
 
99
  *   2. Redistributions in binary form must reproduce the above copyright notice,
-
 
100
  *      this list of conditions and the following disclaimer in the documentation
-
 
101
  *      and/or other materials provided with the distribution.
98
  * License. You may obtain a copy of the License at:
102
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-
 
103
  *      may be used to endorse or promote products derived from this software
99
  *                        opensource.org/licenses/BSD-3-Clause
104
  *      without specific prior written permission.
-
 
105
  *
-
 
106
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
 
107
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
108
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-
 
109
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-
 
110
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
111
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-
 
112
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-
 
113
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-
 
114
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
 
115
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
116
  *
100
  *
117
  ******************************************************************************
101
  ******************************************************************************
118
  */
102
  */
119
 
103
 
120
/* Includes ------------------------------------------------------------------*/
104
/* Includes ------------------------------------------------------------------*/
Line 134... Line 118...
134
/* Private typedef -----------------------------------------------------------*/
118
/* Private typedef -----------------------------------------------------------*/
135
/* Private define ------------------------------------------------------------*/
119
/* Private define ------------------------------------------------------------*/
136
/** @addtogroup GPIO_Private_Constants GPIO Private Constants
120
/** @addtogroup GPIO_Private_Constants GPIO Private Constants
137
  * @{
121
  * @{
138
  */
122
  */
139
#define GPIO_MODE             0x00000003U
123
#define GPIO_MODE             0x00000003u
140
#define EXTI_MODE             0x10000000U
124
#define EXTI_MODE             0x10000000u
141
#define GPIO_MODE_IT          0x00010000U
125
#define GPIO_MODE_IT          0x00010000u
142
#define GPIO_MODE_EVT         0x00020000U
126
#define GPIO_MODE_EVT         0x00020000u
143
#define RISING_EDGE           0x00100000U
127
#define RISING_EDGE           0x00100000u
144
#define FALLING_EDGE          0x00200000U
128
#define FALLING_EDGE          0x00200000u
145
#define GPIO_OUTPUT_TYPE      0x00000010U
129
#define GPIO_OUTPUT_TYPE      0x00000010u
146
 
130
 
147
#define GPIO_NUMBER           16U
131
#define GPIO_NUMBER           16u
148
 
132
 
149
/* Definitions for bit manipulation of CRL and CRH register */
133
/* Definitions for bit manipulation of CRL and CRH register */
150
#define  GPIO_CR_MODE_INPUT         0x00000000U /*!< 00: Input mode (reset state)  */
134
#define  GPIO_CR_MODE_INPUT         0x00000000u /*!< 00: Input mode (reset state)  */
151
#define  GPIO_CR_CNF_ANALOG         0x00000000U /*!< 00: Analog mode  */
135
#define  GPIO_CR_CNF_ANALOG         0x00000000u /*!< 00: Analog mode  */
152
#define  GPIO_CR_CNF_INPUT_FLOATING 0x00000004U /*!< 01: Floating input (reset state)  */
136
#define  GPIO_CR_CNF_INPUT_FLOATING 0x00000004u /*!< 01: Floating input (reset state)  */
153
#define  GPIO_CR_CNF_INPUT_PU_PD    0x00000008U /*!< 10: Input with pull-up / pull-down  */
137
#define  GPIO_CR_CNF_INPUT_PU_PD    0x00000008u /*!< 10: Input with pull-up / pull-down  */
154
#define  GPIO_CR_CNF_GP_OUTPUT_PP   0x00000000U /*!< 00: General purpose output push-pull  */
138
#define  GPIO_CR_CNF_GP_OUTPUT_PP   0x00000000u /*!< 00: General purpose output push-pull  */
155
#define  GPIO_CR_CNF_GP_OUTPUT_OD   0x00000004U /*!< 01: General purpose output Open-drain  */
139
#define  GPIO_CR_CNF_GP_OUTPUT_OD   0x00000004u /*!< 01: General purpose output Open-drain  */
156
#define  GPIO_CR_CNF_AF_OUTPUT_PP   0x00000008U /*!< 10: Alternate function output Push-pull  */
140
#define  GPIO_CR_CNF_AF_OUTPUT_PP   0x00000008u /*!< 10: Alternate function output Push-pull  */
157
#define  GPIO_CR_CNF_AF_OUTPUT_OD   0x0000000CU /*!< 11: Alternate function output Open-drain  */
141
#define  GPIO_CR_CNF_AF_OUTPUT_OD   0x0000000Cu /*!< 11: Alternate function output Open-drain  */
158
 
142
 
159
/**
143
/**
160
  * @}
144
  * @}
161
  */
145
  */
162
/* Private macro -------------------------------------------------------------*/
146
/* Private macro -------------------------------------------------------------*/
Line 191... Line 175...
191
  *         the configuration information for the specified GPIO peripheral.
175
  *         the configuration information for the specified GPIO peripheral.
192
  * @retval None
176
  * @retval None
193
  */
177
  */
194
void HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init)
178
void HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init)
195
{
179
{
196
  uint32_t position;
180
  uint32_t position = 0x00u;
197
  uint32_t ioposition = 0x00U;
181
  uint32_t ioposition;
198
  uint32_t iocurrent = 0x00U;
182
  uint32_t iocurrent;
199
  uint32_t temp = 0x00U;
183
  uint32_t temp;
200
  uint32_t config = 0x00U;
184
  uint32_t config = 0x00u;
201
  __IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */
185
  __IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */
202
  uint32_t registeroffset = 0U; /* offset used during computation of CNF and MODE bits placement inside CRL or CRH register */
186
  uint32_t registeroffset;       /* offset used during computation of CNF and MODE bits placement inside CRL or CRH register */
203
 
187
 
204
  /* Check the parameters */
188
  /* Check the parameters */
205
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
189
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
206
  assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
190
  assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
207
  assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
191
  assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
208
 
192
 
209
  /* Configure the port pins */
193
  /* Configure the port pins */
210
  for (position = 0U; position < GPIO_NUMBER; position++)
194
  while (((GPIO_Init->Pin) >> position) != 0x00u)
211
  {
195
  {
212
    /* Get the IO position */
196
    /* Get the IO position */
213
    ioposition = (0x01U << position);
197
    ioposition = (0x01uL << position);
214
 
198
 
215
    /* Get the current IO position */
199
    /* Get the current IO position */
216
    iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition;
200
    iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition;
217
 
201
 
218
    if (iocurrent == ioposition)
202
    if (iocurrent == ioposition)
Line 292... Line 276...
292
      }
276
      }
293
 
277
 
294
      /* Check if the current bit belongs to first half or last half of the pin count number
278
      /* Check if the current bit belongs to first half or last half of the pin count number
295
       in order to address CRH or CRL register*/
279
       in order to address CRH or CRL register*/
296
      configregister = (iocurrent < GPIO_PIN_8) ? &GPIOx->CRL     : &GPIOx->CRH;
280
      configregister = (iocurrent < GPIO_PIN_8) ? &GPIOx->CRL     : &GPIOx->CRH;
297
      registeroffset = (iocurrent < GPIO_PIN_8) ? (position << 2U) : ((position - 8U) << 2U);
281
      registeroffset = (iocurrent < GPIO_PIN_8) ? (position << 2u) : ((position - 8u) << 2u);
298
 
282
 
299
      /* Apply the new configuration of the pin to the register */
283
      /* Apply the new configuration of the pin to the register */
300
      MODIFY_REG((*configregister), ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << registeroffset), (config << registeroffset));
284
      MODIFY_REG((*configregister), ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << registeroffset), (config << registeroffset));
301
 
285
 
302
      /*--------------------- EXTI Mode Configuration ------------------------*/
286
      /*--------------------- EXTI Mode Configuration ------------------------*/
303
      /* Configure the External Interrupt or event for the current IO */
287
      /* Configure the External Interrupt or event for the current IO */
304
      if ((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
288
      if ((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
305
      {
289
      {
306
        /* Enable AFIO Clock */
290
        /* Enable AFIO Clock */
307
        __HAL_RCC_AFIO_CLK_ENABLE();
291
        __HAL_RCC_AFIO_CLK_ENABLE();
308
        temp = AFIO->EXTICR[position >> 2U];
292
        temp = AFIO->EXTICR[position >> 2u];
309
        CLEAR_BIT(temp, (0x0FU) << (4U * (position & 0x03U)));
293
        CLEAR_BIT(temp, (0x0Fu) << (4u * (position & 0x03u)));
310
        SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4U * (position & 0x03U)));
294
        SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4u * (position & 0x03u)));
311
        AFIO->EXTICR[position >> 2U] = temp;
295
        AFIO->EXTICR[position >> 2u] = temp;
312
 
296
 
313
 
297
 
314
        /* Configure the interrupt mask */
298
        /* Configure the interrupt mask */
315
        if ((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
299
        if ((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
316
        {
300
        {
Line 350... Line 334...
350
        {
334
        {
351
          CLEAR_BIT(EXTI->FTSR, iocurrent);
335
          CLEAR_BIT(EXTI->FTSR, iocurrent);
352
        }
336
        }
353
      }
337
      }
354
    }
338
    }
-
 
339
 
-
 
340
        position++;
355
  }
341
  }
356
}
342
}
357
 
343
 
358
/**
344
/**
359
  * @brief  De-initializes the GPIOx peripheral registers to their default reset values.
345
  * @brief  De-initializes the GPIOx peripheral registers to their default reset values.
Line 362... Line 348...
362
  *         This parameter can be one of GPIO_PIN_x where x can be (0..15).
348
  *         This parameter can be one of GPIO_PIN_x where x can be (0..15).
363
  * @retval None
349
  * @retval None
364
  */
350
  */
365
void HAL_GPIO_DeInit(GPIO_TypeDef  *GPIOx, uint32_t GPIO_Pin)
351
void HAL_GPIO_DeInit(GPIO_TypeDef  *GPIOx, uint32_t GPIO_Pin)
366
{
352
{
367
  uint32_t position = 0x00U;
353
  uint32_t position = 0x00u;
368
  uint32_t iocurrent = 0x00U;
354
  uint32_t iocurrent;
369
  uint32_t tmp = 0x00U;
355
  uint32_t tmp;
370
  __IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */
356
  __IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */
371
  uint32_t registeroffset = 0U;
357
  uint32_t registeroffset;
372
 
358
 
373
  /* Check the parameters */
359
  /* Check the parameters */
374
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
360
  assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
375
  assert_param(IS_GPIO_PIN(GPIO_Pin));
361
  assert_param(IS_GPIO_PIN(GPIO_Pin));
376
 
362
 
377
  /* Configure the port pins */
363
  /* Configure the port pins */
378
  while ((GPIO_Pin >> position) != 0U)
364
  while ((GPIO_Pin >> position) != 0u)
379
  {
365
  {
380
    /* Get current io position */
366
    /* Get current io position */
381
    iocurrent = (GPIO_Pin) & (1U << position);
367
    iocurrent = (GPIO_Pin) & (1uL << position);
382
 
368
 
383
    if (iocurrent)
369
    if (iocurrent)
384
    {
370
    {
385
      /*------------------------- GPIO Mode Configuration --------------------*/
-
 
386
      /* Check if the current bit belongs to first half or last half of the pin count number
-
 
387
       in order to address CRH or CRL register */
-
 
388
      configregister = (iocurrent < GPIO_PIN_8) ? &GPIOx->CRL     : &GPIOx->CRH;
-
 
389
      registeroffset = (iocurrent < GPIO_PIN_8) ? (position << 2U) : ((position - 8U) << 2U);
-
 
390
 
-
 
391
      /* CRL/CRH default value is floating input(0x04) shifted to correct position */
-
 
392
      MODIFY_REG(*configregister, ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << registeroffset), GPIO_CRL_CNF0_0 << registeroffset);
-
 
393
 
-
 
394
      /* ODR default value is 0 */
-
 
395
      CLEAR_BIT(GPIOx->ODR, iocurrent);
-
 
396
 
-
 
397
      /*------------------------- EXTI Mode Configuration --------------------*/
371
      /*------------------------- EXTI Mode Configuration --------------------*/
398
      /* Clear the External Interrupt or Event for the current IO */
372
      /* Clear the External Interrupt or Event for the current IO */
399
 
373
 
400
      tmp = AFIO->EXTICR[position >> 2U];
374
      tmp = AFIO->EXTICR[position >> 2u];
401
      tmp &= 0x0FU << (4U * (position & 0x03U));
375
      tmp &= 0x0FuL << (4u * (position & 0x03u));
402
      if (tmp == (GPIO_GET_INDEX(GPIOx) << (4U * (position & 0x03U))))
376
      if (tmp == (GPIO_GET_INDEX(GPIOx) << (4u * (position & 0x03u))))
403
      {
377
      {
404
        tmp = 0x0FU << (4U * (position & 0x03U));
378
        tmp = 0x0FuL << (4u * (position & 0x03u));
405
        CLEAR_BIT(AFIO->EXTICR[position >> 2U], tmp);
379
        CLEAR_BIT(AFIO->EXTICR[position >> 2u], tmp);
406
 
380
 
407
        /* Clear EXTI line configuration */
381
        /* Clear EXTI line configuration */
408
        CLEAR_BIT(EXTI->IMR, (uint32_t)iocurrent);
382
        CLEAR_BIT(EXTI->IMR, (uint32_t)iocurrent);
409
        CLEAR_BIT(EXTI->EMR, (uint32_t)iocurrent);
383
        CLEAR_BIT(EXTI->EMR, (uint32_t)iocurrent);
410
 
384
 
411
        /* Clear Rising Falling edge configuration */
385
        /* Clear Rising Falling edge configuration */
412
        CLEAR_BIT(EXTI->RTSR, (uint32_t)iocurrent);
386
        CLEAR_BIT(EXTI->RTSR, (uint32_t)iocurrent);
413
        CLEAR_BIT(EXTI->FTSR, (uint32_t)iocurrent);
387
        CLEAR_BIT(EXTI->FTSR, (uint32_t)iocurrent);
414
      }
388
      }
-
 
389
      /*------------------------- GPIO Mode Configuration --------------------*/
-
 
390
      /* Check if the current bit belongs to first half or last half of the pin count number
-
 
391
       in order to address CRH or CRL register */
-
 
392
      configregister = (iocurrent < GPIO_PIN_8) ? &GPIOx->CRL     : &GPIOx->CRH;
-
 
393
      registeroffset = (iocurrent < GPIO_PIN_8) ? (position << 2u) : ((position - 8u) << 2u);
-
 
394
 
-
 
395
      /* CRL/CRH default value is floating input(0x04) shifted to correct position */
-
 
396
      MODIFY_REG(*configregister, ((GPIO_CRL_MODE0 | GPIO_CRL_CNF0) << registeroffset), GPIO_CRL_CNF0_0 << registeroffset);
-
 
397
 
-
 
398
      /* ODR default value is 0 */
-
 
399
      CLEAR_BIT(GPIOx->ODR, iocurrent);
415
    }
400
    }
416
 
401
 
417
    position++;
402
    position++;
418
  }
403
  }
419
}
404
}
Line 487... Line 472...
487
  {
472
  {
488
    GPIOx->BSRR = GPIO_Pin;
473
    GPIOx->BSRR = GPIO_Pin;
489
  }
474
  }
490
  else
475
  else
491
  {
476
  {
492
    GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U;
477
    GPIOx->BSRR = (uint32_t)GPIO_Pin << 16u;
493
  }
478
  }
494
}
479
}
495
 
480
 
496
/**
481
/**
497
  * @brief  Toggles the specified GPIO pin
482
  * @brief  Toggles the specified GPIO pin
Line 499... Line 484...
499
  * @param  GPIO_Pin: Specifies the pins to be toggled.
484
  * @param  GPIO_Pin: Specifies the pins to be toggled.
500
  * @retval None
485
  * @retval None
501
  */
486
  */
502
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
487
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
503
{
488
{
-
 
489
  uint32_t odr;
-
 
490
 
504
  /* Check the parameters */
491
  /* Check the parameters */
505
  assert_param(IS_GPIO_PIN(GPIO_Pin));
492
  assert_param(IS_GPIO_PIN(GPIO_Pin));
506
 
493
 
-
 
494
  /* get current Ouput Data Register value */
507
  GPIOx->ODR ^= GPIO_Pin;
495
  odr = GPIOx->ODR;
-
 
496
 
-
 
497
  /* Set selected pins that were at low level, and reset ones that were high */
-
 
498
  GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin);
508
}
499
}
509
 
500
 
510
/**
501
/**
511
* @brief  Locks GPIO Pins configuration registers.
502
* @brief  Locks GPIO Pins configuration registers.
512
* @note   The locking mechanism allows the IO configuration to be frozen. When the LOCK sequence
503
* @note   The locking mechanism allows the IO configuration to be frozen. When the LOCK sequence
Line 531... Line 522...
531
  GPIOx->LCKR = tmp;
522
  GPIOx->LCKR = tmp;
532
  /* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */
523
  /* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */
533
  GPIOx->LCKR = GPIO_Pin;
524
  GPIOx->LCKR = GPIO_Pin;
534
  /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
525
  /* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
535
  GPIOx->LCKR = tmp;
526
  GPIOx->LCKR = tmp;
536
  /* Read LCKK bit*/
527
  /* Read LCKK register. This read is mandatory to complete key lock sequence */
537
  tmp = GPIOx->LCKR;
528
  tmp = GPIOx->LCKR;
538
 
529
 
-
 
530
  /* read again in order to confirm lock is active */
539
  if ((uint32_t)(GPIOx->LCKR & GPIO_LCKR_LCKK))
531
  if ((uint32_t)(GPIOx->LCKR & GPIO_LCKR_LCKK))
540
  {
532
  {
541
    return HAL_OK;
533
    return HAL_OK;
542
  }
534
  }
543
  else
535
  else
Line 552... Line 544...
552
  * @retval None
544
  * @retval None
553
  */
545
  */
554
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
546
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
555
{
547
{
556
  /* EXTI line interrupt detected */
548
  /* EXTI line interrupt detected */
557
  if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
549
  if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != 0x00u)
558
  {
550
  {
559
    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
551
    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
560
    HAL_GPIO_EXTI_Callback(GPIO_Pin);
552
    HAL_GPIO_EXTI_Callback(GPIO_Pin);
561
  }
553
  }
562
}
554
}