changeset 3900:50eb437029a1

iomux: moved the static device_iomux_mode function to device_io_mode_symbol, updated doc
author Alexandre Becoulet <alexandre.becoulet@free.fr>
date Wed, 18 Apr 2018 15:38:49 +0200
parents bc4fe1660e31
children 7bf75f759731
files libdevice/device_iomux.c libdevice/include/device/class/iomux.h libdevice/include/device/resources.h libdevice/resources.c
diffstat 4 files changed, 42 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/libdevice/device_iomux.c	Wed Apr 18 14:37:03 2018 +0200
+++ b/libdevice/device_iomux.c	Wed Apr 18 15:38:49 2018 +0200
@@ -26,30 +26,6 @@
 
 #include <stdarg.h>
 
-static enum dev_pin_driving_e device_iomux_mode(char l)
-{
-  struct switch_s { char c; char n; };
-  static const struct switch_s sw[10] = {
-    { '^', DEV_PIN_OPENSOURCE },
-    { '_', DEV_PIN_OPENDRAIN },
-    { '`', DEV_PIN_OPENSOURCE_PULLDOWN },
-    { '+', DEV_PIN_INPUT_PULLUP },
-    { ',', DEV_PIN_OPENDRAIN_PULLUP },
-    { '-', DEV_PIN_INPUT_PULLDOWN },
-    { 0, 0 },
-    { '<', DEV_PIN_INPUT },
-    { '=', DEV_PIN_INPUT_PULL },
-    { '>', DEV_PIN_PUSHPULL },
-  };
-
-  /* decode direction symbol using a perfect hash */
-  uint32_t x = ((319838000U * (uint32_t)l) >> 28);
-  if (x < 10 && sw[x].c == l)
-    return sw[x].n;
-
-  return DEV_PIN_DISABLED;
-}
-
 error_t device_iomux_fetch(struct device_s *dev,
                            struct device_iomux_s *iomux, const char *io_list,
                            iomux_demux_t *demux, iomux_io_id_t *io_id,
@@ -57,7 +33,7 @@
 {
   while (*io_list)
     {
-      enum dev_pin_driving_e dir = device_iomux_mode(*io_list);
+      enum dev_pin_driving_e dir = device_io_mode_symbol(*io_list);
       if (dir)
         io_list++;
 
@@ -79,7 +55,7 @@
         return -ENOENT;
 
       /* direction in resource label overrides the one in driver string */
-      enum dev_pin_driving_e dir2 = device_iomux_mode(*r->u.iomux.label);
+      enum dev_pin_driving_e dir2 = device_io_mode_symbol(*r->u.iomux.label);
       if (dir2)
         dir = dir2;
 
--- a/libdevice/include/device/class/iomux.h	Wed Apr 18 14:37:03 2018 +0200
+++ b/libdevice/include/device/class/iomux.h	Wed Apr 18 15:38:49 2018 +0200
@@ -31,13 +31,17 @@
    @section {Purpose}
 
    This class provides functions to configure the pin muxing used by a
-   device inside a chip.
+   device @b internal to a chip.
 
    This is mainly intended for use by device drivers: the @ref
    device_iomux_setup function is called from the device driver
    initialization function and the @ref device_iomux_cleanup is called
    when the driver is unloaded.
 
+   Using this API to configure IOs used to drive an external device is
+   wrong. The @xref{General purpose IO} class must be used for that
+   purpose.
+
    @end section
 */
 
@@ -95,18 +99,21 @@
   })
 
 /**
-   @This fetches the pin muxing information and sets the muxing
-   configuration of IOs whose names are listed in the @tt io_list
-   string. IO muxing information from device resources are used.
+   @This fetches the pin muxing information declared device resources
+   and sets the muxing configuration of IOs whose names are listed in
+   the @tt io_list string.
 
    The device must have a @ref DEV_RES_DEV_PARAM resource entry named
    @tt iomux which specifies the target IO mux controller. @This
    calls the @ref device_iomux_fetch function.
 
-   Example:
+   @section {Examples}
    @code
    device_iomux_setup(uart, ">tx <rx >rts? <cts?", NULL, NULL, NULL);
    @end code
+   @end section
+
+   @see dev_pin_driving_e
 */
 config_depend(CONFIG_DEVICE_IOMUX)
 error_t device_iomux_setup(struct device_s *dev, const char *io_list,
--- a/libdevice/include/device/resources.h	Wed Apr 18 14:37:03 2018 +0200
+++ b/libdevice/include/device/resources.h	Wed Apr 18 15:38:49 2018 +0200
@@ -1017,5 +1017,9 @@
   return 0;
 }
 
+/** @This returns a @ref dev_pin_driving_e value from a char
+    symbol. @ref DEV_PIN_DISABLED is returned if the passed char is
+    not recognized. */
+enum dev_pin_driving_e device_io_mode_symbol(char l);
 
 #endif
--- a/libdevice/resources.c	Wed Apr 18 14:37:03 2018 +0200
+++ b/libdevice/resources.c	Wed Apr 18 15:38:49 2018 +0200
@@ -246,3 +246,27 @@
   return device_get_accessor_by_path(acc, &dev->node, r->u.str_param.value, cl);
 }
 
+enum dev_pin_driving_e device_io_mode_symbol(char l)
+{
+  struct switch_s { char c; char n; };
+  static const struct switch_s sw[10] = {
+    { '^', DEV_PIN_OPENSOURCE },
+    { '_', DEV_PIN_OPENDRAIN },
+    { '`', DEV_PIN_OPENSOURCE_PULLDOWN },
+    { '+', DEV_PIN_INPUT_PULLUP },
+    { ',', DEV_PIN_OPENDRAIN_PULLUP },
+    { '-', DEV_PIN_INPUT_PULLDOWN },
+    { 0, 0 },
+    { '<', DEV_PIN_INPUT },
+    { '=', DEV_PIN_INPUT_PULL },
+    { '>', DEV_PIN_PUSHPULL },
+  };
+
+  /* decode direction symbol using a perfect hash */
+  uint32_t x = ((319838000U * (uint32_t)l) >> 28);
+  if (x < 10 && sw[x].c == l)
+    return sw[x].n;
+
+  return DEV_PIN_DISABLED;
+}
+