Ejemplo n.º 1
0
int main(void)
{
  // initialize
  SystemInit();
  initialise_monitor_handles();
  init_systick();

  /* Initialize the accelerometers */
  init_accelerometers();

  /* Initialize the LCD and Touch modules */
  Delay(0x3FFFFF);
  LCD_Init();
  Delay(0x3FFFFF);
  touch_init();

  /* Clear the LCD, set text color to green and backlight to 100 */
  LCD_Clear(BLACK);
  LCD_SetTextColor(GREEN);
  LCD_SetBackColor(LCD_COLOR_BLACK);
  LCD_BackLight(100);

  /* Add update_game to the timed_task array */
  add_timed_task(update_game, 0.05);

  while(1)
  {
    /* Check if the timed task function has to be called */
    update();
  }
}
Ejemplo n.º 2
0
// Main program
int main(void)
{
    char i;
    char *heap_end;
    
    // Initialize all modules
    uart_init(115200);
    accel_init();
    touch_init((1 << 9) | (1 << 10));       // Channels 9 and 10
    // usb_init();
    setvbuf(stdin, NULL, _IONBF, 0);        // No buffering

    // Run tests
    tests();
    delay(500);
    RGB_LED(0,100,0);                       // Green

    // Welcome banner
    iprintf("\r\n\r\n====== Freescale Freedom FRDM-LK25Z\r\n");
    iprintf("Built: %s %s\r\n\r\n", __DATE__, __TIME__);
    heap_end = _sbrk(0);
    iprintf("Heap:  %p to %p (%d bytes used)\r\n", __heap_start, heap_end, heap_end - __heap_start);
    iprintf("Stack: %p to %p (%d bytes used)\r\n", &i, __StackTop, __StackTop - &i);
    iprintf("%d bytes free\r\n", &i - heap_end);
    
    for(;;) {
        iprintf("monitor> ");
        getchar();
        iprintf("\r\n");
        iprintf("Inputs:  x=%5d   y=%5d   z=%5d ", accel_x(), accel_y(), accel_z());
        iprintf("touch=(%d,%d)\r\n", touch_data(9), touch_data(10));
        // usb_dump();
    }
}
Ejemplo n.º 3
0
void init_system(void)
{
	/* keep mosfet closed to ground (circuit on) */
	gpio_pre_init();

	/* timing first, needed for all delays */
        systick_init();

        /* get globalb config */
        config_read();

        lcd_init_gpio();
        lcd_init_fsmc();

        /* lcd inid always before touch_init, since it resets lcd */
        lcd_init();

        ui_init();

        gpio_init();
        adc_init();
        audio_init();

        rtc_init();

        touch_init();
}
Ejemplo n.º 4
0
void main(){
	//Init LCD
	__C30_UART=1;	
	lcd_initialize();
	lcd_clear();
        touch_init();

        CLEARBIT(T1CONbits.TON); // Disable Timer
        CLEARBIT(T1CONbits.TCS); // Select internal instruction cycle clock
        CLEARBIT(T1CONbits.TGATE); // Disable Gated Timer mode
        TMR1 = 0x00; // Clear timer register
        T1CONbits.TCKPS = 0b10; // Select 1:64 Prescaler
        PR1 = 2000; // Load the period value
        IPC0bits.T1IP = 0x01; // Set Timer1 Interrupt Priority Level
        CLEARBIT(IFS0bits.T1IF); // Clear Timer1 Interrupt Flag
        SETBIT(IEC0bits.T1IE); // Enable Timer1 interrupt



        while(1) {
            int i = 0;

            
            
            touch_select_dim(0);
            lock = 1;
            TMR1 = 0x00;
            SETBIT(T1CONbits.TON); // Start Timer
            while(lock);
            
            for (i = 0; i < 5; i++) {
                xs[i] = touch_adc();
            }

            // read y
            touch_select_dim(1);
            lock = 1;
            TMR1 = 0x00;
            SETBIT(T1CONbits.TON); // Start Timer
            while(lock);
            for (i = 0; i < 5; i++) {
                ys[i] = touch_adc();
            }

            

            qsort(xs, 5, sizeof(uint16_t), cmpfunc);
            qsort(ys, 5, sizeof(uint16_t), cmpfunc);

            lcd_locate(0,0);
            lcd_printf("x position:             ");
            lcd_locate(0,0);
            lcd_printf("x position: %d", xs[2]);
            lcd_locate(0,1);
            lcd_printf("y position:             ");
            lcd_locate(0,1);
            lcd_printf("y position: %d", ys[2]);
        }
}
static void __init touch_panel(int bus_num)
{
    /* touch init */
    touch_init();

	i2c_register_board_info(MSM_8960_GSBI3_QUP_I2C_BUS_ID,
			&synaptics_panel_i2c_bdinfo[0], 1);
}
Ejemplo n.º 6
0
void init()
{
	arduinoRun();
	lcd_init();

	dataflash_init();
	touch_init();
	bmp_init();
}
Ejemplo n.º 7
0
Archivo: ui.c Proyecto: InSoonPark/asf
void ui_init(void)
{

	touch_init();

	LED_Off(LED0_GPIO);
	LED_Off(LED1_GPIO);
	LED_On(LED2_GPIO);
	LED_Off(LED3_GPIO);
}
Ejemplo n.º 8
0
int
main(void)
{
  halInit();
  chSysInit();

  get_device_id();

  /* start stdout port */
  sdStart(SD_STDIO, NULL);

  xflash_init();
  cmdline_init();

  rngStart(&RNGD);

  app_cfg_init();

  check_for_faults();

  gfx_init();
  touch_init();

  sensor_init(SENSOR_1, SD_OW1);
  sensor_init(SENSOR_2, SD_OW2);

  temp_control_init(CONTROLLER_1);
  temp_control_init(CONTROLLER_2);

  ota_update_init();
  net_init();
  web_api_init();
  sntp_init();
  gui_init();
  thread_watchdog_init();

  create_home_screen();

  recovery_screen_create();

  screen_saver_create();

  if (palReadPad(PORT_SELF_TEST_EN, PAD_SELF_TEST_EN) == 0) {
    widget_t* self_test_screen = self_test_screen_create();
    gui_push_screen(self_test_screen);
  }

  recovery_img_init();

  while (TRUE) {
    cmdline_restart();

    toggle_LED1();
  }
}
Ejemplo n.º 9
0
void minig_init (void) {
    SDL_Init(SDL_INIT_EVERYTHING);
    window_size_get(&Mi.sx, &Mi.sy);
    gl_attributes_set();
    Window = SDL_CreateWindow("minig", 0, 0, Mi.sx, Mi.sy, flags);
    Context = SDL_GL_CreateContext(Window);
    SDL_GL_MakeCurrent(Window, Context);
    gl_ext_init();
    gl_configuration_set();

    menu_init();
    touch_init();
    square_init();

    // entity_particle_init();

}
static void __init touch_panel(int bus_num)
{
	/* touch init */
	touch_init();

#if defined(CONFIG_LGE_TOUCH_SYNAPTICS_325)
	i2c_register_board_info(lge_l1_touch_i2c_devices[maker_id_val].bus,
		lge_l1_touch_i2c_devices[maker_id_val].info,
		lge_l1_touch_i2c_devices[maker_id_val].len);
#elif defined(LGU_TOUCH)
	i2c_register_board_info(MSM_8960_GSBI3_QUP_I2C_BUS_ID,
					(&melfas_touch_panel_i2c_bdinfo[1]), 1);
#else
	i2c_register_board_info(MSM_8960_GSBI3_QUP_I2C_BUS_ID,
					(&melfas_touch_panel_i2c_bdinfo[0]), 1);
#endif

}
Ejemplo n.º 11
0
int main( void )
{

   /* initialise host app, pins, watchdog, etc */
    init_system();

    /* configure timer ISR to fire regularly */
    init_timer_isr();

	/* Initialize Touch sensors */
	touch_init();


    /* loop forever */
    for( ; ; )
    {
        touch_measure();

    /*  Time Non-critical host application code goes here  */
    }
}
static void __init touch_panel(int bus_num)
{
	/* touch init */
	touch_init();

	i2c_register_board_info(lge_vu2_touch_i2c_devices[maker_id_val].bus,
		lge_vu2_touch_i2c_devices[maker_id_val].info,
		lge_vu2_touch_i2c_devices[maker_id_val].len);
	
	/*
	if(lge_get_board_revno() < HW_REV_A) {
		i2c_register_board_info(MSM_8960_GSBI3_QUP_I2C_BUS_ID,
						(&melfas_touch_panel_i2c_bdinfo[0]), 1);
	} else if (lge_get_board_revno() == HW_REV_A) {
		i2c_register_board_info(MSM_8960_GSBI3_QUP_I2C_BUS_ID,
						(&melfas_touch_panel_i2c_bdinfo[1]), 1);
	} else if (lge_get_board_revno() > HW_REV_A) {
		i2c_register_board_info(MSM_8960_GSBI3_QUP_I2C_BUS_ID,
						(&melfas_touch_panel_i2c_bdinfo[2]), 1);
	}
	*/

}
Ejemplo n.º 13
0
/** Initializes all of the hardware. */
void initialize(void){

    CPU_PRESCALE(0x00);

    //LED
    DDRE |= (1<<PE2);

    //RGB LED
    DDRB |= (1<<PB5) | (1<<PB6);
    DDRC |= (1<<PC6);

    /** LUFA USB related inits */
	USB_Init();
	CDC_Device_CreateBlockingStream
        (&VirtualSerial_CDC_Interface, &USBSerialStream);

    touch_init();

    pwm16_rgb_init();
    
    /** enable interrupts*/
    sei();
}
Ejemplo n.º 14
0
// Main program
int main(void)
{
    char i;
    char ch;
    char *heap_end;
    char inBuffer[BUF_SIZE];
    int readLen,bufPos;
    int n;
    int nargs[10];
    int hasAccelData = 0;
    int hasTouchData = 0;

    // Initialize all modules
    RGB_LED(100,0,0);
    //uart_init(115200);
    uart_init(9600);
    accel_init();
    touch_init((1 << 9) | (1 << 10));       // Channels 9 and 10
    // usb_init();
    setvbuf(stdin, NULL, _IONBF, 0);        // No buffering

    // Run tests
    tests();
    delay(500);

    // Welcome banner
    iprintf("\r\n\r\n====== Freescale Freedom FRDM-LK25Z\r\n");
    iprintf("Built: %s %s\r\n\r\n", __DATE__, __TIME__);
    heap_end = _sbrk(0);
    iprintf("Heap:  %p to %p (%d bytes used)\r\n", __heap_start, heap_end, 
                heap_end - (char *)__heap_start);
    iprintf("Stack: %p to %p (%d bytes used)\r\n", &i, __StackTop, 
                (char *)__StackTop - &i);
    iprintf("%d bytes free\r\n", &i - heap_end);
    
    inBuffer[0] = 0;  // reset buffer
    bufPos = 0;

    RGB_LED(0,100,0);                       // Green

    for(;;) {
        readLen = uart_read_nonblock(inBuffer+bufPos,BUF_SIZE-(bufPos+2));
        if (readLen>0) {
            bufPos+=readLen;
            // quick trim
            while(bufPos>0 && isspace(inBuffer[bufPos-1]))
                  bufPos--;
            inBuffer[bufPos] = 0;
            if (inBuffer[bufPos-1] == ';') {
                iprintf("(in buf = '%s', len=%d)\r\n",inBuffer,bufPos);
                switch(inBuffer[0]) {
                case 'C':
                    n = sscanf(inBuffer+1,"%i,%i,%i",&nargs[0],&nargs[1],&nargs[2]);
                    if(n==3) RGB_LED(nargs[0],nargs[1],nargs[2]);
                    break;
                case 'R':
                    RGB_LED(100,0,0);
                    break;
                case 'G':
                    RGB_LED(0,100,0);
                    break;
                case 'B':
                    RGB_LED(0,0,100);
                    break;
                case 'A':
                    hasAccelData = 1;
                    break;
                case 'a':
                    hasAccelData = 0;
                    break;
                case 'T':
                    hasTouchData = 1;
                    break;
                case 't':
                    hasTouchData = 0;
                    break;
                case 'i':
                    iprintf("[efb,0.1] empiriKit Freescale Board, v.0.1\r\n");
                    break;
                }
                bufPos = 0;  // "clear" the buffer
            }
        }
        if (hasAccelData)
            iprintf("a%d,%d,%d;\r\n", accel_x(), accel_y(), accel_z());
        if (hasTouchData)
            iprintf("t%d,%d;\r\n", touch_data(9), touch_data(10));
    }
}
Ejemplo n.º 15
0
void SLIDER_init()
{
	touch_init(30, 30, 30, 30);
	
	
}
Ejemplo n.º 16
0
/**
 * \brief Initializes the TC subsystem ready to generate a LED PWM wave.
 *
 * Initializes the on-chip TC module in PWM generation mode, and configures the
 * board LED as an output so that the LED brightness can be adjusted.
 */
