Edit: This is in regards to Teensy 3.6, should of stated that first off. /Edit
I've seen the following example that allows you to output to 8 I/O pins at the same time. This is really going to help me in reading an 8x8 switch matrix.
I don't fully understand the syntax I've seen in examples though:
The way I understand it, this is creating a pointer for an 8 bit value named ptb_16_23. It then assigns this to the Port B output register + 2 (since Port B is really 32 bits and it's bits 16 through 23 that are physically accessible contiguously).
I may have the details of that completely wrong since I don't 100% understand pointers syntax ... but here are my questions.
1) Why is it volatile? I would think the memory address of the Port B register is static. Is it because the value at that address could be changed elsewhere? That wouldn't make sense to me though as I don't think you'd care, since your goal is to change the output values anyways and not using the value already there.
2) Why is it GPIOB_PTOR that gets written to instead of GPIOB_PDOR? As written, this looks like it would toggle bits 16 through 23 rather than setting them all to a logic '1'
My other question would be, how can this be adapted to read the contents of bits 0 through 7 of Port D as an input. Is it as simple as:
GPIOD_PDIR is 32 bits, but does casting it as 8 just truncate to the first 8 bits?
Thanks for any insight you can give me to help me understand how this works!
I've seen the following example that allows you to output to 8 I/O pins at the same time. This is really going to help me in reading an 8x8 switch matrix.
I don't fully understand the syntax I've seen in examples though:
Code:
volatile uint8_t* ptb_16_23 = (volatile uint8_t*) (uintptr_t(&GPIOB_PTOR) + 2);
*ptb_16_23 = 0xffu;
The way I understand it, this is creating a pointer for an 8 bit value named ptb_16_23. It then assigns this to the Port B output register + 2 (since Port B is really 32 bits and it's bits 16 through 23 that are physically accessible contiguously).
I may have the details of that completely wrong since I don't 100% understand pointers syntax ... but here are my questions.
1) Why is it volatile? I would think the memory address of the Port B register is static. Is it because the value at that address could be changed elsewhere? That wouldn't make sense to me though as I don't think you'd care, since your goal is to change the output values anyways and not using the value already there.
2) Why is it GPIOB_PTOR that gets written to instead of GPIOB_PDOR? As written, this looks like it would toggle bits 16 through 23 rather than setting them all to a logic '1'
My other question would be, how can this be adapted to read the contents of bits 0 through 7 of Port D as an input. Is it as simple as:
Code:
uint8_t SwitchInput = (uint8_t) GPIOD_PDIR;
GPIOD_PDIR is 32 bits, but does casting it as 8 just truncate to the first 8 bits?
Thanks for any insight you can give me to help me understand how this works!
Last edited: