/*******************************************************************************
  Function:  inline void SetThershold(void)
  *****************************************************************************/
inline void SetThershold(void)
{
    ACCEL_BMA250_REG    reg;
    uint16_t                idx;

    idx = ReadByteSequence(0, ACCEL_BMA250_ADDR11);

    AccelRxBuffer = (uint8_t *)®

    accelData[idx].cmd = ACCEL_DONE;

    ACCELStartCommandSequence();

#ifndef ACCEL_USE_POLLING
    while(IsBusy())
        ;
#else
    while(ACCELTask() == ACCEL_VALID)
        ;
#endif

    idx = WriteByteSequence(0, ACCEL_BMA250_ADDR14, ACCEL_BMA250_THES);

    accelData[idx].cmd = ACCEL_DONE;

    ACCELStartCommandSequence();

#ifndef ACCEL_USE_POLLING
    while(IsBusy())
        ;
#else
    while(ACCELTask() == ACCEL_VALID)
        ;
#endif

    idx = ReadByteSequence(0, ACCEL_BMA250_ADDR11);

    AccelRxBuffer = (uint8_t *)®

    accelData[idx].cmd = ACCEL_DONE;

    ACCELStartCommandSequence();

#ifndef ACCEL_USE_POLLING
    while(IsBusy())
        ;
#else
    while(ACCELTask() == ACCEL_VALID)
        ;
#endif
}
/*******************************************************************************
  Function:  inline void StartXYAccelConversion(void)
  *****************************************************************************/
inline void StartXYAccelConversion(void)
{
    uint16_t idx;

    AccelRxBuffer = (uint8_t *)&accelXYZData;

    idx = ReadByteSequence(0, ACCEL_BMA250_ACC_X_LSB_ADDR);
    idx = ReadByteSequence(idx, ACCEL_BMA250_ACC_X_MSB_ADDR);

    idx = ReadByteSequence(idx, ACCEL_BMA250_ACC_Y_LSB_ADDR);
    idx = ReadByteSequence(idx, ACCEL_BMA250_ACC_Y_MSB_ADDR);

    accelData[idx].cmd = ACCEL_DONE;

    ACCELStartCommandSequence();
}
/*******************************************************************************
  Function:  inline void SetRangeAndBandwidth(void)
  *****************************************************************************/
inline void SetRangeAndBandwidth(uint8_t accl_range)
{
    ACCEL_BMA250_REG        reg;
    uint16_t                idx;

    idx = ReadByteSequence(0, ACCEL_BMA250_ADDR14);
    AccelRxBuffer = (uint8_t *)®
    accelData[idx].cmd = ACCEL_DONE;
    ACCELStartCommandSequence();
#ifndef ACCEL_USE_POLLING
    while(IsBusy())
        ;
#else
    while(ACCELTask() == ACCEL_VALID)
        ;
#endif

//    reg.range       = accl_range;
//    reg.bandwidth	= ACCEL_BMA250_BW_50;
//    idx = WriteByteSequence(0, ACCEL_BMA250_ADDR14, reg.val);
    idx = WriteByteSequence(0, ACCEL_BMA250_ADDR0F, accl_range);
//    idx = WriteByteSequence(idx, ACCEL_BMA250_ADDR10, 0x08);
    idx = WriteByteSequence(idx, ACCEL_BMA250_ADDR10, 0x0f); //0x0f, bandwidth 1000Hz, updata time 0.5ms
    accelData[idx].cmd = ACCEL_DONE;
    ACCELStartCommandSequence();

#ifndef ACCEL_USE_POLLING
    while(IsBusy())
        ;
#else
    while(ACCELTask() == ACCEL_VALID)
        ;
#endif
}
/*******************************************************************************
  Function:  inline void StartBurstXYZAccelConversion(uint8_t u8_BurstNumber)
  *****************************************************************************/
inline void StartBurstXYZAccelConversion(uint8_t u8_BurstNumber)
{
    uint16_t idx = 0;
    uint8_t i;
    AccelRxBuffer = (uint8_t *)accelXYZBurstData;
    for(i = 0;i < u8_BurstNumber*6;i ++)
    {
        idx = ReadByteSequence(idx, ACCEL_BMA250_FIFO_DATA_ADDR);
    }
    accelData[idx].cmd = ACCEL_DONE;

    ACCELStartCommandSequence();
}
/*******************************************************************************
  Function:  inline void StartZAccelConversion(void)
  *****************************************************************************/
