RGB LED Driver demo
Dependents: NJU6063_HelloWorld
NJU6063.h
00001 /** @file NJU6063.h 00002 * @author k.og 00003 * @version 0.1 00004 * @date 26-Dec-2015 00005 * @brief mbed library to use a NJU6063 RGB LED driver 00006 * http://www.njr.com/semicon/products/NJU6063.html 00007 * interface: I2C 00008 */ 00009 #ifndef MBED_NJU6063_H 00010 #define MBED_NJU6063_H 00011 # 00012 #include "mbed.h" 00013 #define NJU6063_SLAVE 0x40 00014 #define NJU6063_INIT 0x00 00015 #define NJU6063_ILED 0x01 00016 #define NJU6063_PWM1 0x02 00017 #define NJU6063_PWM2 0x03 00018 #define NJU6063_PWM3 0x04 00019 #define NJU6063_DIMM 0x05 00020 #define NJU6063_STON 0x06 00021 #define NJU6063_START 0x07 00022 #define NJU6063_DCHK 0x0b 00023 #define NJU6063_MADRES 0x0d 00024 00025 00026 #define NJU6063_EN 0x01 00027 #define NJU6063_EXT 0x02 00028 #define NJU6063_FDX1 0x00 00029 #define NJU6063_FDX2 0x04 00030 #define NJU6063_FDX4 0x08 00031 #define NJU6063_FDX8 0x0C 00032 #define NJU6063_FC1000KHZ 0x00 00033 #define NJU6063_FC1300KHZ 0x10 00034 #define NJU6063_FC800KHZ 0x20 00035 #define NJU6063_FC2200KHZ 0x30 00036 #define NJU6063_DMGP 0x80 00037 #define NJU6063_DO1 0x40 00038 #define NJU6063_ILED1OFF 0x00 00039 #define NJU6063_ILED1X1 0x03 00040 #define NJU6063_ILED1X05 0x02 00041 #define NJU6063_ILED1X025 0x01 00042 #define NJU6063_ILED2OFF 0x00 00043 #define NJU6063_ILED2X1 0x03 00044 #define NJU6063_ILED2X05 0x02 00045 #define NJU6063_ILED2X025 0x01 00046 #define NJU6063_ILED3OFF 0x00 00047 #define NJU6063_ILED3X1 0x03 00048 #define NJU6063_ILED3X05 0x02 00049 #define NJU6063_ILED3X025 0x01 00050 #define NJU6063_ALL 0xff 00051 00052 #define NJU6063_DEFAULTINIT NJU6063_FC800KHZ|NJU6063_FDX8|NJU6063_EN 00053 #define NJU6063_WAIT wait_us(500*3) 00054 #define NJU6063_WAIT_MS wait_ms(200) 00055 00056 class NJU6063 00057 { 00058 private: 00059 I2C _i2c; 00060 //I2C_TypeDef* _myI2c; 00061 //I2C_HandleTypeDef _myI2cH; 00062 DigitalOut _rst; 00063 int ack; 00064 public: 00065 /** 00066 * @param sda I2C-bus SDA pin 00067 * @param scl I2C-bus SCL pin 00068 * @param rst Digital pin 00069 */ 00070 NJU6063( PinName sda, PinName scl, PinName rst); 00071 /** Destructor of NJU6063 00072 */ 00073 ~NJU6063() {}; 00074 /** NJU6063 Reset 00075 */ 00076 void reset(void); 00077 /** NJU6063 device addres set 00078 * @param n Max number of device. 1 - 254 00079 */ 00080 uint8_t set_multi_device(uint8_t n=0xfe); 00081 /** NJU6063 Initial setting 00082 * @param chip_addr target chip address 00083 * @param d data 00084 * 7 6 5 4 3 2 1 0 00085 * DM DO FC1 FD0 FD1 FD0 EXT EN 00086 * DM DO1 Function 0: Multi device control, 1: GPO 00087 * DO The bit output to DO1 00088 * FC OSC Frequency 0:1MHz, 1:1.3MHz, 2:2.2MHz, 3:0.8MHz 00089 * FD divider 0:1/256, 1:1/512, 2:1/1024, 3:1/2048 00090 * EXT OSC select 0:INT OSC, 1:EXT CLOCK 00091 * EN 0:Disable, 1:Enable 00092 */ 00093 void init(uint8_t chip_addr, uint8_t d); 00094 /** Set LED current 00095 * @param chip_addr target chip address 00096 * @param d1 led1 current set 00097 * @param d2 led2 current set 00098 * @param d3 led3 current set 00099 * 0: LED off, 1: 0.25*ILED, 2: 0.5*ILED, 3: 1*ILED 00100 */ 00101 void set_iled(uint8_t chip_addr, uint8_t d1, uint8_t d2, uint8_t d3); 00102 /** Set PWM Duty 00103 * @param chip_addr target chip address 00104 * @param d1 led1 pwm 0 - 0x7f (127/128) 00105 * @param d2 led2 pwm 0 - 0x7f (127/128) 00106 * @param d3 led3 pwm 0 - 0x7f (127/128) 00107 * @param loop no of loop & no of step 00108 * @param son led3 current set bit0:LED1, bit1:LED2, bit3:LED3 00109 * 00110 * STEP[6:4] 2^n , 0:1, 1:2, 2:4, 3:8, 4:16, 5:32, 6:1, 7:1 00111 * LOOP[3:0] 4*(n+1) , 0:4 ... 15:64 00112 */ 00113 void set_pwm(uint8_t chip_addr, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t loop=0x5f, uint8_t son=0x00); 00114 /** Dimming Start 00115 * @param chip_addr target chip address 00116 */ 00117 void dim_start(uint8_t chip_addr); 00118 /** Dimming stop 00119 */ 00120 void dim_stop(uint8_t chip_addr); 00121 /** Dimming check 00122 */ 00123 void check_dim(void); 00124 }; 00125 00126 #endif // MBED_NJU6063_H
Generated on Tue Jul 19 2022 00:28:04 by 1.7.2