Esempio n. 1
0
static int gefb_set_par(struct fb_info *info)
{
	struct fb_var_screeninfo *var = &info->var;

	/* init your hardware here */
	if (var->bits_per_pixel == 8)
		info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
	else
		info->fix.visual = FB_VISUAL_TRUECOLOR;

	info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;

	if (ge_init(info))
		return -ENOMEM;

	return 0;
}
Esempio n. 2
0
/**
  * @brief  Main program.
  * @param  None 
  * @retval None
  */
int main(void)
{  

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  // Initialize library
  ge_init();

  // Initialize LEDs
  setup_led_gpio();
  led_state = false;
  led_speed = false;

  // Initialize the USER button as an input
  gpio_setup_pin(GE_PBTN2, GPIO_INPUT, false, false);

  // Initialize PBTN1
  gpio_setup_pin(GE_PBTN1, GPIO_INPUT, false, false);

  // Print to serial port
  printf("Hello, World!\n");

  // Print Hello World
  lcd_clear();
  lcd_goto(0, 0);
  lcd_puts("Hello, World!");

  // Setup timer library
  // Set minimum timestep to 1ms (number of counts referecned to 
  // a 72MHz clock)
  timer_set_timestep(72000);
  // register callback for toggling LEDs every 500ms
  led_timer = timer_register(500, &toggle_led, GE_PERIODIC);
  timer_start(led_timer);

  // set mode to the LED demo
  ui_state = LED_DEMO;

  // set pwm level for PWM demo
  float pwm_level = 0.0;

  // setup PWM library
  pwm_freq(10000.0);

  // setup ADC library
  // set sampling rate to 10kHz
  adc_set_fs(10000);
  // register callback method
  adc_callback(&my_adc_callback);
  // enable ADC channels
  adc_enable_channels(chan_to_conv, NUM_ADC);
  adc_initialize_channels();
  adc_start();

  // keep track of how many times the UI has looped
  num_refresh = 0;


  /* Infinite loop */
  /**
   * Handles the user interface state machine
   */
  while (1) {   
    switch (ui_state) {
      /**
       * User can toggle the flashing speed of the Discovery board
       * LEDs. This demos how the timer library can be used.
       */
      case LED_DEMO:
        //check if button depressed
        if (!gpio_read_pin(GE_PBTN2)) {
          if (led_speed) {
            timer_set_period(led_timer, 500);
            led_speed = false;
          } else {
            timer_set_period(led_timer, 100);
            led_speed = true;
          }

          // wait for button to be released
          while (!gpio_read_pin(GE_PBTN2));
        }
        break;

      case PWM_DEMO:
        pwm_level = pwm_level + .05;

        if (pwm_level > 1.0) pwm_level = 0.0;

        pwm_set(PWM_CHAN1, pwm_level);
        pwm_set(PWM_CHAN2, pwm_level);
        pwm_set(PWM_CHAN3, pwm_level);
        pwm_set(PWM_CHAN4, pwm_level);
        break;

      case ADC_DEMO:
        // print results every 10 refreshes
        num_refresh++;
        if (num_refresh >= 10) {
          num_refresh = 0;
          printf("%u\t%u\t%u\t%u\n", val[0], val[1], val[2], val[3]);
          // printf("%u\t%u\n", val[0], val[1]);
        }
        break;

      case USART_DEMO: ;
        if (ge_uart_available()) {
          uint8_t c = ge_uart_get();
          printf("%c\n", c);
          lcd_putc(c);
        }
        break;

      default:
        break;
    }

    // check whether to change state
    if (!gpio_read_pin(GE_PBTN1)) {
      // stop LED timer if necessary
      if (ui_state == LED_DEMO) timer_stop(led_timer);

      ui_state++;
      if (ui_state >= NUM_STATES) ui_state = LED_DEMO;

      change_state();

      // wait for button to be released
      while (!gpio_read_pin(GE_PBTN1));
    }

    delay_ms(50);
  }
}