@@ -229,10 +229,10 @@ static int getPWMCount(int freq)
229
229
}
230
230
231
231
/*
232
- * left motor function
232
+ * motor function
233
233
* called by parseMotorCmd() and rawmotor_l_write()
234
234
*/
235
- static void set_motor_l_freq (int freq )
235
+ static void set_motor_freq (int freq , const int dev_side )
236
236
{
237
237
int dat ;
238
238
@@ -244,65 +244,49 @@ static void set_motor_l_freq(int freq)
244
244
}
245
245
246
246
if (freq == 0 ) {
247
- rpi_gpio_function_set (MOTCLK_L_BASE , RPI_GPF_OUTPUT );
247
+ if (dev_side == DEV_LEFT ) {
248
+ rpi_gpio_function_set (MOTCLK_L_BASE , RPI_GPF_OUTPUT );
249
+ } else if (dev_side == DEV_RIGHT ) {
250
+ rpi_gpio_function_set (MOTCLK_R_BASE , RPI_GPF_OUTPUT );
251
+ }
248
252
return ;
249
253
} else {
250
- rpi_gpio_function_set (MOTCLK_L_BASE , RPI_GPF_ALT0 );
254
+ if (dev_side == DEV_LEFT ) {
255
+ rpi_gpio_function_set (MOTCLK_L_BASE , RPI_GPF_ALT0 );
256
+ } else if (dev_side == DEV_RIGHT ) {
257
+ rpi_gpio_function_set (MOTCLK_R_BASE , RPI_GPF_ALT0 );
258
+ }
251
259
}
252
260
253
261
if (freq > 0 ) {
254
- motor_l_freq_is_positive = 1 ;
255
- rpi_gpio_clear32 (RPI_GPIO_P2MASK , 1 << MOTDIR_L_BASE );
262
+ if (dev_side == DEV_LEFT ) {
263
+ motor_l_freq_is_positive = 1 ;
264
+ rpi_gpio_clear32 (RPI_GPIO_P2MASK , 1 << MOTDIR_L_BASE );
265
+ } else if (dev_side == DEV_RIGHT ) {
266
+ motor_r_freq_is_positive = 1 ;
267
+ rpi_gpio_clear32 (RPI_GPIO_P2MASK , 1 << MOTDIR_R_BASE );
268
+ }
256
269
} else {
257
- motor_l_freq_is_positive = 0 ;
258
- rpi_gpio_set32 (RPI_GPIO_P2MASK , 1 << MOTDIR_L_BASE );
259
- freq = - freq ;
270
+ if (dev_side == DEV_LEFT ) {
271
+ motor_l_freq_is_positive = 0 ;
272
+ rpi_gpio_set32 (RPI_GPIO_P2MASK , 1 << MOTDIR_L_BASE );
273
+ } else if (dev_side == DEV_RIGHT ) {
274
+ motor_r_freq_is_positive = 0 ;
275
+ rpi_gpio_set32 (RPI_GPIO_P2MASK , 1 << MOTDIR_R_BASE );
276
+ freq = - freq ;
277
+ }
260
278
}
261
279
262
280
dat = getPWMCount (freq );
263
281
264
- rpi_pwm_write32 (RPI_PWM_RNG1 , dat );
265
- rpi_pwm_write32 (RPI_PWM_DAT1 , dat >> 1 );
266
-
267
- return ;
268
- }
269
-
270
- /*
271
- * right motor function
272
- * called by parseMotorCmd() and rawmotor_r_write()
273
- */
274
- static void set_motor_r_freq (int freq )
275
- {
276
- int dat ;
277
-
278
- rpi_gpio_function_set (BUZZER_BASE , RPI_GPF_OUTPUT );
279
-
280
- // Reset uncontrollable frequency to zero.
281
- if (abs (freq ) < MOTOR_UNCONTROLLABLE_FREQ ) {
282
- freq = 0 ;
283
- }
284
-
285
- if (freq == 0 ) {
286
- rpi_gpio_function_set (MOTCLK_R_BASE , RPI_GPF_OUTPUT );
287
- return ;
288
- } else {
289
- rpi_gpio_function_set (MOTCLK_R_BASE , RPI_GPF_ALT0 );
290
- }
291
-
292
- if (freq > 0 ) {
293
- motor_r_freq_is_positive = 1 ;
294
- rpi_gpio_set32 (RPI_GPIO_P2MASK , 1 << MOTDIR_R_BASE );
295
- } else {
296
- motor_r_freq_is_positive = 0 ;
297
- rpi_gpio_clear32 (RPI_GPIO_P2MASK , 1 << MOTDIR_R_BASE );
298
- freq = - freq ;
282
+ if (dev_side == DEV_LEFT ) {
283
+ rpi_pwm_write32 (RPI_PWM_RNG1 , dat );
284
+ rpi_pwm_write32 (RPI_PWM_DAT1 , dat >> 1 );
285
+ } else if (dev_side == DEV_RIGHT ) {
286
+ rpi_pwm_write32 (RPI_PWM_RNG2 , dat );
287
+ rpi_pwm_write32 (RPI_PWM_DAT2 , dat >> 1 );
299
288
}
300
289
301
- dat = getPWMCount (freq );
302
-
303
- rpi_pwm_write32 (RPI_PWM_RNG2 , dat );
304
- rpi_pwm_write32 (RPI_PWM_DAT2 , dat >> 1 );
305
-
306
290
return ;
307
291
}
308
292
@@ -326,13 +310,13 @@ static int parseMotorCmd(const char __user *buf, size_t count, int *ret)
326
310
327
311
mutex_lock (& lock );
328
312
329
- set_motor_l_freq (l_motor_val );
330
- set_motor_r_freq (r_motor_val );
313
+ set_motor_freq (l_motor_val , DEV_LEFT );
314
+ set_motor_freq (r_motor_val , DEV_RIGHT );
331
315
332
316
msleep_interruptible (time_val );
333
317
334
- set_motor_l_freq ( 0 );
335
- set_motor_r_freq ( 0 );
318
+ set_motor_freq ( 0 , DEV_LEFT );
319
+ set_motor_freq ( 0 , DEV_RIGHT );
336
320
337
321
mutex_unlock (& lock );
338
322
@@ -751,7 +735,7 @@ static ssize_t rawmotor_l_write(struct file *filep, const char __user *buf,
751
735
DRIVER_NAME , __func__ );
752
736
return ret ;
753
737
}
754
- set_motor_l_freq (freq );
738
+ set_motor_freq (freq , DEV_LEFT );
755
739
756
740
return count ;
757
741
}
@@ -772,7 +756,7 @@ static ssize_t rawmotor_r_write(struct file *filep, const char __user *buf,
772
756
return ret ;
773
757
}
774
758
775
- set_motor_r_freq (freq );
759
+ set_motor_freq (freq , DEV_RIGHT );
776
760
777
761
return count ;
778
762
}
0 commit comments