RGB LED Driver demo

Dependents:   NJU6063_HelloWorld

Committer:
og
Date:
Sun Jan 10 11:49:59 2016 +0000
Revision:
2:137675ac48ab
Parent:
1:bbc915c814da
Child:
3:f83202c2ae59
F401 test

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 2:137675ac48ab 46 I2C_TypeDef* _i2c_type;
og 0:0283db13b7f1 47 DigitalOut _rst;
og 2:137675ac48ab 48 int ack;
og 2:137675ac48ab 49 uint32_t* _i2c_cr1;
og 2:137675ac48ab 50 uint32_t* _i2c_cr2;
og 2:137675ac48ab 51 uint32_t* _i2c_dr;
og 2:137675ac48ab 52 uint32_t* _i2c_sr1;
og 2:137675ac48ab 53 uint32_t* _i2c_sr2;
og 2:137675ac48ab 54 void SetCR1(uint16_t data) { *_i2c_cr1 |= data;}
og 2:137675ac48ab 55 void SetCR2(uint16_t data) { *_i2c_cr2 |= data;}
og 2:137675ac48ab 56 void TxDR(uint8_t data) { *_i2c_dr = data; }
og 0:0283db13b7f1 57 public:
og 1:bbc915c814da 58 /**
og 1:bbc915c814da 59 * @param sda I2C-bus SDA pin
og 1:bbc915c814da 60 * @param scl I2C-bus SCL pin
og 1:bbc915c814da 61 * @param rst Digital pin
og 1:bbc915c814da 62 */
og 0:0283db13b7f1 63 NJU6063( PinName sda, PinName scl, PinName rst);
og 1:bbc915c814da 64 /** Destructor of NJU6063
og 1:bbc915c814da 65 */
og 0:0283db13b7f1 66 ~NJU6063() {};
og 1:bbc915c814da 67 /** NJU6063 Reset
og 1:bbc915c814da 68 */
og 0:0283db13b7f1 69 void reset(void);
og 1:bbc915c814da 70 /** NJU6063 device addres set
og 1:bbc915c814da 71 * @param n Max number of device. 1 - 254
og 1:bbc915c814da 72 */
og 2:137675ac48ab 73 uint8_t set_multi_device(uint8_t n);
og 1:bbc915c814da 74 /** NJU6063 Initial setting
og 1:bbc915c814da 75 * @param chip_addr target chip address
og 1:bbc915c814da 76 * @param d data
og 1:bbc915c814da 77 * 7 6 5 4 3 2 1 0
og 1:bbc915c814da 78 * DM DO FC1 FD0 FD1 FD0 EXT EN
og 1:bbc915c814da 79 * DM DO1 Function 0: Multi device control, 1: GPO
og 1:bbc915c814da 80 * DO The bit output to DO1
og 1:bbc915c814da 81 * FC OSC Frequency 0:1MHz, 1:1.3MHz, 2:2.2MHz, 3:0.8MHz
og 1:bbc915c814da 82 * FD divider 0:1/256, 1:1/512, 2:1/1024, 3:1/2048
og 1:bbc915c814da 83 * EXT OSC select 0:INT OSC, 1:EXT CLOCK
og 1:bbc915c814da 84 * EN 0:Disable, 1:Enable
og 1:bbc915c814da 85 */
og 0:0283db13b7f1 86 void init(uint8_t chip_addr, uint8_t d);
og 1:bbc915c814da 87 /** Set LED current
og 1:bbc915c814da 88 * @param chip_addr target chip address
og 1:bbc915c814da 89 * @param d1 led1 current set
og 1:bbc915c814da 90 * @param d2 led2 current set
og 1:bbc915c814da 91 * @param d3 led3 current set
og 1:bbc915c814da 92 * 0: LED off, 1: 0.25*ILED, 2: 0.5*ILED, 3: 1*ILED
og 1:bbc915c814da 93 */
og 0:0283db13b7f1 94 void set_iled(uint8_t chip_addr, uint8_t d1, uint8_t d2, uint8_t d3);
og 1:bbc915c814da 95 /** Set PWM Duty
og 1:bbc915c814da 96 * @param chip_addr target chip address
og 1:bbc915c814da 97 * @param d1 led1 pwm 0 - 0x7f (127/128)
og 1:bbc915c814da 98 * @param d2 led2 pwm 0 - 0x7f (127/128)
og 1:bbc915c814da 99 * @param d3 led3 pwm 0 - 0x7f (127/128)
og 1:bbc915c814da 100 * @param loop no of loop & no of step
og 1:bbc915c814da 101 * @param son led3 current set bit0:LED1, bit1:LED2, bit3:LED3
og 1:bbc915c814da 102 *
og 1:bbc915c814da 103 * STEP[6:4] 2^n , 0:1, 1:2, 2:4, 3:8, 4:16, 5:32, 6:1, 7:1
og 1:bbc915c814da 104 * LOOP[3:0] 4*(n+1) , 0:4 ... 15:64
og 1:bbc915c814da 105 */
og 0:0283db13b7f1 106 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 107 /** Dimming Start
og 1:bbc915c814da 108 * @param chip_addr target chip address
og 1:bbc915c814da 109 */
og 0:0283db13b7f1 110 void dim_start(uint8_t chip_addr);
og 1:bbc915c814da 111 /** Dimming stop
og 1:bbc915c814da 112 */
og 1:bbc915c814da 113 void dim_stop(uint8_t chip_addr);
og 1:bbc915c814da 114 /** Dimming check
og 1:bbc915c814da 115 */
og 1:bbc915c814da 116 void check_dim(void);
og 0:0283db13b7f1 117 };
og 0:0283db13b7f1 118
og 0:0283db13b7f1 119 #endif // MBED_NJU6063_H