inline void StartZAccelConversion(void)
{
    uint16_t idx;
    
    AccelRxBuffer = (uint8_t *)&accelXYZData.acc_z_msb.val;

    idx = ReadByteSequence(0, ACCEL_BMA250_ACC_Z_MSB_ADDR);

    accelData[idx].cmd = ACCEL_DONE;

    ACCELStartCommandSequence();
    
}
示例#6
0
// Read sysex event:
static dboolean ReadSysExEvent(midi_event_t *event, int event_type, FILE *stream)
{
    event->event_type = (midi_event_type_t)event_type;

    if (!ReadVariableLength(&event->data.sysex.length, stream))
        return false;

    // Read the byte sequence:
    event->data.sysex.data = (byte *)ReadByteSequence(event->data.sysex.length, stream);

    if (!event->data.sysex.data)
        return false;

    return true;
}
/*******************************************************************************
  Function:  inline void ReadChipVersion(void)
  *****************************************************************************/
inline void ReadChipVersion(void)
{
    ACCEL_BMA250_REG        reg;
    uint16_t                idx;

    idx = ReadByteSequence(0, ACCEL_BMA250_VERSION_ADDR);
    AccelRxBuffer = (uint8_t *)&reg;
    accelData[idx].cmd = ACCEL_DONE;
    ACCELStartCommandSequence();
#ifndef ACCEL_USE_POLLING
    while(IsBusy())
        ;
#else
    while(ACCELTask() == ACCEL_VALID)
        ;
#endif

}
示例#8
0
static boolean ReadSysExEvent(midi_event_t *event, int event_type, FILE *stream)
{
    event->event_type = (midi_event_type_t)event_type;

    if (!ReadVariableLength(&event->data.sysex.length, stream))
    {
        fprintf(stderr, "ReadSysExEvent: Failed to read length of SysEx block\n");
        return false;
    }

    // Read the byte sequence:

    event->data.sysex.data = (byte *)ReadByteSequence(event->data.sysex.length, stream);

    if (event->data.sysex.data == NULL)
    {
        fprintf(stderr, "ReadSysExEvent: Failed while reading SysEx event\n");
        return false;
    }

    return true;
}
/*******************************************************************************
  Function:  inline uint8_t WriteByteSequence(uint8_t start_idx, uint8_t addr, uint8_t data)
  *****************************************************************************/
inline ACCEL_RESULT ReadChipID(void)
{
    ACCEL_BMA250_REG        reg;
    uint16_t                idx;

    idx = ReadByteSequence(0, ACCEL_BMA250_CHIP_ID_ADDR);
    AccelRxBuffer = (uint8_t *)&reg;
    accelData[idx].cmd = ACCEL_DONE;
    ACCELStartCommandSequence();
#ifndef ACCEL_USE_POLLING
    while(IsBusy())
        ;
#else
    while(ACCELTask() == ACCEL_VALID)
        ;
#endif
    if(reg.chip_id != ACCEL_BMA250_CHIP_ID)
    {
        return ACCEL_INVALID;
    }
    return ACCEL_VALID;
}
示例#10
0
static boolean ReadMetaEvent(midi_event_t *event, FILE *stream)
{
    byte b;

    event->event_type = MIDI_EVENT_META;

    // Read meta event type:

    if (!ReadByte(&b, stream))
    {
        fprintf(stderr, "ReadMetaEvent: Failed to read meta event type\n");
        return false;
    }

    event->data.meta.type = b;

    // Read length of meta event data:

    if (!ReadVariableLength(&event->data.meta.length, stream))
    {
        fprintf(stderr, "ReadSysExEvent: Failed to read length of "
                                        "SysEx block\n");
        return false;
    }

    // Read the byte sequence:

    event->data.meta.data = ReadByteSequence(event->data.meta.length, stream);

    if (event->data.meta.data == NULL)
    {
        fprintf(stderr, "ReadSysExEvent: Failed while reading SysEx event\n");
        return false;
    }

    return true;
}
示例#11
0
// Read meta event:
static dboolean ReadMetaEvent(midi_event_t *event, FILE *stream)
{
    byte        b;

    event->event_type = MIDI_EVENT_META;

    // Read meta event type:
    if (!ReadByte(&b, stream))
        return false;

    event->data.meta.type = b;

    // Read length of meta event data:
    if (!ReadVariableLength(&event->data.meta.length, stream))
        return false;

    // Read the byte sequence:
    event->data.meta.data = (byte *)ReadByteSequence(event->data.meta.length, stream);

    if (!event->data.meta.data)
        return false;

    return true;
}