1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2015, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
33 #define IRQ_PIO_HANDLERS_SIZE 16
\r
35 /*------------------------------------------------------------------------------
\r
37 *------------------------------------------------------------------------------*/
\r
43 uint8_t group; /*< The IO group containing the pins you want to use. */
\r
44 uint32_t mask; /*< Bitmask indicating which pin(s) to configure. */
\r
45 uint8_t type; /*< Pin type */
\r
46 uint32_t attribute; /*< Pin config attribute. */
\r
49 typedef void(*pio_handler_t)(uint32_t, uint32_t, void*);
\r
51 /*------------------------------------------------------------------------------
\r
53 *------------------------------------------------------------------------------*/
\r
55 #if defined(CONFIG_HAVE_PIO4)
\r
56 #include "peripherals/pio4.h"
\r
63 /*------------------------------------------------------------------------------
\r
64 * Exported functions
\r
65 *------------------------------------------------------------------------------*/
\r
68 * \brief Configures a list of Pin instances.
\r
70 * \details Each of them can either hold a single pin or a group of
\r
71 * pins, depending on the mask value; all pins are configured by this
\r
72 * function. The size of the array must also be provided and is easily
\r
73 * computed using ARRAY_SIZE whenever its length is not known in
\r
76 * \param list Pointer to a list of Pin instances.
\r
77 * \param size Size of the Pin list (calculated using ARRAY_SIZE).
\r
79 * \return 1 if the pins have been configured properly; otherwise 0.
\r
81 extern uint8_t pio_configure(const struct _pin *list, uint32_t size);
\r
84 * \brief Sets a high output level on all the PIOs defined in the
\r
85 * given Pin instance.
\r
87 * \details This has no immediate effects on PIOs that are not output,
\r
88 * but the PIO controller will memorize the value they are changed to
\r
91 * \param pin Pointer to a Pin instance describing one or more pins.
\r
93 extern void pio_set(const struct _pin *pin);
\r
96 * \brief Sets a low output level on all the PIOs defined in the given
\r
99 * \details This has no immediate effects on PIOs that are not output,
\r
100 * but the PIO controller will memorize the value they are changed to
\r
103 * \param pin Pointer to a Pin instance describing one or more pins.
\r
105 extern void pio_clear(const struct _pin *pin);
\r
108 * \brief Returns 1 if one or more PIO of the given Pin instance currently have
\r
109 * a high level; otherwise returns 0. This method returns the actual value that
\r
110 * is being read on the pin. To return the supposed output value of a pin, use
\r
111 * \ref pio_get_output_date_status() instead.
\r
113 * \param pin Pointer to a Pin instance describing one or more pins.
\r
115 * \return 1 if the Pin instance contains at least one PIO that currently has
\r
116 * a high level; otherwise 0.
\r
118 extern uint8_t pio_get(const struct _pin *pin);
\r
121 * \brief Returns 1 if one or more PIO of the given Pin are configured to output a
\r
122 * high level (even if they are not output).
\r
123 * To get the actual value of the pin, use pio_get() instead.
\r
125 * \param pin Pointer to a Pin instance describing one or more pins.
\r
127 * \return 1 if the Pin instance contains at least one PIO that is configured
\r
128 * to output a high level; otherwise 0.
\r
130 extern uint8_t pio_get_output_data_status(const struct _pin *pin);
\r
133 * \brief Configures Glitch or Debouncing filter for input.
\r
135 * \param pin Pointer to a Pin instance describing one or more pins.
\r
136 * \param cuttoff Cutt off frequency for debounce filter.
\r
138 extern void pio_set_debounce_filter(const struct _pin *pin, uint32_t cuttoff);
\r
141 * \brief Enable write protect.
\r
143 * \param pin Pointer to a Pin instance describing one or more pins.
\r
145 extern void pio_enable_write_protect(const struct _pin *pin);
\r
148 * \brief Disable write protect.
\r
150 * \param pin Pointer to a Pin instance describing one or more pins.
\r
152 extern void pio_disable_write_protect(const struct _pin *pin);
\r
155 * \brief Get write protect violation information.
\r
157 * \param pin Pointer to a Pin instance describing one or more pins.
\r
159 extern uint32_t pio_get_write_protect_violation_info(const struct _pin * pin);
\r
162 * \brief Configure all pio outputs low
\r
164 * \param group PIO group number
\r
165 * \param mask Bitmask of one or more pin(s) to configure.
\r
167 extern void pio_output_low(uint32_t group, uint32_t mask);
\r
169 extern void pio_add_handler_to_group(uint32_t group, uint32_t mask,
\r
170 pio_handler_t handler, void* user_arg);
\r
172 extern void pio_reset_all_it(void);
\r
175 * \brief Generate an interrupt on status change for a PIO or a group
\r
178 * \details The provided interrupt handler will be called with the
\r
179 * triggering pin as its parameter (enabling different pin instances
\r
180 * to share the same handler).
\r
182 * \param pin Pointer to a _pin instance.
\r
184 extern void pio_configure_it(const struct _pin * pin);
\r
188 * Enables the given interrupt source if it has been configured. The status
\r
189 * register of the corresponding PIO controller is cleared prior to enabling
\r
191 * \param pin Interrupt source to enable.
\r
193 extern void pio_enable_it(const struct _pin * pin);
\r
196 * Disables a given interrupt source, with no added side effects.
\r
198 * \param pin Interrupt source to disable.
\r
200 extern void pio_disable_it(const struct _pin * pin);
\r
205 #endif /* _PIO_H */
\r