static int servo_motor_open(struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options) { const struct sol_flow_node_type_servo_motor_controller_options *opts; struct servo_motor_data *mdata = data; struct sol_pwm_config pwm_config = { 0 }; opts = (const struct sol_flow_node_type_servo_motor_controller_options *)options; mdata->duty_cycle_range = opts->duty_cycle_range; if (mdata->duty_cycle_range.min > mdata->duty_cycle_range.max) { SOL_WRN("Max pulse width shouldn't be less than min. Swapping values."); mdata->duty_cycle_range.max = opts->duty_cycle_range.min; mdata->duty_cycle_range.min = opts->duty_cycle_range.max; } mdata->duty_cycle_diff = mdata->duty_cycle_range.max - mdata->duty_cycle_range.min; pwm_config.api_version = SOL_PWM_CONFIG_API_VERSION; pwm_config.period_ns = opts->period.val * 1000; pwm_config.duty_cycle_ns = 0; mdata->pwm = sol_pwm_open(opts->chip.val, opts->pin.val, &pwm_config); SOL_NULL_CHECK(mdata->pwm, -ENOMEM); return 0; }
SOL_API struct sol_pwm * sol_pwm_open_by_label(const char *label, const struct sol_pwm_config *config) { int device, channel; _log_init(); #ifdef USE_PIN_MUX if (!sol_pin_mux_map(label, SOL_IO_PWM, &device, &channel)) return sol_pwm_open(device, channel, config); SOL_WRN("Label '%s' couldn't be mapped or can't be used as PWM", label); #else SOL_INF("Pin Multiplexer support is necessary to open a 'board pin'."); (void)device; (void)channel; #endif return NULL; }