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 Jul 17 09:15:10 2015 +0100
Revision:
592:a274ee790e56
Parent:
579:53297373a894
Synchronized with git revision e7144f83a8d75df80c4877936b6ffe552b0be9e6

Full URL: https://github.com/mbedmicro/mbed/commit/e7144f83a8d75df80c4877936b6ffe552b0be9e6/

More API implementation for SAMR21

Who changed what in which revision?

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