xiaoxiang781216 commented on code in PR #3166: URL: https://github.com/apache/nuttx-apps/pull/3166#discussion_r2301281836
########## examples/i2schar/i2schar.h: ########## @@ -83,6 +83,7 @@ struct i2schar_state_s { bool initialized; + bool loopback_mode; Review Comment: ```suggestion bool loopback; ``` ########## examples/i2schar/i2schar_main.c: ########## @@ -35,6 +35,11 @@ #include <errno.h> #include <debug.h> +#include <nuttx/audio/audio.h> +#include <nuttx/audio/i2s.h> +#include <fcntl.h> Review Comment: move to line 31-36 ########## examples/i2schar/i2schar_receiver.c: ########## @@ -79,12 +80,14 @@ pthread_addr_t i2schar_receiver(pthread_addr_t arg) { FAR struct ap_buffer_s *apb; + FAR struct ap_buffer_s *transmitter_buffer = (FAR struct ap_buffer_s *)arg; Review Comment: ```suggestion FAR struct ap_buffer_s *transmitter_apb = (FAR struct ap_buffer_s *)arg; ``` ########## examples/i2schar/i2schar_transmitter.c: ########## @@ -79,17 +80,13 @@ pthread_addr_t i2schar_transmitter(pthread_addr_t arg) { FAR struct ap_buffer_s *apb; - struct audio_buf_desc_s desc; - uint8_t crap; - uint8_t *ptr; + FAR struct ap_buffer_s *transmitter_buffer = (FAR struct ap_buffer_s *)arg; Review Comment: ```suggestion FAR struct ap_buffer_s *transmitter_apb = (FAR struct ap_buffer_s *)arg; ``` ########## examples/i2schar/i2schar_receiver.c: ########## @@ -154,6 +165,51 @@ pthread_addr_t i2schar_receiver(pthread_addr_t arg) } while (nread != bufsize); + /* Print received buffer data (first 16 bytes) regardless of mode */ + + printf("i2schar_receiver: Received data (first 16 bytes): "); + for (int j = 0; j < 16 && j < CONFIG_EXAMPLES_I2SCHAR_BUFSIZE; j++) Review Comment: don't define variable in for loop ########## examples/i2schar/i2schar_receiver.c: ########## @@ -79,12 +80,14 @@ pthread_addr_t i2schar_receiver(pthread_addr_t arg) { FAR struct ap_buffer_s *apb; + FAR struct ap_buffer_s *transmitter_buffer = (FAR struct ap_buffer_s *)arg; struct audio_buf_desc_s desc; int bufsize; int nread; int ret; int fd; int i; + bool loopback_mode = (transmitter_buffer != NULL); Review Comment: ```suggestion bool loopback = (transmitter_apb != NULL); ``` ########## examples/i2schar/i2schar_main.c: ########## @@ -35,6 +35,11 @@ #include <errno.h> #include <debug.h> +#include <nuttx/audio/audio.h> +#include <nuttx/audio/i2s.h> +#include <fcntl.h> +#include <sys/ioctl.h> Review Comment: ditto ########## examples/i2schar/i2schar_main.c: ########## @@ -175,8 +186,81 @@ static void parse_args(FAR struct i2schar_state_s *i2schar, index += nargs; break; +#if defined(CONFIG_EXAMPLES_I2SCHAR_TX) && defined(CONFIG_EXAMPLES_I2SCHAR_RX) + case 'l': + + /* Check if a value is provided */ + + if (ptr[2] == '\0' && index + 1 < argc && + argv[index + 1][0] != '-') + { + /* Value provided as next argument */ + + long loopback_value = strtol(argv[index + 1], NULL, 10); Review Comment: ```suggestion long loopback = strtol(argv[index + 1], NULL, 10); ``` ########## examples/i2schar/i2schar_main.c: ########## @@ -175,8 +186,81 @@ static void parse_args(FAR struct i2schar_state_s *i2schar, index += nargs; break; +#if defined(CONFIG_EXAMPLES_I2SCHAR_TX) && defined(CONFIG_EXAMPLES_I2SCHAR_RX) + case 'l': + + /* Check if a value is provided */ + + if (ptr[2] == '\0' && index + 1 < argc && + argv[index + 1][0] != '-') + { + /* Value provided as next argument */ + + long loopback_value = strtol(argv[index + 1], NULL, 10); + + if (loopback_value == 0) + { + i2schar->loopback_mode = false; + } + else if (loopback_value == 1) + { + i2schar->loopback_mode = true; + } + else + { + printf("Invalid loopback value: %ld (must be 0 or 1)\n", + loopback_value); + exit(1); + } + + index += 2; + } + else if (ptr[2] == '\0') + { + /* No value provided, default to enable */ + + i2schar->loopback_mode = true; + index += 1; + } + + else + { + /* Value provided as part of the same argument */ + + long loopback_value = strtol(&ptr[2], NULL, 10); Review Comment: ```suggestion long loopback = strtol(&ptr[2], NULL, 10); ``` ########## examples/i2schar/i2schar_main.c: ########## @@ -229,13 +424,16 @@ int main(int argc, FAR char *argv[]) pthread_addr_t result; #ifdef CONFIG_EXAMPLES_I2SCHAR_TX pthread_t transmitter; + int fd; #endif #ifdef CONFIG_EXAMPLES_I2SCHAR_RX pthread_t receiver; #endif #if defined(CONFIG_EXAMPLES_I2SCHAR_RX) & defined(CONFIG_EXAMPLES_I2SCHAR_TX) struct sched_param param; #endif + FAR struct ap_buffer_s *transmitter_buffer = NULL; Review Comment: ```suggestion FAR struct ap_buffer_s *transmitter_apb = NULL; ``` -- 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-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org