This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 233ded1ac hal/shell: Add shell commands for hal
233ded1ac is described below
commit 233ded1aca3d57d090c623e3c9b0c0e83c829914
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Sun Nov 2 00:36:50 2025 +0100
hal/shell: Add shell commands for hal
This adds few commands to shell to manipulate
gpio and nvregs.
Signed-off-by: Jerzy Kasenberg <[email protected]>
---
hw/hal/shell_cmds/pkg.yml | 33 +++++++
hw/hal/shell_cmds/src/hal_shell_cmds.c | 153 +++++++++++++++++++++++++++++++++
2 files changed, 186 insertions(+)
diff --git a/hw/hal/shell_cmds/pkg.yml b/hw/hal/shell_cmds/pkg.yml
new file mode 100644
index 000000000..d0d214fd0
--- /dev/null
+++ b/hw/hal/shell_cmds/pkg.yml
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+
+pkg.name: hw/hal/shell_cmds
+pkg.description: Hardware Abstraction Layer shell commands
+pkg.author: "Apache Mynewt <[email protected]>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.whole_archive: true
+
+pkg.deps:
+ - "@apache-mynewt-core/hw/hal"
+ - "@apache-mynewt-core/sys/shell"
+
+pkg.link_tables:
+ - hal_commands
diff --git a/hw/hal/shell_cmds/src/hal_shell_cmds.c
b/hw/hal/shell_cmds/src/hal_shell_cmds.c
new file mode 100644
index 000000000..b89f4ae00
--- /dev/null
+++ b/hw/hal/shell_cmds/src/hal_shell_cmds.c
@@ -0,0 +1,153 @@
+/*
+ * 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 <errno.h>
+#include <string.h>
+#include <os/mynewt.h>
+#include <console/console.h>
+#include <shell/shell.h>
+#include <parse/parse.h>
+#include <hal/hal_gpio.h>
+#include <hal/hal_nvreg.h>
+
+int
+nvreg_dump_func(const struct shell_cmd *cmd, int argc, char *argv[],
+ struct streamer *streamer)
+{
+ int i;
+ uint32_t val;
+ int n = hal_nvreg_get_num_regs();
+
+ for (i = 0; i < n; ++i) {
+ val = hal_nvreg_read(i);
+ streamer_printf(streamer, "reg[%d] = %u (0x%X)\n", i,
+ (unsigned int)val, (unsigned int)val);
+ }
+ return 0;
+}
+
+int
+nvreg_read_func(const struct shell_cmd *cmd, int argc, char *argv[],
+ struct streamer *streamer)
+{
+ int reg = -1;
+ uint32_t val;
+ int rc;
+
+ if (argc > 1) {
+ reg = parse_ll_bounds(argv[1], 0, 256, &rc);
+ }
+ if (reg >= 0) {
+ val = hal_nvreg_read(reg);
+ streamer_printf(streamer, "reg[%d] = %u (0x%X)\n", reg,
+ (unsigned int)val, (unsigned int)val);
+ }
+ return 0;
+}
+
+int
+nvreg_write_func(const struct shell_cmd *cmd, int argc, char *argv[],
+ struct streamer *streamer)
+{
+ int reg = -1;
+ uint32_t val = 0;
+ int rc;
+
+ if (argc > 2) {
+ reg = parse_ll_bounds(argv[1], 0, 256, &rc);
+ if (rc == 0) {
+ val = parse_ll_bounds(argv[2], 0, 0xFFFFFFFF, &rc);
+ }
+ }
+ if (argc >= 3 && rc == 0) {
+ hal_nvreg_write(reg, val);
+ } else {
+ streamer_printf(streamer, "%s <reg> <val>\n", cmd->sc_cmd);
+ }
+ return 0;
+}
+
+int
+gpio_init_out_func(const struct shell_cmd *cmd, int argc, char *argv[],
+ struct streamer *streamer)
+{
+ int pin = -1;
+ int val = -1;
+ int rc;
+
+ if (argc > 1) {
+ pin = parse_ll_bounds(argv[1], 0, 512, &rc);
+ }
+ if (argc > 2) {
+ val = parse_ll_bounds(argv[2], 0, 1, &rc);
+ } else {
+ val = 0;
+ }
+ if (pin >= 0 && val >= 0) {
+ hal_gpio_init_out(pin, val);
+ }
+ return 0;
+}
+
+int
+gpio_write_func(const struct shell_cmd *cmd, int argc, char *argv[],
+ struct streamer *streamer)
+{
+ int pin = -1;
+ int val = -1;
+ int rc;
+
+ if (argc < 3) {
+ streamer_printf(streamer, "%s <pin> 0 | 1\n", cmd->sc_cmd);
+ } else {
+ pin = parse_ll_bounds(argv[1], 0, 512, &rc);
+ val = parse_ll_bounds(argv[2], 0, 1, &rc);
+ }
+ if (pin >= 0 && val >= 0) {
+ hal_gpio_write(pin, val);
+ }
+ return 0;
+}
+
+int
+gpio_toggle_func(const struct shell_cmd *cmd, int argc, char *argv[],
+ struct streamer *streamer)
+{
+ int pin = -1;
+ int rc;
+
+ if (argc < 2) {
+ streamer_printf(streamer, "%s <pin>\n", cmd->sc_cmd);
+ } else {
+ pin = parse_ll_bounds(argv[1], 0, 512, &rc);
+ }
+ if (pin >= 0) {
+ hal_gpio_toggle(pin);
+ }
+ return 0;
+}
+
+SHELL_MODULE_EXT_CMD(hal, nvreg_dump, nvreg_dump_func, NULL);
+SHELL_MODULE_EXT_CMD(hal, nvreg_read, nvreg_read_func, NULL);
+SHELL_MODULE_EXT_CMD(hal, nvreg_write, nvreg_write_func, NULL);
+SHELL_MODULE_EXT_CMD(hal, gpio_init_out, gpio_init_out_func, NULL);
+SHELL_MODULE_EXT_CMD(hal, gpio_write, gpio_write_func, NULL);
+SHELL_MODULE_EXT_CMD(hal, gpio_toggle, gpio_toggle_func, NULL);
+
+SHELL_MODULE_WITH_LINK_TABLE(hal);