Robobo
pio.h
1 /* ----------------------------------------------------------------------------
2  * SAM Software Package License
3  * ----------------------------------------------------------------------------
4  * Copyright (c) 2011-2012, Atmel Corporation
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following condition is met:
10  *
11  * - Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the disclaimer below.
13  *
14  * Atmel's name may not be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * ----------------------------------------------------------------------------
28  */
29 
30 #ifndef _PIO_
31 #define _PIO_
32 
33 /*
34  * Headers
35  */
36 
37 #include "../chip.h"
38 
39 #include <stdint.h>
40 
41 /*
42  * Global Definitions
43  */
44 typedef enum _EPioType
45 {
46  PIO_NOT_A_PIN, /* Not under control of a peripheral. */
47  PIO_PERIPH_A, /* The pin is controlled by the associated signal of peripheral A. */
48  PIO_PERIPH_B, /* The pin is controlled by the associated signal of peripheral B. */
49 #if (defined _SAM3S_) || (defined _SAM3S8_) || (defined _SAM3N_)
50  PIO_PERIPH_C, /* The pin is controlled by the associated signal of peripheral C. */
51  PIO_PERIPH_D, /* The pin is controlled by the associated signal of peripheral D. */
52 #endif /* (defined _SAM3S_) || (defined _SAM3S8_) || (defined _SAM3N_) */
53  PIO_INPUT, /* The pin is an input. */
54  PIO_OUTPUT_0, /* The pin is an output and has a default level of 0. */
55  PIO_OUTPUT_1 /* The pin is an output and has a default level of 1. */
56 } EPioType ;
57 
58 
59 /* Default pin configuration (no attribute). */
60 #define PIO_DEFAULT (0u << 0)
61 /* The internal pin pull-up is active. */
62 #define PIO_PULLUP (1u << 0)
63 /* The internal glitch filter is active. */
64 #define PIO_DEGLITCH (1u << 1)
65 /* The pin is open-drain. */
66 #define PIO_OPENDRAIN (1u << 2)
67 
68 /* The internal debouncing filter is active. */
69 #define PIO_DEBOUNCE (1u << 3)
70 
71 /* Enable additional interrupt modes. */
72 #define PIO_IT_AIME (1u << 4)
73 
74 /* Interrupt High Level/Rising Edge detection is active. */
75 #define PIO_IT_RE_OR_HL (1u << 5)
76 /* Interrupt Edge detection is active. */
77 #define PIO_IT_EDGE (1u << 6)
78 
79 /* Low level interrupt is active */
80 #define PIO_IT_LOW_LEVEL (0 | 0 | PIO_IT_AIME)
81 /* High level interrupt is active */
82 #define PIO_IT_HIGH_LEVEL (PIO_IT_RE_OR_HL | 0 | PIO_IT_AIME)
83 /* Falling edge interrupt is active */
84 #define PIO_IT_FALL_EDGE (0 | PIO_IT_EDGE | PIO_IT_AIME)
85 /* Rising edge interrupt is active */
86 #define PIO_IT_RISE_EDGE (PIO_IT_RE_OR_HL | PIO_IT_EDGE | PIO_IT_AIME)
87 
88 #ifdef __cplusplus
89  extern "C" {
90 #endif
91 
92 /*
93  * The #attribute# field is a bitmask that can either be set to PIO_DEFAULt,
94  * or combine (using bitwise OR '|') any number of the following constants:
95  * - PIO_PULLUP
96  * - PIO_DEGLITCH
97  * - PIO_DEBOUNCE
98  * - PIO_OPENDRAIN
99  * - PIO_IT_LOW_LEVEL
100  * - PIO_IT_HIGH_LEVEL
101  * - PIO_IT_FALL_EDGE
102  * - PIO_IT_RISE_EDGE
103  */
104 
105 
106 /*
107  * Global Functions
108  */
109 extern void PIO_DisableInterrupt( Pio* pPio, const uint32_t dwMask ) ;
110 extern void PIO_PullUp( Pio* pPio, const uint32_t dwMask, const uint32_t dwPullUpEnable ) ;
111 extern void PIO_SetDebounceFilter( Pio* pPio, const uint32_t dwMask, const uint32_t dwCuttOff ) ;
112 
113 extern void PIO_Set( Pio* pPio, const uint32_t dwMask ) ;
114 extern void PIO_Clear( Pio* pPio, const uint32_t dwMask ) ;
115 extern uint32_t PIO_Get( Pio* pPio, const EPioType dwType, const uint32_t dwMask ) ;
116 
117 extern void PIO_SetPeripheral( Pio* pPio, const EPioType dwType, const uint32_t dwMask ) ;
118 extern void PIO_SetInput( Pio* pPio, uint32_t dwMask, uint32_t dwAttribute ) ;
119 extern void PIO_SetOutput( Pio* pPio, uint32_t dwMask, uint32_t dwDefaultValue,
120  uint32_t dwMultiDriveEnable, uint32_t dwPullUpEnable ) ;
121 
122 extern uint32_t PIO_Configure( Pio* pPio, const EPioType dwType, const uint32_t dwMask, const uint32_t dwAttribute ) ;
123 
124 extern uint32_t PIO_GetOutputDataStatus( const Pio* pPio, const uint32_t dwMask ) ;
125 
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif /* #ifndef _PIO_ */
132 
void PIO_SetOutput(Pio *pPio, uint32_t dwMask, uint32_t dwDefaultValue, uint32_t dwMultiDriveEnable, uint32_t dwPullUpEnable)
Configures one or more pin(s) of a PIO controller as outputs, with the given default value...
Definition: pio.c:290
void PIO_SetInput(Pio *pPio, uint32_t dwMask, uint32_t dwAttribute)
Configures one or more pin(s) or a PIO controller as inputs. Optionally, the corresponding internal p...
Definition: pio.c:230
Pio hardware registers.
Definition: component_pio.h:41
void PIO_SetPeripheral(Pio *pPio, EPioType dwType, uint32_t dwMask)
Configures one pin of a PIO controller as being controlled by specific peripheral.
Definition: pio.c:153
uint32_t PIO_Get(Pio *pPio, const EPioType dwType, const uint32_t dwMask)
Returns 1 if one or more PIO of the given Pin instance currently have a high level; otherwise returns...
Definition: pio.c:111
uint32_t PIO_GetOutputDataStatus(const Pio *pPio, const uint32_t dwMask)
Returns 1 if one or more PIO of the given Pin are configured to output a high level (even if they are...
Definition: pio.c:372
uint32_t PIO_Configure(Pio *pPio, const EPioType dwType, const uint32_t dwMask, const uint32_t dwAttribute)
Definition: pio.c:325
void PIO_PullUp(Pio *pPio, const uint32_t dwMask, const uint32_t dwPullUpEnable)
Configures Pio pin internal pull-up.
Definition: pio.c:57
void PIO_SetDebounceFilter(Pio *pPio, const uint32_t dwMask, const uint32_t dwCuttOff)
Configures Glitch or Debouncing filter for input.
Definition: pio.c:76
void PIO_Clear(Pio *pPio, const uint32_t dwMask)
Sets a low output level on all the PIOs defined in the given Pin instance. This has no immediate effe...
Definition: pio.c:141
void PIO_DisableInterrupt(Pio *pPio, const uint32_t dwMask)
Configures Pio pin internal pull-up.
Definition: pio.c:44
void PIO_Set(Pio *pPio, const uint32_t dwMask)
Sets a high output level on all the PIOs defined in the given Pin instance. This has no immediate eff...
Definition: pio.c:95