static void pwm_timer_init(void)
{
	// Assign output pin to timer/counter 0 channel B
	gpio_enable_module_pin(AVR32_TC0_B0_0_0_PIN,
			AVR32_TC0_B0_0_0_FUNCTION);

	// Timer waveform options
	const tc_waveform_opt_t waveform_options = {
		//! Channel selection.
		.channel  = 0,

		//! Software trigger effect on TIOB.
		.bswtrg   = TC_EVT_EFFECT_NOOP,
		//! External event effect on TIOB.
		.beevt    = TC_EVT_EFFECT_NOOP,
		//! RC compare effect on TIOB.
		.bcpc     = TC_EVT_EFFECT_CLEAR,
		//! RB compare effect on TIOB.
		.bcpb     = TC_EVT_EFFECT_SET,

		//! Software trigger effect on TIOA.
		.aswtrg   = TC_EVT_EFFECT_NOOP,
		//! External event effect on TIOA.
		.aeevt    = TC_EVT_EFFECT_NOOP,
		//! RC compare effect on TIOA.
		.acpc     = TC_EVT_EFFECT_NOOP,
		//! RA compare effect on TIOA.
		.acpa     = TC_EVT_EFFECT_NOOP,

		//! Waveform selection
		.wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,
		//! External event trigger enable.
		.enetrg   = false,
		//! External event selection (non-zero for Channel B to work)
		.eevt     = !0,
		//! External event edge selection.
		.eevtedg  = TC_SEL_NO_EDGE,
		//! Counter disable when RC compare.
		.cpcdis   = false,
		//! Counter clock stopped with RC compare.
		.cpcstop  = false,

		//! Burst signal selection.
		.burst    = false,
		//! Clock inversion selection.
		.clki     = false,
		//! Internal source clock 5, fPBA/128.
		.tcclks   = TC_CLOCK_SOURCE_TC5,
	};

	// Setup timer/counter waveform mode
	sysclk_enable_peripheral_clock(&AVR32_TC0);
	tc_init_waveform(&AVR32_TC0, &waveform_options);

	// Write the TOP (RC) and COMPARE (RB) values
	tc_write_rb(&AVR32_TC0, 0, 1);   // Set RB value.
	tc_write_rc(&AVR32_TC0, 0, 255); // Set RC value.

	// Start the timer PWM channel
	tc_start(&AVR32_TC0, 0);
}

