From cbc941282074856fc6179761b70a0c9879b0b64d Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Tue, 11 Oct 2011 21:56:36 +0200 Subject: update firmware to @319 --- firmware/io.c | 402 +++++++++++++++++++--------------------------------------- 1 file changed, 128 insertions(+), 274 deletions(-) (limited to 'firmware/io.c') diff --git a/firmware/io.c b/firmware/io.c index 280f892..4227ec9 100644 --- a/firmware/io.c +++ b/firmware/io.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2007 Embedded Projects (http://www.embedded-projects.net) - * Author: Benedikt Sauter * All rights reserved. * * Short descripton of file: @@ -36,6 +36,8 @@ #include "common.h" #include "protocol.h" #include "io.h" +#include "pin.h" + void io_parser(char *buf) { @@ -77,6 +79,9 @@ void io_parser(char *buf) case CMD_IO_PIN_GET: io_get_pin_usb((uint8_t)buf[2]); break; + case CMD_IO_SET_STATUS_LED: + io_set_status_led_usb((uint8_t)buf[2]); + break; default: answer[0] = buf[0]; answer[1] = RSP_UNKOWN_CMD; @@ -87,12 +92,7 @@ void io_parser(char *buf) uint8_t io_init(uint8_t pin) { - if ((pin >= 1 && pin <= 19) || (pin >= 26 && pin <= 44)) - { - io_set_pin_direction_out(pin); - return RSP_OK; - } - return RSP_UNKOWN_PIN; + return io_set_pin_direction_out(pin); } void io_init_usb(uint8_t pin) @@ -120,16 +120,16 @@ void io_init_port_usb(uint8_t port) uint8_t io_set_port_direction_out(uint8_t port,uint8_t mask) { /* TODO - switch (port) - { - case 1: DDRB = mask; break; + switch (port) + { + case 1: DDRB = mask; break; case 2: DDRC = mask; break; // PC7 = /CS (output) - do we need to mask this ? - case 3: DDRD = mask; break; + case 3: DDRD = mask; break; case 4: DDRE = mask; break; // PE4 = INT4 (input) - do we need to mask this ? - case 5: DDRF = mask; break; - default: return RSP_UNKOWN_PIN; + case 5: DDRF = mask; break; + default: return RSP_UNKOWN_PIN; } - */ + */ return RSP_OK; } @@ -160,6 +160,7 @@ void io_set_port_direction_in_usb(uint8_t port, uint8_t mask) answer[2] = 0; CommandAnswer(3); } + void io_set_port_direction_tri_usb(uint8_t port, uint8_t mask) { answer[0] = CMD_IO_PORT_DIRECTION_TRI; @@ -171,131 +172,41 @@ void io_set_port_direction_tri_usb(uint8_t port, uint8_t mask) uint8_t io_set_pin_direction_out(uint8_t pin) { - if((pin >= 1 && pin <= 19) || (pin >=26 && pin <=44) ) - { - octopus.ports[pin] = PIN_OUT; - - switch(pin) - { - case 1: OX_DDR1 |=(1<= 1 && pin <= 19) || (pin >=26 && pin <=44) ) - { - octopus.ports[pin] = PIN_IN; - switch (pin) - { - case 1: OX_DDR1 &=~(1<= 1 && pin <= 19) || (pin >=26 && pin <=44) ) + if(io_set_pin_direction_out(pin) == RSP_OK && + io_set_pin(pin,1) == RSP_OK) { - octopus.ports[pin] = PIN_TRI; - io_set_pin_direction_out(pin); - io_set_pin(pin,1); - return RSP_OK; - } - else - { - return RSP_UNKOWN_PIN; + octopus.ports[pin] = PIN_TRI; + return RSP_OK; } + else + return RSP_UNKOWN_PIN; } @@ -324,55 +235,58 @@ void io_set_pin_direction_tri_usb(uint8_t pin) } - +//XXX uint8_t io_get_port (uint8_t port, uint8_t *pvalue) { - uint8_t value; - - *pvalue = 0; - switch (port) - { - case 1: value = PINB; break; - case 2: value = PINC; break; /* PC7 = /CS */ - case 3: value = PIND; break; - case 4: value = PINE; break; /* PE4 = INTR */ - case 5: value = PINF; break; - default: return RSP_UNKOWN_PORT; - } - *pvalue = value; - return RSP_OK; + uint8_t value; + + *pvalue = 0; + switch (port) + { + case 1: value = PINB; break; + case 2: value = PINC; break; /* PC7 = /CS */ + case 3: value = PIND; break; + case 4: value = PINE; break; /* PE4 = INTR */ + case 5: value = PINF; break; + default: return RSP_UNKOWN_PORT; + } + + *pvalue = value; + return RSP_OK; } -void io_get_port_usb (uint8_t port) -{ - uint8_t value; +void io_get_port_usb (uint8_t port) +{ + uint8_t value; - answer[0] = CMD_IO_PORT_GET; - answer[1] = (unsigned char)io_get_port (port, &value); - answer[2] = (unsigned char)value; - CommandAnswer(3); + answer[0] = CMD_IO_PORT_GET; + answer[1] = (unsigned char)io_get_port (port, &value); + answer[2] = (unsigned char)value; + answer[3] = 0; + CommandAnswer(4); } +// XXX uint8_t io_set_port(uint8_t port, uint8_t value) { - switch (port) - { - case 1: PORTB = value; break; - case 2: PORTC = value; break; // PC7 = /CS - case 3: PORTD = value; break; - case 4: PORTE = value; break; // PE4 = INTR - case 5: PORTF = value; break; - default: return RSP_UNKOWN_PIN; - } + switch (port) + { + case 1: PORTB = value; break; + case 2: PORTC = value; break; // PC7 = /CS + case 3: PORTD = value; break; + case 4: PORTE = value; break; // PE4 = INTR + case 5: PORTF = value; break; + default: return RSP_UNKOWN_PIN; + } return RSP_OK; } -void io_set_port_usb (uint8_t port, uint8_t value) -{ - answer[0] = CMD_IO_PORT_SET; - answer[1] = (unsigned char)io_set_port (port, value); - answer[2] = 0; - CommandAnswer(3); +void io_set_port_usb (uint8_t port, uint8_t value) +{ + answer[0] = CMD_IO_PORT_SET; + answer[1] = (unsigned char)io_set_port (port, value); + answer[2] = 0; + CommandAnswer(3); } @@ -387,59 +301,20 @@ void io_set_pin_usb(uint8_t pin, uint8_t value) uint8_t io_set_pin(uint8_t pin, uint8_t value) { - if(octopus.ports[pin] == PIN_OUT) - { - switch(pin) - { - case 1: if(value) OX_PORT1 |=(1<