Frederick Huang / Mbed OS LD100-Examples-201907

Dependencies:   libmDot-mbed5 ISL29011

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LD100_util.cpp Source File

LD100_util.cpp

00001 #include "LD100_util.h"
00002 
00003 void LED_D6(bool OnOff)
00004 { 
00005    DigitalOut LED6(D2);
00006    if (OnOff) 
00007     LED6 = 1;
00008    else
00009     LED6 = 0;
00010 }
00011 
00012 DigitalOut resetPin(PA_4);
00013 
00014 int TCA6424_init(I2C& i2c_port)
00015 {
00016     char cmd[4];
00017     const int saddr = 0x22 << 1;
00018     resetPin = 1;
00019     wait_ms(1);    
00020     resetPin = 0;
00021     wait_ms(1);    
00022     resetPin = 1;
00023     wait_ms(1);    
00024    
00025     cmd[0]= 0x05; //Output port 1 
00026     cmd[1]&= 0x9F; //10011111, set P15, P16 to output low
00027     i2c_port.write(saddr, cmd, 2);
00028         
00029     cmd[0]= 0x0D; //Configuration port 1 
00030     cmd[1]= 0x9F; //10011111, turn P15, P16 to output pin
00031     i2c_port.write(saddr, cmd, 2);
00032   return 0;
00033 }
00034 
00035 
00036 int TCA6424_init()
00037 {
00038   I2C i2c_port(I2C_SDA, I2C_SCL);
00039   return TCA6424_init(i2c_port);
00040 }
00041 
00042 void LED_D4(bool OnOff)
00043 { 
00044    char cmd[4];
00045    const int saddr = 0x22 << 1;
00046    I2C i2c_port(I2C_SDA, I2C_SCL);
00047   
00048    cmd[0]= 0x05; //Output port 1 
00049    i2c_port.write(saddr, cmd, 1);        
00050    i2c_port.read(saddr, cmd + 1, 1);  //read recent state
00051     
00052    cmd[0]= 0x05; //Output port 1 
00053    if (OnOff)
00054     cmd[1]|= 0x40; //01000000, set P16 to output High
00055    else
00056     cmd[1]&= 0xBF; //10111111, set P16 to output low
00057    i2c_port.write(saddr, cmd, 2);
00058 }
00059 
00060 void LED_D5(bool OnOff)
00061 { 
00062    char cmd[4];
00063    const int saddr = 0x22 << 1;
00064    I2C i2c_port(I2C_SDA, I2C_SCL);
00065   
00066    cmd[0]= 0x05; //Output port 1 
00067    i2c_port.write(saddr, cmd, 1);        
00068    i2c_port.read(saddr, cmd + 1, 1);  //read recent state
00069     
00070    cmd[0]= 0x05; //Output port 1 
00071    if (OnOff)
00072     cmd[1]|= 0x20; //00100000, set P15 to output High
00073    else
00074     cmd[1]&= 0xDF; //11011111, set P15 to output low
00075    i2c_port.write(saddr, cmd, 2);
00076 }
00077 
00078 
00079 //#define Pin_Charging    IOExpander,ugt::TCA6424_IOPin::P15
00080 //#define Pin_ChargeDone  IOExpander,ugt::TCA6424_IOPin::P16