Ejemplo n.º 1
0
void stm32_boardinitialize(void)
{
#ifdef CONFIG_STM32_FSMC
  /* If the FSMC is enabled, then enable SRAM access */

  stm32_stram_configure();
#endif

#ifdef CONFIG_STM32_OTGFS
  /* Initialize USB if the 1) OTG FS controller is in the configuration and 2)
   * disabled, and 3) the weak function stm32_usb_configure() has been brought
   * into the build. Presumably either CONFIG_USBDEV or CONFIG_USBHOST is also
   * selected.
   */

  stm32_usb_configure();
#endif

  /* Configure on-board LEDs if LED support has been selected. */

#ifdef CONFIG_ARCH_LEDS
  board_autoled_initialize();
#endif

  /* Configure on-board BUTTONs if BUTTON support has been selected. */

#ifdef CONFIG_ARCH_BUTTONS
  board_button_initialize();
#endif
}
Ejemplo n.º 2
0
void stm32_boardinitialize(void)
{
  /* Configure on-board LEDs if LED support has been selected. */

#ifdef CONFIG_ARCH_LEDS
  board_autoled_initialize();
#endif

#ifdef CONFIG_ARCH_BUTTONS
  board_button_initialize();
#endif

  /* Configure SPI chip selects if 1) SP2 is not disabled, and 2) the weak function
   * stm32_spidev_initialize() has been brought into the link.
   */

#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3)
      stm32_spidev_initialize();
#endif


  /* Initialize USB is 1) USBDEV is selected, 2) the USB controller is not
   * disabled, and 3) the weak function stm32_usbinitialize() has been brought
   * into the build.
   */

#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_USB)
  stm32_usbinitialize();
#endif
}
Ejemplo n.º 3
0
void stm32_boardinitialize(void)
{
  /* Initialize USB if the 1) OTG FS controller is in the configuration and 2)
   * disabled, and 3) the weak function stm32_usbinitialize() has been brought
   * into the build. Presumeably either CONFIG_USBDEV or CONFIG_USBHOST is also
   * selected.
   */

#ifdef CONFIG_STM32_OTGFS
  if (stm32_usbinitialize)
    {
      stm32_usbinitialize();
    }
#endif

  /* Configure on-board LEDs if LED support has been selected. */

#ifdef CONFIG_ARCH_LEDS
  board_autoled_initialize();
#endif

  /* Configure on-board BUTTONs if BUTTON support has been selected. */

#ifdef CONFIG_ARCH_BUTTONS
  board_button_initialize();
#endif
}
Ejemplo n.º 4
0
void stm32_pm_buttons(void)
{
  /* Initialize the button GPIOs */

  board_button_initialize();

#ifdef CONFIG_ARCH_IRQBUTTONS
  (void)board_button_irq(0, button_handler, NULL);
#endif
}
Ejemplo n.º 5
0
void stm32_pm_buttons(void)
{
  /* Initialize the button GPIOs */

  board_button_initialize();

#ifdef CONFIG_ARCH_IRQBUTTONS
      xcpt_t oldhandler = board_button_irq(0, button_handler);

      if (oldhandler != NULL)
        {
          lowsyslog(LOG_WARNING, "WARNING: oldhandler:%p is not NULL!  "
                   "Button events may be lost or aliased!\n",
                   oldhandler);
        }
#endif
}
Ejemplo n.º 6
0
__END_DECLS


/****************************************************************************
 * Pre-Processor Definitions
 ****************************************************************************/

/* Configuration ************************************************************/

/* Debug ********************************************************************/

/****************************************************************************
 * Protected Functions
 ****************************************************************************/

/****************************************************************************
 * Public Functions
 ****************************************************************************/

/************************************************************************************
 * Name: stm32_boardinitialize
 *
 * Description:
 *   All STM32 architectures must provide the following entry point.  This entry point
 *   is called early in the initialization -- after all memory has been configured
 *   and mapped but before any devices have been initialized.
 *
 ************************************************************************************/

