Addition USB jump table macros.
[fx2lib.git] / include / fx2macros.h
blob8f114f28cefa5d007c9c1fbe648754c33d83af29
1 /**
2 * Copyright (C) 2008 Ubixum, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 **/
19 #ifndef FX2MACROS_H
20 #define FX2MACROS_H
22 #include "fx2regs.h"
23 #include "fx2types.h"
25 #define MSB(addr) (BYTE)((addr >> 8) & 0xff)
26 #define LSB(addr) (BYTE)(addr & 0xff)
27 #define MAKEWORD(msb,lsb) (((WORD)msb << 8) | lsb)
29 #define MSW(dword) (WORD)((dword >> 16) & 0xffff)
30 #define LSW(dword) (WORD)(dword & 0xffff)
31 #define MAKEDWORD(msw,lsw) (((DWORD)msw << 16) | lsw)
33 // clock stuff
35 typedef enum { CLK_12M =0, CLK_24M, CLK_48M} CLK_SPD;
36 #define CPUFREQ (CLK_SPD)((CPUCS & bmCLKSPD) >> 3)
37 #define SETCPUFREQ(SPD) CPUCS = (CPUCS & ~bmCLKSPD) | (SPD << 3)
39 #define XTAL (CPUFREQ==CLK_12M ? 12000000L :\
40 CPUFREQ==CLK_24M ? 24000000L : 48000000L)
43 // i2c stuff
44 #define I2CFREQ ((I2CTL & bm400KHZ) ? 400000L : 100000L)
47 // endpoints
48 #define IFFREQ (IFCONFIG & bm3048MHZ ? 48000000L : 30000000L)
49 #define SETIF30MHZ() IFCONFIG &= ~bm3048MHZ
50 #define SETIF48MHZ() IFCONFIG |= bm3048MHZ
53 // eeprom stuff
54 #define EEPROM_TWO_BYTE (I2CS & bmBIT4)
57 #endif