RGB LED Driver demo
Dependents: NJU6063_HelloWorld
NJU6063.h@4:7a4b9d444b87, 2016-01-25 (annotated)
- Committer:
- og
- Date:
- Mon Jan 25 08:59:03 2016 +0000
- Revision:
- 4:7a4b9d444b87
- Parent:
- 3:f83202c2ae59
STM32F042K6 don't work
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
og | 0:0283db13b7f1 | 1 | /** @file NJU6063.h |
og | 1:bbc915c814da | 2 | * @author k.og |
og | 1:bbc915c814da | 3 | * @version 0.1 |
og | 1:bbc915c814da | 4 | * @date 26-Dec-2015 |
og | 1:bbc915c814da | 5 | * @brief mbed library to use a NJU6063 RGB LED driver |
og | 0:0283db13b7f1 | 6 | * http://www.njr.com/semicon/products/NJU6063.html |
og | 0:0283db13b7f1 | 7 | * interface: I2C |
og | 0:0283db13b7f1 | 8 | */ |
og | 0:0283db13b7f1 | 9 | #ifndef MBED_NJU6063_H |
og | 0:0283db13b7f1 | 10 | #define MBED_NJU6063_H |
og | 3:f83202c2ae59 | 11 | # |
og | 0:0283db13b7f1 | 12 | #include "mbed.h" |
og | 0:0283db13b7f1 | 13 | #define NJU6063_SLAVE 0x40 |
og | 3:f83202c2ae59 | 14 | #define NJU6063_INIT 0x00 |
og | 3:f83202c2ae59 | 15 | #define NJU6063_ILED 0x01 |
og | 3:f83202c2ae59 | 16 | #define NJU6063_PWM1 0x02 |
og | 3:f83202c2ae59 | 17 | #define NJU6063_PWM2 0x03 |
og | 3:f83202c2ae59 | 18 | #define NJU6063_PWM3 0x04 |
og | 3:f83202c2ae59 | 19 | #define NJU6063_DIMM 0x05 |
og | 3:f83202c2ae59 | 20 | #define NJU6063_STON 0x06 |
og | 3:f83202c2ae59 | 21 | #define NJU6063_START 0x07 |
og | 3:f83202c2ae59 | 22 | #define NJU6063_DCHK 0x0b |
og | 3:f83202c2ae59 | 23 | #define NJU6063_MADRES 0x0d |
og | 3:f83202c2ae59 | 24 | |
og | 0:0283db13b7f1 | 25 | |
og | 3:f83202c2ae59 | 26 | #define NJU6063_EN 0x01 |
og | 3:f83202c2ae59 | 27 | #define NJU6063_EXT 0x02 |
og | 3:f83202c2ae59 | 28 | #define NJU6063_FDX1 0x00 |
og | 3:f83202c2ae59 | 29 | #define NJU6063_FDX2 0x04 |
og | 3:f83202c2ae59 | 30 | #define NJU6063_FDX4 0x08 |
og | 3:f83202c2ae59 | 31 | #define NJU6063_FDX8 0x0C |
og | 3:f83202c2ae59 | 32 | #define NJU6063_FC1000KHZ 0x00 |
og | 3:f83202c2ae59 | 33 | #define NJU6063_FC1300KHZ 0x10 |
og | 3:f83202c2ae59 | 34 | #define NJU6063_FC800KHZ 0x20 |
og | 3:f83202c2ae59 | 35 | #define NJU6063_FC2200KHZ 0x30 |
og | 3:f83202c2ae59 | 36 | #define NJU6063_DMGP 0x80 |
og | 3:f83202c2ae59 | 37 | #define NJU6063_DO1 0x40 |
og | 3:f83202c2ae59 | 38 | #define NJU6063_ILED1OFF 0x00 |
og | 3:f83202c2ae59 | 39 | #define NJU6063_ILED1X1 0x03 |
og | 3:f83202c2ae59 | 40 | #define NJU6063_ILED1X05 0x02 |
og | 3:f83202c2ae59 | 41 | #define NJU6063_ILED1X025 0x01 |
og | 3:f83202c2ae59 | 42 | #define NJU6063_ILED2OFF 0x00 |
og | 3:f83202c2ae59 | 43 | #define NJU6063_ILED2X1 0x03 |
og | 3:f83202c2ae59 | 44 | #define NJU6063_ILED2X05 0x02 |
og | 3:f83202c2ae59 | 45 | #define NJU6063_ILED2X025 0x01 |
og | 3:f83202c2ae59 | 46 | #define NJU6063_ILED3OFF 0x00 |
og | 3:f83202c2ae59 | 47 | #define NJU6063_ILED3X1 0x03 |
og | 3:f83202c2ae59 | 48 | #define NJU6063_ILED3X05 0x02 |
og | 3:f83202c2ae59 | 49 | #define NJU6063_ILED3X025 0x01 |
og | 3:f83202c2ae59 | 50 | #define NJU6063_ALL 0xff |
og | 3:f83202c2ae59 | 51 | |
og | 3:f83202c2ae59 | 52 | #define NJU6063_DEFAULTINIT NJU6063_FC800KHZ|NJU6063_FDX8|NJU6063_EN |
og | 3:f83202c2ae59 | 53 | #define NJU6063_WAIT wait_us(500*3) |
og | 3:f83202c2ae59 | 54 | #define NJU6063_WAIT_MS wait_ms(200) |
og | 0:0283db13b7f1 | 55 | |
og | 0:0283db13b7f1 | 56 | class NJU6063 |
og | 0:0283db13b7f1 | 57 | { |
og | 0:0283db13b7f1 | 58 | private: |
og | 0:0283db13b7f1 | 59 | I2C _i2c; |
og | 3:f83202c2ae59 | 60 | //I2C_TypeDef* _myI2c; |
og | 3:f83202c2ae59 | 61 | //I2C_HandleTypeDef _myI2cH; |
og | 0:0283db13b7f1 | 62 | DigitalOut _rst; |
og | 2:137675ac48ab | 63 | int ack; |
og | 0:0283db13b7f1 | 64 | public: |
og | 1:bbc915c814da | 65 | /** |
og | 1:bbc915c814da | 66 | * @param sda I2C-bus SDA pin |
og | 1:bbc915c814da | 67 | * @param scl I2C-bus SCL pin |
og | 1:bbc915c814da | 68 | * @param rst Digital pin |
og | 1:bbc915c814da | 69 | */ |
og | 0:0283db13b7f1 | 70 | NJU6063( PinName sda, PinName scl, PinName rst); |
og | 1:bbc915c814da | 71 | /** Destructor of NJU6063 |
og | 1:bbc915c814da | 72 | */ |
og | 0:0283db13b7f1 | 73 | ~NJU6063() {}; |
og | 1:bbc915c814da | 74 | /** NJU6063 Reset |
og | 1:bbc915c814da | 75 | */ |
og | 0:0283db13b7f1 | 76 | void reset(void); |
og | 1:bbc915c814da | 77 | /** NJU6063 device addres set |
og | 1:bbc915c814da | 78 | * @param n Max number of device. 1 - 254 |
og | 1:bbc915c814da | 79 | */ |
og | 3:f83202c2ae59 | 80 | uint8_t set_multi_device(uint8_t n=0xfe); |
og | 1:bbc915c814da | 81 | /** NJU6063 Initial setting |
og | 1:bbc915c814da | 82 | * @param chip_addr target chip address |
og | 1:bbc915c814da | 83 | * @param d data |
og | 1:bbc915c814da | 84 | * 7 6 5 4 3 2 1 0 |
og | 1:bbc915c814da | 85 | * DM DO FC1 FD0 FD1 FD0 EXT EN |
og | 1:bbc915c814da | 86 | * DM DO1 Function 0: Multi device control, 1: GPO |
og | 1:bbc915c814da | 87 | * DO The bit output to DO1 |
og | 1:bbc915c814da | 88 | * FC OSC Frequency 0:1MHz, 1:1.3MHz, 2:2.2MHz, 3:0.8MHz |
og | 1:bbc915c814da | 89 | * FD divider 0:1/256, 1:1/512, 2:1/1024, 3:1/2048 |
og | 1:bbc915c814da | 90 | * EXT OSC select 0:INT OSC, 1:EXT CLOCK |
og | 1:bbc915c814da | 91 | * EN 0:Disable, 1:Enable |
og | 1:bbc915c814da | 92 | */ |
og | 0:0283db13b7f1 | 93 | void init(uint8_t chip_addr, uint8_t d); |
og | 1:bbc915c814da | 94 | /** Set LED current |
og | 1:bbc915c814da | 95 | * @param chip_addr target chip address |
og | 1:bbc915c814da | 96 | * @param d1 led1 current set |
og | 1:bbc915c814da | 97 | * @param d2 led2 current set |
og | 1:bbc915c814da | 98 | * @param d3 led3 current set |
og | 1:bbc915c814da | 99 | * 0: LED off, 1: 0.25*ILED, 2: 0.5*ILED, 3: 1*ILED |
og | 1:bbc915c814da | 100 | */ |
og | 0:0283db13b7f1 | 101 | void set_iled(uint8_t chip_addr, uint8_t d1, uint8_t d2, uint8_t d3); |
og | 1:bbc915c814da | 102 | /** Set PWM Duty |
og | 1:bbc915c814da | 103 | * @param chip_addr target chip address |
og | 1:bbc915c814da | 104 | * @param d1 led1 pwm 0 - 0x7f (127/128) |
og | 1:bbc915c814da | 105 | * @param d2 led2 pwm 0 - 0x7f (127/128) |
og | 1:bbc915c814da | 106 | * @param d3 led3 pwm 0 - 0x7f (127/128) |
og | 1:bbc915c814da | 107 | * @param loop no of loop & no of step |
og | 1:bbc915c814da | 108 | * @param son led3 current set bit0:LED1, bit1:LED2, bit3:LED3 |
og | 1:bbc915c814da | 109 | * |
og | 1:bbc915c814da | 110 | * STEP[6:4] 2^n , 0:1, 1:2, 2:4, 3:8, 4:16, 5:32, 6:1, 7:1 |
og | 1:bbc915c814da | 111 | * LOOP[3:0] 4*(n+1) , 0:4 ... 15:64 |
og | 1:bbc915c814da | 112 | */ |
og | 0:0283db13b7f1 | 113 | void set_pwm(uint8_t chip_addr, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t loop=0x5f, uint8_t son=0x00); |
og | 1:bbc915c814da | 114 | /** Dimming Start |
og | 1:bbc915c814da | 115 | * @param chip_addr target chip address |
og | 1:bbc915c814da | 116 | */ |
og | 0:0283db13b7f1 | 117 | void dim_start(uint8_t chip_addr); |
og | 1:bbc915c814da | 118 | /** Dimming stop |
og | 1:bbc915c814da | 119 | */ |
og | 1:bbc915c814da | 120 | void dim_stop(uint8_t chip_addr); |
og | 1:bbc915c814da | 121 | /** Dimming check |
og | 1:bbc915c814da | 122 | */ |
og | 1:bbc915c814da | 123 | void check_dim(void); |
og | 0:0283db13b7f1 | 124 | }; |
og | 0:0283db13b7f1 | 125 | |
og | 0:0283db13b7f1 | 126 | #endif // MBED_NJU6063_H |