summaryrefslogtreecommitdiffstats
path: root/main/fix-serial.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/fix-serial.patch')
-rw-r--r--main/fix-serial.patch149
1 files changed, 58 insertions, 91 deletions
diff --git a/main/fix-serial.patch b/main/fix-serial.patch
index 80b11c5..4c06ffa 100644
--- a/main/fix-serial.patch
+++ b/main/fix-serial.patch
@@ -1,97 +1,64 @@
diff --git a/movement/filesystem.c b/movement/filesystem.c
-index 97e3545..d3c2f83 100644
+index 9df0a8d..ac117af 100644
--- a/movement/filesystem.c
+++ b/movement/filesystem.c
-@@ -275,6 +275,10 @@ void filesystem_process_command(char *line) {
- filesystem_append_file(filename, "\n", 1);
- }
- free(text);
-+ } else if (strcmp(command, "format") == 0) {
-+ lfs_unmount(&lfs);
-+ lfs_format(&lfs, &cfg);
-+ lfs_mount(&lfs, &cfg);
- } else {
- printf("%s: command not found\n", command);
- }
-diff --git a/movement/movement.c b/movement/movement.c
-index 825f130..c7066f7 100644
---- a/movement/movement.c
-+++ b/movement/movement.c
-@@ -547,7 +547,29 @@ bool app_loop(void) {
- tx = "";
- });
- #else
-- read(0, line, 256);
-+#if 0
-+ read(0, &line[ll], sizeof(line)-ll);
-+#else
-+ // JMM yuck just yuck, we do our best to patch this mess up
-+ {
-+ static char buf[sizeof(line) - 1];
-+ static int bl; //again really signed?
-+ int red;
+@@ -280,3 +280,13 @@ int filesystem_cmd_echo(int argc, char *argv[]) {
+ return 0;
+ }
+
++int filesystem_cmd_format(int argc, char *argv[]) {
++ (void) argc;
++ (void) argv;
+
-+ red = read(0, &buf[bl], sizeof(buf) - 1);
++ lfs_unmount(&lfs);
++ lfs_format(&lfs, &cfg);
++ lfs_mount(&lfs, &cfg);
+
-+ if (red > 0) {
-+ write(0, &buf[bl], red);
-+ bl += red;
-+ if (buf[bl-1] == '\r') {
-+ for (red = 0; red < bl; ++red)
-+ line[red] = buf[red] == '\r' ? '\n' : buf[red];
-+ //memcpy(line,buf,bl-1);
-+ bl = 0;
-+ }
-+ }
-+ }
-+#endif
- #endif
- if (strlen(line)) filesystem_process_command(line);
- }
-diff --git a/watch-library/hardware/watch/watch_private.c b/watch-library/hardware/watch/watch_private.c
-index cd607b8..5081fdb 100644
---- a/watch-library/hardware/watch/watch_private.c
-+++ b/watch-library/hardware/watch/watch_private.c
-@@ -246,9 +246,18 @@ void _watch_enable_usb(void) {
- // this function ends up getting called by printf to log stuff to the USB console.
- int _write(int file, char *ptr, int len) {
- (void)file;
-+ int i; //it's 2023 boys and girls you can use size_t and ssize_t
- if (hri_usbdevice_get_CTRLA_ENABLE_bit(USB)) {
-- tud_cdc_n_write(0, (void const*)ptr, len);
-- tud_cdc_n_write_flush(0);
-+ //tud_cdc_n_write(0, (void const*)ptr, len);
-+ for (i = 0; i < len; ++i)
-+ {
-+ if (ptr[i]=='\n') {
-+ tud_cdc_n_write(0, (void const*)"\r\n", 2);
-+ } else {
-+ tud_cdc_n_write(0, (void const*)&ptr[i], 1);
-+ }
-+ tud_cdc_n_write_flush(0);
-+ }
- return len;
- }
++ return 0;
++}
+diff --git a/movement/filesystem.h b/movement/filesystem.h
+index fa3d9d1..ee13cba 100644
+--- a/movement/filesystem.h
++++ b/movement/filesystem.h
+@@ -101,5 +101,6 @@ int filesystem_cmd_cat(int argc, char *argv[]);
+ int filesystem_cmd_df(int argc, char *argv[]);
+ int filesystem_cmd_rm(int argc, char *argv[]);
+ int filesystem_cmd_echo(int argc, char *argv[]);
++int filesystem_cmd_format(int argc, char *argv[]);
-@@ -262,6 +271,8 @@ int _read(int file, char *ptr, int len) {
- int actual_length = strlen(buf);
- if (actual_length) {
- memcpy(ptr, buf, min(len, actual_length));
-+ //JMM yuckity yuck yuck
-+ buf[0] = 0;
- return actual_length;
- }
- return 0;
-diff --git a/watch-library/shared/watch/watch.h b/watch-library/shared/watch/watch.h
-index 790f9a1..b280ae6 100644
---- a/watch-library/shared/watch/watch.h
-+++ b/watch-library/shared/watch/watch.h
-@@ -95,5 +95,6 @@ void watch_reset_to_bootloader(void);
- * @return The number of bytes read, or zero if no bytes were read.
- */
- int read(int file, char *ptr, int len);
-+int write(int file, char *ptr, int len);
-
--#endif /* WATCH_H_ */
-\ No newline at end of file
-+#endif /* WATCH_H_ */
+ #endif // FILESYSTEM_H_
+diff --git a/movement/shell_cmd_list.c b/movement/shell_cmd_list.c
+index 0ea08a5..a5d2d01 100644
+--- a/movement/shell_cmd_list.c
++++ b/movement/shell_cmd_list.c
+@@ -92,6 +92,13 @@ shell_command_t g_shell_commands[] = {
+ .max_args = 3,
+ .cb = filesystem_cmd_echo,
+ },
++ {
++ .name = "format",
++ .help = "usage: format",
++ .min_args = 0,
++ .max_args = 0,
++ .cb = filesystem_cmd_format,
++ },
+ {
+ .name = "stress",
+ .help = "test CDC write; usage: stress [LEN] [DELAY_MS]",
+diff --git a/watch-library/hardware/watch/watch_private_cdc.c b/watch-library/hardware/watch/watch_private_cdc.c
+index a961b5e..31e354d 100644
+--- a/watch-library/hardware/watch/watch_private_cdc.c
++++ b/watch-library/hardware/watch/watch_private_cdc.c
+@@ -145,7 +145,11 @@ static void prv_handle_writes(void) {
+ prv_handle_reads();
+ }
+ if (tud_cdc_write_available()) {
+- tud_cdc_write(&s_write_buf[idx], 1);
++ if (s_write_buf[idx]=='\n') {
++ tud_cdc_write("\r\n", 2);
++ } else {
++ tud_cdc_write(&s_write_buf[idx], 1);
++ }
+ }
+ s_write_buf[idx] = 0;
+ s_write_buf_len--;