/**
 * \brief Application main routine
 */
int main(void)
{
	board_init();
	sysclk_init();

	irq_initialize_vectors();
	cpu_irq_enable();

	pwm_timer_init();
	touch_init();

	while (true) {
		touch_handler();
	}
}
Ejemplo n.º 17
0
void vControl ( void *pvParameters )
{
	portTickType xLastWakeTime;
	signed char valx, valy;
	unsigned char ls, rs, lb, rb;

	can_frame_t out_frame;
	can_frame_t in_frame;
	out_frame.id = 1;
	out_frame.dlc = 6;

	xLastWakeTime = xTaskGetTickCount ();

	/* Button init */
	buttons_init ();

	/* FSM init */
	fsm_init ();

	/* CAN init */
	can_init ();

	/* ADC init */
	adc_init ( ctrlNUM_ADC_VALUES );

	/* Touch init */
	touch_init ( 30, 30, 30, 30 );

	while (1)
	{
		vTaskDelayUntil ( &xLastWakeTime, ctrlTASK_FREQUENCY );

		if ( adc_conversion_complete () == pdTRUE )
		{
			adc_disable ();
			adc_get_value ( &valx, 0 );
			adc_get_value ( &valy, 0 );
			touch_measure ( &ls, &rs, &lb, &rb );

			out_frame.data[0] = valx;
			out_frame.data[1] = valy;
			out_frame.data[2] = ls;
			out_frame.data[3] = rs;
			out_frame.data[4] = lb;
			out_frame.data[5] = rb;

			if (fsm_get_state() == ST_PLAY)
			{
				can_transmit (&out_frame);
			}
						
			can_receive (&in_frame, 0);

			if (in_frame.data[0] == GAME_SENSOR_TRIGGERED)
			{
				// TODO: set triggered state
				fsm_event_t *event = pvPortMalloc (sizeof (fsm_event_t));
				event->type = EV_STOP;
				event->ptr = NULL;
				fsm_event_put (event, portMAX_DELAY);
				in_frame.data[0] = 0;
			}
			else if (in_frame.data[0] == GAME_SENSOR_CLEARED)
			{
				// TODO: set cleared state
				in_frame.data[0] = 0;
			}

			adc_enable ();
			adc_conversion_start ();
		}

		fsm_update ();
	}
}
Ejemplo n.º 18
0
/**
 * \brief Main function.
 *
 * Initializes the board and reads out the production date stored in EEPROM and
 * set timezone from EEPROM if it is set. If it is not set it will open the
 * timezone selector to select the local timezone. It then runs the menu system
 * in an infinite while loop.
 */
