STATIC void pyb_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "PWM(%u", self->pin->phys_port); if (self->active) { mp_printf(print, ", freq=%u, duty=%u", pwm_get_freq(self->channel), pwm_get_duty(self->channel)); } mp_printf(print, ")"); }
/****************************************************************************** * FunctionName : user_light_set_duty * Description : set pwm frequency * Parameters : uint16 freq : 100hz typically * Returns : NONE *******************************************************************************/ void ICACHE_FLASH_ATTR user_light_set_freq(uint16 freq) { if (freq != light_param.pwm_freq) { pwm_set_freq(freq); light_param.pwm_freq = pwm_get_freq(); } }
// Return the PWM clock // NOTE: Can't find a function to query for the period set for the timer, // therefore using the struct. // This may require adjustment if driver libraries are updated. uint32_t platform_pwm_get_clock( unsigned pin ) { // NODE_DBG("Function platform_pwm_get_clock() is called.\n"); if( pin >= NUM_PWM) return 0; if(!pwm_exist(pin)) return 0; return (uint32_t)pwm_get_freq(pin); }
// Set the PWM clock uint32_t platform_pwm_set_clock( unsigned pin, uint32_t clock ) { // NODE_DBG("Function platform_pwm_set_clock() is called.\n"); if( pin >= NUM_PWM) return 0; if(!pwm_exist(pin)) return 0; pwm_set_freq((uint16_t)clock, pin); pwm_start(); return (uint32_t)pwm_get_freq( pin ); }