RGB LED Driver demo

Dependents:   NJU6063_HelloWorld

Committer:
og
Date:
Sat Jan 09 07:39:52 2016 +0000
Revision:
1:bbc915c814da
Parent:
0:0283db13b7f1
Child:
2:137675ac48ab
add switch

Who changed what in which revision?

UserRevisionLine numberNew 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 0:0283db13b7f1 11
og 0:0283db13b7f1 12 #include "mbed.h"
og 0:0283db13b7f1 13 #define NJU6063_SLAVE 0x40
og 0:0283db13b7f1 14 #define EN 0x01
og 0:0283db13b7f1 15 #define EXT 0x02
og 0:0283db13b7f1 16 #define FDX1 0x00
og 0:0283db13b7f1 17 #define FDX2 0x04
og 0:0283db13b7f1 18 #define FDX4 0x08
og 0:0283db13b7f1 19 #define FDX8 0x0C
og 0:0283db13b7f1 20 #define FC1000KHZ 0x00
og 0:0283db13b7f1 21 #define FC1300KHZ 0x10
og 0:0283db13b7f1 22 #define FC800KHZ 0x20
og 0:0283db13b7f1 23 #define FC2200KHZ 0x30
og 0:0283db13b7f1 24 #define DMGP 0x80
og 0:0283db13b7f1 25 #define DO1 0x40
og 0:0283db13b7f1 26 #define ILED1OFF 0x00
og 0:0283db13b7f1 27 #define ILED1X1 0x03
og 0:0283db13b7f1 28 #define ILED1X05 0x02
og 0:0283db13b7f1 29 #define ILED1X025 0x01
og 0:0283db13b7f1 30 #define ILED2OFF 0x00
og 1:bbc915c814da 31 #define ILED2X1 0x03
og 1:bbc915c814da 32 #define ILED2X05 0x02
og 1:bbc915c814da 33 #define ILED2X025 0x01
og 0:0283db13b7f1 34 #define ILED3OFF 0x00
og 1:bbc915c814da 35 #define ILED3X1 0x03
og 1:bbc915c814da 36 #define ILED3X05 0x02
og 1:bbc915c814da 37 #define ILED3X025 0x01
og 0:0283db13b7f1 38 #define ALL 0xff
og 0:0283db13b7f1 39
og 0:0283db13b7f1 40 #define DEFAULTINIT FC800KHZ|FDX8|EN
og 0:0283db13b7f1 41
og 0:0283db13b7f1 42 class NJU6063
og 0:0283db13b7f1 43 {
og 0:0283db13b7f1 44 private:
og 0:0283db13b7f1 45 I2C _i2c;
og 0:0283db13b7f1 46 DigitalOut _rst;
og 0:0283db13b7f1 47 public:
og 1:bbc915c814da 48 /**
og 1:bbc915c814da 49 * @param sda I2C-bus SDA pin
og 1:bbc915c814da 50 * @param scl I2C-bus SCL pin
og 1:bbc915c814da 51 * @param rst Digital pin
og 1:bbc915c814da 52 */
og 0:0283db13b7f1 53 NJU6063( PinName sda, PinName scl, PinName rst);
og 1:bbc915c814da 54 /** Destructor of NJU6063
og 1:bbc915c814da 55 */
og 0:0283db13b7f1 56 ~NJU6063() {};
og 1:bbc915c814da 57 /** NJU6063 Reset
og 1:bbc915c814da 58 */
og 0:0283db13b7f1 59 void reset(void);
og 1:bbc915c814da 60 /** NJU6063 device addres set
og 1:bbc915c814da 61 * @param n Max number of device. 1 - 254
og 1:bbc915c814da 62 */
og 0:0283db13b7f1 63 void set_multi_device(uint8_t n);
og 1:bbc915c814da 64 /** NJU6063 Initial setting
og 1:bbc915c814da 65 * @param chip_addr target chip address
og 1:bbc915c814da 66 * @param d data
og 1:bbc915c814da 67 * 7 6 5 4 3 2 1 0
og 1:bbc915c814da 68 * DM DO FC1 FD0 FD1 FD0 EXT EN
og 1:bbc915c814da 69 * DM DO1 Function 0: Multi device control, 1: GPO
og 1:bbc915c814da 70 * DO The bit output to DO1
og 1:bbc915c814da 71 * FC OSC Frequency 0:1MHz, 1:1.3MHz, 2:2.2MHz, 3:0.8MHz
og 1:bbc915c814da 72 * FD divider 0:1/256, 1:1/512, 2:1/1024, 3:1/2048
og 1:bbc915c814da 73 * EXT OSC select 0:INT OSC, 1:EXT CLOCK
og 1:bbc915c814da 74 * EN 0:Disable, 1:Enable
og 1:bbc915c814da 75 */
og 0:0283db13b7f1 76 void init(uint8_t chip_addr, uint8_t d);
og 1:bbc915c814da 77 /** Set LED current
og 1:bbc915c814da 78 * @param chip_addr target chip address
og 1:bbc915c814da 79 * @param d1 led1 current set
og 1:bbc915c814da 80 * @param d2 led2 current set
og 1:bbc915c814da 81 * @param d3 led3 current set
og 1:bbc915c814da 82 * 0: LED off, 1: 0.25*ILED, 2: 0.5*ILED, 3: 1*ILED
og 1:bbc915c814da 83 */
og 0:0283db13b7f1 84 void set_iled(uint8_t chip_addr, uint8_t d1, uint8_t d2, uint8_t d3);
og 1:bbc915c814da 85 /** Set PWM Duty
og 1:bbc915c814da 86 * @param chip_addr target chip address
og 1:bbc915c814da 87 * @param d1 led1 pwm 0 - 0x7f (127/128)
og 1:bbc915c814da 88 * @param d2 led2 pwm 0 - 0x7f (127/128)
og 1:bbc915c814da 89 * @param d3 led3 pwm 0 - 0x7f (127/128)
og 1:bbc915c814da 90 * @param loop no of loop & no of step
og 1:bbc915c814da 91 * @param son led3 current set bit0:LED1, bit1:LED2, bit3:LED3
og 1:bbc915c814da 92 *
og 1:bbc915c814da 93 * STEP[6:4] 2^n , 0:1, 1:2, 2:4, 3:8, 4:16, 5:32, 6:1, 7:1
og 1:bbc915c814da 94 * LOOP[3:0] 4*(n+1) , 0:4 ... 15:64
og 1:bbc915c814da 95 */
og 0:0283db13b7f1 96 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 97 /** Dimming Start
og 1:bbc915c814da 98 * @param chip_addr target chip address
og 1:bbc915c814da 99 */
og 0:0283db13b7f1 100 void dim_start(uint8_t chip_addr);
og 1:bbc915c814da 101 /** Dimming stop
og 1:bbc915c814da 102 */
og 1:bbc915c814da 103 void dim_stop(uint8_t chip_addr);
og 1:bbc915c814da 104 /** Dimming check
og 1:bbc915c814da 105 */
og 1:bbc915c814da 106 void check_dim(void);
og 0:0283db13b7f1 107 };
og 0:0283db13b7f1 108
og 0:0283db13b7f1 109 #endif // MBED_NJU6063_H