int main(void)
{
	uint8_t menu_status;
	struct keyboard_event input;
	uint32_t rtc_timestamp;

	sysclk_init();
	board_init();
	pmic_init();
	gfx_mono_init();
	touch_init();
	adc_sensors_init();

	// Enable display backlight
	gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT);

	// Workaround for known issue: Enable RTC32 sysclk
	sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
	while (RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm) {
		// Wait for RTC32 sysclk to become stable
	}

	// If we have battery power and RTC is running, don't initialize RTC32
	if (rtc_vbat_system_check(false) != VBAT_STATUS_OK) {
		rtc_init();

		// Set current time to after production date
		rtc_timestamp = production_date_get_timestamp() + 1;
		rtc_set_time(rtc_timestamp);
	}

	// Get current time
	rtc_timestamp = rtc_get_time();
	// Make sure RTC has not been set to a too early date .
	if (rtc_timestamp < FIRST_POSSIBLE_TIMESTAMP) {
		// Set time to 01.01.2011 00:00:00
		rtc_set_time(FIRST_POSSIBLE_TIMESTAMP);
	}

	// Initialize USB CDC class
	cdc_start();

	cpu_irq_enable();

	// Display a splash screen showing button functions
	button_splash();

	// Set timezone from EEPROM or to a default value
	timezone_init();

	/* Main loop. Read keyboard status and pass input to menu system.
	 * When an element has been selected in the menu, it will return the
	 * index of the element that should be run. This can be an application
	 * or another menu.
	 */
	while (true) {

		// (re)initialize menu system
		gfx_mono_menu_init(&main_menu);

		do {
			do {
				keyboard_get_key_state(&input);
			// Wait for key release
			} while (input.type != KEYBOARD_RELEASE);

			// Send key to menu system
			menu_status = gfx_mono_menu_process_key(&main_menu, input.keycode);
		// Wait for something useful to happen in the menu system
		} while (menu_status == GFX_MONO_MENU_EVENT_IDLE);

		switch (menu_status) {
		case 0:
			ntc_sensor_application();
			break;
		case 1:
			lightsensor_application();
			break;
		case 2:
			production_date_application();
			break;
		case 3:
			date_time_application();
			break;
		case 4:
			// Toggle LCD Backlight
			gpio_toggle_pin(NHD_C12832A1Z_BACKLIGHT);
			break;
		case GFX_MONO_MENU_EVENT_EXIT:
			// Fall trough to default and show button splash
		default:
			button_splash();
			break;
		};
	}
}
Ejemplo n.º 19
0
/**
 * \brief Main function.
 *
 * Initializes the board, displays splash screens, then launches application.
 *
 * If the application exits (fails), the error is written to display and an
 * infinite loop with watchdog resets is entered.
 */
