コード例 #1
0
ファイル: st_compass.c プロジェクト: mdunne/ANIMA
void st_compass_init(void) {
    //char response = 0;
    I2C_Init(100000);

    //while(1);
#ifdef DEBUG_VERBOSE
    printf("Awakening Device\r\n");
#endif
    //I2C_WriteReg(ACCEL_I2C_ADDRESS,CTRL_REG1_A,0b00010000);
    //st_ChangeMode(STMICRO_ACTIVEMODE);
    //printf("Control reg: %X",I2C_ReadReg(ACCEL_I2C_ADDRESS,CTRL_REG1_A));
    short testval = 0xDEAD;
    //printf("The value: %X and its switched counterpart %X",(short)testval,(short)switch_endedness(testval));
    //I2C_WriteReg(MAG_I2C_ADDRESS,CRA_REG_M,0b00011100);
    //I2C_WriteReg(MAG_I2C_ADDRESS,MR_REG_M,0);
    //st_mag_ChangeMode(ST_MAG_CONTINUOUS_MODE);
    Reg_Access.full_register = I2C_ReadReg(ACCEL_I2C_ADDRESS, CTRL_REG4_A);
    Reg_Access.CTRL_REG4_A.Endedness = 1;
    Reg_Access.CTRL_REG4_A.Block_Update = 0;
    Reg_Access.CTRL_REG4_A.resolution = 1;
    I2C_WriteReg(ACCEL_I2C_ADDRESS, CTRL_REG4_A, Reg_Access.full_register);
#ifdef DEBUG_VERBOSE
    printf("Device Awakened\r\n");
#endif
    
    return;


}
コード例 #2
0
ファイル: st_compass.c プロジェクト: mdunne/ANIMA
unsigned char st_mag_SetRate(char Rate) {
    Reg_Access.full_register = I2C_ReadReg(MAG_I2C_ADDRESS, CRA_REG_M);
    Reg_Access.ConReg_A.Rate = Rate;
    I2C_WriteReg(MAG_I2C_ADDRESS, CRA_REG_M, Reg_Access.full_register);

    return 0;

}
コード例 #3
0
ファイル: TSL_driver.c プロジェクト: jordonwu/HEXIWEAR
/**
 * disable the sensor
 */
void TSL_Disable()
{
  statusI2C_t
    status = I2C_WriteReg( &(self.protocol), TSL_COMMAND_BIT | TSL_REG_CONTROL, TSL_CONTROL_POWEROFF );

  if ( STATUS_I2C_SUCCESS != status )
  {
    catch(10);
  }
}
コード例 #4
0
ファイル: st_compass.c プロジェクト: mdunne/ANIMA
void st_mag_ChangeMode(char Mode) {

    Reg_Access.full_register = I2C_ReadReg(MAG_I2C_ADDRESS, MR_REG_M);
    printf("After reading of register\r\n");
    switch (Mode) {
        case ST_MAG_CONTINUOUS_MODE:
            Reg_Access.Mode_Reg.Mode = 0;
            I2C_WriteReg(MAG_I2C_ADDRESS, MR_REG_M, Reg_Access.full_register);
            break;
        case ST_MAG_SINGLE_MEASUREMENT_MODE:
            Reg_Access.Mode_Reg.Mode = 1;
            I2C_WriteReg(MAG_I2C_ADDRESS, MR_REG_M, Reg_Access.full_register);
            break;
        case ST_MAG_IDLE_MODE:
            Reg_Access.Mode_Reg.Mode = 2;
            I2C_WriteReg(MAG_I2C_ADDRESS, MR_REG_M, Reg_Access.full_register);
            break;
    }
}
コード例 #5
0
ファイル: st_compass.c プロジェクト: mdunne/ANIMA
unsigned char st_mag_SetGain(char newGain) {

    char regist, fun = CRB_REG_M;
    //st_mag_ChangeMode(st_mag_STANDBYMODE);
    Reg_Access.full_register = I2C_ReadReg(MAG_I2C_ADDRESS, CRB_REG_M);
    Reg_Access.ConReg_B.Gain = newGain;
    I2C_WriteReg(MAG_I2C_ADDRESS, CRB_REG_M, Reg_Access.full_register);
    //st_mag_ChangeMode(st_mag_ACTIVEMODE);
    return 0;

}
コード例 #6
0
ファイル: analog_accel.c プロジェクト: mdunne/ANIMA
void analog_accel_init(void) {
    char response = 0;
    I2C_Init(100000);

    printf("Awakening Device\r\n");
    I2C_WriteReg(I2C_ADDRESS,POWER_CTL, 1 << 3);
    //set the bandwidth to 400Hz
    I2C_WriteReg(I2C_ADDRESS,BW_RATE, 0xC);
    //set the output to full range
    I2C_WriteReg(I2C_ADDRESS,DATA_FORMAT, 1 << 2);
    //analog_WriteReg(DATA_FORMAT,);
    //analog_ChangeMode(analog_ACTIVEMODE);
    printf("Device Awakened\r\n");
    //response = analog_ReadReg(CTRL_REG0);
    response |= 0x10;
    //analog_WriteReg(CTRL_REG0, response);
    //printf("Control Reg 0: %X",CTRL_REG0);
    return;


}
コード例 #7
0
ファイル: st_compass.c プロジェクト: mdunne/ANIMA
unsigned char st_accel_SetRate(char Rate) {
    char regist;
    Reg_Access.full_register = I2C_ReadReg(ACCEL_I2C_ADDRESS, CTRL_REG1_A);
    Reg_Access.CTRL_REG1_A.Rate = Rate;
    //printf("status of axis: %d%d%d\r\n",Reg_Access.CTRL_REG1_A.XEnable,Reg_Access.CTRL_REG1_A.YEnable,Reg_Access.CTRL_REG1_A.ZEnable);
    I2C_WriteReg(ACCEL_I2C_ADDRESS, CTRL_REG1_A, Reg_Access.full_register);
    //regist = I2C_ReadReg(ACCEL_I2C_ADDRESS, CTRL_REG1_A);
    //printf("Regist: %X\r\n",regist);
    //regist=I2C_ReadReg(ACCEL_I2C_ADDRESS,FIFO_CTRL_REG_A);
    //printf("FIFO Regist: %X\r\n",regist);
    return 0;

}
コード例 #8
0
ファイル: st_compass.c プロジェクト: mdunne/ANIMA
/**
 *
 * @param scale
 * @return
 */
