Port Manipulation on Due

Can anyone help me with this?

I'm trying to Convert a library for the Due and I'm finding direct port manipulation a little confusing.

The AVR code is

#define TFT_CS_LOW  {DDRD |= 0x20;PORTD &=~ 0x20;}
#define TFT_CS_HIGH {DDRD |= 0x20;PORTD |=  0x20;}

which switches on and off a single port. In this case PortD bit5

I think the ARM code is something along the lines of,


Can anyone point me in the right direction?

That looks close, you may also need a:
REG_PIOD_OER = 0x20;

If you are only dealing with one bit SODR and CODR may be simpler than OWER and ODSR.

I assume you are referring to the ATMEL datasheet, 32.5.4 and 32.5.5 cover this subject.

I just posted a patch for the Adafruit TFTLCD library to get the due to work on Github, if you search for TFT Due it should pop up.

All this kind of work is done in the pin_magic.h file for that library. It may be a good example to work from, the port maniputlation isn’t too hard once you get your head wrapped around it. The last issue for me to figure out was that if you want to do input you need to enable the peripheral controller clock for each port. Output works with the clock either disabled or enabled.