Exemplo n.º 1
0
def pinMode(gpio_pin, direction, pull=0):
  """ Sets given digital pin to input if direction=1, output otherwise.
      'pull' will set the pull up/down resistor if setting as an input:
      pull=-1 for pull-down, pull=1 for pull up, pull=0 for none. """
  assert (gpio_pin in GPIO), "*Invalid GPIO pin: '%s'" % gpio_pin
  if pinmux.export(gpio_pin):
    addToCleanup(lambda: _unexport(gpio_pin))
  if (direction == INPUT):
    # Pinmux:
    if (pull > 0): pull = CONF_PULLUP
    elif (pull < 0): pull = CONF_PULLDOWN
    else: pull = CONF_PULL_DISABLE
    pinmux.pinMux(GPIO[gpio_pin][2], CONF_GPIO_INPUT | pull)
    # Set input:
    memory.orReg(GPIO[gpio_pin][0]+GPIO_OE, GPIO[gpio_pin][1])
    return
  # Pinmux:
  pinmux.pinMux(GPIO[gpio_pin][2], CONF_GPIO_OUTPUT)
  # Set output:
  memory.clearReg(GPIO[gpio_pin][0]+GPIO_OE, GPIO[gpio_pin][1])
Exemplo n.º 2
0
def pinMode(gpio_pin, direction, pull=0):
  """ Sets given digital pin to input if direction=1, output otherwise.
      'pull' will set the pull up/down resistor if setting as an input:
      pull=-1 for pull-down, pull=1 for pull up, pull=0 for none. """
  assert (gpio_pin in GPIO), "*Invalid GPIO pin: '%s'" % gpio_pin
  if pinmux.export(gpio_pin):
    addToCleanup(lambda: pinmux.unexport(gpio_pin))
  if (direction == INPUT):
    # Pinmux:
    if (pull > 0): pull = CONF_PULLUP
    elif (pull < 0): pull = CONF_PULLDOWN
    else: pull = CONF_PULL_DISABLE
    pinmux.pinMux(GPIO[gpio_pin][2], CONF_GPIO_INPUT | pull)
    # Set input:
    memory.orReg(GPIO[gpio_pin][0]+GPIO_OE, GPIO[gpio_pin][1])
    return
  # Pinmux:
  pinmux.pinMux(GPIO[gpio_pin][2], CONF_GPIO_OUTPUT)
  # Set output:
  memory.clearReg(GPIO[gpio_pin][0]+GPIO_OE, GPIO[gpio_pin][1])
Exemplo n.º 3
0
def analog_init():
  """ Initializes the on-board 8ch 12bit ADC. """
  # Enable ADC module clock, though should already be enabled on
  # newer Angstrom images:
  memory.setReg(CM_WKUP_ADC_TSC_CLKCTRL, MODULEMODE_ENABLE)
  # Wait for enable complete:
  while (memory.getReg(CM_WKUP_ADC_TSC_CLKCTRL) & IDLEST_MASK): delay(1)

  # Software reset:
  memory.setReg(ADC_SYSCONFIG, ADC_SOFTRESET)
  while(memory.getReg(ADC_SYSCONFIG) & ADC_SOFTRESET): pass

  # Make sure STEPCONFIG write protect is off:
  memory.setReg(ADC_CTRL, ADC_STEPCONFIG_WRITE_PROTECT_OFF)

  # Set STEPCONFIG1-STEPCONFIG8 to correspond to ADC inputs 0-7:
  for i in xrange(8):
    config = SEL_INP('AIN%i' % i) | ADC_AVG2
    memory.setReg(eval('ADCSTEPCONFIG%i' % (i+1)), config)
    memory.setReg(eval('ADCSTEPDELAY%i' % (i+1)), SAMPLE_DELAY(15))
  # Now we can enable ADC subsystem, leaving write protect off:
  memory.orReg(ADC_CTRL, TSC_ADC_SS_ENABLE)
Exemplo n.º 4
0
def analog_init():
  """ Initializes the on-board 8ch 12bit ADC. """
  # Enable ADC module clock, though should already be enabled on
  # newer Angstrom images:
  memory.setReg(CM_WKUP_ADC_TSC_CLKCTRL, MODULEMODE_ENABLE)
  # Wait for enable complete:
  while (memory.getReg(CM_WKUP_ADC_TSC_CLKCTRL) & IDLEST_MASK): delay(1)

  # Software reset:
  memory.setReg(ADC_SYSCONFIG, ADC_SOFTRESET)
  while(memory.getReg(ADC_SYSCONFIG) & ADC_SOFTRESET): pass

  # Make sure STEPCONFIG write protect is off:
  memory.setReg(ADC_CTRL, ADC_STEPCONFIG_WRITE_PROTECT_OFF)

  # Set STEPCONFIG1-STEPCONFIG8 to correspond to ADC inputs 0-7:
  for i in xrange(8):
    config = SEL_INP('AIN%i' % i) | ADC_AVG2
    memory.setReg(eval('ADCSTEPCONFIG%i' % (i+1)), config)
    memory.setReg(eval('ADCSTEPDELAY%i' % (i+1)), SAMPLE_DELAY(15))
  # Now we can enable ADC subsystem, leaving write protect off:
  memory.orReg(ADC_CTRL, TSC_ADC_SS_ENABLE)