LP55231 driver
LP55231.h@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.h |
duchonic | 2:79b94bf1cf59 | 3 | * @brief Library for LP55231 |
duchonic | 2:79b94bf1cf59 | 4 | * Version for mbed |
duchonic | 2:79b94bf1cf59 | 5 | * Nicolas Duchoud 22/08/2018 |
duchonic | 2:79b94bf1cf59 | 6 | * |
duchonic | 2:79b94bf1cf59 | 7 | * |
duchonic | 2:79b94bf1cf59 | 8 | * In this file are the function prototypes in the LP55231 class |
duchonic | 2:79b94bf1cf59 | 9 | * |
duchonic | 2:79b94bf1cf59 | 10 | * This code is beerware. If you see me (or any other SparkFun employee) at the |
duchonic | 2:79b94bf1cf59 | 11 | * local pub, and you've found our code helpful, please buy us a round! |
duchonic | 2:79b94bf1cf59 | 12 | * |
duchonic | 2:79b94bf1cf59 | 13 | * Distributed as-is; no warranty is given. |
duchonic | 2:79b94bf1cf59 | 14 | */ |
duchonic | 0:4ff4e0b7f25c | 15 | #include "mbed.h" |
duchonic | 0:4ff4e0b7f25c | 16 | |
duchonic | 0:4ff4e0b7f25c | 17 | #ifndef LP55231_h |
duchonic | 0:4ff4e0b7f25c | 18 | #define LP55231_h |
duchonic | 0:4ff4e0b7f25c | 19 | |
duchonic | 0:4ff4e0b7f25c | 20 | #define REG_ENGINE_CNTRL1 (0x00) |
duchonic | 0:4ff4e0b7f25c | 21 | #define REG_MISC (0x36) |
duchonic | 1:4ab9f195e998 | 22 | |
duchonic | 0:4ff4e0b7f25c | 23 | #define REG_D1_PWM (0x16) /* GREEN1 */ |
duchonic | 0:4ff4e0b7f25c | 24 | #define REG_D2_PWM (0x17) /* BLUE1 */ |
duchonic | 1:4ab9f195e998 | 25 | #define REG_D3_PWM (0x18) /* GREEN2 */ |
duchonic | 1:4ab9f195e998 | 26 | #define REG_D4_PWM (0x19) /* BLUE2 */ |
duchonic | 1:4ab9f195e998 | 27 | #define REG_D5_PWM (0x1A) /* GREEN3 */ |
duchonic | 1:4ab9f195e998 | 28 | #define REG_D6_PWM (0x1B) /* BLUE3 */ |
duchonic | 0:4ff4e0b7f25c | 29 | #define REG_D7_PWM (0x1C) /* RED1 */ |
duchonic | 1:4ab9f195e998 | 30 | #define REG_D8_PWM (0x1D) /* RED2 */ |
duchonic | 1:4ab9f195e998 | 31 | #define REG_D9_PWM (0x1E) /* RED3 */ |
duchonic | 1:4ab9f195e998 | 32 | |
duchonic | 2:79b94bf1cf59 | 33 | /** |
duchonic | 2:79b94bf1cf59 | 34 | * led enums |
duchonic | 2:79b94bf1cf59 | 35 | */ |
duchonic | 1:4ab9f195e998 | 36 | enum LP55231_leds |
duchonic | 1:4ab9f195e998 | 37 | { |
duchonic | 2:79b94bf1cf59 | 38 | /** led1 on board */ |
duchonic | 1:4ab9f195e998 | 39 | LP55231_LED1 = 0, |
duchonic | 2:79b94bf1cf59 | 40 | /** led2 on board */ |
duchonic | 2:79b94bf1cf59 | 41 | LP55231_LED2, |
duchonic | 2:79b94bf1cf59 | 42 | /** led3 on board */ |
duchonic | 2:79b94bf1cf59 | 43 | LP55231_LED3, |
duchonic | 1:4ab9f195e998 | 44 | }; |
duchonic | 1:4ab9f195e998 | 45 | |
duchonic | 2:79b94bf1cf59 | 46 | /** |
duchonic | 2:79b94bf1cf59 | 47 | * struct led colors |
duchonic | 2:79b94bf1cf59 | 48 | */ |
duchonic | 1:4ab9f195e998 | 49 | struct LP55231_colors |
duchonic | 1:4ab9f195e998 | 50 | { |
duchonic | 2:79b94bf1cf59 | 51 | /** color red */ |
duchonic | 1:4ab9f195e998 | 52 | uint8_t red; |
duchonic | 2:79b94bf1cf59 | 53 | /** color green */ |
duchonic | 1:4ab9f195e998 | 54 | uint8_t green; |
duchonic | 2:79b94bf1cf59 | 55 | /** color blue */ |
duchonic | 1:4ab9f195e998 | 56 | uint8_t blue; |
duchonic | 1:4ab9f195e998 | 57 | }; |
duchonic | 1:4ab9f195e998 | 58 | |
duchonic | 2:79b94bf1cf59 | 59 | /** My LP55231 class. |
duchonic | 2:79b94bf1cf59 | 60 | * |
duchonic | 2:79b94bf1cf59 | 61 | * Example: |
duchonic | 2:79b94bf1cf59 | 62 | * @code |
duchonic | 2:79b94bf1cf59 | 63 | * #include "mbed.h" |
duchonic | 2:79b94bf1cf59 | 64 | * #include <LP55231.h> |
duchonic | 2:79b94bf1cf59 | 65 | * |
duchonic | 2:79b94bf1cf59 | 66 | * LP55231 board(I2C_SDA, I2C_SCL, LP55231_I2C_ADDR<<1); |
duchonic | 2:79b94bf1cf59 | 67 | * |
duchonic | 2:79b94bf1cf59 | 68 | * struct LP55231_colors color = {50,100,0}; |
duchonic | 2:79b94bf1cf59 | 69 | * |
duchonic | 2:79b94bf1cf59 | 70 | * if(board.LP55231_Init() != 0) |
duchonic | 2:79b94bf1cf59 | 71 | * { |
duchonic | 2:79b94bf1cf59 | 72 | * printf("FAILED TO INITALIZE\n"); |
duchonic | 2:79b94bf1cf59 | 73 | * }; |
duchonic | 2:79b94bf1cf59 | 74 | * |
duchonic | 2:79b94bf1cf59 | 75 | * board.LP55231_SetLed(LP55231_LED1, color); |
duchonic | 2:79b94bf1cf59 | 76 | * |
duchonic | 2:79b94bf1cf59 | 77 | * @endcode |
duchonic | 2:79b94bf1cf59 | 78 | */ |
duchonic | 0:4ff4e0b7f25c | 79 | class LP55231 |
duchonic | 0:4ff4e0b7f25c | 80 | { |
duchonic | 0:4ff4e0b7f25c | 81 | public: |
duchonic | 0:4ff4e0b7f25c | 82 | |
duchonic | 2:79b94bf1cf59 | 83 | /** |
duchonic | 2:79b94bf1cf59 | 84 | * constructor of LP55231 |
duchonic | 2:79b94bf1cf59 | 85 | * |
duchonic | 2:79b94bf1cf59 | 86 | * @param sda SDA pin |
duchonic | 2:79b94bf1cf59 | 87 | * @param sdl SCL pin |
duchonic | 2:79b94bf1cf59 | 88 | * @param addr (7 bit) address of the I2C peripheral |
duchonic | 0:4ff4e0b7f25c | 89 | */ |
duchonic | 0:4ff4e0b7f25c | 90 | LP55231(PinName sda, PinName scl, uint8_t addr); |
duchonic | 0:4ff4e0b7f25c | 91 | |
duchonic | 2:79b94bf1cf59 | 92 | /** deconstructor */ |
duchonic | 0:4ff4e0b7f25c | 93 | ~LP55231(); |
duchonic | 0:4ff4e0b7f25c | 94 | |
duchonic | 0:4ff4e0b7f25c | 95 | /** |
duchonic | 2:79b94bf1cf59 | 96 | * LP55231 Init |
duchonic | 2:79b94bf1cf59 | 97 | * @returns 0 if ok |
duchonic | 2:79b94bf1cf59 | 98 | * @returns -1 on error*/ |
duchonic | 0:4ff4e0b7f25c | 99 | */ |
duchonic | 0:4ff4e0b7f25c | 100 | uint8_t LP55231_Init(void); |
duchonic | 0:4ff4e0b7f25c | 101 | |
duchonic | 0:4ff4e0b7f25c | 102 | /** |
duchonic | 2:79b94bf1cf59 | 103 | * @param led led to set |
duchonic | 2:79b94bf1cf59 | 104 | * @param color color to set |
duchonic | 0:4ff4e0b7f25c | 105 | */ |
duchonic | 1:4ab9f195e998 | 106 | void LP55231_SetLed(LP55231_leds led, LP55231_colors color); |
duchonic | 0:4ff4e0b7f25c | 107 | |
duchonic | 0:4ff4e0b7f25c | 108 | private: |
duchonic | 2:79b94bf1cf59 | 109 | /** i2c handler */ |
duchonic | 0:4ff4e0b7f25c | 110 | I2C m_i2c; |
duchonic | 2:79b94bf1cf59 | 111 | /** i2c addr */ |
duchonic | 0:4ff4e0b7f25c | 112 | int m_addr; |
duchonic | 0:4ff4e0b7f25c | 113 | /** |
duchonic | 2:79b94bf1cf59 | 114 | * @param registerAddr |
duchonic | 2:79b94bf1cf59 | 115 | * @param data |
duchonic | 0:4ff4e0b7f25c | 116 | */ |
duchonic | 0:4ff4e0b7f25c | 117 | void SetRegister(uint8_t registerAddr, uint8_t data); |
duchonic | 0:4ff4e0b7f25c | 118 | |
duchonic | 0:4ff4e0b7f25c | 119 | }; |
duchonic | 0:4ff4e0b7f25c | 120 | |
duchonic | 0:4ff4e0b7f25c | 121 | |
duchonic | 0:4ff4e0b7f25c | 122 | #endif |