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