aboutsummaryrefslogtreecommitdiff
path: root/lib/usbhost/USB_Host_Shield_2.0/macros.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/usbhost/USB_Host_Shield_2.0/macros.h')
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/macros.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/usbhost/USB_Host_Shield_2.0/macros.h b/lib/usbhost/USB_Host_Shield_2.0/macros.h
new file mode 100644
index 000000000..e14a711fa
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/macros.h
@@ -0,0 +1,82 @@
1/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2
3This software may be distributed and modified under the terms of the GNU
4General Public License version 2 (GPL2) as published by the Free Software
5Foundation and appearing in the file GPL2.TXT included in the packaging of
6this file. Please note that GPL2 Section 2[b] requires that all works based
7on this software must also be made publicly available under the terms of
8the GPL2 ("Copyleft").
9
10Contact information
11-------------------
12
13Circuits At Home, LTD
14Web : http://www.circuitsathome.com
15e-mail : support@circuitsathome.com
16 */
17
18#if !defined(_usb_h_) || defined(MACROS_H)
19#error "Never include macros.h directly; include Usb.h instead"
20#else
21#define MACROS_H
22
23////////////////////////////////////////////////////////////////////////////////
24// HANDY MACROS
25////////////////////////////////////////////////////////////////////////////////
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
32#define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b)))
33#ifndef __BYTE_GRABBING_DEFINED__
34#define __BYTE_GRABBING_DEFINED__ 1
35#ifdef BROKEN_OPTIMIZER_LITTLE_ENDIAN
36// Note: Use this if your compiler generates horrible assembler!
37#define BGRAB0(__usi__) (((uint8_t *)&(__usi__))[0])
38#define BGRAB1(__usi__) (((uint8_t *)&(__usi__))[1])
39#define BGRAB2(__usi__) (((uint8_t *)&(__usi__))[2])
40#define BGRAB3(__usi__) (((uint8_t *)&(__usi__))[3])
41#define BGRAB4(__usi__) (((uint8_t *)&(__usi__))[4])
42#define BGRAB5(__usi__) (((uint8_t *)&(__usi__))[5])
43#define BGRAB6(__usi__) (((uint8_t *)&(__usi__))[6])
44#define BGRAB7(__usi__) (((uint8_t *)&(__usi__))[7])
45#else
46// Note: The cast alone to uint8_t is actually enough.
47// GCC throws out the "& 0xff", and the size is no different.
48// Some compilers need it.
49#define BGRAB0(__usi__) ((uint8_t)((__usi__) & 0xff ))
50#define BGRAB1(__usi__) ((uint8_t)(((__usi__) >> 8) & 0xff))
51#define BGRAB2(__usi__) ((uint8_t)(((__usi__) >> 16) & 0xff))
52#define BGRAB3(__usi__) ((uint8_t)(((__usi__) >> 24) & 0xff))
53#define BGRAB4(__usi__) ((uint8_t)(((__usi__) >> 32) & 0xff))
54#define BGRAB5(__usi__) ((uint8_t)(((__usi__) >> 40) & 0xff))
55#define BGRAB6(__usi__) ((uint8_t)(((__usi__) >> 48) & 0xff))
56#define BGRAB7(__usi__) ((uint8_t)(((__usi__) >> 56) & 0xff))
57#endif
58#define BOVER1(__usi__) ((uint16_t)(__usi__) << 8)
59#define BOVER2(__usi__) ((uint32_t)(__usi__) << 16)
60#define BOVER3(__usi__) ((uint32_t)(__usi__) << 24)
61#define BOVER4(__usi__) ((uint64_t)(__usi__) << 32)
62#define BOVER5(__usi__) ((uint64_t)(__usi__) << 40)
63#define BOVER6(__usi__) ((uint64_t)(__usi__) << 48)
64#define BOVER7(__usi__) ((uint64_t)(__usi__) << 56)
65
66// These are the smallest and fastest ways I have found so far in pure C/C++.
67#define BMAKE16(__usc1__,__usc0__) ((uint16_t)((uint16_t)(__usc0__) | (uint16_t)BOVER1(__usc1__)))
68#define BMAKE32(__usc3__,__usc2__,__usc1__,__usc0__) ((uint32_t)((uint32_t)(__usc0__) | (uint32_t)BOVER1(__usc1__) | (uint32_t)BOVER2(__usc2__) | (uint32_t)BOVER3(__usc3__)))
69#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__)))
70#endif
71
72/*
73 * Debug macros: Strings are stored in progmem (flash) instead of RAM.
74 */
75#define USBTRACE(s) (Notify(PSTR(s), 0x80))
76#define USBTRACE1(s,l) (Notify(PSTR(s), l))
77#define USBTRACE2(s,r) (Notify(PSTR(s), 0x80), D_PrintHex((r), 0x80), Notify(PSTR("\r\n"), 0x80))
78#define USBTRACE3(s,r,l) (Notify(PSTR(s), l), D_PrintHex((r), l), Notify(PSTR("\r\n"), l))
79
80
81#endif /* MACROS_H */
82