Prof Greg Egan / Mbed 2 deprecated UAVXArm-GKE

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers NXP1768pins.c Source File

NXP1768pins.c

00001 // ===============================================================================================
00002 // =                              UAVXArm Quadrocopter Controller                                =
00003 // =                           Copyright (c) 2008 by Prof. Greg Egan                             =
00004 // =                 Original V3.15 Copyright (c) 2007 Ing. Wolfgang Mahringer                   =
00005 // =                           http://code.google.com/p/uavp-mods/                               =
00006 // ===============================================================================================
00007 
00008 //    This is part of UAVXArm.
00009 
00010 //    UAVXArm is free software: you can redistribute it and/or modify it under the terms of the GNU
00011 //    General Public License as published by the Free Software Foundation, either version 3 of the
00012 //    License, or (at your option) any later version.
00013 
00014 //    UAVXArm is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without
00015 //    even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 //    See the GNU General Public License for more details.
00017 
00018 //    You should have received a copy of the GNU General Public License along with this program.
00019 //    If not, see http://www.gnu.org/licenses/
00020 
00021 //    IO functions for NXP LPC1768.
00022 
00023 //    See also: http://bitbucket.org/jpc/lpc1768/
00024 
00025 //    Original Copyright (c) 2010 LoEE - Jakub Piotr Cłapa
00026 //    This program was released under the new BSD license.
00027 
00028 //    Rewritten for UAVXArm by G.K Egan 2011
00029 
00030 #ifdef USE_NXP_PIN_MAP // NOT COMMISSIONED
00031 
00032 #include "UAVXArm.h"
00033 
00034 boolean PinRead(uint8);
00035 void PinWrite(uint8, boolean);
00036 void PinSetOutput(uint8, boolean);
00037 
00038 //extern __inline__ __attribute__((always_inline))
00039 
00040 
00041 boolean PinRead(uint8 pn) {
00042 
00043     static uint8 p,m;
00044     p = pn >> 5;
00045     m = 1 << ( pn & 0x1f );
00046 
00047     switch ( p ) {
00048         case 0:
00049             return ( LPC_GPIO0->FIOPIN & m ) != 0;
00050         case 1:
00051             return ( LPC_GPIO1->FIOPIN & m ) != 0;
00052         case 2:
00053             return ( LPC_GPIO2->FIOPIN & m ) != 0;
00054         case 3:
00055             return ( LPC_GPIO3->FIOPIN & m ) != 0;
00056         case 4:
00057             return ( LPC_GPIO4->FIOPIN & m ) != 0;
00058         default:
00059             return (0);
00060     }
00061 } // PinRead
00062 
00063 void PinWrite(uint8 pn, boolean v) {
00064 
00065     static uint8 p, m;
00066     p = pn >> 5;
00067     m = 1 << ( pn & 0x1f );
00068 
00069     switch ( p ) {
00070         case 0:
00071             if ( v )
00072                 LPC_GPIO0->FIOSET = m;
00073             else
00074                 LPC_GPIO0->FIOCLR = m;
00075             break;
00076         case 1:
00077             if ( v )
00078                 LPC_GPIO1->FIOSET = m;
00079             else
00080                 LPC_GPIO1->FIOCLR = m;
00081             break;
00082         case 2:
00083             if ( v )
00084                 LPC_GPIO2->FIOSET = m;
00085             else
00086                 LPC_GPIO2->FIOCLR = m;
00087             break;
00088         case 3:
00089             if ( v )
00090                 LPC_GPIO3->FIOSET = m;
00091             else
00092                 LPC_GPIO3->FIOCLR = m;
00093             break;
00094         case 4:
00095             if ( v )
00096                 LPC_GPIO4->FIOSET = m;
00097             else
00098                 LPC_GPIO4->FIOCLR = m;
00099             break;
00100         default:
00101             break;
00102     }
00103 } // PinWrite
00104 
00105 void PinSetOutput(uint8 pn, boolean PinIsOutput) {
00106 
00107     static uint8 p,m;
00108     p = pn >> 5;
00109     m = 1 << ( pn & 0x1f );
00110 
00111     switch ( p ) {
00112         case 0:
00113             if ( PinIsOutput )
00114                 LPC_GPIO0->FIODIR |= m;
00115             else
00116                 LPC_GPIO0->FIODIR &= ~m;
00117             break;
00118         case 1:
00119             if ( PinIsOutput )
00120                 LPC_GPIO1->FIODIR |= m;
00121             else
00122                 LPC_GPIO1->FIODIR &= ~m;
00123             break;
00124         case 2:
00125             if ( PinIsOutput )
00126                 LPC_GPIO2->FIODIR |= m;
00127             else
00128                 LPC_GPIO2->FIODIR &= ~m;
00129             break;
00130         case 3:
00131             if ( PinIsOutput )
00132                 LPC_GPIO3->FIODIR |= m;
00133             else
00134                 LPC_GPIO3->FIODIR &= ~m;
00135             break;
00136         case 4:
00137             if ( PinIsOutput )
00138                 LPC_GPIO4->FIODIR |= m;
00139             else
00140                 LPC_GPIO4->FIODIR &= ~m;
00141             break;
00142         default:
00143             break;
00144     }
00145 
00146 } // PinSetOutput
00147  
00148 #endif // USE_NXP_PIN_MAP
00149 
00150