Satellite Observers Workbench. NOT yet complete, just published for forum posters to \"cherry pick\" pieces of code as requiered as an example.
gpio/gpio.c@0:0a841b89d614, 2010-10-11 (annotated)
- Committer:
- AjK
- Date:
- Mon Oct 11 10:34:55 2010 +0000
- Revision:
- 0:0a841b89d614
Totally Alpha quality as this project isn\t completed. Just publishing it as it answers many questions asked in the forums
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AjK | 0:0a841b89d614 | 1 | /**************************************************************************** |
AjK | 0:0a841b89d614 | 2 | * Copyright 2010 Andy Kirkham, Stellar Technologies Ltd |
AjK | 0:0a841b89d614 | 3 | * |
AjK | 0:0a841b89d614 | 4 | * This file is part of the Satellite Observers Workbench (SOWB). |
AjK | 0:0a841b89d614 | 5 | * |
AjK | 0:0a841b89d614 | 6 | * SOWB is free software: you can redistribute it and/or modify |
AjK | 0:0a841b89d614 | 7 | * it under the terms of the GNU General Public License as published by |
AjK | 0:0a841b89d614 | 8 | * the Free Software Foundation, either version 3 of the License, or |
AjK | 0:0a841b89d614 | 9 | * (at your option) any later version. |
AjK | 0:0a841b89d614 | 10 | * |
AjK | 0:0a841b89d614 | 11 | * SOWB is distributed in the hope that it will be useful, |
AjK | 0:0a841b89d614 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
AjK | 0:0a841b89d614 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
AjK | 0:0a841b89d614 | 14 | * GNU General Public License for more details. |
AjK | 0:0a841b89d614 | 15 | * |
AjK | 0:0a841b89d614 | 16 | * You should have received a copy of the GNU General Public License |
AjK | 0:0a841b89d614 | 17 | * along with SOWB. If not, see <http://www.gnu.org/licenses/>. |
AjK | 0:0a841b89d614 | 18 | * |
AjK | 0:0a841b89d614 | 19 | * $Id: main.cpp 5 2010-07-12 20:51:11Z ajk $ |
AjK | 0:0a841b89d614 | 20 | * |
AjK | 0:0a841b89d614 | 21 | ***************************************************************************/ |
AjK | 0:0a841b89d614 | 22 | |
AjK | 0:0a841b89d614 | 23 | #include "sowb.h" |
AjK | 0:0a841b89d614 | 24 | #include "debug.h" |
AjK | 0:0a841b89d614 | 25 | #include "gpio.h" |
AjK | 0:0a841b89d614 | 26 | |
AjK | 0:0a841b89d614 | 27 | |
AjK | 0:0a841b89d614 | 28 | /** gpio_init |
AjK | 0:0a841b89d614 | 29 | */ |
AjK | 0:0a841b89d614 | 30 | void gpio_init(void) { |
AjK | 0:0a841b89d614 | 31 | |
AjK | 0:0a841b89d614 | 32 | DEBUG_INIT_START; |
AjK | 0:0a841b89d614 | 33 | |
AjK | 0:0a841b89d614 | 34 | /* The following code could be condensed into a single set of |
AjK | 0:0a841b89d614 | 35 | and/or statements. However, for code clarity they are laid |
AjK | 0:0a841b89d614 | 36 | out on a "use case" way to see each pin being defined. Since |
AjK | 0:0a841b89d614 | 37 | this is "init" code and only called once at start-up, the |
AjK | 0:0a841b89d614 | 38 | extra overhead isn't worth the effort over cleaner to read |
AjK | 0:0a841b89d614 | 39 | code. */ |
AjK | 0:0a841b89d614 | 40 | |
AjK | 0:0a841b89d614 | 41 | /* The MAX7456 module uses p0.23 (p15) for it's chip select |
AjK | 0:0a841b89d614 | 42 | output. Define it's setup here and use the macros in gpio.h |
AjK | 0:0a841b89d614 | 43 | to assert, deassert or read the pin. */ |
AjK | 0:0a841b89d614 | 44 | //LPC_PINCON->PINSEL1 &= ~(3UL << 14); /* Function GPIO. */ |
AjK | 0:0a841b89d614 | 45 | //LPC_GPIO0->FIODIR |= (1UL << 23); /* P0.23 as output. */ |
AjK | 0:0a841b89d614 | 46 | |
AjK | 0:0a841b89d614 | 47 | /* The MAX7456 module uses p0.16 (p14) for it's chip select |
AjK | 0:0a841b89d614 | 48 | output. Define it's setup here and use the macros in gpio.h |
AjK | 0:0a841b89d614 | 49 | to assert, deassert or read the pin. */ |
AjK | 0:0a841b89d614 | 50 | //LPC_PINCON->PINSEL1 &= ~(3UL << 14); /* Function GPIO. */ |
AjK | 0:0a841b89d614 | 51 | //LPC_GPIO0->FIODIR |= (1UL << 16); /* P0.23 as output. */ |
AjK | 0:0a841b89d614 | 52 | |
AjK | 0:0a841b89d614 | 53 | /* The MAX7456 module uses p0.6 (p8) for it's chip select |
AjK | 0:0a841b89d614 | 54 | output. Define it's setup here and use the macros in gpio.h |
AjK | 0:0a841b89d614 | 55 | to assert, deassert or read the pin. */ |
AjK | 0:0a841b89d614 | 56 | LPC_PINCON->PINSEL0 &= ~(3UL << 12); /* Function GPIO. */ |
AjK | 0:0a841b89d614 | 57 | LPC_GPIO0->FIODIR |= (1UL << 6); /* P0.6 as output. */ |
AjK | 0:0a841b89d614 | 58 | |
AjK | 0:0a841b89d614 | 59 | |
AjK | 0:0a841b89d614 | 60 | /* The MAX7456 module uses p1.31 (p20) for it's reset output. |
AjK | 0:0a841b89d614 | 61 | Define it's setup here and use the macros in gpio.h to assert, |
AjK | 0:0a841b89d614 | 62 | deassert or read the pin. */ |
AjK | 0:0a841b89d614 | 63 | LPC_PINCON->PINSEL3 &= ~(3UL << 30); /* Function GPIO. */ |
AjK | 0:0a841b89d614 | 64 | LPC_GPIO1->FIODIR |= (1UL << 31); /* P1.31 as output. */ |
AjK | 0:0a841b89d614 | 65 | |
AjK | 0:0a841b89d614 | 66 | /* We use p0.25 (p17) for the SD Card detect. */ |
AjK | 0:0a841b89d614 | 67 | LPC_PINCON->PINSEL1 &= ~(3UL << 18); /* Function GPIO. */ |
AjK | 0:0a841b89d614 | 68 | LPC_GPIO0->FIODIR &= ~(1UL << 25); /* P0.25 as Input. */ |
AjK | 0:0a841b89d614 | 69 | |
AjK | 0:0a841b89d614 | 70 | /* We use p0.16 (p14) for the Flash device SSP0 CS signal. */ |
AjK | 0:0a841b89d614 | 71 | LPC_PINCON->PINSEL1 &= ~(3UL << 14); /* Function GPIO. */ |
AjK | 0:0a841b89d614 | 72 | LPC_GPIO0->FIODIR |= (1UL << 16); /* P0.23 as output. */ |
AjK | 0:0a841b89d614 | 73 | |
AjK | 0:0a841b89d614 | 74 | /* We use p0.24 (p16) for the 25AA02E48 device SSP0 CS signal. */ |
AjK | 0:0a841b89d614 | 75 | LPC_PINCON->PINSEL1 &= ~(3UL << 14); /* Function GPIO. */ |
AjK | 0:0a841b89d614 | 76 | LPC_GPIO0->FIODIR |= (1UL << 24); /* P0.24 as output. */ |
AjK | 0:0a841b89d614 | 77 | |
AjK | 0:0a841b89d614 | 78 | /* We use p1.30 (p19) for the MicroSD card device SSP0 CS signal. */ |
AjK | 0:0a841b89d614 | 79 | LPC_PINCON->PINSEL3 &= ~(3UL << 28); /* Function GPIO. */ |
AjK | 0:0a841b89d614 | 80 | LPC_GPIO1->FIODIR |= (1UL << 30); /* P1.30 as output. */ |
AjK | 0:0a841b89d614 | 81 | |
AjK | 0:0a841b89d614 | 82 | /* We use p2.5 (p21) for debugging. */ |
AjK | 0:0a841b89d614 | 83 | LPC_PINCON->PINSEL4 &= ~(3UL << 10); /* Function GPIO. */ |
AjK | 0:0a841b89d614 | 84 | LPC_GPIO2->FIODIR |= (1UL << 5); /* P2.5 as output. */ |
AjK | 0:0a841b89d614 | 85 | |
AjK | 0:0a841b89d614 | 86 | /* We use p2.4 (p22) for debugging. */ |
AjK | 0:0a841b89d614 | 87 | LPC_PINCON->PINSEL4 &= ~(3UL << 8); /* Function GPIO. */ |
AjK | 0:0a841b89d614 | 88 | LPC_GPIO2->FIODIR |= (1UL << 4); /* P2.4 as output. */ |
AjK | 0:0a841b89d614 | 89 | |
AjK | 0:0a841b89d614 | 90 | |
AjK | 0:0a841b89d614 | 91 | #ifdef MBED_LEDS |
AjK | 0:0a841b89d614 | 92 | /* The MBED has four useful little blue LEDs that can be used. |
AjK | 0:0a841b89d614 | 93 | Mbed examples use the DigitalOut led1(LED1) style. Mimic that |
AjK | 0:0a841b89d614 | 94 | using our system here. Here however, I will use shorthand ;) |
AjK | 0:0a841b89d614 | 95 | LED1 LED2 LED3 LED4 */ |
AjK | 0:0a841b89d614 | 96 | LPC_PINCON->PINSEL3 &= ( ~(3UL << 4) & ~(3UL << 8) & ~(3UL << 10) & ~(3UL << 14) ); |
AjK | 0:0a841b89d614 | 97 | LPC_GPIO1->FIODIR |= ( (1UL << 18) | (1UL << 20) | (1UL << 21) | (1UL << 23) ); |
AjK | 0:0a841b89d614 | 98 | #endif |
AjK | 0:0a841b89d614 | 99 | |
AjK | 0:0a841b89d614 | 100 | |
AjK | 0:0a841b89d614 | 101 | SSP0_CS_DEASSERT; |
AjK | 0:0a841b89d614 | 102 | FLASH_CS_DEASSERT; |
AjK | 0:0a841b89d614 | 103 | SDCARD_CS_DEASSERT; |
AjK | 0:0a841b89d614 | 104 | AA02E48_CS_DEASSERT; |
AjK | 0:0a841b89d614 | 105 | MAX7456_CS_DEASSERT; |
AjK | 0:0a841b89d614 | 106 | |
AjK | 0:0a841b89d614 | 107 | DEBUG_INIT_END; |
AjK | 0:0a841b89d614 | 108 | } |
AjK | 0:0a841b89d614 | 109 | |
AjK | 0:0a841b89d614 | 110 | /** gpio_process |
AjK | 0:0a841b89d614 | 111 | */ |
AjK | 0:0a841b89d614 | 112 | void gpio_process(void) { |
AjK | 0:0a841b89d614 | 113 | /* Does nothing, no house keeping required. */ |
AjK | 0:0a841b89d614 | 114 | } |
AjK | 0:0a841b89d614 | 115 |