KurtE
Senior Member+
For a while now, I have not liked having #ifdef tables defined in a different places in the cores or libraries to handle the differences in Arduino pins that are on each of the different boards. It made it more complicated when PJRC releases a new board and likewise if someone builds a custom board and tries to create
a variant to handle the differences.
What the code now does, is to do all of the mappings, using more or less the IMXRT Pin name instead... More specifically the
table is built up with pointers to the PinS port config register... And the tables look like:
The code that converts from pin number to the FlexIO number simply does:
And then looks through the table for a match to pin_mux and returns the index.
I also added a reverse mapping: when you can pass in the FlexIO pin number, and it will return the Teensy IO pin number
or 0xff if there is none...
The current code is in my branch: https://github.com/KurtE/FlexIO_t4/tree/teensy_indep
Note: I plan to merge this back into the main branch in the next week or so, unless there are some major issues uncovered.
As part of this: I added a new example sketch FlexIO_pin_list
Which prints out information about the different FlexIO objects.
Output for Micromod:
Teensy 4.1:
Teensy 4:
And the Dev Board 4:
a variant to handle the differences.
What the code now does, is to do all of the mappings, using more or less the IMXRT Pin name instead... More specifically the
table is built up with pointers to the PinS port config register... And the tables look like:
Code:
// FlexIO1
static const volatile uint32_t *flexio_t4_pins_flexio1[] PROGMEM = {
&IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_00, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_01, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_02, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_03,
&IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_04, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_05, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_06, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_07,
&IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_08, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_09, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_10, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_11,
&IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_26, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_27, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_28, &IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_29};
The code that converts from pin number to the FlexIO number simply does:
Code:
if (pin >= CORE_NUM_DIGITAL)
return 0xff; // pin is out of range.
volatile uint32_t *pin_mux = portConfigRegister(pin);
I also added a reverse mapping: when you can pass in the FlexIO pin number, and it will return the Teensy IO pin number
or 0xff if there is none...
The current code is in my branch: https://github.com/KurtE/FlexIO_t4/tree/teensy_indep
Note: I plan to merge this back into the main branch in the next week or so, unless there are some major issues uncovered.
As part of this: I added a new example sketch FlexIO_pin_list
Which prints out information about the different FlexIO objects.
Output for Micromod:
Code:
Teensy Micromod FlexIO pin list
FlexIO1:
Pin Order: Pin:flex
2:4 3:5 4:6 5:8 33:7
Flex Pin Order: flex:in
4:2 5:3 6:4 7:33 8:5
FlexIO2:
Pin Order: Pin:flex
6:10 7:17 8:16 9:11 10:0 11:2 12:1 13:3 32:12 40:4 41:5 42:6 43:7 44:8 45:9
Flex Pin Order: flex:in
0:10 1:12 2:11 3:13 4:40 5:41 6:42 7:43 8:44 9:45 10:6 11:9 12:32 16:8 17:7
FlexIO3:
Pin Order: Pin:flex
7:17 8:16 14:2 15:3 16:7 17:6 18:1 19:0 20:10 21:11 22:8 23:9 26:14 27:15
Flex Pin Order: flex:in
0:19 1:18 2:14 3:15 6:17 7:16 8:22 9:23 10:20 11:21 14:26 15:27 16:8 17:7
Flex IO Pin ranges:
FlexIO1: 4-8
FlexIO2: 0-12, 16-17
FlexIO3: 0-3, 6-11, 14-17
Bounds check test:
FlexIO1 IOToFlex(46):255 IOToFlex(255):255 FlexToIO(16):255 FlexToIO(255):255
FlexIO2 IOToFlex(46):255 IOToFlex(255):255 FlexToIO(32):255 FlexToIO(255):255
FlexIO3 IOToFlex(46):255 IOToFlex(255):255 FlexToIO(32):255 FlexToIO(255):255
Teensy 4.1:
Code:
Teensy 4.1 FlexIO pin list
FlexIO1:
Pin Order: Pin:flex
2:4 3:5 4:6 5:8 33:7 49:13 50:14 52:12 54:15
Flex Pin Order: flex:in
4:2 5:3 6:4 7:33 8:5 12:52 13:49 14:50 15:54
FlexIO2:
Pin Order: Pin:flex
6:10 7:17 8:16 9:11 10:0 11:2 12:1 13:3 32:12 34:29 35:28 36:18 37:19
Flex Pin Order: flex:in
0:10 1:12 2:11 3:13 10:6 11:9 12:32 16:8 17:7 18:36 19:37 28:35 29:34
FlexIO3:
Pin Order: Pin:flex
7:17 8:16 14:2 15:3 16:7 17:6 18:1 19:0 20:10 21:11 22:8 23:9 26:14 27:15 34:29 35:28 36:18 37:19 38:12 39:13 40:4 41:5
Flex Pin Order: flex:in
0:19 1:18 2:14 3:15 4:40 5:41 6:17 7:16 8:22 9:23 10:20 11:21 12:38 13:39 14:26 15:27 16:8 17:7 18:36 19:37 28:35 29:34
Flex IO Pin ranges:
FlexIO1: 4-8, 12-15
FlexIO2: 0-3, 10-12, 16-19, 28-29
FlexIO3: 0-19, 28-29
Bounds check test:
FlexIO1 IOToFlex(55):255 IOToFlex(255):255 FlexToIO(16):255 FlexToIO(255):255
FlexIO2 IOToFlex(55):255 IOToFlex(255):255 FlexToIO(32):255 FlexToIO(255):255
FlexIO3 IOToFlex(55):255 IOToFlex(255):255 FlexToIO(32):255 FlexToIO(255):255
Teensy 4:
Code:
Teensy 4 FlexIO pin list
FlexIO1:
Pin Order: Pin:flex
2:4 3:5 4:6 5:8 33:7
Flex Pin Order: flex:in
4:2 5:3 6:4 7:33 8:5
FlexIO2:
Pin Order: Pin:flex
6:10 7:17 8:16 9:11 10:0 11:2 12:1 13:3 32:12
Flex Pin Order: flex:in
0:10 1:12 2:11 3:13 10:6 11:9 12:32 16:8 17:7
FlexIO3:
Pin Order: Pin:flex
7:17 8:16 14:2 15:3 16:7 17:6 18:1 19:0 20:10 21:11 22:8 23:9 26:14 27:15
Flex Pin Order: flex:in
0:19 1:18 2:14 3:15 6:17 7:16 8:22 9:23 10:20 11:21 14:26 15:27 16:8 17:7
Flex IO Pin ranges:
FlexIO1: 4-8
FlexIO2: 0-3, 10-12, 16-17
FlexIO3: 0-3, 6-11, 14-17
Bounds check test:
FlexIO1 IOToFlex(40):255 IOToFlex(255):255 FlexToIO(16):255 FlexToIO(255):255
FlexIO2 IOToFlex(40):255 IOToFlex(255):255 FlexToIO(32):255 FlexToIO(255):255
FlexIO3 IOToFlex(40):255 IOToFlex(255):255 FlexToIO(32):255 FlexToIO(255):255
And the Dev Board 4:
Code:
Teensy Micromod FlexIO pin list
FlexIO1:
Pin Order: Pin:flex
2:4 3:5 4:6 5:8 33:7
Flex Pin Order: flex:in
4:2 5:3 6:4 7:33 8:5
FlexIO2:
Pin Order: Pin:flex
6:10 7:17 8:16 9:11 10:0 11:2 12:1 13:3 32:12 40:4 41:5 42:6 43:7 44:8 45:9 46:12 47:14 48:15 49:18 50:19 51:20 52:21 53:22 54:23 55:24 56:25 57:26 58:27 59:28 60:29 61:30 62:31 63:13
Flex Pin Order: flex:in
0:10 1:12 2:11 3:13 4:40 5:41 6:42 7:43 8:44 9:45 10:6 11:9 12:32 13:63 14:47 15:48 16:8 17:7 18:49 19:50 20:51 21:52 22:53 23:54 24:55 25:56 26:57 27:58 28:59 29:60 30:61 31:62
FlexIO3:
Pin Order: Pin:flex
7:17 8:16 14:2 15:3 16:7 17:6 18:1 19:0 20:10 21:11 22:8 23:9 26:14 27:15 49:18 50:19 51:20 52:21 53:22 54:23 55:24 56:25 57:26 58:27 59:28 60:29 61:30 62:31
Flex Pin Order: flex:in
0:19 1:18 2:14 3:15 6:17 7:16 8:22 9:23 10:20 11:21 14:26 15:27 16:8 17:7 18:49 19:50 20:51 21:52 22:53 23:54 24:55 25:56 26:57 27:58 28:59 29:60 30:61 31:62
Flex IO Pin ranges:
FlexIO1: 4-8
FlexIO2: 0-31
FlexIO3: 0-3, 6-11, 14-31
Bounds check test:
FlexIO1 IOToFlex(64):255 IOToFlex(255):255 FlexToIO(16):255 FlexToIO(255):255
FlexIO2 IOToFlex(64):255 IOToFlex(255):255 FlexToIO(32):255 FlexToIO(255):255
FlexIO3 IOToFlex(64):255 IOToFlex(255):255 FlexToIO(32):255 FlexToIO(255):255