Пример #1
0
def pwmEnable(pwm_pin):
  """ Ensures PWM module for the given pin is enabled and its ocp helper
      is loaded. """
  global PWM_PINS_ENABLED
  if PWM_PINS_ENABLED.get(pwm_pin): return
  pin_config = PWM_PINS[pwm_pin]
  assert (pin_config), "*Invalid PWM pin: '%s'" % pwm_pin

  for overlay in pin_config[2]:
    cape_manager.load(overlay, auto_unload=False)
    delay(250) # Give it some time to take effect
  cape_manager.load(pin_config[0], auto_unload=False)
  delay(250)

  helper_path = pin_config[1]
  # Make sure output is disabled, so it won't start outputing a 
  # signal until analogWrite() is called: 
  if (sysfs.kernelFilenameIO('%s/%s' % (helper_path, PWM_RUN)) == '1\n'):
    sysfs.kernelFilenameIO('%s/%s' % (helper_path, PWM_RUN), '0')

  # Duty cyle must be set to 0 before changing frequency:
  sysfs.kernelFilenameIO('%s/%s' % (helper_path, PWM_DUTY), '0')
  # Is this still true??

  sysfs.kernelFilenameIO('%s/%s' % (helper_path, PWM_PERIOD), 
                      str(PWM_DEFAULT_PERIOD))
  addToCleanup(lambda : pwmDisable(pwm_pin))
  PWM_PINS_ENABLED[pwm_pin] = True
Пример #2
0
def pwmEnable(pwm_pin):
    """ Ensures PWM module for the given pin is enabled and its ocp helper
      is loaded. """
    global PWM_PINS_ENABLED
    if PWM_PINS_ENABLED.get(pwm_pin): return
    pin_config = PWM_PINS[pwm_pin]
    assert (pin_config), "*Invalid PWM pin: '%s'" % pwm_pin

    for overlay in pin_config[2]:
        cape_manager.load(overlay, auto_unload=False)
        delay(250)  # Give it some time to take effect
    cape_manager.load(pin_config[0], auto_unload=False)
    delay(250)

    helper_path = pin_config[1]
    # Make sure output is disabled, so it won't start outputing a
    # signal until analogWrite() is called:
    if (sysfs.kernelFilenameIO('%s/%s' % (helper_path, PWM_RUN)) == '1\n'):
        sysfs.kernelFilenameIO('%s/%s' % (helper_path, PWM_RUN), '0')

    # Duty cyle must be set to 0 before changing frequency:
    sysfs.kernelFilenameIO('%s/%s' % (helper_path, PWM_DUTY), '0')
    # Is this still true??

    sysfs.kernelFilenameIO('%s/%s' % (helper_path, PWM_PERIOD),
                           str(PWM_DEFAULT_PERIOD))
    addToCleanup(lambda: pwmDisable(pwm_pin))
    PWM_PINS_ENABLED[pwm_pin] = True
Пример #3
0
def pwm_init():
  # Enable EHRPWM module clocks:
  memory.setReg(CM_PER_EPWMSS1_CLKCTRL, MODULEMODE_ENABLE)
  # Wait for enable complete:
  while (memory.getReg(CM_PER_EPWMSS1_CLKCTRL) & IDLEST_MASK): delay(1)
  memory.setReg(CM_PER_EPWMSS2_CLKCTRL, MODULEMODE_ENABLE)
  # Wait for enable complete:
  while (memory.getReg(CM_PER_EPWMSS2_CLKCTRL) & IDLEST_MASK): delay(1)
Пример #4
0
def pwm_init():
    # Enable EHRPWM module clocks:
    memory.setReg(CM_PER_EPWMSS1_CLKCTRL, MODULEMODE_ENABLE)
    # Wait for enable complete:
    while (memory.getReg(CM_PER_EPWMSS1_CLKCTRL) & IDLEST_MASK):
        delay(1)
    memory.setReg(CM_PER_EPWMSS2_CLKCTRL, MODULEMODE_ENABLE)
    # Wait for enable complete:
    while (memory.getReg(CM_PER_EPWMSS2_CLKCTRL) & IDLEST_MASK):
        delay(1)
Пример #5
0
def pwmEnable(pwm_pin):
  """ Ensures given PWM output is reserved for userspace use and 
      sets proper pinmux. Sets frequency to default value if output
      not already reserved. """
  assert (pwm_pin in PWM_PINS), "*Invalid PWM pin: '%s'" % pwm_pin
  # Set pinmux mode:
  pinmux.pinMux(PWM_PINS[pwm_pin][0], PWM_PINS[pwm_pin][1])
  if ('sysfs' not in pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_REQUEST])):
    # Reserve use of output:
    pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_REQUEST], '1')
    delay(1) # Give it some time to take effect
    # Make sure output is disabled, so it won't start outputing a 
    # signal until analogWrite() is called: 
    if (pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_ENABLE]) == '1\n'):
      pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_ENABLE], '0')
    # Duty cyle must be set to 0 before changing frequency:
    pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_DUTY], '0')
    # Set frequency to default:
    pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_FREQ], str(PWM_DEFAULT_FREQ))
Пример #6
0
def pwmEnable(pwm_pin):
    """ Ensures given PWM output is reserved for userspace use and 
      sets proper pinmux. Sets frequency to default value if output
      not already reserved. """
    assert (pwm_pin in PWM_PINS), "*Invalid PWM pin: '%s'" % pwm_pin
    # Set pinmux mode:
    pinmux.pinMux(PWM_PINS[pwm_pin][0], PWM_PINS[pwm_pin][1])
    if ('sysfs' not in pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_REQUEST])):
        # Reserve use of output:
        pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_REQUEST], '1')
        delay(1)  # Give it some time to take effect
        # Make sure output is disabled, so it won't start outputing a
        # signal until analogWrite() is called:
        if (pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_ENABLE]) == '1\n'):
            pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_ENABLE], '0')
        # Duty cyle must be set to 0 before changing frequency:
        pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_DUTY], '0')
        # Set frequency to default:
        pinmux.kernelFileIO(PWM_FILES[pwm_pin][PWM_FREQ],
                            str(PWM_DEFAULT_FREQ))