main.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef MAIN_H_
  2. #define MAIN_H_
  3. #define VERSION_MAJOR 1
  4. #define VERSION_MINOR 2
  5. #include "util.h"
  6. #include "machine_interface_internal.h"
  7. #include <stdint.h>
  8. /* Timekeeping */
  9. typedef uint16_t jiffies_t;
  10. typedef int16_t s_jiffies_t;
  11. /* time_after(a, b) returns true if the time a is after time b. */
  12. #define time_after(a, b) ((s_jiffies_t)(b) - (s_jiffies_t)(a) < 0)
  13. #define time_before(a, b) time_after(b, a)
  14. /* Number of jiffies-per-second */
  15. #define JPS ((uint32_t)15625)
  16. /* Convert milliseconds to jiffies. */
  17. #define msec2jiffies(msec) ((jiffies_t)DIV_ROUND_UP(JPS * (uint32_t)(msec), (uint32_t)1000))
  18. /* Get the jiffies counter */
  19. static inline jiffies_t get_jiffies(void)
  20. {
  21. /* Our timebase is in Timer1, which is accessed atomically
  22. * by atomic 16-bit I/O register access. */
  23. return (jiffies_t)(TCNT1);
  24. }
  25. /* Pushbuttons */
  26. #define BTN_HALT (1ul << 0) /* Motion halt */
  27. #define BTN_SPINDLE (1ul << 1) /* Spindle on/off */
  28. #define BTN_AXIS_NEXT (1ul << 2) /* Select next axis */
  29. #define BTN_AXIS_PREV (1ul << 3) /* Select previous axis */
  30. #define BTN_TOGGLE (1ul << 4) /* Generic toggle button */
  31. #define BTN_TWOHAND (1ul << 5) /* Twohand security switch */
  32. #define BTN_JOG_POSITIVE (1ul << 6) /* JOG + */
  33. #define BTN_JOG_RAPID (1ul << 7) /* Rapid JOG */
  34. #define BTN_JOG_NEGATIVE (1ul << 8) /* JOG - */
  35. #define BTN_JOG_INC (1ul << 9) /* JOG incremental */
  36. #define BTN_SOFT0 (1ul << 10) /* Softkey 0 */
  37. #define BTN_ONOFF (1ul << 11) /* Turn device on/off */
  38. #define BTN_SOFT1 (1ul << 12) /* Softkey 1 */
  39. #define BTN_ENCPUSH (1ul << 13) /* Encoder pushbutton */
  40. /* External output-port interface */
  41. #define EXTPORT(chipnr, portnr) ((1ul << (portnr)) << ((chipnr) * 8))
  42. #define EXT_LED_HALT EXTPORT(0, 0)
  43. #define EXT_LED_SPINDLE EXTPORT(0, 1)
  44. #define EXT_LED_AXIS_NEXT EXTPORT(0, 2)
  45. #define EXT_LED_AXIS_PREV EXTPORT(0, 3)
  46. #define EXT_LED_TOGGLE EXTPORT(0, 4)
  47. #define EXT_LED_TWOHAND EXTPORT(0, 5)
  48. #define EXT_LED_JOGPOS EXTPORT(0, 6)
  49. #define EXT_LED_JOGRAPID EXTPORT(0, 7)
  50. #define EXT_LED_JOGNEG EXTPORT(1, 0)
  51. #define EXT_LED_JOGINC EXTPORT(1, 1)
  52. #define EXT_LED_SK0 EXTPORT(1, 2)
  53. #define EXT_LED_ONOFF EXTPORT(1, 3)
  54. #define EXT_LED_SK1 EXTPORT(1, 4)
  55. /* Enable/disable LEDs */
  56. void leds_enable(bool enable);
  57. /* Reset the device */
  58. void reset_device_state(void);
  59. /* Axis mask */
  60. void set_axis_enable_mask(uint16_t mask);
  61. /* Axis manipulation */
  62. void axis_pos_update(uint8_t axis, fixpt_t absolute_pos);
  63. /* Spindle state */
  64. void spindle_state_update(bool on);
  65. /* Feed override feedback */
  66. void feed_override_feedback_update(uint8_t percent);
  67. /* Set the estop feedback state */
  68. void set_estop_state(bool asserted);
  69. /* Sets the increment size at index */
  70. bool set_increment_at_index(uint8_t index, fixpt_t increment);
  71. /* Request an update of the user interface */
  72. void update_userinterface(void);
  73. #endif /* MAIN_H_ */