unsigned char st_accel_SetScale(char scale) {
    unsigned char regist;
    Reg_Access.full_register = I2C_ReadReg(ACCEL_I2C_ADDRESS, CTRL_REG4_A);
    Reg_Access.CTRL_REG4_A.Scale = scale;

    I2C_WriteReg(ACCEL_I2C_ADDRESS, CTRL_REG4_A, Reg_Access.full_register);
    regist = I2C_ReadReg(ACCEL_I2C_ADDRESS, CTRL_REG4_A);
    //printf("Regist: %X\r\n",regist);
    //    char regToRead;
    //    st_ChangeMode(STMICRO_STANDBYMODE);
    //    regToRead = st_ReadReg(CTRL_REG4_A);
    //    if (scale == STMICRO_2GSCALE)
    //        regToRead = (regToRead & (~SCALE_MASK))+(0b00 << 4);
    //    if (scale == STMICRO_4GSCALE)
    //        regToRead = (regToRead & (~SCALE_MASK))+(0b01 << 4);
    //    if (scale == STMICRO_8GSCALE)
    //        regToRead = (regToRead & (~SCALE_MASK))+(0b11 << 4);
    //    st_WriteReg(CTRL_REG4_A, regToRead);
    //    st_ChangeMode(STMICRO_ACTIVEMODE);
    return 0;
}
コード例 #9
0
ファイル: MAXIM_driver.c プロジェクト: x29a/HEXIWEAR
/**
 * initialize MAXIM module
 */
statusMAXIM_t MAXIM_Init(
    handleMAXIM_t* maximHandle,
    const settingsMAXIM_t* maximSettings
)
{
    statusI2C_t
    status = I2C_Init( &(maximHandle->protocol), maximSettings->address );

    if ( STATUS_I2C_SUCCESS != status )
    {
        return STATUS_MAXIM_INIT_ERROR;
    }

    else
    {
        /**
         * initialize intern structures,
         * which will be used from now on
         */

        memcpy( (void*)&self,     (void*)maximHandle,   sizeof(self) );
        memcpy( (void*)&settings, (void*)maximSettings, sizeof(settings) );

        uint8_t
        foo = 0;

        // read revision ID
        statusI2C_t
        i2cStatus = STATUS_I2C_SUCCESS;

        genericI2cHandle_t
        i2cProtocol = self.protocol;

        uint8_t
        revID  = 0,
        partID = 0;

        // read revision ID
        i2cStatus |= I2C_ReadReg( &i2cProtocol, MAXIM_REG_ID_REV, &revID );

        // read part ID
        i2cStatus |= I2C_ReadReg( &i2cProtocol, MAXIM_REG_ID_PART, &partID );

        /**
         * set up the registers
         */

        // reset the module
        i2cStatus |= MAXIM_Reset();

        // LED amplitude -> max
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_LED1_PA , 0x7F );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_LED2_PA , 0x7F );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_LED3_PA , 0x7F );

        // set the slots
