Welcome! Log In Create A New Profile

Advanced

fastio.h in Marlin

Posted by srinidhi 
fastio.h in Marlin
November 08, 2022 04:48AM
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.
Re: fastio.h in Marlin
November 08, 2022 05:36AM
See the PR that created this macro

[github.com]

Also please do not cross post. One post is enough!

Edited 1 time(s). Last edit at 11/08/2022 07:15AM by Dust.
Sorry, only registered users may post in this forum.

Click here to login