hw/drivers/io_expander/tca9535/src/tca9535.c
static void
tca9535_interrupt_ev_cb(struct os_event *ev)
{
    int rc, i;
    uint16_t pin_input, changed_pins;
    struct tca9535_io_expander_dev_cfg *cfg;
    struct io_expander_dev *dev = (struct io_expander_dev *) ev->ev_arg;

    cfg  = (struct tca9535_io_expander_dev_cfg *)dev->ioexp_dev.od_init_arg;

    /* Read current state of pins */
    rc = tca9535_read_in16(dev, &pin_input);
    if (rc) {
        TCA9535_ERR("Failed to get pin values 0x%02X\n", cfg->i2c_addr);
        return;
    }

    changed_pins = (cfg->last_interrupt_input) ^ pin_input;
    //TCA9535_INFO("%x\n", changed_pins);
    cfg->last_interrupt_input = pin_input;

    /* Check for any activated interrupts */
    rc = 1;
    for (i=0;i<IO_EXPANDER_MAX_IRQ;i++) {
        if (dev->ioexp_irqs[i].enabled == 0) rc=0;

        if ((changed_pins & (1<<i)) == 0) continue;
#if MYNEWT_VAL(TCA9535_INT_STATS)
        switch(i) {
        case (0x0): STATS_INC(g_tca9535_stats, p0irqs);break;
        case (0x1): STATS_INC(g_tca9535_stats, p1irqs);break;
        case (0x2): STATS_INC(g_tca9535_stats, p2irqs);break;
        case (0x3): STATS_INC(g_tca9535_stats, p3irqs);break;
        case (0x4): STATS_INC(g_tca9535_stats, p4irqs);break;
        case (0x5): STATS_INC(g_tca9535_stats, p5irqs);break;
        case (0x6): STATS_INC(g_tca9535_stats, p6irqs);break;
        case (0x7): STATS_INC(g_tca9535_stats, p7irqs);break;
        case (0x8): STATS_INC(g_tca9535_stats, p8irqs);break;
        case (0x9): STATS_INC(g_tca9535_stats, p9irqs);break;
        case (0xA): STATS_INC(g_tca9535_stats, pAirqs);break;
        case (0xB): STATS_INC(g_tca9535_stats, pBirqs);break;
        case (0xC): STATS_INC(g_tca9535_stats, pCirqs);break;
        case (0xD): STATS_INC(g_tca9535_stats, pDirqs);break;
        case (0xE): STATS_INC(g_tca9535_stats, pEirqs);break;
        case (0xF): STATS_INC(g_tca9535_stats, pFirqs);break;
        }
#endif
    }

    if (rc == 1)
    {
        /* No interrupts to service */
        return;
    }

    if (!changed_pins) return;

    for (i=0;i<IO_EXPANDER_MAX_IRQ;i++) {
        if ((changed_pins & (1<<i)) == 0) continue;
        if (dev->ioexp_irqs[i].enabled == 0) continue;
        int pin_now  = ((pin_input & (1<<i)) != 0);
        if ((dev->ioexp_irqs[i].trig == HAL_GPIO_TRIG_RISING)  && pin_now == 0) continue;
        if ((dev->ioexp_irqs[i].trig == HAL_GPIO_TRIG_FALLING) && pin_now == 1) continue;

        /* Call interrupt cb */
        assert(dev->ioexp_irqs[i].func);
        dev->ioexp_irqs[i].func(dev->ioexp_irqs[i].arg);
    }

}
/**
 *  Event callback that is called everytime an input-pin changes
 *  If an input pin has a callback associated with the current
 *  change (rising / falling) call this is called.
 **/
