Hello. Currently I try to implement a driver for a One Wire device to use it on KW41Z board and struggle to make a basic pin setup.
I see only two options of resolving the question inclined in the topic title: either there should be two configuration of a pin with input and output directions set respectively and the pin init function should be called each time I need to change the direction, or the port registers should be changed manually.
Can you say which way is better, and if the second one (with port registers) is more appropriate, can you help me with the port registers setup?
If you want to change pin direction efficiently it is not wise to perform the complete initialisation each time (it will work but is slower). It is easy to simply use the data direction register as follows:
GPIOx_PDDR |= (pins);
GPIOx_PDDR &= ~(pins);
Or bit band it to avoid the AND/OR operation.