Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# pca9532.c

    00001
    00002 // system includes
    00003 #include "global.h"
    00004
    00005 // local includes
    00006 #include "i2c.h"
    00007 #include "pca9532.h"
    00008
    00009 // functions
    00010 void pca9532Init(u08 node)
    00011 {
    00012     u08 packet[2];
    00013
    00014     // reset all registers to default state
    00015     packet[1] = 0;
    00016     packet[0] = PCA9532_REG_LS0;
    00017     i2cMasterSend(PCA9532_I2C_BASE_ADDR|node, 2, packet);
    00018     packet[0] = PCA9532_REG_LS1;
    00019     i2cMasterSend(PCA9532_I2C_BASE_ADDR|node, 2, packet);
    00020     packet[0] = PCA9532_REG_LS2;
    00021     i2cMasterSend(PCA9532_I2C_BASE_ADDR|node, 2, packet);
    00022     packet[0] = PCA9532_REG_LS3;
    00023     i2cMasterSend(PCA9532_I2C_BASE_ADDR|node, 2, packet);
    00024
    00025     pca9532SetFreq(node, 0, 0);
    00026     pca9532SetFreq(node, 1, 0);
    00027     pca9532SetPWM(node, 0, 0);
    00028     pca9532SetPWM(node, 1, 0);
    00029 }
    00030
    00031 void pca9532SetPinState(u08 node, u08 pin, u08 state)
    00032 {
    00033     u08 packet[2];
    00034
    00035     // determine the register to access
    00036     packet[0] = PCA9532_REG_LS0+(pin/4);
    00037     // get the current state
    00038     i2cMasterSend(PCA9532_I2C_BASE_ADDR|node, 1, &packet[0]);
    00039     i2cMasterReceive(PCA9532_I2C_BASE_ADDR|node, 1, &packet[1]);
    00040     // clear old state and set new one
    00041     packet[1] &= ~(3<<((pin%4)*2));
    00042     packet[1] |= state<<((pin%4)*2);
    00043     // write back to device
    00044     i2cMasterSend(PCA9532_I2C_BASE_ADDR|node, 2, packet);
    00045 }
    00046
    00047 void pca9532SetFreq(u08 node, u08 ch, u08 period)
    00048 {
    00049     u08 packet[2];
    00050     packet[0] = PCA9532_REG_PSC0+(ch<<1);
    00051     packet[1] = period;
    00052     i2cMasterSend(PCA9532_I2C_BASE_ADDR|node, 2, packet);
    00053 }
    00054
    00055 void pca9532SetPWM(u08 node, u08 ch, u08 duty)
    00056 {
    00057     u08 packet[2];
    00058     packet[0] = PCA9532_REG_PWM0+(ch<<1);
    00059     packet[1] = duty;
    00060     i2cMasterSend(PCA9532_I2C_BASE_ADDR|node, 2, packet);
    00061 }
    00062
    00063 u16 pca9532GetInput(u08 node)
    00064 {
    00065     return 0;
    00066 }