int main(void)
{
    /* Holds state of the QTouch button */
    enum pot_t potstate      = POT_OFF;
    /* Last state of the QTouch button for change detection */
    enum pot_t last_potstate = POT_OFF;
    /* Holds user-selected power-setting */
    uint8_t wattage      = 0;
    /* Last power-setting for change detection */
    uint8_t last_wattage = 0;
    /* Whether the plate element is/should be actuated */
    bool power      = false;
    /* Last power setting for change detection */
    bool last_power = false;
    /* Last time a simulation step was executed */
    uint32_t last_sim_step;
    /* Last time a control step was executed */
    uint32_t last_ctl_step;

    /* The WDT was just reset by the WDT functional test*/
    classb_last_wdt_reset = rtc_get_time();

    last_sim_step = classb_last_wdt_reset;
    last_ctl_step = classb_last_wdt_reset;

    sysclk_init();
    board_init();
    pmic_init();
    gfx_mono_init();
    touch_init();
    main_init_rtc32();

    cpu_irq_enable();

    /* Enable display backlight */
    ioport_set_pin_level(LCD_BACKLIGHT_ENABLE_PIN,
                         LCD_BACKLIGHT_ENABLE_LEVEL);

    /* If an error was detected, skip directly to displaying it */
    if (classb_error) {
        goto display_error;
    }


    /* Check if required jumpers are mounted, show explanation if not */
    if (!main_check_jumpers()) {
        show_explain_splash();
    }

    /* Display a splash screen showing button functions */
    show_button_splash();

    /* Initialize the ADC, DAC and Timer/Counter modules that are used to
     * emulate real world objects.
     */
    main_init_adc_dac();
    main_init_tc();

    /* Initialize subsystems used for Class B testing */
    oven_classb_init_tests();

    /* Reset the simulation states */
    oven_plant_init();

    /* Clear screen */
    gfx_mono_draw_filled_rect(0, 0, 128, 32, GFX_PIXEL_CLR);

    /* Draw the initial axis system */
    oven_ui_draw_axis();

    /* Draw the user interface */
    oven_ui_update_graphics(potstate, wattage, power);

    /* Run simulation as long as no error is detected in class B tests */
    while (!classb_error) {
        uint32_t current_time;

        oven_wdt_periodic_reset();
        current_time = rtc_get_time();

        /* Add power on SW1 press, wrap at 20 */
        if (oven_ui_power_button_is_pressed()) {
            wattage = (wattage + 5) % 20;
        }

        /* Check QTouch sensor and map this to `potstate`. This is
         * needed both for simulation and for the control routine.
         */
        potstate = (!touch_key_is_pressed()) ? POT_ON : POT_OFF;

        /* Execute control routine periodically */
        if (current_time > (last_ctl_step + OVEN_CTL_STEP_TIME)) {
            ovenctl_execute_control_step(current_time, &wattage,
                                         &power, potstate);
            last_ctl_step = current_time;
        }

        /* Execute simulation step periodically */
        if (current_time > (last_sim_step + OVEN_SIM_STEP_TIME)) {
            main_execute_simulation_step(current_time, potstate);
            last_sim_step = current_time;
        }

        /* Update graphics on wattage, power or pot on/off change */
        if ((potstate != last_potstate) || (power != last_power)
                || (wattage != last_wattage)) {
            oven_ui_update_graphics(potstate, wattage, power);
        }

        /* Update variable states for change detection on next loop
         * iteration.
         */
        last_power    = power;
        last_wattage  = wattage;
        last_potstate = potstate;

        /* If back/menu button is pressed, pause simulation and test
         * timers, and show menu.
         */
        if (oven_ui_back_button_is_pressed()) {
            /* Disable interrupt monitoring, if enabled */
            classb_intmon_set_state(TEMP_SANITY_TEST, M_DISABLE);
            classb_intmon_set_state(PER_CLASSB_TESTS, M_DISABLE);

            OVEN_PERIODIC_TEMPTEST_TC.CTRLA &= ~TC1_CLKSEL_gm;
            OVEN_PERIODIC_CLASSB_TC.CTRLA &= ~TC0_CLKSEL_gm;

            /* Show the error insertion menu */
            oven_classb_error_insertion();

            /* Re-enable timers upon return */
            OVEN_PERIODIC_CLASSB_TC.CTRLA |= TC_CLKSEL_DIV1024_gc;
            /* If user did not induce an error in the temperature
             * test timing, re-enable it correctly.
             */
            if ((OVEN_PERIODIC_TEMPTEST_TC.CTRLA & TC1_CLKSEL_gm)
                    == TC_CLKSEL_OFF_gc) {
                OVEN_PERIODIC_TEMPTEST_TC.CTRLA
                |= TC_CLKSEL_DIV1024_gc;
            }

            /* Re-enable interrupt monitoring if the oven is
             * supposed to be on, i.e., they were enabled before.
             */
            if (wattage > 0) {
                classb_intmon_set_state(TEMP_SANITY_TEST,
                                        M_ENABLE);
                classb_intmon_set_state(PER_CLASSB_TESTS,
                                        M_ENABLE);
            }

            /* Reset UI */
            gfx_mono_draw_filled_rect(0, 0, 128, 32, GFX_PIXEL_CLR);
            oven_ui_draw_axis();
            oven_ui_update_graphics(potstate, wattage, power);
        }
    }

display_error:
    /* Show red status LED and write the error on display */
    oven_ui_set_status_leds(S_RED);
    oven_classb_display_error();

    /* Enter infinite loop of watchdog resets so user can read display */
    while (true) {
        oven_wdt_periodic_reset();
    }
}
Ejemplo n.º 20
0
void touch_test(void)
{
	touch_init();
	key_irq_init();	
}
Ejemplo n.º 21
0
void ui_init(void)
{
    ui_has_initialized = 1;
    gr_init();
    ev_init(input_callback, NULL);
#ifdef BOARD_TOUCH_RECOVERY
    touch_init();
#endif

    text_col = text_row = 0;
    text_rows = gr_fb_height() / CHAR_HEIGHT;
    max_menu_rows = text_rows - MIN_LOG_ROWS;
#ifdef BOARD_TOUCH_RECOVERY
    max_menu_rows = get_max_menu_rows(max_menu_rows);
#endif
    if (max_menu_rows > MENU_MAX_ROWS)
        max_menu_rows = MENU_MAX_ROWS;
    if (text_rows > MAX_ROWS) text_rows = MAX_ROWS;
    text_top = 1;

    text_cols = gr_fb_width() / CHAR_WIDTH;
    if (text_cols > MAX_COLS - 1) text_cols = MAX_COLS - 1;

    int i;
    for (i = 0; BITMAPS[i].name != NULL; ++i) {
        int result = res_create_surface(BITMAPS[i].name, BITMAPS[i].surface);
        if (result < 0) {
            LOGE("Missing bitmap %s\n(Code %d)\n", BITMAPS[i].name, result);
        }
    }

    gProgressBarIndeterminate = malloc(ui_parameters.indeterminate_frames *
                                       sizeof(gr_surface));
    for (i = 0; i < ui_parameters.indeterminate_frames; ++i) {
        char filename[40];
        // "indeterminate01.png", "indeterminate02.png", ...
        sprintf(filename, "indeterminate%02d", i+1);
        int result = res_create_surface(filename, gProgressBarIndeterminate+i);
        if (result < 0) {
            LOGE("Missing bitmap %s\n(Code %d)\n", filename, result);
        }
    }

    if (ui_parameters.installing_frames > 0) {
        gInstallationOverlay = malloc(ui_parameters.installing_frames *
                                      sizeof(gr_surface));
        for (i = 0; i < ui_parameters.installing_frames; ++i) {
            char filename[40];
            // "icon_installing_overlay01.png",
            // "icon_installing_overlay02.png", ...
            sprintf(filename, "icon_installing_overlay%02d", i+1);
            int result = res_create_surface(filename, gInstallationOverlay+i);
            if (result < 0) {
                LOGE("Missing bitmap %s\n(Code %d)\n", filename, result);
            }
        }

        // Adjust the offset to account for the positioning of the
        // base image on the screen.
        if (gBackgroundIcon[BACKGROUND_ICON_INSTALLING] != NULL) {
            gr_surface bg = gBackgroundIcon[BACKGROUND_ICON_INSTALLING];
            ui_parameters.install_overlay_offset_x +=
                (gr_fb_width() - gr_get_width(bg)) / 2;
            ui_parameters.install_overlay_offset_y +=
                (gr_fb_height() - gr_get_height(bg)) / 2;
        }
    } else {
        gInstallationOverlay = NULL;
    }

    char enable_key_repeat[PROPERTY_VALUE_MAX];
    property_get("ro.cwm.enable_key_repeat", enable_key_repeat, "");
    if (!strcmp(enable_key_repeat, "true") || !strcmp(enable_key_repeat, "1")) {
        boardEnableKeyRepeat = 1;

        char key_list[PROPERTY_VALUE_MAX];
        property_get("ro.cwm.repeatable_keys", key_list, "");
        if (strlen(key_list) == 0) {
            boardRepeatableKeys[boardNumRepeatableKeys++] = KEY_UP;
            boardRepeatableKeys[boardNumRepeatableKeys++] = KEY_DOWN;
            boardRepeatableKeys[boardNumRepeatableKeys++] = KEY_VOLUMEUP;
            boardRepeatableKeys[boardNumRepeatableKeys++] = KEY_VOLUMEDOWN;
        } else {
            char *pch = strtok(key_list, ",");
            while (pch != NULL) {
                boardRepeatableKeys[boardNumRepeatableKeys++] = atoi(pch);
                pch = strtok(NULL, ",");
            }
        }
    }

    pthread_t t;
    pthread_create(&t, NULL, progress_thread, NULL);
    pthread_create(&t, NULL, input_thread, NULL);
}
int main(){
  uint8_t start_r, old_IPL;
  uint8_t hz50_scaler, hz5_scaler, hz1_scaler, sec;
  uint32_t tick = 0;

  hz50_scaler = hz5_scaler = hz1_scaler = sec = 0;

  touch_init();

  __delay_ms(200);
  lcd_initialize();             // Initialize the LCD 

  motor_init();

  lcd_clear();
  lcd_locate(0,0);
  lcd_printf("-- Ball position: --");

  timers_initialize();          // Initialize timers

  while (1) {
    start_r = 0;
    while(!start_r) {      
      // disable all maskable interrupts
      SET_AND_SAVE_CPU_IPL(old_IPL, 7);
      start_r = start;

      // enable all maskable interrupts
      RESTORE_CPU_IPL(old_IPL);
    }

    // Periodic real-time task code starts here = CENTER_X + RADIUS * cos(tick * SPEED);
//      Ypos_set = CENT!!!
    double pidX, pidY;
    uint16_t duty_us_x, duty_us_y;

    // 50Hz control task
    if(hz50_scaler == 0) {
      calcQEI(Xpos_set, Xpos, Ypos_set, Ypos);
//      Xpos_set = CENTER_X;
//      Xpos_set = CENTER_Y;
      Xpos_set = CENTER_X + RADIUS * cos(tick * SPEED);
      Ypos_set = CENTER_Y + RADIUS * sin(tick * SPEED);
      tick++;


      pidX = pidX_controller(Xpos);
      pidY = pidY_controller(Ypos);

      // TODO: Convert PID to motor duty cycle (900-2100 us)

      // setMotorDuty is a wrapper function that calls your motor_set_duty
      // implementation in flexmotor.c. The 2nd parameter expects a value
      // between 900-2100 us
//      duty_us_x = cap((pidX*1000.0), 2100, 900);
//      duty_us_y = cap((pidY*1000.0), 2100, 900);

      duty_us_x = cap((pidX + 1500), 2100, 900);
      duty_us_y = cap((pidY + 1500), 2100, 900);
      motor_set_duty(1, duty_us_x);
      motor_set_duty(2, duty_us_y+100);
//      setMotorDuty(MOTOR_X_CHAN, duty_us_x);
//      setMotorDuty(MOTOR_Y_CHAN, duty_us_y);
    }

    // 5Hz display task
    if(hz5_scaler == 0) {
//      lcd_locate(0,1);
//      lcd_printf("Xp=%.1f,Yp=%.1f", Xpos, Ypos);
//      lcd_locate(0,2);
//      lcd_printf("X*=%.1f, Y*=%.1f", Xpos_set, Ypos_set);
//      lcd_locate(0,3);
//      lcd_printf("pX=%.1f,pY=%.1f", pidX, pidY);
//      lcd_locate(0,4);
//      lcd_printf("dx=%u, dY=%u", duty_us_x, duty_us_y);
//
      if(deadline_miss >= 1) {
        lcd_locate(0,6);
        lcd_printf("%4d d_misses!!!", deadline_miss);
      }
    }

    // 1Hz seconds display task
    if(hz1_scaler == 0) {
      lcd_locate(0,7);
      lcd_printf("QEI: %5u", getQEI());
      sec++;
    }
    
    hz50_scaler = (hz50_scaler + 1) % 2;
    hz5_scaler = (hz5_scaler + 1) % 20;
    hz1_scaler = (hz1_scaler + 1) % 100;

    start = 0;
  }

  return 0;
}
Ejemplo n.º 23
0
int main( void )
{

   /* initialize host app, pins, watchdog, etc */
    // init_system();

    /* configure timer ISR to fire regularly */
    // init_timer_isr();
	
	// Configure CPU and peripherals clock
	xmega_set_cpu_clock_to_32MHz();
	
	// Enable interrupts
	PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
	
	// Power management - configure sleep mode to IDLE
	set_sleep_mode(SLEEP_SMODE_IDLE_gc);
	// Enable sleep mode
	sleep_enable();

#ifdef MMSN_DEBUG
	// Initialize serial communication terminal
	// usartCommTerminalInit();
	
	// Configure and initialize communication bus usart
	xmega_usart_configure();
		
	/* RS-485 PHYSICAL DEVICE CONFIGURATION */
	// Initialize GPIO related to RS-485 interface
	rs485_driver_gpio_initialize();
		
	// Enable driver to be able to send data
	rs485_driver_enable();

	// Redirect stream to standard output
	stdout = &mystdout;

	/* Print out welcome message */
	printf_P(PSTR("\nGeneric Board ver 1.00\n"));
#endif

	// Heartbeat timer - 8MHz prescales by 8 => 1MHz
	// Thus 1ms equals to 1000 ticks
	xmega_timer_config(&TIMER_HEARTBEAT, TC_CLKSEL_DIV8_gc, (TICKS_PER_MS * qt_measurement_period_msec));

	/* Initialize Touch sensors */
	touch_init();

	// Configure PIN6 as input
	PORT_DIRCLR(POWER_SUPPLY_MEASUREMENT_IO);
	
	// ADC conversion on pin 6
	uint16_t u16ConvResult = xmega_generate_adc_random_value(&ADCA, ADC_REFSEL_INT1V_gc | 0x02, ADC_CH_MUXPOS_PIN6_gc);
	printf("Power meter = %u\n", u16ConvResult);
	
	// Configure PIN5 as input
	PORT_DIRCLR(OPTO_IO);
	
	u16ConvResult = xmega_generate_adc_random_value(&ADCA, ADC_REFSEL_INT1V_gc | 0x02, ADC_CH_MUXPOS_PIN5_gc);
	printf("Opto = %u\n", u16ConvResult);

    /* loop forever */
    for(;;)
    {
        touch_measure();
		
		// Test every 2s
		if(gCounter >= 40)
		{
			printf("\n");
			printf("\nSensor[0]: %d - ", GET_SENSOR_STATE(0));
			printf("Sensor[1]: %d - ", GET_SENSOR_STATE(1));
			printf("Sensor[2]: %d - ", GET_SENSOR_STATE(2));
			printf("Sensor[3]: %d\n", GET_SENSOR_STATE(3));
			printf("Sensor[4]: %d - ", GET_SENSOR_STATE(4));
			printf("Sensor[5]: %d - ", GET_SENSOR_STATE(5));
			printf("Sensor[6]: %d - ", GET_SENSOR_STATE(6));
			printf("Sensor[7]: %d\n", GET_SENSOR_STATE(7));
			printf("Sensor[8]: %d - ", GET_SENSOR_STATE(8));
			printf("Sensor[9]: %d - ", GET_SENSOR_STATE(9));
			printf("Sensor[10]: %d - ", GET_SENSOR_STATE(10));
			printf("Sensor[11]: %d\n", GET_SENSOR_STATE(11));
			printf("Sensor[12]: %d - ", GET_SENSOR_STATE(12));
			printf("Sensor[13]: %d - ", GET_SENSOR_STATE(13));
			printf("Sensor[14]: %d - ", GET_SENSOR_STATE(14));
			printf("Sensor[15]: %d\n", GET_SENSOR_STATE(15));
			
			printf("Sensor[16]: %d - ", GET_SENSOR_STATE(16));
			printf("Sensor[17]: %d - ", GET_SENSOR_STATE(17));
			printf("Sensor[18]: %d - ", GET_SENSOR_STATE(18));
			printf("Sensor[19]: %d\n", GET_SENSOR_STATE(19));
			printf("Sensor[20]: %d - ", GET_SENSOR_STATE(20));
			printf("Sensor[21]: %d - ", GET_SENSOR_STATE(21));
			printf("Sensor[22]: %d - ", GET_SENSOR_STATE(22));
			printf("Sensor[23]: %d\n", GET_SENSOR_STATE(23));
			printf("Sensor[24]: %d - ", GET_SENSOR_STATE(24));
			printf("Sensor[25]: %d - ", GET_SENSOR_STATE(25));
			printf("Sensor[26]: %d - ", GET_SENSOR_STATE(26));
			printf("Sensor[27]: %d\n", GET_SENSOR_STATE(27));
			printf("Sensor[28]: %d - ", GET_SENSOR_STATE(28));
			printf("Sensor[29]: %d - ", GET_SENSOR_STATE(29));
			printf("Sensor[30]: %d - ", GET_SENSOR_STATE(30));
			printf("Sensor[31]: %d\n", GET_SENSOR_STATE(31));
			printf("\n");
			
			u16ConvResult = xmega_generate_adc_random_value(&ADCA, ADC_REFSEL_INT1V_gc, ADC_CH_MUXPOS_PIN5_gc);
			printf("Opto = %i\n", u16ConvResult);
			/*
			printf("\nCh_Sig[0]: %u	", qt_measure_data.channel_signals[0]);
			printf("Ch_Sig[1]: %u	", qt_measure_data.channel_signals[1]);
			printf("Ch_Sig[2]: %u	", qt_measure_data.channel_signals[2]);
			printf("Ch_Sig[3]: %u", qt_measure_data.channel_signals[3]);
			printf("\nCh_Sig[4]: %u	", qt_measure_data.channel_signals[4]);
			printf("Ch_Sig[5]: %u	", qt_measure_data.channel_signals[5]);
			printf("Ch_Sig[6]: %u	", qt_measure_data.channel_signals[6]);
			printf("Ch_Sig[7]: %u", qt_measure_data.channel_signals[7]);
			printf("\nCh_Sig[8]: %u	", qt_measure_data.channel_signals[8]);
			printf("Ch_Sig[9]: %u	", qt_measure_data.channel_signals[9]);
			
			printf("Ch_Sig[10]: %u	", qt_measure_data.channel_signals[10]);
			printf("Ch_Sig[11]: %u", qt_measure_data.channel_signals[11]);
			printf("\nCh_Sig[12]: %u	", qt_measure_data.channel_signals[12]);
			printf("Ch_Sig[13]: %u	", qt_measure_data.channel_signals[13]);
			printf("Ch_Sig[14]: %u	", qt_measure_data.channel_signals[14]);
			printf("Ch_Sig[15]: %u", qt_measure_data.channel_signals[15]);
			printf("\nCh_Sig[16]: %u	", qt_measure_data.channel_signals[16]);
			printf("Ch_Sig[17]: %u	", qt_measure_data.channel_signals[17]);
			printf("Ch_Sig[18]: %u	", qt_measure_data.channel_signals[18]);
			printf("Ch_Sig[19]: %u", qt_measure_data.channel_signals[19]);
			printf("\nCh_Sig[20]: %u	", qt_measure_data.channel_signals[20]);
			
			printf("Ch_Sig[21]: %u	", qt_measure_data.channel_signals[21]);
			printf("Ch_Sig[22]: %u	", qt_measure_data.channel_signals[22]);
			printf("Ch_Sig[23]: %u", qt_measure_data.channel_signals[23]);
			printf("\nCh_Sig[24]: %u	", qt_measure_data.channel_signals[24]);
			printf("Ch_Sig[25]: %u	", qt_measure_data.channel_signals[25]);
			printf("Ch_Sig[26]: %u	", qt_measure_data.channel_signals[26]);
			printf("Ch_Sig[27]: %u", qt_measure_data.channel_signals[27]);
			printf("\nCh_Sig[28]: %u	", qt_measure_data.channel_signals[28]);
			printf("Ch_Sig[29]: %u	", qt_measure_data.channel_signals[29]);
			printf("Ch_Sig[30]: %u	", qt_measure_data.channel_signals[30]);
			printf("Ch_Sig[31]: %u", qt_measure_data.channel_signals[31]); */
			
			printf("\ndelta[0]: %i	", qt_get_sensor_delta(0));
			printf("delta[1]: %i	", qt_get_sensor_delta(1));
			printf("delta[2]: %i	", qt_get_sensor_delta(2));
			printf("delta[3]: %i", qt_get_sensor_delta(3));
			printf("\ndelta[4]: %i	", qt_get_sensor_delta(4));
			printf("delta[5]: %i	", qt_get_sensor_delta(5));
			printf("delta[6]: %i	", qt_get_sensor_delta(6));
			printf("delta[7]: %i", qt_get_sensor_delta(7));
			printf("\ndelta[8]: %i	", qt_get_sensor_delta(8));
			printf("delta[9]: %i	", qt_get_sensor_delta(9));
			
			printf("delta[10]: %i	", qt_get_sensor_delta(10));
			printf("delta[11]: %i", qt_get_sensor_delta(11));
			printf("\ndelta[12]: %i	", qt_get_sensor_delta(12));
			printf("delta[13]: %i	", qt_get_sensor_delta(13));
			printf("delta[14]: %i	", qt_get_sensor_delta(14));
			printf("delta[15]: %i", qt_get_sensor_delta(15));
			printf("\ndelta[16]: %i	", qt_get_sensor_delta(16));
			printf("delta[17]: %i	", qt_get_sensor_delta(17));
			printf("delta[18]: %i	", qt_get_sensor_delta(18));
			printf("delta[19]: %i", qt_get_sensor_delta(19));
			printf("\ndelta[20]: %i	", qt_get_sensor_delta(20));
			
			printf("delta[21]: %i	", qt_get_sensor_delta(21));
			printf("delta[22]: %i	", qt_get_sensor_delta(22));
			printf("delta[23]: %i", qt_get_sensor_delta(23));
			printf("\ndelta[24]: %i	", qt_get_sensor_delta(24));
			printf("delta[25]: %i	", qt_get_sensor_delta(25));
			printf("delta[26]: %i	", qt_get_sensor_delta(26));
			printf("delta[27]: %i", qt_get_sensor_delta(27));
			printf("\ndelta[28]: %i	", qt_get_sensor_delta(28));
			printf("delta[29]: %i	", qt_get_sensor_delta(29));
			printf("delta[30]: %i	", qt_get_sensor_delta(30));
			printf("delta[31]: %i", qt_get_sensor_delta(31));
			
			gCounter = 0;
		}

    /*  Time Non-critical host application code goes here  */
    }
}