Skip to content

Commit

Permalink
Update DesigningLibraries.md
Browse files Browse the repository at this point in the history
  • Loading branch information
SpenceKonde authored Mar 22, 2022
1 parent 021e894 commit 7f77598
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ProjectPlanning/DesigningLibraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ A closely related phenomonon is "platform creep" where a library originally desg
### How to get platform support wrong
These antipatterns are exremely common, and their consequences for the library are often disastrous.
#### Testing for specfic parts
So you added support for the ATmega4809 to your library, and you needed some #if macros to do so. The worst way to do this is `#ifdef __AVR_ATmega9-4809__` = because the same code you wrote will almost certainly work of a any membmer of the 0-series, and quite possiblly any AVR device released after 2016 (if your changes in this example only relateed to manipulating pins, this is the case). Often changing a test like that to `#if __AVR_ARCH__ > 100` will with a trivial change add support for dozens of parts instead of a singke part!
So you added support for the ATmega4809 to your library, and you needed some #if macros to do so. The worst way to do this is `#ifdef __AVR_ATmega9-4809__` = because the same code you wrote will almost certainly work of a any membmer of the 0-series, and quite possiblly any AVR device released after 2016 (if your changes in this example only relateed to manipulating pins, this is the case). Often changing a test like that to `#if __AVR_ARCH__ > 100` will with a trivial change add support for dozens of parts instead of a singke part! If the key factor was the fully memory-mapped flash, `__AVR_ARCH__ == 103` will catch all of those.
#### Making assumptions about the mapping of pin numbers to ports
Just say no. There are so many libraries that ae locked to a small number of parts because of adhoc handling of the nmbering of the pins on a specific board. Especoall in the case of official Ardino boards, where pin mapping design decisions tend towards maximum perversity, this is particularly tempting - and particlarly destructive.
Just say no. There are so many libraries that ae locked to a small number of parts because of adhoc handling of the nmbering of the pins on a specific board. Especoall in the case of official Ardino boards, where pin mapping design decisions tend towards maximum perversity, this is particularly tempting - and particlarly destructive. For example, on the 4809, the hardware screams out a particular mapping of ardiuino pin numbers to ports + bits; The Ardino designers ignored this and came up with an aggressively bad pin mapping instead.

Many parts have multiple pin mappings that may be used; FastLED ties itself to a specific pin mapping for every part, and that's why it' list of supported parts is so meagre.

0 comments on commit 7f77598

Please sign in to comment.