Implemented first Hangar-Service
Dependencies: CalibrateMagneto QuaternionMath
Fork of SML2 by
LEDDriver.cpp
- Committer:
- pvaibhav
- Date:
- 2015-01-14
- Revision:
- 1:c279bc3af90c
- Parent:
- 0:943820483318
- Child:
- 4:e759b8c756da
File content as of revision 1:c279bc3af90c:
#include "LEDDriver.h" #include "mbed.h" #define DEBUG "LEDDriver" #include "Logger.h" #include <cassert> LEDDriver::LEDDriver(I2C &i2c) : I2CPeripheral(i2c, 0x60 /* I2C address of the LED controller */) { // cf. LP5562TME/NOPB datasheet page 14 // Supply 3.6V to VDD (hardware - done) // Supply 1.8V to EN (hardware - done) wait_ms(1); // wait 1 ms write_reg(0x00, 0xC0); // chip_en to 1, log_en to 1 wait_us(500); // wait 500 usec write_reg(0x08, 0x61); // set PWM freq high, enable power save mode, start internal clock write_reg(0x70, 0x00); // configure all LEDs to be controlled from I2C registers setColor(Colors::black); } void LEDDriver::setColor(const uint8_t r, const uint8_t g, const uint8_t b) { write_reg(0x04, r); write_reg(0x03, g); write_reg(0x02, b); } void LEDDriver::setColor(const float r, const float g, const float b) { setColor(r * 255, g * 255, b * 255); } void LEDDriver::setColor(const Color color) { const uint8_t r = (color >> 16) & 0xff; const uint8_t g = (color >> 8) & 0xff; const uint8_t b = (color >> 0) & 0xff; setColor(r, g, b); } LEDDriver& LEDDriver::operator=(const Color& c) { setColor(c); return *this; } void LEDDriver::setOutputCurrent(const float mA) { assert(mA <= 25.5); assert(mA >= 0.1); write_reg(0x05, mA * 10); write_reg(0x06, mA * 10); write_reg(0x07, mA * 10); INFO("Output current => %0.1f mA", mA); }