__EXPORT void stm32_boardinitialize(void)
{
	/* configure LEDs */
	board_autoled_initialize();
	board_button_initialize();
	stm32_configgpio(GPIO_CAN_CTRL);

	/* configure CAN interface */

	stm32_configgpio(GPIO_CAN1_RX);
	stm32_configgpio(GPIO_CAN1_TX);

#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || \
    defined(CONFIG_STM32_SPI3)
	board_spiinitialize();
#endif
}
Ejemplo n.º 7
0
void up_pmbuttons(void)
{
  /* Initialize the button GPIOs */

  board_button_initialize();

#ifdef CONFIG_ARCH_IRQBUTTONS
  int i;
  for (i = CONFIG_PM_IRQBUTTONS_MIN; i <= CONFIG_PM_IRQBUTTONS_MAX; i++)
    {
      xcpt_t oldhandler = board_button_irq(i, g_buttonhandlers[BUTTON_INDEX(i)]);

      if (oldhandler != NULL)
        {
          lowsyslog(LOG_WARNING, "WARNING: oldhandler:%p is not NULL!  "
                    "Button events may be lost or aliased!\n",
                    oldhandler);
        }
    }
#endif
}
Ejemplo n.º 8
0
int buttons_main(int argc, char *argv[])
{
  uint8_t newset;
  irqstate_t flags;
  int i;

  /* If this example is configured as an NX add-on, then limit the number of
   * samples that we collect before returning.  Otherwise, we never return
   */

#ifdef CONFIG_NSH_BUILTIN_APPS
  long maxbuttons = 1;
  g_nbuttons      = 0;
  if (argc > 1)
    {
      maxbuttons = strtol(argv[1], NULL, 10);
    }
  lowsyslog("maxbuttons: %d\n", maxbuttons);
#endif

  /* Initialize the button GPIOs */

  board_button_initialize();

  /* Register to recieve button interrupts */

#ifdef CONFIG_ARCH_IRQBUTTONS
  for (i = CONFIG_EXAMPLES_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLES_IRQBUTTONS_MAX; i++)
    {
      xcpt_t oldhandler = board_button_irq(i, g_buttoninfo[BUTTON_INDEX(i)].handler);

      /* Use lowsyslog() for compatibility with interrrupt handler output. */

      lowsyslog("Attached handler at %p to button %d [%s], oldhandler:%p\n",
                g_buttoninfo[BUTTON_INDEX(i)].handler, i,
                g_buttoninfo[BUTTON_INDEX(i)].name, oldhandler);

      /* Some hardware multiplexes different GPIO button sources to the same
       * physical interrupt.  If we register multiple such multiplexed button
       * interrupts, then the second registration will overwrite the first.  In
       * this case, the first button interrupts may be aliased to the second
       * interrupt handler (or worse, could be lost).
       */

      if (oldhandler != NULL)
        {
          lowsyslog("WARNING: oldhandler:%p is not NULL!  "
                    "Button events may be lost or aliased!\n",
                    oldhandler);
        }
    }
#endif

  /* Poll button state */

  g_oldset = board_buttons();
#ifdef CONFIG_NSH_BUILTIN_APPS
  while (g_nbuttons < maxbuttons)
#else
  for (;;)
#endif
    {
      /* Get the set of pressed and release buttons. */

      newset = board_buttons();

      /* Any changes from the last sample? */

      if (newset != g_oldset)
        {
          /* Disable interrupts so that output here will not collide with
           * output from an interrupt handler.
           */

          flags = irqsave();

          /* Use lowsyslog() for compatibility with interrrupt handler
           * output.
           */

          lowsyslog("POLL SET:%02x:\n", newset);
          show_buttons(g_oldset, newset);
          g_oldset = newset;
          irqrestore(flags);
        }

      /* Sleep a little... but not long.  This will determine how fast we
       * poll for button changes.
       */

      usleep(150000); /* 150 Milliseconds */
    }

  /* Un-register button handlers */

#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_NSH_BUILTIN_APPS)
  for (i = CONFIG_EXAMPLES_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLES_IRQBUTTONS_MAX; i++)
    {
      (void)board_button_irq(i, NULL);
    }
#endif

  return 0;
}
Ejemplo n.º 9
0
static int gsensor_daemon(int argc, char *argv[]){
  g_gsensor_started = true;
  struct adc_msg_s sample[CONFIG_MYAPPS_GSENSOR_GROUPSIZE];
  size_t readsize;
  ssize_t nbytes;
  int errval = 0;
  int ret;
  int i,j;
  int am_channel,am_data;

  

  

  /* Check if we have initialized */

  if (!g_adcstate.initialized)
  {
      /* Initialization of the ADC hardware is performed by logic external to
       * this test.
       */

       printf("adc_main here: Initializing external ADC device\n");
       ret = board_gsensoradc_setup();
       if (ret < 0)
       {
        printf("adc_main here: boardctl failed: %d\n", errno);
        errval = 1;
        goto errout;
      }

      /* Set the default values */

      adc_devpath(&g_adcstate, CONFIG_MYAPPS_GSENSOR_DEVPATH);

#if CONFIG_MYAPPS_GSENSOR_NSAMPLES > 0
      g_adcstate.count = CONFIG_MYAPPS_GSENSOR_NSAMPLES;
#else
      g_adcstate.count = 1;
#endif
      g_adcstate.initialized = true;
    }

  /* If this example is configured as an NX add-on, then limit the number of
   * samples that we collect before returning.  Otherwise, we never return
   */

#if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_MYAPPS_GSENSOR_NSAMPLES > 0
   printf("adc_main: g_adcstate.count: %d\n", g_adcstate.count);
#endif

  /* Open the ADC device for reading */

   printf("adc_main: Hardware initialized. Opening the ADC device: %s\n",
     g_adcstate.devpath);

   fd = open(g_adcstate.devpath, O_RDONLY);
   if (fd < 0)
   {
    printf("adc_main: open %s failed: %d\n", g_adcstate.devpath, errno);
    errval = 2;
    goto errout;
  }

  fp = fopen("/sdcard/TEST.txt", "w");
  if (fp < 0) {
    printf("error opening TEST.TXT");
    return 1;
  }
  
  board_button_initialize();

  xcpt_t oldhandler = board_button_irq(0, button_handler);

      /* Use lowsyslog() for compatibility with interrupt handler output. */

  lowsyslog(LOG_INFO, "Attached handler at %p to button 0 [User button], oldhandler:%p\n",
    button_handler, oldhandler);

  /* Now loop the appropriate number of times, displaying the collected
   * ADC samples.
   */
/*
#if defined(CONFIG_NSH_BUILTIN_APPS)
  for (; g_adcstate.count > 0; g_adcstate.count--)
#elif CONFIG_MYAPPS_GSENSOR_NSAMPLES > 0
  for (g_adcstate.count = 0;
       g_adcstate.count < CONFIG_MYAPPS_GSENSOR_NSAMPLES;
       g_adcstate.count++)
#else
  for (;;)
#endif*/

    while(cont_gsensor)
    {
    /* Flush any output before the loop entered or from the previous pass
     * through the loop.
     */
    //fflush(stdout);
     
     printf("\nSample number %d\n",++j);
     fprintf(fp,"\nSample number %d\n",j);


#ifdef CONFIG_MYAPPS_GSENSOR_SWTRIG
    /* Issue the software trigger to start ADC conversion */

     ret = ioctl(fd, ANIOC_TRIGGER, 0);
     if (ret < 0)
     {
      int errcode = errno;
      printf("adc_main: ANIOC_TRIGGER ioctl failed: %d\n", errcode);
    }
#endif

    /* Read up to CONFIG_MYAPPS_ADC_GROUPSIZE samples */

    readsize = CONFIG_MYAPPS_GSENSOR_GROUPSIZE * sizeof(struct adc_msg_s);
    nbytes = read(fd, sample, readsize);

    /* Handle unexpected return values */

    if (nbytes < 0)
    {
      errval = errno;
      if (errval != EINTR)
      {
        printf("adc_main: read %s failed: %d\n",
         g_adcstate.devpath, errval);
        errval = 3;
        goto errout_with_dev;
      }

      printf("adc_main: Interrupted read...\n");
    }
    else if (nbytes == 0)
    {
      printf("adc_main: No data read, Ignoring\n");
    }

    /* Print the sample data on successful return */

    else
    {
      int nsamples = nbytes / sizeof(struct adc_msg_s);
      if (nsamples * sizeof(struct adc_msg_s) != nbytes)
      {
        printf("adc_main: read size=%ld is not a multiple of sample size=%d, Ignoring\n",
         (long)nbytes, sizeof(struct adc_msg_s));
      }
      else
      {
        printf("Sample:\n");
        for (i = 0; i < nsamples; i++)
        {
          am_channel = sample[i].am_channel;
          am_data = sample[i].am_data;

          printf("%d: channel: %d value: %d\n",
           i+1,am_channel , am_data);

          fprintf(fp,"%d: channel: %d value: %d\n",
           i+1, am_channel, am_data);

          if(am_data >3500){
            printf("Environment in channel %d too dry\n",am_channel);
          }else if(am_data <1000){
            printf("Environment in channel %d too wet\n",am_channel);
          }else{
            printf("Environment in channel %d is perfect\n",am_channel);
          }

          fflush(fp);
        }
      }
    }

    usleep(150000);
  }

  (void)board_button_irq(0, NULL);
  fclose(fp);
  close(fd);
  task_delete(g_gsensor_pid);

  /* Error exits */

  errout_with_dev:
  (void)board_button_irq(0, NULL);
  fclose(fp);
  close(fd);
  task_delete(g_gsensor_pid);

  errout:
  printf("Terminating!\n");
  fflush(stdout);
  task_delete(g_gsensor_pid);
}