You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/02/28 22:22:11 UTC

[incubator-nuttx] branch master updated: MCP9844 shutdown mode support (#403)

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 922e67c  MCP9844 shutdown mode support (#403)
922e67c is described below

commit 922e67c7cc18571319a1a0f4a4d23bd17a8f1b1c
Author: macman88 <jj...@gmail.com>
AuthorDate: Fri Feb 28 16:20:47 2020 -0600

    MCP9844 shutdown mode support (#403)
    
    * Added shutdown support to the MCP9844 sensor driver.
    * Clean up debug messages
    * Clean up comments and formatting
---
 drivers/sensors/mcp9844.c       | 61 +++++++++++++++++++++++++++++++++++++----
 include/nuttx/sensors/mcp9844.h |  4 +++
 2 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/drivers/sensors/mcp9844.c b/drivers/sensors/mcp9844.c
index b2897da..d23b403 100644
--- a/drivers/sensors/mcp9844.c
+++ b/drivers/sensors/mcp9844.c
@@ -1,6 +1,7 @@
 /****************************************************************************
  * drivers/sensors/mcp9844.c
  * Character driver for the MCP9844 Temperature Sensor
+ * Also supports the MCP9808 Temperature Sensor
  *
  *   Copyright (C) 2015 DS-Automotion GmbH. All rights reserved.
  *   Author: Alexander Entinger <a....@ds-automotion.com>
@@ -267,8 +268,8 @@ static int mcp9844_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
           uint16_t raw_temperature = 0;
           ret = mcp9844_read_u16(priv, MCP9844_TEMP_REG, &raw_temperature);
 
-          /* Convert from the proprietary sensor temperature data representation
-           * to a more user friendly version.
+          /* Convert from the proprietary sensor temperature data
+           * representation to a more user-friendly version.
            */
 
           if (ret == OK)
@@ -307,8 +308,58 @@ static int mcp9844_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
           ret = mcp9844_write_u16(priv, MCP9844_RESO_REG, (uint16_t)(arg));
           if (ret != OK)
             {
-              snerr("ERROR: ioctl::SNIOC_SETRESOLUTION - mcp9844_write_u16 failed"
-                    " - no resolution set\n");
+              snerr("ERROR: ioctl::SNIOC_SETRESOLUTION - mcp9844_write_u16"
+                  "failed - no resolution set\n");
+            }
+        }
+        break;
+
+      case SNIOC_SHUTDOWN:
+        {
+          uint16_t config_reg;
+
+          /* Perform a read-modify-write cycle on the config register */
+
+          ret = mcp9844_read_u16(priv, MCP9844_CONF_REG, &config_reg);
+          if (ret == OK)
+            {
+              config_reg |= MCP9844_CONF_REG_SHDN;
+              ret = mcp9844_write_u16(priv, MCP9844_CONF_REG, config_reg);
+              if (ret != OK)
+                {
+                  snerr("ERROR: ioctl::SNIOC_SHUTDOWN - "
+                        "mcp9844_write_u16 failed\n");
+                }
+            }
+          else
+            {
+              snerr("ERROR: ioctl::SNIOC_SHUTDOWN - "
+                    "mcp9844_read_u16 failed\n");
+            }
+        }
+        break;
+
+      case SNIOC_POWERUP:
+        {
+          uint16_t config_reg;
+
+          /* Perform a read-modify-write cycle on the config register */
+
+          ret = mcp9844_read_u16(priv, MCP9844_CONF_REG, &config_reg);
+          if (ret == OK)
+            {
+              config_reg &= ~MCP9844_CONF_REG_SHDN;
+              ret = mcp9844_write_u16(priv, MCP9844_CONF_REG, config_reg);
+              if (ret != OK)
+                {
+                  snerr("ERROR: ioctl::SNIOC_POWERUP - "
+                        "mcp9844_write_u16 failed\n");
+                }
+            }
+          else
+            {
+              snerr("ERROR: ioctl::SNIOC_POWERUP - "
+                    "mcp9844_read_u16 failed\n");
             }
         }
         break;
@@ -349,7 +400,7 @@ int mcp9844_register(FAR const char *devpath, FAR struct i2c_master_s *i2c,
 
   DEBUGASSERT(i2c != NULL);
 
-  /* Initialize the LM-75 device structure */
+  /* Initialize the MCP9844 device structure */
 
   FAR struct mcp9844_dev_s *priv =
     (FAR struct mcp9844_dev_s *)kmm_malloc(sizeof(struct mcp9844_dev_s));
diff --git a/include/nuttx/sensors/mcp9844.h b/include/nuttx/sensors/mcp9844.h
index 754e4d6..6ae95f0 100644
--- a/include/nuttx/sensors/mcp9844.h
+++ b/include/nuttx/sensors/mcp9844.h
@@ -58,6 +58,10 @@
 #define MCP9844_TEMP_REG      (0x05)     /* Sensor Temperature Register */
 #define MCP9844_RESO_REG      (0x09)     /* Register to control the resolution of the temperature sensor */
 
+/* Configuration Register Bit definitions */
+
+#define MCP9844_CONF_REG_SHDN   (1<<8)
+
 /* Resolution Register Bit definitions */
 
 #define MCP9844_RESO_REG_BIT_0  (1<<0)