Event callback that is called everytime an input-pin changes
If an input pin has a callback associated with the current
change (rising / falling) call this is called.
Event callback that is called everytime an input - pin changes If an input pin has a callback associated with the current change ( rising / falling ) call this is called .
static void
tca9535_interrupt_ev_cb(struct os_event *ev)
{
    int rc, i;
    uint16_t pin_input, changed_pins;
    struct tca9535_io_expander_dev_cfg *cfg;
    struct io_expander_dev *dev = (struct io_expander_dev *) ev->ev_arg;
    cfg  = (struct tca9535_io_expander_dev_cfg *)dev->ioexp_dev.od_init_arg;
    rc = tca9535_read_in16(dev, &pin_input);
    if (rc) {
        TCA9535_ERR("Failed to get pin values 0x%02X\n", cfg->i2c_addr);
        return;
    }
    changed_pins = (cfg->last_interrupt_input) ^ pin_input;
    cfg->last_interrupt_input = pin_input;
    rc = 1;
    for (i=0;i<IO_EXPANDER_MAX_IRQ;i++) {
        if (dev->ioexp_irqs[i].enabled == 0) rc=0;
        if ((changed_pins & (1<<i)) == 0) continue;
#if MYNEWT_VAL(TCA9535_INT_STATS)
        switch(i) {
        case (0x0): STATS_INC(g_tca9535_stats, p0irqs);break;
        case (0x1): STATS_INC(g_tca9535_stats, p1irqs);break;
        case (0x2): STATS_INC(g_tca9535_stats, p2irqs);break;
        case (0x3): STATS_INC(g_tca9535_stats, p3irqs);break;
        case (0x4): STATS_INC(g_tca9535_stats, p4irqs);break;
        case (0x5): STATS_INC(g_tca9535_stats, p5irqs);break;
        case (0x6): STATS_INC(g_tca9535_stats, p6irqs);break;
        case (0x7): STATS_INC(g_tca9535_stats, p7irqs);break;
        case (0x8): STATS_INC(g_tca9535_stats, p8irqs);break;
        case (0x9): STATS_INC(g_tca9535_stats, p9irqs);break;
        case (0xA): STATS_INC(g_tca9535_stats, pAirqs);break;
        case (0xB): STATS_INC(g_tca9535_stats, pBirqs);break;
        case (0xC): STATS_INC(g_tca9535_stats, pCirqs);break;
        case (0xD): STATS_INC(g_tca9535_stats, pDirqs);break;
        case (0xE): STATS_INC(g_tca9535_stats, pEirqs);break;
        case (0xF): STATS_INC(g_tca9535_stats, pFirqs);break;
        }
#endif
    }
    if (rc == 1)
    {
        return;
    }
    if (!changed_pins) return;
    for (i=0;i<IO_EXPANDER_MAX_IRQ;i++) {
        if ((changed_pins & (1<<i)) == 0) continue;
        if (dev->ioexp_irqs[i].enabled == 0) continue;
        int pin_now  = ((pin_input & (1<<i)) != 0);
        if ((dev->ioexp_irqs[i].trig == HAL_GPIO_TRIG_RISING)  && pin_now == 0) continue;
        if ((dev->ioexp_irqs[i].trig == HAL_GPIO_TRIG_FALLING) && pin_now == 1) continue;
        assert(dev->ioexp_irqs[i].func);
        dev->ioexp_irqs[i].func(dev->ioexp_irqs[i].arg);
    }
}
static void tca9535_interrupt_ev_cb ( struct os_event * ev ) { int rc , i ; uint16_t pin_input , changed_pins ; struct tca9535_io_expander_dev_cfg * cfg ; struct io_expander_dev * dev = ( struct io_expander_dev * ) ev -> ev_arg ; cfg = ( struct tca9535_io_expander_dev_cfg * ) dev -> ioexp_dev . od_init_arg ; rc = tca9535_read_in16 ( dev , & pin_input ) ; if ( rc ) { TCA9535_ERR ( " \n " , cfg -> i2c_addr ) ; return ; } changed_pins = ( cfg -> last_interrupt_input ) ^ pin_input ; cfg -> last_interrupt_input = pin_input ; rc = 1 ; for ( i = 0 ; i < IO_EXPANDER_MAX_IRQ ; i ++ ) { if ( dev -> ioexp_irqs [ i ] . enabled == 0 ) rc = 0 ; if ( ( changed_pins & ( 1 << i ) ) == 0 ) continue ; #if MYNEWT_VAL ( TCA9535_INT_STATS ) switch ( i ) { case ( 0x0 ) : STATS_INC ( g_tca9535_stats , p0irqs ) ; break ; case ( 0x1 ) : STATS_INC ( g_tca9535_stats , p1irqs ) ; break ; case ( 0x2 ) : STATS_INC ( g_tca9535_stats , p2irqs ) ; break ; case ( 0x3 ) : STATS_INC ( g_tca9535_stats , p3irqs ) ; break ; case ( 0x4 ) : STATS_INC ( g_tca9535_stats , p4irqs ) ; break ; case ( 0x5 ) : STATS_INC ( g_tca9535_stats , p5irqs ) ; break ; case ( 0x6 ) : STATS_INC ( g_tca9535_stats , p6irqs ) ; break ; case ( 0x7 ) : STATS_INC ( g_tca9535_stats , p7irqs ) ; break ; case ( 0x8 ) : STATS_INC ( g_tca9535_stats , p8irqs ) ; break ; case ( 0x9 ) : STATS_INC ( g_tca9535_stats , p9irqs ) ; break ; case ( 0xA ) : STATS_INC ( g_tca9535_stats , pAirqs ) ; break ; case ( 0xB ) : STATS_INC ( g_tca9535_stats , pBirqs ) ; break ; case ( 0xC ) : STATS_INC ( g_tca9535_stats , pCirqs ) ; break ; case ( 0xD ) : STATS_INC ( g_tca9535_stats , pDirqs ) ; break ; case ( 0xE ) : STATS_INC ( g_tca9535_stats , pEirqs ) ; break ; case ( 0xF ) : STATS_INC ( g_tca9535_stats , pFirqs ) ; break ; } #endif } if ( rc == 1 ) { return ; } if ( ! changed_pins ) return ; for ( i = 0 ; i < IO_EXPANDER_MAX_IRQ ; i ++ ) { if ( ( changed_pins & ( 1 << i ) ) == 0 ) continue ; if ( dev -> ioexp_irqs [ i ] . enabled == 0 ) continue ; int pin_now = ( ( pin_input & ( 1 << i ) ) != 0 ) ; if ( ( dev -> ioexp_irqs [ i ] . trig == HAL_GPIO_TRIG_RISING ) && pin_now == 0 ) continue ; if ( ( dev -> ioexp_irqs [ i ] . trig == HAL_GPIO_TRIG_FALLING ) && pin_now == 1 ) continue ; assert ( dev -> ioexp_irqs [ i ] . func ) ; dev -> ioexp_irqs [ i ] . func ( dev -> ioexp_irqs [ i ] . arg ) ; } }
Event callback that is called everytime an input-pin changes
  If an input pin has a callback associated with the current
  change (rising / falling) call this is called.
Event callback that is called everytime an input - pin changes If an input pin has a callback associated with the current change ( rising / falling ) call this is called .
/* Read current state of pins */ //TCA9535_INFO("%x\n", changed_pins); /* Check for any activated interrupts */ /* No interrupts to service */ /* Call interrupt cb */