Пример #1
0
void TwoWire::end() {
    DTWI::I2C_STATUS status = di2c.getStatus();

    if(beginCount == 0)
    {
        return;
    }

    destroyTask(getTaskId(onI2C));
    beginCount = 0;

    if(status.fMaster)
    {
        di2c.endMaster();
    }
    else if(status.fSlave)
    {
        // forcefully end the slave
        di2c.endSlave(true);
    }

    // clean out the read / write buffer
    di2c.abort();
    di2c.discard();
    }
Пример #2
0
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity)
{
    DTWI::I2C_STATUS status;

    // may have to wait for the last action to finish before
    // a repeated start can occur
    while(!di2c.startMasterRead(address, quantity));

    do
    {
        status = di2c.getStatus();
    } while(status.fMyBus && !status.fNacking);

    while(!di2c.stopMaster());

    return(di2c.available());
}
Пример #3
0
static void onI2C(int id, void * tptr)
{
    DTWI::I2C_STATUS status = di2c.getStatus();
    uint8_t data;

    if(status.fSlave)
    {
        if(status.fRead)
        {
            while(di2c.available() > 0)
            {
                onReceiveServiceR(NULL, di2c.available());
            }
        }

        // on writing out, we only call once when the 
        // new session starts
        else if(status.fWrite && iSessionCur != status.iSession)
        {
            iSessionCur = status.iSession;
            onRequestServiceR();
        }
    }
}
Пример #4
0
uint8_t TwoWire::txBufferIndex = 0;
uint8_t TwoWire::txBufferLength = 0;

uint8_t TwoWire::transmitting = 0;
void (*TwoWire::user_onRequest)(void);
void (*TwoWire::user_onReceive)(int);

uint32_t TwoWire::beginCount = 0;

static void (*onReceiveServiceR) (uint8_t*, int) = NULL;
static void (*onRequestServiceR)(void)           = NULL;
static uint32_t iSessionCur                     = 0xFF;

static void onI2C(int id __attribute__((unused)), void * tptr __attribute__((unused)))
{
    DTWI::I2C_STATUS status = di2c.getStatus();

    if(status.fSlave)
    {
        if(status.fRead)
        {
            while(di2c.available() > 0)
            {
                onReceiveServiceR(NULL, di2c.available());
            }
        }

        // on writing out, we only call once when the 
        // new session starts
        else if(status.fWrite && iSessionCur != status.iSession)
        {