You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's look first at what happens for `PIN('A', 3)`:
280
+
281
+
- `(bank) - 'A'` results in `'A' - 'A'` which will evaluate to `0`. As a 16 bit binary value this would be `0b00000000,00000000`.
282
+
- Next we bit shift this value left by 8 bits because we want to store `bank` in the upper byte of this 16 bit, or 2 byte value. In this case the result remains the same: `0b00000000,00000000`.
283
+
- Finally we bitwise OR the value above with `num`, in our case `3` which has a 16 bit binary representation of `0b00000000,00000011`. The result in binary is `0b00000000,00000011`.
284
+
285
+
Let's take a look at what happens for `PIN('G',11)`:
286
+
287
+
- `(bank) - 'G'` results in `'G' - 'A'` which will evaluate to `6`. As a 16 bit binary value this would be `0b00000000,00000110`.
288
+
- Next we bit shift this value left by 8 bits because we want to store `bank` in the upper byte of this 16 bit, or 2 byte value. This results in a binary value of: `0b00000110,00000000`.
289
+
- Finally we bitwise OR the value above with `num`, in our case `11` which has a 16 bit binary representation of `0b00000000,00001011`. The result of the bitwise OR in binary is `0b00000110,00001011` which is a combination of `bank` in the upper byte and `pin` in the lower byte.
290
+
275
291
Let's rewrite the `gpio_set_mode()` function to take our pin specification:
276
292
277
293
```c
@@ -1755,37 +1771,6 @@ print the result to the UART, and check for the expected output in the test.
1755
1771
1756
1772
Happy testing!
1757
1773
1758
-
## Appendix
1759
-
1760
-
In this section you will find some further explanations forselect pointsin this guide.
This functionis perhaps most easily understood through a worked example. Let's take pins `A3` and `G11` and see what is happening in the function above, step by step.
Let's look first at what happens for`PIN('A', 3)`:
1778
-
1779
-
- `(bank) - 'A'` results in`'A' - 'A'` which will evaluate to `0`. As a 16 bit binary value this would be `0b00000000,00000000`.
1780
-
- Next we bit shift this value left by 8 bits because we want to store `bank`in the upper byte of this 16 bit, or 2 byte value. In this case the result remains the same: `0b00000000,00000000`.
1781
-
- Finally we bitwise OR the value above with `num`, in our case `3` which has a 16 bit binary representation of `0b00000000,00000011`. The result in binary is `0b00000000,00000011`
1782
-
1783
-
Let's take a look at what happens for `PIN('G',11)`
1784
-
1785
-
- `(bank) - 'G'` results in `'G' - 'A'` which will evaluate to `6`. As a 16 bit binary value this would be `0b00000000,00000110`.
1786
-
- Next we bit shift this value left by 8 bits because we want to store `bank` in the upper byte of this 16 bit, or 2 byte value. This results in a binary value of: `0b00000110,00000000`.
1787
-
- Finally we bitwise OR the value above with `num`, in our case `11` which has a 16 bit binary representation of `0b00000000,00001011`. The result of the bitwise OR in binary is `0b00000110,00001011` which is a combination of `bank` in the upper byte and `pin` in the lower byte.
1788
-
1789
1774
## About me
1790
1775
1791
1776
I am Sergey Lyubka, an engineer and entrepreneur. I hold a MSc in Physics from
0 commit comments