uint32_t gpio_set(PinName pin) { int f = 0; unsigned int port = (unsigned int)MBED_GPIO_PORT(pin); f = SCU_PINIO_FAST | ((port > 4) ? (4) : (0)); pin_function(pin, f); return (1 << ((int)pin & 0x1F)); }
void gpio_init(gpio_t *obj, PinName pin) { if (pin == NC) return; obj->pin = pin; obj->mask = gpio_set(pin); LPC_GPIO_T *port_reg = (LPC_GPIO_T *) (LPC_GPIO_PORT_BASE); unsigned int port = (unsigned int)MBED_GPIO_PORT(pin); obj->reg_set = &port_reg->SET[port]; obj->reg_clr = &port_reg->CLR[port]; obj->reg_in = &port_reg->PIN[port]; obj->reg_dir = &port_reg->DIR[port]; }
int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) { uint32_t portnum, pinnum; //, pmask; if (pin == NC) return -1; irq_handler = handler; /* Set port and pin numbers */ obj->port = portnum = MBED_GPIO_PORT(pin); obj->pin = pinnum = MBED_GPIO_PIN(pin); /* Add to channel table */ channel_ids[channel] = id; obj->ch = channel; /* Clear rising and falling edge detection */ //pmask = (1 << channel); //LPC_GPIO_PIN_INT->IST = pmask; /* Set SCU */ if (channel < 4) { LPC_SCU->PINTSEL0 &= ~(0xFF << (portnum << 3)); LPC_SCU->PINTSEL0 |= (((portnum << 5) | pinnum) << (channel << 3)); } else { LPC_SCU->PINTSEL1 &= ~(0xFF << ((portnum - 4) << 3)); LPC_SCU->PINTSEL1 |= (((portnum << 5) | pinnum) << ((channel - 4) << 3)); } #if !defined(CORE_M0) NVIC_SetVector((IRQn_Type)(PIN_INT0_IRQn + channel), (uint32_t)handle_interrupt_in); NVIC_EnableIRQ((IRQn_Type)(PIN_INT0_IRQn + channel)); #else NVIC_SetVector((IRQn_Type)PIN_INT4_IRQn, (uint32_t)handle_interrupt_in); NVIC_EnableIRQ((IRQn_Type)PIN_INT4_IRQn); #endif // Increment channel number channel++; channel %= CHANNEL_MAX; return 0; }