Class module for NCP5623B I2C LED driver
Dependents: mDotEVBM2X MTDOT-EVB-LinkCheck-AL MTDOT-EVBDemo-DRH MTDOT_BOX_EVB_Blinky ... more
Revision 1:f0efe8462d0e, committed 2015-10-27
- Comitter:
- mfiore
- Date:
- Tue Oct 27 19:56:56 2015 +0000
- Parent:
- 0:b28a2dfe05fd
- Child:
- 2:9c70b63e3b1e
- Commit message:
- <CTRL><SHIFT><f> to fix formatting
Changed in this revision
| NCP5623B.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/NCP5623B.cpp Mon Jul 06 19:29:08 2015 +0000
+++ b/NCP5623B.cpp Tue Oct 27 19:56:56 2015 +0000
@@ -19,49 +19,48 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
#include "NCP5623B.h"
#include "mbed_debug.h"
#include "rtos.h"
-
+
NCP5623B::NCP5623B(I2C &i2c)
{
_i2c = &i2c;
NCP5623B::init();
-
+
return;
}
uint8_t NCP5623B::init(void)
{
uint8_t result = 0;
-
+
_i2c->frequency(400000);
-
+
// Turn off all LEDs and initialize all registers
- result |= NCP5623B::writeRegister(NCP5623B::DIMDWNSET, 0x00);
+ result |= NCP5623B::writeRegister(NCP5623B::DIMDWNSET, 0x00);
result |= NCP5623B::writeRegister(NCP5623B::DIMTIME, 0x01);
osDelay (1000);
result |= NCP5623B::writeRegister(NCP5623B::LEDCURR, 0x00);
- result |= NCP5623B::writeRegister(NCP5623B::PWMLED1, 0x00);
- result |= NCP5623B::writeRegister(NCP5623B::PWMLED2, 0x00);
- result |= NCP5623B::writeRegister(NCP5623B::PWMLED3, 0x00);
+ result |= NCP5623B::writeRegister(NCP5623B::PWMLED1, 0x00);
+ result |= NCP5623B::writeRegister(NCP5623B::PWMLED2, 0x00);
+ result |= NCP5623B::writeRegister(NCP5623B::PWMLED3, 0x00);
- if(result != 0)
- {
+ if(result != 0) {
debug("ILS29011:init failed\n\r");
}
-
- return result;
+
+ return result;
}
- /** Shutdown LEDS
- * @return status of command
- */
+/** Shutdown LEDS
+ * @return status of command
+ */
uint8_t NCP5623B::shutdown(void) const
{
- uint8_t result = 0;
+ uint8_t result = 0;
result |= NCP5623B::writeRegister(NCP5623B::SHUTDWN, 0x00);
return result;
@@ -74,75 +73,72 @@
*/
uint8_t NCP5623B::setLEDCurrent(uint8_t data) const
{
- uint8_t result = 0;
+ uint8_t result = 0;
result |= NCP5623B::writeRegister(NCP5623B::LEDCURR, data);
return result;
}
- /** Set PWM mode for specific LED
- * @lednum - selects LED
- * @data - PWM value to set range 0-31 0-100% Pulse width
- * @return status of command
- */
+/** Set PWM mode for specific LED
+ * @lednum - selects LED
+ * @data - PWM value to set range 0-31 0-100% Pulse width
+ * @return status of command
+ */
uint8_t NCP5623B::setPWM(LEDNUM lednum, int8_t data ) const
{
- uint8_t result = 0;
+ uint8_t result = 0;
- switch (lednum) {
- case NCP5623B::LED_1:
- result |= NCP5623B::writeRegister(NCP5623B::PWMLED1, data);
- break;
- case NCP5623B::LED_2:
- result |= NCP5623B::writeRegister(NCP5623B::PWMLED2, data);
- break;
- case NCP5623B::LED_3:
- result |= NCP5623B::writeRegister(NCP5623B::PWMLED3, data);
- break;
- }
+ switch (lednum) {
+ case NCP5623B::LED_1:
+ result |= NCP5623B::writeRegister(NCP5623B::PWMLED1, data);
+ break;
+ case NCP5623B::LED_2:
+ result |= NCP5623B::writeRegister(NCP5623B::PWMLED2, data);
+ break;
+ case NCP5623B::LED_3:
+ result |= NCP5623B::writeRegister(NCP5623B::PWMLED3, data);
+ break;
+ }
return result;
}
- /** Set Dimming mode for all LEDs
- * @dimdir - direction of dimming
- * @endstep - ending step of ramp up or ramp down range 0-31
- * @steptime - time per step range 0-31 in 8 msec multiples
- * @return status of command
- */
- uint8_t NCP5623B::setDimming(DIMDIRECTION dimdir, uint8_t endstep, uint8_t steptime) const
+/** Set Dimming mode for all LEDs
+ * @dimdir - direction of dimming
+ * @endstep - ending step of ramp up or ramp down range 0-31
+ * @steptime - time per step range 0-31 in 8 msec multiples
+ * @return status of command
+ */
+uint8_t NCP5623B::setDimming(DIMDIRECTION dimdir, uint8_t endstep, uint8_t steptime) const
{
- uint8_t result = 0;
+ uint8_t result = 0;
- if (dimdir == NCP5623B::DIMDWN)
- result |= NCP5623B::writeRegister(NCP5623B::DIMDWNSET, endstep);
- else
- result |= NCP5623B::writeRegister(NCP5623B::DIMUPSET, endstep);
+ if (dimdir == NCP5623B::DIMDWN)
+ result |= NCP5623B::writeRegister(NCP5623B::DIMDWNSET, endstep);
+ else
+ result |= NCP5623B::writeRegister(NCP5623B::DIMUPSET, endstep);
- result |= NCP5623B::writeRegister(NCP5623B::DIMTIME, steptime);
+ result |= NCP5623B::writeRegister(NCP5623B::DIMTIME, steptime);
- return result;
+ return result;
}
- /** Write to a register (exposed for debugging reasons)
- * @param reg - The register to be written
- * @param data - The data to be written
- */
+/** Write to a register (exposed for debugging reasons)
+ * @param reg - The register to be written
+ * @param data - The data to be written
+ */
uint8_t NCP5623B::writeRegister(NCP5623B::REGISTER const reg, uint8_t const data) const
{
char buf[1];
uint8_t result = 0;
buf[0] = reg | (data & NCP5623B::DATAMASK);
-
+
// __disable_irq(); // // Tickers and other timebase events can jack up the I2C bus for some devices
result |= _i2c->write(_i2c_addr, buf, 1);
// __enable_irq(); // Just need to block during the transaction
- if(result != 0)
- {
+ if(result != 0) {
debug("NCP5623B:writeRegister failed\n\r");
}
-
+
return result;
}
-
-