user28961: I'm working with the capacitive sensor library currently and the author does not use digitalWrite(), but instead sets the output of a pin via functions changing the bitmasks of certain registers:
https://github.com/PaulStoffregen/CapacitiveSensor/blob/master/CapacitiveSensor.h#L39
I looked into the OneWire library description those functions come from, but I still can't see any advantage over simply using the standard way Arduino proposes.

user30376: With direct access to the pin registers, there is no need to call a function (since the digitalWrite function itself calls some functions), which is slower than manipulating the bits directly. You are also able to set the bits of several ports at the same time.
The manipulation of port registers is described in the PortManipulation chapter. It states:

Generally speaking, doing this sort of thing is not a good idea

However it could/should be used for time-sensitive applications. This is an interesting read on this topic.

user30005: 
Is there an advantage to set pinmodes via bitmask and register?

I can name a few:
1) speed - I benchmarked the arduino pin ops vs. direct register ops here;
2) size - the code size is considerably bigger with the arduino library;
3) portability - the bitmark approach is supported by any C-compiler;
4) convention - i'm used to the bitmask approach and wrote all of my libraries around it;
...
as i'm sure others have their reasons to use the bitmasks.

user10794: 
I still can't see any advantage over simply using the standard way Arduino proposes.

The standard functions are slower.

There is a very good reason that the Arduino "standard" functions digitalRead, digitalWrite and pinMode are slower than direct port manipulation: They take a variable as the pin number and value to set it to.
This means that the functions in question then have to do a table lookup to translate the pin number to a port number and a bit position. The advantage is you can write code like this:
for (int i = 0; i < 20; i++)
  {
  pinMode (i, OUTPUT);
  digitalWrite (i, LOW);
  }

That's quite handy!
However if you have timing-critical code, and you happen to know the pin number in advance, and it won't change, then you can use a library digitalWriteFast which can optimize that for you. The library cleverly detects if a particular call is given a variable or constant. If a constant then it does the faster port manipulation method (this can now be done at compile-time to find the port and bit number).
There seem to be a few different versions of this library around. The one I linked above fails if you don't pass a constant, others fall back to just doing a digitalWrite (etc).
Inside the library there is code like this:
if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \

In other words it uses a compiler directive to detect if the argument (P = pin, and V = value) are constants or not.

You can also, of course, do direct port manipulation but be warned that if you do then your code becomes pretty non-portable. Try going from an Atmega328 to an Atmega16U4 and the ports and bit positions will change.

Another library: https://code.google.com/archive/p/digitalwritefast/downloads

28961: <p>I'm working with the capacitive sensor library currently and the author does not use <code>digitalWrite()</code>, but instead sets the output of a pin via functions changing the bitmasks of certain registers:</p>

<p><a href="https://github.com/PaulStoffregen/CapacitiveSensor/blob/master/CapacitiveSensor.h#L39">https://github.com/PaulStoffregen/CapacitiveSensor/blob/master/CapacitiveSensor.h#L39</a></p>

<p>I looked into the <a href="http://playground.arduino.cc/Learning/OneWire">OneWire library description</a> those functions come from, but I still can't see any advantage over simply using the standard way Arduino proposes.</p>
 30376: <p>With direct access to the pin registers, there is no need to call a function (since the <code>digitalWrite</code> function itself calls some functions), which is slower than manipulating the bits directly. You are also able to set the bits of several ports at the same time.</p>

<p>The manipulation of port registers is described <a href="https://www.arduino.cc/en/Reference/PortManipulation" rel="nofollow noreferrer">in the PortManipulation chapter</a>. It states:</p>

<blockquote>
  <p>Generally speaking, doing this sort of thing is not a good idea</p>
</blockquote>

<p>However it could/should be used for time-sensitive applications. <a href="http://jeelabs.org/2010/01/06/pin-io-performance/" rel="nofollow noreferrer">This</a> is an interesting read on this topic.</p>
 30005: <blockquote>
  <p>Is there an advantage to set pinmodes via bitmask and register?</p>
</blockquote>

<p>I can name a few:</p>

<p>1) speed - I benchmarked the arduino pin ops vs. direct register ops <a href="https://dannyelectronics.wordpress.com/2016/05/01/the-price-of-avr-arduino/" rel="nofollow noreferrer">here</a>;</p>

<p>2) size - the code size is considerably bigger with the arduino library;</p>

<p>3) portability - the bitmark approach is supported by any C-compiler;</p>

<p>4) convention - i'm used to the bitmask approach and wrote all of my libraries around it;
...</p>

<p>as i'm sure others have their reasons to use the bitmasks.</p>
 10794: <blockquote>
  <p>I still can't see any advantage over simply using the standard way Arduino proposes.</p>
</blockquote>

<p>The standard functions are slower.</p>

<hr>

<p>There is a very good reason that the Arduino "standard" functions <code>digitalRead</code>, <code>digitalWrite</code> and <code>pinMode</code> are slower than direct port manipulation: They take <strong>a variable</strong> as the pin number and value to set it to.</p>

<p>This means that the functions in question then have to do a table lookup to translate the pin number to a port number and a bit position. The advantage is you can write code like this:</p>

<pre><code>for (int i = 0; i &lt; 20; i++)
  {
  pinMode (i, OUTPUT);
  digitalWrite (i, LOW);
  }
</code></pre>

<p>That's quite handy!</p>

<p>However if you have timing-critical code, and you happen to know the pin number in advance, and it won't change, then you can use a library <a href="https://github.com/NicksonYap/digitalWriteFast" rel="nofollow noreferrer">digitalWriteFast</a> which can optimize that for you. The library cleverly detects if a particular call is given a variable or constant. If a constant then it does the faster port manipulation method (this can now be done at compile-time to find the port and bit number).</p>

<p>There seem to be a few different versions of this library around. The one I linked above fails if you don't pass a constant, others fall back to just doing a <code>digitalWrite</code> (etc).</p>

<p>Inside the library there is code like this:</p>

<pre><code>if (__builtin_constant_p(P) &amp;&amp; __builtin_constant_p(V)) { \
</code></pre>

<p>In other words it uses a compiler directive to detect if the argument (P = pin, and V = value) are constants or not.</p>

<hr>

<p>You can also, of course, do direct port manipulation but be warned that if you do then your code becomes pretty non-portable. Try going from an Atmega328 to an Atmega16U4 and the ports and bit positions will change.</p>

<hr>

<p>Another library: <a href="https://code.google.com/archive/p/digitalwritefast/downloads" rel="nofollow noreferrer">https://code.google.com/archive/p/digitalwritefast/downloads</a></p>
