Esempio n. 1
0
void HardwareInit(){

#ifdef DEBUG
	USART_Init(16); //(16)115200 8N1 (16MHz crystal)
#endif

	timer2_setup();

	DDRD	= (1<<LED1) | (1<<LED2) ; //status led1 & 2 output
	PORTD	= 0;

	DDRB	&= ~(1<<PB0);
	PORTB	|=  (1<<PB0);	// PB0 input with pull-up

	sei();
}
Esempio n. 2
0
void vga_setup ( unsigned char use_dma ) {

  /* Enable TIM2 clock. */
  rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM2EN);

  //__enable_irq();
  //cm_enable_interrupts();

  /* Without this the timer interrupt routine will never be called. */
  nvic_enable_irq ( NVIC_TIM2_IRQ );
  //nvic_set_priority(NVIC_TIM2_IRQ, 0);

  timer2_setup();

  vga_gpio_setup();

  if ( use_dma ) {
    dma_setup();
    vga_pixelclock_setup();
  }

  return;
}
Esempio n. 3
0
int main ( void ) {

#if 1 // go for 120MHz, built into libopencm3
  // requires: external 8MHz crystal on pin5/6 with associated caps to ground
  rcc_clock_setup_hse_3v3 ( &hse_8mhz_3v3 [ CLOCK_3V3_120MHZ ] );
#endif

#if 1 // fill framebuffer with offset squares
  //unsigned char i;
  unsigned int x, y;
  unsigned char v;
  for ( y = 0; y < FBHEIGHT; y++ ) {

    //i = 0;
    i = ( y / 10 ) % 5;

    for ( x = 0; x < FBWIDTH; x++ ) {

      if ( x % 10 == 0 ) {
        i++;
      }

      if ( i == 0 ) {
        v = (unsigned char) GPIO0;
      } else if ( i == 1 ) {
        v = (unsigned char) GPIO1;
      } else if ( i == 2 ) {
        v = (unsigned char) GPIO2;
      } else if ( i == 3 ) {
        v = (unsigned char) GPIO3;
      } else if ( i == 4 ) {
        v = (unsigned char) GPIO4;
      } else if ( i == 5 ) {
        v = (unsigned char) GPIO5;
      } else {
        i = 0;
        v = (unsigned char) GPIO0;
      }

      *( framebuffer + ( y * FBWIDTH ) + x ) = v;

      //*( framebuffer + ( y * FBWIDTH ) + x ) = (unsigned char) 0;
      //*( framebuffer + ( y * FBWIDTH ) + x ) = (unsigned char)( GPIO3 );
      //*( framebuffer + ( y * FBWIDTH ) + x ) = (unsigned char)( GPIO5 );
      //*( framebuffer + ( y * FBWIDTH ) + x ) = (unsigned char)( GPIO1 | GPIO3 );
      //*( framebuffer + ( y * FBWIDTH ) + x ) = (unsigned char)( GPIO1 | GPIO0 );
      //*( framebuffer + ( y * FBWIDTH ) + x ) = (unsigned char)( GPIO0 | GPIO1 );
      //*( framebuffer + ( y * FBWIDTH ) + x ) = (unsigned char)( GPIO0 | GPIO1 | GPIO2 | GPIO3 );
      //*( framebuffer + ( y * FBWIDTH ) + x ) = (unsigned char)( GPIO2 | GPIO3 );
      //*( framebuffer + ( y * FBWIDTH ) + x ) = (unsigned char)( GPIO4 | GPIO5 );

    } // x

  } // y
#endif

#if 0 // fill framebuffer with vertical stripes of all colours (1px per colour)
  //unsigned char i;
  unsigned int x, y;
  unsigned char v;

  for ( y = 0; y < FBHEIGHT; y++ ) {

    i = 0;
    for ( x = 0; x < FBWIDTH; x++ ) {

      *( framebuffer + ( y * FBWIDTH ) + x ) = i / 6;
      //*( framebuffer + ( y * FBWIDTH ) + x ) = (unsigned char)( GPIO0 | GPIO1 );

      i++;
    } // x

  } // y
#endif

#if 0 // vertical strip every 10 pixels
  //unsigned char i;
  unsigned int x, y;

  for ( y = 0; y < FBHEIGHT; y++ ) {

    i = 0;
    for ( x = 0; x < FBWIDTH; x++ ) {

      if ( i >= 9 ) {
        *( framebuffer + ( y * FBWIDTH ) + x ) = GPIO0;
      }

      if ( i == 12 ) {
        i = 0;
      }

      i++;
    } // x
  } // y
#endif

  gpio_setup();

  /* Enable TIM2 clock. */
  rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM2EN);

  //__enable_irq();
  //cm_enable_interrupts();

  nvic_setup();

  timer2_setup();

  dma_setup();

  gpio_set ( GPIOB, GPIO12 );

  TIM_SR(TIM2) &= ~TIM_SR_UIF; /* Clear interrrupt flag. */

  while ( 1 ) {
    __asm__("nop");
  } // while forever

  return 0;
}
Esempio n. 4
0
static void handle_data(void){
    #ifdef USE_STTERM
    unsigned char tmp_c;
    #endif

    uint32_t tmp=0;
    char crc=0;

    #ifdef USE_STTERM
    if(stlinky_rx_ready()){
        scanf("%c", &tmp_c);
        INPUT[k] = tmp_c;
        gpio_toggle(GPIOD, GPIO15);
    #else
    if(usart_has_data()){
        INPUT[k] = usart_read();
    #endif
    k++;
    if(k==1 && INPUT[0]!=0x53){ // 'S'
        #ifdef DEBUG
        printf("ERROR AT START-BYTE %d\r\n",INPUT[0]);
        #endif
        k=0;
    }
    if(k==10 && INPUT[9]!=0x45){ // 'E'
        #ifdef DEBUG
        printf("ERROR AT END-BYTE %d\r\n",INPUT[8]);
        #endif
        k=0;
    }
    if(k==11){
        #ifdef DEBUG
        printf("Package: ");
        for(tmp=0;tmp<10;tmp++) printf("%d ",INPUT[tmp]);
        printf("\n");
        #endif
        for(tmp=0;tmp<8;tmp++) KEYS[tmp] = INPUT[tmp+1];
        crc = getCRC(KEYS,8);
        if(crc==INPUT[10]){
            #ifdef DEBUG
            printf("INPUT OK!\r\n");
                #endif
                if(usb_ready == 3) usb_send_packet(KEYS, 8);
            }else{
                #ifdef DEBUG
                printf("ERROR AT CRC-BYTE %d vs %d\r\n",INPUT[10],crc);
                #endif
            }
            k=0;
        }
    }
}
void tim3_isr(void){
    if(timer_get_flag(TIM3, TIM_SR_UIF)){
        handle_data();
        timer_clear_flag(TIM3, TIM_SR_UIF);
    }
}

void tim4_isr(void){
    if(timer_get_flag(TIM4, TIM_SR_UIF)){
        if(usb_ready==3){
            gpio_toggle(GPIOD,GPIO14);
            KEYS[0]=0;
            KEYS[1]=0;
            KEYS[3]=0;
            KEYS[4]=0;
            KEYS[5]=0;
            KEYS[6]=0;
            KEYS[7]=0;

            KEYS[2]=0x04;
            usb_send_packet(KEYS, 8);
            KEYS[2]=0x00;
            usb_send_packet(KEYS, 8);
            KEYS[2]=0x05;
            usb_send_packet(KEYS, 8);
            KEYS[2]=0x00;
            usb_send_packet(KEYS, 8);
        }
        timer_clear_flag(TIM4, TIM_SR_UIF);
    }
}

void tim5_isr(void){
    if(timer_get_flag(TIM5, TIM_SR_UIF)){
        gpio_toggle(GPIOD, GPIO15);
        timer_clear_flag(TIM5, TIM_SR_UIF);
    }
}

int main(void) {
    iwdg_reset();
    iwdg_set_period_ms(5);
    iwdg_start();

    rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]);
    rcc_periph_clock_enable(RCC_GPIOD);
    systick_setup();

    gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15);
    gpio_clear(GPIOD, GPIO12 | GPIO13 | GPIO14 | GPIO15);

    iwdg_set_period_ms(500);
    iwdg_reset();
    msleep(400);
    iwdg_set_period_ms(5);
    iwdg_reset();

    gpio_set(GPIOD, GPIO15);

//    msleep(100000); /* SLEEEEEEEEEEEEEEEEEEEEEEP */

    #ifdef USE_STTERM
    stlinky_init();
    #else
    usart_setup();
    #endif

    timer2_setup(100);

    usb_setup();

    //timer4_setup(1);
    timer3_setup(100);
    timer5_setup(2);

//    gpio_set(GPIOD, GPIO12 | GPIO13 | GPIO14 | GPIO15);

    while(1) {
        iwdg_reset();
    }

    return 0;
}