You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/01/30 16:01:03 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a change in pull request #5369: cdcacm:support returning c_cflag & speed via termios

pkarashchenko commented on a change in pull request #5369:
URL: https://github.com/apache/incubator-nuttx/pull/5369#discussion_r795206657



##########
File path: drivers/usbdev/cdcacm.c
##########
@@ -2342,7 +2342,11 @@ static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
         termiosp->c_iflag = serdev->tc_iflag;
         termiosp->c_oflag = serdev->tc_oflag;
         termiosp->c_lflag = serdev->tc_lflag;
-        termiosp->c_cflag = CS8;
+        termiosp->c_cflag =
+            ((priv->linecoding.parity != CDC_PARITY_NONE) ? PARENB : 0) |

Review comment:
       Not sure about the logic, but as for me the readability of such code is bad. I suggest to split it into few lines:
   ```
   termiosp->c_cflag = CS8;
   
   if (priv->linecoding.parity != CDC_PARITY_NONE)
     {
       termiosp->c_cflag |= PARENB;
       if (priv->linecoding.parity == CDC_PARITY_ODD)
         {
           termiosp->c_cflag |= PARODD;
         }
     }
   
   if (priv->linecoding.stop == CDC_CHFMT_STOP2)
     {
       termiosp->c_cflag |= CSTOPB;
     }
   ``` 
   or a few ternary operators
   ```
   termiosp->c_cflag = CS8;
   termiosp->c_cflag |= (priv->linecoding.parity != CDC_PARITY_NONE) ? PARENB : 0;
   termiosp->c_cflag |= (priv->linecoding.parity == CDC_PARITY_ODD) ? PARODD : 0;
   termiosp->c_cflag |= (priv->linecoding.stop == CDC_CHFMT_STOP2) ? CSTOPB : 0;
   ```

##########
File path: drivers/usbdev/cdcacm.c
##########
@@ -2354,6 +2358,10 @@ static int cdcuart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
 
         termiosp->c_cflag |= (priv->iflow) ? CRTS_IFLOW : 0;

Review comment:
       ```suggestion
           termiosp->c_cflag |= priv->iflow ? CRTS_IFLOW : 0;
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org