File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -603,3 +603,40 @@ ap3_err_t servoWrite(uint8_t pin, uint32_t val)
603603
604604 return ap3_pwm_output (pin, th, fw, clk);
605605}
606+
607+ ap3_err_t tone (uint8_t pin, uint32_t freq)
608+ {
609+ uint32_t clk = AM_HAL_CTIMER_HFRC_12MHZ;
610+
611+ uint32_t fw = 0 ;
612+ if (freq > 0 )
613+ {
614+ // Determine the frame width based on input freq
615+ fw = 12000000 / freq;
616+ }
617+ uint32_t th = fw / 2 ; // 50% time high
618+
619+ return ap3_pwm_output (pin, th, fw, clk);
620+ }
621+ ap3_err_t tone (uint8_t pin, uint32_t freq, uint32_t duration)
622+ {
623+ ap3_err_t status = AP3_OK;
624+ status = tone (pin, freq);
625+ if (status != AP3_OK)
626+ {
627+ return (status);
628+ }
629+
630+ uint32_t startTime = millis ();
631+
632+ while (millis () - startTime < duration)
633+ ;
634+
635+ status = noTone (pin);
636+ return (status);
637+ }
638+
639+ ap3_err_t noTone (uint8_t pin)
640+ {
641+ return tone (pin, 0 );
642+ }
Original file line number Diff line number Diff line change @@ -51,4 +51,8 @@ ap3_err_t analogWrite(uint8_t pin, uint32_t val);
5151ap3_err_t servoWriteResolution (uint8_t res );
5252ap3_err_t servoWrite (uint8_t pin , uint32_t val );
5353
54+ ap3_err_t tone (uint8_t pin , uint32_t freq );
55+ ap3_err_t tone (uint8_t pin , uint32_t freq , uint32_t duration );
56+ ap3_err_t noTone (uint8_t pin );
57+
5458#endif // _AP3_ANALOG_H_
You can’t perform that action at this time.
0 commit comments