+/*
+ * There are two \a mode to stop the dc motor:
+ * - DC_MOTOR_DISABLE_MODE
+ * - DC_MOTOR_IDLE
+ *
+ * The DC_MOTOR_DISABLE_MODE shut down the DC motor and
+ * leave it floating to rotate.
+ * The DC_MOTOR_IDLE does not shut down DC motor, but put
+ * its supply pin in short circuite, in this way the motor result
+ * braked from intentional rotation.
+ */
+static void dc_motor_stop(int index)
+{
+ DCMotor *dcm = &dcm_all[index];
+
+ DC_MOTOR_LOCK;
+
+ dcm->status &= ~DC_MOTOR_ACTIVE;
+ dcm->expire_time = DC_MOTOR_NO_EXPIRE;
+ pwm_enable(dcm->cfg->pwm_dev, false);
+
+ if (dcm->cfg->braked)
+ {
+ DC_MOTOR_STOP_BRAKED(dcm->index);
+ }
+ else
+ {
+ DC_MOTOR_STOP_FLOAT(dcm->index);
+ }
+
+ DC_MOTOR_UNLOCK;
+}