Пример #1
0
// Lua: clock = getclock()
static int lpwmled_getclock( lua_State* L )
{
  unsigned id;
  u32 clk;
  clk = platform_pwm_get_clock( led.pwmidr );
  lua_pushinteger( L, clk );
  return 1;
}
Пример #2
0
// Lua: clock = getclock( id )
static int ICACHE_FLASH_ATTR lpwm_getclock( lua_State* L )
{
  unsigned id;
  u32 clk;
  
  id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( pwm, id );
  clk = platform_pwm_get_clock( id );
  lua_pushinteger( L, clk );
  return 1;
}
Пример #3
0
u32 platform_pwm_setup( unsigned id, u32 frequency, unsigned duty )
{
  PWM_MATCHCFG_Type PWMMatchCfgDat;
  u32 divisor = platform_pwm_get_clock( id ) / frequency - 1;
    
  PWM_MatchUpdate( LPC_PWM1, 0, divisor, PWM_MATCH_UPDATE_NOW ); // PWM1 cycle rate
  PWM_MatchUpdate( LPC_PWM1, id, ( divisor * duty ) / 100, PWM_MATCH_UPDATE_NOW ); // PWM1 channel edge position
  
  if ( id > 1 ) // Channel one is permanently single-edge
    PWM_ChannelConfig( LPC_PWM1, id, PWM_CHANNEL_SINGLE_EDGE );
  
  PWMMatchCfgDat.IntOnMatch = DISABLE;
  PWMMatchCfgDat.MatchChannel = id;
  PWMMatchCfgDat.ResetOnMatch = DISABLE;
  PWMMatchCfgDat.StopOnMatch = DISABLE;
  PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);

  PWM_ResetCounter(LPC_PWM1);
  PWM_CounterCmd(LPC_PWM1, ENABLE);

  PWM_ChannelCmd(LPC_PWM1, id, ENABLE);

  return platform_pwm_get_clock( id ) / divisor;
}
Пример #4
0
uint32_t platform_pwm_setup( unsigned pin, uint32_t frequency, unsigned duty )
{
  uint32_t clock;
  if ( pin < NUM_PWM)
  {
    platform_gpio_mode(pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT);  // disable gpio interrupt first
    if(!pwm_add(pin)) 
      return 0;
    // pwm_set_duty(DUTY(duty), pin);
    pwm_set_duty(0, pin);
    pwms_duty[pin] = duty;
    pwm_set_freq((uint16_t)frequency, pin);
  } else {
    return 0;
  }
  clock = platform_pwm_get_clock( pin );
  pwm_start();
  return clock;
}