Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////
- // SETTING A SINGLE PIN //
- ///////////////////////////
- // if "pin" is a compile time constant the if statement will be compiled out.
- if(pin>31) {
- // set this pin by writing the bit for the pin
- // to the high bank
- GPIO.out1_w1ts.val = (1 << ((pin - 32)&31));
- } else if(pin>-1) {
- // set the pin in the low bank
- GPIO.out_w1ts = (1 << (pin &31));
- }
- ///////////////////////////
- // CLEARING A SINGLE PIN //
- ///////////////////////////
- // if "pin" is a compile time constant the if statement will be compiled out.
- if(pin>31) {
- // clear this pin by writing the bit for the pin
- // to the high bank
- GPIO.out1_w1tc.val = (1 << ((pin - 32)&31));
- } else if(pin>-1) {
- // clear the pin in the low bank
- GPIO.out_w1tc = (1 << (pin &31));
- }
- /////////////////////////
- // SET/CLEAR MANY PINS //
- /////////////////////////
- To do this you simply combine the flags you want to set or clear into one 32 bit value
- GPIO.out_w1ts = (1<<pin_d0)|(1<<pin_d1)||(1<<pin_d6); // set pin_d0, pin_d1, and pin_d6
- // above assumes those pins are less than GPIO 32
- // And the same with clearing them
- /////////////////////////
- // NOTES //
- /////////////////////////
- // This can be too fast sometimes if you use it to control timing sensitive components.
- // I workaround that by setting/clearing multiple times instead of just once
- //
- // Even for a single pin this is much faster than digitalWrite for some reason
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement