Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: include/Lib17_DIO.h
- Revision:
- 1:2f99edb5545c
- Parent:
- 0:127224866798
- Child:
- 2:b77d327026af
--- a/include/Lib17_DIO.h Mon Apr 11 15:05:27 2011 +0000 +++ b/include/Lib17_DIO.h Mon Apr 11 15:39:47 2011 +0000 @@ -18,8 +18,17 @@ * supersede the GPL and are specifically designed for licensees interested in * retaining the proprietary status of their code. * + * $Id:$ + * ***************************************************************************/ +/** + * @file Lib17_DIO.h + * @see http://cornflakes.wikidot.com/lib17:core + * @defgroup API The Lib17 Core API + * @defgroup Lib17_DIO Lib17_DIO functions + */ + #ifndef AJK_Lib17_DIO_H #define AJK_Lib17_DIO_H @@ -28,6 +37,15 @@ namespace AjK { +/** Lib17_DIO - Adds pin input/output objects. + * + * The Mbed library supplies the DigitalIn and DigitalOut objects to allow you + * to specify ins and outs. + * + * Lib17_DIO allows library objects to implement pins without the requirement + * to link against the Mbed library. This increase portability when using + * alternate compilers (such as the Code Red GCC C++ compiler for LPCXpresso). + */ class Lib17_DIO { public: enum Direction { @@ -60,23 +78,185 @@ Lib17_DIO(PinName p, Direction d = Out, PinMode m = PullDown) { init(p, d, m); }; + /** + * write + * + * Writes a value to the pin. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @param i Zero makes the pin 0v, non-zero makes the pin 1. + */ void write(int i) { if (i!=0) { pinUp(); } else { pinDn(); } } + + /** + * read + * + * Reads the value on the pin. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return int 0v returns zero, otherwise returns 1. + */ int read(void) { return pinIs() ? 1 : 0; }; + + /** + * output + * + * Setup the pin to be an output. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return int 0v returns zero, otherwise returns 1. + */ void output(void) { *((volatile uint32_t *)fiodir) |= mask; } + + /** + * input + * + * Setup the pin to be an input. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return int 0v returns zero, otherwise returns 1. + */ void input(void) { *((volatile uint32_t *)fiodir) &= ~mask; } + /** + * getPin + * + * Get the PinName this object is operating on. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return int 0v returns zero, otherwise returns 1. + */ PinName getPin(void) { return pin; } + + /** + * getDirection + * + * Get the operational direction this pin is setup for. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return int 0v returns zero, otherwise returns 1. + */ int getDirection(void) { return *((volatile uint32_t *)fiomask) & mask ? 1 : 0; } + /** + * operator int() + * + * Reads the value on the pin. + * + * @see read + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return int 0v returns zero, otherwise returns 1. + */ operator int() { return read(); } + + /** + * operator= + * + * Writes a value to the pin. + * + * @see write + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + */ Lib17_DIO& operator= (int value) { write(value); return *this; } + + /** + * operator= + * + * Writes a value to the pin. + * + * @see write + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + */ Lib17_DIO& operator= (Lib17_DIO& rhs) { write(rhs.read()); return *this; } + /** + * getMask + * + * Get the mask value for this pin. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return uint32_t The mask value used by this pin. + */ uint32_t getMask(void) { return mask; } + + /** + * getFiodir + * + * Get the FIODIR register for the port the pin is on. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return uint32_t The register value. + */ uint32_t getFiodir(void) { return fiodir; } + + /** + * getFiomask + * + * Get the FIOMASK register for the port the pin is on. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return uint32_t The register value. + */ uint32_t getFiomask(void) { return fiomask; } + + /** + * getFiopin + * + * Get the FIOPIN register for the port the pin is on. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return uint32_t The register value. + */ uint32_t getFiopin(void) { return fiopin; } + + /** + * getFioset + * + * Get the FIOSET register for the port the pin is on. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return uint32_t The register value. + */ uint32_t getFioset(void) { return fioset; } + + /** + * getFioclr + * + * Get the FIOCLR register for the port the pin is on. + * + * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio + * @ingroup Lib17_DIO + * @ingroup API + * @return uint32_t The register value. + */ uint32_t getFioclr(void) { return fioclr; }