Exemplo n.º 1
0
void
ADC::update_system_power(void)
{
#ifdef CONFIG_ARCH_BOARD_PX4FMU_V2
	system_power_s system_power;
	system_power.timestamp = hrt_absolute_time();

	system_power.voltage5V_v = 0;
	for (unsigned i = 0; i < _channel_count; i++) {
		if (_samples[i].am_channel == 4) {
			// it is 2:1 scaled
			system_power.voltage5V_v = _samples[i].am_data * (6.6f / 4096);
		}
	}

	// these are not ADC related, but it is convenient to
	// publish these to the same topic
	system_power.usb_connected = stm32_gpioread(GPIO_OTGFS_VBUS);

	// note that the valid pins are active low
	system_power.brick_valid   = !stm32_gpioread(GPIO_VDD_BRICK_VALID);
	system_power.servo_valid   = !stm32_gpioread(GPIO_VDD_SERVO_VALID);

	// OC pins are active low
	system_power.periph_5V_OC  = !stm32_gpioread(GPIO_VDD_5V_PERIPH_OC);
	system_power.hipower_5V_OC = !stm32_gpioread(GPIO_VDD_5V_HIPOWER_OC);

	/* lazily publish */
	if (_to_system_power > 0) {
		orb_publish(ORB_ID(system_power), _to_system_power, &system_power);
	} else {
		_to_system_power = orb_advertise(ORB_ID(system_power), &system_power);
	}
#endif // CONFIG_ARCH_BOARD_PX4FMU_V2
}
Exemplo n.º 2
0
__EXPORT void led_toggle(int led)
{
	switch (led) {
	case 0:
		if (stm32_gpioread(GPIO_LED0)) {
			stm32_gpiowrite(GPIO_LED0, false);

		} else {
			stm32_gpiowrite(GPIO_LED0, true);
		}

		break;

	case 1:
		if (stm32_gpioread(GPIO_LED1)) {
			stm32_gpiowrite(GPIO_LED1, false);

		} else {
			stm32_gpiowrite(GPIO_LED1, true);
		}

		break;

	default:
		warnx("LED ID not recognized\n");
	}
}
Exemplo n.º 3
0
uint8_t up_read_inputs(void)
{
  uint8_t bits = 0;
  bits |= stm32_gpioread(GPIO_D14) == 0 ? 1 : 0;
  bits |= stm32_gpioread(GPIO_D15) == 0 ? 2 : 0;
  bits |= stm32_gpioread(GPIO_A2)  == 0 ? 4 : 0;
  bits |= stm32_gpioread(GPIO_A3)  == 0 ? 8 : 0;
  return bits;
}
Exemplo n.º 4
0
uint8_t board_buttons(void)
{
  uint8_t ret = 0;
  int i;

  /* Check that state of each key */

  for (i = 0; i < NUM_BUTTONS; i++)
    {
       /* A LOW value means that the key is pressed for most keys.  The exception
        * is the WAKEUP button.
        */

       bool released = stm32_gpioread(g_buttons[i]);
       if (i == BUTTON_WAKEUP)
         {
           released = !released;
         }

       /* Accumulate the set of depressed (not released) keys */

       if (!released)
         {
            ret |= (1 << i);
         }
    }

  return ret;
}
Exemplo n.º 5
0
__END_DECLS

/****************************************************************************
 * Protected Functions
 ****************************************************************************/
/****************************************************************************
 * Public Functions
 ****************************************************************************/
/************************************************************************************
 * Name: board_peripheral_reset
 *
 * Description:
 *
 ************************************************************************************/
__EXPORT void board_peripheral_reset(int ms)
{
	bool last = stm32_gpioread(GPIO_SPEKTRUM_PWR_EN);
	/* Keep Spektum on to discharge rail*/
	stm32_gpiowrite(GPIO_SPEKTRUM_PWR_EN, 1);

	/* wait for the peripheral rail to reach GND */
	usleep(ms * 1000);
	warnx("reset done, %d ms", ms);

	/* re-enable power */
	/* switch the peripheral rail back on */
	stm32_gpiowrite(GPIO_SPEKTRUM_PWR_EN, last);

}
Exemplo n.º 6
0
/**
 * @brief           Measure the current consumption of a given spring.
 * @return          current consumption of a given spring (in microamps)
 * warning          'spring' index starts at 1, not 0.
 * @param[in]       spring: selected spring ([1..SPRING_COUNT])
 * @param[out]      uA: selected spring current measurement, in microamps)
 */
