From ac2b17b1a04ea1212534c1e212584ee6647c4a6a Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Thu, 20 Aug 2015 13:43:09 +0100 Subject: [PATCH] arduidio: Simplified pin mapping Again... Signed-off-by: Michel Pollet --- examples/shared/arduidiot_pins.c | 250 ++++++++++++++++++------------- examples/shared/arduidiot_pins.h | 8 +- 2 files changed, 150 insertions(+), 108 deletions(-) diff --git a/examples/shared/arduidiot_pins.c b/examples/shared/arduidiot_pins.c index 7feb38c..db5899c 100644 --- a/examples/shared/arduidiot_pins.c +++ b/examples/shared/arduidiot_pins.c @@ -25,14 +25,31 @@ #include "sim_irq.h" #include "avr_ioport.h" -#define PIN(_n, _p, _b) \ - [ _n] = { .ardupin = _n, .port = _p, .pin = _b } - -#define ADC(_n, _p, _b) \ - [ _n] = { .ardupin = _n, .port = _p, .pin = _b, .analog = 1, .adc = _b } +#ifndef _CONCAT2 +#define _CONCAT2(_np, _nn) _np##_nn +#define _CONCAT(_np, _nn) _CONCAT2(_np,_nn) +#endif + +enum { + _AVR_PORTA = 0, + _AVR_PORTB, _AVR_PORTC, _AVR_PORTD, _AVR_PORTE, _AVR_PORTF, + _AVR_PORTG, _AVR_PORTH, _AVR_PORTI, _AVR_PORTJ, _AVR_PORTK, + _AVR_PORTL, +}; +#ifdef ARDUIDIO_FULL +#define PIN(_n, _p, _b) \ + [ _n] = { .ardupin = _n, .port = _CONCAT(_AVR_PORT, _p), .pin = _b } +#define ADCB(_n, _p, _b) \ + [ _n] = { .ardupin = _n, .port = _CONCAT(_AVR_PORT, _p), .pin = _b, .analog = 1, .adc = _b } #define ADCL(_n, _p, _b, _a) \ - [ _n] = { .ardupin = _n, .port = _p, .pin = _b, .analog = 1, .adc = _a } + [ _n] = { .ardupin = _n, .port = _CONCAT(_AVR_PORT, _p), .pin = _b, .analog = 1, .adc = _a } +#else +#define PIN(_n, _p, _b) \ + [ _n] = { .port = _CONCAT(_AVR_PORT, _p), .pin = _b } +#define ADCB(_n, _p, _b) PIN(_n, _p, _b) +#define ADCL(_n, _p, _b, _a) PIN(_n, _p, _b) +#endif #define PORT(_B, _P) \ PIN( _B + 0, _P, 0), \ @@ -44,109 +61,125 @@ PIN( _B + 6, _P, 6), \ PIN( _B + 7, _P, 7) +#define ADC(_B, _P) \ + ADCB( _B + 0, _P, 0), \ + ADCB( _B + 1, _P, 1), \ + ADCB( _B + 2, _P, 2), \ + ADCB( _B + 3, _P, 3), \ + ADCB( _B + 4, _P, 4), \ + ADCB( _B + 5, _P, 5), \ + ADCB( _B + 6, _P, 6), \ + ADCB( _B + 7, _P, 7) + +const ardupin_t arduidiot_168[] = { + PORT( 0, D), + PORT( 8, B), + ADC( 16, C), /* technically, 2 adc mode than there is.. */ +}; + const ardupin_t arduidiot_644[] = { - PORT( 0, 'B'), - PORT( 8, 'D'), - PORT(16, 'C'), + PORT( 0, B), + PORT( 8, D), + PORT(16, C), - ADC(24, 'A', 7), - ADC(25, 'A', 6), - ADC(26, 'A', 5), - ADC(27, 'A', 4), - ADC(28, 'A', 3), - ADC(29, 'A', 2), - ADC(30, 'A', 1), - ADC(31, 'A', 0), + ADCB(24, A, 7), + ADCB(25, A, 6), + ADCB(26, A, 5), + ADCB(27, A, 4), + ADCB(28, A, 3), + ADCB(29, A, 2), + ADCB(30, A, 1), + ADCB(31, A, 0), }; const ardupin_t arduidiot_2560[] = { - PIN( 0, 'E', 0), - PIN( 1, 'E', 1), - PIN( 2, 'E', 4), - PIN( 3, 'E', 5), - PIN( 4, 'G', 5), - PIN( 5, 'E', 3), - PIN( 6, 'H', 3), - PIN( 7, 'H', 4), - PIN( 8, 'H', 5), - PIN( 9, 'H', 6), - - PIN(10, 'B', 4), - PIN(11, 'B', 5), - PIN(12, 'B', 6), - PIN(13, 'B', 7), - PIN(14, 'J', 1), - PIN(15, 'J', 0), - PIN(16, 'H', 1), - PIN(17, 'H', 0), - PIN(18, 'D', 3), - PIN(19, 'D', 2), - - PIN(20, 'D', 1), - PIN(21, 'D', 0), - PORT(22, 'A'), - - PIN(30, 'C', 7), - PIN(31, 'C', 6), - PIN(32, 'C', 5), - PIN(33, 'C', 4), - PIN(34, 'C', 3), - PIN(35, 'C', 2), - PIN(36, 'C', 1), - PIN(37, 'C', 0), - PIN(38, 'D', 7), - PIN(39, 'G', 2), - - PIN(40, 'G', 1), - PIN(41, 'G', 0), - PIN(42, 'L', 7), - PIN(43, 'L', 6), - PIN(44, 'L', 5), - PIN(45, 'L', 4), - PIN(46, 'L', 3), - PIN(47, 'L', 2), - PIN(48, 'L', 1), - PIN(49, 'L', 0), - - PIN(50, 'B', 3), - PIN(51, 'B', 2), - PIN(52, 'B', 1), - PIN(53, 'B', 0), - ADC(54, 'F', 0), - ADC(55, 'F', 1), - ADC(56, 'F', 2), - ADC(57, 'F', 3), - ADC(58, 'F', 4), - ADC(59, 'F', 5), - - ADC(60, 'F', 6), - ADC(61, 'F', 7), - ADCL(62, 'K', 0, 8), - ADCL(63, 'K', 1, 9), - ADCL(64, 'K', 2, 10), - ADCL(65, 'K', 3, 11), - ADCL(66, 'K', 4, 12), - ADCL(67, 'K', 5, 13), - ADCL(68, 'K', 6, 14), - ADCL(69, 'K', 7, 15), - - PIN(70, 'G', 4), - PIN(71, 'G', 3), - PIN(72, 'J', 2), - PIN(73, 'J', 3), - PIN(74, 'J', 7), - PIN(75, 'J', 4), - PIN(76, 'J', 5), - PIN(77, 'J', 6), - PIN(78, 'E', 2), - PIN(79, 'E', 6), - - PIN(80, 'E', 7), - PIN(81, 'D', 4), - PIN(82, 'D', 5), - PIN(83, 'D', 6), - PIN(84, 'H', 2), - PIN(85, 'H', 7), + PIN( 0, E, 0), + PIN( 1, E, 1), + PIN( 2, E, 4), + PIN( 3, E, 5), + PIN( 4, G, 5), + PIN( 5, E, 3), + PIN( 6, H, 3), + PIN( 7, H, 4), + PIN( 8, H, 5), + PIN( 9, H, 6), + + PIN(10, B, 4), + PIN(11, B, 5), + PIN(12, B, 6), + PIN(13, B, 7), + PIN(14, J, 1), + PIN(15, J, 0), + PIN(16, H, 1), + PIN(17, H, 0), + PIN(18, D, 3), + PIN(19, D, 2), + + PIN(20, D, 1), + PIN(21, D, 0), + PORT(22, A), + + PIN(30, C, 7), + PIN(31, C, 6), + PIN(32, C, 5), + PIN(33, C, 4), + PIN(34, C, 3), + PIN(35, C, 2), + PIN(36, C, 1), + PIN(37, C, 0), + PIN(38, D, 7), + PIN(39, G, 2), + + PIN(40, G, 1), + PIN(41, G, 0), + PIN(42, L, 7), + PIN(43, L, 6), + PIN(44, L, 5), + PIN(45, L, 4), + PIN(46, L, 3), + PIN(47, L, 2), + PIN(48, L, 1), + PIN(49, L, 0), + + PIN(50, B, 3), + PIN(51, B, 2), + PIN(52, B, 1), + PIN(53, B, 0), + ADCB(54, F, 0), + ADCB(55, F, 1), + ADCB(56, F, 2), + ADCB(57, F, 3), + ADCB(58, F, 4), + ADCB(59, F, 5), + + ADCB(60, F, 6), + ADCB(61, F, 7), + ADCL(62, K, 0, 8), + ADCL(63, K, 1, 9), + ADCL(64, K, 2, 10), + ADCL(65, K, 3, 11), + ADCL(66, K, 4, 12), + ADCL(67, K, 5, 13), + ADCL(68, K, 6, 14), + ADCL(69, K, 7, 15), + + PIN(70, G, 4), + PIN(71, G, 3), + PIN(72, J, 2), + PIN(73, J, 3), + PIN(74, J, 7), + PIN(75, J, 4), + PIN(76, J, 5), + PIN(77, J, 6), + PIN(78, E, 2), + PIN(79, E, 6), + + PIN(80, E, 7), + PIN(81, D, 4), + PIN(82, D, 5), + PIN(83, D, 6), + PIN(84, H, 2), + PIN(85, H, 7), }; struct avr_irq_t * @@ -155,19 +188,22 @@ get_ardu_irq( uint8_t ardupin, const ardupin_t pins[]) { +#ifdef ARDUIDIO_FULL if (pins[ardupin].ardupin != ardupin) { printf("%s pin %d isn't correct in table\n", __func__, ardupin); return NULL; } +#endif struct avr_irq_t * irq = avr_io_getirq(avr, - AVR_IOCTL_IOPORT_GETIRQ(pins[ardupin].port), pins[ardupin].pin); + AVR_IOCTL_IOPORT_GETIRQ('A' + 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); + 'A' + pins[ardupin].port, pins[ardupin].pin); return NULL; } else printf("%s pin %2d is PORT%C%d\n", __func__, ardupin, - pins[ardupin].port, pins[ardupin].pin); + 'A' + pins[ardupin].port, pins[ardupin].pin); return irq; } diff --git a/examples/shared/arduidiot_pins.h b/examples/shared/arduidiot_pins.h index 87e6af6..07c1643 100644 --- a/examples/shared/arduidiot_pins.h +++ b/examples/shared/arduidiot_pins.h @@ -27,9 +27,15 @@ #include +#ifdef ARDUIDIO_FULL typedef struct ardupin_t { - uint32_t port : 7, pin : 3, analog : 1, adc : 4, pwm : 1, ardupin; + uint32_t port : 4, pin : 3, analog : 1, adc : 4, pwm : 1, ardupin; } ardupin_t, *ardupin_p; +#else +typedef struct ardupin_t { + uint8_t port : 4, pin : 3; +} ardupin_t, *ardupin_p; +#endif struct avr_t; -- 2.39.5