Quantcast
Channel: Reprap Forum - Firmware - Marlin
Viewing all articles
Browse latest Browse all 2831

fastio.h in Marlin (1 reply)

$
0
0
Hi,
I am going through the fast IO macros defined in Marlin's fastio.h file. I have largely understood the macros but I'm not able to grasp the below code.

#define _WRITE_NC(IO,V) do{ \
  if (V) SBI(DIO ## IO ## _WPORT, DIO ## IO ## _PIN); \
  else   CBI(DIO ## IO ## _WPORT, DIO ## IO ## _PIN); \
}while(0)

#define _WRITE_C(IO,V) do{ \
  uint8_t port_bits = DIO ## IO ## _WPORT;                  /* Get a mask from the current port bits */ \
  if (V) port_bits = ~port_bits;                            /* For setting bits, invert the mask */ \
  DIO ## IO ## _RPORT = port_bits & _BV(DIO ## IO ## _PIN); /* Atomically toggle the output port bits */ \
}while(0)


My understanding is _WRITE_NC sets the value 1 or 0 to the corresponding IO bit by accessing the PORT register.
_WRITE_C toggles the bits if V = 1. But, shouldn't the mask be taken from the PIN register and finally written to the PORT register. I think the code should be this:

#define _WRITE_C(IO,V) do{ \
  uint8_t port_bits = DIO ## IO ## _RPORT;                  /* Get a mask from the current port bits */ \
  if (V) port_bits = ~port_bits;                            /* For setting bits, invert the mask */ \
  DIO ## IO ## _WPORT = port_bits & _BV(DIO ## IO ## _PIN); /* Atomically toggle the output port bits */ \
}while(0)

Please help me out with this.

Viewing all articles
Browse latest Browse all 2831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>