You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/12/07 15:07:21 UTC

[GitHub] mlaz closed pull request #1378: lp5523: Fixing selftest, set_output_on and set_n_regs

mlaz closed pull request #1378: lp5523: Fixing selftest, set_output_on and set_n_regs
URL: https://github.com/apache/mynewt-core/pull/1378
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/drivers/led/lp5523/src/lp5523.c b/hw/drivers/led/lp5523/src/lp5523.c
index 8ef7907fb0..0865bd461b 100644
--- a/hw/drivers/led/lp5523/src/lp5523.c
+++ b/hw/drivers/led/lp5523/src/lp5523.c
@@ -311,26 +311,35 @@ int
 lp5523_set_output_on(struct led_itf *itf, uint8_t output, uint8_t on)
 {
     int rc;
-    uint16_t outputs;
+    uint8_t reg_addr;
+    uint8_t reg;
+    uint8_t shamt;
 
     if ((output < 1) || (output > 9)) {
         rc = -1;
         goto err;
     }
 
-    rc = lp5523_get_bitfield(itf, LP5523_OUTPUT_CTRL_MSB,
-                             &outputs);
+    if (output < 9) {
+        reg_addr = LP5523_OUTPUT_CTRL_LSB;
+        shamt = output - 1;
+    } else {
+        reg_addr = LP5523_OUTPUT_CTRL_MSB;
+        shamt = output - 9;
+    }
+
+    rc = lp5523_get_reg(itf, reg_addr, &reg);
     if (rc) {
         goto err;
     }
 
     if (!on) {
-        outputs &= ~(0x1 << (output - 1));
+        reg &= ~(0x01 << (shamt));
     } else {
-        outputs |= (0x1 << (output - 1));
+        reg |= (0x01 << (shamt));
     }
 
-    rc = lp5523_set_bitfield(itf, LP5523_OUTPUT_CTRL_MSB, outputs);
+    rc = lp5523_set_reg(itf, reg_addr, reg);
     if (rc) {
         goto err;
     }
@@ -344,20 +353,29 @@ int
 lp5523_get_output_on(struct led_itf *itf, uint8_t output, uint8_t *on)
 {
     int rc;
-    uint16_t outputs;
+    uint8_t reg_addr;
+    uint8_t reg;
+    uint8_t shamt;
 
     if ((output < 1) || (output > 9)) {
         rc = -1;
         goto err;
     }
 
-    rc = lp5523_get_bitfield(itf, LP5523_OUTPUT_CTRL_MSB,
-                             &outputs);
+    if (output < 9) {
+        reg_addr = LP5523_OUTPUT_CTRL_LSB;
+        shamt = output - 1;
+    } else {
+        reg_addr = LP5523_OUTPUT_CTRL_MSB;
+        shamt = output - 9;
+    }
+
+    rc = lp5523_get_reg(itf, reg_addr, &reg);
     if (rc) {
         goto err;
     }
 
-    *on = (outputs & (0x1 << (output - 1)));
+    *on = (reg & (0x1 << shamt));
 
     return 0;
 err:
@@ -874,6 +892,7 @@ lp5523_self_test(struct led_itf *itf) {
     uint8_t vdd;
     uint8_t adc;
     uint8_t i;
+    uint8_t on = 0;
 
     rc = lp5523_get_status(itf, &status);
     if (rc) {
@@ -897,8 +916,14 @@ lp5523_self_test(struct led_itf *itf) {
         return rc;
     }
 
-    i = 1;
-    while (i <= 9) {
+    for (i = 1; i <= 9; ++i) {
+        rc = lp5523_get_output_on(itf, i, &on);
+        if (rc) {
+            return rc;
+        }
+        if (!on) {
+            continue;
+        }
         /* set LED PWM to 0xff */
         rc = lp5523_set_output_reg(itf, LP5523_PWM, i, 0xff);
         if (rc) {
@@ -921,7 +946,6 @@ lp5523_self_test(struct led_itf *itf) {
         if (rc) {
             return rc;
         }
-        ++i;
     }
 
     return 0;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services