]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blob - fx2lib/fw/device.c
Import fx2lib into fx2lafw directly.
[sigrok-firmware-fx2lafw.git] / fx2lib / fw / device.c
1 /**
2  * Copyright (C) 2009 Ubixum, Inc. 
3  *
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.
8  *
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.
13  *
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  **/
18
19 #include <fx2macros.h>
20
21 #ifdef DEBUG_FIRMWARE
22 #include <stdio.h>
23 #else
24 #define printf(...)
25 #endif
26
27 //************************** Configuration Handlers *****************************
28
29 // change to support as many interfaces as you need
30 //volatile xdata BYTE interface=0;
31 //volatile xdata BYTE alt=0; // alt interface
32
33 // set *alt_ifc to the current alt interface for ifc
34 BOOL handle_get_interface(BYTE ifc, BYTE* alt_ifc) {
35 // *alt_ifc=alt;
36  return TRUE;
37 }
38 // return TRUE if you set the interface requested
39 // NOTE this function should reconfigure and reset the endpoints
40 // according to the interface descriptors you provided.
41 BOOL handle_set_interface(BYTE ifc,BYTE alt_ifc) {  
42  printf ( "Set Interface.\n" );
43  //interface=ifc;
44  //alt=alt_ifc;
45  return TRUE;
46 }
47
48 // handle getting and setting the configuration
49 // 1 is the default.  If you support more than one config
50 // keep track of the config number and return the correct number
51 // config numbers are set int the dscr file.
52 //volatile BYTE config=1;
53 BYTE handle_get_configuration() { 
54  return 1;
55 }
56
57 // NOTE changing config requires the device to reset all the endpoints
58 BOOL handle_set_configuration(BYTE cfg) { 
59  printf ( "Set Configuration.\n" );
60  //config=cfg;
61  return TRUE;
62 }
63
64
65 //******************* VENDOR COMMAND HANDLERS **************************
66
67
68 BOOL handle_vendorcommand(BYTE cmd) {
69  // your custom vendor handler code here..
70  return FALSE; // not handled by handlers
71 }
72
73
74 //********************  INIT ***********************
75
76 void main_init() {
77
78  REVCTL=3;
79  SETIF48MHZ();
80
81  // set IFCONFIG
82  // config your endpoints etc.
83  // config gpif
84  
85  printf ( "Initialization Done.\n" );
86
87 }
88
89
90 void main_loop() {
91  // do some work
92 }
93
94