Library designed as an interface to the mbed Pin Connect Block
PinConnectBlock.h@0:1b1cf3daf204, 2011-11-29 (annotated)
- Committer:
- Blaze513
- Date:
- Tue Nov 29 05:08:41 2011 +0000
- Revision:
- 0:1b1cf3daf204
- Child:
- 1:e9f239e90ef4
initial release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Blaze513 | 0:1b1cf3daf204 | 1 | #ifndef LPC1768PinConnectBlockLibrary |
Blaze513 | 0:1b1cf3daf204 | 2 | #define LPC1768PinConnectBlockLibrary |
Blaze513 | 0:1b1cf3daf204 | 3 | |
Blaze513 | 0:1b1cf3daf204 | 4 | #include "cmsis.h" |
Blaze513 | 0:1b1cf3daf204 | 5 | |
Blaze513 | 0:1b1cf3daf204 | 6 | #ifdef __cplusplus |
Blaze513 | 0:1b1cf3daf204 | 7 | extern "C" |
Blaze513 | 0:1b1cf3daf204 | 8 | { |
Blaze513 | 0:1b1cf3daf204 | 9 | #endif |
Blaze513 | 0:1b1cf3daf204 | 10 | |
Blaze513 | 0:1b1cf3daf204 | 11 | namespace PinConnectBlock |
Blaze513 | 0:1b1cf3daf204 | 12 | { |
Blaze513 | 0:1b1cf3daf204 | 13 | unsigned char ValidateInput( |
Blaze513 | 0:1b1cf3daf204 | 14 | unsigned char Port, unsigned char Pin, unsigned char Mode); |
Blaze513 | 0:1b1cf3daf204 | 15 | //This function accepts a Port number, Pin number, and Mode code for |
Blaze513 | 0:1b1cf3daf204 | 16 | //a pin that is to be connected to microcontroller hardware. It |
Blaze513 | 0:1b1cf3daf204 | 17 | //validates the input for future use as input to connection setting |
Blaze513 | 0:1b1cf3daf204 | 18 | //functions. It will check for the validity of the Port and Pin and |
Blaze513 | 0:1b1cf3daf204 | 19 | //the validity of the Function, Resistor, and Open Drain mode |
Blaze513 | 0:1b1cf3daf204 | 20 | //selections for a valid Port and Pin. The Mode codes are specified |
Blaze513 | 0:1b1cf3daf204 | 21 | //as follows: |
Blaze513 | 0:1b1cf3daf204 | 22 | // |
Blaze513 | 0:1b1cf3daf204 | 23 | //Bits 7:5 - Reserved ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 24 | //Bit 4 - OpenDrain Mode | See documentation for the mapping of | |
Blaze513 | 0:1b1cf3daf204 | 25 | //Bits 3:2 - Resistor Mode | mode code values to connections. The | |
Blaze513 | 0:1b1cf3daf204 | 26 | //Bits 1:0 - Function Mode | reserved bits must be 0. | |
Blaze513 | 0:1b1cf3daf204 | 27 | // ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 28 | //The return value is a code with flags to alert the user of errors in |
Blaze513 | 0:1b1cf3daf204 | 29 | //the input. The errors are specified as follows: |
Blaze513 | 0:1b1cf3daf204 | 30 | // |
Blaze513 | 0:1b1cf3daf204 | 31 | //Bits 7:6 - Reserved |
Blaze513 | 0:1b1cf3daf204 | 32 | //Bit 5 - OpenDrain Mode |
Blaze513 | 0:1b1cf3daf204 | 33 | //Bit 4 - Resistor Mode ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 34 | //Bit 3 - Function Mode | A value of 0 indicates there are no | |
Blaze513 | 0:1b1cf3daf204 | 35 | //Bit 2 - Mode | errors. A value of 1 indicates an | |
Blaze513 | 0:1b1cf3daf204 | 36 | //Bit 1 - Pin | error in the input corresponding with | |
Blaze513 | 0:1b1cf3daf204 | 37 | //Bit 0 - Port | that bit. Reserved bits will be 0. | |
Blaze513 | 0:1b1cf3daf204 | 38 | // ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 39 | void SetPinConnection( |
Blaze513 | 0:1b1cf3daf204 | 40 | unsigned char Port, unsigned char Pin, unsigned char Mode); |
Blaze513 | 0:1b1cf3daf204 | 41 | //This function accepts a Port number, Pin number, and Mode code and |
Blaze513 | 0:1b1cf3daf204 | 42 | //connects the selected Pin on the selected Port to the hardware |
Blaze513 | 0:1b1cf3daf204 | 43 | //specified in the Mode code. This function will not check for the |
Blaze513 | 0:1b1cf3daf204 | 44 | //validity of the input and will write to a reserved or unrelated |
Blaze513 | 0:1b1cf3daf204 | 45 | //sector if an invalid Port and Pin are specified. It will reject any |
Blaze513 | 0:1b1cf3daf204 | 46 | //portion of the Mode code that connects 1.0:1.17 to functions 10 or |
Blaze513 | 0:1b1cf3daf204 | 47 | //11, 0.27:0.30 to resistor hardware, or 0.27:0.28 to open drain mode |
Blaze513 | 0:1b1cf3daf204 | 48 | //hardware, and will complete any valid connections in the Mode code. |
Blaze513 | 0:1b1cf3daf204 | 49 | //The Mode codes are specified as follows: |
Blaze513 | 0:1b1cf3daf204 | 50 | // |
Blaze513 | 0:1b1cf3daf204 | 51 | //Bits 7:5 - Reserved ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 52 | //Bit 4 - OpenDrain Mode | See documentation for the mapping of | |
Blaze513 | 0:1b1cf3daf204 | 53 | //Bits 3:2 - Resistor Mode | mode code values to connections. The | |
Blaze513 | 0:1b1cf3daf204 | 54 | //Bits 1:0 - Function Mode | reserved bits must be 0. | |
Blaze513 | 0:1b1cf3daf204 | 55 | // ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 56 | unsigned char GetPinConnection( |
Blaze513 | 0:1b1cf3daf204 | 57 | unsigned char Port, unsigned char Pin); |
Blaze513 | 0:1b1cf3daf204 | 58 | //This function accepts a Port number and Pin number and returns a |
Blaze513 | 0:1b1cf3daf204 | 59 | //mode code that specifies the hardware connected to the selected Pin |
Blaze513 | 0:1b1cf3daf204 | 60 | //on the selected Port. This function will not check for the validity |
Blaze513 | 0:1b1cf3daf204 | 61 | //of the input and will return junk bits from a reserved or unrelated |
Blaze513 | 0:1b1cf3daf204 | 62 | //sector if an invalid Port and Pin are specified. The Mode codes are |
Blaze513 | 0:1b1cf3daf204 | 63 | //specified as follows: |
Blaze513 | 0:1b1cf3daf204 | 64 | // |
Blaze513 | 0:1b1cf3daf204 | 65 | //Bits 7:5 - Reserved ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 66 | //Bit 4 - OpenDrain Mode | See documentation for the mapping of | |
Blaze513 | 0:1b1cf3daf204 | 67 | //Bits 3:2 - Resistor Mode | mode code values to connections. The | |
Blaze513 | 0:1b1cf3daf204 | 68 | //Bits 1:0 - Function Mode | reserved bits must be 0. | |
Blaze513 | 0:1b1cf3daf204 | 69 | // ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 70 | void SetFunctionMode( |
Blaze513 | 0:1b1cf3daf204 | 71 | unsigned char Port, unsigned char Pin, unsigned char Mode); |
Blaze513 | 0:1b1cf3daf204 | 72 | //This function accepts a Port number, Pin number, and Mode code and |
Blaze513 | 0:1b1cf3daf204 | 73 | //connects the selected Pin on the selected Port to the function |
Blaze513 | 0:1b1cf3daf204 | 74 | //hardware specified in the Mode code. This function will not check |
Blaze513 | 0:1b1cf3daf204 | 75 | //for the validity of the input and will write to a reserved or |
Blaze513 | 0:1b1cf3daf204 | 76 | //non-function mode sector if an invalid Port and Pin are specified. |
Blaze513 | 0:1b1cf3daf204 | 77 | //Mode codes are specified as follows: |
Blaze513 | 0:1b1cf3daf204 | 78 | // ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 79 | // | See documentation for the mapping of | |
Blaze513 | 0:1b1cf3daf204 | 80 | //Bits 7:2 - Reserved | mode code values to connections. The | |
Blaze513 | 0:1b1cf3daf204 | 81 | //Bits 1:0 - Function Mode | reserved bits and modes must be 0. | |
Blaze513 | 0:1b1cf3daf204 | 82 | // ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 83 | unsigned char GetFunctionMode(unsigned char Port, unsigned char Pin); |
Blaze513 | 0:1b1cf3daf204 | 84 | //This function accepts a Port number and Pin number and returns a |
Blaze513 | 0:1b1cf3daf204 | 85 | //mode code that specifies the function hardware connected to the |
Blaze513 | 0:1b1cf3daf204 | 86 | //selected Pin on the selected Port. This function will not check for |
Blaze513 | 0:1b1cf3daf204 | 87 | //the validity of the input and will return junk bits from a reserved |
Blaze513 | 0:1b1cf3daf204 | 88 | //or non-function mode sector if an invalid Port and Pin are |
Blaze513 | 0:1b1cf3daf204 | 89 | //specified. The Mode codes are specified as follows: |
Blaze513 | 0:1b1cf3daf204 | 90 | // ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 91 | // | See documentation for the mapping of | |
Blaze513 | 0:1b1cf3daf204 | 92 | //Bits 2:7 - Reserved | mode code values to connections. The | |
Blaze513 | 0:1b1cf3daf204 | 93 | //Bits 1:0 - Function Mode | reserved bits will be 0. | |
Blaze513 | 0:1b1cf3daf204 | 94 | // ------------------------------------------ |
Blaze513 | 0:1b1cf3daf204 | 95 | void SetResistorMode( |
Blaze513 | 0:1b1cf3daf204 | 96 | unsigned char Port, unsigned char Pin, unsigned char Mode); |
Blaze513 | 0:1b1cf3daf204 | 97 | //This function accepts a Port number, Pin number, and Mode code and |
Blaze513 | 0:1b1cf3daf204 | 98 | //connects the selected Pin on the selected Port to the resistor |
Blaze513 | 0:1b1cf3daf204 | 99 | //hardware specified in the Mode code. This function will not check |
Blaze513 | 0:1b1cf3daf204 | 100 | //for the validity of the input and will write to a reserved or |
Blaze513 | 0:1b1cf3daf204 | 101 | //non-resistor mode sector if an invalid Port and Pin are specified. |
Blaze513 | 0:1b1cf3daf204 | 102 | //The Mode codes are ------------------------------------------- |
Blaze513 | 0:1b1cf3daf204 | 103 | //specified as follows: | Value - Connection | |
Blaze513 | 0:1b1cf3daf204 | 104 | // |-----------------------------------------| |
Blaze513 | 0:1b1cf3daf204 | 105 | // | 00 - Pull Up Resistor | |
Blaze513 | 0:1b1cf3daf204 | 106 | // | 01 - Repeater Mode | |
Blaze513 | 0:1b1cf3daf204 | 107 | //Bits 7:2 - Reserved | 10 - No Resistor | |
Blaze513 | 0:1b1cf3daf204 | 108 | //Bits 1:0 - Resistor Mode | 11 - Pull Down Resistor | |
Blaze513 | 0:1b1cf3daf204 | 109 | // ------------------------------------------- |
Blaze513 | 0:1b1cf3daf204 | 110 | unsigned char GetResistorMode(unsigned char Port, unsigned char Pin); |
Blaze513 | 0:1b1cf3daf204 | 111 | //This function accepts a Port number and Pin number and returns a |
Blaze513 | 0:1b1cf3daf204 | 112 | //mode code that specifies the resistor hardware connected to the |
Blaze513 | 0:1b1cf3daf204 | 113 | //selected Pin on the selected Port. This function will not check for |
Blaze513 | 0:1b1cf3daf204 | 114 | //the validity of the input and will return junk bits from a reserved |
Blaze513 | 0:1b1cf3daf204 | 115 | //or non-resistor mode sector if an invalid Port and Pin are |
Blaze513 | 0:1b1cf3daf204 | 116 | //specified. The Mode ------------------------------------------- |
Blaze513 | 0:1b1cf3daf204 | 117 | //codes are specified as | Value - Connection | |
Blaze513 | 0:1b1cf3daf204 | 118 | //follows: |-----------------------------------------| |
Blaze513 | 0:1b1cf3daf204 | 119 | // | 00 - Pull Up Resistor | |
Blaze513 | 0:1b1cf3daf204 | 120 | // | 01 - Repeater Mode | |
Blaze513 | 0:1b1cf3daf204 | 121 | //Bits 7:2 - Reserved | 10 - No Resistor | |
Blaze513 | 0:1b1cf3daf204 | 122 | //Bits 1:0 - Resistor Mode | 11 - Pull Down Resistor | |
Blaze513 | 0:1b1cf3daf204 | 123 | // ------------------------------------------- |
Blaze513 | 0:1b1cf3daf204 | 124 | void SetOpenDrainMode( |
Blaze513 | 0:1b1cf3daf204 | 125 | unsigned char Port, unsigned char Pin, bool Mode); |
Blaze513 | 0:1b1cf3daf204 | 126 | //This function accepts a Port number, Pin number, and Mode bit and |
Blaze513 | 0:1b1cf3daf204 | 127 | //connects or disconnects the open drain hardware for the selected Pin |
Blaze513 | 0:1b1cf3daf204 | 128 | //on the selected Port. A 0 will disconnect the open drain hardware, |
Blaze513 | 0:1b1cf3daf204 | 129 | //and a 1 will connect the open drain hardware. This function will |
Blaze513 | 0:1b1cf3daf204 | 130 | //not check for the validity of the input before making a connection, |
Blaze513 | 0:1b1cf3daf204 | 131 | //and will write to a reserved or non-open drain mode sector if an |
Blaze513 | 0:1b1cf3daf204 | 132 | //invalid Port and Pin are specified. |
Blaze513 | 0:1b1cf3daf204 | 133 | bool GetOpenDrainMode(unsigned char Port, unsigned char Pin); |
Blaze513 | 0:1b1cf3daf204 | 134 | //This function accepts a Port number and Pin number and returns a |
Blaze513 | 0:1b1cf3daf204 | 135 | //mode bit that specifies the resistor hardware that is connected to |
Blaze513 | 0:1b1cf3daf204 | 136 | //the selected Pin on the selected Port. A value of 0 indicates that |
Blaze513 | 0:1b1cf3daf204 | 137 | //the open drain hardware is disconnected, and a value of 1 indicates |
Blaze513 | 0:1b1cf3daf204 | 138 | //that the open drain hardware is connected. This function will not |
Blaze513 | 0:1b1cf3daf204 | 139 | //check for the validity of the input and will return a junk bit from |
Blaze513 | 0:1b1cf3daf204 | 140 | //a reserved or non-open drain sector if an invalid Port and Pin are |
Blaze513 | 0:1b1cf3daf204 | 141 | //specified. |
Blaze513 | 0:1b1cf3daf204 | 142 | void SetTraceMode(bool Mode); |
Blaze513 | 0:1b1cf3daf204 | 143 | //This function accepts a Mode bit and connects or disconnects the |
Blaze513 | 0:1b1cf3daf204 | 144 | //trace port hardware. A value of 0 will disconnect the trace port |
Blaze513 | 0:1b1cf3daf204 | 145 | //hardware, and a value of 1 will connect the trace port hardware. |
Blaze513 | 0:1b1cf3daf204 | 146 | //The trace port uses pins 2.2:2.6, and will override any function, |
Blaze513 | 0:1b1cf3daf204 | 147 | //resistor, or open drain hardware connected to these pins. |
Blaze513 | 0:1b1cf3daf204 | 148 | bool GetTraceMode(); |
Blaze513 | 0:1b1cf3daf204 | 149 | //This function returns a mode bit that specifies the current |
Blaze513 | 0:1b1cf3daf204 | 150 | //connection status of the trace port. A value of 0 indicates that |
Blaze513 | 0:1b1cf3daf204 | 151 | //the trace port is disconnected, and a value of 1 indicates that the |
Blaze513 | 0:1b1cf3daf204 | 152 | //trace port is connected. |
Blaze513 | 0:1b1cf3daf204 | 153 | void SetI2C0Mode(unsigned char Mode); |
Blaze513 | 0:1b1cf3daf204 | 154 | //This function accepts a Mode code and connects or disconnects |
Blaze513 | 0:1b1cf3daf204 | 155 | //specialized I2C hardware to the I2C0 bus on pins 0.27:0.28. The |
Blaze513 | 0:1b1cf3daf204 | 156 | //Mode codes are specified as follows: |
Blaze513 | 0:1b1cf3daf204 | 157 | // ----------------------------------------------- |
Blaze513 | 0:1b1cf3daf204 | 158 | //Bit 1: I2C Fast Mode | A value of 0 will disconnect the hard- | |
Blaze513 | 0:1b1cf3daf204 | 159 | //Bit 0: I2C Filter | ware, and a value of 1 will connect it. | |
Blaze513 | 0:1b1cf3daf204 | 160 | // ----------------------------------------------- |
Blaze513 | 0:1b1cf3daf204 | 161 | //For non-I2C of these pins, the Filter and Fast Mode hardware should |
Blaze513 | 0:1b1cf3daf204 | 162 | //be disconnected. For normal I2C use of these pins, the Filter |
Blaze513 | 0:1b1cf3daf204 | 163 | //hardware should be connected and the Fast Mode hardware should be |
Blaze513 | 0:1b1cf3daf204 | 164 | //disconnected. For I2C Fast Mode, the Filter hardware and Fast Mode |
Blaze513 | 0:1b1cf3daf204 | 165 | //hardware should both be connected. |
Blaze513 | 0:1b1cf3daf204 | 166 | unsigned char GetI2C0Mode(); |
Blaze513 | 0:1b1cf3daf204 | 167 | //This function returns a mode code that specifies the current |
Blaze513 | 0:1b1cf3daf204 | 168 | //connection status of the I2C0 bus with its specialized I2C hardware. |
Blaze513 | 0:1b1cf3daf204 | 169 | //The first two bits indicate the current hardware connection, and |
Blaze513 | 0:1b1cf3daf204 | 170 | //the next four bits indicate errors in the connection. The |
Blaze513 | 0:1b1cf3daf204 | 171 | //connection status of SCL pin 0.28 must mach that of SDA pin 0.27. |
Blaze513 | 0:1b1cf3daf204 | 172 | //If this is not the case, the bus will not function properly and the |
Blaze513 | 0:1b1cf3daf204 | 173 | //function will return an error code. The I2C Mode codes are |
Blaze513 | 0:1b1cf3daf204 | 174 | //specified as follows: ---------------------------- |
Blaze513 | 0:1b1cf3daf204 | 175 | // | A value of o indicates | |
Blaze513 | 0:1b1cf3daf204 | 176 | //Bit 5: Error - Only SCL Fast Mode is On | the hardware is discon- | |
Blaze513 | 0:1b1cf3daf204 | 177 | //Bit 4: Error - Only SDA Fast Mode is On | nected or the error is | |
Blaze513 | 0:1b1cf3daf204 | 178 | //Bit 3: Error - Only SCL Filter is On | not present. A value of | |
Blaze513 | 0:1b1cf3daf204 | 179 | //Bit 2: Error - Only SDA Filter is On | 1 indicates the hardware | |
Blaze513 | 0:1b1cf3daf204 | 180 | //Bit 1: I2C Fast Mode | is connected or the | |
Blaze513 | 0:1b1cf3daf204 | 181 | //Bit 0: I2C Filter | error is present. | |
Blaze513 | 0:1b1cf3daf204 | 182 | // ---------------------------- |
Blaze513 | 0:1b1cf3daf204 | 183 | } |
Blaze513 | 0:1b1cf3daf204 | 184 | |
Blaze513 | 0:1b1cf3daf204 | 185 | #ifdef __cplusplus |
Blaze513 | 0:1b1cf3daf204 | 186 | } |
Blaze513 | 0:1b1cf3daf204 | 187 | #endif |
Blaze513 | 0:1b1cf3daf204 | 188 | |
Blaze513 | 0:1b1cf3daf204 | 189 | #endif |