Пример #1
0
int process_command(char** data){
	if (!data[0]) return 0;
	if (is_equal_string(data[0], "start")){
		int gpio = 0;
		int duty = 0;
		if (!data[1] || !data[2]) return 0;
		gpio = starts_with(data[1], "con:");
		duty = starts_with(data[2], "duty:");
		if (gpio == NA || duty == NA) return 0;
		dbg_print("Starts con %d, duty %d\r\n", gpio, duty);
		start_pwm(gpio, duty);
	} else if (is_equal_string(data[0], "stop")){
		int gpio = 0;
		if (!data[1] ) return 0;
		gpio = starts_with(data[1], "con:");
		if (gpio == NA ) return 0;
		dbg_print("Stops con %d\r\n", gpio);
		stop_pwm(gpio);
	} else if (is_equal_string(data[0], "period")){
		int period = 0;
		if (!data[1] ) return 0;
		period = starts_with(data[1], "");
		if (period == NA ) return 0;
		dbg_print("Period %d\r\n", period);
		set_period(period);
	}
	return 0;
}
Пример #2
0
void setup_pwm()
{ 
    // R_FORWARD on P3.4
    init_pwm(&TB1CTL);
  
    set_pwm_resolution(&TB1CCR0, PWM_RES);
    set_pwm_value(&TB1CCR1, PWM_RES / DIVIDE_BY_TWO);
    set_pwm_output(&TB1CCTL1);
    
    P3DIR |= R_FORWARD;
    P3SEL0 |= R_FORWARD;
    P3SEL1 &= ~R_FORWARD;   
    
    start_pwm(&TB1CTL);
    
    // L_FORWARD on P3.6
    init_pwm(&TB2CTL);
  
    set_pwm_resolution(&TB2CCR0, PWM_RES);
    set_pwm_value(&TB2CCR1, PWM_RES / DIVIDE_BY_TWO);
    set_pwm_output(&TB2CCTL1);
    
    P3DIR |= L_FORWARD;
    P3SEL0 |= L_FORWARD;
    P3SEL1 &= ~L_FORWARD;   
    
    start_pwm(&TB2CTL);
    
    // R_REVERSE on P3.5  
    set_pwm_value(&TB1CCR2, PWM_RES / DIVIDE_BY_TWO);
    set_pwm_output(&TB1CCTL2);
    
    P3DIR |= R_REVERSE;
    P3SEL0 |= R_REVERSE;
    P3SEL1 &= ~R_REVERSE;   
    
    // L_REVERSE on P3.7 
    set_pwm_value(&TB2CCR2, PWM_RES / DIVIDE_BY_TWO);
    set_pwm_output(&TB2CCTL2);
    
    P3DIR |= L_REVERSE;
    P3SEL0 |= L_REVERSE;
    P3SEL1 &= ~L_REVERSE;   
}
Пример #3
0
int main(int argc, char *argv[])
{
	int freq;
	while(1)
	{
		printf("Enter the frequency:- ");
		scanf("%d", &freq);
		start_pwm(freq, 50);
	}
	return 0;
}
Пример #4
0
int main(void)
{
    /* Do system initialization, eg: hardware, nvdm, logging and random seed. */
    system_init();

    /* bsp_ept_gpio_setting_init() under driver/board/mt76x7_hdk/ept will initialize the GPIO settings
     * generated by easy pinmux tool (ept). ept_*.c and ept*.h are the ept files and will be used by
     * bsp_ept_gpio_setting_init() for GPIO pinumux setup.
     */
    bsp_ept_gpio_setting_init();

    int nvdm_deviceKey_len = sizeof(deviceKey);
    int nvdm_deviceId_len = sizeof(deviceId);
    int nvdm_host_len = sizeof(host);

    nvdm_write_data_item("common", "deviceId", NVDM_DATA_ITEM_TYPE_STRING, (uint8_t *)deviceId, nvdm_deviceId_len);
    nvdm_write_data_item("common", "deviceKey", NVDM_DATA_ITEM_TYPE_STRING, (uint8_t *)deviceKey, nvdm_deviceKey_len);
    nvdm_write_data_item("common", "host", NVDM_DATA_ITEM_TYPE_STRING, (uint8_t *)host, nvdm_host_len);

    wifi_connection_register_event_handler(WIFI_EVENT_IOT_INIT_COMPLETE , _wifi_event_handler);
    wifi_connection_register_event_handler(WIFI_EVENT_IOT_CONNECTED, _wifi_event_handler);
    wifi_connection_register_event_handler(WIFI_EVENT_IOT_PORT_SECURE, _wifi_event_handler);
    wifi_connection_register_event_handler(WIFI_EVENT_IOT_DISCONNECTED, _wifi_event_handler);

    wifi_config.opmode = WIFI_MODE_STA_ONLY;

    strcpy((char *)wifi_config.sta_config.ssid, Ssid);
    wifi_config.sta_config.ssid_length = strlen(Ssid);
    strcpy((char *)wifi_config.sta_config.password, Password);
    wifi_config.sta_config.password_length = strlen(Password);

    xTaskCreate(wifi_initial_task, "User app", 1024, NULL, 1, NULL);

    /* Initialize pwm */
    start_pwm();

    /* Initialize cli task to enable user input cli command from uart port.*/
#if defined(MTK_MINICLI_ENABLE)
    cli_def_create();
    cli_task_create();
#endif

    vTaskStartScheduler();

    /* If all is well, the scheduler will now be running, and the following line
    will never be reached.  If the following line does execute, then there was
    insufficient FreeRTOS heap memory available for the idle and/or timer tasks
    to be created.  See the memory management section on the FreeRTOS web site
    for more details. */
    for ( ;; );
}
Пример #5
0
int main()
{
	seed_rand();
	setup_mcu();
	led_driver_init();
	pwm_timer_init();
	pir_init();
	
	// the PIR sensor takes a few seconds
	_delay_ms(5000);
	
	sei();
	
	uint8_t lower_pwm= 1;
	uint8_t upper_pwm= 70;
	uint8_t base_delay_interval= 10;
	
	while(1)
	{
		while( !(PIND && PD2) );
		
		uint8_t pins[4]= { PB1, PB2, PB3, PB4 };
		uint8_t pin_starts[4];
		uint8_t pin_pwm[4];
		uint16_t delay_count= 0;
		uint8_t still_fading= 1;
			
		for( uint8_t i= 0; i < 4; ++i )
		{
			// number of base_delay_interval intervals to wait before lighting them up
			pin_starts[i]= range_rand(50);
			pin_pwm[i]= lower_pwm;
		}
			
		// fade them up
		delay_count= 0;
		still_fading= 1;
		while( still_fading )
		{
			still_fading= 0;
				
			for( uint8_t i= 0; i < 4; ++i )
			{
				if( delay_count >= pin_starts[i] && pin_pwm[i] < upper_pwm )
				{
					pin_pwm[i]++;
					start_pwm( pins[i], pin_pwm[i] );
				}
					
				if( pin_pwm[i] < upper_pwm )
					still_fading= 1;
			}
				
			_delay_ms( base_delay_interval );
			delay_count++;
		}
			
		// wait for no more motion for 5 seconds
		delay_count= 0;
		while( delay_count < (5000/base_delay_interval) )
		{
			if( PIND && PD2 )
			{
				delay_count= 0;
				continue;
			}
			
			_delay_ms( base_delay_interval );
			delay_count++;
		}
		
		// fade them off
		for( uint8_t i= 0; i < 4; ++i )
		{
			// number of base_delay_interval intervals to wait before shutting them down
			pin_starts[i]= range_rand(60);
			pin_pwm[i]= upper_pwm;
		}
		
		delay_count= 0;
		still_fading= 1;
		while( still_fading )
		{
			still_fading= 0;
			
			for( uint8_t i= 0; i < 4; ++i )
			{
				if( delay_count >= pin_starts[i] )
				{
					if( pin_pwm[i] > lower_pwm )
					{
						pin_pwm[i]--;
					
						start_pwm( pins[i], pin_pwm[i] );
					}
					
					if( pin_pwm[i] <= lower_pwm )
						stop_pwm( pins[i] );
				}
				
				if( pin_pwm[i] > lower_pwm )
					still_fading= 1;
			}
			
			_delay_ms( base_delay_interval );
			delay_count++;
		}
		
		_delay_ms(2000);
	}
	
	return 0;
}