user6936: TL;DR
With regards to the USB host library:

Which is the correct file to modify the Arduino pin used for the USB Host slave select (SS) line?


I would like to add USB host functionality, to a particular Arduino setup, whilst, also, being able to use an Ethernet/SD (or just SD) shield.
As both the Ethernet shield and USB Host shield use pin 10 to select the W5500 and MAX3421E respectively1, obviously I can not use a standard USB Host shield. However, I could employ one of the small form factor boards, such as the USB Host Shield 2.0 Arduino UNO MEGA ADK Compatible Google Android ADK which I found on eBay:

As this board is not in the usual shield "shape", one would not be constrained by which pin to connected to which MAX3421E input/output, in particular the chip select (SS) input. So, one could use a pin (or pins) that is not reserved by the Ethernet shield.
However, it does not appear to be possible to simply specify the "select pin" (i.e. the Arduino pin connected to the SS line) when using the USB Host shield library (or any of the pins used by the library), in setup().
Therefore, I wondered if it was possible to modify the library, so that the pin used to select the USB/MAX3421E could be changed, either by:

"Hardcoding" a different "select" pin number into a header file;
Adding an argument to the Init() method, or;
Adding a method to the USB class, such as Usb.DefineSelect().

The latter two options, I could work through, given the time. However, as a quick and dirty hack, where would I hardcode in a change from pin 10 to a pin of my choosing? Does anyone know? Has anyone had to do this?

Nitty-gritty
I have had a look through the library to see where pin 10 is defined as the chip select, and avrpins.h looked like a possible candidate for modification, although it would be rather "rude" (for want of a better word) and probably mess up the other boards.
usbhost.h seems a much better proposition. Looking at usbhost.h, the lines 88-91:
#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
#elif  defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi;

Looking at the statement
typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi;

the last argument appears to be the pin used for select. For the Uno (ATmega328P), in avrpins.h (line 535) Pb2 is P10 (pin 10), so I could substitute Pb2 for some other pin definition, i.e. Pd5 for P5 (pin 5) (line 529 in avrpins.h).
However, what I don't understand is that for the statement
typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;

which deals with the Mega (ATmega2560), in avrpins.h (line 512) Pb0is P53 (pin 53). As Pb4 is actually P10 (pin 10) (line 466), why is Pb0 en lieu of Pb4 used? That doesn't tie up with the fact that Pin 10 is used for both the Uno and Mega boards. It seems to suggest the pin 10 is used on the Uno and pin 53 is used on the Mega. Unless I have misinterpreted the typedef.

Footnote
1 For the USB host shield, from Arduino USB Host Shield

Arduino communicates with the MAX3421E using the SPI bus (through the
ICSP header). This is on digital pins 10, 11, 12, and 13 on the Uno
and pins 10, 50, 51, and 52 on the Mega. On both boards, pin 10 is
used to select the MAX3421E. Pins 7, 8 and 9 are used for GPX, INT and
RES pins.

The key piece of information here is that pin 10 is used by both the Uno and Mega boards.
For the Ethernet shield, from Arduino Ethernet Shield V2

Arduino communicates with both the W5500 and SD card using the SPI bus
(through the ICSP header). This is on digital pins 10, 11, 12, and 13
on the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10
is used to select the W5500 and pin 4 for the SD card. These pins
cannot be used for general I/O. On the Mega, the hardware SS pin, 53,
is not used to select either the W5500 or the SD card, but it must be
kept as an output or the SPI interface won't work.
Note that because the W5500 and SD card share the SPI bus, only one at
a time can be active. If you are using both peripherals in your
program, this should be taken care of by the corresponding libraries.
If you're not using one of the peripherals in your program, however,
you'll need to explicitly deselect it. To do this with the SD card,
set pin 4 as an output and write a high to it. For the W5500, set
digital pin 10 as a high output.

Here, yet again, the key piece of information here is that pin 10 is used by both the Uno and Mega boards to select the Ethernet.

user6936: In order to change the Arduino pin used to select the USB Host board, in order words, where the device's SS line is assigned to an Arduino pin (with the Arduino as the SPI Master and the USB host is the SPI slave), the line to change is at line 43 in UsbCore.h:
typedef MAX3421e<P10, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.x

So to use pin 5, for example, en lieu of pin 10, the line would become:
typedef MAX3421e<P5, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.x

The clue was in the comment on line 27 in UsbCore.h
/* shield pins. First parameter - SS pin, second parameter - INT pin */

With this suggested modification to the code, Pin 5 would go to the USB Host SS line and then there would be no conflict with the Ethernet board that uses Pin 10 for its SS line.

This issue, I have subsequently discovered, is covered by the USB Host Shield Hardware Manual, under the Interface modifications section. I guess I should have just read the manual first! RTFM...

Clarification of the issue
I must be honest that my question was somewhat confused. After having read the SPI library, it states that 

Note about Slave Select (SS) pin on AVR based boards
All AVR based boards have an SS pin that is useful when they act as a
  slave controlled by an external master. Since this library supports
  only master mode, this pin should be set always as OUTPUT otherwise
  the SPI interface could be put automatically into slave mode by
  hardware, rendering the library inoperative.
