Ejemplo n.º 1
0
JshPinFunction jshPinAnalogOutput(Pin pin, JsVarFloat value, JsVarFloat freq, JshAnalogOutputFlags flags) {
  /* we set the bit field here so that if the user changes the pin state
   * later on, we can get rid of the IRQs */
  if (!jshGetPinStateIsManual(pin)) {
    BITFIELD_SET(jshPinSoftPWM, pin, 0);
    jshPinSetState(pin, JSHPINSTATE_GPIO_OUT);
  }
  BITFIELD_SET(jshPinSoftPWM, pin, 1);
  if (freq<=0) freq=50;
  jstPinPWM(freq, value, pin);
  return JSH_NOTHING;
} // if freq<=0, the default is used
Ejemplo n.º 2
0
// Set the pin state
void jshPinSetState(Pin pin, JshPinState state) {
  /* Make sure we kill software PWM if we set the pin state
   * after we've started it */
  if (BITFIELD_GET(jshPinSoftPWM, pin)) {
    BITFIELD_SET(jshPinSoftPWM, pin, 0);
    jstPinPWM(0,0,pin);
  }

  uint32_t ipin = (uint32_t)pinInfo[pin].pin;
  switch (state) {
    case JSHPINSTATE_UNDEFINED :
      nrf_gpio_cfg_default(ipin);
      break;
    case JSHPINSTATE_GPIO_OUT :
      nrf_gpio_cfg_output(ipin);
      break;
    case JSHPINSTATE_GPIO_OUT_OPENDRAIN :
      NRF_GPIO->PIN_CNF[ipin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
                              | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
                              | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
                              | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
                              | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
      break;
    case JSHPINSTATE_GPIO_IN :
      nrf_gpio_cfg_input(ipin, NRF_GPIO_PIN_NOPULL);
      break;
    case JSHPINSTATE_GPIO_IN_PULLUP :
      nrf_gpio_cfg_input(ipin, NRF_GPIO_PIN_PULLUP);
      break;
    case JSHPINSTATE_GPIO_IN_PULLDOWN :
      nrf_gpio_cfg_input(ipin, NRF_GPIO_PIN_PULLDOWN);
      break;
    /*case JSHPINSTATE_ADC_IN :
      break;
    case JSHPINSTATE_AF_OUT :
      break;
    case JSHPINSTATE_AF_OUT_OPENDRAIN :
      break;
    case JSHPINSTATE_USART_IN :
      break;
    case JSHPINSTATE_USART_OUT :
      break;
    case JSHPINSTATE_DAC_OUT :
      break;*/
    case JSHPINSTATE_I2C :
      NRF_GPIO->PIN_CNF[ipin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
                              | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)
                              | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
                              | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
                              | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
      // may need to be set to GPIO_PIN_CNF_DIR_Output as well depending on I2C state?
      break;
    default : assert(0);
      break;
  }
}
Ejemplo n.º 3
0
static int listdirs_test_fn1(const struct redfish_dir_entry *oda, void *v)
{
	struct listdirs_test_fn1_data *data = v;
	int idx = -1;

	if (sscanf(oda->name, "%d", &idx) != 1)
		return -EINVAL;
	if ((idx < 0) || (idx > MAX_LISTDIRS_TEST_ENTRIES))
		return -EINVAL;
	BITFIELD_SET(data->found, idx);
	return 0;
}
Ejemplo n.º 4
0
void jshSetPinStateIsManual(Pin pin, bool manual) {
  BITFIELD_SET(jshPinStateIsManual, pin, manual);
}