LP55231 driver
LP55231.cpp@2:79b94bf1cf59, 2018-08-22 (annotated)
- Committer:
- duchonic
- Date:
- Wed Aug 22 16:13:56 2018 +0000
- Revision:
- 2:79b94bf1cf59
- Parent:
- 1:4ab9f195e998
documentation added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
duchonic | 2:79b94bf1cf59 | 1 | /** |
duchonic | 2:79b94bf1cf59 | 2 | * @file LP55231.cpp |
duchonic | 2:79b94bf1cf59 | 3 | * |
duchonic | 2:79b94bf1cf59 | 4 | */ |
duchonic | 2:79b94bf1cf59 | 5 | |
duchonic | 0:4ff4e0b7f25c | 6 | #include "LP55231.h" |
duchonic | 1:4ab9f195e998 | 7 | #include "main.h" |
duchonic | 0:4ff4e0b7f25c | 8 | |
duchonic | 0:4ff4e0b7f25c | 9 | LP55231::LP55231(PinName sda, PinName scl, uint8_t addr) : m_i2c(sda, scl), m_addr(addr) {} |
duchonic | 0:4ff4e0b7f25c | 10 | |
duchonic | 0:4ff4e0b7f25c | 11 | uint8_t LP55231::LP55231_Init(void){ |
duchonic | 0:4ff4e0b7f25c | 12 | |
duchonic | 0:4ff4e0b7f25c | 13 | SetRegister(REG_ENGINE_CNTRL1, 0x40); |
duchonic | 0:4ff4e0b7f25c | 14 | SetRegister(REG_MISC, 0x53); |
duchonic | 0:4ff4e0b7f25c | 15 | |
duchonic | 0:4ff4e0b7f25c | 16 | return 0; |
duchonic | 0:4ff4e0b7f25c | 17 | } |
duchonic | 0:4ff4e0b7f25c | 18 | |
duchonic | 0:4ff4e0b7f25c | 19 | LP55231::~LP55231(void) { |
duchonic | 0:4ff4e0b7f25c | 20 | }; |
duchonic | 0:4ff4e0b7f25c | 21 | |
duchonic | 0:4ff4e0b7f25c | 22 | |
duchonic | 1:4ab9f195e998 | 23 | void LP55231::LP55231_SetLed(LP55231_leds led, LP55231_colors color) |
duchonic | 0:4ff4e0b7f25c | 24 | { |
duchonic | 1:4ab9f195e998 | 25 | switch(led) |
duchonic | 1:4ab9f195e998 | 26 | { |
duchonic | 1:4ab9f195e998 | 27 | case LP55231_LED1: |
duchonic | 1:4ab9f195e998 | 28 | { |
duchonic | 1:4ab9f195e998 | 29 | SetRegister(REG_D7_PWM, color.red); /* RED1 */ |
duchonic | 1:4ab9f195e998 | 30 | SetRegister(REG_D1_PWM, color.green); /* GREEN1 */ |
duchonic | 1:4ab9f195e998 | 31 | SetRegister(REG_D2_PWM, color.blue); /* BLUE1 */ |
duchonic | 1:4ab9f195e998 | 32 | break; |
duchonic | 1:4ab9f195e998 | 33 | } |
duchonic | 1:4ab9f195e998 | 34 | case LP55231_LED2: |
duchonic | 1:4ab9f195e998 | 35 | { |
duchonic | 1:4ab9f195e998 | 36 | SetRegister(REG_D8_PWM, color.red); /* RED2 */ |
duchonic | 1:4ab9f195e998 | 37 | SetRegister(REG_D3_PWM, color.green); /* GREEN2 */ |
duchonic | 1:4ab9f195e998 | 38 | SetRegister(REG_D4_PWM, color.blue); /* BLUE2 */ |
duchonic | 1:4ab9f195e998 | 39 | break; |
duchonic | 1:4ab9f195e998 | 40 | } |
duchonic | 1:4ab9f195e998 | 41 | case LP55231_LED3: |
duchonic | 1:4ab9f195e998 | 42 | { |
duchonic | 1:4ab9f195e998 | 43 | SetRegister(REG_D9_PWM, color.red); /* RED3 */ |
duchonic | 1:4ab9f195e998 | 44 | SetRegister(REG_D5_PWM, color.green); /* GREEN3 */ |
duchonic | 1:4ab9f195e998 | 45 | SetRegister(REG_D6_PWM, color.blue); /* BLUE3 */ |
duchonic | 1:4ab9f195e998 | 46 | break; |
duchonic | 1:4ab9f195e998 | 47 | } |
duchonic | 1:4ab9f195e998 | 48 | default: |
duchonic | 1:4ab9f195e998 | 49 | { |
duchonic | 1:4ab9f195e998 | 50 | ASSERT(0); |
duchonic | 1:4ab9f195e998 | 51 | break; |
duchonic | 1:4ab9f195e998 | 52 | } |
duchonic | 1:4ab9f195e998 | 53 | } |
duchonic | 0:4ff4e0b7f25c | 54 | } |
duchonic | 0:4ff4e0b7f25c | 55 | |
duchonic | 0:4ff4e0b7f25c | 56 | // --- Private Functions --- // |
duchonic | 0:4ff4e0b7f25c | 57 | |
duchonic | 0:4ff4e0b7f25c | 58 | void LP55231::SetRegister(uint8_t registerAddr, uint8_t data) |
duchonic | 0:4ff4e0b7f25c | 59 | { |
duchonic | 0:4ff4e0b7f25c | 60 | char data_write[2]; |
duchonic | 0:4ff4e0b7f25c | 61 | data_write[0] = registerAddr; |
duchonic | 0:4ff4e0b7f25c | 62 | data_write[1] = data; |
duchonic | 1:4ab9f195e998 | 63 | m_i2c.write(m_addr, data_write, 2); |
duchonic | 0:4ff4e0b7f25c | 64 | } |