int spwrm_get_current(uint8_t spring, int32_t *uA)
{
    int ret;
    uint8_t adc, chan;
    uint32_t spin, uV;

    CHECK_SPRING(spring);
    CHECK_NULL_ARG(uA);

    adc = spwrm_get_adc_device(spring);
    chan = spwrm_get_adc_channel(spring);
    spin = spwrm_get_sign_pin(spring);
    *uA = 0;

    ret = adc_get_data(adc, chan, &uV);
    if (ret) {
        dbg_error("%s(): failed to get %s data! (%d)\n", __func__,
                  spwrm_get_name(spring), ret);
        return ret;
    }
    /* Convert to uV */
    uV = adc_get_uV(uV);
    /* Get data sign */
    if (stm32_gpioread(spin) == 0) {
        dbg_verbose("%s(): pin=0 => sign=-\n", __func__);
        *uA = -((int32_t) max9929f_get_Iload(uV));
    } else {
        dbg_verbose("%s(): pin=1 => sign=+\n", __func__);
        *uA = (int32_t) max9929f_get_Iload(uV);
    }
    dbg_verbose("%s(): measured voltage=%uuV => current=%duA\n",
                __func__, uV, *uA);

    return 0;
}
Exemplo n.º 7
0
int stm32_sdio_initialize(void)
{
  int ret;

#ifdef HAVE_NCD
  /* Card detect */

  bool cd_status;

  /* Configure the card detect GPIO */

  stm32_configgpio(GPIO_SDMMC1_NCD);

  /* Register an interrupt handler for the card detect pin */

  (void)stm32_gpiosetevent(GPIO_SDMMC1_NCD, true, true, true,
                           stm32_ncd_interrupt, NULL);
#endif

  /* Mount the SDIO-based MMC/SD block driver */
  /* First, get an instance of the SDIO interface */

  finfo("Initializing SDIO slot %d\n", SDIO_SLOTNO);

  g_sdio_dev = sdio_initialize(SDIO_SLOTNO);
  if (!g_sdio_dev)
    {
      ferr("ERROR: Failed to initialize SDIO slot %d\n", SDIO_SLOTNO);
      return -ENODEV;
    }

  /* Now bind the SDIO interface to the MMC/SD driver */

  finfo("Bind SDIO to the MMC/SD driver, minor=%d\n", SDIO_MINOR);

  ret = mmcsd_slotinitialize(SDIO_MINOR, g_sdio_dev);
  if (ret != OK)
    {
      ferr("ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
      return ret;
    }

  finfo("Successfully bound SDIO to the MMC/SD driver\n");

#ifdef HAVE_NCD
  /* Use SD card detect pin to check if a card is g_sd_inserted */

  cd_status = !stm32_gpioread(GPIO_SDMMC1_NCD);
  finfo("Card detect : %d\n", cd_status);

  sdio_mediachange(g_sdio_dev, cd_status);
#else
  /* Assume that the SD card is inserted.  What choice do we have? */

  sdio_mediachange(g_sdio_dev, true);
#endif

  return OK;
}
Exemplo n.º 8
0
uint32_t board_buttons(void)
{
  uint32_t ret = 0;

  ret = (stm32_gpioread(g_buttons[i]) == false ? 1 : 0);

  return ret;
}
Exemplo n.º 9
0
__EXPORT void led_toggle(int led)
{
	if (led == 0)
	{
		if (stm32_gpioread(GPIO_LED1))
			stm32_gpiowrite(GPIO_LED1, false);
		else
			stm32_gpiowrite(GPIO_LED1, true);
	}
	if (led == 1)
	{
		if (stm32_gpioread(GPIO_LED2))
			stm32_gpiowrite(GPIO_LED2, false);
		else
			stm32_gpiowrite(GPIO_LED2, true);
	}
}
Exemplo n.º 10
0
__EXPORT void led_toggle(int led)
{
	const uint32_t param = _led_param_get(led);

	if (param) {
		stm32_gpiowrite(param, !stm32_gpioread(param));
	}
}
Exemplo n.º 11
0
uint8_t board_buttons(void)
{
  /* Check that state of each USER button. A LOW value means that the key is
   * pressed.
   */

  bool released = stm32_gpioread(GPIO_BTN_USER);
  return !released;
}
Exemplo n.º 12
0
uint8_t up_buttons(void)
{
  uint8_t ret = 0;

  /* Check that state of each key.  A LOW value means that the key is pressed, */

  if (!stm32_gpioread(GPIO_BTN_KEY1))
    {
      ret |= BUTTON_KEY1_BIT;
    }

  if (!stm32_gpioread(GPIO_BTN_KEY2))
    {
      ret |= BUTTON_KEY2_BIT;
    }

  return ret;
}
Exemplo n.º 13
0
uint32_t
PX4FMU::gpio_read(void)
{
	uint32_t bits = 0;

	for (unsigned i = 0; i < _ngpio; i++)
		if (stm32_gpioread(_gpio_tab[i].input))
			bits |= (1 << i);

	return bits;
}
Exemplo n.º 14
0
__EXPORT void buzzer_toggle(int buzzer)
{
	if (buzzer == 0)
	{
#if defined(GPIO_BUZZER)
		if (stm32_gpioread(GPIO_BUZZER))
			stm32_gpiowrite(GPIO_BUZZER, false);
		else
			stm32_gpiowrite(GPIO_BUZZER, true);
#endif
	}
}
Exemplo n.º 15
0
static int determin_hw_version(int *version, int *revision)
{
	*revision = 0; /* default revision */
	int rv = 0;
	int pos = 0;
	stm32_configgpio(GPIO_PULLDOWN | (HW_VER_PB4 & ~GPIO_PUPD_MASK));
	up_udelay(10);
	rv |= stm32_gpioread(HW_VER_PB4) << pos++;
	stm32_configgpio(HW_VER_PB4);
	up_udelay(10);
	rv |= stm32_gpioread(HW_VER_PB4) << pos++;

	int votes = 16;
	int ones[2] = {0, 0};
	int zeros[2] = {0, 0};

	while (votes--) {
		stm32_configgpio(GPIO_PULLDOWN | (HW_VER_PB12 & ~GPIO_PUPD_MASK));
		up_udelay(10);
		stm32_gpioread(HW_VER_PB12) ? ones[0]++ : zeros[0]++;
		stm32_configgpio(HW_VER_PB12);
		up_udelay(10);
		stm32_gpioread(HW_VER_PB12) ? ones[1]++ : zeros[1]++;
	}

	if (ones[0] > zeros[0]) {
		rv |= 1 << pos;
	}

	pos++;

	if (ones[1] > zeros[1]) {
		rv |= 1 << pos;
	}

	stm32_configgpio(HW_VER_PB4_INIT);
	stm32_configgpio(HW_VER_PB12_INIT);
	*version = rv;
	return OK;
}
Exemplo n.º 16
0
uint8_t board_buttons(void)
{
  uint8_t ret = 0;

  /* Check that state of each key */

  if (!stm32_gpioread(g_buttons[BUTTON_BUT]))
    {
      ret |= BUTTON_BUT_BIT;
    }

  return ret;
}
Exemplo n.º 17
0
uint8_t stm32_spi1status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
{
  /* The card detect pin is pulled up so that we detect the presence of a card
   * by see a low value on the input pin.
   */

  if (stm32_gpioread(GPIO_SD_CD))
    {
      return 0;
    }

  return SPI_STATUS_PRESENT;
}
Exemplo n.º 18
0
static int stm32_ncd_interrupt(int irq, FAR void *context)
{
  bool present;

  present = !stm32_gpioread(GPIO_SDMMC1_NCD);
  if (g_sdio_dev && present != g_sd_inserted)
    {
      sdio_mediachange(g_sdio_dev, present);
      g_sd_inserted = present;
    }

  return OK;
}
Exemplo n.º 19
0
int nsh_archinitialize(void)
{
#ifdef NSH_HAVEMMCSD
  int ret;

  /* Card detect */
  bool cd_status;

  /* Configure the card detect GPIO */

  stm32_configgpio(GPIO_SD_CD);

  /* Register an interrupt handler for the card detect pin */

  stm32_gpiosetevent(GPIO_SD_CD, true, true, true, nsh_cdinterrupt);

  /* Mount the SDIO-based MMC/SD block driver */

  /* First, get an instance of the SDIO interface */

  message("nsh_archinitialize: Initializing SDIO slot %d\n",
          CONFIG_NSH_MMCSDSLOTNO);
  g_sdiodev = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO);
  if (!g_sdiodev)
    {
      message("nsh_archinitialize: Failed to initialize SDIO slot %d\n",
              CONFIG_NSH_MMCSDSLOTNO);
      return -ENODEV;
    }

  /* Now bind the SDIO interface to the MMC/SD driver */

  message("nsh_archinitialize: Bind SDIO to the MMC/SD driver, minor=%d\n",
          CONFIG_NSH_MMCSDMINOR);
  ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, g_sdiodev);
  if (ret != OK)
    {
      message("nsh_archinitialize: Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
      return ret;
    }
  dbg("nsh_archinitialize: Successfully bound SDIO to the MMC/SD driver\n");

  /* Use SD card detect pin to check if a card is inserted */

  cd_status = !stm32_gpioread(GPIO_SD_CD);
  vdbg("Card detect : %hhu\n", cd_status);

  sdio_mediachange(g_sdiodev, cd_status);
#endif
  return OK;
}
Exemplo n.º 20
0
void
ADC::update_system_power(hrt_abstime now)
{
#if defined (CONFIG_ARCH_BOARD_PX4FMU_V2) || \
    defined (CONFIG_ARCH_BOARD_MINDPX_V2) || \
    defined (CONFIG_ARCH_BOARD_PX4FMU_V4)
	system_power_s system_power = {};
	system_power.timestamp = now;

	system_power.voltage5V_v = 0;

	for (unsigned i = 0; i < _channel_count; i++) {
		if (_samples[i].am_channel == ADC_5V_RAIL_SENSE) {
			// it is 2:1 scaled
			system_power.voltage5V_v = _samples[i].am_data * (6.6f / 4096);
		}
	}

	// these are not ADC related, but it is convenient to
	// publish these to the same topic
	system_power.usb_connected = stm32_gpioread(GPIO_OTGFS_VBUS);

#if defined (CONFIG_ARCH_BOARD_MINDPX_V2)
	// note that the valid pins are active low
	system_power.brick_valid   = 1;
	system_power.servo_valid   = 1;

	// OC pins are active low
	system_power.periph_5V_OC  = 1;
	system_power.hipower_5V_OC = 1;
#elif defined (CONFIG_ARCH_BOARD_PX4FMU_V4)
	// note that the valid pins are active high
	system_power.brick_valid   = stm32_gpioread(GPIO_VDD_BRICK_VALID);
	system_power.servo_valid   = 1;

	// OC pins are not supported
	system_power.periph_5V_OC  = 0;
	system_power.hipower_5V_OC = 0;
#else
	// note that the valid pins are active low
	system_power.brick_valid   = !stm32_gpioread(GPIO_VDD_BRICK_VALID);
	system_power.servo_valid   = !stm32_gpioread(GPIO_VDD_SERVO_VALID);

	// OC pins are active low
	system_power.periph_5V_OC  = !stm32_gpioread(GPIO_VDD_5V_PERIPH_OC);
	system_power.hipower_5V_OC = !stm32_gpioread(GPIO_VDD_5V_HIPOWER_OC);
#endif

	/* lazily publish */
	if (_to_system_power != nullptr) {
		orb_publish(ORB_ID(system_power), _to_system_power, &system_power);

	} else {
		_to_system_power = orb_advertise(ORB_ID(system_power), &system_power);
	}

#endif // CONFIG_ARCH_BOARD_PX4FMU_V2
}
Exemplo n.º 21
0
__END_DECLS

