No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

117 líneas
3.7 KiB

  1. /** @defgroup syscon_file SYSCON peripheral API
  2. * @ingroup peripheral_apis
  3. * @brief SWM050 SYSCON API.
  4. * LGPL License Terms @ref lgpl_license
  5. * @author @htmlonly © @endhtmlonly 2019
  6. * Icenowy Zheng <icenowy@aosc.io>
  7. * @author @htmlonly &copy; @endhtmlonly 2019
  8. * Caleb Szalacinski <contact@skiboy.net>
  9. */
  10. /*
  11. * This file is part of the libopencm3 project.
  12. *
  13. * Copyright (C) 2019 Icenowy Zheng <icenowy@aosc.io>
  14. * Copyright (C) 2019 Caleb Szalacinski <contact@skiboy.net>
  15. *
  16. * This library is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Lesser General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This library is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Lesser General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Lesser General Public License
  27. * along with this library. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. /**@{*/
  30. #include <libopencm3/swm050/syscon.h>
  31. #include <libopencm3/swm050/gpio.h>
  32. /*---------------------------------------------------------------------------*/
  33. /** @brief Select the alternative function of a Group of Pins
  34. Select the alternative function of one or more pins of GPIO.
  35. @param[in] gpios Pin identifiers @ref gpio_pin_id
  36. If multiple pins are to be changed, use bitwise OR '|' to separate
  37. them.
  38. @param[in] af_en Whether alternative function is selected
  39. */
  40. void syscon_sel_af(uint16_t gpios, bool af_en)
  41. {
  42. uint32_t masked_reg32;
  43. if (gpios & GPIO0) {
  44. masked_reg32 = SYSCON_PORTA_SEL & (~0x3);
  45. SYSCON_PORTA_SEL = masked_reg32 | (af_en ? 0x1 : 0x0);
  46. }
  47. if (gpios & GPIO1) {
  48. masked_reg32 = SYSCON_PORTA_SEL & (~0xc);
  49. SYSCON_PORTA_SEL = masked_reg32 | (af_en ? 0x4 : 0x0);
  50. }
  51. if (gpios & GPIO2) {
  52. masked_reg32 = SYSCON_PORTA_SEL & (~0x30);
  53. SYSCON_PORTA_SEL = masked_reg32 | (af_en ? 0x10 : 0x0);
  54. }
  55. if (gpios & GPIO7) {
  56. masked_reg32 = SYSCON_PORTA_SEL & (~0xc000);
  57. SYSCON_PORTA_SEL = masked_reg32 | (af_en ? 0x4000 : 0x0);
  58. }
  59. }
  60. /*---------------------------------------------------------------------------*/
  61. /** @brief Enable the internal pull-up of a Group of Pins
  62. Enable or disable the internal pull-up of one or more pins of GPIO.
  63. @param[in] gpios Pin identifiers @ref gpio_pin_id
  64. If multiple pins are to be changed, use bitwise OR '|' to separate
  65. them.
  66. @param[in] en True to enable pull-up, false to disable.
  67. */
  68. void syscon_pullup(uint16_t gpios, bool en)
  69. {
  70. if (en) {
  71. SYSCON_PORTA_PULLUP |= gpios;
  72. } else {
  73. SYSCON_PORTA_PULLUP &= ~gpios;
  74. }
  75. }
  76. /*---------------------------------------------------------------------------*/
  77. /** @brief Enable the input function of a Group of Pins
  78. Enable or disable the input function of one or more pins of GPIO. Disabling
  79. the input function of pins decreases the power usage of the MCU.
  80. @param[in] gpios Pin identifiers @ref gpio_pin_id
  81. If multiple pins are to be changed, use bitwise OR '|' to separate
  82. them.
  83. @param[in] en True to enable input function.
  84. */
  85. void syscon_input_enable(uint16_t gpios, bool en)
  86. {
  87. if (en) {
  88. SYSCON_PORTA_INEN &= ~gpios;
  89. } else {
  90. SYSCON_PORTA_INEN |= gpios;
  91. }
  92. }
  93. /*---------------------------------------------------------------------------*/
  94. /** @brief Select the SWD function of GPIO 1/2
  95. Enable or disable the SWD debugging port at GPIO 1/2. When SWD debugging port
  96. is enabled, GPIO and AF of the SWD pins will be both unavailable.
  97. @param[in] en True to enable SWD.
  98. */
  99. void syscon_sel_swd(bool en)
  100. {
  101. SYSCON_SWD_SEL = en;
  102. }
  103. /**@}*/