From: Michel Pollet Date: Wed, 6 Jun 2012 07:44:48 +0000 (+0100) Subject: reprap: Split arduidiot_pins for generic use X-Git-Tag: v1.0~92 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=80ac5d5142c6658f4fa57b79e6b4cb87114df47d;p=sx%2Fsimavr.git reprap: Split arduidiot_pins for generic use Returns a simavr irq for an arduinio pin (only for m644 for now) Signed-off-by: Michel Pollet --- diff --git a/examples/board_reprap/src/reprap.c b/examples/board_reprap/src/reprap.c index fc81d7c..4bfc2e6 100644 --- a/examples/board_reprap/src/reprap.c +++ b/examples/board_reprap/src/reprap.c @@ -38,6 +38,7 @@ #include "button.h" #include "reprap.h" +#include "arduidiot_pins.h" #define __AVR_ATmega644__ #include "marlin/pins.h" @@ -60,73 +61,12 @@ reprap_t reprap; avr_t * avr = NULL; -typedef struct ardupin_t { - uint32_t port : 7, pin : 3, analog : 1, adc : 3, pwm : 1, ardupin; -} ardupin_t, *ardupin_p; - -ardupin_t arduidiot_644[32] = { - [ 0] = { .ardupin = 0, .port = 'B', .pin = 0 }, - [ 1] = { .ardupin = 1, .port = 'B', .pin = 1 }, - [ 2] = { .ardupin = 2, .port = 'B', .pin = 2 }, - [ 3] = { .ardupin = 3, .port = 'B', .pin = 3 }, - [ 4] = { .ardupin = 4, .port = 'B', .pin = 4 }, - [ 5] = { .ardupin = 5, .port = 'B', .pin = 5 }, - [ 6] = { .ardupin = 6, .port = 'B', .pin = 6 }, - [ 7] = { .ardupin = 7, .port = 'B', .pin = 7 }, - - [ 8] = { .ardupin = 8, .port = 'D', .pin = 0 }, - [ 9] = { .ardupin = 9, .port = 'D', .pin = 1 }, - [10] = { .ardupin = 10, .port = 'D', .pin = 2 }, - [11] = { .ardupin = 11, .port = 'D', .pin = 3 }, - [12] = { .ardupin = 12, .port = 'D', .pin = 4 }, - [13] = { .ardupin = 13, .port = 'D', .pin = 5 }, - [14] = { .ardupin = 14, .port = 'D', .pin = 6 }, - [15] = { .ardupin = 15, .port = 'D', .pin = 7 }, - - [16] = { .ardupin = 16, .port = 'C', .pin = 0 }, - [17] = { .ardupin = 17, .port = 'C', .pin = 1 }, - [18] = { .ardupin = 18, .port = 'C', .pin = 2 }, - [19] = { .ardupin = 19, .port = 'C', .pin = 3 }, - [20] = { .ardupin = 20, .port = 'C', .pin = 4 }, - [21] = { .ardupin = 21, .port = 'C', .pin = 5 }, - [22] = { .ardupin = 22, .port = 'C', .pin = 6 }, - [23] = { .ardupin = 23, .port = 'C', .pin = 7 }, - - [24] = { .ardupin = 24, .port = 'A', .pin = 7, .analog = 1, .adc = 7 }, - [25] = { .ardupin = 25, .port = 'A', .pin = 6, .analog = 1, .adc = 6 }, - [26] = { .ardupin = 26, .port = 'A', .pin = 5, .analog = 1, .adc = 5 }, - [27] = { .ardupin = 27, .port = 'A', .pin = 4, .analog = 1, .adc = 4 }, - [28] = { .ardupin = 28, .port = 'A', .pin = 3, .analog = 1, .adc = 3 }, - [29] = { .ardupin = 29, .port = 'A', .pin = 2, .analog = 1, .adc = 2 }, - [30] = { .ardupin = 30, .port = 'A', .pin = 1, .analog = 1, .adc = 1 }, - [31] = { .ardupin = 31, .port = 'A', .pin = 0, .analog = 1, .adc = 0 }, -}; - // gnu hackery to make sure the parameter is expanded #define _TERMISTOR_TABLE(num) \ temptable_##num #define TERMISTOR_TABLE(num) \ _TERMISTOR_TABLE(num) -struct avr_irq_t * -get_ardu_irq( - struct avr_t * avr, - int ardupin, - ardupin_t pins[]) -{ - if (pins[ardupin].ardupin != ardupin) { - printf("%s pin %d isn't correct in table\n", __func__, ardupin); - return NULL; - } - struct avr_irq_t * irq = avr_io_getirq(avr, - AVR_IOCTL_IOPORT_GETIRQ(pins[ardupin].port), pins[ardupin].pin); - if (!irq) { - printf("%s pin %d PORT%C%d not found\n", __func__, ardupin, pins[ardupin].port, pins[ardupin].pin); - return NULL; - } - return irq; -} - /* * called when the AVR change any of the pins on port B * so lets update our buffer diff --git a/examples/shared/arduidiot_pins.c b/examples/shared/arduidiot_pins.c new file mode 100644 index 0000000..7a4e2dc --- /dev/null +++ b/examples/shared/arduidiot_pins.c @@ -0,0 +1,83 @@ +/* + arduidiot_pins.c + + Copyright 2008-2012 Michel Pollet + + This file is part of simavr. + + simavr is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + simavr is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with simavr. If not, see . + */ + +#include +#include +#include "arduidiot_pins.h" +#include "sim_irq.h" +#include "avr_ioport.h" + +ardupin_t arduidiot_644[32] = { + [ 0] = { .ardupin = 0, .port = 'B', .pin = 0 }, + [ 1] = { .ardupin = 1, .port = 'B', .pin = 1 }, + [ 2] = { .ardupin = 2, .port = 'B', .pin = 2 }, + [ 3] = { .ardupin = 3, .port = 'B', .pin = 3 }, + [ 4] = { .ardupin = 4, .port = 'B', .pin = 4 }, + [ 5] = { .ardupin = 5, .port = 'B', .pin = 5 }, + [ 6] = { .ardupin = 6, .port = 'B', .pin = 6 }, + [ 7] = { .ardupin = 7, .port = 'B', .pin = 7 }, + + [ 8] = { .ardupin = 8, .port = 'D', .pin = 0 }, + [ 9] = { .ardupin = 9, .port = 'D', .pin = 1 }, + [10] = { .ardupin = 10, .port = 'D', .pin = 2 }, + [11] = { .ardupin = 11, .port = 'D', .pin = 3 }, + [12] = { .ardupin = 12, .port = 'D', .pin = 4 }, + [13] = { .ardupin = 13, .port = 'D', .pin = 5 }, + [14] = { .ardupin = 14, .port = 'D', .pin = 6 }, + [15] = { .ardupin = 15, .port = 'D', .pin = 7 }, + + [16] = { .ardupin = 16, .port = 'C', .pin = 0 }, + [17] = { .ardupin = 17, .port = 'C', .pin = 1 }, + [18] = { .ardupin = 18, .port = 'C', .pin = 2 }, + [19] = { .ardupin = 19, .port = 'C', .pin = 3 }, + [20] = { .ardupin = 20, .port = 'C', .pin = 4 }, + [21] = { .ardupin = 21, .port = 'C', .pin = 5 }, + [22] = { .ardupin = 22, .port = 'C', .pin = 6 }, + [23] = { .ardupin = 23, .port = 'C', .pin = 7 }, + + [24] = { .ardupin = 24, .port = 'A', .pin = 7, .analog = 1, .adc = 7 }, + [25] = { .ardupin = 25, .port = 'A', .pin = 6, .analog = 1, .adc = 6 }, + [26] = { .ardupin = 26, .port = 'A', .pin = 5, .analog = 1, .adc = 5 }, + [27] = { .ardupin = 27, .port = 'A', .pin = 4, .analog = 1, .adc = 4 }, + [28] = { .ardupin = 28, .port = 'A', .pin = 3, .analog = 1, .adc = 3 }, + [29] = { .ardupin = 29, .port = 'A', .pin = 2, .analog = 1, .adc = 2 }, + [30] = { .ardupin = 30, .port = 'A', .pin = 1, .analog = 1, .adc = 1 }, + [31] = { .ardupin = 31, .port = 'A', .pin = 0, .analog = 1, .adc = 0 }, +}; + +struct avr_irq_t * +get_ardu_irq( + struct avr_t * avr, + int ardupin, + ardupin_t pins[]) +{ + if (pins[ardupin].ardupin != ardupin) { + printf("%s pin %d isn't correct in table\n", __func__, ardupin); + return NULL; + } + struct avr_irq_t * irq = avr_io_getirq(avr, + AVR_IOCTL_IOPORT_GETIRQ(pins[ardupin].port), pins[ardupin].pin); + if (!irq) { + printf("%s pin %d PORT%C%d not found\n", __func__, ardupin, pins[ardupin].port, pins[ardupin].pin); + return NULL; + } + return irq; +} diff --git a/examples/shared/arduidiot_pins.h b/examples/shared/arduidiot_pins.h new file mode 100644 index 0000000..f9e5bb4 --- /dev/null +++ b/examples/shared/arduidiot_pins.h @@ -0,0 +1,44 @@ +/* + arduidiot_pins.h + + Copyright 2008-2012 Michel Pollet + + This file is part of simavr. + + simavr is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + simavr is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with simavr. If not, see . + */ + +/* + * This file helps maps arduino pins to the matching AVR pin + */ +#ifndef __ARDUIDIOT_PINS_H__ +#define __ARDUIDIOT_PINS_H__ + +#include + +typedef struct ardupin_t { + uint32_t port : 7, pin : 3, analog : 1, adc : 3, pwm : 1, ardupin; +} ardupin_t, *ardupin_p; + +struct avr_t; + +struct avr_irq_t * +get_ardu_irq( + struct avr_t * avr, + int ardupin, + ardupin_t pins[]); + +extern ardupin_t arduidiot_644[32]; + +#endif