Esempio n. 1
0
void pmProcess() {
  static int lastTick = 0;
  static int lastAdcTick = 0;

  if (systickGetTick() - lastTick > TICK_BETWEEN_STATE) {
    lastTick = systickGetTick();

    if (targetState > state) {
      state++;
      if (statesFunctions[state].call) {
        statesFunctions[state].call(true);
      }
    } else if (targetState < state) {
      if (statesFunctions[state].call) {
        statesFunctions[state].call(false);
      }
      state--;
    }
  }

  // VBAT sampling can't be done to often or it will affect the reading, ~100Hz is OK.
  if (systickGetTick() - lastAdcTick > pmConfig->ticksBetweenAdcMeasurement && !NRF_ADC->BUSY)
  {
    uint16_t rawValue = NRF_ADC->RESULT;
    lastAdcTick = systickGetTick();

	  if (adcState == adcVBAT) {
		  vBat = (float) (rawValue / 1023.0) * 1.2 * pmConfig->vbatFactor;
		  if (pmConfig->hasCharger) {
		    pmStartAdc(adcISET);
		  } else {
	      pmStartAdc(adcVBAT);
	    }
	  } else if (adcState == adcISET) {
		  // V_ISET = I_CHARGE / 400 × R_ISET
		  float v = (float) (rawValue / 1023.0) * 1.2 * 3;
		  iSet = (v * 400.0) / 1000.0;
		  pmStartAdc(adcVBAT);
	  }
	  //TODO: Handle the battery charging...
  }

}
Esempio n. 2
0
static void pmRunSystem(bool enable)
{
  if (enable) {
    // Release the reset pin!
    nrf_gpio_pin_set(STM_NRST_PIN);

    //Activate UART TX pin
    nrf_gpio_cfg_output(UART_TX_PIN);
    nrf_gpio_pin_set(UART_TX_PIN);

    nrf_gpio_cfg_output(PM_EN1);
    nrf_gpio_cfg_output(PM_EN2);
    // Set 500mA current
    nrf_gpio_pin_set(PM_EN1);
    nrf_gpio_pin_clear(PM_EN2);
    // 980mA current
//    nrf_gpio_pin_clear(PM_EN1);
//    nrf_gpio_pin_set(PM_EN2);

    // Enable charging
    nrf_gpio_cfg_output(PM_CHG_EN);
    nrf_gpio_pin_clear(PM_CHG_EN);

    // Enable RF power amplifier
    nrf_gpio_cfg_output(RADIO_PAEN_PIN);
#ifdef DISABLE_PA
    nrf_gpio_pin_clear(RADIO_PAEN_PIN);
#else
    nrf_gpio_pin_set(RADIO_PAEN_PIN);
#endif

    // Sink battery divider
    nrf_gpio_cfg_output(PM_VBAT_SINK_PIN);
    nrf_gpio_pin_clear(PM_VBAT_SINK_PIN);

    pmStartAdc(adcVBAT);

  } else {
    //Disable UART
    nrf_gpio_cfg_input(UART_TX_PIN, NRF_GPIO_PIN_PULLDOWN);

    //Hold reset
    nrf_gpio_pin_clear(STM_NRST_PIN);
  }
}
Esempio n. 3
0
static void pmRunSystem(bool enable)
{
  if (enable) {
    // Release the reset pin!
    nrf_gpio_pin_set(STM_NRST_PIN);

    //Activate UART TX pin
    nrf_gpio_cfg_output(UART_TX_PIN);
    nrf_gpio_pin_set(UART_TX_PIN);

    if (pmConfig->hasCharger) {
      nrf_gpio_cfg_output(PM_EN1);
      nrf_gpio_cfg_output(PM_EN2);
    #ifdef ENABLE_FAST_CHARGE_1A
      // 980mA current
      nrf_gpio_pin_clear(PM_EN1);
      nrf_gpio_pin_set(PM_EN2);
    #else
      // Set 500mA current
      nrf_gpio_pin_set(PM_EN1);
      nrf_gpio_pin_clear(PM_EN2);
    #endif
      // Enable charging
      nrf_gpio_cfg_output(PM_CHG_EN);
      nrf_gpio_pin_clear(PM_CHG_EN);
    }

    if (platformHasRfx2411n()) {
      // Enable RF power amplifier
      nrf_gpio_cfg_output(RADIO_PA_RX_EN);
      nrf_gpio_cfg_output(RADIO_PA_MODE);
      nrf_gpio_cfg_output(RADIO_PA_ANT_SW);
    #ifdef USE_EXT_ANTENNA
      // Select u.FL antenna
      nrf_gpio_pin_clear(RADIO_PA_ANT_SW);
    #else
      // Select chip antenna
      nrf_gpio_pin_set(RADIO_PA_ANT_SW);
    #endif

    #ifdef RFX2411N_BYPASS_MODE
        nrf_gpio_pin_set(RADIO_PA_MODE);
    #else
        nrf_gpio_pin_set(RADIO_PA_RX_EN);
        nrf_gpio_pin_clear(RADIO_PA_MODE);
    #endif
    } else {
        // Enable RF power amplifier
        nrf_gpio_cfg_output(RADIO_PAEN_PIN);

    #ifdef DISABLE_PA
        nrf_gpio_pin_clear(RADIO_PAEN_PIN);
        nrf_gpio_cfg_output(RADIO_PATX_DIS_PIN);
        nrf_gpio_pin_clear(RADIO_PATX_DIS_PIN);
    #else
        nrf_gpio_pin_set(RADIO_PAEN_PIN);
    #endif
    }

    if (pmConfig->hasVbatSink) {
      // Sink battery divider
      nrf_gpio_cfg_output(PM_VBAT_SINK_PIN);
      nrf_gpio_pin_clear(PM_VBAT_SINK_PIN);
    }

    pmStartAdc(adcVBAT);

  } else {
    //Disable UART
    nrf_gpio_cfg_input(UART_TX_PIN, NRF_GPIO_PIN_PULLDOWN);

    //Hold reset
    nrf_gpio_pin_clear(STM_NRST_PIN);
  }
}