My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

macros.h 4.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  13. Contact information
  14. -------------------
  15. Circuits At Home, LTD
  16. Web : http://www.circuitsathome.com
  17. e-mail : support@circuitsathome.com
  18. */
  19. #ifndef _usb_h_
  20. #error "Never include macros.h directly; include Usb.h instead"
  21. #endif
  22. #ifndef MACROS_H
  23. #define MACROS_H
  24. ////////////////////////////////////////////////////////////////////////////////
  25. // HANDY MACROS
  26. ////////////////////////////////////////////////////////////////////////////////
  27. #define VALUE_BETWEEN(v,l,h) (((v)>(l)) && ((v)<(h)))
  28. #define VALUE_WITHIN(v,l,h) (((v)>=(l)) && ((v)<=(h)))
  29. #define output_pgm_message(wa,fp,mp,el) wa = &mp, fp((char *)pgm_read_pointer(wa), el)
  30. #define output_if_between(v,l,h,wa,fp,mp,el) if(VALUE_BETWEEN(v,l,h)) output_pgm_message(wa,fp,mp[v-(l+1)],el);
  31. #define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b)))
  32. #ifndef __BYTE_GRABBING_DEFINED__
  33. #define __BYTE_GRABBING_DEFINED__ 1
  34. #ifdef BROKEN_OPTIMIZER_LITTLE_ENDIAN
  35. // Note: Use this if your compiler generates horrible assembler!
  36. #define BGRAB0(__usi__) (((uint8_t *)&(__usi__))[0])
  37. #define BGRAB1(__usi__) (((uint8_t *)&(__usi__))[1])
  38. #define BGRAB2(__usi__) (((uint8_t *)&(__usi__))[2])
  39. #define BGRAB3(__usi__) (((uint8_t *)&(__usi__))[3])
  40. #define BGRAB4(__usi__) (((uint8_t *)&(__usi__))[4])
  41. #define BGRAB5(__usi__) (((uint8_t *)&(__usi__))[5])
  42. #define BGRAB6(__usi__) (((uint8_t *)&(__usi__))[6])
  43. #define BGRAB7(__usi__) (((uint8_t *)&(__usi__))[7])
  44. #else
  45. // Note: The cast alone to uint8_t is actually enough.
  46. // GCC throws out the "& 0xff", and the size is no different.
  47. // Some compilers need it.
  48. #define BGRAB0(__usi__) ((uint8_t)((__usi__) & 0xff ))
  49. #define BGRAB1(__usi__) ((uint8_t)(((__usi__) >> 8) & 0xff))
  50. #define BGRAB2(__usi__) ((uint8_t)(((__usi__) >> 16) & 0xff))
  51. #define BGRAB3(__usi__) ((uint8_t)(((__usi__) >> 24) & 0xff))
  52. #define BGRAB4(__usi__) ((uint8_t)(((__usi__) >> 32) & 0xff))
  53. #define BGRAB5(__usi__) ((uint8_t)(((__usi__) >> 40) & 0xff))
  54. #define BGRAB6(__usi__) ((uint8_t)(((__usi__) >> 48) & 0xff))
  55. #define BGRAB7(__usi__) ((uint8_t)(((__usi__) >> 56) & 0xff))
  56. #endif
  57. #define BOVER1(__usi__) ((uint16_t)(__usi__) << 8)
  58. #define BOVER2(__usi__) ((uint32_t)(__usi__) << 16)
  59. #define BOVER3(__usi__) ((uint32_t)(__usi__) << 24)
  60. #define BOVER4(__usi__) ((uint64_t)(__usi__) << 32)
  61. #define BOVER5(__usi__) ((uint64_t)(__usi__) << 40)
  62. #define BOVER6(__usi__) ((uint64_t)(__usi__) << 48)
  63. #define BOVER7(__usi__) ((uint64_t)(__usi__) << 56)
  64. // These are the smallest and fastest ways I have found so far in pure C/C++.
  65. #define BMAKE16(__usc1__,__usc0__) ((uint16_t)((uint16_t)(__usc0__) | (uint16_t)BOVER1(__usc1__)))
  66. #define BMAKE32(__usc3__,__usc2__,__usc1__,__usc0__) ((uint32_t)((uint32_t)(__usc0__) | (uint32_t)BOVER1(__usc1__) | (uint32_t)BOVER2(__usc2__) | (uint32_t)BOVER3(__usc3__)))
  67. #define BMAKE64(__usc7__,__usc6__,__usc5__,__usc4__,__usc3__,__usc2__,__usc1__,__usc0__) ((uint64_t)((uint64_t)__usc0__ | (uint64_t)BOVER1(__usc1__) | (uint64_t)BOVER2(__usc2__) | (uint64_t)BOVER3(__usc3__) | (uint64_t)BOVER4(__usc4__) | (uint64_t)BOVER5(__usc5__) | (uint64_t)BOVER6(__usc6__) | (uint64_t)BOVER1(__usc7__)))
  68. #endif
  69. /*
  70. * Debug macros: Strings are stored in progmem (flash) instead of RAM.
  71. */
  72. #define USBTRACE(s) (Notify(PSTR(s), 0x80))
  73. #define USBTRACE1(s,l) (Notify(PSTR(s), l))
  74. #define USBTRACE2(s,r) (Notify(PSTR(s), 0x80), D_PrintHex((r), 0x80), Notify(PSTR("\r\n"), 0x80))
  75. #define USBTRACE3(s,r,l) (Notify(PSTR(s), l), D_PrintHex((r), l), Notify(PSTR("\r\n"), l))
  76. #endif /* MACROS_H */