LP55231 driver

Committer:
duchonic
Date:
Wed Aug 22 08:59:37 2018 +0000
Revision:
1:4ab9f195e998
Parent:
0:4ff4e0b7f25c
Child:
2:79b94bf1cf59
colors, all 3 leds

Who changed what in which revision?

UserRevisionLine numberNew contents of line
duchonic 0:4ff4e0b7f25c 1 #include "LP55231.h"
duchonic 1:4ab9f195e998 2 #include "main.h"
duchonic 0:4ff4e0b7f25c 3
duchonic 0:4ff4e0b7f25c 4 LP55231::LP55231(PinName sda, PinName scl, uint8_t addr) : m_i2c(sda, scl), m_addr(addr) {}
duchonic 0:4ff4e0b7f25c 5
duchonic 0:4ff4e0b7f25c 6 uint8_t LP55231::LP55231_Init(void){
duchonic 0:4ff4e0b7f25c 7
duchonic 0:4ff4e0b7f25c 8 SetRegister(REG_ENGINE_CNTRL1, 0x40);
duchonic 0:4ff4e0b7f25c 9 SetRegister(REG_MISC, 0x53);
duchonic 0:4ff4e0b7f25c 10
duchonic 0:4ff4e0b7f25c 11 return 0;
duchonic 0:4ff4e0b7f25c 12 }
duchonic 0:4ff4e0b7f25c 13
duchonic 0:4ff4e0b7f25c 14 LP55231::~LP55231(void) {
duchonic 0:4ff4e0b7f25c 15 };
duchonic 0:4ff4e0b7f25c 16
duchonic 0:4ff4e0b7f25c 17
duchonic 1:4ab9f195e998 18 void LP55231::LP55231_SetLed(LP55231_leds led, LP55231_colors color)
duchonic 0:4ff4e0b7f25c 19 {
duchonic 1:4ab9f195e998 20 switch(led)
duchonic 1:4ab9f195e998 21 {
duchonic 1:4ab9f195e998 22 case LP55231_LED1:
duchonic 1:4ab9f195e998 23 {
duchonic 1:4ab9f195e998 24 SetRegister(REG_D7_PWM, color.red); /* RED1 */
duchonic 1:4ab9f195e998 25 SetRegister(REG_D1_PWM, color.green); /* GREEN1 */
duchonic 1:4ab9f195e998 26 SetRegister(REG_D2_PWM, color.blue); /* BLUE1 */
duchonic 1:4ab9f195e998 27 break;
duchonic 1:4ab9f195e998 28 }
duchonic 1:4ab9f195e998 29 case LP55231_LED2:
duchonic 1:4ab9f195e998 30 {
duchonic 1:4ab9f195e998 31 SetRegister(REG_D8_PWM, color.red); /* RED2 */
duchonic 1:4ab9f195e998 32 SetRegister(REG_D3_PWM, color.green); /* GREEN2 */
duchonic 1:4ab9f195e998 33 SetRegister(REG_D4_PWM, color.blue); /* BLUE2 */
duchonic 1:4ab9f195e998 34 break;
duchonic 1:4ab9f195e998 35 }
duchonic 1:4ab9f195e998 36 case LP55231_LED3:
duchonic 1:4ab9f195e998 37 {
duchonic 1:4ab9f195e998 38 SetRegister(REG_D9_PWM, color.red); /* RED3 */
duchonic 1:4ab9f195e998 39 SetRegister(REG_D5_PWM, color.green); /* GREEN3 */
duchonic 1:4ab9f195e998 40 SetRegister(REG_D6_PWM, color.blue); /* BLUE3 */
duchonic 1:4ab9f195e998 41 break;
duchonic 1:4ab9f195e998 42 }
duchonic 1:4ab9f195e998 43 default:
duchonic 1:4ab9f195e998 44 {
duchonic 1:4ab9f195e998 45 ASSERT(0);
duchonic 1:4ab9f195e998 46 break;
duchonic 1:4ab9f195e998 47 }
duchonic 1:4ab9f195e998 48 }
duchonic 0:4ff4e0b7f25c 49 }
duchonic 0:4ff4e0b7f25c 50
duchonic 0:4ff4e0b7f25c 51 // --- Private Functions --- //
duchonic 0:4ff4e0b7f25c 52
duchonic 0:4ff4e0b7f25c 53 void LP55231::SetRegister(uint8_t registerAddr, uint8_t data)
duchonic 0:4ff4e0b7f25c 54 {
duchonic 0:4ff4e0b7f25c 55 char data_write[2];
duchonic 0:4ff4e0b7f25c 56 data_write[0] = registerAddr;
duchonic 0:4ff4e0b7f25c 57 data_write[1] = data;
duchonic 1:4ab9f195e998 58 m_i2c.write(m_addr, data_write, 2);
duchonic 0:4ff4e0b7f25c 59 }