void InterruptIn::fall(void (*fptr)(void)) { if (fptr) { _fall.attach(fptr); gpio_irq_set(&gpio_irq, IRQ_FALL, 1); } else { gpio_irq_set(&gpio_irq, IRQ_FALL, 0); } }
void InterruptIn::rise(void (*fptr)(void)) { if (fptr) { _rise.attach(fptr); gpio_irq_set(&gpio_irq, IRQ_RISE, 1); } else { gpio_irq_set(&gpio_irq, IRQ_RISE, 0); } }
void gpio_ir_recv_handler(uint32_t id, uint32_t event) { uint32_t current_timestamp; IRSendRev *pIR; pIR = (IRSendRev *)id; gpio_irq_disable((gpio_irq_t *)(pIR->pGpioIrqRecv)); current_timestamp = micros(); switch(pIR->rcvstate) { case STATE_IDLE: if ((pIR->recv_wait_int) == IRQ_LOW) { pIR->rcvstate = STATE_MARK; pIR->prev_timestamp = current_timestamp; } break; case STATE_MARK: if ((pIR->recv_wait_int) == IRQ_HIGH) { // mark transition to space pIR->recv_buf[(pIR->recv_len)++] = current_timestamp - (pIR->prev_timestamp); pIR->prev_timestamp = current_timestamp; pIR->rcvstate = STATE_SPACE; gtimer_reload((gtimer_t *)(pIR->pTimerRecv), GAP); gtimer_start((gtimer_t *)(pIR->pTimerRecv)); } break; case STATE_SPACE: if ((pIR->recv_wait_int) == IRQ_LOW) { // space transition to mark gtimer_stop((gtimer_t *)(pIR->pTimerRecv)); pIR->recv_buf[(pIR->recv_len)++] = current_timestamp - (pIR->prev_timestamp); pIR->prev_timestamp = current_timestamp; pIR->rcvstate = STATE_MARK; } break; case STATE_STOP: break; } if ((pIR->recv_wait_int) == IRQ_LOW ) { // Change to listen to high level event (pIR->recv_wait_int) = IRQ_HIGH; gpio_irq_set((gpio_irq_t *)(pIR->pGpioIrqRecv), (gpio_irq_event)IRQ_HIGH, 1); gpio_irq_enable((gpio_irq_t *)(pIR->pGpioIrqRecv)); } else if ((pIR->recv_wait_int) == IRQ_HIGH) { // Change to listen to low level event (pIR->recv_wait_int) = IRQ_LOW; gpio_irq_set((gpio_irq_t *)(pIR->pGpioIrqRecv), (gpio_irq_event)IRQ_LOW, 1); gpio_irq_enable((gpio_irq_t *)(pIR->pGpioIrqRecv)); } }
void InterruptIn::fall(Callback<void()> func) { core_util_critical_section_enter(); if (func) { _fall.attach(func); gpio_irq_set(&gpio_irq, IRQ_FALL, 1); } else { _fall.attach(NULL); gpio_irq_set(&gpio_irq, IRQ_FALL, 0); } core_util_critical_section_exit(); }
void InterruptIn::rise(Callback<void()> func) { core_util_critical_section_enter(); if (func) { _rise.attach(func); gpio_irq_set(&gpio_irq, IRQ_RISE, 1); } else { _rise.attach(NULL); gpio_irq_set(&gpio_irq, IRQ_RISE, 0); } core_util_critical_section_exit(); }
void DispatcherPrivate::set_receive_input(SYNCHRONIZATION_CHANNEL* channel, PinName pin, PinMode pull, ReceiveChannelMode rcmode) { if (channel->data->state->recv.mode != ReceiveChannelModeNone) gpio_irq_free(&channel->data->state->recv.gpio_irq); channel->data->state->recv.mode = rcmode; gpio_init_in(&channel->data->state->recv.gpio, pin); gpio_irq_init(&channel->data->state->recv.gpio_irq, pin, (&DispatcherPrivate::channel_irq_handler), (uint32_t)channel); gpio_mode(&channel->data->state->recv.gpio, pull); gpio_irq_event evt = IRQ_NONE; switch (rcmode) { case ReceiveChannelInterruptRise: evt = IRQ_RISE; break; case ReceiveChannelInterruptFall: evt = IRQ_FALL; break; case ReceiveChannelModeNone: break; } if (evt != IRQ_NONE) { gpio_irq_set(&channel->data->state->recv.gpio_irq, evt, 1); gpio_irq_enable(&channel->data->state->recv.gpio_irq); } }
INT32 wmt_plat_bgf_eint_ctrl ( ENUM_PIN_STATE state ) { #if CFG_WMT_PS_SUPPORT switch(state) { case PIN_STA_INIT: /*set to gpio input low, pull down eanble*/ aml_gpio_input_mtk(MTK_BGF_INT); WMT_DBG_FUNC("WMT-PLAT:BGFInt init(in pd) \n"); break; case PIN_STA_MUX: /*set to EINT mode,interrupt input, pull up enable*/ gpio_set_status(MTK_BGF_INT,gpio_status_in); aml_clr_reg32_mask(P_PAD_PULL_UP_REG4,0x1<<10);//pull up resister gpio_irq_set(MTK_BGF_INT,GPIO_IRQ(mtk_bgf_irq_no,GPIO_IRQ_LOW)); WMT_DBG_FUNC("WMT-PLAT:BGFInt mux (eint) \n"); break; case PIN_STA_IN_L: case PIN_STA_DEINIT: /*first: disable bgf inq wake up host function*/ do { int iret; iret = disable_irq_wake(mtk_bgf_irq_no); if(iret){ WMT_WARN_FUNC("disable_irq_wake(bgf:%d) fail(%d)\n",mtk_bgf_irq_no,iret); iret = 0; } else{ WMT_INFO_FUNC("disable_irq_wake(bgf:%d)--,ret(%d)\n",mtk_bgf_irq_no,iret); } } while (0); /*second: set to gpio input low, pull down eanble*/ //aml_set_reg32_mask(P_PAD_PULL_UP_REG4,0x1<<10); aml_gpio_input_mtk(MTK_BGF_INT); WMT_DBG_FUNC("WMT-PLAT:BGFInt deinit(in pd) \n"); break; default: WMT_WARN_FUNC("WMT-PLAT:Warnning, invalid state(%d) on BGF EINT\n", state); break; } #endif return 0; }
void config_loguart() { /* Log uart RX pin doesn't support gpio interrupt. * To make log uart wake system, we can parallel log uart RX with another gpio interrupt pin. */ gpio_irq_t gpio_rx_wake; gpio_irq_init(&gpio_rx_wake, LOGUART_RX_WAKE, gpio_loguart_rx_irq_callback, NULL); gpio_irq_set(&gpio_rx_wake, IRQ_FALL, 1); // Falling Edge Trigger gpio_irq_enable(&gpio_rx_wake); }
void uartadapter_gpio_init() { gpio_init(&gpio_led, UA_GPIO_IRQ_PIN); gpio_dir(&gpio_led, PIN_INPUT); // Direction: Output gpio_mode(&gpio_led, PullNone); // No pull gpio_irq_init(&gpio_btn, UA_GPIO_IRQ_PIN, uartadapter_gpio_irq, (uint32_t)(&gpio_led)); gpio_irq_set(&gpio_btn, IRQ_FALL, 1); // Falling Edge Trigger gpio_irq_enable(&gpio_btn); }
void IRSendRev::Init(int revPin) { gpio_irq_init((gpio_irq_t *)pGpioIrqRecv, (PinName)(g_APinDescription[revPin].pinname), (gpio_irq_handler)gpio_ir_recv_handler, (uint32_t)this); gpio_irq_set((gpio_irq_t *)pGpioIrqRecv, (gpio_irq_event)IRQ_LOW, 1); gpio_irq_enable((gpio_irq_t *)pGpioIrqRecv); gtimer_init((gtimer_t *)pTimerRecv, TIMER4); gtimer_start_one_shout((gtimer_t *)pTimerRecv, GAP, (void *)ir_recv_timer_handler, (uint32_t)this); gtimer_stop((gtimer_t *)pTimerRecv); Clear(); }
void config_uart() { // setup uart serial_init(&mysobj, UART_TX, UART_RX); serial_baud(&mysobj, 38400); serial_format(&mysobj, 8, ParityNone, 1); serial_irq_handler(&mysobj, uart_irq_callback, (uint32_t)&mysobj); serial_irq_set(&mysobj, RxIrq, 1); serial_irq_set(&mysobj, TxIrq, 1); // config uart rx as gpio wakeup pin gpio_irq_t gpio_rx_wake; gpio_irq_init(&gpio_rx_wake, UART_RX, gpio_uart_rx_irq_callback, NULL); gpio_irq_set(&gpio_rx_wake, IRQ_FALL, 1); // Falling Edge Trigger gpio_irq_enable(&gpio_rx_wake); }
/** * @brief Main program. * @param None * @retval None */ void main(void) { gpio_irq_t gpio_btn; // Init LED control pin gpio_init(&gpio_led, GPIO_LED_PIN); gpio_dir(&gpio_led, PIN_OUTPUT); // Direction: Output gpio_mode(&gpio_led, PullNone); // No pull // Initial Push Button pin as interrupt source gpio_irq_init(&gpio_btn, GPIO_IRQ_PIN, gpio_demo_irq_handler, (uint32_t)(&gpio_led)); gpio_irq_set(&gpio_btn, IRQ_FALL, 1); // Falling Edge Trigger gpio_irq_enable(&gpio_btn); led_ctrl = 1; gpio_write(&gpio_led, led_ctrl); while(1); }
void main(void) { gpio_t gpio_led; gpio_irq_t gpio_btn; // Init LED control pin gpio_init(&gpio_led, GPIO_LED_PIN); gpio_dir(&gpio_led, PIN_OUTPUT); // Direction: Output gpio_mode(&gpio_led, PullNone); // No pull // Initial Push Button pin as interrupt source gpio_irq_init(&gpio_btn, GPIO_IRQ_PIN, gpio_demo_irq_handler, (uint32_t)(&gpio_led)); gpio_irq_set(&gpio_btn, IRQ_FALL, 1); // Falling Edge Trigger gpio_irq_enable(&gpio_btn); // led on means system is in run mode gpio_write(&gpio_led, 1); printf("\r\nPush button at PC_4 to enter deep sleep\r\n"); while(1); }
void pinMode( uint32_t ulPin, uint32_t ulMode) { void *pGpio_t; if ( ulPin < 0 || ulPin > TOTAL_GPIO_PIN_NUM ) { return; } if ( (g_APinDescription[ulPin].ulPinType == PIO_GPIO || g_APinDescription[ulPin].ulPinType == PIO_GPIO_IRQ) && g_APinDescription[ulPin].ulPinMode == ulMode) { return; } if ( g_APinDescription[ulPin].ulPinType == PIO_PWM ) { pinRemoveMode(ulPin); } if ( g_APinDescription[ulPin].ulPinType == PIO_GPIO && (ulMode == INPUT_IRQ_FALL || ulMode == INPUT_IRQ_RISE) ) { // requst type from gpio_t to gpio_irq_t pinRemoveMode(ulPin); } if ( g_APinDescription[ulPin].ulPinType == PIO_GPIO_IRQ && (ulMode == INPUT || ulMode == OUTPUT || ulMode == INPUT_PULLUP || ulMode == INPUT_PULLNONE || ulMode == OUTPUT_OPENDRAIN) ) { // requst type from gpio_irq_t to gpio_t pinRemoveMode(ulPin); } if ( g_APinDescription[ulPin].ulPinType == NOT_INITIAL ) { if (ulMode == INPUT_IRQ_FALL || ulMode == INPUT_IRQ_RISE) { gpio_pin_struct[ulPin] = malloc ( sizeof(gpio_irq_t) ); pGpio_t = gpio_pin_struct[ulPin]; gpio_irq_init( pGpio_t, g_APinDescription[ulPin].pinname, gpioIrqHandler, ulPin); g_APinDescription[ulPin].ulPinType = PIO_GPIO_IRQ; } else { gpio_pin_struct[ulPin] = malloc ( sizeof(gpio_t) ); pGpio_t = gpio_pin_struct[ulPin]; gpio_init( pGpio_t, g_APinDescription[ulPin].pinname ); g_APinDescription[ulPin].ulPinType = PIO_GPIO; } g_APinDescription[ulPin].ulPinMode = ulMode; } else { pGpio_t = gpio_pin_struct[ulPin]; } switch ( ulMode ) { case INPUT: gpio_dir( (gpio_t *)pGpio_t, PIN_INPUT ); gpio_mode( (gpio_t *)pGpio_t, PullDown ); break; case INPUT_PULLNONE: gpio_dir( (gpio_t *)pGpio_t, PIN_INPUT ); gpio_mode( (gpio_t *)pGpio_t, PullNone ); break; case INPUT_PULLUP: gpio_dir( (gpio_t *)pGpio_t, PIN_INPUT ); gpio_mode( (gpio_t *)pGpio_t, PullUp ); break; case OUTPUT: gpio_dir( (gpio_t *)pGpio_t, PIN_OUTPUT ); gpio_mode( (gpio_t *)pGpio_t, PullNone ); break; case OUTPUT_OPENDRAIN: gpio_dir( (gpio_t *)pGpio_t, PIN_OUTPUT ); gpio_mode( (gpio_t *)pGpio_t, OpenDrain ); break; case INPUT_IRQ_FALL: gpio_irq_set( (gpio_irq_t *)pGpio_t, IRQ_FALL, 1 ); gpio_irq_enable( (gpio_irq_t *)pGpio_t ); break; case INPUT_IRQ_RISE: gpio_irq_set( (gpio_irq_t *)pGpio_t, IRQ_RISE, 1 ); gpio_irq_enable( (gpio_irq_t *)pGpio_t ); break; case INPUT_IRQ_LOW: gpio_irq_set( (gpio_irq_t *)pGpio_t, IRQ_LOW, 1 ); gpio_irq_enable( (gpio_irq_t *)pGpio_t ); break; case INPUT_IRQ_HIGH: gpio_irq_set( (gpio_irq_t *)pGpio_t, IRQ_HIGH, 1 ); gpio_irq_enable( (gpio_irq_t *)pGpio_t ); break; default: break ; } }