auto-sync
This commit is contained in:
parent
01dc89b295
commit
b4bdc5c5db
|
@ -21,5 +21,6 @@ HW_LAYER_SRC_CPP = $(PROJECT_DIR)/hw_layer/hardware.cpp \
|
|||
$(PROJECT_DIR)/hw_layer/pwm_generator.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/trigger_input.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/HIP9011.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/stepper.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/stm32f4/mpu_util.cpp
|
||||
|
|
@ -1,13 +1,11 @@
|
|||
/*
|
||||
* pin_repository.h
|
||||
*
|
||||
* @date Jan 15, 2013
|
||||
* @author Andrey Belomutskiy, (c) 2012-2014
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file pin_repository.h
|
||||
* @brief I/O pin registry header
|
||||
*
|
||||
*
|
||||
*
|
||||
* @date Jan 15, 2013
|
||||
* @author Andrey Belomutskiy, (c) 2012-2014
|
||||
*/
|
||||
|
||||
#ifndef PIN_REPOSITORY_H_
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* @file stepper.cpp
|
||||
*
|
||||
* http://rusefi.com/wiki/index.php?title=Hardware:Stepper_motor
|
||||
*
|
||||
* @date Dec 24, 2014
|
||||
* @author Andrey Belomutskiy, (c) 2012-2014
|
||||
*/
|
||||
|
||||
#include "stepper.h"
|
||||
#include "pin_repository.h"
|
||||
|
||||
#define ST_DELAY_MS 20
|
||||
|
||||
#define ST_COUNT 200
|
||||
|
||||
static msg_t stThread(StepperMotor *motor) {
|
||||
chRegSetThreadName("stepper");
|
||||
|
||||
// let's part the motor in a known position to begin with
|
||||
for (int i = 0; i < ST_COUNT; i++) {
|
||||
motor->pulse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void StepperMotor::pulse() {
|
||||
palWritePad(stepPort, stepPin, true);
|
||||
chThdSleepMilliseconds(ST_DELAY_MS);
|
||||
palWritePad(stepPort, stepPin, false);
|
||||
chThdSleepMilliseconds(ST_DELAY_MS);
|
||||
}
|
||||
|
||||
|
||||
void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin) {
|
||||
position = 0;
|
||||
|
||||
stepPort = getHwPort(stepPin);
|
||||
this->stepPin = getHwPin(stepPin);
|
||||
|
||||
mySetPadMode("st step", stepPort, this->stepPin, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
mySetPadMode("st dir", getHwPort(directionPin), getHwPin(directionPin), PAL_MODE_OUTPUT_PUSHPULL);
|
||||
|
||||
chThdCreateStatic(stThreadStack, sizeof(stThreadStack), NORMALPRIO, (tfunc_t) stThread, this);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* @file stepper.h
|
||||
*
|
||||
* @date Dec 24, 2014
|
||||
* @author Andrey Belomutskiy, (c) 2012-2014
|
||||
*/
|
||||
#ifndef STEPPER_H_
|
||||
#define STEPPER_H_
|
||||
|
||||
#include "main.h"
|
||||
|
||||
class StepperMotor {
|
||||
public:
|
||||
void initialize(brain_pin_e stepPin, brain_pin_e directionPin);
|
||||
void pulse();
|
||||
private:
|
||||
|
||||
GPIO_TypeDef * stepPort;
|
||||
ioportmask_t stepPin;
|
||||
GPIO_TypeDef * directionPort;
|
||||
ioportmask_t directionPin;
|
||||
|
||||
int position;
|
||||
|
||||
THD_WORKING_AREA(stThreadStack, UTILITY_THREAD_STACK_SIZE);
|
||||
|
||||
};
|
||||
|
||||
#endif /* STEPPER_H_ */
|
Loading…
Reference in New Issue