Beispiel #1
0
int main(void)
{
	clock_setup();
	gpio_setup();
	tim_setup();
	spi_setup();
	dac_setup();
	dma_setup();
	usb_setup();

	/* Attach the device to USB. */
	syscfg_enable_usb_pullup();

	/* Clear interrupt. */
	usbdevfs_clear_interrupt(USBDEVFS_ALL_INTERRUPT);

	/* Enable interrupt. */
	usbdevfs_enable_interrupt(USBDEVFS_CORRECT_TRANSFER | USBDEVFS_ERROR |
				  USBDEVFS_RESET | USBDEVFS_SOF);

	/* Wait forever and do nothing. */
	while (1)
		__asm__ ("nop");

	return 0;
}
void usbh_kbd_init(void)
{
	clock_setup();
	gpio_setup();

	tim_setup();

	usart_init();
	gpio_set(GPIOD,  GPIO13);
}
int main(void)
{
	clock_setup();
	gpio_setup();
	tim_setup();

	while (1)
		__asm("nop");

	return 0;
}
Beispiel #4
0
/*******************************************
 * Main
 */
int main(void)
{
    uint32_t i;
    uint8_t d1 = 0;
    int8_t delta = +1; // Step for testing

    clock_init();
    gpio_setup();
    tim_setup();
    i2c_setup();
    lcd_init();

    lcd_seekto(1, 0 );
    lcd_writes("................");

    while (1) {
        // Blink
        gpio_toggle(GPIOB, GPIO1);

        // Put chars to LCD
        //lcd_putchar(' ' + d1);
        lcd_home();
        lcd_writes("Count ");
        lcd_write_uint(d1, 3);

        if( d1 % 10 == 0 )
        {
            lcd_seekto(1, d1 / 10 );
            lcd_writes(".<^^>.");
        }

        // Spinwait s bit
        for (i = 0; i < ( 20 * 72000 ); i++)
        {
            __asm__("nop");
        }

        // Sweep PWM
        d1 += delta;

        // Pingpong
        if( d1 >= 100 )
            delta = -1;
        else if( d1 <= 0 )
            delta = +1;

        pwm_set( d1 );
    }

    // Never reached
    return 0;
}
Beispiel #5
0
int main(void)
{
	clock_setup();
	gpio_setup();
	tim_setup();

	/* Loop calling Wait For Interrupt. In older pre cortex ARM this is
	 * just equivalent to nop. On cortex it puts the cpu to sleep until
	 * one of the three occurs:
	 *
	 * a non-masked interrupt occurs and is taken
	 * an interrupt masked by PRIMASK becomes pending
	 * a Debug Entry request
	 */
	while (1)
		__WFI(); /* Wait For Interrupt. */

	return 0;
}
Beispiel #6
0
int main(void) {
    clock_setup();
    gpio_setup();
    usart_setup();
    systick_setup();
    tim_setup();

    /* wait 3 seconds to allow Linux detecting /dev/ttyUSB */
    while (systick_counter_ms < 3000) ;

    /* output signal is on GPIO C 10 (EXT1-8) */
    /* gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_TRIGGER); */

    while (1) {
	/* If the input signal is high */
	if (gpio_get(GPIO_BANK_TIM1_CH2, GPIO_TIM1_CH2) != 0) {
	    /* Output a raising edge */
	    gpio_set(GPIOC, GPIO_TRIGGER);
	    /* Wait for the input signal going down, max 2 ms */
	    for (systick_counter_ms = 0; systick_counter_ms < 2;)
		if (gpio_get(GPIO_BANK_TIM1_CH2, GPIO_TIM1_CH2) == 0)
		    break;
	    /* Output a falling edge */
	    gpio_clear(GPIOC, GPIO_TRIGGER);
	} else {
	    latency = 0;
	    /* Output a raising edge (trigger signal) */
	    gpio_set(GPIOC, GPIO_TRIGGER);
	    /* Wait for the latency to be available */
	    for (systick_counter_ms = 0; systick_counter_ms < 2;)
		if (latency != 0)
		    break;
	    /* Output a falling edge */
	    gpio_clear(GPIOC, GPIO_TRIGGER);
	    if (latency != 0)
		printf("%3d - %3d\n", latency, latency_max);
	}

	/* Wait 1 ms before next trigger */
	for (systick_counter_ms = 0; systick_counter_ms < 1;) ;
    }
}
Beispiel #7
0
int main(void)
{
	int i, j0, j1, j2, j3, d0, d1, d2, d3, j, k, kd;

	clock_setup();
	gpio_setup();
	tim_setup();

#ifdef COMPARE
	j0 = 0;
	d0 = 1;
	j1 = 0;
	d1 = 1;
	j2 = 0;
	d2 = 1;
	j3 = 0;
	d3 = 1;
	while (1) {
		TIM1_CCR1 = gamma_table_linear[j0];
		j0 += d0;
		if (j0 == 255)
			d0 =- 1;
		if (j0 == 0)
			d0 = 1;
		TIM1_CCR2 = gamma_table_1_3[j1];
		j1 += d1;
		if (j1 == 255)
			d1 =- 1;
		if (j1 == 0)
			d1 = 1;
		TIM1_CCR3 = gamma_table_2_5[j2];
		j2 += d2;
		if (j2 == 255)
			d2 =- 1;
		if (j2 == 0)
			d2 = 1;
		TIM1_CCR4= gamma_table_3_0[j3];
		j3 += d3;
		if (j3 == 255)
			d3 =- 1;
		if (j3 == 0)
			d3 = 1;
		for (i = 0; i < 50000; i++);
	}
#endif

#ifdef MOVING_FADE
	j0 = 0;
	d0 = 1;
	j1 = 128;
	d1 = 1;
	j2 = 255;
	d2 = -1;
	j3 = 128;
	d3 = -1;
	while (1) {
		TIM1_CCR1 = GAMMA_TABLE[j0];
		j0 += d0;
		if (j0 == 255)
			d0 =- 1;
		if (j0 == 0)
			d0 = 1;
		TIM1_CCR2 = GAMMA_TABLE[j1];
		j1 += d1;
		if (j1 == 255)
			d1 =- 1;
		if (j1 == 0)
			d1 = 1;
		TIM1_CCR3 = GAMMA_TABLE[j2];
		j2 += d2;
		if (j2 == 255)
			d2 =- 1;
		if (j2 == 0)
			d2 = 1;
		TIM1_CCR4 = GAMMA_TABLE[j3];
		j3 += d3;
		if (j3 == 255)
			d3 =- 1;
		if (j3 == 0)
			d3 = 1;
		for (i = 0; i < 10000; i++);
	}
#endif

#ifdef KITT
	j0 = 255;
	d0 = -1;
	j1 = 20;
	d1 = -1;
	j2 = 20;
	d2 = -1;
	j3 = 20;
	d3 = -1;
	j = 0;
	k = 0;
	kd = 1;
	while (1) {
		TIM1_CCR1 = GAMMA_TABLE[j0];
		j0 += d0;
		if (j0 == 255)
			d0 =- 1;
		if (j0 == 19)
			j0 = 20;
		TIM1_CCR2 = GAMMA_TABLE[j1];
		j1 += d1;
		if (j1 == 255)
			d1 =- 1;
		if (j1 == 19)
			j1 = 20;
		TIM1_CCR3 = GAMMA_TABLE[j2];
		j2 += d2;
		if (j2 == 255)
			d2 =- 1;
		if (j2 == 19)
			j2 = 20;
		TIM1_CCR4 = GAMMA_TABLE[j3];
		j3 += d3;
		if (j3 == 255)
			d3 =- 1;
		if (j3 == 19)
			j3 = 20;
		for (i = 0; i < 5000; i++);
		j++;
		if (j == 100) {
			j = 0;
			switch (k += kd) {
				case 0:
					j0 = 255;
					break;
				case 1:
					j1 = 255;
					break;
				case 2:
					j2 = 255;
					break;
				case 3:
					j3 = 255;
					break;
			}
			if (k == 3)
				kd =- 1;
			if (k == 0)
				kd = 1;
		}
	}
#endif

	return 0;
}
void Encoder::Init(void)
{
   rcc_peripheral_enable_clock(&RCC_APB1ENR, REV_CNT_RCC_ENR);
   tim_setup();
   last_pulse_timespan = MAX_CNT;
}