From 48c2cc163064c782117e6051d280aa5160b6fb60 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Wed, 27 Apr 2011 01:55:39 +0200 Subject: [PATCH] IO pins ready --- firmware/src/edubrm.c | 34 ++++++++++++++++++---------------- firmware/src/ssp.c | 4 ++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/firmware/src/edubrm.c b/firmware/src/edubrm.c index 1bcbbf5..d7726ad 100644 --- a/firmware/src/edubrm.c +++ b/firmware/src/edubrm.c @@ -16,10 +16,9 @@ void GetInReport (uint8_t src[], uint32_t length) src[i*2+1] = (v>>8) & 0xff; } src[14] = 0; - src[14] |= (LPC_GPIO2->MASKED_ACCESS[1<<0] & (1<<0)); - src[14] |= (LPC_GPIO2->MASKED_ACCESS[1<<6] & (1<<6)) >> 5; + src[14] |= (LPC_GPIO2->MASKED_ACCESS[1<<6] & (1<<6)) >> 6; + src[14] |= (LPC_GPIO2->MASKED_ACCESS[1<<0] & (1<<0)) << 1; src[14] |= (LPC_GPIO2->MASKED_ACCESS[1<<7] & (1<<7)) >> 5; - } void SetOutReport (uint8_t dst[], uint32_t length) @@ -67,24 +66,23 @@ void SetOutReport (uint8_t dst[], uint32_t length) case 'P': states = dst[1]; PinDir(states); - // TODO: set pins to states (1 is INPUT, 0 is OUTPUT) - // pin1 is PIN_1 - // pin2 is PIN_2 - // pin3 is PIN_11 break; case 'o': which = dst[1] >> 1; state = dst[1] & 0x01; PinState(which, state); - // TODO: set output pins (which) to state (state) - // pin1 is PIN_1 - // pin2 is PIN_2 - // pin3 is PIN_11 break; } } void PinInit() { + // set pins function + LPC_IOCON->PIO2_0 &= ~0x07; + LPC_IOCON->PIO2_0 |= 0x00; + LPC_IOCON->PIO2_6 &= ~0x07; + LPC_IOCON->PIO2_6 |= 0x00; + LPC_IOCON->PIO2_7 &= ~0x07; + LPC_IOCON->PIO2_7 |= 0x00; PinDir(0); // all 3 pins are output 0 PinState(1, 0); PinState(2, 0); @@ -100,15 +98,15 @@ void EduInit() { void PinDir(uint16_t mask) { mask &= 7; mask ^= 7; - mask = ((mask & 4) << 5) | ((mask & 2) << 5) | (mask & 1); + mask = ((mask & 4) << 5) | ((mask & 2) >> 1) | ((mask & 1)<<6); LPC_GPIO2->DIR |= mask; mask |= ~(1<<0 | 1<<6 | 1<<7); LPC_GPIO2->DIR &= mask; - if (!(mask & 1)) + if (!(mask & (1<<6))) PinState(1, 0); - if (!(mask & (1<<6))) + if (!(mask & (1<<0))) PinState(2, 0); if (!(mask & (1<<7))) @@ -119,7 +117,12 @@ void PinDir(uint16_t mask) { void PinState(uint8_t which, uint8_t state) { state &= 1; which -= 1; - if (which > 0)which += 5; + switch (which) { + case 0: which = 6; break; + case 1: which = 0; break; + case 2: which = 7; break; + } + if (which < 0) return; LPC_GPIO2->MASKED_ACCESS[1<MASKED_ACCESS[1<IR = 0xff; LPC_GPIO1->DIR ^= 1<<6; LPC_TMR16B1->MR0 -= 100; - } //static uint8_t x = 0; diff --git a/firmware/src/ssp.c b/firmware/src/ssp.c index 02c6d32..41c9732 100644 --- a/firmware/src/ssp.c +++ b/firmware/src/ssp.c @@ -60,8 +60,8 @@ LPC_SSP->CPSR = 0x02; LPC_IOCON->PIO0_7 = 0x00; // D/C^ LPC_GPIO0->DIR |= 1 << 7; -LPC_IOCON->PIO2_0 = 0x00; // RES^ -LPC_GPIO2->DIR |= 1 << 0; +// LPC_IOCON->PIO2_0 = 0x00; // RES^ +// LPC_GPIO2->DIR |= 1 << 0; // SSP Enable with Master mode LPC_SSP->CR1 = (0x01<<1) | (0x00<<2);