t
Fork of mbed-dev by
targets/TARGET_Atmel/TARGET_SAM_CortexM4/drivers/pio/pio.h@149:156823d33999, 2016-10-28 (annotated)
- Committer:
- <>
- Date:
- Fri Oct 28 11:17:30 2016 +0100
- Revision:
- 149:156823d33999
- Parent:
- targets/hal/TARGET_Atmel/TARGET_SAM_CortexM4/drivers/pio/pio.h@107:414e9c822e99
This updates the lib to the mbed lib v128
NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 107:414e9c822e99 | 1 | /** |
mbed_official | 107:414e9c822e99 | 2 | * \file |
mbed_official | 107:414e9c822e99 | 3 | * |
mbed_official | 107:414e9c822e99 | 4 | * \brief Parallel Input/Output (PIO) Controller driver for SAM. |
mbed_official | 107:414e9c822e99 | 5 | * |
mbed_official | 107:414e9c822e99 | 6 | * Copyright (c) 2011-2015 Atmel Corporation. All rights reserved. |
mbed_official | 107:414e9c822e99 | 7 | * |
mbed_official | 107:414e9c822e99 | 8 | * \asf_license_start |
mbed_official | 107:414e9c822e99 | 9 | * |
mbed_official | 107:414e9c822e99 | 10 | * \page License |
mbed_official | 107:414e9c822e99 | 11 | * |
mbed_official | 107:414e9c822e99 | 12 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 107:414e9c822e99 | 13 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 107:414e9c822e99 | 14 | * |
mbed_official | 107:414e9c822e99 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 107:414e9c822e99 | 16 | * this list of conditions and the following disclaimer. |
mbed_official | 107:414e9c822e99 | 17 | * |
mbed_official | 107:414e9c822e99 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 107:414e9c822e99 | 19 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 107:414e9c822e99 | 20 | * and/or other materials provided with the distribution. |
mbed_official | 107:414e9c822e99 | 21 | * |
mbed_official | 107:414e9c822e99 | 22 | * 3. The name of Atmel may not be used to endorse or promote products derived |
mbed_official | 107:414e9c822e99 | 23 | * from this software without specific prior written permission. |
mbed_official | 107:414e9c822e99 | 24 | * |
mbed_official | 107:414e9c822e99 | 25 | * 4. This software may only be redistributed and used in connection with an |
mbed_official | 107:414e9c822e99 | 26 | * Atmel microcontroller product. |
mbed_official | 107:414e9c822e99 | 27 | * |
mbed_official | 107:414e9c822e99 | 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED |
mbed_official | 107:414e9c822e99 | 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
mbed_official | 107:414e9c822e99 | 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
mbed_official | 107:414e9c822e99 | 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR |
mbed_official | 107:414e9c822e99 | 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 107:414e9c822e99 | 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
mbed_official | 107:414e9c822e99 | 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
mbed_official | 107:414e9c822e99 | 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
mbed_official | 107:414e9c822e99 | 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
mbed_official | 107:414e9c822e99 | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
mbed_official | 107:414e9c822e99 | 38 | * POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 107:414e9c822e99 | 39 | * |
mbed_official | 107:414e9c822e99 | 40 | * \asf_license_stop |
mbed_official | 107:414e9c822e99 | 41 | * |
mbed_official | 107:414e9c822e99 | 42 | */ |
mbed_official | 107:414e9c822e99 | 43 | /* |
mbed_official | 107:414e9c822e99 | 44 | * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> |
mbed_official | 107:414e9c822e99 | 45 | */ |
mbed_official | 107:414e9c822e99 | 46 | |
mbed_official | 107:414e9c822e99 | 47 | #ifndef PIO_H_INCLUDED |
mbed_official | 107:414e9c822e99 | 48 | #define PIO_H_INCLUDED |
mbed_official | 107:414e9c822e99 | 49 | |
mbed_official | 107:414e9c822e99 | 50 | #include "compiler.h" |
mbed_official | 107:414e9c822e99 | 51 | |
mbed_official | 107:414e9c822e99 | 52 | #ifdef __cplusplus |
mbed_official | 107:414e9c822e99 | 53 | extern "C" { |
mbed_official | 107:414e9c822e99 | 54 | #endif |
mbed_official | 107:414e9c822e99 | 55 | |
mbed_official | 107:414e9c822e99 | 56 | /* Compute PIO register length */ |
mbed_official | 107:414e9c822e99 | 57 | #define PIO_DELTA ((uint32_t) PIOB - (uint32_t) PIOA) |
mbed_official | 107:414e9c822e99 | 58 | |
mbed_official | 107:414e9c822e99 | 59 | /* GPIO Support */ |
mbed_official | 107:414e9c822e99 | 60 | #define PIO_TYPE_Pos 27 |
mbed_official | 107:414e9c822e99 | 61 | /* PIO Type Mask */ |
mbed_official | 107:414e9c822e99 | 62 | #define PIO_TYPE_Msk (0xFu << PIO_TYPE_Pos) |
mbed_official | 107:414e9c822e99 | 63 | /* The pin is not a function pin. */ |
mbed_official | 107:414e9c822e99 | 64 | #define PIO_TYPE_NOT_A_PIN (0x0u << PIO_TYPE_Pos) |
mbed_official | 107:414e9c822e99 | 65 | /* The pin is controlled by the peripheral A. */ |
mbed_official | 107:414e9c822e99 | 66 | #define PIO_TYPE_PIO_PERIPH_A (0x1u << PIO_TYPE_Pos) |
mbed_official | 107:414e9c822e99 | 67 | /* The pin is controlled by the peripheral B. */ |
mbed_official | 107:414e9c822e99 | 68 | #define PIO_TYPE_PIO_PERIPH_B (0x2u << PIO_TYPE_Pos) |
mbed_official | 107:414e9c822e99 | 69 | /* The pin is controlled by the peripheral C. */ |
mbed_official | 107:414e9c822e99 | 70 | #define PIO_TYPE_PIO_PERIPH_C (0x3u << PIO_TYPE_Pos) |
mbed_official | 107:414e9c822e99 | 71 | /* The pin is controlled by the peripheral D. */ |
mbed_official | 107:414e9c822e99 | 72 | #define PIO_TYPE_PIO_PERIPH_D (0x4u << PIO_TYPE_Pos) |
mbed_official | 107:414e9c822e99 | 73 | /* The pin is an input. */ |
mbed_official | 107:414e9c822e99 | 74 | #define PIO_TYPE_PIO_INPUT (0x5u << PIO_TYPE_Pos) |
mbed_official | 107:414e9c822e99 | 75 | /* The pin is an output and has a default level of 0. */ |
mbed_official | 107:414e9c822e99 | 76 | #define PIO_TYPE_PIO_OUTPUT_0 (0x6u << PIO_TYPE_Pos) |
mbed_official | 107:414e9c822e99 | 77 | /* The pin is an output and has a default level of 1. */ |
mbed_official | 107:414e9c822e99 | 78 | #define PIO_TYPE_PIO_OUTPUT_1 (0x7u << PIO_TYPE_Pos) |
mbed_official | 107:414e9c822e99 | 79 | |
mbed_official | 107:414e9c822e99 | 80 | typedef enum _pio_type { |
mbed_official | 107:414e9c822e99 | 81 | PIO_NOT_A_PIN = PIO_TYPE_NOT_A_PIN, |
mbed_official | 107:414e9c822e99 | 82 | PIO_PERIPH_A = PIO_TYPE_PIO_PERIPH_A, |
mbed_official | 107:414e9c822e99 | 83 | PIO_PERIPH_B = PIO_TYPE_PIO_PERIPH_B, |
mbed_official | 107:414e9c822e99 | 84 | #if (SAM3S || SAM3N || SAM4S || SAM4E || SAM4N || SAM4C || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70) |
mbed_official | 107:414e9c822e99 | 85 | PIO_PERIPH_C = PIO_TYPE_PIO_PERIPH_C, |
mbed_official | 107:414e9c822e99 | 86 | PIO_PERIPH_D = PIO_TYPE_PIO_PERIPH_D, |
mbed_official | 107:414e9c822e99 | 87 | #endif |
mbed_official | 107:414e9c822e99 | 88 | PIO_INPUT = PIO_TYPE_PIO_INPUT, |
mbed_official | 107:414e9c822e99 | 89 | PIO_OUTPUT_0 = PIO_TYPE_PIO_OUTPUT_0, |
mbed_official | 107:414e9c822e99 | 90 | PIO_OUTPUT_1 = PIO_TYPE_PIO_OUTPUT_1 |
mbed_official | 107:414e9c822e99 | 91 | } pio_type_t; |
mbed_official | 107:414e9c822e99 | 92 | |
mbed_official | 107:414e9c822e99 | 93 | /* Default pin configuration (no attribute). */ |
mbed_official | 107:414e9c822e99 | 94 | #define PIO_DEFAULT (0u << 0) |
mbed_official | 107:414e9c822e99 | 95 | /* The internal pin pull-up is active. */ |
mbed_official | 107:414e9c822e99 | 96 | #define PIO_PULLUP (1u << 0) |
mbed_official | 107:414e9c822e99 | 97 | /* The internal glitch filter is active. */ |
mbed_official | 107:414e9c822e99 | 98 | #define PIO_DEGLITCH (1u << 1) |
mbed_official | 107:414e9c822e99 | 99 | /* The pin is open-drain. */ |
mbed_official | 107:414e9c822e99 | 100 | #define PIO_OPENDRAIN (1u << 2) |
mbed_official | 107:414e9c822e99 | 101 | |
mbed_official | 107:414e9c822e99 | 102 | /* The internal debouncing filter is active. */ |
mbed_official | 107:414e9c822e99 | 103 | #define PIO_DEBOUNCE (1u << 3) |
mbed_official | 107:414e9c822e99 | 104 | |
mbed_official | 107:414e9c822e99 | 105 | /* Enable additional interrupt modes. */ |
mbed_official | 107:414e9c822e99 | 106 | #define PIO_IT_AIME (1u << 4) |
mbed_official | 107:414e9c822e99 | 107 | |
mbed_official | 107:414e9c822e99 | 108 | /* Interrupt High Level/Rising Edge detection is active. */ |
mbed_official | 107:414e9c822e99 | 109 | #define PIO_IT_RE_OR_HL (1u << 5) |
mbed_official | 107:414e9c822e99 | 110 | /* Interrupt Edge detection is active. */ |
mbed_official | 107:414e9c822e99 | 111 | #define PIO_IT_EDGE (1u << 6) |
mbed_official | 107:414e9c822e99 | 112 | |
mbed_official | 107:414e9c822e99 | 113 | /* Low level interrupt is active */ |
mbed_official | 107:414e9c822e99 | 114 | #define PIO_IT_LOW_LEVEL (0 | 0 | PIO_IT_AIME) |
mbed_official | 107:414e9c822e99 | 115 | /* High level interrupt is active */ |
mbed_official | 107:414e9c822e99 | 116 | #define PIO_IT_HIGH_LEVEL (PIO_IT_RE_OR_HL | 0 | PIO_IT_AIME) |
mbed_official | 107:414e9c822e99 | 117 | /* Falling edge interrupt is active */ |
mbed_official | 107:414e9c822e99 | 118 | #define PIO_IT_FALL_EDGE (0 | PIO_IT_EDGE | PIO_IT_AIME) |
mbed_official | 107:414e9c822e99 | 119 | /* Rising edge interrupt is active */ |
mbed_official | 107:414e9c822e99 | 120 | #define PIO_IT_RISE_EDGE (PIO_IT_RE_OR_HL | PIO_IT_EDGE | PIO_IT_AIME) |
mbed_official | 107:414e9c822e99 | 121 | |
mbed_official | 107:414e9c822e99 | 122 | /* |
mbed_official | 107:414e9c822e99 | 123 | * The #attribute# field is a bitmask that can either be set to PIO_DEFAULT, |
mbed_official | 107:414e9c822e99 | 124 | * or combine (using bitwise OR '|') any number of the following constants: |
mbed_official | 107:414e9c822e99 | 125 | * - PIO_PULLUP |
mbed_official | 107:414e9c822e99 | 126 | * - PIO_DEGLITCH |
mbed_official | 107:414e9c822e99 | 127 | * - PIO_DEBOUNCE |
mbed_official | 107:414e9c822e99 | 128 | * - PIO_OPENDRAIN |
mbed_official | 107:414e9c822e99 | 129 | * - PIO_IT_LOW_LEVEL |
mbed_official | 107:414e9c822e99 | 130 | * - PIO_IT_HIGH_LEVEL |
mbed_official | 107:414e9c822e99 | 131 | * - PIO_IT_FALL_EDGE |
mbed_official | 107:414e9c822e99 | 132 | * - PIO_IT_RISE_EDGE |
mbed_official | 107:414e9c822e99 | 133 | */ |
mbed_official | 107:414e9c822e99 | 134 | void pio_pull_up(Pio *p_pio, const uint32_t ul_mask, |
mbed_official | 107:414e9c822e99 | 135 | const uint32_t ul_pull_up_enable); |
mbed_official | 107:414e9c822e99 | 136 | void pio_set_debounce_filter(Pio *p_pio, const uint32_t ul_mask, |
mbed_official | 107:414e9c822e99 | 137 | const uint32_t ul_cut_off); |
mbed_official | 107:414e9c822e99 | 138 | void pio_set(Pio *p_pio, const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 139 | void pio_clear(Pio *p_pio, const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 140 | uint32_t pio_get(Pio *p_pio, const pio_type_t ul_type, |
mbed_official | 107:414e9c822e99 | 141 | const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 142 | void pio_set_peripheral(Pio *p_pio, const pio_type_t ul_type, |
mbed_official | 107:414e9c822e99 | 143 | const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 144 | void pio_set_input(Pio *p_pio, const uint32_t ul_mask, |
mbed_official | 107:414e9c822e99 | 145 | const uint32_t ul_attribute); |
mbed_official | 107:414e9c822e99 | 146 | void pio_set_output(Pio *p_pio, const uint32_t ul_mask, |
mbed_official | 107:414e9c822e99 | 147 | const uint32_t ul_default_level, |
mbed_official | 107:414e9c822e99 | 148 | const uint32_t ul_multidrive_enable, |
mbed_official | 107:414e9c822e99 | 149 | const uint32_t ul_pull_up_enable); |
mbed_official | 107:414e9c822e99 | 150 | uint32_t pio_configure(Pio *p_pio, const pio_type_t ul_type, |
mbed_official | 107:414e9c822e99 | 151 | const uint32_t ul_mask, const uint32_t ul_attribute); |
mbed_official | 107:414e9c822e99 | 152 | uint32_t pio_get_output_data_status(const Pio *p_pio, |
mbed_official | 107:414e9c822e99 | 153 | const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 154 | void pio_set_multi_driver(Pio *p_pio, const uint32_t ul_mask, |
mbed_official | 107:414e9c822e99 | 155 | const uint32_t ul_multi_driver_enable); |
mbed_official | 107:414e9c822e99 | 156 | uint32_t pio_get_multi_driver_status(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 157 | |
mbed_official | 107:414e9c822e99 | 158 | #if (SAM3S || SAM3N || SAM4S || SAM4E || SAM4N || SAM4C || SAMG || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70) |
mbed_official | 107:414e9c822e99 | 159 | void pio_pull_down(Pio *p_pio, const uint32_t ul_mask, |
mbed_official | 107:414e9c822e99 | 160 | const uint32_t ul_pull_down_enable); |
mbed_official | 107:414e9c822e99 | 161 | #endif |
mbed_official | 107:414e9c822e99 | 162 | |
mbed_official | 107:414e9c822e99 | 163 | void pio_enable_output_write(Pio *p_pio, const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 164 | void pio_disable_output_write(Pio *p_pio, const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 165 | uint32_t pio_get_output_write_status(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 166 | void pio_sync_output_write(Pio *p_pio, const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 167 | |
mbed_official | 107:414e9c822e99 | 168 | #if (SAM3S || SAM3N || SAM4S || SAM4E || SAM4N || SAM4C || SAMG || SAM4CP || SAM4CM || SAMV71 || SAMV70 || SAME70 || SAMS70) |
mbed_official | 107:414e9c822e99 | 169 | void pio_set_schmitt_trigger(Pio *p_pio, const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 170 | uint32_t pio_get_schmitt_trigger(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 171 | #endif |
mbed_official | 107:414e9c822e99 | 172 | |
mbed_official | 107:414e9c822e99 | 173 | void pio_configure_interrupt(Pio *p_pio, const uint32_t ul_mask, |
mbed_official | 107:414e9c822e99 | 174 | const uint32_t ul_attr); |
mbed_official | 107:414e9c822e99 | 175 | void pio_enable_interrupt(Pio *p_pio, const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 176 | void pio_disable_interrupt(Pio *p_pio, const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 177 | uint32_t pio_get_interrupt_status(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 178 | uint32_t pio_get_interrupt_mask(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 179 | void pio_set_additional_interrupt_mode(Pio *p_pio, |
mbed_official | 107:414e9c822e99 | 180 | const uint32_t ul_mask, const uint32_t ul_attribute); |
mbed_official | 107:414e9c822e99 | 181 | void pio_set_writeprotect(Pio *p_pio, const uint32_t ul_enable); |
mbed_official | 107:414e9c822e99 | 182 | uint32_t pio_get_writeprotect_status(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 183 | |
mbed_official | 107:414e9c822e99 | 184 | #if (SAM3S || SAM4S || SAM4E || SAMV71 || SAMV70 || SAME70 || SAMS70) |
mbed_official | 107:414e9c822e99 | 185 | void pio_capture_set_mode(Pio *p_pio, uint32_t ul_mode); |
mbed_official | 107:414e9c822e99 | 186 | void pio_capture_enable(Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 187 | void pio_capture_disable(Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 188 | uint32_t pio_capture_read(const Pio *p_pio, uint32_t * pul_data); |
mbed_official | 107:414e9c822e99 | 189 | void pio_capture_enable_interrupt(Pio *p_pio, const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 190 | void pio_capture_disable_interrupt(Pio * p_pio, const uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 191 | uint32_t pio_capture_get_interrupt_status(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 192 | uint32_t pio_capture_get_interrupt_mask(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 193 | #if !(SAMV71 || SAMV70 || SAME70 || SAMS70) |
mbed_official | 107:414e9c822e99 | 194 | Pdc *pio_capture_get_pdc_base(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 195 | #endif |
mbed_official | 107:414e9c822e99 | 196 | #endif |
mbed_official | 107:414e9c822e99 | 197 | |
mbed_official | 107:414e9c822e99 | 198 | /* GPIO Support */ |
mbed_official | 107:414e9c822e99 | 199 | uint32_t pio_get_pin_value(uint32_t pin); |
mbed_official | 107:414e9c822e99 | 200 | void pio_set_pin_high(uint32_t pin); |
mbed_official | 107:414e9c822e99 | 201 | void pio_set_pin_low(uint32_t pin); |
mbed_official | 107:414e9c822e99 | 202 | void pio_toggle_pin(uint32_t pin); |
mbed_official | 107:414e9c822e99 | 203 | void pio_enable_pin_interrupt(uint32_t pin); |
mbed_official | 107:414e9c822e99 | 204 | void pio_disable_pin_interrupt(uint32_t pin); |
mbed_official | 107:414e9c822e99 | 205 | Pio *pio_get_pin_group(uint32_t pin); |
mbed_official | 107:414e9c822e99 | 206 | uint32_t pio_get_pin_group_id(uint32_t pin); |
mbed_official | 107:414e9c822e99 | 207 | uint32_t pio_get_pin_group_mask(uint32_t pin); |
mbed_official | 107:414e9c822e99 | 208 | uint32_t pio_configure_pin(uint32_t ul_pin, const uint32_t ul_flags); |
mbed_official | 107:414e9c822e99 | 209 | void pio_set_pin_group_high(Pio *p_pio, uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 210 | void pio_set_pin_group_low(Pio *p_pio, uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 211 | void pio_toggle_pin_group(Pio *p_pio, uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 212 | uint32_t pio_configure_pin_group(Pio *p_pio, uint32_t ul_mask, |
mbed_official | 107:414e9c822e99 | 213 | const uint32_t ul_flags); |
mbed_official | 107:414e9c822e99 | 214 | |
mbed_official | 107:414e9c822e99 | 215 | #if (SAM4C || SAM4CP || SAM4CM || SAMG55) |
mbed_official | 107:414e9c822e99 | 216 | enum pio_io_drive_mode { |
mbed_official | 107:414e9c822e99 | 217 | PIO_IO_DRIVE_LOW = 0, |
mbed_official | 107:414e9c822e99 | 218 | PIO_IO_DRIVE_HIGH, |
mbed_official | 107:414e9c822e99 | 219 | }; |
mbed_official | 107:414e9c822e99 | 220 | void pio_set_io_drive(Pio *p_pio, uint32_t ul_line, |
mbed_official | 107:414e9c822e99 | 221 | enum pio_io_drive_mode mode); |
mbed_official | 107:414e9c822e99 | 222 | #endif |
mbed_official | 107:414e9c822e99 | 223 | |
mbed_official | 107:414e9c822e99 | 224 | #if (SAMV71 || SAMV70 || SAME70 || SAMS70) |
mbed_official | 107:414e9c822e99 | 225 | void pio_keypad_enable(Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 226 | void pio_keypad_disable(Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 227 | void pio_keypad_set_row_num(Pio *p_pio, uint8_t num); |
mbed_official | 107:414e9c822e99 | 228 | uint8_t pio_keypad_get_row_num(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 229 | void pio_keypad_set_column_num(Pio *p_pio, uint8_t num); |
mbed_official | 107:414e9c822e99 | 230 | uint8_t pio_keypad_get_column_num(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 231 | void pio_keypad_set_debouncing_value(Pio *p_pio, uint16_t value); |
mbed_official | 107:414e9c822e99 | 232 | uint16_t pio_keypad_get_debouncing_value(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 233 | void pio_keypad_enable_interrupt(Pio *p_pio, uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 234 | void pio_keypad_disable_interrupt(Pio *p_pio, uint32_t ul_mask); |
mbed_official | 107:414e9c822e99 | 235 | uint32_t pio_keypad_get_interrupt_mask(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 236 | uint32_t pio_keypad_get_press_status(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 237 | uint32_t pio_keypad_get_release_status(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 238 | uint8_t pio_keypad_get_simult_press_num(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 239 | uint8_t pio_keypad_get_simult_release_num(const Pio *p_pio); |
mbed_official | 107:414e9c822e99 | 240 | uint8_t pio_keypad_get_press_row_index(const Pio *p_pio, uint8_t queue); |
mbed_official | 107:414e9c822e99 | 241 | uint8_t pio_keypad_get_press_column_index(const Pio *p_pio, uint8_t queue); |
mbed_official | 107:414e9c822e99 | 242 | uint8_t pio_keypad_get_release_row_index(const Pio *p_pio, uint8_t queue); |
mbed_official | 107:414e9c822e99 | 243 | uint8_t pio_keypad_get_release_column_index(const Pio *p_pio, uint8_t queue); |
mbed_official | 107:414e9c822e99 | 244 | #endif |
mbed_official | 107:414e9c822e99 | 245 | /** |
mbed_official | 107:414e9c822e99 | 246 | * \page sam_pio_quickstart Quick Start Guide for the SAM PIO driver |
mbed_official | 107:414e9c822e99 | 247 | * |
mbed_official | 107:414e9c822e99 | 248 | * This is the quick start guide for the \ref sam_drivers_pio_group "PIO Driver", |
mbed_official | 107:414e9c822e99 | 249 | * with step-by-step instructions on how to configure and use the driver for |
mbed_official | 107:414e9c822e99 | 250 | * specific use cases. |
mbed_official | 107:414e9c822e99 | 251 | * |
mbed_official | 107:414e9c822e99 | 252 | * The section described below can be compiled into e.g. the main application |
mbed_official | 107:414e9c822e99 | 253 | * loop or any other function that will need to interface with the IO port. |
mbed_official | 107:414e9c822e99 | 254 | * |
mbed_official | 107:414e9c822e99 | 255 | * \section sam_pio_usecases PIO use cases |
mbed_official | 107:414e9c822e99 | 256 | * - \ref sam_pio_quickstart_basic |
mbed_official | 107:414e9c822e99 | 257 | * - \ref sam_pio_quickstart_use_case_2 |
mbed_official | 107:414e9c822e99 | 258 | * |
mbed_official | 107:414e9c822e99 | 259 | * \section sam_pio_quickstart_basic Basic usage of the PIO driver |
mbed_official | 107:414e9c822e99 | 260 | * This section will present a basic use case for the PIO driver. This use case |
mbed_official | 107:414e9c822e99 | 261 | * will configure pin 23 on port A as output and pin 16 as an input with pullup, |
mbed_official | 107:414e9c822e99 | 262 | * and then toggle the output pin's value to match that of the input pin. |
mbed_official | 107:414e9c822e99 | 263 | * |
mbed_official | 107:414e9c822e99 | 264 | * \subsection sam_pio_quickstart_use_case_1_prereq Prerequisites |
mbed_official | 107:414e9c822e99 | 265 | * - \ref group_pmc "Power Management Controller driver" |
mbed_official | 107:414e9c822e99 | 266 | * |
mbed_official | 107:414e9c822e99 | 267 | * \subsection sam_pio_quickstart_use_case_1_setup_steps Initialization code |
mbed_official | 107:414e9c822e99 | 268 | * Add to the application initialization code: |
mbed_official | 107:414e9c822e99 | 269 | * \code |
mbed_official | 107:414e9c822e99 | 270 | pmc_enable_periph_clk(ID_PIOA); |
mbed_official | 107:414e9c822e99 | 271 | |
mbed_official | 107:414e9c822e99 | 272 | pio_set_output(PIOA, PIO_PA23, LOW, DISABLE, ENABLE); |
mbed_official | 107:414e9c822e99 | 273 | pio_set_input(PIOA, PIO_PA16, PIO_PULLUP); |
mbed_official | 107:414e9c822e99 | 274 | \endcode |
mbed_official | 107:414e9c822e99 | 275 | * |
mbed_official | 107:414e9c822e99 | 276 | * \subsection sam_pio_quickstart_use_case_1_setup_steps_workflow Workflow |
mbed_official | 107:414e9c822e99 | 277 | * -# Enable the module clock to the PIOA peripheral: |
mbed_official | 107:414e9c822e99 | 278 | * \code pmc_enable_periph_clk(ID_PIOA); \endcode |
mbed_official | 107:414e9c822e99 | 279 | * -# Set pin 23 direction on PIOA as output, default low level: |
mbed_official | 107:414e9c822e99 | 280 | * \code pio_set_output(PIOA, PIO_PA23, LOW, DISABLE, ENABLE); \endcode |
mbed_official | 107:414e9c822e99 | 281 | * -# Set pin 16 direction on PIOA as input, with pullup: |
mbed_official | 107:414e9c822e99 | 282 | * \code pio_set_input(PIOA, PIO_PA16, PIO_PULLUP); \endcode |
mbed_official | 107:414e9c822e99 | 283 | * |
mbed_official | 107:414e9c822e99 | 284 | * \subsection sam_pio_quickstart_use_case_1_example_code Example code |
mbed_official | 107:414e9c822e99 | 285 | * Set the state of output pin 23 to match input pin 16: |
mbed_official | 107:414e9c822e99 | 286 | * \code |
mbed_official | 107:414e9c822e99 | 287 | if (pio_get(PIOA, PIO_TYPE_PIO_INPUT, PIO_PA16)) |
mbed_official | 107:414e9c822e99 | 288 | pio_clear(PIOA, PIO_PA23); |
mbed_official | 107:414e9c822e99 | 289 | else |
mbed_official | 107:414e9c822e99 | 290 | pio_set(PIOA, PIO_PA23); |
mbed_official | 107:414e9c822e99 | 291 | \endcode |
mbed_official | 107:414e9c822e99 | 292 | * |
mbed_official | 107:414e9c822e99 | 293 | * \subsection sam_pio_quickstart_use_case_1_example_workflow Workflow |
mbed_official | 107:414e9c822e99 | 294 | * -# We check the value of the pin: |
mbed_official | 107:414e9c822e99 | 295 | * \code |
mbed_official | 107:414e9c822e99 | 296 | if (pio_get(PIOA, PIO_TYPE_PIO_INPUT, PIO_PA16)) |
mbed_official | 107:414e9c822e99 | 297 | \endcode |
mbed_official | 107:414e9c822e99 | 298 | * -# Then we set the new output value based on the read pin value: |
mbed_official | 107:414e9c822e99 | 299 | * \code |
mbed_official | 107:414e9c822e99 | 300 | pio_clear(PIOA, PIO_PA23); |
mbed_official | 107:414e9c822e99 | 301 | else |
mbed_official | 107:414e9c822e99 | 302 | pio_set(PIOA, PIO_PA23); |
mbed_official | 107:414e9c822e99 | 303 | \endcode |
mbed_official | 107:414e9c822e99 | 304 | */ |
mbed_official | 107:414e9c822e99 | 305 | |
mbed_official | 107:414e9c822e99 | 306 | /** |
mbed_official | 107:414e9c822e99 | 307 | * \page sam_pio_quickstart_use_case_2 Advanced use case - Interrupt driven edge detection |
mbed_official | 107:414e9c822e99 | 308 | * |
mbed_official | 107:414e9c822e99 | 309 | * \section sam_pio_quickstart_use_case_2 Advanced Use Case 1 |
mbed_official | 107:414e9c822e99 | 310 | * This section will present a more advanced use case for the PIO driver. This use case |
mbed_official | 107:414e9c822e99 | 311 | * will configure pin 23 on port A as output and pin 16 as an input with pullup, |
mbed_official | 107:414e9c822e99 | 312 | * and then toggle the output pin's value to match that of the input pin using the interrupt |
mbed_official | 107:414e9c822e99 | 313 | * controller within the device. |
mbed_official | 107:414e9c822e99 | 314 | * |
mbed_official | 107:414e9c822e99 | 315 | * \subsection sam_pio_quickstart_use_case_2_prereq Prerequisites |
mbed_official | 107:414e9c822e99 | 316 | * - \ref group_pmc "Power Management Controller driver" |
mbed_official | 107:414e9c822e99 | 317 | * |
mbed_official | 107:414e9c822e99 | 318 | * \subsection sam_pio_quickstart_use_case_2_setup_steps Initialization code |
mbed_official | 107:414e9c822e99 | 319 | * Add to the application initialization code: |
mbed_official | 107:414e9c822e99 | 320 | * \code |
mbed_official | 107:414e9c822e99 | 321 | pmc_enable_periph_clk(ID_PIOA); |
mbed_official | 107:414e9c822e99 | 322 | |
mbed_official | 107:414e9c822e99 | 323 | pio_set_output(PIOA, PIO_PA23, LOW, DISABLE, ENABLE); |
mbed_official | 107:414e9c822e99 | 324 | pio_set_input(PIOA, PIO_PA16, PIO_PULLUP); |
mbed_official | 107:414e9c822e99 | 325 | |
mbed_official | 107:414e9c822e99 | 326 | pio_handler_set(PIOA, ID_PIOA, PIO_PA16, PIO_IT_EDGE, pin_edge_handler); |
mbed_official | 107:414e9c822e99 | 327 | pio_enable_interrupt(PIOA, PIO_PA16); |
mbed_official | 107:414e9c822e99 | 328 | |
mbed_official | 107:414e9c822e99 | 329 | NVIC_EnableIRQ(PIOA_IRQn); |
mbed_official | 107:414e9c822e99 | 330 | \endcode |
mbed_official | 107:414e9c822e99 | 331 | * |
mbed_official | 107:414e9c822e99 | 332 | * \subsection sam_pio_quickstart_use_case_2_setup_steps_workflow Workflow |
mbed_official | 107:414e9c822e99 | 333 | * -# Enable the module clock to the PIOA peripheral: |
mbed_official | 107:414e9c822e99 | 334 | * \code pmc_enable_periph_clk(ID_PIOA); \endcode |
mbed_official | 107:414e9c822e99 | 335 | * -# Set pin 23 direction on PIOA as output, default low level: |
mbed_official | 107:414e9c822e99 | 336 | * \code pio_set_output(PIOA, PIO_PA23, LOW, DISABLE, ENABLE); \endcode |
mbed_official | 107:414e9c822e99 | 337 | * -# Set pin 16 direction on PIOA as input, with pullup: |
mbed_official | 107:414e9c822e99 | 338 | * \code pio_set_input(PIOA, PIO_PA16, PIO_PULLUP); \endcode |
mbed_official | 107:414e9c822e99 | 339 | * -# Configure the input pin 16 interrupt mode and handler: |
mbed_official | 107:414e9c822e99 | 340 | * \code pio_handler_set(PIOA, ID_PIOA, PIO_PA16, PIO_IT_EDGE, pin_edge_handler); \endcode |
mbed_official | 107:414e9c822e99 | 341 | * -# Enable the interrupt for the configured input pin: |
mbed_official | 107:414e9c822e99 | 342 | * \code pio_enable_interrupt(PIOA, PIO_PA16); \endcode |
mbed_official | 107:414e9c822e99 | 343 | * -# Enable interrupt handling from the PIOA module: |
mbed_official | 107:414e9c822e99 | 344 | * \code NVIC_EnableIRQ(PIOA_IRQn); \endcode |
mbed_official | 107:414e9c822e99 | 345 | * |
mbed_official | 107:414e9c822e99 | 346 | * \subsection sam_pio_quickstart_use_case_2_example_code Example code |
mbed_official | 107:414e9c822e99 | 347 | * Add the following function to your application: |
mbed_official | 107:414e9c822e99 | 348 | * \code |
mbed_official | 107:414e9c822e99 | 349 | void pin_edge_handler(const uint32_t id, const uint32_t index) |
mbed_official | 107:414e9c822e99 | 350 | { |
mbed_official | 107:414e9c822e99 | 351 | if ((id == ID_PIOA) && (index == PIO_PA16)){ |
mbed_official | 107:414e9c822e99 | 352 | if (pio_get(PIOA, PIO_TYPE_PIO_INPUT, PIO_PA16)) |
mbed_official | 107:414e9c822e99 | 353 | pio_clear(PIOA, PIO_PA23); |
mbed_official | 107:414e9c822e99 | 354 | else |
mbed_official | 107:414e9c822e99 | 355 | pio_set(PIOA, PIO_PA23); |
mbed_official | 107:414e9c822e99 | 356 | } |
mbed_official | 107:414e9c822e99 | 357 | } |
mbed_official | 107:414e9c822e99 | 358 | \endcode |
mbed_official | 107:414e9c822e99 | 359 | * |
mbed_official | 107:414e9c822e99 | 360 | * \subsection sam_pio_quickstart_use_case_2_example_workflow Workflow |
mbed_official | 107:414e9c822e99 | 361 | * -# We check the value of the pin: |
mbed_official | 107:414e9c822e99 | 362 | * \code |
mbed_official | 107:414e9c822e99 | 363 | if (pio_get(PIOA, PIO_TYPE_PIO_INPUT, PIO_PA16)) |
mbed_official | 107:414e9c822e99 | 364 | \endcode |
mbed_official | 107:414e9c822e99 | 365 | * -# Then we set the new output value based on the read pin value: |
mbed_official | 107:414e9c822e99 | 366 | * \code |
mbed_official | 107:414e9c822e99 | 367 | pio_clear(PIOA, PIO_PA23); |
mbed_official | 107:414e9c822e99 | 368 | else |
mbed_official | 107:414e9c822e99 | 369 | pio_set(PIOA, PIO_PA23); |
mbed_official | 107:414e9c822e99 | 370 | \endcode |
mbed_official | 107:414e9c822e99 | 371 | */ |
mbed_official | 107:414e9c822e99 | 372 | |
mbed_official | 107:414e9c822e99 | 373 | #ifdef __cplusplus |
mbed_official | 107:414e9c822e99 | 374 | } |
mbed_official | 107:414e9c822e99 | 375 | #endif |
mbed_official | 107:414e9c822e99 | 376 | |
mbed_official | 107:414e9c822e99 | 377 | #endif /* PIO_H_INCLUDED */ |