VMINT32 analogRead(VMUINT8 ulPin)
{
	vm_dcl_adc_control_create_object_t obj_data;
	VMINT status = 0 , i;
	vm_dcl_adc_control_send_start_t start_data;

	if(ulPin > 3)// for ADC0 ADC1 ADC2 ADC3
	{
		vm_log_info("ADC pin number is error");
		return -1;
	}

	vm_dcl_close(g_adc_handle);

	g_adc_handle = vm_dcl_open(VM_DCL_GPIO, ulPin);

	vm_dcl_control(g_adc_handle,VM_DCL_GPIO_COMMAND_SET_MODE_2,NULL);
	vm_dcl_close(g_adc_handle);

	// Open ADC device
	g_adc_handle = vm_dcl_open(VM_DCL_ADC,0);
	// register ADC result callback
	status = vm_dcl_register_callback(g_adc_handle, VM_DCL_ADC_GET_RESULT ,(vm_dcl_callback)adc_callback, (void *)NULL);

	// Indicate to the ADC module driver to notify the result.
	obj_data.owner_id = vm_dcl_get_owner_id();
	// Set physical ADC channel which should be measured.
	obj_data.channel = PIN2CHANNEL(ulPin);
	// Set measurement period, the unit is in ticks.
	obj_data.period = 1;
	// Measurement count.
	obj_data.evaluate_count = 1;
	// Whether to send message to owner module or not.
	obj_data.send_message_primitive = 1;

	// setup ADC object
	status = vm_dcl_control(g_adc_handle,VM_DCL_ADC_COMMAND_CREATE_OBJECT,(void *)&obj_data);

	// start ADC
	start_data.owner_id = vm_dcl_get_owner_id();
	status = vm_dcl_control(g_adc_handle,VM_DCL_ADC_COMMAND_SEND_START,(void *)&start_data);

	return g_adc_result;
}
Example #2
0
void key_init(void){
    VM_DCL_HANDLE kbd_handle;
    vm_dcl_kbd_control_pin_t kbdmap;

    kbd_handle = vm_dcl_open(VM_DCL_KBD,0);
    kbdmap.col_map = 0x09;
    kbdmap.row_map =0x05;
    vm_dcl_control(kbd_handle,VM_DCL_KBD_COMMAND_CONFIG_PIN, (void *)(&kbdmap));

    vm_dcl_close(kbd_handle);
}
Example #3
0
void detachInterrupt(uint32_t pin)
{
    if(VM_DCL_HANDLE_INVALID != gExinterruptsPio[pin].handle)
    {
    	vm_dcl_close(gExinterruptsPio[pin].handle);
    }
	gExinterruptsPio[pin].handle = VM_DCL_HANDLE_INVALID;
       gExinterruptsPio[pin].cb = NULL;
	g_APinDescription[gExinterruptsPio[pin].pin].ulHandle = VM_DCL_HANDLE_INVALID;
	g_APinDescription[gExinterruptsPio[pin].pin].ulPinType= PIO_DIGITAL;
}
Example #4
0
ADC_HANDLE open_hx711(int scl_pin, int sda_pin)
{
	ADC_HANDLE handle = 0;
	handle_details* details;
	hx711_task* task;

	while (open_handles[handle] != NULL)
	{
		handle++;
		if (handle > MAX_HANDLE)
		{
			return ADC_HANDLE_INVALID;
		}
	}

	details = vm_calloc(sizeof(handle_details));
	if (details == NULL)
	{
		return ADC_HANDLE_INVALID;
	}

	task = &details->task;
	task->scl_handle = vm_dcl_open(VM_DCL_GPIO, scl_pin);
	if (task->scl_handle == VM_DCL_HANDLE_INVALID)
	{
		vm_free(details);
		return ADC_HANDLE_INVALID;
	}
	vm_dcl_control(task->scl_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
	vm_dcl_control(task->scl_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_OUT, NULL);
	vm_dcl_control(task->scl_handle, VM_DCL_GPIO_COMMAND_WRITE_HIGH, NULL);

	task->sda_handle = vm_dcl_open(VM_DCL_GPIO, sda_pin);
	if (task->sda_handle == VM_DCL_HANDLE_INVALID)
	{
		vm_dcl_close(task->scl_handle);
		vm_free(details);
		return ADC_HANDLE_INVALID;
	}
	vm_dcl_control(task->sda_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
	vm_dcl_control(task->sda_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);

	vm_mutex_init(&details->mutex);
	task->op = WAIT;
	task->delay = 100;
	task->callback = dummy_callback;
	task->callback_env = NULL;
	open_handles[handle] = details;
	write_console("open\n");
	vm_thread_create(measurement, (void*) details, (VM_THREAD_PRIORITY) 0);
	return handle;
}
Example #5
0
void UARTClass::end( void )
{
// clear any received data
    _rx_buffer->_iHead = _rx_buffer->_iTail ;
    vm_dcl_close(uart_handle);
  
    if(_usbNum == 2)
    {
        g_APinDescription[0].ulHandle = VM_DCL_HANDLE_INVALID;
        g_APinDescription[0].ulPinType = PIO_DIGITAL;
    }
    else
    {
        usb_device_handle = -1;
    }
}
VMINT8 pinMode(VMUINT8 ulPin,VMUINT8 ulMode)
{
	VM_DCL_HANDLE gpio_handle;
	gpio_handle = vm_dcl_open(VM_DCL_GPIO, ulPin);

    if(gpio_handle != VM_DCL_HANDLE_INVALID)
    {
		switch(ulMode)
		{
			case INPUT:
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);
			break;

			case OUTPUT:
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_OUT, NULL);
			break;

			case INPUT_PULLUP:
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_ENABLE_PULL, NULL);
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_SET_PULL_HIGH, NULL);
			break;

			case INPUT_PULLDN:
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_ENABLE_PULL, NULL);
				vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_SET_PULL_LOW, NULL);
			break;

			default:
			break;
		}
    }
    else
    {
    	vm_log_info("gpio set pin mode fail");
    	return -1;
    }

	vm_dcl_close(gpio_handle);
	return TRUE;
}
void lcd_backlight_level(VMUINT32 ulValue)
{
    VM_DCL_HANDLE pwm_handle;
    vm_dcl_pwm_set_clock_t pwm_clock;
    vm_dcl_pwm_set_counter_threshold_t pwm_config_adv;
    vm_dcl_config_pin_mode(3, VM_DCL_PIN_MODE_PWM);
    pwm_handle = vm_dcl_open(PIN2PWM(3), vm_dcl_get_owner_id());
    vm_dcl_control(pwm_handle, VM_PWM_CMD_START, 0);
    pwm_config_adv.counter = 100;
    pwm_config_adv.threshold = ulValue;
    pwm_clock.source_clock = 0;
    pwm_clock.source_clock_division = 3;
    vm_dcl_control(pwm_handle, VM_PWM_CMD_SET_CLOCK, (void *) (&pwm_clock));
    vm_dcl_control(pwm_handle, VM_PWM_CMD_SET_COUNTER_AND_THRESHOLD,
            (void *) (&pwm_config_adv));
    vm_dcl_close(pwm_handle);
}
VMINT8 digitalWrite(VMUINT8 ulPin,VMUINT8 ulData)
{
	VM_DCL_HANDLE gpio_handle;
	gpio_handle = vm_dcl_open(VM_DCL_GPIO, ulPin);

    if(gpio_handle != VM_DCL_HANDLE_INVALID)
    {
		if(ulData == LOW)
			vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_WRITE_LOW, NULL);
		else if(ulData == HIGH)
			vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_WRITE_HIGH, NULL);
    }
    else
    {
    	vm_log_info("gpio write pin fail");
    	return -1;
    }

	vm_dcl_close(gpio_handle);
	return TRUE;
}
VMINT8 digitalRead(VMUINT8 ulPin)
{
	VM_DCL_HANDLE gpio_handle;
	vm_dcl_gpio_control_level_status_t data;
	VMUINT8 ret;

	gpio_handle = vm_dcl_open(VM_DCL_GPIO, ulPin);

    if(gpio_handle != VM_DCL_HANDLE_INVALID)
    {
		vm_dcl_control(gpio_handle, VM_DCL_GPIO_COMMAND_READ, (void*)&data);

		if (data.level_status == 1)ret = HIGH;
		else ret = LOW;
    }
    else
    {
    	vm_log_info("gpio read pin fail");
    	return -1;
    }

    vm_dcl_close(gpio_handle);
    return ret;
}
Example #10
0
void attachInterrupt(VMUINT32 pin, void (*callback)(void), VMUINT32 mode)
{

	VM_DCL_HANDLE gpio_handle;
    VM_DCL_HANDLE eint_handle;
    vm_dcl_eint_control_config_t eint_config;
    vm_dcl_eint_control_sensitivity_t sens_data;
    vm_dcl_eint_control_hw_debounce_t deboun_time;
    VM_DCL_STATUS status;

    VMUINT8 i;
    for(i=0;i<EXTERNAL_NUM_INTERRUPTS;i++)
	{
    	if(gExinterruptsPio[i].pin == pin)
		{
    		vm_log_info("open EINT number is %d",gExinterruptsPio[i].eint);
			break;
		}
	}
    if(i == EXTERNAL_NUM_INTERRUPTS)
	{
    	vm_log_info("open EINT number error");
    	return;
	}

	detachInterrupt(pin);

	gpio_handle = vm_dcl_open(VM_DCL_GPIO,pin);
	if(gpio_handle == VM_DCL_HANDLE_INVALID)
	{
		vm_log_info("open eint gpio error, gpio_handle is %d", gpio_handle);
		return;
	}
	switch(pin)
	{
		case 0:case 1:case 2:
			vm_log_info("VM_DCL_GPIO_COMMAND_SET_MODE_1");
			vm_dcl_control(gpio_handle,VM_DCL_GPIO_COMMAND_SET_MODE_1,NULL);
		break;

		case 13:case 18:case 46:case 52:
			vm_log_info("VM_DCL_GPIO_COMMAND_SET_MODE_2");
			vm_dcl_control(gpio_handle,VM_DCL_GPIO_COMMAND_SET_MODE_2,NULL);
		break;

		case 10:case 11:
			vm_log_info("VM_DCL_GPIO_COMMAND_SET_MODE_3");
			vm_dcl_control(gpio_handle,VM_DCL_GPIO_COMMAND_SET_MODE_3,NULL);
		break;

		case 25:
			vm_log_info("VM_DCL_GPIO_COMMAND_SET_MODE_4");
			vm_dcl_control(gpio_handle,VM_DCL_GPIO_COMMAND_SET_MODE_4,NULL);
		break;

		default:
		break;
	}
	vm_dcl_control(gpio_handle,VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);
	vm_dcl_close(gpio_handle);


    memset(&eint_config,0, sizeof(vm_dcl_eint_control_config_t));
    memset(&sens_data,0, sizeof(vm_dcl_eint_control_sensitivity_t));
    memset(&deboun_time,0, sizeof(vm_dcl_eint_control_hw_debounce_t));

	eint_handle = vm_dcl_open(VM_DCL_EINT,gExinterruptsPio[i].eint);

    if(VM_DCL_HANDLE_INVALID == eint_handle)
    {
        vm_log_info("open EINT error, eint_handle is %d",eint_handle);
        return;
    }

    gExinterruptsPio[i].handle = eint_handle;
    gExinterruptsPio[i].cb = callback;

    status = vm_dcl_control(eint_handle ,VM_DCL_EINT_COMMAND_MASK,NULL);  // Usually, before we config eint, we mask it firstly.
    if(status != VM_DCL_STATUS_OK)
    {
    	vm_log_info("VM_DCL_EINT_COMMAND_MASK  = %d", status);
    }

	status = vm_dcl_register_callback(eint_handle , VM_DCL_EINT_EVENT_TRIGGER,(vm_dcl_callback)eint_callback,(void*)NULL );
	if(status != VM_DCL_STATUS_OK)
	{
		vm_log_info("VM_DCL_EINT_EVENT_TRIGGER = %d", status);
	}

    if(gExinterruptsPio[i].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_DCL_EINT_COMMAND_SET_SENSITIVITY,(void *)&sens_data);  /* set eint sensitivity */
	    if(status != VM_DCL_STATUS_OK)
	    {
	        vm_log_info("VM_DCL_EINT_COMMAND_SET_SENSITIVITY = %d", status);
	    }

	    deboun_time.debounce_time = 1;  // debounce time 1ms
	    status = vm_dcl_control(eint_handle ,VM_DCL_EINT_COMMAND_SET_HW_DEBOUNCE,(void *)&deboun_time); /* set debounce time */
	    if(status != VM_DCL_STATUS_OK)
	    {
	        vm_log_info("VM_DCL_EINT_COMMAND_SET_HW_DEBOUNCE = %d", status);
	    }

	    status = vm_dcl_control(eint_handle ,VM_DCL_EINT_COMMAND_MASK,NULL);  /* Usually, before we config eint, we mask it firstly. */
	    if(status != VM_DCL_STATUS_OK)
	    {
	    	vm_log_info("VM_DCL_EINT_COMMAND_MASK  = %d", status);
	    }

	    eint_config.debounce_enable = 0;    // 1 means enable hw debounce, 0 means disable.

	    status = vm_dcl_control(eint_handle ,VM_DCL_EINT_COMMAND_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_DCL_EINT_COMMAND_CONFIG = %d", status);
	    }

	    if (mode == CHANGE)
	    {
	    	vm_dcl_eint_control_auto_change_polarity_t auto_change;
		    auto_change.auto_change_polarity = 1;
	        status = vm_dcl_control(eint_handle ,VM_DCL_EINT_COMMAND_SET_AUTO_CHANGE_POLARITY,(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_DCL_EINT_COMMAND_CONFIG change = %d", status);
	        }
	    }

	    gExinterruptsPio[i].first ++;

	    vm_log_info("attach Interrupt ok.");
    }
    else
    {
        status = vm_dcl_control(eint_handle,VM_DCL_EINT_COMMAND_UNMASK,NULL);  // call this function to unmask this eint.
        if(status != VM_DCL_STATUS_OK)
        {
             vm_log_info("VM_DCL_EINT_COMMAND_CONFIG = %d", status);
        }
    }
}
static VM_DRV_TP_BOOL ctp_goodix_gt9xx_init(void) {
	VM_DCL_HANDLE sda_handle, scl_handle;
	VM_DCL_HANDLE eint_handle, reset_handle;
	VM_DRV_TP_BOOL ack;
	ctp_info_t ctp_info;
	VMUINT16 reg_value;

	VMUINT8 i = 0;

	//turn on VSIM1
	*VSIM1_CON2 = *VSIM1_CON2 | 0x0002;
	*VSIM1_CON0 = *VSIM1_CON0 | 0x0001;

	// init i2c
	if (gpio_ctp_i2c_sda_pin != 0xFF) {
		sda_handle = vm_dcl_open(VM_DCL_GPIO, gpio_ctp_i2c_sda_pin);
		scl_handle = vm_dcl_open(VM_DCL_GPIO, gpio_ctp_i2c_scl_pin);

		vm_dcl_control(sda_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
		vm_dcl_control(scl_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
		CTP_DELAY_TIME = 3;
	}

	ctp_i2c_configure(CTP_SLAVE_ADDR, CTP_DELAY_TIME);

	eint_handle = vm_dcl_open(VM_DCL_GPIO, gpio_ctp_eint_pin);
	reset_handle = vm_dcl_open(VM_DCL_GPIO, gpio_ctp_reset_pin);

	////////////////////////////reset//////////////////////////////////
	vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_OUT, NULL);
	vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_WRITE_LOW, NULL);

	vm_dcl_control(reset_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
	vm_dcl_control(reset_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_OUT, NULL);
	vm_dcl_control(reset_handle, VM_DCL_GPIO_COMMAND_WRITE_LOW, NULL);
	delay_ms(5);
	vm_dcl_control(reset_handle, VM_DCL_GPIO_COMMAND_WRITE_HIGH, NULL);
	delay_ms(10);
	//////////////////////////////////////////////////////////////////
	vm_dcl_close(eint_handle);
	vm_dcl_close(reset_handle);

	//vm_dcl_control(eint_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);
	//vm_dcl_control(eint_handle, gpio_ctp_eint_pin_M_EINT, NULL);
	//EINT_Set_Sensitivity(custom_eint_get_channel(touch_panel_eint_chann), EDGE_SENSITIVE);
	ctp_init_EINT();

	ack = ctp_goodix_gt9xx_set_configuration();
	if (ack == VM_DRV_TP_FALSE) {
		vm_log_info("ctp_goodix_gt9xx_set_configuration fail!!!");
		return VM_DRV_TP_FALSE;
	}
	vm_log_info("ctp_goodix_gt9xx_set_configuration OK!!!");

	ack = ctp_goodix_gt9xx_get_information(&ctp_info);

	if (ack == VM_DRV_TP_FALSE) {
		vm_log_info("read information fail");
		return VM_DRV_TP_FALSE;
	}

	return VM_DRV_TP_TRUE;

}