It is, however, possible to use any pin as the Slave Select (SS) for
  the devices. For example, the Arduino Ethernet shield uses pin 4 to
  control the SPI connection to the on-board SD card, and pin 10 to
  control the connection to the Ethernet controller.

With respect to the first paragraph, the Uno uses pin 10 and Mega uses pin 53 as the Arduino SS line - so that must be set as an output in order for the Arduino to be the Master. Are realising this as being my source of confusion, it became apparent that the typedef statements, in usbhost.h, were not where I should have been looking to change the device's Slave Select pin.
With respect to the second paragraph,  I want to use pin 5 (for example) to control the Slave Select (SS) for the USB Host device, instead of the default pin 10.

6936: <h3>TL;DR</h3>
<p>With regards to the <a href="https://github.com/felis/USB_Host_Shield_2.0" rel="nofollow noreferrer">USB host library</a>:</p>
<ul>
<li>Which is the correct file to modify the Arduino pin used for the USB Host slave select (SS) line?</li>
</ul>
<hr />
<p>I would like to add USB host functionality, to a particular Arduino setup, whilst, also, being able to use an Ethernet/SD (or just SD) shield.</p>
<p>As both the Ethernet shield and USB Host shield use pin 10 to select the W5500 and MAX3421E respectively<sup>1</sup>, obviously I can not use a standard USB Host shield. However, I could employ one of the small form factor boards, such as the <a href="http://www.ebay.co.uk/itm/182052269837" rel="nofollow noreferrer">USB Host Shield 2.0 Arduino UNO MEGA ADK Compatible Google Android ADK</a> which I found on eBay:</p>
<p><a href="https://i.stack.imgur.com/QVuZN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QVuZN.jpg" alt="USB Host shield" /></a></p>
<p>As this board is not in the usual shield &quot;shape&quot;, one would not be constrained by which pin to connected to which MAX3421E input/output, in particular the chip select (SS) input. So, one could use a pin (or pins) that is not reserved by the Ethernet shield.</p>
<p><em>However</em>, it does not appear to be possible to simply specify the &quot;select pin&quot; (i.e. the Arduino pin connected to the SS line) when using the <a href="https://github.com/felis/USB_Host_Shield_2.0" rel="nofollow noreferrer">USB Host shield library</a> (or any of the pins used by the library), in <code>setup()</code>.</p>
<p>Therefore, I wondered if it was possible to modify the library, so that the pin used to select the USB/MAX3421E could be changed, either by:</p>
<ul>
<li>&quot;Hardcoding&quot; a <em>different</em> &quot;select&quot; pin number into a header file;</li>
<li>Adding an argument to the <code>Init()</code> method, or;</li>
<li>Adding a method to the <code>USB</code> class, such as <code>Usb.DefineSelect()</code>.</li>
</ul>
<p>The latter two options, I could work through, given the time. However, as a quick and dirty hack, where would I hardcode in a change from pin 10 to a pin of my choosing? Does anyone know? Has anyone had to do this?</p>
<hr />
<h3>Nitty-gritty</h3>
<p>I have had a look through the library to see where pin 10 is defined as the chip select, and <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/avrpins.h" rel="nofollow noreferrer">avrpins.h</a> looked like a possible candidate for modification, although it would be rather &quot;rude&quot; (for want of a better word) and probably mess up the other boards.</p>
<p><a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/usbhost.h" rel="nofollow noreferrer">usbhost.h</a> seems a much better proposition. Looking at usbhost.h, the <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/usbhost.h#L88" rel="nofollow noreferrer">lines 88-91</a>:</p>
<pre><code>#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
typedef SPi&lt; Pb1, Pb2, Pb3, Pb0 &gt; spi;
#elif  defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
typedef SPi&lt; Pb5, Pb3, Pb4, Pb2 &gt; spi;
</code></pre>
<p>Looking at the statement</p>
<pre><code>typedef SPi&lt; Pb5, Pb3, Pb4, Pb2 &gt; spi;
</code></pre>
<p>the last argument appears to be the pin used for <em>select</em>. For the Uno (ATmega328P), in avrpins.h (<a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/avrpins.h#L535" rel="nofollow noreferrer">line 535</a>) <code>Pb2</code> is <code>P10</code> (pin 10), so I could substitute <code>Pb2</code> for some other pin definition, i.e. <code>Pd5</code> for <code>P5</code> (pin 5) (<a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/avrpins.h#L529" rel="nofollow noreferrer">line 529</a> in avrpins.h).</p>
<p>However, what I don't understand is that for the statement</p>
<pre><code>typedef SPi&lt; Pb1, Pb2, Pb3, Pb0 &gt; spi;
</code></pre>
<p>which deals with the Mega (ATmega2560), in avrpins.h (<a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/avrpins.h#L512" rel="nofollow noreferrer">line 512</a>) <code>Pb0</code>is <code>P53</code> (pin 53). As <code>Pb4</code> is actually <code>P10</code> (pin 10) (<a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/avrpins.h#L466" rel="nofollow noreferrer">line 466</a>), why is <code>Pb0</code> en lieu of <code>Pb4</code> used? That doesn't tie up with the fact that Pin 10 is used for both the Uno and Mega boards. It seems to suggest the pin 10 is used on the Uno and pin 53 is used on the Mega. Unless I have misinterpreted the <code>typedef</code>.</p>
<hr />
<h3>Footnote</h3>
<p><sup>1</sup> For the USB host shield, from <a href="https://www.arduino.cc/en/Main/ArduinoUSBHostShield" rel="nofollow noreferrer">Arduino USB Host Shield</a></p>
<blockquote>
<p>Arduino communicates with the MAX3421E using the SPI bus (through the
ICSP header). This is on digital pins 10, 11, 12, and 13 on the Uno
and pins 10, 50, 51, and 52 on the Mega. On both boards, pin 10 is
used to select the MAX3421E. Pins 7, 8 and 9 are used for GPX, INT and
RES pins.</p>
</blockquote>
<p>The key piece of information here is that pin 10 is used by <em>both</em> the Uno and Mega boards.</p>
<p>For the Ethernet shield, from <a href="https://www.arduino.cc/en/Main/ArduinoEthernetShield" rel="nofollow noreferrer">Arduino Ethernet Shield V2</a></p>
<blockquote>
<p>Arduino communicates with both the W5500 and SD card using the SPI bus
(through the ICSP header). This is on digital pins 10, 11, 12, and 13
on the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10
is used to select the W5500 and pin 4 for the SD card. These pins
cannot be used for general I/O. On the Mega, the hardware SS pin, 53,
is not used to select either the W5500 or the SD card, but it must be
kept as an output or the SPI interface won't work.</p>
<p>Note that because the W5500 and SD card share the SPI bus, only one at
a time can be active. If you are using both peripherals in your
program, this should be taken care of by the corresponding libraries.
If you're not using one of the peripherals in your program, however,
you'll need to explicitly deselect it. To do this with the SD card,
set pin 4 as an output and write a high to it. For the W5500, set
digital pin 10 as a high output.</p>
</blockquote>
<p>Here, yet again, the key piece of information here is that pin 10 is used by <em>both</em> the Uno and Mega boards to select the Ethernet.</p>
 6936: <p>In order to change the Arduino pin used to select the USB Host board, in order words, where the device's SS line is assigned to an Arduino pin (with the Arduino as the SPI Master and the USB host is the SPI slave), the line to change is at <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/UsbCore.h#L43" rel="nofollow noreferrer">line 43 in <code>UsbCore.h</code></a>:</p>

<pre><code>typedef MAX3421e&lt;P10, P9&gt; MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.x
</code></pre>

<p>So to use pin 5, for example, en lieu of pin 10, the line would become:</p>

<pre><code>typedef MAX3421e&lt;P5, P9&gt; MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.x
</code></pre>

<p>The clue was in the comment on <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/UsbCore.h#L27" rel="nofollow noreferrer">line 27 in <code>UsbCore.h</code></a></p>

<pre><code>/* shield pins. First parameter - SS pin, second parameter - INT pin */
</code></pre>

<p>With this suggested modification to the code, Pin 5 would go to the USB Host SS line and then there would be no conflict with the Ethernet board that uses Pin 10 for its SS line.</p>

<hr>

<p>This issue, I have subsequently discovered, is covered by the <a href="https://www.circuitsathome.com/usb-host-shield-hardware-manual/" rel="nofollow noreferrer">USB Host Shield Hardware Manual</a>, under the <strong>Interface modifications</strong> section. I guess I should have just read the manual first! RTFM...</p>

<hr>

<h3>Clarification of the issue</h3>

<p>I must be honest that my question was somewhat confused. After having read the <a href="https://www.arduino.cc/en/reference/SPI" rel="nofollow noreferrer">SPI library</a>, it states that </p>

<blockquote>
  <p><strong>Note about Slave Select (SS) pin on AVR based boards</strong></p>
  
  <p>All AVR based boards have an SS pin that is useful when they act as a
  slave controlled by an external master. Since this library supports
  only master mode, this pin should be set always as OUTPUT otherwise
  the SPI interface could be put automatically into slave mode by
  hardware, rendering the library inoperative.</p>
  
  <p>It is, however, possible to use any pin as the Slave Select (SS) for
  the devices. For example, the Arduino Ethernet shield uses pin 4 to
  control the SPI connection to the on-board SD card, and pin 10 to
  control the connection to the Ethernet controller.</p>
</blockquote>

<p>With respect to the first paragraph, the Uno uses pin 10 and Mega uses pin 53 as the Arduino SS line - so that must be set as an output in order for the Arduino to be the Master. Are realising this as being my source of confusion, it became apparent that the <code>typedef</code> statements, in <code>usbhost.h</code>, were <em>not</em> where I should have been looking to change the device's Slave Select pin.</p>

<p>With respect to the second paragraph,  I want to use pin 5 (for example) to control the Slave Select (SS) for the USB Host device, instead of the default pin 10.</p>
