Simon's and Max' camera steering software. https://stiefel.tech
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

89 lines
2.2 KiB

#ifndef INCLUDED_DRIVER_ALLEGRO_4988
#define INCLUDED_DRIVER_ALLEGRO_4988
#define CFG_SAMPLE_RATE_US 5
#define CFG_PERIPHERAL_SRC_PCM 1
#define CFG_DEPRECATED_ARG 0
#define PI_PWM_0 12
#define PI_PWM_1 13
#define PI_SW_PWM_RANGE 255
#include <queue>
#include <string>
#include <memory>
namespace simon {
namespace a4988 {
typedef struct
{
const unsigned gpio_en;
const unsigned gpio_step;
const unsigned gpio_dir;
const unsigned gpio_microsteps;
} a4988_settings_t;
class c_cmd
{
public:
explicit c_cmd(const std::string cmd) : m_cmd(cmd) {}
bool operator==(const std::string& vgl) {
return (vgl==m_cmd ? true : false);
}
virtual ~c_cmd(void) noexcept {}
private:
const std::string m_cmd;
};
class c_move : public c_cmd
{
public:
const unsigned steps;
const bool dir;
const unsigned period_us;
c_move(const unsigned isteps, const bool idir,
const unsigned iperiod_us)
: c_cmd("move"), steps(isteps), dir(idir), period_us(iperiod_us){}
};
class c_enable : public c_cmd
{
public:
const bool enabled;
explicit c_enable(const bool ienabled)
: c_cmd("enable"), enabled(ienabled) {}
};
class c_kill : public c_cmd
{
public:
c_kill(void)
: c_cmd("kill") {}
};
class c_allegro_4988
{
public:
explicit c_allegro_4988(std::unique_ptr<a4988_settings_t> ptr_set);
int enable(void);
int disable(void);
void kill(void);
void post(std::shared_ptr<c_cmd> cmd);
void post_move(const unsigned steps, const bool dir,
const unsigned period_us);
void run(void);
unsigned get_microsteps(void);
private:
std::unique_ptr<a4988_settings_t> m_ptr_set;
bool m_initialized;
std::queue<std::shared_ptr<c_cmd>> m_queue;
unsigned m_pwm_freq;
bool m_alive;
bool m_hw_pwm_possible;
private:
void initialize(void);
int set_pwm_freq(const unsigned pwm_freq);
};
} // namespace a4988
} // namespace simon
#endif /*INCLUDED_DRIVER_ALLEGRO_4988*/