Implemented first Hangar-Service
Dependencies: CalibrateMagneto QuaternionMath
Fork of SML2 by
Diff: LEDDriver.cpp
- Revision:
- 0:943820483318
- Child:
- 1:c279bc3af90c
diff -r 000000000000 -r 943820483318 LEDDriver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LEDDriver.cpp Tue Jan 13 11:23:01 2015 +0000 @@ -0,0 +1,51 @@ +#include "LEDDriver.h" +#include "mbed.h" +#define DEBUG "LEDDriver.cpp" +#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("LED output current => %0.1f mA", mA); +}