kasjer commented on code in PR #3236:
URL: https://github.com/apache/mynewt-core/pull/3236#discussion_r1628832266


##########
hw/usb/tinyusb/msc_fat_view/src/entry_config.c:
##########
@@ -0,0 +1,288 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stdint.h>
+#include <ctype.h>
+#include <stream/stream.h>
+#include <msc_fat_view/msc_fat_view.h>
+#include <modlog/modlog.h>
+#include <hal/hal_flash.h>
+#include <config/config.h>
+
+struct config_export_stream {
+    struct out_stream out_stream;
+    /* Buffer to write to (can be NULL) */
+    uint8_t *buffer;
+    /* Stream start offset, writes to stream preceding this will be dropped */
+    uint32_t buffer_start_offset;
+    /* Stream end offset, writes to stream after this will be dropped */
+    uint16_t buffer_end_offset;
+    /* Current stream write offset */
+    uint32_t write_offset;
+};
+
+static int
+config_export_write(struct out_stream *ostream, const uint8_t *buf, uint32_t 
count)
+{
+    struct config_export_stream *str = (struct config_export_stream *)ostream;
+    uint32_t upper_limit = str->write_offset + count;
+    uint32_t lower_limit = str->write_offset;
+    int cnt = count;
+
+    if (lower_limit < str->buffer_end_offset && upper_limit > 
str->buffer_start_offset) {
+        if (lower_limit < str->buffer_start_offset) {
+            cnt -= str->buffer_start_offset - lower_limit;
+            lower_limit = str->buffer_start_offset;
+        }
+        if (upper_limit > str->buffer_end_offset) {
+            cnt -= upper_limit - str->buffer_end_offset;
+        }
+        memcpy(str->buffer + lower_limit - str->buffer_start_offset,
+               buf + (lower_limit - str->write_offset), cnt);
+    }
+    str->write_offset += count;
+
+    return count;
+}
+
+static int
+config_export_flush(struct out_stream *ostream)
+{
+    return 0;
+}
+
+OSTREAM_DEF(config_export);
+
+static struct config_export_stream export_stream = {
+    .out_stream.vft = &config_export_vft,
+};
+
+static void
+config_text_export(char *name, char *val)

Review Comment:
   Function prototype matches typedef from config/config.h
   ```c
   /**
    * Called per-configuration variable being exported.
    *
    * @param name The name of the variable to export
    * @param val  The value of the variable to export
    */
   typedef void (*conf_export_func_t)(char *name, char *val);```



-- 
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...@mynewt.apache.org

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

Reply via email to