Provides an API software interface to TIMER2 to control upto four stepper motors.
inc/SimpleStepperOutput.h@0:7393c52297ee, 2011-05-02 (annotated)
- Committer:
- AjK
- Date:
- Mon May 02 10:02:18 2011 +0000
- Revision:
- 0:7393c52297ee
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AjK | 0:7393c52297ee | 1 | /**************************************************************************** |
AjK | 0:7393c52297ee | 2 | * Product: LIB17 Open Source Library |
AjK | 0:7393c52297ee | 3 | * |
AjK | 0:7393c52297ee | 4 | * Steller Technologies Limited |
AjK | 0:7393c52297ee | 5 | * ---------------------------- |
AjK | 0:7393c52297ee | 6 | * |
AjK | 0:7393c52297ee | 7 | * Copyright (C) 2002-2011 Steller Technologies Limited. All rights reserved. |
AjK | 0:7393c52297ee | 8 | * |
AjK | 0:7393c52297ee | 9 | * This software may be distributed and modified under the terms of the GNU |
AjK | 0:7393c52297ee | 10 | * General Public License version 2 (GPL) as published by the Free Software |
AjK | 0:7393c52297ee | 11 | * Foundation and appearing in the file GPL.TXT included in the packaging of |
AjK | 0:7393c52297ee | 12 | * this file. Please note that GPL Section 2[b] requires that all works based |
AjK | 0:7393c52297ee | 13 | * on this software must also be made publicly available under the terms of |
AjK | 0:7393c52297ee | 14 | * the GPL ("Copyleft"). |
AjK | 0:7393c52297ee | 15 | * |
AjK | 0:7393c52297ee | 16 | * Alternatively, this software may be distributed and modified under the |
AjK | 0:7393c52297ee | 17 | * terms of Steller Technologies Limited commercial licenses, which expressly |
AjK | 0:7393c52297ee | 18 | * supersede the GPL and are specifically designed for licensees interested in |
AjK | 0:7393c52297ee | 19 | * retaining the proprietary status of their code. |
AjK | 0:7393c52297ee | 20 | * |
AjK | 0:7393c52297ee | 21 | * $Id:$ |
AjK | 0:7393c52297ee | 22 | * |
AjK | 0:7393c52297ee | 23 | ***************************************************************************/ |
AjK | 0:7393c52297ee | 24 | |
AjK | 0:7393c52297ee | 25 | /** |
AjK | 0:7393c52297ee | 26 | * @defgroup SimpleStepperOutput SimpleStepperOutput functions |
AjK | 0:7393c52297ee | 27 | */ |
AjK | 0:7393c52297ee | 28 | |
AjK | 0:7393c52297ee | 29 | #ifndef AJK_SIMPLESTEPPEROUTPUT_H |
AjK | 0:7393c52297ee | 30 | #define AJK_SIMPLESTEPPEROUTPUT_H |
AjK | 0:7393c52297ee | 31 | |
AjK | 0:7393c52297ee | 32 | #ifndef __ARMCC_VERSION |
AjK | 0:7393c52297ee | 33 | #include "SimpleStepperMbed.h" |
AjK | 0:7393c52297ee | 34 | #else |
AjK | 0:7393c52297ee | 35 | #include "mbed.h" |
AjK | 0:7393c52297ee | 36 | #endif |
AjK | 0:7393c52297ee | 37 | |
AjK | 0:7393c52297ee | 38 | |
AjK | 0:7393c52297ee | 39 | namespace AjK { |
AjK | 0:7393c52297ee | 40 | |
AjK | 0:7393c52297ee | 41 | /** SimpleStepperOutput - Adds pin output objects. |
AjK | 0:7393c52297ee | 42 | * |
AjK | 0:7393c52297ee | 43 | * The Mbed library supplies the DigitalIn and DigitalOut objects to allow you |
AjK | 0:7393c52297ee | 44 | * to specify ins and outs. |
AjK | 0:7393c52297ee | 45 | * |
AjK | 0:7393c52297ee | 46 | * SimpleStepperOutput allows library objects to implement pins without the requirement |
AjK | 0:7393c52297ee | 47 | * to link against the Mbed library. This increase portability when using |
AjK | 0:7393c52297ee | 48 | * alternate compilers (such as the Code Red GCC C++ compiler for LPCXpresso). |
AjK | 0:7393c52297ee | 49 | * |
AjK | 0:7393c52297ee | 50 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 51 | */ |
AjK | 0:7393c52297ee | 52 | class SimpleStepperOutput { |
AjK | 0:7393c52297ee | 53 | public: |
AjK | 0:7393c52297ee | 54 | enum Direction { |
AjK | 0:7393c52297ee | 55 | Out = 0 |
AjK | 0:7393c52297ee | 56 | , In |
AjK | 0:7393c52297ee | 57 | }; |
AjK | 0:7393c52297ee | 58 | |
AjK | 0:7393c52297ee | 59 | protected: |
AjK | 0:7393c52297ee | 60 | PinName pin; |
AjK | 0:7393c52297ee | 61 | uint32_t mask; |
AjK | 0:7393c52297ee | 62 | uint32_t fiodir; |
AjK | 0:7393c52297ee | 63 | uint32_t fiomask; |
AjK | 0:7393c52297ee | 64 | uint32_t fiopin; |
AjK | 0:7393c52297ee | 65 | uint32_t fioset; |
AjK | 0:7393c52297ee | 66 | uint32_t fioclr; |
AjK | 0:7393c52297ee | 67 | |
AjK | 0:7393c52297ee | 68 | inline void setpin(PinName p) { pin = p; } |
AjK | 0:7393c52297ee | 69 | inline void setmask(PinName p) { mask = (uint32_t)(1UL << ((uint32_t)p & 0x1F)); } |
AjK | 0:7393c52297ee | 70 | inline void setDir(PinName p) { fiodir = (uint32_t)(p & ~0x1F) + 0x00; } |
AjK | 0:7393c52297ee | 71 | inline void setMask(PinName p) { fiomask = (uint32_t)(p & ~0x1F) + 0x10; } |
AjK | 0:7393c52297ee | 72 | inline void setPin(PinName p) { fiopin = (uint32_t)(p & ~0x1F) + 0x14; } |
AjK | 0:7393c52297ee | 73 | inline void setSet(PinName p) { fioset = (uint32_t)(p & ~0x1F) + 0x18; } |
AjK | 0:7393c52297ee | 74 | inline void setClr(PinName p) { fioclr = (uint32_t)(p & ~0x1F) + 0x1C; } |
AjK | 0:7393c52297ee | 75 | |
AjK | 0:7393c52297ee | 76 | inline void pinUp() { *((volatile uint32_t *)fioset) = mask; } |
AjK | 0:7393c52297ee | 77 | inline void pinDn() { *((volatile uint32_t *)fioclr) = mask; } |
AjK | 0:7393c52297ee | 78 | inline uint32_t pinIs() { return *((volatile uint32_t *)(fiopin)) & mask; } |
AjK | 0:7393c52297ee | 79 | |
AjK | 0:7393c52297ee | 80 | public: |
AjK | 0:7393c52297ee | 81 | |
AjK | 0:7393c52297ee | 82 | /** Constructor |
AjK | 0:7393c52297ee | 83 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 84 | */ |
AjK | 0:7393c52297ee | 85 | SimpleStepperOutput(PinName p, Direction d = Out, PinMode m = PullDown) { init(p, d, m); }; |
AjK | 0:7393c52297ee | 86 | |
AjK | 0:7393c52297ee | 87 | /** write |
AjK | 0:7393c52297ee | 88 | * |
AjK | 0:7393c52297ee | 89 | * Writes a value to the pin. |
AjK | 0:7393c52297ee | 90 | * |
AjK | 0:7393c52297ee | 91 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 92 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 93 | * @param i Zero makes the pin 0v, non-zero makes the pin 1. |
AjK | 0:7393c52297ee | 94 | */ |
AjK | 0:7393c52297ee | 95 | void write(int i) { if (i!=0) { pinUp(); } else { pinDn(); } } |
AjK | 0:7393c52297ee | 96 | |
AjK | 0:7393c52297ee | 97 | /** read |
AjK | 0:7393c52297ee | 98 | * |
AjK | 0:7393c52297ee | 99 | * Reads the value on the pin. |
AjK | 0:7393c52297ee | 100 | * |
AjK | 0:7393c52297ee | 101 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 102 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 103 | * @return int 0v returns zero, otherwise returns 1. |
AjK | 0:7393c52297ee | 104 | */ |
AjK | 0:7393c52297ee | 105 | int read(void) { return pinIs() ? 1 : 0; }; |
AjK | 0:7393c52297ee | 106 | |
AjK | 0:7393c52297ee | 107 | /** output |
AjK | 0:7393c52297ee | 108 | * |
AjK | 0:7393c52297ee | 109 | * Setup the pin to be an output. |
AjK | 0:7393c52297ee | 110 | * |
AjK | 0:7393c52297ee | 111 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 112 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 113 | * @ingroup API |
AjK | 0:7393c52297ee | 114 | * @return int 0v returns zero, otherwise returns 1. |
AjK | 0:7393c52297ee | 115 | */ |
AjK | 0:7393c52297ee | 116 | void output(void) { *((volatile uint32_t *)fiodir) |= mask; } |
AjK | 0:7393c52297ee | 117 | |
AjK | 0:7393c52297ee | 118 | /** input |
AjK | 0:7393c52297ee | 119 | * |
AjK | 0:7393c52297ee | 120 | * Setup the pin to be an input. |
AjK | 0:7393c52297ee | 121 | * |
AjK | 0:7393c52297ee | 122 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 123 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 124 | * @return int 0v returns zero, otherwise returns 1. |
AjK | 0:7393c52297ee | 125 | */ |
AjK | 0:7393c52297ee | 126 | void input(void) { *((volatile uint32_t *)fiodir) &= ~mask; } |
AjK | 0:7393c52297ee | 127 | |
AjK | 0:7393c52297ee | 128 | /** getPin |
AjK | 0:7393c52297ee | 129 | * |
AjK | 0:7393c52297ee | 130 | * Get the PinName this object is operating on. |
AjK | 0:7393c52297ee | 131 | * |
AjK | 0:7393c52297ee | 132 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 133 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 134 | * @return int 0v returns zero, otherwise returns 1. |
AjK | 0:7393c52297ee | 135 | */ |
AjK | 0:7393c52297ee | 136 | PinName getPin(void) { return pin; } |
AjK | 0:7393c52297ee | 137 | |
AjK | 0:7393c52297ee | 138 | /** getDirection |
AjK | 0:7393c52297ee | 139 | * |
AjK | 0:7393c52297ee | 140 | * Get the operational direction this pin is setup for. |
AjK | 0:7393c52297ee | 141 | * |
AjK | 0:7393c52297ee | 142 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 143 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 144 | * @return int 0v returns zero, otherwise returns 1. |
AjK | 0:7393c52297ee | 145 | */ |
AjK | 0:7393c52297ee | 146 | int getDirection(void) { return *((volatile uint32_t *)fiomask) & mask ? 1 : 0; } |
AjK | 0:7393c52297ee | 147 | |
AjK | 0:7393c52297ee | 148 | /** operator int() |
AjK | 0:7393c52297ee | 149 | * |
AjK | 0:7393c52297ee | 150 | * Reads the value on the pin. |
AjK | 0:7393c52297ee | 151 | * |
AjK | 0:7393c52297ee | 152 | * @see read |
AjK | 0:7393c52297ee | 153 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 154 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 155 | * @return int 0v returns zero, otherwise returns 1. |
AjK | 0:7393c52297ee | 156 | */ |
AjK | 0:7393c52297ee | 157 | operator int() { return read(); } |
AjK | 0:7393c52297ee | 158 | |
AjK | 0:7393c52297ee | 159 | /** operator= |
AjK | 0:7393c52297ee | 160 | * |
AjK | 0:7393c52297ee | 161 | * Writes a value to the pin. |
AjK | 0:7393c52297ee | 162 | * |
AjK | 0:7393c52297ee | 163 | * @see write |
AjK | 0:7393c52297ee | 164 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 165 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 166 | */ |
AjK | 0:7393c52297ee | 167 | SimpleStepperOutput& operator= (int value) { write(value); return *this; } |
AjK | 0:7393c52297ee | 168 | |
AjK | 0:7393c52297ee | 169 | /** operator= |
AjK | 0:7393c52297ee | 170 | * |
AjK | 0:7393c52297ee | 171 | * Writes a value to the pin. |
AjK | 0:7393c52297ee | 172 | * |
AjK | 0:7393c52297ee | 173 | * @see write |
AjK | 0:7393c52297ee | 174 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 175 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 176 | */ |
AjK | 0:7393c52297ee | 177 | SimpleStepperOutput& operator= (SimpleStepperOutput& rhs) { write(rhs.read()); return *this; } |
AjK | 0:7393c52297ee | 178 | |
AjK | 0:7393c52297ee | 179 | /** getMask |
AjK | 0:7393c52297ee | 180 | * |
AjK | 0:7393c52297ee | 181 | * Get the mask value for this pin. |
AjK | 0:7393c52297ee | 182 | * |
AjK | 0:7393c52297ee | 183 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 184 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 185 | * @return uint32_t The mask value used by this pin. |
AjK | 0:7393c52297ee | 186 | */ |
AjK | 0:7393c52297ee | 187 | uint32_t getMask(void) { return mask; } |
AjK | 0:7393c52297ee | 188 | |
AjK | 0:7393c52297ee | 189 | /** getFiodir |
AjK | 0:7393c52297ee | 190 | * |
AjK | 0:7393c52297ee | 191 | * Get the FIODIR register for the port the pin is on. |
AjK | 0:7393c52297ee | 192 | * |
AjK | 0:7393c52297ee | 193 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 194 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 195 | * @return uint32_t The register value. |
AjK | 0:7393c52297ee | 196 | */ |
AjK | 0:7393c52297ee | 197 | uint32_t getFiodir(void) { return fiodir; } |
AjK | 0:7393c52297ee | 198 | |
AjK | 0:7393c52297ee | 199 | /** getFiomask |
AjK | 0:7393c52297ee | 200 | * |
AjK | 0:7393c52297ee | 201 | * Get the FIOMASK register for the port the pin is on. |
AjK | 0:7393c52297ee | 202 | * |
AjK | 0:7393c52297ee | 203 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 204 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 205 | * @return uint32_t The register value. |
AjK | 0:7393c52297ee | 206 | */ |
AjK | 0:7393c52297ee | 207 | uint32_t getFiomask(void) { return fiomask; } |
AjK | 0:7393c52297ee | 208 | |
AjK | 0:7393c52297ee | 209 | /** getFiopin |
AjK | 0:7393c52297ee | 210 | * |
AjK | 0:7393c52297ee | 211 | * Get the FIOPIN register for the port the pin is on. |
AjK | 0:7393c52297ee | 212 | * |
AjK | 0:7393c52297ee | 213 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 214 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 215 | * @return uint32_t The register value. |
AjK | 0:7393c52297ee | 216 | */ |
AjK | 0:7393c52297ee | 217 | uint32_t getFiopin(void) { return fiopin; } |
AjK | 0:7393c52297ee | 218 | |
AjK | 0:7393c52297ee | 219 | /** getFioset |
AjK | 0:7393c52297ee | 220 | * |
AjK | 0:7393c52297ee | 221 | * Get the FIOSET register for the port the pin is on. |
AjK | 0:7393c52297ee | 222 | * |
AjK | 0:7393c52297ee | 223 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 224 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 225 | * @return uint32_t The register value. |
AjK | 0:7393c52297ee | 226 | */ |
AjK | 0:7393c52297ee | 227 | uint32_t getFioset(void) { return fioset; } |
AjK | 0:7393c52297ee | 228 | |
AjK | 0:7393c52297ee | 229 | /** getFioclr |
AjK | 0:7393c52297ee | 230 | * |
AjK | 0:7393c52297ee | 231 | * Get the FIOCLR register for the port the pin is on. |
AjK | 0:7393c52297ee | 232 | * |
AjK | 0:7393c52297ee | 233 | * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio |
AjK | 0:7393c52297ee | 234 | * @ingroup SimpleStepperOutput |
AjK | 0:7393c52297ee | 235 | * @return uint32_t The register value. |
AjK | 0:7393c52297ee | 236 | */ |
AjK | 0:7393c52297ee | 237 | uint32_t getFioclr(void) { return fioclr; } |
AjK | 0:7393c52297ee | 238 | |
AjK | 0:7393c52297ee | 239 | |
AjK | 0:7393c52297ee | 240 | protected: |
AjK | 0:7393c52297ee | 241 | void init(PinName p, Direction d, PinMode m) |
AjK | 0:7393c52297ee | 242 | { |
AjK | 0:7393c52297ee | 243 | // We rely on the fact that by default the LPC1768 |
AjK | 0:7393c52297ee | 244 | // sets all pins to be GPIO. The user will change |
AjK | 0:7393c52297ee | 245 | // that if they need to. So we don't bother trying |
AjK | 0:7393c52297ee | 246 | // to setup PINSELx |
AjK | 0:7393c52297ee | 247 | |
AjK | 0:7393c52297ee | 248 | // psel(); // Not used, see above. |
AjK | 0:7393c52297ee | 249 | |
AjK | 0:7393c52297ee | 250 | setpin(p); |
AjK | 0:7393c52297ee | 251 | setmask(p); |
AjK | 0:7393c52297ee | 252 | setDir(p); |
AjK | 0:7393c52297ee | 253 | setMask(p); |
AjK | 0:7393c52297ee | 254 | setPin(p); |
AjK | 0:7393c52297ee | 255 | setSet(p); |
AjK | 0:7393c52297ee | 256 | setClr(p); |
AjK | 0:7393c52297ee | 257 | |
AjK | 0:7393c52297ee | 258 | if (d == Out) output(); |
AjK | 0:7393c52297ee | 259 | else mode( m ); |
AjK | 0:7393c52297ee | 260 | } |
AjK | 0:7393c52297ee | 261 | |
AjK | 0:7393c52297ee | 262 | protected: |
AjK | 0:7393c52297ee | 263 | void psel(void) |
AjK | 0:7393c52297ee | 264 | { |
AjK | 0:7393c52297ee | 265 | uint32_t ppsel, pumask; |
AjK | 0:7393c52297ee | 266 | |
AjK | 0:7393c52297ee | 267 | if (pin >= P0_0 && pin <= P0_15) ppsel = (uint32_t)(&LPC_PINCON->PINSEL0); |
AjK | 0:7393c52297ee | 268 | else if (pin >= P0_16 && pin <= P0_31) ppsel = (uint32_t)(&LPC_PINCON->PINSEL1); |
AjK | 0:7393c52297ee | 269 | else if (pin >= P1_0 && pin <= P1_15) ppsel = (uint32_t)(&LPC_PINCON->PINSEL2); |
AjK | 0:7393c52297ee | 270 | else if (pin >= P1_16 && pin <= P1_31) ppsel = (uint32_t)(&LPC_PINCON->PINSEL3); |
AjK | 0:7393c52297ee | 271 | else if (pin >= P2_0 && pin <= P2_15) ppsel = (uint32_t)(&LPC_PINCON->PINSEL4); |
AjK | 0:7393c52297ee | 272 | else if (pin >= P3_16 && pin <= P3_31) ppsel = (uint32_t)(&LPC_PINCON->PINSEL7); |
AjK | 0:7393c52297ee | 273 | else if (pin >= P4_16 && pin <= P4_31) ppsel = (uint32_t)(&LPC_PINCON->PINSEL9); |
AjK | 0:7393c52297ee | 274 | else return; |
AjK | 0:7393c52297ee | 275 | |
AjK | 0:7393c52297ee | 276 | pumask = ~(3UL << ((pin & 0x1F)>>1)); |
AjK | 0:7393c52297ee | 277 | *((volatile uint32_t *)ppsel) &= pumask; |
AjK | 0:7393c52297ee | 278 | } |
AjK | 0:7393c52297ee | 279 | |
AjK | 0:7393c52297ee | 280 | public: |
AjK | 0:7393c52297ee | 281 | void mode(PinMode m) |
AjK | 0:7393c52297ee | 282 | { |
AjK | 0:7393c52297ee | 283 | uint32_t ppmod, pumask; |
AjK | 0:7393c52297ee | 284 | |
AjK | 0:7393c52297ee | 285 | if (m == OpenDrain) { |
AjK | 0:7393c52297ee | 286 | openDrain(1); |
AjK | 0:7393c52297ee | 287 | } |
AjK | 0:7393c52297ee | 288 | else { |
AjK | 0:7393c52297ee | 289 | if (pin >= P0_0 && pin <= P0_15) { |
AjK | 0:7393c52297ee | 290 | ppmod = (uint32_t)(&LPC_PINCON->PINMODE0); |
AjK | 0:7393c52297ee | 291 | pumask = ((m & 0x3) << ( ((pin & 0x1F)-0)*2) ); |
AjK | 0:7393c52297ee | 292 | } |
AjK | 0:7393c52297ee | 293 | else if (pin >= P0_16 && pin <= P0_31) { |
AjK | 0:7393c52297ee | 294 | ppmod = (uint32_t)(&LPC_PINCON->PINMODE1); |
AjK | 0:7393c52297ee | 295 | pumask = ((m & 0x3) << ( ((pin & 0x1F)-16)*2) ); |
AjK | 0:7393c52297ee | 296 | } |
AjK | 0:7393c52297ee | 297 | else if (pin >= P1_0 && pin <= P1_15) { |
AjK | 0:7393c52297ee | 298 | ppmod = (uint32_t)(&LPC_PINCON->PINMODE2); |
AjK | 0:7393c52297ee | 299 | pumask = ((m & 0x3) << ( ((pin & 0x1F)-0)*2) ); |
AjK | 0:7393c52297ee | 300 | } |
AjK | 0:7393c52297ee | 301 | else if (pin >= P1_16 && pin <= P1_31) { |
AjK | 0:7393c52297ee | 302 | ppmod = (uint32_t)(&LPC_PINCON->PINMODE3); |
AjK | 0:7393c52297ee | 303 | pumask = ((m & 0x3) << ( ((pin & 0x1F)-16)*2) ); |
AjK | 0:7393c52297ee | 304 | } |
AjK | 0:7393c52297ee | 305 | else if (pin >= P2_0 && pin <= P2_15) { |
AjK | 0:7393c52297ee | 306 | ppmod = (uint32_t)(&LPC_PINCON->PINMODE4); |
AjK | 0:7393c52297ee | 307 | pumask = ((m & 0x3) << ( ((pin & 0x1F)-0)*2) ); |
AjK | 0:7393c52297ee | 308 | } |
AjK | 0:7393c52297ee | 309 | else if (pin >= P3_16 && pin <= P3_31) { |
AjK | 0:7393c52297ee | 310 | ppmod = (uint32_t)(&LPC_PINCON->PINMODE7); |
AjK | 0:7393c52297ee | 311 | pumask = ((m & 0x3) << ( ((pin & 0x1F)-16)*2) ); |
AjK | 0:7393c52297ee | 312 | } |
AjK | 0:7393c52297ee | 313 | else if (pin >= P4_16 && pin <= P4_31) { |
AjK | 0:7393c52297ee | 314 | ppmod = (uint32_t)(&LPC_PINCON->PINMODE9); |
AjK | 0:7393c52297ee | 315 | pumask = ((m & 0x3) << ( ((pin & 0x1F)-16)*2) ); |
AjK | 0:7393c52297ee | 316 | } |
AjK | 0:7393c52297ee | 317 | else return; |
AjK | 0:7393c52297ee | 318 | |
AjK | 0:7393c52297ee | 319 | *((volatile uint32_t *)ppmod) |= pumask; |
AjK | 0:7393c52297ee | 320 | } |
AjK | 0:7393c52297ee | 321 | } |
AjK | 0:7393c52297ee | 322 | |
AjK | 0:7393c52297ee | 323 | public: |
AjK | 0:7393c52297ee | 324 | void openDrain(int i = 1) |
AjK | 0:7393c52297ee | 325 | { |
AjK | 0:7393c52297ee | 326 | if (pin >= P0_0 && pin <= P0_31) { if (i) LPC_PINCON->PINMODE_OD0 |= mask; else LPC_PINCON->PINMODE_OD0 &= ~mask; } |
AjK | 0:7393c52297ee | 327 | else if (pin >= P1_0 && pin <= P1_31) { if (i) LPC_PINCON->PINMODE_OD1 |= mask; else LPC_PINCON->PINMODE_OD1 &= ~mask; } |
AjK | 0:7393c52297ee | 328 | else if (pin >= P2_0 && pin <= P2_31) { if (i) LPC_PINCON->PINMODE_OD2 |= mask; else LPC_PINCON->PINMODE_OD2 &= ~mask; } |
AjK | 0:7393c52297ee | 329 | else if (pin >= P3_16 && pin <= P3_31) { if (i) LPC_PINCON->PINMODE_OD3 |= mask; else LPC_PINCON->PINMODE_OD3 &= ~mask; } |
AjK | 0:7393c52297ee | 330 | else if (pin >= P4_16 && pin <= P4_31) { if (i) LPC_PINCON->PINMODE_OD4 |= mask; else LPC_PINCON->PINMODE_OD4 &= ~mask; } |
AjK | 0:7393c52297ee | 331 | } |
AjK | 0:7393c52297ee | 332 | |
AjK | 0:7393c52297ee | 333 | }; |
AjK | 0:7393c52297ee | 334 | |
AjK | 0:7393c52297ee | 335 | }; /* namespace AjK ends. */ |
AjK | 0:7393c52297ee | 336 | |
AjK | 0:7393c52297ee | 337 | using namespace AjK; |
AjK | 0:7393c52297ee | 338 | |
AjK | 0:7393c52297ee | 339 | #endif /* AJK_SIMPLESTEPPEROUTPUT_H */ |