//    foo = ( settings.slot1 << MAXIM_SLOT_1_3_SHIFT ) | ( settings.slot2 << MAXIM_SLOT_2_4_SHIFT );
//    i2cStatus |= I2C_writeReg( &i2cProtocol, MAXIM_REG_MULTILED_MODE_CR_12 , foo );
//
//    foo = ( settings.slot3 << MAXIM_SLOT_1_3_SHIFT ) | ( settings.slot4 << MAXIM_SLOT_2_4_SHIFT );
//    i2cStatus |= I2C_writeReg( &i2cProtocol, MAXIM_REG_MULTILED_MODE_CR_34 , foo );

        foo = ( slotGreen << MAXIM_SLOT_1_3_SHIFT ) | ( slotGreen << MAXIM_SLOT_2_4_SHIFT );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_MULTILED_MODE_CR_12 , foo );
        foo = ( slotGreen << MAXIM_SLOT_1_3_SHIFT ) | ( slotGreen << MAXIM_SLOT_2_4_SHIFT );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_MULTILED_MODE_CR_34 , foo );

        // set the timings
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_SPO2_CFG , settings.pulseWidth << MAXIM_SPO2_LED_PW_SHIFT );

        // clear FIFO pointers
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_FIFO_WR_PTR , 0 );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_FIFO_RD_PTR , 0 );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_FIFO_OV_PTR , 0 );

        // set the mode
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_MODE_CFG , settings.mode << MAXIM_MODE_SHIFT );
//    i2cStatus |= I2C_writeReg( &i2cProtocol, MAXIM_REG_MODE_CFG , modeMultiLED << MAXIM_MODE_SHIFT );

        switch ( settings.mode )
        {
        case modeHR:        {
            channelsPerSample = 1;
            break;
        }

        case modeSPO2:      {
            channelsPerSample = 2;
            break;
        }

        case modeMultiLED:  {
            channelsPerSample = 3;
            break;
        }

        default:
        {}
        }

        // read FIFO pointers
        i2cStatus |= I2C_ReadReg( &i2cProtocol, MAXIM_REG_FIFO_WR_PTR , &foo );
        i2cStatus |= I2C_ReadReg( &i2cProtocol, MAXIM_REG_FIFO_RD_PTR , &foo );
        i2cStatus |= I2C_ReadReg( &i2cProtocol, MAXIM_REG_FIFO_OV_PTR , &foo );

        if ( STATUS_I2C_SUCCESS != i2cStatus )
        {
            catch(11);
            return STATUS_MAXIM_PROTOCOL_ERROR;
        }

        else
        {
            return STATUS_MAXIM_SUCCESS;
        }
    }
コード例 #10
0
ファイル: MAXIM_driver.c プロジェクト: Btar/HEXIWEAR
/**
 * initialize MAXIM module
 */
maxim_status_t MAXIM_Init(
                                  handleMAXIM_t* maximHandle,
                          const settingsMAXIM_t* maximSettings
                        )
{
    /**
    * initialize intern structures,
    * which will be used from now on
    */

    memcpy( (void*)&self,     (void*)maximHandle,   sizeof(self) );
    memcpy( (void*)&settings, (void*)maximSettings, sizeof(settings) );

    statusI2C_t
    	status = I2C_Init( &(self.protocol), settings.address, settings.baudRate_kbps );

    if ( STATUS_I2C_SUCCESS != status )
    {
    return STATUS_MAXIM_INIT_ERROR;
    }

    else
    {
        // read revision ID
        statusI2C_t
          i2cStatus = STATUS_I2C_SUCCESS;

        genericI2cHandle_t
          i2cProtocol = self.protocol;

        /**
         * set up the registers
         */

        i2cStatus |= MAXIM_Reset();

        OSA_TimeDelay(50);

        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_LED_RED_PA,   0xFF );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_LED_IR_PA,    0x33 );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_LED_GREEN_PA, 0xFF );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_PROXY_PA,     0x19 );

        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_MULTILED_MODE_CR_12, 0x03 );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_MULTILED_MODE_CR_34, 0x00 );

        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_FIFO_CFG , 0x06 );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_SPO2_CFG , 0x43 );

        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_PROXY_INT_THR , 0x14 );

        /** clear FIFO pointers */
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_FIFO_WR_PTR , 0 );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_FIFO_RD_PTR , 0 );
        i2cStatus |= I2C_WriteReg( &i2cProtocol, MAXIM_REG_FIFO_OV_PTR , 0 );

        // read only green LED valus
        maxim_bytesPerSample = MAXIM_BYTES_PER_ADC_VALUE * 1;
        maxim_bitMask        = 0x00003FFFF;

        return STATUS_MAXIM_SUCCESS;
    }
}