@@ -417,100 +417,12 @@ static inline int z_impl_pwm_get_cycles_per_sec(const struct device *dev,
417417 return api -> get_cycles_per_sec (dev , channel , cycles );
418418}
419419
420- /**
421- * @brief Set the period and pulse width in microseconds for a single PWM
422- * output.
423- *
424- * @param[in] dev PWM device instance.
425- * @param channel PWM channel.
426- * @param period Period (in microseconds) set to the PWM.
427- * @param pulse Pulse width (in microseconds) set to the PWM.
428- * @param flags Flags for pin configuration (polarity).
429- *
430- * @retval 0 If successful.
431- * @retval -ENOTSUP If requested period or pulse cycles are not supported.
432- * @retval -errno Other negative errno code on failure.
433- */
434- static inline int pwm_set_usec (const struct device * dev , uint32_t channel ,
435- uint32_t period , uint32_t pulse ,
436- pwm_flags_t flags )
437- {
438- int err ;
439- uint64_t pulse_cycles ;
440- uint64_t period_cycles ;
441- uint64_t cycles_per_sec ;
442-
443- err = pwm_get_cycles_per_sec (dev , channel , & cycles_per_sec );
444- if (err < 0 ) {
445- return err ;
446- }
447-
448- period_cycles = (period * cycles_per_sec ) / USEC_PER_SEC ;
449- if (period_cycles > UINT32_MAX ) {
450- return - ENOTSUP ;
451- }
452-
453- pulse_cycles = (pulse * cycles_per_sec ) / USEC_PER_SEC ;
454- if (pulse_cycles > UINT32_MAX ) {
455- return - ENOTSUP ;
456- }
457-
458- return pwm_set_cycles (dev , channel , (uint32_t )period_cycles ,
459- (uint32_t )pulse_cycles , flags );
460- }
461-
462- /**
463- * @brief Set the period and pulse width in microseconds from a struct
464- * pwm_dt_spec (with custom period).
465- *
466- * This is equivalent to:
467- *
468- * pwm_set_usec(spec->dev, spec->channel, period, pulse, spec->flags)
469- *
470- * The period specified in @p spec is ignored. This API call can be used when
471- * the period specified in Devicetree needs to be changed at runtime.
472- *
473- * @param[in] spec PWM specification from devicetree.
474- * @param period Period (in microseconds) set to the PWM.
475- * @param pulse Pulse width (in microseconds) set to the PWM.
476- *
477- * @return A value from pwm_set_usec().
478- *
479- * @see pwm_set_usec_pulse_dt()
480- */
481- static inline int pwm_set_usec_dt (const struct pwm_dt_spec * spec ,
482- uint32_t period , uint32_t pulse )
483- {
484- return pwm_set_usec (spec -> dev , spec -> channel , period , pulse ,
485- spec -> flags );
486- }
487-
488- /**
489- * @brief Set the period and pulse width in microseconds from a struct
490- * pwm_dt_spec.
491- *
492- * This is equivalent to:
493- *
494- * pwm_set_usec(spec->dev, spec->channel, spec->period / NSEC_PER_USEC,
495- * pulse, spec->flags)
496- *
497- * @param[in] spec PWM specification from devicetree.
498- * @param pulse Pulse width (in microseconds) set to the PWM.
499- *
500- * @return A value from pwm_set_usec().
501- *
502- * @see pwm_set_usec_dt()
503- */
504- static inline int pwm_set_usec_pulse_dt (const struct pwm_dt_spec * spec ,
505- uint32_t pulse )
506- {
507- return pwm_set_usec (spec -> dev , spec -> channel ,
508- spec -> period / NSEC_PER_USEC , pulse , spec -> flags );
509- }
510-
511420/**
512421 * @brief Set the period and pulse width in nanoseconds for a single PWM output.
513422 *
423+ * @note Utility macros such as PWM_MSEC() can be used to convert from other
424+ * scales or units to nanoseconds, the units used by this function.
425+ *
514426 * @param[in] dev PWM device instance.
515427 * @param channel PWM channel.
516428 * @param period Period (in nanoseconds) set to the PWM.
@@ -521,9 +433,8 @@ static inline int pwm_set_usec_pulse_dt(const struct pwm_dt_spec *spec,
521433 * @retval -ENOTSUP If requested period or pulse cycles are not supported.
522434 * @retval -errno Other negative errno code on failure.
523435 */
524- static inline int pwm_set_nsec (const struct device * dev , uint32_t channel ,
525- uint32_t period , uint32_t pulse ,
526- pwm_flags_t flags )
436+ static inline int pwm_set (const struct device * dev , uint32_t channel ,
437+ uint32_t period , uint32_t pulse , pwm_flags_t flags )
527438{
528439 int err ;
529440 uint64_t pulse_cycles ;
@@ -555,7 +466,7 @@ static inline int pwm_set_nsec(const struct device *dev, uint32_t channel,
555466 *
556467 * This is equivalent to:
557468 *
558- * pwm_set_nsec (spec->dev, spec->channel, period, pulse, spec->flags)
469+ * pwm_set (spec->dev, spec->channel, period, pulse, spec->flags)
559470 *
560471 * The period specified in @p spec is ignored. This API call can be used when
561472 * the period specified in Devicetree needs to be changed at runtime.
@@ -564,15 +475,14 @@ static inline int pwm_set_nsec(const struct device *dev, uint32_t channel,
564475 * @param period Period (in nanoseconds) set to the PWM.
565476 * @param pulse Pulse width (in nanoseconds) set to the PWM.
566477 *
567- * @return A value from pwm_set_nsec ().
478+ * @return A value from pwm_set ().
568479 *
569- * @see pwm_set_nsec_pulse_dt ()
480+ * @see pwm_set_pulse_dt ()
570481 */
571- static inline int pwm_set_nsec_dt (const struct pwm_dt_spec * spec ,
572- uint32_t period , uint32_t pulse )
482+ static inline int pwm_set_dt (const struct pwm_dt_spec * spec , uint32_t period ,
483+ uint32_t pulse )
573484{
574- return pwm_set_nsec (spec -> dev , spec -> channel , period , pulse ,
575- spec -> flags );
485+ return pwm_set (spec -> dev , spec -> channel , period , pulse , spec -> flags );
576486}
577487
578488/**
@@ -581,20 +491,20 @@ static inline int pwm_set_nsec_dt(const struct pwm_dt_spec *spec,
581491 *
582492 * This is equivalent to:
583493 *
584- * pwm_set_nsec (spec->dev, spec->channel, spec->period, pulse, spec->flags)
494+ * pwm_set (spec->dev, spec->channel, spec->period, pulse, spec->flags)
585495 *
586496 * @param[in] spec PWM specification from devicetree.
587497 * @param pulse Pulse width (in nanoseconds) set to the PWM.
588498 *
589- * @return A value from pwm_set_nsec ().
499+ * @return A value from pwm_set ().
590500 *
591- * @see pwm_set_nsec_pulse_dt ()
501+ * @see pwm_set_pulse_dt ()
592502 */
593- static inline int pwm_set_nsec_pulse_dt (const struct pwm_dt_spec * spec ,
594- uint32_t pulse )
503+ static inline int pwm_set_pulse_dt (const struct pwm_dt_spec * spec ,
504+ uint32_t pulse )
595505{
596- return pwm_set_nsec (spec -> dev , spec -> channel , spec -> period , pulse ,
597- spec -> flags );
506+ return pwm_set (spec -> dev , spec -> channel , spec -> period , pulse ,
507+ spec -> flags );
598508}
599509
600510/**
@@ -934,26 +844,27 @@ pwm_pin_set_cycles(const struct device *dev, uint32_t channel, uint32_t period,
934844
935845/**
936846 * @brief Set the period and pulse width for a single PWM output.
937- * @deprecated Use pwm_set_usec () instead.
847+ * @deprecated Use pwm_set() with PWM_USEC () instead.
938848 */
939849__deprecated static inline int pwm_pin_set_usec (const struct device * dev ,
940850 uint32_t channel ,
941851 uint32_t period , uint32_t pulse ,
942852 pwm_flags_t flags )
943853{
944- return pwm_set_usec (dev , channel , period , pulse , flags );
854+ return pwm_set (dev , channel , period * NSEC_PER_USEC ,
855+ pulse * NSEC_PER_USEC , flags );
945856}
946857
947858/**
948859 * @brief Set the period and pulse width for a single PWM output.
949- * @deprecated Use pwm_set_nsec () instead.
860+ * @deprecated Use pwm_set () instead.
950861 */
951862__deprecated static inline int pwm_pin_set_nsec (const struct device * dev ,
952863 uint32_t channel ,
953864 uint32_t period , uint32_t pulse ,
954865 pwm_flags_t flags )
955866{
956- return pwm_set_nsec (dev , channel , period , pulse , flags );
867+ return pwm_set (dev , channel , period , pulse , flags );
957868}
958869
959870/**
0 commit comments