pinmux.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /**
  2. * \file
  3. *
  4. * \brief SAM Pin Multiplexer Driver
  5. *
  6. * Copyright (C) 2012-2016 Atmel Corporation. All rights reserved.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. *
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. *
  22. * 3. The name of Atmel may not be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * 4. This software may only be redistributed and used in connection with an
  26. * Atmel microcontroller product.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  31. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  32. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * \asf_license_stop
  41. *
  42. */
  43. /*
  44. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  45. */
  46. #ifndef PINMUX_H_INCLUDED
  47. #define PINMUX_H_INCLUDED
  48. /**
  49. * \defgroup asfdoc_sam0_system_pinmux_group SAM System Pin Multiplexer (SYSTEM PINMUX) Driver
  50. *
  51. * This driver for Atmel&reg; | SMART ARM&reg;-based microcontrollers provides
  52. * an interface for the configuration and management of the device's physical
  53. * I/O Pins, to alter the direction and input/drive characteristics as well as
  54. * to configure the pin peripheral multiplexer selection.
  55. *
  56. * The following peripheral is used by this module:
  57. * - PORT (Port I/O Management)
  58. *
  59. * The following devices can use this module:
  60. * - Atmel | SMART SAM D20/D21
  61. * - Atmel | SMART SAM R21
  62. * - Atmel | SMART SAM D09/D10/D11
  63. * - Atmel | SMART SAM L21/L22
  64. * - Atmel | SMART SAM DA1
  65. * - Atmel | SMART SAM C20/C21
  66. * - Atmel | SMART SAM HA1
  67. *
  68. * The outline of this documentation is as follows:
  69. * - \ref asfdoc_sam0_system_pinmux_prerequisites
  70. * - \ref asfdoc_sam0_system_pinmux_module_overview
  71. * - \ref asfdoc_sam0_system_pinmux_special_considerations
  72. * - \ref asfdoc_sam0_system_pinmux_extra_info
  73. * - \ref asfdoc_sam0_system_pinmux_examples
  74. * - \ref asfdoc_sam0_system_pinmux_api_overview
  75. *
  76. *
  77. * \section asfdoc_sam0_system_pinmux_prerequisites Prerequisites
  78. *
  79. * There are no prerequisites for this module.
  80. *
  81. *
  82. * \section asfdoc_sam0_system_pinmux_module_overview Module Overview
  83. *
  84. * The SAM devices contain a number of General Purpose I/O pins, used to
  85. * interface the user application logic and internal hardware peripherals to
  86. * an external system. The Pin Multiplexer (PINMUX) driver provides a method
  87. * of configuring the individual pin peripheral multiplexers to select
  88. * alternate pin functions.
  89. *
  90. * \subsection asfdoc_sam0_system_pinmux_features Driver Feature Macro Definition
  91. * <table>
  92. * <tr>
  93. * <th>Driver Feature Macro</th>
  94. * <th>Supported devices</th>
  95. * </tr>
  96. * <tr>
  97. * <td>FEATURE_SYSTEM_PINMUX_DRIVE_STRENGTH</td>
  98. * <td>SAM L21, SAM C20/C21</td>
  99. * </tr>
  100. * </table>
  101. * \note The specific features are only available in the driver when the
  102. * selected device supports those features.
  103. *
  104. * \subsection asfdoc_sam0_system_pinmux_physical_logical_pins Physical and Logical GPIO Pins
  105. * SAM devices use two naming conventions for the I/O pins in the device; one
  106. * physical and one logical. Each physical pin on a device package is assigned
  107. * both a physical port and pin identifier (e.g. "PORTA.0") as well as a
  108. * monotonically incrementing logical GPIO number (e.g. "GPIO0"). While the
  109. * former is used to map physical pins to their physical internal device module
  110. * counterparts, for simplicity the design of this driver uses the logical GPIO
  111. * numbers instead.
  112. *
  113. * \subsection asfdoc_sam0_system_pinmux_peripheral_muxing Peripheral Multiplexing
  114. * SAM devices contain a peripheral MUX, which is individually controllable
  115. * for each I/O pin of the device. The peripheral MUX allows you to select the
  116. * function of a physical package pin - whether it will be controlled as a user
  117. * controllable GPIO pin, or whether it will be connected internally to one of
  118. * several peripheral modules (such as an I<SUP>2</SUP>C module). When a pin is
  119. * configured in GPIO mode, other peripherals connected to the same pin will be
  120. * disabled.
  121. *
  122. * \subsection asfdoc_sam0_system_pinmux_pad_characteristics Special Pad Characteristics
  123. * There are several special modes that can be selected on one or more I/O pins
  124. * of the device, which alter the input and output characteristics of the pad.
  125. *
  126. * \subsubsection asfdoc_sam0_system_pinmux_drive_strength Drive Strength
  127. * The Drive Strength configures the strength of the output driver on the
  128. * pad. Normally, there is a fixed current limit that each I/O pin can safely
  129. * drive, however some I/O pads offer a higher drive mode which increases this
  130. * limit for that I/O pin at the expense of an increased power consumption.
  131. *
  132. * \subsubsection asfdoc_sam0_system_pinmux_slew_rate Slew Rate
  133. * The Slew Rate configures the slew rate of the output driver, limiting the
  134. * rate at which the pad output voltage can change with time.
  135. *
  136. * \subsubsection asfdoc_sam0_system_pinmux_input_sample_mode Input Sample Mode
  137. * The Input Sample Mode configures the input sampler buffer of the pad. By
  138. * default, the input buffer is only sampled "on-demand", i.e. when the user
  139. * application attempts to read from the input buffer. This mode is the most
  140. * power efficient, but increases the latency of the input sample by two clock
  141. * cycles of the port clock. To reduce latency, the input sampler can instead
  142. * be configured to always sample the input buffer on each port clock cycle, at
  143. * the expense of an increased power consumption.
  144. *
  145. * \subsection asfdoc_sam0_system_pinmux_module_overview_physical Physical Connection
  146. *
  147. * \ref asfdoc_sam0_system_pinmux_intconnections "The diagram below" shows
  148. * how this module is interconnected within the device:
  149. *
  150. * \anchor asfdoc_sam0_system_pinmux_intconnections
  151. * \dot
  152. * digraph overview {
  153. * node [label="Port Pad" shape=square] pad;
  154. *
  155. * subgraph driver {
  156. * node [label="Peripheral MUX" shape=trapezium] pinmux;
  157. * node [label="GPIO Module" shape=ellipse shape=ellipse style=filled fillcolor=lightgray] gpio;
  158. * node [label="Other Peripheral Modules" shape=ellipse style=filled fillcolor=lightgray] peripherals;
  159. * }
  160. *
  161. * pinmux -> gpio;
  162. * pad -> pinmux;
  163. * pinmux -> peripherals;
  164. * }
  165. * \enddot
  166. *
  167. * \section asfdoc_sam0_system_pinmux_special_considerations Special Considerations
  168. *
  169. * The SAM port pin input sampling mode is set in groups of four physical
  170. * pins; setting the sampling mode of any pin in a sub-group of eight I/O pins
  171. * will configure the sampling mode of the entire sub-group.
  172. *
  173. * High Drive Strength output driver mode is not available on all device pins -
  174. * refer to your device specific datasheet.
  175. *
  176. *
  177. * \section asfdoc_sam0_system_pinmux_extra_info Extra Information
  178. *
  179. * For extra information, see \ref asfdoc_sam0_system_pinmux_extra. This includes:
  180. * - \ref asfdoc_sam0_system_pinmux_extra_acronyms
  181. * - \ref asfdoc_sam0_system_pinmux_extra_dependencies
  182. * - \ref asfdoc_sam0_system_pinmux_extra_errata
  183. * - \ref asfdoc_sam0_system_pinmux_extra_history
  184. *
  185. *
  186. * \section asfdoc_sam0_system_pinmux_examples Examples
  187. *
  188. * For a list of examples related to this driver, see
  189. * \ref asfdoc_sam0_system_pinmux_exqsg.
  190. *
  191. *
  192. * \section asfdoc_sam0_system_pinmux_api_overview API Overview
  193. * @{
  194. */
  195. #include <compiler.h>
  196. #ifdef __cplusplus
  197. extern "C" {
  198. #endif
  199. /*@{*/
  200. #if (SAML21) || (SAMC20) || (SAMC21) || (SAMD21) || (SAMD10) || (SAMD11) || (SAMR30) || defined(__DOXYGEN__)
  201. /** Output Driver Strength Selection feature support */
  202. # define FEATURE_SYSTEM_PINMUX_DRIVE_STRENGTH
  203. #endif
  204. /*@}*/
  205. /** Peripheral multiplexer index to select GPIO mode for a pin */
  206. #define SYSTEM_PINMUX_GPIO (1 << 7)
  207. /**
  208. * \brief Port pin direction configuration enum.
  209. *
  210. * Enum for the possible pin direction settings of the port pin configuration
  211. * structure, to indicate the direction the pin should use.
  212. */
  213. enum system_pinmux_pin_dir {
  214. /** The pin's input buffer should be enabled, so that the pin state can
  215. * be read */
  216. SYSTEM_PINMUX_PIN_DIR_INPUT,
  217. /** The pin's output buffer should be enabled, so that the pin state can
  218. * be set (but not read back) */
  219. SYSTEM_PINMUX_PIN_DIR_OUTPUT,
  220. /** The pin's output and input buffers should both be enabled, so that the
  221. * pin state can be set and read back */
  222. SYSTEM_PINMUX_PIN_DIR_OUTPUT_WITH_READBACK,
  223. };
  224. /**
  225. * \brief Port pin input pull configuration enum.
  226. *
  227. * Enum for the possible pin pull settings of the port pin configuration
  228. * structure, to indicate the type of logic level pull the pin should use.
  229. */
  230. enum system_pinmux_pin_pull {
  231. /** No logical pull should be applied to the pin */
  232. SYSTEM_PINMUX_PIN_PULL_NONE,
  233. /** Pin should be pulled up when idle */
  234. SYSTEM_PINMUX_PIN_PULL_UP,
  235. /** Pin should be pulled down when idle */
  236. SYSTEM_PINMUX_PIN_PULL_DOWN,
  237. };
  238. /**
  239. * \brief Port pin digital input sampling mode enum.
  240. *
  241. * Enum for the possible input sampling modes for the port pin configuration
  242. * structure, to indicate the type of sampling a port pin should use.
  243. */
  244. enum system_pinmux_pin_sample {
  245. /** Pin input buffer should continuously sample the pin state */
  246. SYSTEM_PINMUX_PIN_SAMPLE_CONTINUOUS,
  247. /** Pin input buffer should be enabled when the IN register is read */
  248. SYSTEM_PINMUX_PIN_SAMPLE_ONDEMAND,
  249. };
  250. /**
  251. * \brief Port pin configuration structure.
  252. *
  253. * Configuration structure for a port pin instance. This structure should
  254. * be initialized by the \ref system_pinmux_get_config_defaults() function
  255. * before being modified by the user application.
  256. */
  257. struct system_pinmux_config {
  258. /** MUX index of the peripheral that should control the pin, if peripheral
  259. * control is desired. For GPIO use, this should be set to
  260. * \ref SYSTEM_PINMUX_GPIO. */
  261. uint8_t mux_position;
  262. /** Port buffer input/output direction */
  263. enum system_pinmux_pin_dir direction;
  264. /** Logic level pull of the input buffer */
  265. enum system_pinmux_pin_pull input_pull;
  266. /** Enable lowest possible powerstate on the pin
  267. *
  268. * \note All other configurations will be ignored, the pin will be disabled.
  269. */
  270. bool powersave;
  271. };
  272. /** \name Configuration and Initialization
  273. * @{
  274. */
  275. /**
  276. * \brief Initializes a Port pin configuration structure to defaults.
  277. *
  278. * Initializes a given Port pin configuration structure to a set of
  279. * known default values. This function should be called on all new
  280. * instances of these configuration structures before being modified by the
  281. * user application.
  282. *
  283. * The default configuration is as follows:
  284. * \li Non peripheral (i.e. GPIO) controlled
  285. * \li Input mode with internal pull-up enabled
  286. *
  287. * \param[out] config Configuration structure to initialize to default values
  288. */
  289. static inline void system_pinmux_get_config_defaults(
  290. struct system_pinmux_config *const config)
  291. {
  292. /* Sanity check arguments */
  293. Assert(config);
  294. /* Default configuration values */
  295. config->mux_position = SYSTEM_PINMUX_GPIO;
  296. config->direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
  297. config->input_pull = SYSTEM_PINMUX_PIN_PULL_UP;
  298. config->powersave = false;
  299. }
  300. void system_pinmux_pin_set_config(
  301. const uint8_t gpio_pin,
  302. const struct system_pinmux_config *const config);
  303. void system_pinmux_group_set_config(
  304. PortGroup *const port,
  305. const uint32_t mask,
  306. const struct system_pinmux_config *const config);
  307. /** @} */
  308. /** \name Special Mode Configuration (Physical Group Orientated)
  309. * @{
  310. */
  311. /**
  312. * \brief Retrieves the PORT module group instance from a given GPIO pin number.
  313. *
  314. * Retrieves the PORT module group instance associated with a given logical
  315. * GPIO pin number.
  316. *
  317. * \param[in] gpio_pin Index of the GPIO pin to convert
  318. *
  319. * \return Base address of the associated PORT module.
  320. */
  321. static inline PortGroup* system_pinmux_get_group_from_gpio_pin(
  322. const uint8_t gpio_pin)
  323. {
  324. uint8_t port_index = (gpio_pin / 128);
  325. uint8_t group_index = (gpio_pin / 32);
  326. /* Array of available ports */
  327. Port *const ports[PORT_INST_NUM] = PORT_INSTS;
  328. if (port_index < PORT_INST_NUM) {
  329. return &(ports[port_index]->Group[group_index]);
  330. } else {
  331. Assert(false);
  332. return NULL;
  333. }
  334. }
  335. void system_pinmux_group_set_input_sample_mode(
  336. PortGroup *const port,
  337. const uint32_t mask,
  338. const enum system_pinmux_pin_sample mode);
  339. /** @} */
  340. /** \name Special Mode Configuration (Logical Pin Orientated)
  341. * @{
  342. */
  343. /**
  344. * \brief Retrieves the currently selected MUX position of a logical pin.
  345. *
  346. * Retrieves the selected MUX peripheral on a given logical GPIO pin.
  347. *
  348. * \param[in] gpio_pin Index of the GPIO pin to configure
  349. *
  350. * \return Currently selected peripheral index on the specified pin.
  351. */
  352. static inline uint8_t system_pinmux_pin_get_mux_position(
  353. const uint8_t gpio_pin)
  354. {
  355. PortGroup *const port = system_pinmux_get_group_from_gpio_pin(gpio_pin);
  356. uint32_t pin_index = (gpio_pin % 32);
  357. if (!(port->PINCFG[pin_index].reg & PORT_PINCFG_PMUXEN)) {
  358. return SYSTEM_PINMUX_GPIO;
  359. }
  360. uint32_t pmux_reg = port->PMUX[pin_index / 2].reg;
  361. if (pin_index & 1) {
  362. return (pmux_reg & PORT_PMUX_PMUXO_Msk) >> PORT_PMUX_PMUXO_Pos;
  363. }
  364. else {
  365. return (pmux_reg & PORT_PMUX_PMUXE_Msk) >> PORT_PMUX_PMUXE_Pos;
  366. }
  367. }
  368. /**
  369. * \brief Configures the input sampling mode for a GPIO pin.
  370. *
  371. * Configures the input sampling mode for a GPIO input, to
  372. * control when the physical I/O pin value is sampled and
  373. * stored inside the microcontroller.
  374. *
  375. * \param[in] gpio_pin Index of the GPIO pin to configure
  376. * \param[in] mode New pin sampling mode to configure
  377. */
  378. static inline void system_pinmux_pin_set_input_sample_mode(
  379. const uint8_t gpio_pin,
  380. const enum system_pinmux_pin_sample mode)
  381. {
  382. PortGroup* const port = system_pinmux_get_group_from_gpio_pin(gpio_pin);
  383. uint32_t pin_index = (gpio_pin % 32);
  384. if (mode == SYSTEM_PINMUX_PIN_SAMPLE_ONDEMAND) {
  385. port->CTRL.reg |= (1 << pin_index);
  386. } else {
  387. port->CTRL.reg &= ~(1 << pin_index);
  388. }
  389. }
  390. /** @} */
  391. #ifdef FEATURE_SYSTEM_PINMUX_DRIVE_STRENGTH
  392. /**
  393. * \brief Port pin drive output strength enum.
  394. *
  395. * Enum for the possible output drive strengths for the port pin
  396. * configuration structure, to indicate the driver strength the pin should
  397. * use.
  398. */
  399. enum system_pinmux_pin_strength {
  400. /** Normal output driver strength */
  401. SYSTEM_PINMUX_PIN_STRENGTH_NORMAL,
  402. /** High current output driver strength */
  403. SYSTEM_PINMUX_PIN_STRENGTH_HIGH,
  404. };
  405. /**
  406. * \brief Configures the output driver strength mode for a GPIO pin.
  407. *
  408. * Configures the output drive strength for a GPIO output, to
  409. * control the amount of current the pad is able to sink/source.
  410. *
  411. * \param[in] gpio_pin Index of the GPIO pin to configure
  412. * \param[in] mode New output driver strength mode to configure
  413. */
  414. static inline void system_pinmux_pin_set_output_strength(
  415. const uint8_t gpio_pin,
  416. const enum system_pinmux_pin_strength mode)
  417. {
  418. PortGroup* const port = system_pinmux_get_group_from_gpio_pin(gpio_pin);
  419. uint32_t pin_index = (gpio_pin % 32);
  420. if (mode == SYSTEM_PINMUX_PIN_STRENGTH_HIGH) {
  421. port->PINCFG[pin_index].reg |= PORT_PINCFG_DRVSTR;
  422. }
  423. else {
  424. port->PINCFG[pin_index].reg &= ~PORT_PINCFG_DRVSTR;
  425. }
  426. }
  427. void system_pinmux_group_set_output_strength(
  428. PortGroup *const port,
  429. const uint32_t mask,
  430. const enum system_pinmux_pin_strength mode);
  431. #endif
  432. #ifdef FEATURE_SYSTEM_PINMUX_SLEWRATE_LIMITER
  433. /**
  434. * \brief Port pin output slew rate enum.
  435. *
  436. * Enum for the possible output drive slew rates for the port pin
  437. * configuration structure, to indicate the driver slew rate the pin should
  438. * use.
  439. */
  440. enum system_pinmux_pin_slew_rate {
  441. /** Normal pin output slew rate */
  442. SYSTEM_PINMUX_PIN_SLEW_RATE_NORMAL,
  443. /** Enable slew rate limiter on the pin */
  444. SYSTEM_PINMUX_PIN_SLEW_RATE_LIMITED,
  445. };
  446. /**
  447. * \brief Configures the output slew rate mode for a GPIO pin.
  448. *
  449. * Configures the output slew rate mode for a GPIO output, to
  450. * control the speed at which the physical output pin can react to
  451. * logical changes of the I/O pin value.
  452. *
  453. * \param[in] gpio_pin Index of the GPIO pin to configure
  454. * \param[in] mode New pin slew rate mode to configure
  455. */
  456. static inline void system_pinmux_pin_set_output_slew_rate(
  457. const uint8_t gpio_pin,
  458. const enum system_pinmux_pin_slew_rate mode)
  459. {
  460. PortGroup* const port = system_pinmux_get_group_from_gpio_pin(gpio_pin);
  461. uint32_t pin_index = (gpio_pin % 32);
  462. if (mode == SYSTEM_PINMUX_PIN_SLEW_RATE_LIMITED) {
  463. port->PINCFG[pin_index].reg |= PORT_PINCFG_SLEWLIM;
  464. }
  465. else {
  466. port->PINCFG[pin_index].reg &= ~PORT_PINCFG_SLEWLIM;
  467. }
  468. }
  469. void system_pinmux_group_set_output_slew_rate(
  470. PortGroup *const port,
  471. const uint32_t mask,
  472. const enum system_pinmux_pin_slew_rate mode);
  473. #endif
  474. #ifdef FEATURE_SYSTEM_PINMUX_OPEN_DRAIN
  475. /**
  476. * \brief Port pin output drive mode enum.
  477. *
  478. * Enum for the possible output drive modes for the port pin configuration
  479. * structure, to indicate the output mode the pin should use.
  480. */
  481. enum system_pinmux_pin_drive {
  482. /** Use totem pole output drive mode */
  483. SYSTEM_PINMUX_PIN_DRIVE_TOTEM,
  484. /** Use open drain output drive mode */
  485. SYSTEM_PINMUX_PIN_DRIVE_OPEN_DRAIN,
  486. };
  487. /**
  488. * \brief Configures the output driver mode for a GPIO pin.
  489. *
  490. * Configures the output driver mode for a GPIO output, to
  491. * control the pad behavior.
  492. *
  493. * \param[in] gpio_pin Index of the GPIO pin to configure
  494. * \param[in] mode New pad output driver mode to configure
  495. */
  496. static inline void system_pinmux_pin_set_output_drive(
  497. const uint8_t gpio_pin,
  498. const enum system_pinmux_pin_drive mode)
  499. {
  500. PortGroup* const port = system_pinmux_get_group_from_gpio_pin(gpio_pin);
  501. uint32_t pin_index = (gpio_pin % 32);
  502. if (mode == SYSTEM_PINMUX_PIN_DRIVE_OPEN_DRAIN) {
  503. port->PINCFG[pin_index].reg |= PORT_PINCFG_ODRAIN;
  504. }
  505. else {
  506. port->PINCFG[pin_index].reg &= ~PORT_PINCFG_ODRAIN;
  507. }
  508. }
  509. void system_pinmux_group_set_output_drive(
  510. PortGroup *const port,
  511. const uint32_t mask,
  512. const enum system_pinmux_pin_drive mode);
  513. #endif
  514. #ifdef __cplusplus
  515. }
  516. #endif
  517. /** @} */
  518. /**
  519. * \page asfdoc_sam0_system_pinmux_extra Extra Information for SYSTEM PINMUX Driver
  520. *
  521. * \section asfdoc_sam0_system_pinmux_extra_acronyms Acronyms
  522. * The table below presents the acronyms used in this module:
  523. *
  524. * <table>
  525. * <tr>
  526. * <th>Acronym</th>
  527. * <th>Description</th>
  528. * </tr>
  529. * <tr>
  530. * <td>GPIO</td>
  531. * <td>General Purpose Input/Output</td>
  532. * </tr>
  533. * <tr>
  534. * <td>MUX</td>
  535. * <td>Multiplexer</td>
  536. * </tr>
  537. * </table>
  538. *
  539. *
  540. * \section asfdoc_sam0_system_pinmux_extra_dependencies Dependencies
  541. * This driver has the following dependencies:
  542. *
  543. * - None
  544. *
  545. *
  546. * \section asfdoc_sam0_system_pinmux_extra_errata Errata
  547. * There are no errata related to this driver.
  548. *
  549. *
  550. * \section asfdoc_sam0_system_pinmux_extra_history Module History
  551. * An overview of the module history is presented in the table below, with
  552. * details on the enhancements and fixes made to the module since its first
  553. * release. The current version of this corresponds to the newest version in
  554. * the table.
  555. *
  556. * <table>
  557. * <tr>
  558. * <th>Changelog</th>
  559. * </tr>
  560. * <tr>
  561. * <td>Removed code of open drain, slew limit and drive strength
  562. * features</td>
  563. * </tr>
  564. * <tr>
  565. * <td>Fixed broken sampling mode function implementations, which wrote
  566. * corrupt configuration values to the device registers</td>
  567. * </tr>
  568. * <tr>
  569. * <td>Added missing NULL pointer asserts to the PORT driver functions</td>
  570. * </tr>
  571. * <tr>
  572. * <td>Initial Release</td>
  573. * </tr>
  574. * </table>
  575. */
  576. /**
  577. * \page asfdoc_sam0_system_pinmux_exqsg Examples for SYSTEM PINMUX Driver
  578. *
  579. * This is a list of the available Quick Start guides (QSGs) and example
  580. * applications for \ref asfdoc_sam0_system_pinmux_group. QSGs are simple
  581. * examples with step-by-step instructions to configure and use this driver in a
  582. * selection of use cases. Note that a QSG can be compiled as a standalone
  583. * application or be added to the user application.
  584. *
  585. * - \subpage asfdoc_sam0_system_pinmux_basic_use_case
  586. *
  587. * \page asfdoc_sam0_system_pinmux_document_revision_history Document Revision History
  588. *
  589. * <table>
  590. * <tr>
  591. * <th>Doc. Rev.</td>
  592. * <th>Date</td>
  593. * <th>Comments</td>
  594. * </tr>
  595. * <tr>
  596. * <td>42121F</td>
  597. * <td>12/2015</td>
  598. * <td>Added support for SAM L21/L22, SAM DA1, SAM D09, and SAM C20/C21</td>
  599. * </tr>
  600. * <tr>
  601. * <td>42121E</td>
  602. * <td>12/2014</td>
  603. * <td>Added support for SAM R21 and SAM D10/D11</td>
  604. * </tr>
  605. * <tr>
  606. * <td>42121D</td>
  607. * <td>01/2014</td>
  608. * <td>Added support for SAM D21</td>
  609. * </tr>
  610. * <tr>
  611. * <td>42121C</td>
  612. * <td>09/2013</td>
  613. * <td>Fixed incorrect documentation for the device pin sampling mode</td>
  614. * </tr>
  615. * <tr>
  616. * <td>42121B</td>
  617. * <td>06/2013</td>
  618. * <td>Corrected documentation typos</td>
  619. * </tr>
  620. * <tr>
  621. * <td>42121A</td>
  622. * <td>06/2013</td>
  623. * <td>Initial release</td>
  624. * </tr>
  625. * </table>
  626. */
  627. #endif