00001 #ifndef INC_DCCONTROL_H
00002 #define INC_DCCONTROL_H
00003
00008 #if defined(WIN32) || defined(WIN64)
00009
00010 #define DCCONTROL_API __stdcall
00011 #else
00012 #define DCCONTROL_API __attribute__((visibility("default")))
00013 #endif
00014
00015 #if defined(__cplusplus)
00016 extern "C"
00017 {
00018 #endif
00019
00027
00028 #ifdef _MSC_VER
00029 typedef unsigned __int8 uint8_t;
00030 typedef unsigned __int32 uint32_t;
00031 #endif
00032
00041 typedef int device_t;
00042
00051 typedef int result_t;
00052
00061 #define device_undefined -1
00062
00071
00080 #define result_ok 0
00081
00090 #define result_error -1
00091
00100 #define result_not_implemented -2
00101
00110 #define result_dataerror -3
00111
00120 #define result_nodevice -4
00121
00123
00124
00125
00134 typedef enum {
00135 DevStateOff,
00136 DevStateStop,
00137 DevStateMoving,
00138 DevStateTune,
00139 DevStateHoming,
00140 DevStateCalibr = 0x0C,
00141 DevStateAlarm = 0x0A
00142 } DevState;
00143
00154 typedef enum {
00155 PwmStateOff,
00156 PwmStateBrak,
00157 PwmStateRunfwd,
00158 PwmStateRunbck,
00159 PwmStateInvbrak
00160 } PwmState;
00161
00170 typedef enum {
00171 PinGPIO = 0x00,
00172 PinSyncIn = 0x01,
00173 PinSyncOut = 0x02
00174 } SyncPinMode;
00175
00190 #define STATE_RIGHT_EDGE 0x0001
00191 #define STATE_LEFT_EDGE 0x0002
00192 #define STATE_EXT_POWER 0x0004
00193 #define STATE_ERRC 0x0008
00194 #define STATE_ERRD 0x0010
00195 #define STATE_POWER_DISABLE 0x0020
00196 #define STATE_TTLIO_PINOUT 0x0040
00197 #define STATE_TTLIO_LEVEL 0x0080
00198 #define STATE_BUTTON_RIGHT 0x0100
00199 #define STATE_BUTTON_LEFT 0x0200
00200 #define STATE_OVERHEAT 0x2000
00201 #define STATE_OVERLOAD_VOLTAGE 0x4000
00202 #define STATE_OVERLOAD_CURRENT 0x8000
00204
00205
00220 #define ENGINE_REVERSE 0x0001
00221 #define ENGINE_FINISHING 0x0002
00222 #define ENGINE_MAX_SPEED 0x0004
00223 #define ENGINE_ANTIPLAY 0x0008
00224 #define ENGINE_ACCEL_ON 0x0010
00225 #define ENGINE_LIMIT_VOLT 0x0020
00226 #define ENGINE_LIMIT_CURR 0x0040
00227 #define ENGINE_LIMIT_RPM 0x0080
00228 #define ENGINE_HOLD 0x0100
00229 #define ENGINE_DYNAMIC_HOLD 0x0200
00230 #define ENGINE_ONLY_FINISHING 0x0400
00232
00233
00248 #define MICROSTEP_MODE_FULL 0x01
00249 #define MICROSTEP_MODE_FRAC_2 0x02
00250 #define MICROSTEP_MODE_FRAC_4 0x04
00251 #define MICROSTEP_MODE_FRAC_8 0x08
00252 #define MICROSTEP_MODE_FRAC_16 0x10
00253 #define MICROSTEP_MODE_FRAC_32 0x20
00254 #define MICROSTEP_MODE_FRAC_64 0x40
00255 #define MICROSTEP_MODE_FRAC_128 0x80
00257
00258
00273 #define ENGINE_TYPE_DC 0x01
00274 #define ENGINE_TYPE_STEP 0x02
00275 #define ENGINE_TYPE_BRUSHLESS 0x04
00277
00278
00291 #define FEEDBACK_POTENTIOMETER 0x00
00292 #define FEEDBACK_ENCODER 0x01
00293 #define FEEDBACK_ENCODERDIFF 0x02
00295 #define FEEDBACK_ENCODERHALL 0x04
00296 #define FEEDBACK_EMF 0x08
00297 #define FEEDBACK_NONE 0x10
00299
00300
00312 #define TTL_SETUP_DIROUT 0x0001
00313 #define TTL_SETUP_OUTSET 0x0002
00314 #define TTL_SETUP_FRONT 0x0010
00316
00317
00328 #define TTL_SYNCIN_ONMOVE 0x0001
00329 #define TTL_SYNCIN_MULTI_SHIFT 0x0004
00330 #define TTL_SYNCIN_DIRRIGHT 0x0008
00332
00333
00344 #define TTL_SYNCOUT_ONSTART 0x0001
00345 #define TTL_SYNCOUT_ONSTOP 0x0002
00346 #define TTL_SYNCOUT_ONPERIOD 0x0004
00348
00349
00363 #define BORDER_IS_ENCODER 0x0001
00364 #define BORDER_STOP_LEFT 0x0002
00365 #define BORDER_STOP_RIGHT 0x0004
00367
00368
00382 #define ENDER_DIRECT 0x0001
00383 #define ENDER_ON1 0x0002
00384 #define ENDER_ON2 0x0004
00386
00387
00403 #define HOME_DIR_FAST 0x01
00404 #define HOME_STOP_FAST 0x02
00405 #define HOME_DIR_SLOW 0x04
00406 #define HOME_REV_EN 0x08
00408 // ------------------------------------
00409
00420 typedef struct
00421 {
00422 DevState device_state;
00423 PwmState pwm_state;
00424 unsigned int flags;
00425 unsigned int current_position;
00426 int current_rpm;
00427 int current_input;
00428 int current_engine_voltage;
00429 int current_power_voltage;
00430 int current_temp;
00431 } state_t;
00432
00444 typedef struct
00445 {
00446 int winding_voltage_a;
00447 int winding_voltage_b;
00448 int winding_voltage_c;
00449 int winding_current_a;
00450 int winding_current_b;
00451 int winding_current_c;
00452 int current_temp;
00453 } chart_data_t;
00454
00478 typedef struct
00479 {
00480 int amp_vout1;
00481 int amp_vout2;
00482 int amp_vext;
00483 int amp_vkey;
00484 int amp_engcur;
00485 int amp_tempkey;
00486 int off_vout1;
00487 int off_vout2;
00488 int off_vext;
00489 int off_vkey;
00490 int off_engcur;
00491 int off_tempkey;
00492 } calibration_settings_t;
00493
00513 typedef struct
00514 {
00515 unsigned int nom_voltage;
00516 unsigned int nom_input;
00517 unsigned int nom_rpm;
00518 unsigned int flags;
00519 int antiplay;
00520 int microstep_mode;
00521 int type;
00522 } engine_settings_t;
00523
00548 typedef struct
00549 {
00550 unsigned int kpi;
00551 unsigned int kii;
00552 unsigned int kdi;
00553 unsigned int kpu;
00554 unsigned int kiu;
00555 unsigned int kdu;
00556 unsigned int kprpm;
00557 unsigned int kirpm;
00558 unsigned int kdrpm;
00559 unsigned int kppos;
00560 unsigned int kipos;
00561 unsigned int kdpos;
00562 unsigned int kpe1;
00563 unsigned int kie1;
00564 unsigned int kde1;
00565 unsigned int kpe2;
00566 unsigned int kie2;
00567 unsigned int kde2;
00568 unsigned int kpe3;
00569 unsigned int kie3;
00570 unsigned int kde3;
00571 } pid_settings_t;
00572
00587 typedef struct
00588 {
00589 unsigned int setup_flags;
00590 unsigned int syncin_flags;
00591 unsigned int syncout_flags;
00592 SyncPinMode sync_pin_mode;
00593 unsigned int impulse_time;
00594 unsigned int impulse_period;
00595 } sync_settings_t;
00596
00611 typedef struct
00612 {
00613 int fast_home;
00614 int slow_home;
00615 unsigned int delta;
00616 unsigned int flags;
00617 } home_settings_t;
00618
00632 typedef struct
00633 {
00634 int adc_va1;
00635 int adc_va2;
00636 int adc_vb1;
00637 int adc_vext;
00638 int adc_vsup;
00639 int adc_acur;
00640 int adc_bcur;
00641 int adc_fullcur;
00642 int adc_pot;
00643 int adc_tempkey;
00644 int cdc_va1;
00645 int cdc_va2;
00646 int cdc_vb1;
00647 int cdc_vext;
00648 int cdc_vsup;
00649 int cdc_acur;
00650 int cdc_bcur;
00651 int cdc_fullcur;
00652 int cdc_tempkey;
00653 int cdc_dutycycle;
00654 } analog_data_t;
00655
00656
00657
00669
00680 device_t DCCONTROL_API open_device (const char* name);
00681
00692 result_t DCCONTROL_API close_device (device_t id);
00693
00706 result_t DCCONTROL_API probe_device (const char* name);
00707
00726 result_t DCCONTROL_API enumerate_devices(int* name_count, char*** names, int probe_devices);
00727
00742 result_t DCCONTROL_API free_enumerate_devices (int name_count, char** names);
00743
00754 result_t DCCONTROL_API init_device (device_t id);
00755
00766 result_t DCCONTROL_API deinit_device (device_t id);
00767
00786 result_t DCCONTROL_API get_device_information (device_t id, char* manufacturer, char* manufacturer_id, char* product_description);
00787
00795 result_t DCCONTROL_API reset_locks ();
00797
00798
00799
00811
00824 result_t DCCONTROL_API command_move (device_t id, unsigned int pos);
00825
00838 result_t DCCONTROL_API command_movr (device_t id, int offset);
00839
00850 result_t DCCONTROL_API command_left (device_t id);
00851
00862 result_t DCCONTROL_API command_right (device_t id);
00863
00874 result_t DCCONTROL_API command_stop (device_t id);
00875
00886 result_t DCCONTROL_API command_zero (device_t id);
00887
00911 result_t DCCONTROL_API command_home (device_t id);
00912
00926 result_t DCCONTROL_API get_status (device_t id, state_t* state);
00927
00929
00930
00942
00955 result_t DCCONTROL_API get_pwm_freq (device_t id, unsigned int* freq);
00956
00969 result_t DCCONTROL_API set_pwm_freq (device_t id, unsigned int freq);
00970
00985 result_t DCCONTROL_API get_feedback_settings (device_t id, unsigned int* ips, unsigned int* feedback_flags);
00986
01001 result_t DCCONTROL_API set_feedback_settings (device_t id, unsigned int ips, unsigned int feedback_flags);
01002
01019 result_t DCCONTROL_API get_move_settings (device_t id, unsigned int* rpm, unsigned int* accel, unsigned int* tuneup_threshold);
01020
01037 result_t DCCONTROL_API set_move_settings (device_t id, unsigned int rpm, unsigned int accel, unsigned int tuneup_threshold);
01038
01055 result_t DCCONTROL_API get_engine_settings (device_t id, engine_settings_t* engine_settings);
01056
01075 result_t DCCONTROL_API set_engine_settings (device_t id, const engine_settings_t* engine_settings);
01076
01098 result_t DCCONTROL_API get_secure_settings (device_t id, unsigned int* critical_curr, unsigned int* critical_voltage, unsigned int* critical_temp);
01099
01123 result_t DCCONTROL_API set_secure_settings (device_t id, unsigned int critical_curr, unsigned int critical_voltage, unsigned int critical_temp);
01124
01145 result_t DCCONTROL_API get_edges_settings (device_t id, int* border_flags, int* enders_flags, int* left, int* right);
01146
01165 result_t DCCONTROL_API set_edges_settings (device_t id, int border_flags, int enders_flags, int left, int right);
01166
01187 result_t DCCONTROL_API get_pid_settings (device_t id, pid_settings_t* pid_settings);
01188
01211 result_t DCCONTROL_API set_pid_settings (device_t id, const pid_settings_t* pid_settings);
01212
01230 result_t DCCONTROL_API get_sync_settings (device_t id, sync_settings_t* sync_settings);
01231
01249 result_t DCCONTROL_API set_sync_settings (device_t id, const sync_settings_t* sync_settings);
01250
01267 result_t DCCONTROL_API get_home_settings(device_t id, home_settings_t* home_settings);
01268
01285 result_t DCCONTROL_API set_home_settings(device_t id, const home_settings_t home_settings);
01286
01297 result_t DCCONTROL_API command_read_settings(device_t id);
01298
01309 result_t DCCONTROL_API command_save_settings(device_t id);
01310
01323 result_t DCCONTROL_API get_serial_number(device_t id, uint32_t* serial);
01324
01341 result_t DCCONTROL_API get_firmware_version(device_t id, unsigned int* major, unsigned int* minor, unsigned int* release);
01342
01358 result_t DCCONTROL_API get_analog_data (device_t id, analog_data_t* ad);
01374 result_t DCCONTROL_API get_chart_data (device_t id, chart_data_t* chart_data);
01375
01376
01377
01378
01397
01418 result_t DCCONTROL_API get_calibration_coeffs(device_t id, calibration_settings_t* cs);
01419
01444 result_t DCCONTROL_API set_calibration_coeffs(device_t id, const calibration_settings_t* cs);
01445
01458 device_t DCCONTROL_API open_raw_device (const char* name);
01459
01476 result_t DCCONTROL_API set_serial_number(device_t id, uint32_t serial, uint32_t key);
01477
01490 result_t DCCONTROL_API has_firmware(device_t id, uint8_t* ret);
01491
01506 result_t DCCONTROL_API write_key(device_t id, uint32_t key);
01507
01520 result_t DCCONTROL_API command_calibrate(device_t id);
01521
01534 result_t DCCONTROL_API command_reset(device_t id);
01535
01551 result_t DCCONTROL_API command_update_firmware(device_t id, const uint8_t* data, uint32_t data_size);
01552
01553
01555
01556 #if defined(__cplusplus)
01557 };
01558 #endif
01559
01560 #endif
01561