@@ -86,6 +86,12 @@ void servo_set_bounds(uint a, uint b)
8686 }
8787}
8888
89+ /**
90+ * @brief Set up the servo system.
91+ *
92+ * Attach IRQ handler, allocate and initialize memory. *
93+ *
94+ */
8995int servo_init (void )
9096{
9197 for (int i = 0 ; i < 30 ; ++ i )
@@ -102,11 +108,25 @@ int servo_init(void)
102108 return 0 ;
103109}
104110
111+
112+ /**
113+ * @brief Reference the primary clock.
114+ *
115+ * Set the clock source to CLOCKS_FC0_SRC_VALUE_PLL_SYS_CLKSRC_PRIMARY
116+ *
117+ */
105118int servo_clock_auto (void )
106119{
107120 return servo_clock_source (CLOCKS_FC0_SRC_VALUE_PLL_SYS_CLKSRC_PRIMARY );
108121}
109122
123+
124+ /**
125+ * @brief Specify the clock source.
126+ *
127+ * Specify the clock source.
128+ *
129+ */
110130int servo_clock_source (uint src )
111131{
112132 clkdiv = (float )frequency_count_khz (src ) * (float )KILO / (FREQ * WRAP );
@@ -115,16 +135,19 @@ int servo_clock_source(uint src)
115135 return 1 ;
116136 }
117137 us_per_unit = 1.f / (FREQ * WRAP ) / MICRO ;
118-
119- //min = 0.025f * WRAP;
120- //max = 0.125f * WRAP;
121138
122139 min = min_us / us_per_unit ;
123140 max = max_us / us_per_unit ;
124141
125142 return 0 ;
126143}
127144
145+ /**
146+ * @brief Probably don't use this
147+ *
148+ * Not a good idea
149+ *
150+ */
128151int servo_clock_manual (uint freq )
129152{
130153 clkdiv = (float )freq * 1000.f / (FREQ * WRAP );
@@ -138,6 +161,13 @@ int servo_clock_manual(uint freq)
138161 return 0 ;
139162}
140163
164+ /**
165+ * @brief Allocate a pin to controlling a servo
166+ *
167+ * Binds the specified pin to PWM output.
168+ *
169+ * @param pin The pin to make PWM output.
170+ */
141171int servo_attach (uint pin )
142172{
143173 uint slice = pwm_gpio_to_slice_num (pin );
@@ -168,6 +198,13 @@ int servo_attach(uint pin)
168198 return 0 ;
169199}
170200
201+ /**
202+ * @brief Move a servo.
203+ * Move the servo on the specified pin to the specified angle.
204+ *
205+ * @param pin The PWM pin controlling a servo.
206+ * @param angle The angle to move to.
207+ */
171208int servo_move_to (uint pin , uint angle )
172209{
173210 if (slice_map [pin ] < 0 )
@@ -182,6 +219,15 @@ int servo_move_to(uint pin, uint angle)
182219 return 0 ;
183220}
184221
222+ /**
223+ * @brief Move a servo.
224+ *
225+ * Move a servo by specifing microseconds.
226+ * Note that this is dangerous and can damage your servo if you are not careful!
227+ *
228+ * @param pin The PWM pin.
229+ * @param us The amount of time in microseconds the PWM signal is high.
230+ */
185231int servo_microseconds (uint pin , uint us )
186232{
187233 if (slice_map [pin ] < 0 )
0 commit comments