void UARTClass::begin( const uint32_t dwBaudRate ) { vm_sio_ctrl_dcb_t data; if(_usbNum == 2) { if(!changePinType(0, PIO_UART, &uart_handle)) return; if(uart_handle == VM_DCL_HANDLE_INVALID) uart_handle = vm_dcl_open(vm_uart_port1,vm_dcl_get_ownerid()); } else { uart_handle = vm_dcl_open(vm_usb_port1,vm_dcl_get_ownerid()); } if(VM_DCL_HANDLE_INVALID==uart_handle) { vm_log_info((char*)"UARTClass failed"); return; } data.u4OwenrId = vm_dcl_get_ownerid(); data.rUARTConfig.u4Baud = dwBaudRate; data.rUARTConfig.u1DataBits = 8; data.rUARTConfig.u1StopBits = 1; data.rUARTConfig.u1Parity = 0; data.rUARTConfig.u1FlowControl = 1; data.rUARTConfig.ucXonChar = 0x11; data.rUARTConfig.ucXoffChar = 0x13; data.rUARTConfig.fgDSRCheck = 0; vm_dcl_control(uart_handle,VM_SIO_CMD_SET_DCB_CONFIG,(void *)&data); vm_dcl_registercallback(uart_handle,VM_UART_READY_TO_READ,(VM_DCL_CALLBACK)UartIrqHandler,(void*)NULL); if(_usbNum == 2) { setPinHandle(0, uart_handle); } else { usb_device_handle = uart_handle; } }
void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode) { VM_DCL_HANDLE eint_handle; vm_eint_ctrl_config_t eint_config; vm_eint_ctrl_set_sensitivity_t sens_data; vm_eint_ctrl_set_hw_deounce_t deboun_time; VM_DCL_STATUS status; if(pin > EXTERNAL_NUM_INTERRUPTS) return ; detachInterrupt(pin); if(!changePinType(gExinterruptsPio[pin].pin, PIO_EINT, &eint_handle)) return; memset(&eint_config,0, sizeof(vm_eint_ctrl_config_t)); memset(&sens_data,0, sizeof(vm_eint_ctrl_set_sensitivity_t)); memset(&deboun_time,0, sizeof(vm_eint_ctrl_set_hw_deounce_t)); if(eint_handle == VM_DCL_HANDLE_INVALID) eint_handle = vm_dcl_open(VM_DCL_EINT,gExinterruptsPio[pin].eint); if(VM_DCL_HANDLE_INVALID == eint_handle) { vm_log_info("open EINT error"); return; } setPinHandle(gExinterruptsPio[pin].pin, eint_handle); gExinterruptsPio[pin].handle = eint_handle; gExinterruptsPio[pin].cb = callback; status = vm_dcl_control(eint_handle ,VM_EINT_CMD_MASK,NULL); /* Usually, before we config eint, we mask it firstly. */ if(status != VM_DCL_STATUS_OK) { vm_log_info("VM_EINT_CMD_MASK = %d", status); } status = vm_dcl_registercallback(eint_handle , VM_EVENT_EINT_TRIGGER,(VM_DCL_CALLBACK)eint_callback,(void*)NULL ); if(status != VM_DCL_STATUS_OK) { vm_log_info("VM_EVENT_EINT_TRIGGER = %d", status); } if(gExinterruptsPio[pin].first == 0) { if (mode == CHANGE) { sens_data.sensitivity = 0; eint_config.act_polarity = 0; eint_config.auto_unmask = 1; } else { if (mode == FALLING) { sens_data.sensitivity = 0; eint_config.act_polarity = 0; eint_config.auto_unmask = 1; } else if (mode == RISING) { sens_data.sensitivity = 0; eint_config.act_polarity = 1; eint_config.auto_unmask = 1; } else { vm_log_info("mode not support = %d", mode); } } status = vm_dcl_control(eint_handle ,VM_EINT_CMD_SET_SENSITIVITY,(void *)&sens_data); /* set eint sensitivity */ if(status != VM_DCL_STATUS_OK) { vm_log_info("VM_EINT_CMD_SET_SENSITIVITY = %d", status); } deboun_time.debounce_time = 1; /* debounce time 1ms */ status = vm_dcl_control(eint_handle ,VM_EINT_CMD_SET_HW_DEBOUNCE,(void *)&deboun_time); /* set debounce time */ if(status != VM_DCL_STATUS_OK) { vm_log_info("VM_EINT_CMD_SET_HW_DEBOUNCE = %d", status); } status = vm_dcl_control(eint_handle ,VM_EINT_CMD_MASK,NULL); /* Usually, before we config eint, we mask it firstly. */ if(status != VM_DCL_STATUS_OK) { vm_log_info("VM_EINT_CMD_MASK = %d", status); } eint_config.debounce_en = 0; /* 1 means enable hw debounce, 0 means disable. */ status = vm_dcl_control(eint_handle ,VM_EINT_CMD_CONFIG,(void *)&eint_config); /* Please call this api finally, because we will unmask eint in this command. */ if(status != VM_DCL_STATUS_OK) { vm_log_info("VM_EINT_CMD_CONFIG = %d", status); } if (mode == CHANGE) { vm_eint_ctrl_set_auto_change_pol_t auto_change; auto_change.autoChangePol = 1; status = vm_dcl_control(eint_handle ,VM_EINT_CMD_SET_AUTO_CHANGE_POLARTIY,(void *)&auto_change); /* Please call this api finally, because we will unmask eint in this command. */ if(status != VM_DCL_STATUS_OK) { vm_log_info("VM_EINT_CMD_CONFIG chage= %d", status); } } gExinterruptsPio[pin].first ++; } else { status = vm_dcl_control(eint_handle,VM_EINT_CMD_UNMASK,NULL); /* call this function to unmask this eint. */ if(status != VM_DCL_STATUS_OK) { vm_log_info("VM_EINT_CMD_CONFIG = %d", status); } } }