|
101 | 101 | # endif |
102 | 102 | #endif /* CONSOLE_UART */ |
103 | 103 |
|
104 | | -#ifdef CONFIG_ESP32S3_USBSERIAL |
| 104 | +#if defined(CONFIG_ESP32S3_USBSERIAL) && !defined(CONSOLE_DEV) |
105 | 105 | # define CONSOLE_DEV g_uart_usbserial |
| 106 | +#endif |
| 107 | + |
| 108 | +#ifdef CONFIG_ESP32S3_USBSERIAL |
106 | 109 | # define TTYACM0_DEV g_uart_usbserial |
107 | 110 | #endif |
108 | 111 |
|
@@ -855,194 +858,196 @@ static int esp32s3_ioctl(struct file *filep, int cmd, unsigned long arg) |
855 | 858 | { |
856 | 859 | #ifdef CONFIG_SERIAL_TIOCSERGSTRUCT |
857 | 860 |
|
858 | | - /* Get the internal driver data structure for debug purposes. */ |
859 | | - |
860 | | - case TIOCSERGSTRUCT: |
861 | | - { |
862 | | - struct esp32s3_uart_s *user = (struct esp32s3_uart_s *)arg; |
863 | | - if (user == NULL) |
864 | | - { |
865 | | - ret = -EINVAL; |
866 | | - } |
867 | | - else |
868 | | - { |
869 | | - memcpy(user, dev->priv, sizeof(struct esp32s3_uart_s)); |
870 | | - } |
871 | | - } |
872 | | - break; |
| 861 | + /* Get the internal driver data structure for debug purposes. */ |
| 862 | + |
| 863 | + case TIOCSERGSTRUCT: |
| 864 | + { |
| 865 | + struct esp32s3_uart_s *user = (struct esp32s3_uart_s *)arg; |
| 866 | + |
| 867 | + if (user == NULL) |
| 868 | + { |
| 869 | + ret = -EINVAL; |
| 870 | + } |
| 871 | + else |
| 872 | + { |
| 873 | + memcpy(user, dev->priv, sizeof(struct esp32s3_uart_s)); |
| 874 | + } |
| 875 | + } |
| 876 | + break; |
873 | 877 | #endif |
874 | 878 |
|
875 | 879 | #ifdef CONFIG_SERIAL_TERMIOS |
876 | 880 |
|
877 | | - /* Fill a termios structure with the required information. */ |
| 881 | + /* Fill a termios structure with the required information. */ |
| 882 | + |
| 883 | + case TCGETS: |
| 884 | + { |
| 885 | + struct termios *termiosp = (struct termios *)arg; |
| 886 | + struct esp32s3_uart_s *priv = (struct esp32s3_uart_s *)dev->priv; |
878 | 887 |
|
879 | | - case TCGETS: |
880 | | - { |
881 | | - struct termios *termiosp = (struct termios *)arg; |
882 | | - struct esp32s3_uart_s *priv = (struct esp32s3_uart_s *)dev->priv; |
883 | | - if (termiosp == NULL) |
884 | | - { |
885 | | - ret = -EINVAL; |
886 | | - break; |
887 | | - } |
| 888 | + if (termiosp == NULL) |
| 889 | + { |
| 890 | + ret = -EINVAL; |
| 891 | + break; |
| 892 | + } |
888 | 893 |
|
889 | | - /* Return parity (0 = no parity, 1 = odd parity, 2 = even parity). */ |
| 894 | + /* Return parity (0 = no, 1 = odd, 2 = even). */ |
890 | 895 |
|
891 | | - termiosp->c_cflag = (priv->parity != 0 ? PARENB : 0) | |
892 | | - (priv->parity == 1 ? PARODD : 0); |
| 896 | + termiosp->c_cflag = (priv->parity != 0 ? PARENB : 0) | |
| 897 | + (priv->parity == 1 ? PARODD : 0); |
893 | 898 |
|
894 | | - /* Return stop bits */ |
| 899 | + /* Return stop bits */ |
895 | 900 |
|
896 | | - termiosp->c_cflag |= priv->stop_b2 != 0 ? CSTOPB : 0; |
| 901 | + termiosp->c_cflag |= priv->stop_b2 != 0 ? CSTOPB : 0; |
897 | 902 |
|
898 | 903 | #ifdef CONFIG_SERIAL_OFLOWCONTROL |
899 | | - termiosp->c_cflag |= priv->oflow != 0 ? CCTS_OFLOW : 0; |
| 904 | + termiosp->c_cflag |= priv->oflow != 0 ? CCTS_OFLOW : 0; |
900 | 905 | #endif |
901 | 906 | #ifdef CONFIG_SERIAL_IFLOWCONTROL |
902 | | - termiosp->c_cflag |= priv->iflow != 0 ? CRTS_IFLOW : 0; |
| 907 | + termiosp->c_cflag |= priv->iflow != 0 ? CRTS_IFLOW : 0; |
903 | 908 | #endif |
904 | 909 |
|
905 | | - /* Set the baud rate in the termiosp using the |
906 | | - * cfsetispeed interface. |
907 | | - */ |
908 | | - |
909 | | - cfsetispeed(termiosp, priv->baud); |
910 | | - |
911 | | - /* Return number of bits. */ |
912 | | - |
913 | | - switch (priv->bits) |
914 | | - { |
915 | | - case 5: |
916 | | - termiosp->c_cflag |= CS5; |
917 | | - break; |
918 | | - |
919 | | - case 6: |
920 | | - termiosp->c_cflag |= CS6; |
921 | | - break; |
922 | | - |
923 | | - case 7: |
924 | | - termiosp->c_cflag |= CS7; |
925 | | - break; |
926 | | - |
927 | | - default: |
928 | | - case 8: |
929 | | - termiosp->c_cflag |= CS8; |
930 | | - break; |
931 | | - } |
932 | | - } |
933 | | - break; |
934 | | - |
935 | | - case TCSETS: |
936 | | - { |
937 | | - struct termios *termiosp = (struct termios *)arg; |
938 | | - struct esp32s3_uart_s *priv = (struct esp32s3_uart_s *)dev->priv; |
939 | | - uint32_t baud; |
940 | | - uint32_t current_int_sts; |
941 | | - uint8_t parity; |
942 | | - uint8_t bits; |
943 | | - uint8_t stop2; |
| 910 | + /* Set the baud rate in the termiosp using the |
| 911 | + * cfsetispeed interface. |
| 912 | + */ |
| 913 | + |
| 914 | + cfsetispeed(termiosp, priv->baud); |
| 915 | + |
| 916 | + /* Return number of bits. */ |
| 917 | + |
| 918 | + switch (priv->bits) |
| 919 | + { |
| 920 | + case 5: |
| 921 | + termiosp->c_cflag |= CS5; |
| 922 | + break; |
| 923 | + |
| 924 | + case 6: |
| 925 | + termiosp->c_cflag |= CS6; |
| 926 | + break; |
| 927 | + |
| 928 | + case 7: |
| 929 | + termiosp->c_cflag |= CS7; |
| 930 | + break; |
| 931 | + |
| 932 | + default: |
| 933 | + case 8: |
| 934 | + termiosp->c_cflag |= CS8; |
| 935 | + break; |
| 936 | + } |
| 937 | + } |
| 938 | + break; |
| 939 | + |
| 940 | + case TCSETS: |
| 941 | + { |
| 942 | + struct termios *termiosp = (struct termios *)arg; |
| 943 | + struct esp32s3_uart_s *priv = (struct esp32s3_uart_s *)dev->priv; |
| 944 | + uint32_t baud; |
| 945 | + uint32_t current_int_sts; |
| 946 | + uint8_t parity; |
| 947 | + uint8_t bits; |
| 948 | + uint8_t stop2; |
944 | 949 | #ifdef CONFIG_SERIAL_IFLOWCONTROL |
945 | | - bool iflow; |
| 950 | + bool iflow; |
946 | 951 | #endif |
947 | 952 | #ifdef CONFIG_SERIAL_OFLOWCONTROL |
948 | | - bool oflow; |
| 953 | + bool oflow; |
949 | 954 | #endif |
950 | 955 |
|
951 | | - if (termiosp == NULL) |
952 | | - { |
953 | | - ret = -EINVAL; |
954 | | - break; |
955 | | - } |
| 956 | + if (termiosp == NULL) |
| 957 | + { |
| 958 | + ret = -EINVAL; |
| 959 | + break; |
| 960 | + } |
956 | 961 |
|
957 | | - /* Get the target baud rate to change. */ |
| 962 | + /* Get the target baud rate to change. */ |
958 | 963 |
|
959 | | - baud = cfgetispeed(termiosp); |
| 964 | + baud = cfgetispeed(termiosp); |
960 | 965 |
|
961 | | - /* Decode number of bits. */ |
| 966 | + /* Decode number of bits. */ |
962 | 967 |
|
963 | | - switch (termiosp->c_cflag & CSIZE) |
964 | | - { |
965 | | - case CS5: |
966 | | - bits = 5; |
967 | | - break; |
| 968 | + switch (termiosp->c_cflag & CSIZE) |
| 969 | + { |
| 970 | + case CS5: |
| 971 | + bits = 5; |
| 972 | + break; |
968 | 973 |
|
969 | | - case CS6: |
970 | | - bits = 6; |
971 | | - break; |
| 974 | + case CS6: |
| 975 | + bits = 6; |
| 976 | + break; |
972 | 977 |
|
973 | | - case CS7: |
974 | | - bits = 7; |
975 | | - break; |
| 978 | + case CS7: |
| 979 | + bits = 7; |
| 980 | + break; |
976 | 981 |
|
977 | | - case CS8: |
978 | | - bits = 8; |
979 | | - break; |
| 982 | + case CS8: |
| 983 | + bits = 8; |
| 984 | + break; |
980 | 985 |
|
981 | | - default: |
982 | | - ret = -EINVAL; |
983 | | - break; |
984 | | - } |
| 986 | + default: |
| 987 | + ret = -EINVAL; |
| 988 | + break; |
| 989 | + } |
985 | 990 |
|
986 | | - /* Decode parity. */ |
| 991 | + /* Decode parity. */ |
987 | 992 |
|
988 | | - if ((termiosp->c_cflag & PARENB) != 0) |
989 | | - { |
990 | | - parity = (termiosp->c_cflag & PARODD) != 0 ? 1 : 2; |
991 | | - } |
992 | | - else |
993 | | - { |
994 | | - parity = 0; |
995 | | - } |
| 993 | + if ((termiosp->c_cflag & PARENB) != 0) |
| 994 | + { |
| 995 | + parity = (termiosp->c_cflag & PARODD) != 0 ? 1 : 2; |
| 996 | + } |
| 997 | + else |
| 998 | + { |
| 999 | + parity = 0; |
| 1000 | + } |
996 | 1001 |
|
997 | | - /* Decode stop bits. */ |
| 1002 | + /* Decode stop bits. */ |
998 | 1003 |
|
999 | | - stop2 = (termiosp->c_cflag & CSTOPB) != 0 ? 1 : 0; |
| 1004 | + stop2 = (termiosp->c_cflag & CSTOPB) != 0 ? 1 : 0; |
1000 | 1005 |
|
1001 | 1006 | #ifdef CONFIG_SERIAL_IFLOWCONTROL |
1002 | | - iflow = (termiosp->c_cflag & CRTS_IFLOW) != 0; |
| 1007 | + iflow = (termiosp->c_cflag & CRTS_IFLOW) != 0; |
1003 | 1008 | #endif |
1004 | 1009 | #ifdef CONFIG_SERIAL_OFLOWCONTROL |
1005 | | - oflow = (termiosp->c_cflag & CCTS_OFLOW) != 0; |
| 1010 | + oflow = (termiosp->c_cflag & CCTS_OFLOW) != 0; |
1006 | 1011 | #endif |
1007 | 1012 |
|
1008 | | - /* Verify that all settings are valid before |
1009 | | - * performing the changes. |
1010 | | - */ |
| 1013 | + /* Verify that all settings are valid before |
| 1014 | + * performing the changes. |
| 1015 | + */ |
1011 | 1016 |
|
1012 | | - if (ret == OK) |
1013 | | - { |
1014 | | - /* Fill the private struct fields. */ |
| 1017 | + if (ret == OK) |
| 1018 | + { |
| 1019 | + /* Fill the private struct fields. */ |
1015 | 1020 |
|
1016 | | - priv->baud = baud; |
1017 | | - priv->parity = parity; |
1018 | | - priv->bits = bits; |
1019 | | - priv->stop_b2 = stop2; |
| 1021 | + priv->baud = baud; |
| 1022 | + priv->parity = parity; |
| 1023 | + priv->bits = bits; |
| 1024 | + priv->stop_b2 = stop2; |
1020 | 1025 | #ifdef CONFIG_SERIAL_IFLOWCONTROL |
1021 | | - priv->iflow = iflow; |
| 1026 | + priv->iflow = iflow; |
1022 | 1027 | #endif |
1023 | 1028 | #ifdef CONFIG_SERIAL_OFLOWCONTROL |
1024 | | - priv->oflow = oflow; |
| 1029 | + priv->oflow = oflow; |
1025 | 1030 | #endif |
1026 | 1031 |
|
1027 | | - /* Effect the changes immediately - note that we do not |
1028 | | - * implement TCSADRAIN or TCSAFLUSH, only TCSANOW option. |
1029 | | - * See nuttx/libs/libc/termios/lib_tcsetattr.c |
1030 | | - */ |
| 1032 | + /* Effect the changes immediately - note that we do not |
| 1033 | + * implement TCSADRAIN or TCSAFLUSH, only TCSANOW option. |
| 1034 | + * See nuttx/libs/libc/termios/lib_tcsetattr.c |
| 1035 | + */ |
1031 | 1036 |
|
1032 | | - esp32s3_lowputc_disable_all_uart_int(priv, ¤t_int_sts); |
1033 | | - ret = esp32s3_setup(dev); |
| 1037 | + esp32s3_lowputc_disable_all_uart_int(priv, ¤t_int_sts); |
| 1038 | + ret = esp32s3_setup(dev); |
1034 | 1039 |
|
1035 | | - /* Restore the interrupt state */ |
| 1040 | + /* Restore the interrupt state */ |
1036 | 1041 |
|
1037 | | - esp32s3_lowputc_restore_all_uart_int(priv, ¤t_int_sts); |
1038 | | - } |
1039 | | - } |
1040 | | - break; |
| 1042 | + esp32s3_lowputc_restore_all_uart_int(priv, ¤t_int_sts); |
| 1043 | + } |
| 1044 | + } |
| 1045 | + break; |
1041 | 1046 | #endif /* CONFIG_SERIAL_TERMIOS */ |
1042 | 1047 |
|
1043 | | - default: |
1044 | | - ret = -ENOTTY; |
1045 | | - break; |
| 1048 | + default: |
| 1049 | + ret = -ENOTTY; |
| 1050 | + break; |
1046 | 1051 | } |
1047 | 1052 |
|
1048 | 1053 | return ret; |
@@ -1086,6 +1091,7 @@ static bool esp32s3_rxflowcontrol(struct uart_dev_s *dev, |
1086 | 1091 | { |
1087 | 1092 | bool ret = false; |
1088 | 1093 | struct esp32s3_uart_s *priv = dev->priv; |
| 1094 | + |
1089 | 1095 | if (priv->iflow) |
1090 | 1096 | { |
1091 | 1097 | if (nbuffered == 0 || upper == false) |
|
0 commit comments