/****************************************************************************
 * Private Functions
 ****************************************************************************/

static int _bootloader_force_pin_callback(int irq, void *context)
{
	if (stm32_gpioread(GPIO_FORCE_BOOTLOADER)) {
		up_systemreset();
	}

	return 0;
}
Exemplo n.º 22
0
static int nsh_cdinterrupt(int irq, FAR void *context)
{
  static bool inserted = 0xff; /* Impossible value */
  bool present;

  present = !stm32_gpioread(GPIO_SD_CD);
  if (present != inserted)
    {
      sdio_mediachange(g_sdiodev, present);
      inserted = present;
    }

  return OK;
}
Exemplo n.º 23
0
void stm32_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
    spidbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
    
    if (devid == SPIDEV_WIRELESS) {
    
        stm32_gpiowrite(GPIO_CC1101_CS, !selected);

        /* Wait for MISO to go low, indicates that Quart has stabilized */
        if (selected) {
            while( stm32_gpioread(GPIO_SPI2_MISO) ) up_waste();
        }
        
    }
}
Exemplo n.º 24
0
static uint8_t stm32_gpio_get(void *driver_data, uint8_t pin)
{
    uint32_t cfgset;
    int ret;

    lldbg("%s: pin=%hhu\n", __func__, pin);

    ret = map_pin_nr_to_cfgset(pin, &cfgset);
    if (ret) {
        lldbg("%s: Invalid pin %hhu\n", pin);
        return -EINVAL;
    }

    return stm32_gpioread(cfgset);
}
Exemplo n.º 25
0
uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
{
  uint8_t ret = 0;

#if defined(CONFIG_MMCSD)
  if (devid == SPIDEV_MMCSD)
    {
      /* A low value indicates the card is present */

      if (!stm32_gpioread(GPIO_SD_CD))
        {
          ret = SPI_STATUS_PRESENT;
        }
    }
#endif

  return ret;
}
Exemplo n.º 26
0
void sif_gpio2_update(void)
{
    uint32_t val;

    switch(vsn_sif.gpio[1]) {
        case VSN_SIF_GPIO_HIGHZ:    val = GPIO_GP2_HIZ; break;
        case VSN_SIF_GPIO_PULLUP:   val = GPIO_GP2_PUP; break;
        case VSN_SIF_GPIO_PULLDOWN: val = GPIO_GP2_PDN; break;
        case VSN_SIF_GPIO_OUTLOW:   val = GPIO_GP2_LOW; break;
        case VSN_SIF_GPIO_OUTHIGH:  val = GPIO_GP2_HIGH;break;
        default: return;
    }
    if (stm32_configgpio(val) == ERROR)
        printf("Error updating2\n");

    if (stm32_gpioread(val))
        vsn_sif.gpio[1] |= VSN_SIF_GPIO_READ_MASK;
    else vsn_sif.gpio[1] &= ~VSN_SIF_GPIO_READ_MASK;
}
Exemplo n.º 27
0
uint8_t up_buttons(void)
{
  uint8_t ret = 0;
  int i;

  /* Check that state of each key */

  for (i = 0; i < NUM_BUTTONS; i++)
    {
       /* A LOW value means that the key is pressed */

       if (!stm32_gpioread(g_buttons[i]))
         {
           ret |= (1 << i);
         }
    }

  return ret;
}
Exemplo n.º 28
0
static ajoy_buttonset_t ajoy_buttons(FAR const struct ajoy_lowerhalf_s *lower)
{
  ajoy_buttonset_t ret = 0;
  int i;

  /* Read each joystick GPIO value */

  for (i = 0; i < AJOY_NGPIOS; i++)
    {
      /* Button outputs are pulled high. So a sensed low level means that the
       * button is pressed.
       */

      if (!stm32_gpioread(g_joygpio[i]))
        {
          ret |= (1 << i);
        }
    }

  iinfo("Returning: %02x\n", ret);
  return ret;
}
Exemplo n.º 29
0
static bool read_hwid_bit(uint32_t gpio)
{
    bool level;

    /*
     * Configure the pin as input pull-up. A '0' state if forced by installing
     * a pull-down resistor.
     */
    stm32_configgpio(gpio | GPIO_PULLUP);

    /* Read level */
    level = stm32_gpioread(gpio);

    /*
     * To minimize power consumption, if level reads '0' configure the pin
     * as input pull-down.
     */
    if (!level) {
        stm32_configgpio(gpio | GPIO_PULLDOWN);
    }

    return level;
}
Exemplo n.º 30
0
uint8_t up_buttons(void)
{
  uint8_t ret = 0;
  int i;

  /* Check that state of each key */

  for (i = 0; i < NUM_BUTTONS; i++)
    {
       /* A LOW value means that the key is pressed.
        */

       bool released = stm32_gpioread(g_buttons[i]);

       /* Accumulate the set of depressed (not released) keys */

       if (!released)
         {
            ret |= (1 << i);
         }
    }

  return ret;
}