├── help.png ├── libusb-1.0.so ├── src ├── helios.cpp ├── sdk │ ├── .DS_Store │ ├── OpenLaserShowController.def │ ├── HeliosDacAPI.h │ ├── HeliosDac.h │ ├── HeliosDacAPI.cpp │ ├── OpenLaserShowControllerV1.0.0-Mod.h │ ├── HeliosDac.cpp │ └── libusb.h ├── pd-lib-builder │ ├── CHANGELOG.txt │ ├── README.md │ ├── tips-tricks.md │ └── Makefile.pdlibbuilder ├── pd_helios.cpp └── pd_helios.h ├── libusb-1.0.0.dylib ├── .gitignore ├── Makefile ├── red_square.pd ├── helios_point_rotation.pd ├── README.md ├── help-helios.pd └── LICENSE /help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timredfern/pd_helios/HEAD/help.png -------------------------------------------------------------------------------- /libusb-1.0.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timredfern/pd_helios/HEAD/libusb-1.0.so -------------------------------------------------------------------------------- /src/helios.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timredfern/pd_helios/HEAD/src/helios.cpp -------------------------------------------------------------------------------- /libusb-1.0.0.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timredfern/pd_helios/HEAD/libusb-1.0.0.dylib -------------------------------------------------------------------------------- /src/sdk/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timredfern/pd_helios/HEAD/src/sdk/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /src/sdk/OpenLaserShowController.def: -------------------------------------------------------------------------------- 1 | LIBRARY HeliosLaserDAC 2 | EXPORTS 3 | OLSC_GetAPIVersion 4 | OLSC_GetDeviceCapabilities 5 | OLSC_GetDeviceCount 6 | OLSC_GetInterfaceName 7 | OLSC_GetLastErrorNumber 8 | OLSC_GetStatus 9 | OLSC_Initialize 10 | OLSC_Pause 11 | OLSC_Play 12 | OLSC_ReadDMX 13 | OLSC_ReadTTL 14 | OLSC_SetCallback 15 | OLSC_Shutdown 16 | OLSC_Shutter 17 | OLSC_WriteDMX 18 | OLSC_WriteFrame 19 | OLSC_WriteFrameEx 20 | OLSC_WriteTTL 21 | EzAudDacWriteFrame 22 | EzAudDacWriteFrameNR 23 | EzAudDacGetCardNum 24 | EzAudDacGetStatus 25 | EzAudDacClose 26 | EzAudDacStop -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile to build class 'helios' for Pure Data. 2 | 3 | lib.name = helios 4 | 5 | helios.class.sources = src/sdk/HeliosDac.cpp src/pd_helios.cpp src/helios.cpp 6 | 7 | uname := $(shell uname) 8 | 9 | ifeq ($(findstring $(uname), Linux GNU GNU/kFreeBSD), $(uname)) 10 | system = Linux 11 | endif 12 | 13 | ifeq ($(uname), Darwin) 14 | system = Darwin 15 | endif 16 | 17 | ifeq ($(filter MINGW% MSYS%, $(uname)), $(uname)) 18 | system = Windows 19 | endif 20 | 21 | ifeq ($(system), Darwin) 22 | ldlibs = libusb-1.0.0.dylib 23 | else 24 | ldlibs = -lusb-1.0 25 | endif 26 | 27 | ldflags = -Wl,-rpath,./ 28 | 29 | include src/pd-lib-builder/Makefile.pdlibbuilder 30 | -------------------------------------------------------------------------------- /red_square.pd: -------------------------------------------------------------------------------- 1 | #N canvas 550 549 556 434 10; 2 | #X msg 140 143 -100 100 255 0 0; 3 | #X obj 17 172 helios_point_rotation; 4 | #X obj 16 268 list append; 5 | #X obj 255 141 helios_point_rotation; 6 | #X msg 376 107 100 100 255 0 0; 7 | #X obj 52 210 helios_point_rotation; 8 | #X obj 248 210 helios_point_rotation; 9 | #X obj 15 318 list append; 10 | #X obj 102 267 list append; 11 | #X obj 141 11 loadbang; 12 | #X text 16 420 A red square that can be rotated; 13 | #X obj 17 12 inlet; 14 | #X msg 319 286 -100 100 255 0 0; 15 | #X obj 195 319 helios_point_rotation; 16 | #X obj 17 64 trigger f f f f f; 17 | #X obj 142 64 trigger b b b b b; 18 | #X msg 176 177 100 -100 255 0 0; 19 | #X msg 371 178 -100 -100 255 0 0; 20 | #X obj 15 356 list append; 21 | #X obj 15 389 outlet; 22 | #X connect 0 0 1 1; 23 | #X connect 1 0 2 0; 24 | #X connect 2 0 7 0; 25 | #X connect 3 0 2 1; 26 | #X connect 4 0 3 1; 27 | #X connect 5 0 8 0; 28 | #X connect 6 0 8 1; 29 | #X connect 7 0 18 0; 30 | #X connect 8 0 7 1; 31 | #X connect 9 0 15 0; 32 | #X connect 11 0 14 0; 33 | #X connect 12 0 13 1; 34 | #X connect 13 0 18 1; 35 | #X connect 14 0 1 0; 36 | #X connect 14 1 3 0; 37 | #X connect 14 2 5 0; 38 | #X connect 14 3 6 0; 39 | #X connect 14 4 13 0; 40 | #X connect 15 0 0 0; 41 | #X connect 15 1 4 0; 42 | #X connect 15 2 16 0; 43 | #X connect 15 3 17 0; 44 | #X connect 15 4 12 0; 45 | #X connect 16 0 5 1; 46 | #X connect 17 0 6 1; 47 | #X connect 18 0 19 0; 48 | -------------------------------------------------------------------------------- /helios_point_rotation.pd: -------------------------------------------------------------------------------- 1 | #N canvas 919 451 401 419 10; 2 | #X obj 16 13 inlet; 3 | #X obj 62 159 sin 0; 4 | #X obj 16 158 cos 0; 5 | #X obj 15 208 *; 6 | #X obj 51 208 *; 7 | #X obj 97 96 unpack f f f f f; 8 | #X obj 15 275 pack f f f f f; 9 | #X obj 86 210 *, f 1; 10 | #X obj 120 210 *; 11 | #X obj 46 243 +; 12 | #X obj 15 241 -; 13 | #X obj 16 54 * 0.0174533; 14 | #X obj 109 15 inlet; 15 | #X obj 15 319 outlet; 16 | #X floatatom 16 93 5 0 0 0 - - -, f 5; 17 | #X obj 109 54 trigger bang list; 18 | #X obj 158 160 sin 0; 19 | #X obj 112 159 cos 0; 20 | #X obj 16 123 trigger f f f f; 21 | #X text 15 388 sending a number (in degrees) to the left inlet will 22 | rotate the point about the origin; 23 | #X text 15 347 send a single helios point (a list of 5 numbers) to 24 | the right inlet- it will be copied to the outlet; 25 | #X connect 0 0 11 0; 26 | #X connect 1 0 4 0; 27 | #X connect 2 0 3 0; 28 | #X connect 3 0 10 0; 29 | #X connect 4 0 9 0; 30 | #X connect 5 0 3 1; 31 | #X connect 5 0 4 1; 32 | #X connect 5 1 8 1; 33 | #X connect 5 1 7 1; 34 | #X connect 5 2 6 2; 35 | #X connect 5 3 6 3; 36 | #X connect 5 4 6 4; 37 | #X connect 6 0 13 0; 38 | #X connect 7 0 9 1; 39 | #X connect 8 0 10 1; 40 | #X connect 9 0 6 1; 41 | #X connect 10 0 6 0; 42 | #X connect 11 0 14 0; 43 | #X connect 12 0 15 0; 44 | #X connect 14 0 18 0; 45 | #X connect 15 0 14 0; 46 | #X connect 15 1 5 0; 47 | #X connect 16 0 8 0; 48 | #X connect 17 0 7 0; 49 | #X connect 18 0 2 0; 50 | #X connect 18 1 16 0; 51 | #X connect 18 2 1 0; 52 | #X connect 18 3 17 0; 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pd_helios 2 | Pure data external for the Helios Laser DAC 3 | 4 | * https://github.com/Grix/helios_dac 5 | * https://github.com/pure-data/pure-data 6 | 7 | ![help-helios.pd](help.png) 8 | 9 | ## Version 10 | 11 | 0.1 12 | 13 | note - it's not presently possible to have more than 1 helios object open. 14 | 15 | ## Use 16 | 17 | pd_helios currently builds on MacOS, tested on Mojave (OSX v10.14). It builds on Ubuntu 16.04 x64 but I haven't got it to work - using a VM, don't know if this is the issue. It should work on Microsoft Windows with the appropriate libusb library. 18 | 19 | ## To build 20 | 21 | Clone this repo and the source code to pure data 22 | 23 | ``` 24 | git clone git@github.com:timredfern/pd_helios.git 25 | git clone https://github.com/pure-data/pure-data 26 | cd pd_helios 27 | make PDINCLUDEDIR=../pure-data/src/ 28 | ``` 29 | 30 | (or wherever you cloned pure data) 31 | 32 | To test the example patch: 33 | 34 | ``` 35 | pd help-helios.pd 36 | ``` 37 | 38 | (from wherever you have installed Pd. For the Purr-data distribution of Pd, I used this:) 39 | 40 | ``` 41 | /Applications/Pd-l2ork.app/Contents/MacOS/nwjs help-helios.pd 42 | ``` 43 | 44 | ## Problems with old versions of MacOS (specifically EL Capitan) 45 | 46 | Install libusb from Homebrew 47 | 48 | First follow these instructions: https://brew.sh/ 49 | 50 | Then: 51 | 52 | ``` 53 | brew install libusb 54 | 55 | ``` 56 | 57 | ## Copyright 58 | 59 | Except as otherwise noted, all files in the this distribution are 60 | 61 | #### Copyright © 2019 Tim Redfern 62 | 63 | For information on usage and redistribution, and for a DISCLAIMER OF ALL 64 | WARRANTIES, see LICENSE included in this distribution. 65 | (Note that Helios SDK and libusb are copyrighted separately). 66 | 67 | ## NOTE 68 | 69 | Lasers are dangerous. Improper use of this software can damage your laser, or yourself. This software comes with NO WARRANTY, see above. 70 | 71 | ## Acknowledgements 72 | 73 | Thanks to NULL + VOID 74 | -------------------------------------------------------------------------------- /help-helios.pd: -------------------------------------------------------------------------------- 1 | #N canvas 221 633 568 294 10; 2 | #X obj 28 24 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1 3 | ; 4 | #X obj 55 104 red_square; 5 | #X floatatom 55 77 5 0 0 0 - - -, f 5; 6 | #X floatatom 25 247 5 0 0 0 - - -, f 5; 7 | #X obj 55 50 loadbang; 8 | #X obj 25 217 helios 20000; 9 | #X msg 70 160 intensity \$1; 10 | #X floatatom 70 132 5 0 0 0 - - -, f 5; 11 | #N canvas 921 539 532 304 settings 0; 12 | #X obj 18 291 s settings; 13 | #X floatatom 49 163 5 0 0 0 - - -, f 5; 14 | #X text 101 163 <---------; 15 | #X floatatom 38 90 5 0 0 0 - - -, f 5; 16 | #X text 101 90 <---------; 17 | #X floatatom 21 21 5 0 0 0 - - -, f 5; 18 | #X text 101 21 <---------; 19 | #X msg 21 49 maxangle \$1; 20 | #X text 172 21 set the max angle for a corner before inserting points 21 | - default 15 degrees; 22 | #X msg 38 118 subdivide \$1; 23 | #X text 172 90 set the subdivision length for straight lines - default 24 | 15; 25 | #X msg 49 191 blanknum \$1; 26 | #X text 172 163 set the number of dwell points to insert at corners 27 | - default 8; 28 | #X text 150 240 pd_helios processes drawing shapes and adds extra points 29 | for the laser to be able to keep within it's mechanical limits. Generally 30 | \, increasing these makes better drawings \, but slows the laser down. 31 | If you reduce them to the point the laser makes a noise \, you're doing 32 | it wrong :-); 33 | #X connect 1 0 11 0; 34 | #X connect 3 0 9 0; 35 | #X connect 5 0 7 0; 36 | #X connect 7 0 0 0; 37 | #X connect 9 0 0 0; 38 | #X connect 11 0 0 0; 39 | #X restore 470 22 pd settings; 40 | #X obj 111 189 r settings; 41 | #X text 181 211 [optional] initialise helios with points per second 42 | for your laser - max 40k; 43 | #X text 110 217 <---------; 44 | #X text 109 246 <---------; 45 | #X text 181 248 helios prints the number of points output \, negative 46 | number for an error; 47 | #X text 183 132 set the intensity [output power] from 0 to 255; 48 | #X text 112 132 <---------; 49 | #X text 111 78 <---------; 50 | #X text 182 78 turn the red square!; 51 | #X text 111 26 <---------; 52 | #X text 182 26 activate the laser; 53 | #X text 23 277 pd_helios v0.2; 54 | #X connect 0 0 5 0; 55 | #X connect 1 0 5 0; 56 | #X connect 2 0 1 0; 57 | #X connect 4 0 2 0; 58 | #X connect 5 0 3 0; 59 | #X connect 6 0 5 0; 60 | #X connect 7 0 6 0; 61 | #X connect 9 0 5 0; 62 | -------------------------------------------------------------------------------- /src/pd-lib-builder/CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | Changelog for Makefile.pdlibbuilder. 2 | 3 | v0.5.1, dated 2018-03-15 4 | Fixes and improvements for Windows builds: 5 | - properly evaluate variables 'PDDIR' and 'PDBINDIR' to find pd.dll 6 | - define default path of 32 bit Pd on 64 bit Windows 7 | - link C++ externals with standard C libs on Windows, they don't load otherwise 8 | - strip installed Windows binaries by default 9 | (issues #34, #39, #41, #42 respectively) 10 | Warning for all platforms: variable 'PD_PATH' is no longer supported, use the 11 | equivalent 'PDDIR'. 12 | 13 | v0.5.0, dated 2018-01-23 14 | Implement target architecture detection for Windows builds, 15 | and set appropriate options for 32 and 64 bit (used to be for 32 bit only). 16 | (feature, issue #37 #38, merge commit 215bf3e) 17 | 18 | v0.4.4, dated 2016-11-22 19 | Use variable 'system' when evaluating 'for{Linux,Darwin,Windows}' 20 | (bugfix, issue #31, commit 2c14110) 21 | 22 | v0.4.3, dated 2016-11-02 23 | Replace flags '-fpic' by 'fPIC'. 24 | (bugfix, issue #29, commit 426b38b) 25 | 26 | v0.4.2, dated 2016-10-30 27 | Fix issue where incorrect message about m_pd.h is given. 28 | (bugfix, commit 2e13d8f) 29 | 30 | v0.4.1, dated 2016-10-27 31 | Respect cflag for minimum OSX version when defined by lib makefile. 32 | (bugfix, pull request #22, commit 48c4127) 33 | 34 | v0.4.0, dated 2016-10-14 35 | Introduced path variables PDDIR, PDINCLUDEDIR, PDBINDIR, PDLIBDIR which can 36 | also be defined in environment. 37 | (feature, issue #27, commit b0dab72) 38 | 39 | v0.3.1, dated 2016-10-13 40 | Fix bug where pd.dll wouldn't be found. 41 | (bugfix, commit a0c87be) 42 | 43 | v0.3.0, dated 2016-10-09 44 | Variable 'PD_PATH' introduced for pd-extended / pd-l2ork compatibility. 45 | (feature, issue #26, commit 41e9743) 46 | 47 | v0.2.8, dated 2016-10-09 48 | Allow installed files to contain weird characters (notably '$'). 49 | (bugfix, pull request #20, commit 5b920b1) 50 | 51 | v0.2.7, dated 2016-10-04 52 | Remove all default pd search paths except vanilla's. 53 | (discussion, issue #25, commit a6a89dc) 54 | 55 | v0.2.6, dated 2016-09-20 56 | Redefined dependency checking so it won't stall rebuilds on OSX. 57 | (bugfix, issue #16, commit 9fd1795) 58 | 59 | v0.2.5, dated 2016-06-26 60 | Fixed dependency checking for object files in other directories. 61 | (bugfix, commit f06e550) 62 | 63 | v0.2.4, dated 2016-06-25 64 | Fixed regression bug that disabled all dependency checking. 65 | (bugfix, commit 1d7bb5e) 66 | 67 | v0.2.3, dated 2016-03-29 68 | Disabled dependency checking for OSX <= 10.5 because it stalled rebuilds. 69 | (bugfix, issue #16, commit eb614fd) 70 | 71 | v0.2.2, dated 2016-03-28 72 | Removed target 'pre' because it forced rebuild of everything in 'all'. 73 | (bugfix, issue #17, commit c989c8e) 74 | 75 | v0.2.1, dated 2015-12-27 76 | Implement / respect 'CPPFLAGS','CFLAGS'and 'LDFLAGS'. 77 | (bugfix, issue #5, commit 98f3582) 78 | 79 | v0.2.0, dated 2015-12-19 80 | Added per-platform multiline defines 'forLinux', 'forDarwin', 'forWindows'. 81 | (feature, pull request #9, commit 3946ea5) 82 | 83 | v0.1.0, dated 2015-12-08 84 | Added targets 'pre' and 'post' to automatically run before and after 'all'. 85 | (feature, pull request #4, commit a5678ac) 86 | 87 | v0.0.2, dated 2015-12-06 88 | Improved methods for searching pd paths. 89 | (bugfix, commit ed37e6b) 90 | 91 | v0.0.1, dated 2015-10-31 92 | Fixed expansion of variable 'lib.version'. 93 | (bugfix, issue #1, commit 974b617) 94 | 95 | v0.0.0, dated 2015-06-24 96 | Initial version. 97 | (commit 16517a2) 98 | -------------------------------------------------------------------------------- /src/pd-lib-builder/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### Makefile.pdlibbuilder ### 4 | 5 | Helper makefile for Pure Data external libraries. 6 | Written by Katja Vetter March-June 2015 for the public domain. No warranties. 7 | Inspired by Hans Christoph Steiner's Makefile Template and Stephan Beal's 8 | ShakeNMake. 9 | 10 | GNU make version >= 3.81 required. 11 | 12 | 13 | ### characteristics ### 14 | 15 | 16 | * defines build settings based on autodetected OS and architecture 17 | * defines rules to build Pd class- or lib executables from C or C++ sources 18 | * defines rules for libdir installation 19 | * defines convenience targets for developer and user 20 | * evaluates implicit dependencies for non-clean builds 21 | 22 | 23 | ### basic usage ### 24 | 25 | 26 | In your Makefile, define your Pd lib name and class files, and include 27 | Makefile.pdlibbuilder at the end of the Makefile. Like so: 28 | 29 | 30 | # Makefile for mylib 31 | 32 | lib.name = mylib 33 | 34 | class.sources = myclass1.c myclass2.c 35 | 36 | datafiles = myclass1-help.pd myclass2-help.pd README.txt LICENSE.txt 37 | 38 | include Makefile.pdlibbuilder 39 | 40 | 41 | For files in class.sources it is assumed that class name == source file 42 | basename. The default target builds all classes as individual executables 43 | with Pd's default extension for the platform. For anything more than the 44 | most basic usage, read the documentation sections in Makefile.pdlibbuilder. 45 | 46 | 47 | ### paths ### 48 | 49 | 50 | Makefile.pdlibbuilder >= v0.4.0 supports pd path variables which can be 51 | defined not only as make command argument but also in the environment, to 52 | override platform-dependent defaults: 53 | 54 | PDDIR: 55 | Root directory of 'portable' pd package. When defined, PDINCLUDEDIR and 56 | PDBINDIR will be evaluated as $(PDDIR)/src and $(PDDIR)/bin. 57 | 58 | PDINCLUDEDIR: 59 | Directory where Pd API m_pd.h should be found, and other Pd header files. 60 | Overrides the default search path. 61 | 62 | PDBINDIR: 63 | Directory where pd.dll should be found for linking (Windows only). Overrides 64 | the default search path. 65 | 66 | PDLIBDIR: 67 | Root directory for installation of Pd library directories. Overrides the 68 | default install location. 69 | 70 | 71 | ### documentation ### 72 | 73 | 74 | This README.md provides only basic information. A large comment section inside 75 | Makefile.pdlibbuilder lists and explains the available user variables, default 76 | paths, and targets. The internal documentation reflects the exact functionality 77 | of the particular version. A tips&tricks page is in the works. 78 | 79 | 80 | ### versioning ### 81 | 82 | 83 | The project is versioned in MAJOR.MINOR.BUGFIX format (see http://semver.org), 84 | and maintained at https://github.com/pure-data/pd-lib-builder. Pd lib developers 85 | are invited to regulary check for updates, and to contribute and discuss 86 | improvements here. If you really need to distribute a personalized version with 87 | your library, rename Makefile.pdlibbuilder to avoid confusion. 88 | 89 | 90 | ### examples ### 91 | 92 | 93 | Here are a few projects using the Makefile.pdlibbuilder approach: 94 | 95 | https://github.com/pure-data/helloworld 96 | 97 | https://github.com/electrickery/pd-cyclone (stable) 98 | 99 | https://github.com/porres/pd-cyclone (experimental) 100 | 101 | https://git.iem.at/pd/iemguts 102 | 103 | https://git.iem.at/pd/iemnet 104 | 105 | https://git.iem.at/pd/iem_ambi 106 | 107 | https://git.iem.at/pd/mediasettings 108 | 109 | https://git.iem.at/pd-gui/punish 110 | 111 | https://github.com/residuum/PuRestJson 112 | 113 | More examples will be referenced here when they are available. 114 | -------------------------------------------------------------------------------- /src/pd_helios.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * pd_helios 3 | * © 2019 Tim Redfern 4 | * licenced under the LGPL v3.0 5 | * see LICENSE 6 | */ 7 | 8 | #include "pd_helios.h" 9 | 10 | #define _USE_MATH_DEFINES 11 | 12 | #include 13 | 14 | #define RAD_2_DEG 180.0 / M_PI 15 | 16 | using namespace std; 17 | 18 | static float getLineDegreesAtIndex(vector &line,int i){ 19 | //return angle between this point and the next 20 | if ((i<1)||(i>(line.size()-2))){ 21 | return 0.0f; 22 | } 23 | //https://stackoverflow.com/questions/14066933/direct-way-of-computing-clockwise-angle-between-2-vectors 24 | 25 | // dot product between [x1, y1] and [x2, y2] 26 | // dot = x1*x2 + y1*y2 27 | 28 | float dot = ((line[i].x-line[i-1].x)*(line[i+1].x-line[i].x)) + 29 | ((line[i].y-line[i-1].y)*(line[i+1].y-line[i].y)); 30 | 31 | // determinant det = x1*y2 - y1*x2 32 | 33 | float det = ((line[i].x-line[i-1].x)*(line[i+1].y-line[i].y)) + 34 | ((line[i].y-line[i-1].y)*(line[i+1].x-line[i].x)); 35 | 36 | return atan2(det, dot)* RAD_2_DEG; // atan2(y, x) or atan2(sin, cos) 37 | } 38 | 39 | int Helios::draw(std::vector &points){ 40 | line=points; 41 | return draw(); 42 | } 43 | 44 | int Helios::draw(){ 45 | 46 | int xoffs=output_centre.x; 47 | int yoffs=output_centre.y; 48 | 49 | //save data 50 | vector points; 51 | 52 | //insert blank points to get laser to shape starting point 53 | for (int l=0;lmax_angle?((angle/180)*blank_num):0)<<" dwell points"<max_angle) { 80 | num_dwellpoints=((angle/180)*blank_num); 81 | } 82 | 83 | for (int l=0;l 20 | #include 21 | 22 | //class that resembles a HeliosPoint but with floats for coords 23 | class point { 24 | public: 25 | point(){ 26 | x=y=0; 27 | r=g=b=0; 28 | } 29 | point(float _x, float _y){ 30 | x=_x; 31 | y=_y; 32 | } 33 | point(int _x, int _y){ 34 | x=_x; 35 | y=_y; 36 | } 37 | point(float _x, float _y,uint8_t _r,uint8_t _g,uint8_t _b){ 38 | x=_x; 39 | y=_y; 40 | r=_r; 41 | g=_g; 42 | b=_b; 43 | } 44 | point(const point &p){ 45 | x=p.x; 46 | y=p.y; 47 | r=p.r; 48 | g=p.g; 49 | b=p.b; 50 | } 51 | point operator+ (const point& p){ 52 | point np(x+p.x,y+p.y); 53 | return np; 54 | } 55 | point& operator+= (const point& p){ 56 | x+=p.x; 57 | y+=p.y; 58 | return *this; 59 | } 60 | bool operator!=( const point& p){ 61 | return x==p.x&&y==p.y; 62 | } 63 | float distance(const point& p){ 64 | return pow((pow(p.x-x,2)+pow(p.y-y,2)),0.5); 65 | } 66 | float x,y; 67 | std::uint8_t r,g,b; 68 | }; 69 | 70 | class Helios 71 | { 72 | public: 73 | 74 | Helios(int _pps=20000,int _intensity=255,int _device = 0,int _subdivide=DEFAULT_SUBDIVIDE,int _blank_num=DEFAULT_BLANK_NUM,int _max_angle=DEFAULT_MAX_ANGLE,bool _enabled=false) 75 | { 76 | std::cout << "Helios v "<=numdevices){ 87 | std::cout << ": could not open device "<<_device<-1&&i<256&&i!=intensity){ 123 | intensity=i; 124 | //std::cout << "Helios v "<0&&i<256&&i!=subdivide){ 129 | subdivide=i; 130 | //std::cout << "Helios v "<-1&&i<256&&i!=blank_num){ 135 | blank_num=i; 136 | //std::cout << "Helios v "<=0.0f&&f<90.0f&&f!=max_angle){ 141 | max_angle=f; 142 | //std::cout << "Helios v "< &points); 163 | 164 | //repeat previous drawing (intensity is re-calculated) 165 | int draw(); 166 | 167 | private: 168 | 169 | int device; 170 | HeliosDac dac; 171 | int pps; 172 | int intensity; 173 | 174 | bool enabled; 175 | 176 | int subdivide,blank_num; 177 | float max_angle; 178 | 179 | point output_centre; 180 | 181 | std::vector line; 182 | 183 | }; 184 | 185 | #endif //Helios_h -------------------------------------------------------------------------------- /src/sdk/HeliosDacAPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | Helios Laser DAC SDK shared library, HEADER 3 | By Gitle Mikkelsen 4 | gitlem@gmail.com 5 | 6 | Dependencies: 7 | Libusb 1.0 (GNU Lesser General Public License, see libusb.h) 8 | HeliosDAC class 9 | OpenLaserShowControllerV1.0.0 header and .def file (only on windows) 10 | 11 | Standard: C++14 12 | 13 | BASIC USAGE: 14 | 1. Call OpenDevices() or OLSC_Initialize() to open devices, returns number of available devices 15 | 2. To send a new frame, first call GetStatus() or OLSC_GetStatus(). If the function returns ready 16 | (1 for GetStatus, OLSC_STATUS_BUFFER_EMPTY for OLSC_GetStatus), then you can call WriteFrame() 17 | or OLSC_WriteFrame() / OLSC_WriteFrameEx(). 18 | The status should be polled until it returns ready. It can and sometimes will fail to return ready on the first try. 19 | 3. To stop output, use Stop() or OLSC_Pause(). To restart output you must send a new frame as described above. 20 | 4. When the DAC is no longer needed, free it using CloseDevices() or OLSC_Shutdown() 21 | See OpenLaserShowControllerV1.0.0-Mod.h for documentation on OLSC_* functions. Not recommended for cross-platform apps 22 | 23 | The DAC is double-buffered. When it receives its first frame, it starts outputting it. When a second frame is sent to 24 | the DAC while the first frame is being played, the second frame is stored in the DACs memory until the first frame 25 | finishes playback, at which point the second, buffered frame will start playing. If the DAC finished playback of a frame 26 | without having received and buffered a second frame, it will by default loop the first frame until a new frame is 27 | received (but the flag HELIOS_FLAG_SINGLE_MODE will make it stop playback instead). 28 | The GetStatus() function actually checks whether or not the buffer on the DAC is empty or full. If it is full, the DAC 29 | cannot receive a new frame until the currently playing frame finishes, freeing up the buffer. 30 | */ 31 | 32 | #pragma once 33 | 34 | #include "HeliosDac.h" 35 | 36 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) 37 | #include "OpenLaserShowControllerV1.0.0-Mod.h" 38 | #define HELIOS_EXPORT extern "C" __declspec (dllexport) 39 | #else 40 | #define HELIOS_EXPORT extern "C" 41 | #endif 42 | 43 | #define STDCALL __stdcall 44 | 45 | bool inited = false; 46 | bool flipX = true; 47 | 48 | HeliosDac* dacController; 49 | 50 | //initializes drivers, opens connection to all devices. 51 | //Returns number of available devices. 52 | //NB: To re-scan for newly connected DACs after this function has once been called before, you must first call CloseDevices() 53 | HELIOS_EXPORT int OpenDevices(); 54 | 55 | //Gets status from the specified dac. 56 | //Return 1 if ready to receive new frame, 0 if not, -1 if communcation failed 57 | HELIOS_EXPORT int GetStatus(unsigned int dacNum); 58 | 59 | //Sets libusb debug log level 60 | //See libusb.h for log level values 61 | HELIOS_EXPORT int SetLibusbDebugLogLevel(int logLevel); 62 | 63 | //writes and outputs a frame to the speficied dac 64 | //dacNum: dac number (0 to n where n+1 is the return value from OpenDevices() ) 65 | //pps: rate of output in points per second 66 | //flags: (default is 0) 67 | // Bit 0 (LSB) = if true, start output immediately, instead of waiting for current frame (if there is one) to finish playing 68 | // Bit 1 = if true, play frame only once, instead of repeating until another frame is written 69 | // Bit 2-7 = reserved 70 | //points: pointer to point data. See point structure documentation in HeliosDac.h 71 | //numOfPoints: number of points in the frame 72 | //returns 1 if successful 73 | HELIOS_EXPORT int WriteFrame(unsigned int dacNum, int pps, std::uint8_t flags, HeliosPoint* points, int numOfPoints); 74 | 75 | //sets the shutter of the specified dac. 76 | //value 1 = shutter open, value 0 = shutter closed 77 | //returns 1 if successful 78 | HELIOS_EXPORT int SetShutter(unsigned int dacNum, bool shutterValue); 79 | 80 | //Returns the firmware version number. Returns -1 if communcation failed. 81 | HELIOS_EXPORT int GetFirmwareVersion(unsigned int dacNum); 82 | 83 | //gets a descriptive name of the specified dac 84 | //name is max 32 bytes long, char needs to be able to hold 32 bytes 85 | //returns 1 if successful, return 0 if the proper name couldn't be fetched from the DAC, but name is 86 | //still populated with a fallback numbered name based on order of discovery by the library 87 | //return -1 if unsuccessful and name is not populated. 88 | HELIOS_EXPORT int GetName(unsigned int dacNum, char* name); 89 | 90 | //gets a descriptive name of the specified dac 91 | //name is max 31 bytes long including null terminator 92 | //returns 1 if successful, return 0 if the transfer failed 93 | HELIOS_EXPORT int SetName(unsigned int dacNum, char* name); 94 | 95 | //stops, blanks and centers output on the specified dac 96 | //returns 1 if successful 97 | HELIOS_EXPORT int Stop(unsigned int dacNum); 98 | 99 | //closes connection to all dacs and frees resources 100 | //should be called when library is no longer needed (program exit for example) 101 | HELIOS_EXPORT int CloseDevices(); 102 | 103 | //Clears the GPNVM1 bit on the DACs microcontroller. This will cause the DAC to boot into SAM-BA bootloader 104 | //which allows new firmware to be uploaded over USB. 105 | HELIOS_EXPORT int EraseFirmware(unsigned int dacNum); 106 | 107 | 108 | /* EzAudDac API */ 109 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) 110 | 111 | struct EAD_Pnt_s { 112 | int16_t X; 113 | int16_t Y; 114 | int16_t R; 115 | int16_t G; 116 | int16_t B; 117 | int16_t I; 118 | int16_t AL; 119 | int16_t AR; 120 | }; 121 | 122 | HELIOS_EXPORT int STDCALL EzAudDacGetCardNum(void); 123 | HELIOS_EXPORT bool STDCALL EzAudDacWriteFrame(const int *CardNum, const struct EAD_Pnt_s* data, int Bytes, uint16_t PPS); 124 | HELIOS_EXPORT bool STDCALL EzAudDacWriteFrameNR(const int *CardNum, const struct EAD_Pnt_s* data, int Bytes, uint16_t PPS, uint16_t Reps); 125 | HELIOS_EXPORT int STDCALL EzAudDacGetStatus(const int *CardNum); 126 | HELIOS_EXPORT bool STDCALL EzAudDacStop(const int *CardNum); 127 | HELIOS_EXPORT bool STDCALL EzAudDacClose(void); 128 | 129 | #endif -------------------------------------------------------------------------------- /src/pd-lib-builder/tips-tricks.md: -------------------------------------------------------------------------------- 1 | pd-lib-builder cheatsheet 2 | ========================= 3 | 4 | # Creating special builds 5 | 6 | ## cross-compiling W32 binaries from linux 7 | 8 | I'm using the following to cross-compile W32 binaries on my Debian/64bit system, 9 | using `mingw-w64`. 10 | 11 | Assuming you have unzipped a W32 package for Pd into `${WINPDPATH}`, run: 12 | 13 | make system=Windows pdbinpath="${WINPDPATH}/bin/" pdincludepath="${WINPDPATH}/src/" CC=i686-w64-mingw32-gcc 14 | 15 | (if the project uses C++, you might also need to set `CXX=i686-w64-mingw32-g++`) 16 | 17 | ## building double-precision externals 18 | 19 | At the time of writing (2018-02) there is no official Pd that supports 20 | double-precision numbers yet. 21 | However, if you do get hold of an experimental double-precision Pd, you can 22 | easily build your externals for 64-bit numbers: 23 | 24 | make CPPFLAGS="-DPD_FLOATSIZE=64" 25 | 26 | ## building externals for W64 (64-bit Windows) 27 | 28 | At the time of writing (2018-02) there is no official Pd that supports 29 | W64 yet. 30 | However, if you do get hold of an experimental W64 Pd, you can 31 | easily build your externals for this environment with 32 | 33 | make CPPFLAGS="-DPD_LONGINTTYPE=__int64" CC=x86_64-w64-mingw32-gcc 34 | 35 | 36 | To build a double-precision external for W64, use something like: 37 | 38 | make CPPFLAGS="-DPD_LONGINTTYPE=__int64 -DPD_FLOATSIZE=64" CC=x86_64-w64-mingw32-gcc 39 | 40 | 41 | ## TODO universal binaries on OSX 42 | 43 | 44 | # Project management 45 | 46 | In general it is advised to put the `Makefile.pdlibbuilder` into a separate 47 | subdirectory (e.g. `pd-lib-builder/`). 48 | This makes it much easier to update the `Makefile.pdlibbuilder` later 49 | 50 | You *should* also use a variable to the actual path of the Makefile.pdlibbuilder 51 | (even if you keep it in the root-directory), as this allows easy experimenting 52 | with newer (or older) (or site-specific) versions of the pd-lib-builder 53 | Makefile. 54 | 55 | ~~~make 56 | PDLIBBUILDER_DIR=pd-lib-builder/ 57 | include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder 58 | ~~~ 59 | 60 | ## Keeping pd-lib-builder up-to-date 61 | 62 | ### `git subtree` 63 | 64 | With git-subtrees, you make the pd-lib-builder repository (or any other 65 | repository for that matter) part of your own repository - with full history and 66 | everything - put nicely into a distinct subdirectory. 67 | 68 | Support for *manipulating* subtrees has been added with Git-v1.7.11 (May 2012). 69 | The nice thing however is, that from "outside" the subtree is part of your 70 | repository like any other directory. E.g. older versions of Git can clone your 71 | repository with the full subtree (and all it's history) just fine. 72 | You can also use git-archive to make a complete snapshot of your repository 73 | (including the subtree) - nice, if you e.g. want self-contained downloads of 74 | your project from git hosting platforms (like Github, Gitlab, Bitbucket,...) 75 | 76 | In short, `git subtree` is the better `git submodule`. 77 | 78 | So here's how to do it: 79 | 80 | #### Initial setup/check-out 81 | This will create a `pd-lib-builder/` directory containing the full history of 82 | the pd-lib-builder repository up to its release `v0.5.0` 83 | 84 | ~~~sh 85 | git subtree add --prefix=pd-lib-builder/ https://github.com/pure-data/pd-lib-builder v0.5.0 86 | ~~~ 87 | 88 | This will automatically merge the `pd-lib-builder/` history into your current 89 | branch, so everything is ready to go. 90 | 91 | #### Cloning your repository with the subtree 92 | Nothing special, really. 93 | Just clone your repository as always: 94 | 95 | ~~~sh 96 | git clone https://git.example.org/pd/superbonk~.git 97 | ~~~ 98 | 99 | #### Updating the subtree 100 | Time passes and sooner or later you will find, that there is a shiny new 101 | pd-lib-builder with plenty of bugfixes and new features. 102 | To update your local copy to pd-lib-builder's current `master`, simply run: 103 | 104 | ~~~sh 105 | git subtree pull --prefix pd-lib-builder/ https://github.com/pure-data/pd-lib-builder master 106 | ~~~ 107 | 108 | #### Pulling the updated subtree into existing clones 109 | Again, nothing special. 110 | Just pull as always: 111 | 112 | ~~~sh 113 | git pull 114 | ~~~ 115 | 116 | 117 | #### Further reading 118 | More on the power of `git subtree` can be found online 119 | - https://medium.com/@v/git-subtrees-a-tutorial-6ff568381844 120 | - https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree 121 | - ... 122 | 123 | ### ~~`git submodule`~~ [DISCOURAGED] 124 | 125 | 126 | #### Initial setup/check-out 127 | To add a new submodule to your repository, just run `git submodule add` and 128 | commit the changes: 129 | 130 | ~~~sh 131 | git submodule add https://github.com/pure-data/pd-lib-builder 132 | git commit .gitmodules pd-lib-builder/ -m "Added pd-lib-builder as git-submodule" 133 | ~~~ 134 | 135 | #### Cloning your repository with the submodule 136 | 137 | When doing a fresh clone of your repository, pass the `--recursive` option to 138 | automatically fetch all submodules: 139 | 140 | ~~~sh 141 | git clone --recursive https://git.example.org/pd/superbonk~.git 142 | ~~~ 143 | 144 | If you've cloned non-recursively, you can initialize and update the submodules 145 | manually: 146 | 147 | ~~~sh 148 | git submodule init 149 | git submodule update 150 | ~~~ 151 | 152 | #### Updating the submodule 153 | Submodules are usually fixed to a given commit in their repository. 154 | To update the `pd-lib-builder` submodule to the current `master` do something 155 | like: 156 | 157 | ~~~sh 158 | cd pd-lib-builder 159 | git checkout master 160 | git pull 161 | cd .. 162 | git status pd-lib-builder 163 | git commit pd-lib-builder -m "Updated pd-lib-builder to current master" 164 | ~~~ 165 | 166 | #### Pulling the updated submodule into existing clones 167 | After you have pushed the submodule updates in your repository, other clones of 168 | the repository can be updated as follows: 169 | 170 | ~~~sh 171 | git pull 172 | ~~~ 173 | 174 | The above will make your repository aware, that the submodule is out-of-sync. 175 | 176 | ~~~sh 177 | $ LANG=C git status pd-lib-builder 178 | On branch master 179 | Your branch is up to date with 'origin/master'. 180 | 181 | Changes not staged for commit: 182 | (use "git add ..." to update what will be committed) 183 | (use "git checkout -- ..." to discard changes in working directory) 184 | 185 | modified: pd-lib-builder (new commits) 186 | $ 187 | ~~~ 188 | 189 | In order to sync the submodule to the correct commit, run the following: 190 | 191 | ~~~sh 192 | git submodule update 193 | ~~~ 194 | 195 | #### Drawbacks 196 | `git submodule` has a number of drawbacks: 197 | - it requires special commands to synchronize the submodules, in addition to 198 | synching your repository. 199 | - you must make sure to use an URL for the submodule that is accessible to your 200 | potential users. e.g. using `git@github.com:pure-data/pd-lib-builder` is bad, 201 | because it requires everybody who wants to checkout your sources to have a 202 | github-account - even if they could checkout *your* repository anonymously. 203 | - submodules will be excluded from `git archive`. This means, that if you use a 204 | mainstream git provider (like Github, GitLab, Bitbucket,...) and make releases 205 | by creating a `git tag`, the automatically generated zipfiles with the sources 206 | will lack the submodule - and your users will not be able to compile your 207 | source code. 208 | 209 | In general, I would suggest to **avoid** `git submodule`, and instead use the 210 | better `git subtree` (above). 211 | 212 | -------------------------------------------------------------------------------- /src/sdk/HeliosDac.h: -------------------------------------------------------------------------------- 1 | /* 2 | SDK for Helios Laser DAC class, HEADER 3 | By Gitle Mikkelsen 4 | gitlem@gmail.com 5 | 6 | Dependencies: 7 | Libusb 1.0 (GNU Lesser General Public License, see libusb.h) 8 | 9 | Standard: C++14 10 | git repo: https://github.com/Grix/helios_dac.git 11 | 12 | BASIC USAGE: 13 | 1. Call OpenDevices() to open devices, returns number of available devices. 14 | 2. To send a frame to the DAC, first call GetStatus(). If the function returns ready (1), 15 | then you can call WriteFrame(). The status should be polled until it returns ready. 16 | It can and sometimes will fail to return ready on the first try. 17 | 3. To stop output, use Stop(). To restart output you must send a new frame as described above. 18 | 4. When the DAC is no longer needed, destroy the instance (destructors will free everything and close the connection) 19 | 20 | The DAC is double-buffered. When it receives its first frame, it starts outputting it. When a second frame is sent to 21 | the DAC while the first frame is being played, the second frame is stored in the DACs memory until the first frame 22 | finishes playback, at which point the second, buffered frame will start playing. If the DAC finished playback of a frame 23 | without having received and buffered a second frame, it will by default loop the first frame until a new frame is 24 | received (but the flag HELIOS_FLAG_SINGLE_MODE will make it stop playback instead). 25 | The GetStatus() function actually checks whether or not the buffer on the DAC is empty or full. If it is full, the DAC 26 | cannot receive a new frame until the currently playing frame finishes, freeing up the buffer. 27 | */ 28 | 29 | #pragma once 30 | 31 | #include "libusb.h" 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #define HELIOS_SDK_VERSION 6 41 | 42 | #define HELIOS_MAX_POINTS 0x1000 43 | #define HELIOS_MAX_RATE 0xFFFF 44 | #define HELIOS_MIN_RATE 7 45 | 46 | #define HELIOS_SUCCESS 1 47 | 48 | // Functions return negative values if something went wrong 49 | // Attempted to perform an action before calling OpenDevices() 50 | #define HELIOS_ERROR_NOT_INITIALIZED -1 51 | // Attempted to perform an action with an invalid device number 52 | #define HELIOS_ERROR_INVALID_DEVNUM -2 53 | // WriteFrame() called with null pointer to points 54 | #define HELIOS_ERROR_NULL_POINTS -3 55 | // WriteFrame() called with a frame containing too many points 56 | #define HELIOS_ERROR_TOO_MANY_POINTS -4 57 | // WriteFrame() called with pps higher than maximum allowed 58 | #define HELIOS_ERROR_PPS_TOO_HIGH -5 59 | // WriteFrame() called with pps lower than minimum allowed 60 | #define HELIOS_ERROR_PPS_TOO_LOW -6 61 | 62 | // Errors from the HeliosDacDevice class begin at -1000 63 | // Attempted to perform an operation on a closed DAC device 64 | #define HELIOS_ERROR_DEVICE_CLOSED -1000 65 | // Attempted to send a new frame with HELIOS_FLAGS_DONT_BLOCK before previous DoFrame() completed 66 | #define HELIOS_ERROR_DEVICE_FRAME_READY -1001 67 | // Operation failed because SendControl() failed (if operation failed because of libusb_interrupt_transfer failure, the error code will be a libusb error instead) 68 | #define HELIOS_ERROR_DEVICE_SEND_CONTROL -1002 69 | // Received an unexpected result from a call to SendControl() 70 | #define HELIOS_ERROR_DEVICE_RESULT -1003 71 | // Attempted to call SendControl() with a null buffer pointer 72 | #define HELIOS_ERROR_DEVICE_NULL_BUFFER -1004 73 | // Attempted to call SendControl() with a control signal that is too long 74 | #define HELIOS_ERROR_DEVICE_SIGNAL_TOO_LONG -1005 75 | 76 | // Errors from libusb are the libusb error code added to -5000. See libusb.h for libusb error codes. 77 | #define HELIOS_ERROR_LIBUSB_BASE -5000 78 | 79 | #define HELIOS_FLAGS_DEFAULT 0 80 | #define HELIOS_FLAGS_START_IMMEDIATELY (1 << 0) 81 | #define HELIOS_FLAGS_SINGLE_MODE (1 << 1) 82 | #define HELIOS_FLAGS_DONT_BLOCK (1 << 2) 83 | 84 | //usb properties 85 | #define HELIOS_VID 0x1209 86 | #define HELIOS_PID 0xE500 87 | #define EP_BULK_OUT 0x02 88 | #define EP_BULK_IN 0x81 89 | #define EP_INT_OUT 0x06 90 | #define EP_INT_IN 0x83 91 | 92 | #ifdef _DEBUG 93 | #define LIBUSB_LOG_LEVEL LIBUSB_LOG_LEVEL_WARNING 94 | #else 95 | #define LIBUSB_LOG_LEVEL LIBUSB_LOG_LEVEL_NONE 96 | #endif 97 | 98 | //point data structure 99 | typedef struct 100 | { 101 | std::uint16_t x; //12 bit (from 0 to 0xFFF) 102 | std::uint16_t y; //12 bit (from 0 to 0xFFF) 103 | std::uint8_t r; //8 bit (from 0 to 0xFF) 104 | std::uint8_t g; //8 bit (from 0 to 0xFF) 105 | std::uint8_t b; //8 bit (from 0 to 0xFF) 106 | std::uint8_t i; //8 bit (from 0 to 0xFF) 107 | } HeliosPoint; 108 | 109 | class HeliosDac 110 | { 111 | public: 112 | 113 | HeliosDac(); 114 | ~HeliosDac(); 115 | 116 | //unless otherwise specified, functions return HELIOS_SUCCESS if OK, and HELIOS_ERROR if something went wrong. 117 | 118 | //initializes drivers, opens connection to all devices. 119 | //Returns number of available devices. 120 | //NB: To re-scan for newly connected DACs after this function has once been called before, you must first call CloseDevices() 121 | int OpenDevices(); 122 | 123 | //closes and frees all devices 124 | int CloseDevices(); 125 | 126 | //sets debug log level in libusb 127 | int SetLibusbDebugLogLevel(int logLevel); 128 | 129 | //writes and outputs a frame to the speficied dac 130 | //devNum: dac number (0 to n where n+1 is the return value from OpenDevices() ) 131 | //pps: rate of output in points per second 132 | //flags: (default is 0) 133 | // Bit 0 (LSB) = if 1, start output immediately, instead of waiting for current frame (if there is one) to finish playing 134 | // Bit 1 = if 1, play frame only once, instead of repeating until another frame is written 135 | // Bit 2 = if 1, don't let WriteFrame() block execution while waiting for the transfer to finish 136 | // (NB: then the function might return 1 even if it fails) 137 | // Bit 3-7 = reserved 138 | //points: pointer to point data. See point structure declaration earlier in this document 139 | //numOfPoints: number of points in the frame 140 | int WriteFrame(unsigned int devNum, unsigned int pps, std::uint8_t flags, HeliosPoint* points, unsigned int numOfPoints); 141 | 142 | //Gets status of DAC, 1 means DAC is ready to receive frame, 0 means it is not 143 | int GetStatus(unsigned int devNum); 144 | 145 | //Returns firmware version of DAC 146 | int GetFirmwareVersion(unsigned int devNum); 147 | 148 | //Gets name of DAC (populates name with max 32 characters) 149 | int GetName(unsigned int devNum, char* name); 150 | 151 | //Sets name of DAC (name must be max 31 characters incl. null terminator) 152 | int SetName(unsigned int devNum, char* name); 153 | 154 | //Stops output of DAC until new frame is written (NB: blocks for 100ms) 155 | int Stop(unsigned int devNum); 156 | 157 | //Sets shutter level of DAC 158 | int SetShutter(unsigned int devNum, bool level); 159 | 160 | //Erase the firmware of the DAC, allowing it to be updated by accessing the SAM-BA bootloader 161 | int EraseFirmware(unsigned int devNum); 162 | 163 | private: 164 | 165 | class HeliosDacDevice //individual dac, interal use 166 | { 167 | public: 168 | 169 | HeliosDacDevice(libusb_device_handle*); 170 | ~HeliosDacDevice(); 171 | int SendFrame(unsigned int pps, std::uint8_t flags, HeliosPoint* points, unsigned int numOfPoints); 172 | int GetStatus(); 173 | int GetFirmwareVersion(); 174 | int GetName(char* name); 175 | int SetName(char* name); 176 | int SetShutter(bool level); 177 | int Stop(); 178 | int EraseFirmware(); 179 | 180 | private: 181 | 182 | int DoFrame(); 183 | void FrameHandler(); 184 | int SendControl(std::uint8_t* buffer, unsigned int bufferSize); 185 | 186 | struct libusb_transfer* interruptTransfer = NULL; 187 | struct libusb_device_handle* usbHandle; 188 | std::mutex frameLock; 189 | bool frameReady = false; 190 | int firmwareVersion = 0; 191 | char name[32]; 192 | bool closed = true; 193 | std::uint8_t* frameBuffer; 194 | unsigned int frameBufferSize; 195 | int frameResult = -1; 196 | 197 | }; 198 | 199 | std::vector> deviceList; 200 | std::mutex threadLock; 201 | bool inited = false; 202 | }; 203 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /src/sdk/HeliosDacAPI.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Helios Laser DAC SDK shared library 3 | By Gitle Mikkelsen 4 | 5 | See HeliosDacAPI.h for documentation 6 | 7 | Dependencies: 8 | Libusb 1.0 (GNU Lesser General Public License, see libusb.h) 9 | HeliosDAC class 10 | OpenLaserShowControllerV1.0.0 header and .def file (only on windows) 11 | 12 | git repo: https://github.com/Grix/helios_dac.git 13 | */ 14 | 15 | #include "HeliosDacAPI.h" 16 | 17 | int OpenDevices() 18 | { 19 | if (inited) 20 | return dacController->OpenDevices(); 21 | 22 | dacController = new HeliosDac(); 23 | 24 | int result = dacController->OpenDevices(); 25 | 26 | if (result <= 0) 27 | delete dacController; 28 | else 29 | inited = true; 30 | 31 | return result; 32 | } 33 | 34 | int WriteFrame(unsigned int dacNum, int pps, std::uint8_t flags, HeliosPoint* points, int numOfPoints) 35 | { 36 | if (!inited) 37 | return HELIOS_ERROR_NOT_INITIALIZED; 38 | 39 | return dacController->WriteFrame(dacNum, pps, flags, points, numOfPoints); 40 | } 41 | 42 | int SetLibusbDebugLogLevel(int logLevel) 43 | { 44 | if (!inited) 45 | return HELIOS_ERROR_NOT_INITIALIZED; 46 | 47 | return dacController->SetLibusbDebugLogLevel(logLevel); 48 | } 49 | 50 | int Stop(unsigned int dacNum) 51 | { 52 | if (!inited) 53 | return HELIOS_ERROR_NOT_INITIALIZED; 54 | 55 | return dacController->Stop(dacNum); 56 | } 57 | 58 | int GetName(unsigned int dacNum, char* name) 59 | { 60 | if (!inited) 61 | return HELIOS_ERROR_NOT_INITIALIZED; 62 | 63 | return dacController->GetName(dacNum, name); 64 | } 65 | 66 | int SetName(unsigned int dacNum, char* name) 67 | { 68 | if (!inited) 69 | return HELIOS_ERROR_NOT_INITIALIZED; 70 | 71 | return dacController->SetName(dacNum, name); 72 | } 73 | 74 | int GetStatus(unsigned int dacNum) 75 | { 76 | if (!inited) 77 | return HELIOS_ERROR_NOT_INITIALIZED; 78 | 79 | return (int)dacController->GetStatus(dacNum); 80 | } 81 | 82 | int SetShutter(unsigned int dacNum, bool value) 83 | { 84 | if (!inited) 85 | return HELIOS_ERROR_NOT_INITIALIZED; 86 | 87 | return dacController->SetShutter(dacNum, value); 88 | } 89 | 90 | int GetFirmwareVersion(unsigned int dacNum) 91 | { 92 | if (!inited) 93 | return HELIOS_ERROR_NOT_INITIALIZED; 94 | 95 | return dacController->GetFirmwareVersion(dacNum); 96 | } 97 | 98 | int EraseFirmware(unsigned int dacNum) 99 | { 100 | if (!inited) 101 | return HELIOS_ERROR_NOT_INITIALIZED; 102 | 103 | return dacController->EraseFirmware(dacNum); 104 | } 105 | 106 | int CloseDevices() 107 | { 108 | if (inited) 109 | { 110 | inited = false; 111 | delete dacController; 112 | return HELIOS_SUCCESS; 113 | } 114 | else 115 | return HELIOS_ERROR_NOT_INITIALIZED; 116 | } 117 | 118 | 119 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) 120 | 121 | //OLSC implementation 122 | //OLSC API is designed by Chris Favreau, MIT License 123 | 124 | OLSC_API int __stdcall OLSC_GetAPIVersion(void) 125 | { 126 | return OPEN_LASER_SHOW_DEVICE_API_VERSION; 127 | } 128 | 129 | OLSC_API int __stdcall OLSC_GetInterfaceName(char* pString) 130 | { 131 | memcpy(pString, "Helios", 7); 132 | return OLSC_ERROR_SUCCESS; 133 | } 134 | 135 | OLSC_API int __stdcall OLSC_Initialize(void) 136 | { 137 | return OpenDevices(); 138 | } 139 | 140 | OLSC_API int __stdcall OLSC_Shutdown(void) 141 | { 142 | CloseDevices(); 143 | return OLSC_ERROR_SUCCESS; 144 | } 145 | 146 | OLSC_API int __stdcall OLSC_GetDeviceCount(void) 147 | { 148 | if (!inited) 149 | return OLSC_ERROR_NONE; 150 | else 151 | return dacController->OpenDevices(); 152 | } 153 | 154 | OLSC_API int __stdcall OLSC_GetDeviceCapabilities(int device_number, struct LASER_SHOW_DEVICE_CAPABILITIES& device_capabilities) 155 | { 156 | if (!inited) 157 | return OLSC_ERROR_NONE; 158 | 159 | device_capabilities.color_resolution = 8; 160 | device_capabilities.xy_resolution = 12; 161 | device_capabilities.has_dmx_in = false; 162 | device_capabilities.has_dmx_out = false; 163 | device_capabilities.has_ttl_in = false; 164 | device_capabilities.has_ttl_out = false; 165 | device_capabilities.max_frame_size = HELIOS_MAX_POINTS; 166 | device_capabilities.max_speed = HELIOS_MAX_RATE; 167 | device_capabilities.min_frame_size = 1; 168 | device_capabilities.min_speed = HELIOS_MIN_RATE; 169 | GetName(device_number, &device_capabilities.name[0]); 170 | device_capabilities.uses_callbacks = false; 171 | device_capabilities.version_major = 1; 172 | device_capabilities.version_minor = 0; 173 | 174 | return OLSC_ERROR_SUCCESS; 175 | } 176 | 177 | OLSC_API int __stdcall OLSC_GetLastErrorNumber(int device_number, int& number, char* string_pointer, int string_length) 178 | { 179 | //not supported yet 180 | return OLSC_ERROR_NONE; 181 | } 182 | 183 | OLSC_API int __stdcall OLSC_Play(int device_number) 184 | { 185 | //not supported yet, use OLSC_WriteFrame() 186 | return OLSC_ERROR_NONE; 187 | } 188 | 189 | OLSC_API int __stdcall OLSC_Pause(int device_number) 190 | { 191 | return Stop(device_number); 192 | } 193 | 194 | OLSC_API int __stdcall OLSC_Shutter(int device_number, int state) 195 | { 196 | return SetShutter(device_number, (state == 1)); 197 | } 198 | 199 | OLSC_API int __stdcall OLSC_WriteFrameEx(int device_number, int display_speed, int point_count, struct LASER_SHOW_DEVICE_POINT *points) 200 | { 201 | struct LASER_SHOW_DEVICE_FRAME frame; 202 | frame.display_speed = display_speed; 203 | frame.point_count = point_count; 204 | frame.points = points; 205 | 206 | return OLSC_WriteFrame(device_number, frame); 207 | } 208 | 209 | OLSC_API int __stdcall OLSC_WriteFrame(int device_number, struct LASER_SHOW_DEVICE_FRAME frame) 210 | { 211 | if (!inited) 212 | return OLSC_ERROR_FAILED; 213 | 214 | //convert frame structure 215 | HeliosPoint frameBuffer[HELIOS_MAX_POINTS * 7 + 5]; 216 | for (int i = 0; i < frame.point_count; i++) 217 | { 218 | frameBuffer[i].x = (frame.points[i].x >> 4); 219 | frameBuffer[i].y = (frame.points[i].y >> 4); 220 | frameBuffer[i].r = (std::uint8_t)frame.points[i].r; 221 | frameBuffer[i].g = (std::uint8_t)frame.points[i].g; 222 | frameBuffer[i].b = (std::uint8_t)frame.points[i].b; 223 | frameBuffer[i].i = (std::uint8_t)frame.points[i].i; 224 | } 225 | 226 | //send frame to dac 227 | return dacController->WriteFrame(device_number, frame.display_speed, HELIOS_FLAGS_DEFAULT, frameBuffer, frame.point_count); 228 | } 229 | 230 | OLSC_API int __stdcall OLSC_GetStatus(int device_number, DWORD& status) 231 | { 232 | if (!inited) 233 | return OLSC_ERROR_NONE; 234 | 235 | std::uint8_t statusResult = GetStatus(device_number); 236 | if (statusResult == HELIOS_ERROR) 237 | return OLSC_ERROR_FAILED; 238 | 239 | if (statusResult == 1) 240 | { 241 | status = OLSC_STATUS_BUFFER_EMPTY; 242 | } 243 | else 244 | status = OLSC_STATUS_BUFFER_FULL; 245 | 246 | return OLSC_ERROR_SUCCESS; 247 | } 248 | 249 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) 250 | OLSC_API int __stdcall OLSC_SetCallback(int device_number, HWND parent_window_handle, uint32_t message) 251 | { 252 | //not supported 253 | return OLSC_ERROR_NONE; 254 | } 255 | #endif 256 | 257 | OLSC_API int __stdcall OLSC_WriteDMX(int device_number, int start_address, std::uint8_t *data_pointer, int length) 258 | { 259 | //not supported 260 | return OLSC_ERROR_NONE; 261 | } 262 | 263 | OLSC_API int __stdcall OLSC_ReadDMX(int device_number, int start_address, std::uint8_t *data_pointer, int length) 264 | { 265 | //not supported 266 | return OLSC_ERROR_NONE; 267 | } 268 | 269 | OLSC_API int __stdcall OLSC_WriteTTL(int device_number, DWORD data) 270 | { 271 | //not supported 272 | return OLSC_ERROR_NONE; 273 | } 274 | 275 | OLSC_API int __stdcall OLSC_ReadTTL(int device_number, DWORD& data) 276 | { 277 | //not supported 278 | return OLSC_ERROR_NONE; 279 | } 280 | 281 | //EZAudDAC API wrapper 282 | 283 | bool STDCALL EzAudDacWriteFrameNR(const int *CardNum, const struct EAD_Pnt_s* data, int Bytes, uint16_t PPS, uint16_t Reps) 284 | { 285 | unsigned int dacNum = *CardNum; 286 | unsigned int numPoints = Bytes / sizeof(*data); 287 | HeliosPoint frameBuffer[HELIOS_MAX_POINTS * 7 + 5]; 288 | for (unsigned int i = 0; i < numPoints; i++) 289 | { 290 | frameBuffer[i].x = (data[i].X + 0xFFFF / 2) >> 4; 291 | frameBuffer[i].y = (data[i].Y + 0xFFFF / 2) >> 4; 292 | frameBuffer[i].r = (data[i].R + 0xFFFF / 2) >> 8; 293 | frameBuffer[i].g = (data[i].G + 0xFFFF / 2) >> 8; 294 | frameBuffer[i].b = (data[i].B + 0xFFFF / 2) >> 8; 295 | frameBuffer[i].i = (data[i].I + 0xFFFF / 2) >> 8; 296 | } 297 | if (Reps == 1) 298 | return WriteFrame(dacNum, PPS, HELIOS_FLAGS_SINGLE_MODE, frameBuffer, numPoints); 299 | else 300 | return WriteFrame(dacNum, PPS, HELIOS_FLAGS_DEFAULT, frameBuffer, numPoints); //ignore reps over 1, play continuously instead 301 | } 302 | 303 | bool STDCALL EzAudDacWriteFrame(const int *CardNum, const struct EAD_Pnt_s* data, int Bytes, uint16_t PPS) 304 | { 305 | unsigned int dacNum = *CardNum; 306 | unsigned int numPoints = Bytes / sizeof(*data); 307 | HeliosPoint frameBuffer[HELIOS_MAX_POINTS * 7 + 5]; 308 | for (unsigned int i = 0; i < numPoints; i++) 309 | { 310 | frameBuffer[i].x = (data[i].X + 0xFFFF/2) >> 4; 311 | frameBuffer[i].y = (data[i].Y + 0xFFFF/2) >> 4; 312 | frameBuffer[i].r = (data[i].R + 0xFFFF/2) >> 8; 313 | frameBuffer[i].g = (data[i].G + 0xFFFF/2) >> 8; 314 | frameBuffer[i].b = (data[i].B + 0xFFFF/2) >> 8; 315 | frameBuffer[i].i = (data[i].I + 0xFFFF/2) >> 8; 316 | } 317 | return WriteFrame(dacNum, PPS, HELIOS_FLAGS_DEFAULT, frameBuffer, numPoints); 318 | } 319 | 320 | int STDCALL EzAudDacGetCardNum(void) 321 | { 322 | return OpenDevices(); 323 | } 324 | 325 | int STDCALL EzAudDacGetStatus(const int *CardNum) 326 | { 327 | unsigned int dacNum = *CardNum; 328 | return GetStatus(dacNum); 329 | } 330 | 331 | bool STDCALL EzAudDacClose(void) 332 | { 333 | return CloseDevices(); 334 | } 335 | 336 | bool STDCALL EzAudDacStop(const int *CardNum) 337 | { 338 | unsigned int dacNum = *CardNum; 339 | return Stop(dacNum); 340 | } 341 | 342 | #endif 343 | -------------------------------------------------------------------------------- /src/sdk/OpenLaserShowControllerV1.0.0-Mod.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | OpenLaserShowController.h : main header file for the OpenLaserShowController DLL 4 | 5 | [!! Slightly modified for Helios] 6 | -> Changes: 7 | - Not dependent on windows.h 8 | - stdint types 9 | - OLSC_SetCallback removed 10 | - OPEN_LASER_SHOW_DEVICE_API_VERSION defined 11 | 12 | Copyright (c) 2009 Dennis Kromhout, Chris Favreau, Andreas Unger 13 | 14 | Permission is hereby granted, free of charge, to any person 15 | obtaining a copy of this software and associated documentation 16 | files (the "Software"), to deal in the Software without 17 | restriction, including without limitation the rights to use, 18 | copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | copies of the Software, and to permit persons to whom the 20 | Software is furnished to do so, subject to the following 21 | conditions: 22 | 23 | The above copyright notice and this permission notice shall be 24 | included in all copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 27 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 28 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 29 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 30 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 31 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 32 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 33 | OTHER DEALINGS IN THE SOFTWARE. 34 | 35 | */ 36 | 37 | // **************************************************************************************************************** 38 | // ** Open Laser Show Controler Version 1 API 39 | // **************************************************************************************************************** 40 | 41 | #ifndef __OPENLASERSHOWCONTROLLER_H__ 42 | #define __OPENLASERSHOWCONTROLLER_H__ 43 | 44 | #include 45 | 46 | #pragma pack(1) 47 | 48 | // **************************************************************************************************************** 49 | // ** Constants 50 | // **************************************************************************************************************** 51 | 52 | #define OPEN_LASER_SHOW_DEVICE_API_VERSION 1 53 | 54 | // Shutter State 55 | #define LASER_SHOW_DEVICE_SHUTTER_STATE_ON 0 56 | #define LASER_SHOW_DEVICE_SHUTTER_STATE_OFF 1 57 | 58 | // Standard Errors 59 | // TODO - add errors to this list so we can be more verbose in describing the particular error that occurred. 60 | #define OLSC_ERROR_SUCCESS 1 61 | #define OLSC_ERROR_NONE 0 62 | #define OLSC_ERROR_INVALID_PARAMETER -1 63 | #define OLSC_ERROR_FAILED -2 64 | 65 | // Status Bits 66 | // Status Clear 67 | #define OLSC_STATUS_NONE 0x00000000 68 | // Bit 0 = Buffer Full 69 | #define OLSC_STATUS_BUFFER_FULL 0x00000001 70 | // Bit 1 = Buffer Empty 71 | #define OLSC_STATUS_BUFFER_EMPTY 0x00000002 72 | // Bit 2 = DMX Out Complete 73 | #define OLSC_STATUS_DMX_OUT_COMPLETE 0x00000004 74 | // Bit 3 = DMX In Ready 75 | #define OLSC_STATUS_DMX_IN_READY 0x00000008 76 | // Bit 4 = TTL Out Complete 77 | #define OLSC_STATUS_TTL_OUT_COMPLETE 0x00000010 78 | // Bit 5 = TLL In Ready 79 | #define OLSC_STATUS_TTL_IN_READY 0x00000020 80 | // Bit 6 = Resreved 81 | // Bit 7 = Reserved 82 | // Bit 8 = Reserved 83 | // Bit 9-30 = Reserved 84 | // Bit 31 = An Error Occured 85 | #define OLSC_STATUS_ERROR 0x80000000 86 | 87 | // **************************************************************************************************************** 88 | // ** Data Structures 89 | // **************************************************************************************************************** 90 | 91 | struct LASER_SHOW_DEVICE_CAPABILITIES 92 | { 93 | // Device Name 94 | char name[1024]; 95 | // Device Version 96 | int version_major; 97 | int version_minor; 98 | // Min Speed/Max Speed 99 | int min_speed; 100 | int max_speed; 101 | // Min Frame Size/Max Frame Size 102 | int min_frame_size; 103 | int max_frame_size; 104 | // DMX In/Out? 105 | bool has_dmx_in; 106 | bool has_dmx_out; 107 | // TTL In/Out? 108 | bool has_ttl_in; 109 | bool has_ttl_out; 110 | // X/Y Resolution (8 to 16 bits) 111 | int xy_resolution; 112 | // Color Resolution (1 to 16 bits) 113 | int color_resolution; 114 | // Uses callbacks? 115 | bool uses_callbacks; 116 | }; 117 | 118 | 119 | struct LASER_SHOW_DEVICE_POINT 120 | { 121 | std::uint16_t x; //16bit 122 | std::uint16_t y; //16bit 123 | std::uint16_t r; //8bit !! 124 | std::uint16_t g; //8bit !! 125 | std::uint16_t b; //8bit !! 126 | std::uint16_t i; //8bit !! 127 | }; 128 | 129 | 130 | struct LASER_SHOW_DEVICE_FRAME 131 | { 132 | int display_speed; 133 | int point_count; 134 | struct LASER_SHOW_DEVICE_POINT *points; 135 | }; 136 | 137 | // **************************************************************************************************************** 138 | // ** Function Prototypes 139 | // **************************************************************************************************************** 140 | 141 | // Comment out if this .H file is part of an application 142 | // This needs to be defined if this .H file is part of a driver DLL 143 | // *** BE SURE TO DEFINE OLSC_EXPORTS if you are writing an OLSC Driver DLL 144 | #define OLSC_EXPORTS 1 145 | 146 | #ifdef OLSC_EXPORTS 147 | #define OLSC_API __declspec(dllexport) 148 | #else 149 | #define OLSC_API __declspec(dllimport) 150 | #endif 151 | 152 | #ifdef __cplusplus 153 | extern "C" { 154 | #endif 155 | 156 | // OLSC_GetAPIVersion 157 | // Inputs: None 158 | // Outputs: Returns a single integer that represents the version number 159 | // Description: Returns the version of the OpenDAC API 160 | // so we don't make any critical errors when using this DLL 161 | OLSC_API int WINAPI OLSC_GetAPIVersion(void); 162 | 163 | // OLSC_GetInterfaceName 164 | // Inputs: Pointer to a string at least 64 characters in length 165 | // Outputs: Returns success or failure 166 | // Description: Returns the string name of the OpenDC Interface 167 | OLSC_API int WINAPI OLSC_GetInterfaceName(char *pString); 168 | 169 | // OLSC_Initialize 170 | // Inputs: None 171 | // Outputs: Returns the number of available devices. 172 | // Description: Initializes the hardware 173 | OLSC_API int WINAPI OLSC_Initialize(void); 174 | 175 | // OLSC_Shutdown 176 | // Inputs: None 177 | // Outputs: Returns success or failure 178 | // Description: Shuts down all devices 179 | OLSC_API int WINAPI OLSC_Shutdown(void); 180 | 181 | // OLSC_GetDeviceCount 182 | // Inputs: None 183 | // Outputs: Returns the number of available devices 184 | // Description: Has to be called AFTER Intialize has been called. Thsi function 185 | // is to be used to query the number of available devices without calling 186 | // intialize again and again 187 | OLSC_API int WINAPI OLSC_GetDeviceCount(void); 188 | 189 | // OLSC_GetCapabilities 190 | // Inputs: device Number, device capabilties structure to be filled in 191 | // Outputs: Returns success or failure 192 | // Description: Gets the capabilties of each device attached 193 | // Caps: 194 | // Device Name 195 | // Device Version 196 | // Min Speed/Max Speed 197 | // Min Frame Size/Max Frame Size 198 | // DMX In/Out? 199 | // TTL In/Out? 200 | // X/Y Resolution (8 to 16 bits) 201 | // Color Resolution (1 to 16 bits) 202 | // Uses callbacks? 203 | // Some reserved space for future use 204 | OLSC_API int WINAPI OLSC_GetDeviceCapabilities(int device_number, struct LASER_SHOW_DEVICE_CAPABILITIES &device_capabilities); 205 | 206 | // OLSC_GetLastErrorNumber 207 | // Inputs: device number, error string pointer, and string length max. 208 | // Outputs: error number, and actual error string 209 | // Description: Get the string and/or number associated with the last error 210 | OLSC_API int WINAPI OLSC_GetLastErrorNumber(int device_number, int &number, char *string_pointer, int string_length); 211 | 212 | // OLSC_Play 213 | // Inputs: device number 214 | // Outputs: Returns success or failure 215 | // Description: Starts the output on a particular device or all devices 216 | OLSC_API int WINAPI OLSC_Play(int device_number); 217 | 218 | // OLSC_Pause 219 | // Inputs: device number 220 | // Outputs: Returns success or failure 221 | // Description: Stops the output on a particular device or all devices 222 | OLSC_API int WINAPI OLSC_Pause(int device_number); 223 | 224 | // OLSC_Shutter 225 | // Inputs: device number, shutter state (LASER_SHOW_DEVICE_SHUTTER_STATE) 226 | // Outputs: Returns success or failure 227 | // Description: Turns the laser show device's shutter On/Off 228 | OLSC_API int WINAPI OLSC_Shutter(int device_number, int state); 229 | 230 | // OLSC_WriteFrameEx 231 | // Inputs: device number, display speed (pps), point count, point to array of LASER_SHOW_DEVICE_POINTs 232 | // Outputs: Returns success or failure 233 | // Description: 234 | // Writes a frame to a particular device or all devices 235 | // Point Array: 236 | // X 16 bit unsigned 237 | // Y 16 bit unsigned 238 | // R 16 bit unsigned 239 | // G 16 bit unsigned 240 | // B 16 bit unsigned 241 | // I 16 bit unsigned 242 | // 243 | // ** Any frame that is written will be displayed until another frame is written to take its place or the Output is Paused 244 | // 245 | OLSC_API int WINAPI OLSC_WriteFrameEx(int device_number, int display_speed, int point_count, struct LASER_SHOW_DEVICE_POINT *points); 246 | 247 | // OLSC_WriteFrame 248 | // Inputs: device number, frame structure (LASER_SHOW_DEIVCE_FRAME) 249 | // Outputs: Returns success or failure 250 | // Description: 251 | // Writes a frame to a particular device or all devices 252 | // Pass in a frame: 253 | // Point Count 254 | // Display Speed PPS 255 | // Point Array: 256 | // X 16 bit unsigned 257 | // Y 16 bit unsigned 258 | // R 16 bit unsigned 259 | // G 16 bit unsigned 260 | // B 16 bit unsigned 261 | // I 16 bit unsigned 262 | // 263 | // ** Any frame that is written will be displayed until another frame is written to take its place or the Output is Paused 264 | // 265 | OLSC_API int WINAPI OLSC_WriteFrame(int device_number, struct LASER_SHOW_DEVICE_FRAME frame); 266 | 267 | // OLSC_GetStatus() 268 | // Inputs: device number, status DWORD 269 | // Outputs: Returns success or failure 270 | // Description: 271 | // Gets the status of a particular device 272 | // Can be used for polling or in conjunction with Windows Message Callback 273 | // Status Structure or Bit Mask: 274 | // Bit 0 = Buffer Full 275 | // Bit 1 = Buffer Empty 276 | // Bit 2 = DMX Out Complete 277 | // Bit 3 = DMX In Ready 278 | // Bit 4 = TTL Out Complete 279 | // Bit 5 = TLL In Ready 280 | // Bit 6 = Resreved 281 | // Bit 7 = Reserved 282 | // Bit 8 = Reserved 283 | // Bit 9-30 = Reserved 284 | // Bit 31 = An Error Occured 285 | OLSC_API int WINAPI OLSC_GetStatus(int device_number, uint32_t &status); 286 | 287 | 288 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) 289 | #include 290 | // OLSC_SetCallback() 291 | // Inputs: device number, parent window handle (for SendMessage), message DWORD 292 | // Outputs: Returns success or failure 293 | // Description: 294 | // Sets the call back window parent handle and windows message to send to run the callback 295 | // and set the call back notification mask bits per the GetStatus mask. The Callback message 296 | // will return the Device Number in the wParam and the Status mask in the lParam. 297 | // We all work in windows right? 298 | // This interface is optional in the DLL and in the application. The DLL writers should take this into account. 299 | // So if you use the callback ... be able to function without it... it is used for efficiency. 300 | OLSC_API int WINAPI OLSC_SetCallback(int device_number, HWND parent_window_handle, uint32_t message); 301 | #endif 302 | 303 | // OLSC_WriteDMX() 304 | // Inputs: device number, start address, data pointer, data length 305 | // Outputs: Returns success or failure 306 | // Description: 307 | // Writes DMX data to a particular device 308 | OLSC_API int WINAPI OLSC_WriteDMX(int device_number, int start_address, std::uint8_t *data_pointer, int length); 309 | 310 | // OLSC_ReadDMX() 311 | // Inputs: device number, start address, data pointer, data length 312 | // Outputs: Returns success or failure 313 | // Description: 314 | // Reads DMX data from a particular device 315 | OLSC_API int WINAPI OLSC_ReadDMX(int device_number, int start_address, std::uint8_t *data_pointer, int length); 316 | 317 | // OLSC_WriteTTL() 318 | // Inputs: device number, data DWORD (up to 32 bits of TTL outputs) 319 | // Outputs: Returns success or failure 320 | // Description: 321 | // Writes TTL data from a particular device 322 | OLSC_API int WINAPI OLSC_WriteTTL(int device_number, uint32_t data); 323 | 324 | // OLSC_ReadTTL() 325 | // Inputs: device number, data DWORD (up to 32 bits of TTL inputs) 326 | // Outputs: Returns success or failure 327 | // Description: 328 | // Reads TTL data from a particular device 329 | OLSC_API int WINAPI OLSC_ReadTTL(int device_number, uint32_t &data); 330 | 331 | #ifdef __cplusplus 332 | } 333 | #endif 334 | 335 | #endif // __OPENLASERSHOWCONTROLLER_H__ 336 | -------------------------------------------------------------------------------- /src/sdk/HeliosDac.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SDK for Helios Laser DAC class, SOURCE 3 | By Gitle Mikkelsen 4 | gitlem@gmail.com 5 | 6 | Dependencies: 7 | Libusb 1.0 (GNU Lesser General Public License, see libusb.h) 8 | 9 | Standard: C++14 10 | git repo: https://github.com/Grix/helios_dac.git 11 | 12 | See header HeliosDac.h for function and usage documentation 13 | */ 14 | 15 | 16 | #include "HeliosDac.h" 17 | 18 | HeliosDac::HeliosDac() 19 | { 20 | inited = false; 21 | } 22 | 23 | HeliosDac::~HeliosDac() 24 | { 25 | CloseDevices(); 26 | } 27 | 28 | int HeliosDac::OpenDevices() 29 | { 30 | if (inited) 31 | return deviceList.size(); 32 | 33 | int result = libusb_init(NULL); 34 | if (result < 0) 35 | return result; 36 | 37 | libusb_set_debug(NULL, LIBUSB_LOG_LEVEL); 38 | 39 | libusb_device** devs; 40 | ssize_t cnt = libusb_get_device_list(NULL, &devs); 41 | if (cnt < 0) 42 | return (int)cnt; 43 | 44 | std::lock_guard lock(threadLock); 45 | 46 | unsigned int devNum = 0; 47 | for (int i = 0; i < cnt; i++) 48 | { 49 | struct libusb_device_descriptor devDesc; 50 | int result = libusb_get_device_descriptor(devs[i], &devDesc); 51 | if (result < 0) 52 | continue; 53 | 54 | if ((devDesc.idProduct != HELIOS_PID) || (devDesc.idVendor != HELIOS_VID)) 55 | continue; 56 | 57 | libusb_device_handle* devHandle; 58 | result = libusb_open(devs[i], &devHandle); 59 | if (result < 0) 60 | continue; 61 | 62 | result = libusb_claim_interface(devHandle, 0); 63 | if (result < 0) 64 | continue; 65 | 66 | result = libusb_set_interface_alt_setting(devHandle, 0, 1); 67 | if (result < 0) 68 | continue; 69 | 70 | //successfully opened, add to device list 71 | deviceList.push_back(std::make_unique(devHandle)); 72 | 73 | devNum++; 74 | } 75 | 76 | libusb_free_device_list(devs, 1); 77 | 78 | if (devNum > 0) 79 | inited = true; 80 | 81 | return devNum; 82 | } 83 | 84 | int HeliosDac::CloseDevices() 85 | { 86 | if (!inited) 87 | return HELIOS_ERROR_NOT_INITIALIZED; 88 | 89 | std::lock_guard lock(threadLock); 90 | inited = false; 91 | deviceList.clear(); //various destructors will clean all devices 92 | 93 | libusb_exit(NULL); 94 | 95 | return HELIOS_SUCCESS; 96 | } 97 | 98 | int HeliosDac::SetLibusbDebugLogLevel(int logLevel) 99 | { 100 | if (!inited) 101 | return HELIOS_ERROR_NOT_INITIALIZED; 102 | 103 | libusb_set_debug(NULL, logLevel); 104 | 105 | return HELIOS_SUCCESS; 106 | } 107 | 108 | int HeliosDac::WriteFrame(unsigned int devNum, unsigned int pps, std::uint8_t flags, HeliosPoint* points, unsigned int numOfPoints) 109 | { 110 | if (!inited) 111 | return HELIOS_ERROR_NOT_INITIALIZED; 112 | 113 | if (points == NULL) 114 | return HELIOS_ERROR_NULL_POINTS; 115 | 116 | if (numOfPoints > HELIOS_MAX_POINTS) 117 | return HELIOS_ERROR_TOO_MANY_POINTS; 118 | 119 | if (pps > HELIOS_MAX_RATE) 120 | return HELIOS_ERROR_PPS_TOO_HIGH; 121 | 122 | if (pps < HELIOS_MIN_RATE) 123 | return HELIOS_ERROR_PPS_TOO_LOW; 124 | 125 | std::unique_lock lock(threadLock); 126 | HeliosDacDevice* dev = NULL; 127 | if (devNum < deviceList.size()) 128 | dev = deviceList[devNum].get(); 129 | lock.unlock(); 130 | 131 | if (dev == NULL) 132 | return HELIOS_ERROR_INVALID_DEVNUM; 133 | 134 | return dev->SendFrame(pps, flags, points, numOfPoints); 135 | } 136 | 137 | int HeliosDac::GetStatus(unsigned int devNum) 138 | { 139 | if (!inited) 140 | return HELIOS_ERROR_NOT_INITIALIZED; 141 | 142 | std::unique_lock lock(threadLock); 143 | HeliosDacDevice* dev = NULL; 144 | if (devNum < deviceList.size()) 145 | dev = deviceList[devNum].get(); 146 | lock.unlock(); 147 | if (dev == NULL) 148 | return HELIOS_ERROR_INVALID_DEVNUM; 149 | 150 | return dev->GetStatus(); 151 | } 152 | 153 | int HeliosDac::GetFirmwareVersion(unsigned int devNum) 154 | { 155 | if (!inited) 156 | return HELIOS_ERROR_NOT_INITIALIZED; 157 | 158 | std::unique_lock lock(threadLock); 159 | HeliosDacDevice* dev = NULL; 160 | if (devNum < deviceList.size()) 161 | dev = deviceList[devNum].get(); 162 | lock.unlock(); 163 | if (dev == NULL) 164 | return HELIOS_ERROR_INVALID_DEVNUM; 165 | 166 | return dev->GetFirmwareVersion(); 167 | } 168 | 169 | int HeliosDac::GetName(unsigned int devNum, char* name) 170 | { 171 | if (!inited) 172 | return HELIOS_ERROR_NOT_INITIALIZED; 173 | 174 | std::unique_lock lock(threadLock); 175 | HeliosDacDevice* dev = NULL; 176 | if (devNum < deviceList.size()) 177 | dev = deviceList[devNum].get(); 178 | lock.unlock(); 179 | if (dev == NULL) 180 | return HELIOS_ERROR_INVALID_DEVNUM; 181 | 182 | char dacName[32]; 183 | if (dev->GetName(dacName) < 0) 184 | { 185 | // The device didn't return a name so build a generic name 186 | memcpy(name, "Helios ", 8); 187 | name[7] = (char)((int)(devNum >= 10) + 48); 188 | name[8] = (char)((int)(devNum % 10) + 48); 189 | name[9] = '\0'; 190 | } 191 | else 192 | { 193 | memcpy(name, dacName, 32); 194 | } 195 | return HELIOS_SUCCESS; 196 | } 197 | 198 | int HeliosDac::SetName(unsigned int devNum, char* name) 199 | { 200 | if (!inited) 201 | return HELIOS_ERROR_NOT_INITIALIZED; 202 | 203 | std::unique_lock lock(threadLock); 204 | HeliosDacDevice* dev = NULL; 205 | if (devNum < deviceList.size()) 206 | dev = deviceList[devNum].get(); 207 | lock.unlock(); 208 | if (dev == NULL) 209 | return HELIOS_ERROR_INVALID_DEVNUM; 210 | 211 | return dev->SetName(name); 212 | } 213 | 214 | int HeliosDac::Stop(unsigned int devNum) 215 | { 216 | if (!inited) 217 | return HELIOS_ERROR_NOT_INITIALIZED; 218 | 219 | std::unique_lock lock(threadLock); 220 | HeliosDacDevice* dev = NULL; 221 | if (devNum < deviceList.size()) 222 | dev = deviceList[devNum].get(); 223 | lock.unlock(); 224 | if (dev == NULL) 225 | return HELIOS_ERROR_INVALID_DEVNUM; 226 | 227 | return dev->Stop(); 228 | } 229 | 230 | int HeliosDac::SetShutter(unsigned int devNum, bool level) 231 | { 232 | if (!inited) 233 | return HELIOS_ERROR_NOT_INITIALIZED; 234 | 235 | std::unique_lock lock(threadLock); 236 | HeliosDacDevice* dev = NULL; 237 | if (devNum < deviceList.size()) 238 | dev = deviceList[devNum].get(); 239 | lock.unlock(); 240 | if (dev == NULL) 241 | return HELIOS_ERROR_INVALID_DEVNUM; 242 | 243 | return dev->SetShutter(level); 244 | } 245 | 246 | int HeliosDac::EraseFirmware(unsigned int devNum) 247 | { 248 | if (!inited) 249 | return HELIOS_ERROR_NOT_INITIALIZED; 250 | 251 | std::unique_lock lock(threadLock); 252 | HeliosDacDevice* dev = NULL; 253 | if (devNum < deviceList.size()) 254 | dev = deviceList[devNum].get(); 255 | lock.unlock(); 256 | if (dev == NULL) 257 | return HELIOS_ERROR_INVALID_DEVNUM; 258 | 259 | return dev->EraseFirmware(); 260 | } 261 | 262 | 263 | /// ----------------------------------------------------------------------- 264 | /// HELIOSDACDEVICE START (one instance for each connected DAC) 265 | /// ----------------------------------------------------------------------- 266 | 267 | HeliosDac::HeliosDacDevice::HeliosDacDevice(libusb_device_handle* handle) 268 | { 269 | closed = true; 270 | usbHandle = handle; 271 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 272 | std::lock_guardlock(frameLock); 273 | 274 | int actualLength = 0; 275 | 276 | //catch any lingering transfers 277 | std::uint8_t ctrlBuffer0[32]; 278 | while (libusb_interrupt_transfer(usbHandle, EP_INT_IN, ctrlBuffer0, 32, &actualLength, 5) == LIBUSB_SUCCESS); 279 | 280 | //get firmware version 281 | firmwareVersion = 0; 282 | bool repeat = true; 283 | for (int i = 0; ((i < 2) && repeat); i++) //retry command if necessary 284 | { 285 | std::uint8_t ctrlBuffer[2] = { 0x04, 0 }; 286 | int transferResult = libusb_interrupt_transfer(usbHandle, EP_INT_OUT, ctrlBuffer, 2, &actualLength, 32); 287 | if ((transferResult == LIBUSB_SUCCESS) && (actualLength == 2)) 288 | { 289 | for (int j = 0; ((j < 3) && repeat); j++) //retry response getting if necessary 290 | { 291 | std::uint8_t ctrlBuffer2[32]; 292 | transferResult = libusb_interrupt_transfer(usbHandle, EP_INT_IN, ctrlBuffer2, 32, &actualLength, 32); 293 | if (transferResult == LIBUSB_SUCCESS) 294 | { 295 | if (ctrlBuffer2[0] == 0x84) 296 | { 297 | firmwareVersion = ((ctrlBuffer2[1] << 0) | 298 | (ctrlBuffer2[2] << 8) | 299 | (ctrlBuffer2[3] << 16) | 300 | (ctrlBuffer2[4] << 24)); 301 | repeat = false; 302 | } 303 | } 304 | } 305 | } 306 | } 307 | 308 | 309 | //send sdk firmware version 310 | repeat = true; 311 | for (int i = 0; ((i < 2) && repeat); i++) //retry command if necessary 312 | { 313 | std::uint8_t ctrlBuffer3[2] = { 0x07, HELIOS_SDK_VERSION }; 314 | int transferResult = libusb_interrupt_transfer(usbHandle, EP_INT_OUT, ctrlBuffer3, 2, &actualLength, 32); 315 | if ((transferResult == LIBUSB_SUCCESS) && (actualLength == 2)) 316 | repeat = false; 317 | } 318 | 319 | frameBuffer = new std::uint8_t[HELIOS_MAX_POINTS * 7 + 5]; 320 | 321 | closed = false; 322 | 323 | std::thread frameHandlerThread(&HeliosDac::HeliosDacDevice::FrameHandler, this); 324 | frameHandlerThread.detach(); 325 | } 326 | 327 | //sends a raw frame buffer (implemented as bulk transfer) to a dac device 328 | //returns 1 if success 329 | int HeliosDac::HeliosDacDevice::SendFrame(unsigned int pps, std::uint8_t flags, HeliosPoint* points, unsigned int numOfPoints) 330 | { 331 | if (closed) 332 | return HELIOS_ERROR_DEVICE_CLOSED; 333 | 334 | if (frameReady) 335 | return HELIOS_ERROR_DEVICE_FRAME_READY; 336 | 337 | unsigned int bufPos = 0; 338 | 339 | //this is a bug workaround, the mcu won't correctly receive transfers with these sizes 340 | unsigned int ppsActual = pps; 341 | unsigned int numOfPointsActual = numOfPoints; 342 | if ((((int)numOfPoints-45) % 64) == 0) 343 | { 344 | numOfPointsActual--; 345 | //adjust pps to keep the same frame duration even with one less point 346 | ppsActual = (unsigned int)((pps * (double)numOfPointsActual / (double)numOfPoints) + 0.5); 347 | } 348 | 349 | //prepare frame buffer 350 | for (unsigned int i = 0; i < numOfPointsActual; i++) 351 | { 352 | frameBuffer[bufPos++] = (points[i].x >> 4); 353 | frameBuffer[bufPos++] = ((points[i].x & 0x0F) << 4) | (points[i].y >> 8); 354 | frameBuffer[bufPos++] = (points[i].y & 0xFF); 355 | frameBuffer[bufPos++] = points[i].r; 356 | frameBuffer[bufPos++] = points[i].g; 357 | frameBuffer[bufPos++] = points[i].b; 358 | frameBuffer[bufPos++] = points[i].i; 359 | } 360 | frameBuffer[bufPos++] = (ppsActual & 0xFF); 361 | frameBuffer[bufPos++] = (ppsActual >> 8); 362 | frameBuffer[bufPos++] = (numOfPointsActual & 0xFF); 363 | frameBuffer[bufPos++] = (numOfPointsActual >> 8); 364 | frameBuffer[bufPos++] = flags; 365 | 366 | frameBufferSize = bufPos; 367 | 368 | if ((flags & HELIOS_FLAGS_DONT_BLOCK) != 0) 369 | { 370 | frameReady = true; 371 | return HELIOS_SUCCESS; 372 | } 373 | else 374 | { 375 | return DoFrame(); 376 | } 377 | } 378 | 379 | //sends frame to DAC 380 | int HeliosDac::HeliosDacDevice::DoFrame() 381 | { 382 | if (closed) 383 | return HELIOS_ERROR_DEVICE_CLOSED; 384 | 385 | int actualLength = 0; 386 | int transferResult = libusb_bulk_transfer(usbHandle, EP_BULK_OUT, frameBuffer, frameBufferSize, &actualLength, 8 + (frameBufferSize >> 5)); 387 | 388 | if (transferResult == LIBUSB_SUCCESS) 389 | return HELIOS_SUCCESS; 390 | else 391 | return HELIOS_ERROR_LIBUSB_BASE + transferResult; 392 | } 393 | 394 | //continually running thread, when a frame is ready, it is sent to the DAC 395 | //only used if HELIOS_FLAGS_DONT_BLOCK is used with writeframe 396 | void HeliosDac::HeliosDacDevice::FrameHandler() 397 | { 398 | while (!closed) 399 | { 400 | //wait until frame is ready to be sent 401 | while ((!frameReady) && (!closed)) 402 | std::this_thread::sleep_for(std::chrono::microseconds(100)); 403 | 404 | if (closed) 405 | return; 406 | 407 | DoFrame(); 408 | 409 | frameReady = false; 410 | } 411 | } 412 | 413 | 414 | //Gets firmware version of DAC 415 | int HeliosDac::HeliosDacDevice::GetFirmwareVersion() 416 | { 417 | if (closed) 418 | return HELIOS_ERROR_DEVICE_CLOSED; 419 | 420 | return firmwareVersion; 421 | } 422 | 423 | //Gets firmware version of DAC 424 | int HeliosDac::HeliosDacDevice::GetName(char* dacName) 425 | { 426 | if (closed) 427 | { 428 | return HELIOS_ERROR_DEVICE_CLOSED; 429 | } 430 | 431 | int errorCode; 432 | 433 | std::lock_guard lock(frameLock); 434 | 435 | for (int i = 0; (i < 2); i++) //retry command if necessary 436 | { 437 | int actualLength = 0; 438 | std::uint8_t ctrlBuffer4[2] = { 0x05, 0 }; 439 | if (SendControl(ctrlBuffer4, 2) == HELIOS_SUCCESS) 440 | { 441 | std::uint8_t ctrlBuffer5[32]; 442 | int transferResult = libusb_interrupt_transfer(usbHandle, EP_INT_IN, ctrlBuffer5, 32, &actualLength, 32); 443 | 444 | if (transferResult == LIBUSB_SUCCESS) 445 | { 446 | if (ctrlBuffer5[0] == 0x85) 447 | { 448 | ctrlBuffer5[31] = '\0'; 449 | memcpy(name, &ctrlBuffer5[1], 31); 450 | memcpy(dacName, &ctrlBuffer5[1], 31); 451 | return HELIOS_SUCCESS; 452 | } 453 | else 454 | { 455 | errorCode = HELIOS_ERROR_DEVICE_RESULT; 456 | } 457 | } 458 | else 459 | { 460 | errorCode = HELIOS_ERROR_LIBUSB_BASE + transferResult; 461 | } 462 | } 463 | else 464 | { 465 | errorCode = HELIOS_ERROR_DEVICE_SEND_CONTROL; 466 | } 467 | } 468 | 469 | return errorCode; 470 | } 471 | 472 | //Gets status of DAC, 1 means DAC is ready to receive frame, 0 means it's not 473 | int HeliosDac::HeliosDacDevice::GetStatus() 474 | { 475 | if (closed) 476 | return HELIOS_ERROR_DEVICE_CLOSED; 477 | 478 | int errorCode; 479 | 480 | std::lock_guard lock(frameLock); 481 | 482 | int actualLength = 0; 483 | std::uint8_t ctrlBuffer[2] = { 0x03, 0 }; 484 | if (SendControl(ctrlBuffer, 2) == HELIOS_SUCCESS) 485 | { 486 | std::uint8_t ctrlBuffer2[32]; 487 | int transferResult = libusb_interrupt_transfer(usbHandle, EP_INT_IN, ctrlBuffer2, 32, &actualLength, 16); 488 | if (transferResult == LIBUSB_SUCCESS) 489 | { 490 | if (ctrlBuffer2[0] == 0x83) //STATUS ID 491 | { 492 | if (ctrlBuffer2[1] == 0) 493 | return 0; 494 | else 495 | return 1; 496 | } 497 | else 498 | { 499 | errorCode = HELIOS_ERROR_DEVICE_RESULT; 500 | } 501 | } 502 | else 503 | { 504 | errorCode = HELIOS_ERROR_LIBUSB_BASE + transferResult; 505 | } 506 | } 507 | else 508 | { 509 | errorCode = HELIOS_ERROR_DEVICE_SEND_CONTROL; 510 | } 511 | 512 | return errorCode; 513 | } 514 | 515 | //Set shutter level of DAC 516 | int HeliosDac::HeliosDacDevice::SetShutter(bool level) 517 | { 518 | if (closed) 519 | return HELIOS_ERROR_DEVICE_CLOSED; 520 | 521 | std::lock_guard lock(frameLock); 522 | 523 | std::uint8_t txBuffer[2] = { 0x02, level }; 524 | if (SendControl(txBuffer, 2) == HELIOS_SUCCESS) 525 | return HELIOS_SUCCESS; 526 | else 527 | return HELIOS_ERROR_DEVICE_SEND_CONTROL; 528 | } 529 | 530 | //Stops output of DAC 531 | int HeliosDac::HeliosDacDevice::Stop() 532 | { 533 | if (closed) 534 | return HELIOS_ERROR_DEVICE_CLOSED; 535 | 536 | std::lock_guard lock(frameLock); 537 | 538 | std::uint8_t txBuffer[2] = { 0x01, 0 }; 539 | if (SendControl(txBuffer, 2) == HELIOS_SUCCESS) 540 | { 541 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 542 | return HELIOS_SUCCESS; 543 | } 544 | else 545 | return HELIOS_ERROR_DEVICE_SEND_CONTROL; 546 | } 547 | 548 | //Sets persistent name of DAC 549 | int HeliosDac::HeliosDacDevice::SetName(char* name) 550 | { 551 | if (closed) 552 | return HELIOS_ERROR_DEVICE_CLOSED; 553 | 554 | std::lock_guard lock(frameLock); 555 | 556 | std::uint8_t txBuffer[32] = { 0x06 }; 557 | memcpy(&txBuffer[1], name, 30); 558 | txBuffer[31] = '\0'; 559 | if (SendControl(txBuffer, 32) == HELIOS_SUCCESS) 560 | return HELIOS_SUCCESS; 561 | else 562 | return HELIOS_ERROR_DEVICE_SEND_CONTROL; 563 | } 564 | 565 | //Erases the firmware of the DAC, allowing it to be updated 566 | int HeliosDac::HeliosDacDevice::EraseFirmware() 567 | { 568 | if (closed) 569 | return HELIOS_ERROR_DEVICE_CLOSED; 570 | 571 | std::lock_guard lock(frameLock); 572 | 573 | std::uint8_t txBuffer[2] = { 0xDE, 0 }; 574 | if (SendControl(txBuffer, 2) == HELIOS_SUCCESS) 575 | { 576 | closed = true; 577 | return HELIOS_SUCCESS; 578 | } 579 | else 580 | return HELIOS_ERROR_DEVICE_SEND_CONTROL; 581 | } 582 | 583 | //sends a raw control signal (implemented as interrupt transfer) to a dac device 584 | //returns 1 if successful 585 | int HeliosDac::HeliosDacDevice::SendControl(std::uint8_t* bufferAddress, unsigned int length) 586 | { 587 | if (bufferAddress == NULL) 588 | return HELIOS_ERROR_DEVICE_NULL_BUFFER; 589 | 590 | if (length > 32) 591 | return HELIOS_ERROR_DEVICE_SIGNAL_TOO_LONG; 592 | 593 | int actualLength = 0; 594 | int transferResult = libusb_interrupt_transfer(usbHandle, EP_INT_OUT, bufferAddress, length, &actualLength, 16); 595 | 596 | if (transferResult == LIBUSB_SUCCESS) 597 | return HELIOS_SUCCESS; 598 | else 599 | return HELIOS_ERROR_LIBUSB_BASE + transferResult; 600 | } 601 | 602 | HeliosDac::HeliosDacDevice::~HeliosDacDevice() 603 | { 604 | closed = true; 605 | std::lock_guardlock(frameLock); //wait until all threads have closed 606 | 607 | libusb_close(usbHandle); 608 | delete frameBuffer; 609 | } 610 | -------------------------------------------------------------------------------- /src/pd-lib-builder/Makefile.pdlibbuilder: -------------------------------------------------------------------------------- 1 | # Makefile.pdlibbuilder dated 2018-03-15 2 | version = 0.5.1 3 | 4 | # Helper makefile for Pure Data external libraries. 5 | # Written by Katja Vetter March-June 2015 for the public domain. No warranties. 6 | # Inspired by Hans Christoph Steiner's Makefile Template and Stephan Beal's 7 | # ShakeNMake. 8 | # 9 | # Grab the newest version of Makefile.pdlibbuilder from 10 | # https://github.com/pure-data/pd-lib-builder/ 11 | # 12 | # GNU make version >= 3.81 required. 13 | # 14 | # 15 | #=== characteristics =========================================================== 16 | # 17 | # 18 | # - defines build settings based on autodetected OS and architecture 19 | # - defines rules to build Pd class- or lib executables from C or C++ sources 20 | # - defines rules for libdir installation 21 | # - defines convenience targets for developer and user 22 | # - evaluates implicit dependencies for non-clean builds 23 | # 24 | # 25 | #=== basic usage =============================================================== 26 | # 27 | # 28 | # In your Makefile, define your Pd lib name and class files, and include 29 | # Makefile.pdlibbuilder at the end of the Makefile. Like so: 30 | # 31 | # ________________________________________________________________________ 32 | # 33 | # # Makefile for mylib 34 | # 35 | # lib.name = mylib 36 | # 37 | # class.sources = myclass1.c myclass2.c 38 | # 39 | # datafiles = myclass1-help.pd myclass2-help.pd README.txt LICENSE.txt 40 | # 41 | # include Makefile.pdlibbuilder 42 | # ________________________________________________________________________ 43 | # 44 | # 45 | # For files in class.sources it is assumed that class basename == source file 46 | # basename. The default target builds all classes as individual executables 47 | # with Pd's default extension for the platform. For anything more than the 48 | # most basic usage, continue reading. 49 | # 50 | # 51 | #=== list of Makefile.pdlibbuilder API variables =============================== 52 | # 53 | # 54 | # Variables available for definition in your library Makefile: 55 | # 56 | # - lib.name 57 | # - lib.setup.sources 58 | # - class.sources 59 | # - common.sources 60 | # - shared.sources 61 | # - .class.sources 62 | # - .class.ldflags 63 | # - .class.ldlibs 64 | # - cflags 65 | # - ldflags 66 | # - ldlibs 67 | # - datafiles 68 | # - datadirs 69 | # - makefiles 70 | # - makefiledirs 71 | # - externalsdir 72 | # 73 | # Optional multiline defines evaluated per operating system: 74 | # 75 | # - forLinux 76 | # - forDarwin 77 | # - forWindows 78 | # 79 | # Variables available for your makefile or make command line: 80 | # 81 | # - make-lib-executable 82 | # - suppress-wunused 83 | # 84 | # Path variables for make command line or environment: 85 | # 86 | # - PDDIR 87 | # - PDINCLUDEDIR 88 | # - PDBINDIR 89 | # - PDLIBDIR 90 | # 91 | # Standard make variables for make command line or environment: 92 | # 93 | # - CPPFLAGS 94 | # - CFLAGS 95 | # - LDFLAGS 96 | # - CC 97 | # - CXX 98 | # - INSTALL 99 | # - STRIP 100 | # - DESTDIR 101 | # 102 | # Deprecated path variables: 103 | # 104 | # - pdincludepath 105 | # - pdbinpath 106 | # - objectsdir 107 | # 108 | # 109 | #=== descriptions of Makefile.pdlibbuilder API variables ======================= 110 | # 111 | # 112 | # lib.name: 113 | # Name of the library directory as it will be installed / distributed. Also the 114 | # name of the lib executable in the case where all classes are linked into 115 | # a single binary. 116 | # 117 | # lib.setup.sources: 118 | # Source file(s) (C or C++) which must be compiled only when linking all classes 119 | # into a single lib binary. 120 | # 121 | # class.sources: 122 | # All sources files (C or C++) for which the condition holds that 123 | # class name == source file basename. 124 | # 125 | # .class.sources: 126 | # Source file(s) (C or C++) specific to class . Use this for 127 | # multiple-source classes or when class name != source file basename. 128 | # 129 | # common.sources: 130 | # Source file(s) which must be statically linked to each class in the library. 131 | # 132 | # shared.sources: 133 | # Source file(s) (C or C++) to build a shared dynamic link lib, to be linked 134 | # with all class executables. 135 | # 136 | # cflags, ldflags, ldlibs: 137 | # Define cflags (preprocessor&compiler), ldflags (linker) and ldlibs (dynamic 138 | # link libs) for the whole library. These flags are added to platform-specific 139 | # flags defined by Makefile.pdlibbuilder. 140 | # 141 | # .class.ldflags and .class.ldlibs: 142 | # Define ldflags resp. ldlibs specific to class . These flags are 143 | # added to platform-specific flags defined by Makefile.pdlibbuilder, and flags 144 | # defined in your Makefile for the whole library. Note: cflags can not be 145 | # defined per class in the current implementation. 146 | # 147 | # datafiles and datadirs: 148 | # All extra files you want to include in binary distributions of the 149 | # library: abstractions and help patches, example patches, meta patch, readme 150 | # and license texts, manuals, sound files, etcetera. Use 'datafiles' for all 151 | # files that should go into your lib rootdir and 'datadirs' for complete 152 | # directories you want to copy from source to distribution. 153 | # 154 | # forLinux, forDarwin, forWindows: 155 | # Shorthand for 'variable definitions for Linux only' etc. Use like: 156 | # define forLinux 157 | # cflags += -DLINUX 158 | # class.sources += linuxthing.c 159 | # endef 160 | # 161 | # makefiles and makefiledirs: 162 | # Extra makefiles or directories with makefiles that should be made in sub-make 163 | # processes. 164 | # 165 | # make-lib-executable: 166 | # When this variable is defined 'yes' in your makefile or as command argument, 167 | # Makefile.pdlibbuilder will try to build all classes into a single library 168 | # executable (but it will force exit if lib.setup.sources is undefined). 169 | # If your makefile defines 'make-lib-executable=yes' as the library default, 170 | # this can still be overridden with 'make-lib-executable=no' as command argument 171 | # to build individual class executables (the Makefile.pdlibbuilder default.) 172 | # 173 | # suppress-wunused: 174 | # When this variable is defined ('yes' or any other value), -Wunused-variable, 175 | # -Wunused-parameter, -Wunused-value and -Wunused-function are suppressed, 176 | # but the other warnings from -Wall are retained. 177 | # 178 | # PDDIR: 179 | # Root directory of 'portable' pd package. When defined, PDINCLUDEDIR and 180 | # PDBINDIR will be evaluated as $(PDDIR)/src and $(PDDIR)/bin. 181 | # 182 | # PDINCLUDEDIR: 183 | # Directory where Pd API m_pd.h should be found, and other Pd header files. 184 | # Overrides the default search path. 185 | # 186 | # PDBINDIR: 187 | # Directory where pd.dll should be found for linking (Windows only). Overrides 188 | # the default search path. 189 | # 190 | # PDLIBDIR: 191 | # Root directory for installation of Pd library directories. Overrides the 192 | # default install location. 193 | # 194 | # DESTDIR: 195 | # Prepended path component for staged install. 196 | # 197 | # CPPFLAGS: 198 | # Preprocessor flags which are not strictly required for building. 199 | # 200 | # CFLAGS: 201 | # Compiler flags which are not strictly required for building. Compiler flags 202 | # defined by Makefile.pdlibbuilder for warning, optimization and architecture 203 | # specification are overriden by CFLAGS. 204 | # 205 | # LDFLAGS: 206 | # Linker flags which are not strictly required for building. Linker flags 207 | # defined by Makefile.pdlibbuilder for architecture specification are overriden 208 | # by LDFLAGS. 209 | # 210 | # CC and CXX: 211 | # C and C++ compiler programs as defined in your build environment. 212 | # 213 | # INSTALL 214 | # Definition of install program. 215 | # 216 | # STRIP 217 | # Name of strip program. Default 'strip' can be overridden in cross compilation 218 | # environments. 219 | # 220 | # objectsdir: 221 | # Root directory for installation of Pd library directories, like PDLIBDIR but 222 | # not overridable by environment. Supported for compatibility with pd-extended 223 | # central makefile, but deprecated otherwise. 224 | # 225 | # pdincludepath, pdbinpath: 226 | # As PDINCLUDEDIR and PDBINDIR but not overridable by environment. Deprecated 227 | # as user variables. 228 | # 229 | # 230 | #=== paths ===================================================================== 231 | # 232 | # 233 | # Source files in directories other than current working directory must be 234 | # prefixed with their relative path. Do not rely on VPATH or vpath. 235 | # Object (.o) files are built in the directory of their source files. 236 | # Executables are built in current working directory. 237 | # 238 | # Default search path for m_pd.h and other API header files is platform 239 | # dependent, and overridable by PDINCLUDEDIR: 240 | # 241 | # Linux: /usr/include/pd 242 | # 243 | # OSX: /Applications/Pd*.app/Contents/Resources/src 244 | # 245 | # Windows: %PROGRAMFILES%/Pd/src 246 | # %PROGRAMFILES(X86)%/Pd/src (32 bit builds on 64 bit Windows) 247 | # 248 | # Default search path for binary pd.dll (Windows), overridable by PDBINDIR 249 | # 250 | # %PROGRAMFILES%/Pd/bin 251 | # %PROGRAMFILES(X86)%/Pd/bin (32 bit builds on 64 bit Windows) 252 | # 253 | # Default location to install pd libraries is platform dependent, and 254 | # overridable by PDLIBDIR: 255 | # 256 | # Linux: /usr/local/lib/pd-externals 257 | # OSX: ~/Library/Pd 258 | # Windows: %APPDATA%/Pd 259 | # 260 | # https://puredata.info/docs/faq/how-do-i-install-externals-and-help-files 261 | # The rationale for not installing to ~/pd-externals by default on Linux 262 | # is that some people share the home dir between 32 and 64 bit installations. 263 | # 264 | # 265 | #=== targets =================================================================== 266 | # 267 | # 268 | # all: build $(executables) plus optional post target 269 | # post: target to build after $(executables) 270 | # alldebug: build all with -g option turned on for debug symbols 271 | # : force clean build of an individual class 272 | # .pre: make preprocessor output file in current working directory 273 | # .lst: make asm/source output file in current working directory 274 | # 275 | # install: install executables and data files 276 | # clean: remove build products from source tree 277 | # 278 | # help: print help text 279 | # vars: print makefile variables 280 | # allvars: print all variables 281 | # depend: print generated prerequisites 282 | # coffee: dummy target 283 | # 284 | # Variable $(executables) expands to class executables plus optional shared lib, 285 | # or alternatively to single lib executable when make-lib-executable=true. 286 | # Targets pre and post can be defined by library makefile. Make sure to include 287 | # Makefile.pdlibbuilder first so default target all will not be redefined. 288 | # 289 | # 290 | #=== Pd-extended libdir concept ================================================ 291 | # 292 | # 293 | # For libdir layout as conceived by Hans-Christoph Steiner, see: 294 | # 295 | # https://puredata.info/docs/developer/Libdir 296 | # 297 | # Files README.txt, LICENSE.txt and -meta.pd are part of the libdir 298 | # convention. Help patches for each class and abstraction are supposed to be 299 | # available. Makefile.pdlibbuilder does not force the presence of these files 300 | # however. It does not automatically include such files in libdir installations. 301 | # Data files you want to include in distributions must be defined explicitly in 302 | # your Makefile. 303 | # 304 | # 305 | #=== Makefile.pdlibbuilder syntax conventions ================================== 306 | # 307 | # 308 | # Makefile.pdlibbuilder variable names are lower case. Default make variables, 309 | # environment variables, and standard user variables (CC, CXX, CFLAGS, DESTDIR) 310 | # are upper case. Use target 'allvars' to print all variables and their values. 311 | # 312 | # 'Fields' in data variables are separated by dots, like in 'foo.class.sources'. 313 | # Words in variables expressing a function or command are separated by dashes, 314 | # like in 'make-lib-executable'. 315 | # 316 | # 317 | #=== useful make options ======================================================= 318 | # 319 | # 320 | # Use 'make -d ' to print debug details of the make process. 321 | # Use 'make -p ' to print make's database. 322 | # 323 | # 324 | #=== TODO ====================================================================== 325 | # 326 | # 327 | # - decide whether to use -static-libgcc or shared dll in MinGW 328 | # - cygwin support 329 | # - android support 330 | # - figure out how to handle '$' in filenames 331 | # - add makefile template targets dpkg-source dist libdir distclean tags? 332 | # 333 | # 334 | #=== end of documentation sections ============================================= 335 | # 336 | # 337 | ################################################################################ 338 | ################################################################################ 339 | ################################################################################ 340 | 341 | 342 | # GNU make version 3.81 (2006) or higher is required because of the following: 343 | # - function 'info' 344 | # - variable '.DEFAULT_GOAL' 345 | 346 | # force exit when make version is < 3.81 347 | ifneq ($(firstword $(sort 3.81 $(MAKE_VERSION))), 3.81) 348 | $(error GNU make version 3.81 or higher is required) 349 | endif 350 | 351 | # Relative path to externals root dir in multi-lib source tree like 352 | # pd-extended SVN. Default is parent of current working directory. May be 353 | # defined differently in including makefile. 354 | externalsdir ?= .. 355 | 356 | # variable you can use to check if Makefile.pdlibbuilder is already included 357 | Makefile.pdlibbuilder = true 358 | 359 | 360 | ################################################################################ 361 | ### variables: library name and version ######################################## 362 | ################################################################################ 363 | 364 | 365 | # strip possibles spaces from lib.name, they mess up calculated file names 366 | lib.name := $(strip $(lib.name)) 367 | 368 | # if meta file exists, check library version 369 | metafile := $(wildcard $(lib.name)-meta.pd) 370 | 371 | ifdef metafile 372 | lib.version := $(shell sed -n \ 373 | 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' \ 374 | $(metafile)) 375 | endif 376 | 377 | 378 | ################################################################################ 379 | ### variables: files ########################################################### 380 | ################################################################################ 381 | 382 | 383 | #=== sources =================================================================== 384 | 385 | 386 | # (re)define .class.sources using file names in class.sources 387 | 388 | define add-class-source 389 | $(notdir $(basename $v)).class.sources += $v 390 | endef 391 | 392 | $(foreach v, $(class.sources), $(eval $(add-class-source))) 393 | 394 | # derive class names from .class.sources variables 395 | sourcevariables := $(filter %.class.sources, $(.VARIABLES)) 396 | classes := $(basename $(basename $(sourcevariables))) 397 | 398 | # accumulate all source files specified in makefile 399 | classes.sources := $(sort $(foreach v, $(sourcevariables), $($v))) 400 | all.sources := $(classes.sources) $(lib.setup.sources) \ 401 | $(shared.sources) $(common.sources) 402 | 403 | 404 | #=== object files ============================================================== 405 | 406 | 407 | # construct object filenames from all C and C++ source file names 408 | classes.objects := $(addsuffix .o, $(basename $(classes.sources))) 409 | common.objects := $(addsuffix .o, $(basename $(common.sources))) 410 | shared.objects := $(addsuffix .o, $(basename $(shared.sources))) 411 | lib.setup.objects := $(addsuffix .o, $(basename $(lib.setup.sources))) 412 | all.objects = $(classes.objects) $(common.objects) $(shared.objects) \ 413 | $(lib.setup.objects) 414 | 415 | 416 | #=== executables =============================================================== 417 | 418 | 419 | # use recursive variables here because executable extension is not yet known 420 | 421 | # construct class executable names from class names 422 | classes.executables = $(addsuffix .$(extension), $(classes)) 423 | 424 | # construct shared lib executable name if shared sources are defined 425 | ifdef shared.sources 426 | shared.lib = lib$(lib.name).$(shared.extension) 427 | else 428 | shared.lib = 429 | endif 430 | 431 | 432 | ################################################################################ 433 | ### platform detection ######################################################### 434 | ################################################################################ 435 | 436 | 437 | #=== operating system ========================================================== 438 | 439 | 440 | # The following systems are defined: Linux, Darwin, Windows. GNU and 441 | # GNU/kFreeBSD are treated as Linux to get the same options. 442 | 443 | uname := $(shell uname) 444 | 445 | ifeq ($(findstring $(uname), Linux GNU GNU/kFreeBSD), $(uname)) 446 | system = Linux 447 | endif 448 | 449 | ifeq ($(uname), Darwin) 450 | system = Darwin 451 | endif 452 | 453 | ifeq ($(filter MINGW% MSYS%, $(uname)), $(uname)) 454 | system = Windows 455 | endif 456 | 457 | # Unfortunately not all Mingw versions provide a link cc > gcc, therefore 458 | # gcc is hardcoded here (but not if CC is redefined). 459 | ifeq ($(system), Windows) 460 | ifeq ($(origin CC), default) 461 | CC = gcc 462 | endif 463 | endif 464 | 465 | # evaluate possible system-specific multiline defines from library makefile 466 | $(eval $(for$(system))) 467 | 468 | 469 | # TODO: Cygwin, Android 470 | 471 | 472 | #=== architecture ============================================================== 473 | 474 | 475 | # native architecture of the build machine 476 | build.arch := $(shell uname -m) 477 | 478 | # Target architecture as reported by compiler. Give precedence to eventual 479 | # user-defined compiler. The first field of -- is extracted. 480 | ifneq ($(origin CXX), default) 481 | dumpmachine.cpu = $(firstword $(subst -, ,$(shell $(CXX) -dumpmachine))) 482 | else 483 | dumpmachine.cpu = $(firstword $(subst -, ,$(shell $(CC) -dumpmachine))) 484 | endif 485 | 486 | # Target architecture as reported by compiler is only used for Windows at the 487 | # moment. For other systems this still has to be tested. 488 | ifeq ($(system), Windows) 489 | target.arch = $(dumpmachine.cpu) 490 | else 491 | target.arch = $(build.arch) 492 | endif 493 | 494 | 495 | ################################################################################ 496 | ### variables per platform ##################################################### 497 | ################################################################################ 498 | 499 | 500 | #=== flags per architecture ==================================================== 501 | 502 | 503 | # Set architecture-dependent cflags, mainly for Linux. For Mac and Windows, 504 | # arch.c.flags are overriden below. 505 | 506 | # Raspberry Pi 1st generation 507 | ifeq ($(target.arch), armv6l) 508 | arch.c.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard 509 | 510 | # Beagle, Udoo, RPi2 etc. 511 | else ifeq ($(target.arch), armv7l) 512 | arch.c.flags = -march=armv7-a -mfpu=vfpv3 -mfloat-abi=hard 513 | 514 | # Intel 32 bit, build with SSE and SSE2 instructions 515 | else ifeq ($(findstring $(target.arch), i386 i686), $(target.arch)) 516 | arch.c.flags = -march=pentium4 -mfpmath=sse -msse -msse2 517 | 518 | # Intel/AMD 64 bit, build with SSE, SSE2 and SSE3 instructions 519 | else ifeq ($(findstring $(target.arch), x86_64), $(target.arch)) 520 | arch.c.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3 521 | 522 | # if none of the above architectures detected 523 | else 524 | arch.c.flags = 525 | endif 526 | 527 | 528 | #=== flags and paths for Linux ================================================= 529 | 530 | 531 | ifeq ($(system), Linux) 532 | prefix = /usr/local 533 | libdir := $(prefix)/lib 534 | pkglibdir = $(libdir)/pd-externals 535 | pdincludepath := $(wildcard /usr/include/pd) 536 | extension = pd_linux 537 | cpp.flags := -DUNIX -std=c++14 538 | c.flags := -fPIC 539 | c.ldflags := -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags 540 | c.ldlibs := -lc -lm 541 | cxx.flags := -fPIC -fcheck-new 542 | cxx.ldflags := -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags 543 | cxx.ldlibs := -lc -lm -lstdc++ 544 | shared.extension = so 545 | shared.ldflags := -rdynamic -fPIC -shared -Wl,-soname,$(shared.lib) 546 | endif 547 | 548 | 549 | #=== flags and paths for Darwin ================================================ 550 | 551 | 552 | # On OSX we try to build fat binaries by default. It is assumed that OSX i386 553 | # can build for ppc and OSX x86_64 can't. TODO: try to refine this condition. 554 | # LLVM-clang doesn't support -fcheck-new, therefore this flag is omitted for 555 | # OSX x86_64. 556 | 557 | 558 | ifeq ($(system), Darwin) 559 | pkglibdir = $(HOME)/Library/Pd 560 | pdincludepath := $(firstword $(wildcard \ 561 | /Applications/Pd*.app/Contents/Resources/src)) 562 | extension = pd_darwin 563 | cpp.flags := -DUNIX -DMACOSX -I /sw/include -std=c++14 564 | c.flags := 565 | c.ldflags := -undefined suppress -flat_namespace -bundle 566 | c.ldlibs := -lc 567 | cxx.ldflags := -undefined suppress -flat_namespace -bundle 568 | cxx.ldlibs := -lc 569 | shared.extension = dylib 570 | shared.ldflags = -dynamiclib -undefined dynamic_lookup \ 571 | -install_name @loader_path/$(shared.lib) \ 572 | -compatibility_version 1 -current_version 1.0 573 | version.flag := $(filter $(cflags), -mmacosx-version-min=%) 574 | arch := i386 x86_64 575 | version.flag = -mmacosx-version-min=10.10 576 | 577 | ifneq ($(filter -mmacosx-version-min=%, $(cflags)),) 578 | version.flag := $(filter -mmacosx-version-min=%, $(cflags)) 579 | endif 580 | arch.c.flags := $(addprefix -arch , $(arch)) $(version.flag) 581 | arch.ld.flags := $(arch.c.flags) 582 | endif 583 | 584 | 585 | #=== flags and paths for Windows =============================================== 586 | 587 | 588 | # Standard paths on Windows contain spaces, and GNU make functions treat such 589 | # paths as lists, with unintended effects. Therefore we must use shell function 590 | # ls instead of make's wildcard when probing for a path, and use double quotes 591 | # when specifying a path in a command argument. 592 | 593 | # Default paths in Mingw / Mingw-w64 environments. 'PROGRAMFILES' is standard 594 | # location for builds with native architecture, 'ProgramFiles(x86)' for i686 595 | # builds on x86_64 Windows (detection method by Lucas Cordiviola). Curly braces 596 | # required because of parentheses in variable name. 597 | ifeq ($(system), Windows) 598 | pkglibdir := $(APPDATA)/Pd 599 | ifeq ($(MINGW_CHOST), i686-w64-mingw32) 600 | programfiles := ${ProgramFiles(x86)} 601 | else 602 | programfiles := $(PROGRAMFILES) 603 | endif 604 | pdbinpath := $(programfiles)/Pd/bin 605 | pdincludepath := $(programfiles)/Pd/src 606 | endif 607 | 608 | # Store default path to pd.dll in PDBINDIR if the latter is not user-defined. 609 | # For include path this is done in the platform-independent paths section below, 610 | # but for PDBINDIR it is done here so ld flags can be evaluated as immediate 611 | # variables. 612 | ifeq ($(system), Windows) 613 | ifdef PDDIR 614 | PDBINDIR := $(PDDIR)/bin 615 | endif 616 | PDBINDIR ?= $(pdbinpath) 617 | endif 618 | 619 | # TODO: decide whether -mms-bitfields should be specified. 620 | ifeq ($(system), Windows) 621 | cpp.flags := -DMSW -DNT 622 | ifeq ($(filter i%86 mingw32, $(target.arch)), $(target.arch)) 623 | arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse 624 | else ifeq (x86_64, $(target.arch)) 625 | cpp.flags := -DMSW -DNT -DPD_LONGINTTYPE=__int64 626 | arch.c.flags := -march=core2 -msse -msse2 -msse3 -mfpmath=sse 627 | else 628 | arch.c.flags = 629 | endif 630 | extension = dll 631 | c.flags := 632 | c.ldflags := -static-libgcc -shared \ 633 | -Wl,--enable-auto-import "$(PDBINDIR)/pd.dll" 634 | c.ldlibs := 635 | cxx.flags := -fcheck-new 636 | cxx.ldflags := -static-libgcc -static-libstdc++ -shared \ 637 | -Wl,--enable-auto-import "$(PDBINDIR)/pd.dll" 638 | cxx.ldlibs := 639 | shared.extension = dll 640 | shared.ldflags := -static-libgcc -shared "$(PDBINDIR)/pd.dll" 641 | stripflags = --strip-all 642 | endif 643 | 644 | 645 | #=== paths ===================================================================== 646 | 647 | 648 | # Platform-dependent default paths are specified above, but overridable. 649 | # Path variables in upper case can be defined as make command argument or in the 650 | # environment. Variable 'objectsdir' is supported for compatibility with 651 | # the build system that pd-l2ork has inherited from pd-extended. 652 | 653 | PDINCLUDEDIR ?= $(pdincludepath) 654 | PDLIBDIR ?= $(firstword $(objectsdir) $(pkglibdir)) 655 | 656 | ifdef PDDIR 657 | PDINCLUDEDIR := $(wildcard $(PDDIR)/src) 658 | endif 659 | 660 | # base path where all components of the lib will be installed by default 661 | installpath := $(DESTDIR)$(PDLIBDIR)/$(lib.name) 662 | 663 | # check if include path contains spaces (as is often the case on Windows) 664 | # if so, store the path so we can later do checks with it 665 | pdincludepathwithspaces := $(if $(word 2, $(PDINCLUDEDIR)), $(PDINCLUDEDIR)) 666 | 667 | 668 | #=== accumulated build flags =================================================== 669 | 670 | 671 | # From GNU make docs: 'Users expect to be able to specify CFLAGS freely 672 | # themselves.' So we use CFLAGS to define options which are not strictly 673 | # required for compilation: optimizations, architecture specifications, and 674 | # warnings. CFLAGS can be safely overriden using a make command argument. 675 | # Variables cflags, ldflags and ldlibs may be defined in including makefile. 676 | 677 | optimization.flags = -O3 -ffast-math -funroll-loops -fomit-frame-pointer 678 | warn.flags = -Wall -Wextra -Wshadow -Winline -Wstrict-aliasing 679 | 680 | # suppress -Wunused-variable & Co if you don't want to clutter a build log 681 | ifdef suppress-wunused 682 | warn.flags += $(addprefix -Wno-unused-, function parameter value variable) 683 | endif 684 | 685 | CFLAGS = $(warn.flags) $(optimization.flags) $(arch.c.flags) 686 | 687 | # preprocessor flags 688 | cpp.flags := -DPD -I "$(PDINCLUDEDIR)" $(cpp.flags) $(CPPFLAGS) 689 | 690 | # flags for dependency checking (cflags from makefile may define -I options) 691 | depcheck.flags := $(cpp.flags) $(cflags) 692 | 693 | # architecture specifications for linker are overridable by LDFLAGS 694 | LDFLAGS := $(arch.ld.flags) 695 | 696 | # now add the same ld flags to shared dynamic lib 697 | shared.ldflags := $(shared.ldflags) $(LDFLAGS) 698 | 699 | # accumulated flags for C compiler / linker 700 | c.flags := $(cpp.flags) $(c.flags) $(cflags) $(CFLAGS) 701 | c.ldflags := $(c.ldflags) $(ldflags) $(LDFLAGS) 702 | c.ldlibs := $(c.ldlibs) $(ldlibs) 703 | 704 | # accumulated flags for C++ compiler / linker 705 | cxx.flags := $(cpp.flags) $(cxx.flags) $(cflags) $(CFLAGS) 706 | cxx.ldflags := $(cxx.ldflags) $(ldflags) $(LDFLAGS) 707 | cxx.ldlibs := $(cxx.ldlibs) $(ldlibs) 708 | 709 | 710 | ################################################################################ 711 | ### variables: tools ########################################################### 712 | ################################################################################ 713 | 714 | 715 | # aliases so we can later define 'compile-$1' and set 'c' or 'cxx' as argument 716 | compile-c := $(CC) 717 | compile-cxx := $(CXX) 718 | 719 | 720 | ################################################################################ 721 | ### checks ##################################################################### 722 | ################################################################################ 723 | 724 | 725 | # At this point most variables are defined. Now do some checks and info's 726 | # before rules begin. 727 | 728 | # 'forward declaration' of default target, needed to do checks 729 | all: 730 | 731 | # To avoid unpredictable results, make sure the default target is not redefined 732 | # by including makefile. 733 | ifneq ($(.DEFAULT_GOAL), all) 734 | $(error Default target must be 'all'.) 735 | endif 736 | 737 | # find out which target(s) will be made 738 | ifdef MAKECMDGOALS 739 | goals := $(MAKECMDGOALS) 740 | else 741 | goals := all 742 | endif 743 | 744 | # store path to Pd API m_pd.h if it is found 745 | ifdef PDINCLUDEDIR 746 | mpdh := $(shell ls "$(PDINCLUDEDIR)/m_pd.h") 747 | endif 748 | 749 | # store path to pd.dll; if not found, ls will give a useful error 750 | ifeq ($(system), Windows) 751 | pddll := $(shell ls "$(PDBINDIR)/pd.dll") 752 | endif 753 | 754 | # print Makefile.pdlibbuilder version 755 | $(info ++++ info: using Makefile.pdlibbuilder version $(version)) 756 | 757 | # when making target all, check if m_pd.h is found and print info about it 758 | ifeq ($(goals), all) 759 | $(if $(mpdh), \ 760 | $(info ++++ info: using Pd API $(mpdh)), \ 761 | $(warning Where is Pd API m_pd.h? Do 'make help' for info.)) 762 | endif 763 | 764 | # print target info 765 | $(info ++++ info: making target $(goals) $(if $(lib.name),in lib $(lib.name))) 766 | 767 | # when installing, print installpath info 768 | $(if $(filter install install-lib, $(goals)), $(info ++++ info: \ 769 | installpath is '$(installpath)')) 770 | 771 | 772 | #=== define executables ======================================================== 773 | 774 | 775 | # By default we build class executables, and optionally a shared dynamic link 776 | # lib. When make-lib-executable=yes we build all classes into a single lib 777 | # executable, on the condition that variable lib.setup.sources is defined. 778 | 779 | ifeq ($(make-lib-executable),yes) 780 | $(if $(lib.setup.sources), ,\ 781 | $(error Can not build library blob because lib.setup.sources is undefined)) 782 | executables := $(lib.name).$(extension) 783 | else 784 | executables := $(classes.executables) $(shared.lib) 785 | endif 786 | 787 | 788 | ################################################################################ 789 | ### rules: special targets ##################################################### 790 | ################################################################################ 791 | 792 | 793 | # Disable built-in rules. If some target can't be built with the specified 794 | # rules, it should not be built at all. 795 | MAKEFLAGS += --no-builtin-rules 796 | 797 | .PRECIOUS: 798 | .SUFFIXES: 799 | .PHONY: all post build-lib \ 800 | $(classes) $(makefiledirs) $(makefiles) \ 801 | install install-executables install-datafiles install-datadirs \ 802 | force clean vars allvars depend help 803 | 804 | 805 | ################################################################################ 806 | ### rules: build targets ####################################################### 807 | ################################################################################ 808 | 809 | 810 | # Target all forces the build of targets [$(executables) post] in 811 | # deterministic order. Target $(executables) builds class executables plus 812 | # optional shared lib or alternatively a single lib executable when 813 | # make-lib-executable=true. Target post is optionally defined by 814 | # library makefile. 815 | 816 | all: post 817 | post: $(executables) 818 | 819 | all: 820 | $(info ++++info: target all in lib $(lib.name) completed) 821 | 822 | # build all with -g option turned on for debug symbols 823 | alldebug: c.flags += -g 824 | alldebug: cxx.flags += -g 825 | alldebug: all 826 | 827 | 828 | #=== class executable ========================================================== 829 | 830 | 831 | # recipe for linking objects in class executable 832 | # argument $1 = compiler type (c or cxx) 833 | # argument $2 = class basename 834 | define link-class 835 | $(compile-$1) \ 836 | $($1.ldflags) $($2.class.ldflags) \ 837 | -o $2.$(extension) \ 838 | $(addsuffix .o, $(basename $($2.class.sources))) \ 839 | $(addsuffix .o, $(basename $(common.sources))) \ 840 | $($1.ldlibs) $($2.class.ldlibs) $(shared.lib) 841 | endef 842 | 843 | # general rule for linking object files in class executable 844 | %.$(extension): $(shared.lib) 845 | $(info ++++ info: linking objects in $@ for lib $(lib.name)) 846 | $(if $(filter %.cc %.cpp, $($*.class.sources)), \ 847 | $(call link-class,cxx,$*), \ 848 | $(call link-class,c,$*)) 849 | 850 | 851 | #=== library blob ============================================================== 852 | 853 | 854 | # build all classes into single executable 855 | build-lib: $(lib.name).$(extension) 856 | $(info ++++ info: library blob $(lib.name).$(extension) completed) 857 | 858 | # recipe for linking objects in lib executable 859 | # argument $1 = compiler type (c or cxx) 860 | define link-lib 861 | $(compile-$1) \ 862 | $($1.ldflags) $(lib.ldflags) \ 863 | -o $(lib.name).$(extension) $(all.objects) \ 864 | $($1.ldlibs) $(lib.ldlibs) 865 | endef 866 | 867 | # rule for linking objects in lib executable 868 | # declared conditionally to avoid name clashes 869 | ifeq ($(make-lib-executable),yes) 870 | $(lib.name).$(extension): $(all.objects) 871 | $(if $(filter %.cc %.cpp, $(all.sources)), \ 872 | $(call link-lib,cxx), \ 873 | $(call link-lib,c)) 874 | endif 875 | 876 | 877 | #=== shared dynamic lib ======================================================== 878 | 879 | 880 | # recipe for linking objects in shared executable 881 | # argument $1 = compiler type (c or cxx) 882 | define link-shared 883 | $(compile-$1) \ 884 | $(shared.ldflags) \ 885 | -o lib$(lib.name).$(shared.extension) $(shared.objects) \ 886 | $($1.ldlibs) $(shared.ldlibs) 887 | endef 888 | 889 | # rule for linking objects in shared executable 890 | # build recipe is in macro 'link-shared' 891 | lib$(lib.name).$(shared.extension): $(shared.objects) 892 | $(info ++++ info: linking objects in shared lib $@) 893 | $(if $(filter %.cc %.cpp, $(shared.sources)), \ 894 | $(call link-shared,cxx), \ 895 | $(call link-shared,c)) 896 | 897 | 898 | #=== object files ============================================================== 899 | 900 | 901 | # recipe to make .o file from source 902 | # argument $1 is compiler type (c or cxx) 903 | define make-object-file 904 | $(info ++++ info: making $@ in lib $(lib.name)) 905 | $(compile-$1) \ 906 | $($1.flags) \ 907 | -o $@ -c $< 908 | endef 909 | 910 | # Three rules to create .o files. These are double colon 'terminal' rules, 911 | # meaning they are the last in a rules chain. 912 | 913 | %.o:: %.c 914 | $(call make-object-file,c) 915 | 916 | %.o:: %.cc 917 | $(call make-object-file,cxx) 918 | 919 | %.o:: %.cpp 920 | $(call make-object-file,cxx) 921 | 922 | 923 | #=== explicit prerequisites for class executables ============================== 924 | 925 | 926 | # For class executables, prerequisite rules are declared in run time. Target 927 | # 'depend' prints these rules for debugging purposes. 928 | 929 | # declare explicit prerequisites rule like 'class: class.extension' 930 | # argument $v is class basename 931 | define declare-class-target 932 | $v: $v.$(extension) 933 | endef 934 | 935 | # declare explicit prerequisites rule like 'class.extension: object1.o object2.o' 936 | # argument $v is class basename 937 | define declare-class-executable-target 938 | $v.$(extension): $(addsuffix .o, $(basename $($v.class.sources))) \ 939 | $(addsuffix .o, $(basename $(common.sources))) 940 | endef 941 | 942 | # evaluate explicit prerequisite rules for all classes 943 | $(foreach v, $(classes), $(eval $(declare-class-target))) 944 | $(foreach v, $(classes), $(eval $(declare-class-executable-target))) 945 | 946 | 947 | #=== implicit prerequisites for class executables ============================== 948 | 949 | 950 | # Evaluating implicit prerequisites (header files) with help from the 951 | # preprocessor is 'expensive' so this is done conditionally and selectively. 952 | # Note that it is also possible to trigger a build via install targets, in 953 | # which case implicit prerequisites are not checked. 954 | 955 | # When the Pd include path contains spaces it will mess up the implicit 956 | # prerequisites rules. 957 | disable-dependency-tracking := $(strip $(pdincludepathwithspaces)) 958 | 959 | ifndef disable-dependency-tracking 960 | must-build-everything := $(filter all, $(goals)) 961 | must-build-class := $(filter $(classes), $(goals)) 962 | must-build-sources := $(foreach v, $(must-build-class), $($v.class.sources)) 963 | endif 964 | 965 | # declare implicit prerequisites rule like 'object.o: header1.h header2.h ...' 966 | # argument $1 is input source file(s) 967 | # dir is explicitly added because option -MM strips it by default 968 | define declare-object-target 969 | $(dir $1)$(filter %.o: %.h, $(shell $(CPP) $(depcheck.flags) -MM $1)) $(MAKEFILE_LIST) 970 | endef 971 | 972 | # evaluate implicit prerequisite rules when rebuilding everything 973 | ifdef must-build-everything 974 | $(if $(wildcard $(all.objects)), \ 975 | $(info ++++ info: evaluating implicit prerequisites in lib $(lib.name).....) \ 976 | $(foreach v, $(all.sources), $(eval $(call declare-object-target, $v)))) 977 | endif 978 | 979 | # evaluate implicit prerequisite rules when selectively building classes 980 | ifdef must-build-class 981 | $(foreach v, $(must-build-sources), \ 982 | $(eval $(call declare-object-target, $v))) 983 | $(foreach v, $(shared.sources), \ 984 | $(eval $(call declare-object-target, $v))) 985 | endif 986 | 987 | 988 | ################################################################################ 989 | ### rules: preprocessor and assembly files ##################################### 990 | ################################################################################ 991 | 992 | 993 | # Preprocessor and assembly output files for bug tracing etc. They are not part 994 | # of the build processes for executables. By default these files are created in 995 | # the current working directory. Dependency tracking is not performed, the build 996 | # is forced instead to make sure it's up to date. 997 | 998 | force: 999 | 1000 | 1001 | #=== preprocessor file ========================================================= 1002 | 1003 | 1004 | # make preprocessor output file with extension .pre 1005 | # argument $1 = compiler type (c or cxx) 1006 | define make-preprocessor-file 1007 | $(info ++++ info: making preprocessor output file $(notdir $*.pre) \ 1008 | in current working directory) 1009 | $(compile-$1) -E $< $(c.flags) $($1.flags) -o $(notdir $*.pre) 1010 | endef 1011 | 1012 | %.pre:: %.c force 1013 | $(call make-preprocessor-file,c) 1014 | 1015 | %.pre:: %.cc force 1016 | $(call make-preprocessor-file,cxx) 1017 | 1018 | %.pre:: %.cpp force 1019 | $(call make-preprocessor-file,cxx) 1020 | 1021 | 1022 | #=== assembly file ============================================================= 1023 | 1024 | 1025 | # make C / assembly interleaved output file with extension .lst 1026 | # argument $1 = compiler type (c or cxx) 1027 | define make-assembly-file 1028 | $(info ++++ info: making assembly output file $(notdir $*.lst) \ 1029 | in current working directory) 1030 | $(compile-$1) \ 1031 | -c -Wa,-a,-ad -fverbose-asm \ 1032 | $($1.flags) \ 1033 | $< > $(notdir $*.lst) 1034 | endef 1035 | 1036 | %.lst:: %.c force 1037 | $(call make-assembly-file,c) 1038 | 1039 | %.lst:: %.cc force 1040 | $(call make-assembly-file,cxx) 1041 | 1042 | %.lst:: %.cpp force 1043 | $(call make-assembly-file,cxx) 1044 | 1045 | 1046 | ################################################################################ 1047 | ### rules: installation targets ################################################ 1048 | ################################################################################ 1049 | 1050 | 1051 | #=== strip ===================================================================== 1052 | 1053 | 1054 | # Stripping of installed binaries will only be done when variable 'stripflags' 1055 | # is defined non-empty. No default definition is provided except for Windows 1056 | # where the unstripped binaries are large, especially in the case of Mingw-w64. 1057 | 1058 | # Note: while stripping all symbols ('-s' or '--strip-all') is possible for 1059 | # Linux and Windows, in the case of OSX only non-global symbols can be stripped 1060 | # (option '-x' or '--discard-all'). 1061 | 1062 | # Make definition of strip command overridable so it can be defined in an 1063 | # environment for cross-compilation. 1064 | STRIP ?= strip 1065 | 1066 | # Commands in 'strip-executables' will be executed conditionally in the rule for 1067 | # target 'install-executables'. 1068 | strip-executables = cd "$(installpath)" && \ 1069 | $(foreach v, $(executables), $(STRIP) $(stripflags) '$v';) 1070 | 1071 | 1072 | #=== install =================================================================== 1073 | 1074 | 1075 | # Install targets depend on successful exit status of target all because nothing 1076 | # must be installed in case of a build error. 1077 | 1078 | # -p = preserve time stamps 1079 | # -m = set permission mode (as in chmod) 1080 | # -d = create all components of specified directories 1081 | INSTALL = install 1082 | INSTALL_PROGRAM := $(INSTALL) -p -m 644 1083 | INSTALL_DATA := $(INSTALL) -p -m 644 1084 | INSTALL_DIR := $(INSTALL) -m 755 -d 1085 | 1086 | # strip spaces from file names 1087 | executables := $(strip $(executables)) 1088 | datafiles := $(strip $(datafiles)) 1089 | datadirs := $(strip $(datadirs)) 1090 | 1091 | # Do not make any install sub-target with empty variable definition because the 1092 | # install program would exit with an error. 1093 | install: $(if $(executables), install-executables) 1094 | install: $(if $(datafiles), install-datafiles) 1095 | install: $(if $(datadirs), install-datadirs) 1096 | 1097 | install-executables: all 1098 | $(INSTALL_DIR) -v "$(installpath)" 1099 | $(foreach v, $(executables), \ 1100 | $(INSTALL_PROGRAM) '$v' "$(installpath)";) 1101 | $(info ++++ info: executables of lib $(lib.name) installed \ 1102 | from $(CURDIR) to $(installpath)) 1103 | $(if $(stripflags), $(strip-executables),) 1104 | 1105 | install-datafiles: all 1106 | $(INSTALL_DIR) -v "$(installpath)" 1107 | $(foreach v, $(datafiles), \ 1108 | $(INSTALL_DATA) '$(v)' "$(installpath)";) 1109 | $(info ++++ info: data files of lib $(lib.name) installed \ 1110 | from $(CURDIR) to $(installpath)) 1111 | 1112 | install-datadirs: all 1113 | $(foreach v, $(datadirs), $(INSTALL_DIR) "$(installpath)/$v";) 1114 | $(foreach v, $(datadirs), \ 1115 | $(INSTALL_DATA) $(wildcard $v/*) "$(installpath)/$v";) 1116 | $(info ++++ info: data directories of lib $(lib.name) installed \ 1117 | from $(CURDIR) to $(installpath)) 1118 | 1119 | 1120 | ################################################################################ 1121 | ### rules: distribution targets ################################################ 1122 | ################################################################################ 1123 | 1124 | 1125 | # TODO 1126 | # These targets are implemented in Makefile Template, but I have to figure out 1127 | # how to do it under the not-so-strict conditions of Makefile.pdlibbuilder. 1128 | 1129 | # make source package 1130 | dist: 1131 | @echo "target dist not yet implemented" 1132 | 1133 | # make Debian source package 1134 | dpkg-source: 1135 | @echo "target dpkg-source not yet implemented" 1136 | 1137 | $(ORIGDIR): 1138 | 1139 | $(DISTDIR): 1140 | 1141 | 1142 | ################################################################################ 1143 | ### rules: clean targets ####################################################### 1144 | ################################################################################ 1145 | 1146 | 1147 | # delete build products from build tree 1148 | clean: 1149 | rm -f $(all.objects) 1150 | rm -f $(classes.executables) $(lib.name).$(extension) $(shared.lib) 1151 | rm -f *.pre *.lst 1152 | 1153 | # remove distribution directories and tarballs from build tree 1154 | distclean: clean 1155 | @echo "target distclean not yet implemented" 1156 | 1157 | 1158 | ################################################################################ 1159 | ### rules: submake targets ##################################################### 1160 | ################################################################################ 1161 | 1162 | 1163 | # Iterate over sub-makefiles or makefiles in other directories. 1164 | 1165 | # When 'continue-make=yes' is set, sub-makes will report 'true' to the parent 1166 | # process regardless of their real exit status. This prevents the parent make 1167 | # from being aborted by a sub-make error. Useful when you want to quickly find 1168 | # out which sub-makes from a large set will succeed. 1169 | ifeq ($(continue-make),yes) 1170 | continue = || true 1171 | endif 1172 | 1173 | # These targets will trigger sub-make processes for entries in 'makefiledirs' 1174 | # and 'makefiles'. 1175 | all alldebug install clean distclean dist dkpg-source: \ 1176 | $(makefiledirs) $(makefiles) 1177 | 1178 | # this expands to identical rules for each entry in 'makefiledirs' 1179 | $(makefiledirs): 1180 | $(MAKE) --directory=$@ $(MAKECMDGOALS) $(continue) 1181 | 1182 | # this expands to identical rules for each entry in 'makefiles' 1183 | $(makefiles): 1184 | $(MAKE) --directory=$(dir $@) --makefile=$(notdir $@) $(MAKECMDGOALS) $(continue) 1185 | 1186 | 1187 | ################################################################################ 1188 | ### rules: convenience targets ################################################# 1189 | ################################################################################ 1190 | 1191 | 1192 | #=== show variables ============================================================ 1193 | 1194 | 1195 | # Several 'function' macro's cause errors when expanded within a rule or without 1196 | # proper arguments. Variables which are set with the define directive are only 1197 | # shown by name for that reason. 1198 | functions = \ 1199 | add-class-source \ 1200 | declare-class-target \ 1201 | declare-class-executable-target \ 1202 | declare-object-target \ 1203 | link-class \ 1204 | link-lib \ 1205 | link-shared \ 1206 | make-object-file \ 1207 | make-preprocessor-file \ 1208 | make-assembly-file 1209 | 1210 | 1211 | # show variables from makefiles 1212 | vars: 1213 | $(info ++++ info: showing makefile variables:) 1214 | $(foreach v,\ 1215 | $(sort $(filter-out $(functions) functions, $(.VARIABLES))),\ 1216 | $(if $(filter file, $(origin $v)),\ 1217 | $(info variable $v = $($v)))) 1218 | $(foreach v, $(functions), $(info 'function' name: $v)) 1219 | @echo 1220 | 1221 | # show all variables 1222 | allvars: 1223 | $(info ++++ info: showing default, automatic and makefile variables:) 1224 | $(foreach v, \ 1225 | $(sort $(filter-out $(functions) functions, $(.VARIABLES))), \ 1226 | $(info variable ($(origin $v)) $v = $($v))) 1227 | $(foreach v, $(functions), $(info 'function' name: $v)) 1228 | @echo 1229 | 1230 | 1231 | #=== show dependencies ========================================================= 1232 | 1233 | 1234 | # show generated prerequisites rules 1235 | depend: 1236 | $(info ++++ info: generated prerequisite rules) 1237 | $(foreach v, $(classes), $(info $(declare-class-target))) 1238 | $(foreach v, $(classes), $(info $(declare-class-executable-target))) 1239 | $(foreach v, $(all.sources), $(info $(call declare-object-target, $v))) 1240 | @echo 1241 | 1242 | 1243 | #=== show help text ============================================================ 1244 | 1245 | 1246 | # brief info about targets and paths 1247 | 1248 | ifdef mpdh 1249 | mpdhinfo := $(mpdh) 1250 | else 1251 | mpdhinfo := m_pd.h was not found. Is Pd installed? 1252 | endif 1253 | 1254 | help: 1255 | @echo 1256 | @echo " Main targets:" 1257 | @echo " all: build executables (default target)" 1258 | @echo " install: install all components of the library" 1259 | @echo " vars: print makefile variables for troubleshooting" 1260 | @echo " allvars: print all variables for troubleshooting" 1261 | @echo " help: print this help text" 1262 | @echo 1263 | @echo " Pd API m_pd.h:" 1264 | @echo " $(mpdhinfo)" 1265 | @echo " You may specify your preferred Pd include directory as argument" 1266 | @echo " to the make command, like 'PDINCLUDEDIR=path/to/pd/src'." 1267 | @echo 1268 | @echo " Path for installation of your libdir(s):" 1269 | @echo " $(PDLIBDIR)" 1270 | @echo " Alternatively you may specify your path for installation as argument" 1271 | @echo " to the make command, like 'PDLIBDIR=path/to/pd-externals'." 1272 | @echo 1273 | @echo " Default paths are listed in the doc sections in Makefile.pdlibbuilder." 1274 | @echo 1275 | 1276 | 1277 | #=== dummy target ============================================================== 1278 | 1279 | 1280 | coffee: 1281 | @echo "Makefile.pdlibbuilder: Can not make coffee. Sorry." 1282 | 1283 | 1284 | ################################################################################ 1285 | ### end of rules sections ###################################################### 1286 | ################################################################################ 1287 | 1288 | 1289 | # for syntax highlighting in vim and github 1290 | # vim: set filetype=make: 1291 | 1292 | -------------------------------------------------------------------------------- /src/sdk/libusb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Public libusb header file 3 | * Copyright © 2001 Johannes Erdfelt 4 | * Copyright © 2007-2008 Daniel Drake 5 | * Copyright © 2012 Pete Batard 6 | * Copyright © 2012 Nathan Hjelm 7 | * For more information, please visit: http://libusb.info 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef LIBUSB_H 25 | #define LIBUSB_H 26 | 27 | #ifdef _MSC_VER 28 | /* on MS environments, the inline keyword is available in C++ only */ 29 | #if !defined(__cplusplus) 30 | #define inline __inline 31 | #endif 32 | /* ssize_t is also not available (copy/paste from MinGW) */ 33 | #ifndef _SSIZE_T_DEFINED 34 | #define _SSIZE_T_DEFINED 35 | #undef ssize_t 36 | #ifdef _WIN64 37 | typedef __int64 ssize_t; 38 | #else 39 | typedef int ssize_t; 40 | #endif /* _WIN64 */ 41 | #endif /* _SSIZE_T_DEFINED */ 42 | #endif /* _MSC_VER */ 43 | 44 | /* stdint.h is not available on older MSVC */ 45 | #if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H)) 46 | typedef unsigned __int8 uint8_t; 47 | typedef unsigned __int16 uint16_t; 48 | typedef unsigned __int32 uint32_t; 49 | #else 50 | #include 51 | #endif 52 | 53 | #if !defined(_WIN32_WCE) 54 | #include 55 | #endif 56 | 57 | #if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__HAIKU__) 58 | #include 59 | #endif 60 | 61 | #include 62 | #include 63 | 64 | /* 'interface' might be defined as a macro on Windows, so we need to 65 | * undefine it so as not to break the current libusb API, because 66 | * libusb_config_descriptor has an 'interface' member 67 | * As this can be problematic if you include windows.h after libusb.h 68 | * in your sources, we force windows.h to be included first. */ 69 | #if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) 70 | #include 71 | #if defined(interface) 72 | #undef interface 73 | #endif 74 | #if !defined(__CYGWIN__) 75 | #include 76 | #endif 77 | #endif 78 | 79 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) 80 | #define LIBUSB_DEPRECATED_FOR(f) \ 81 | __attribute__((deprecated("Use " #f " instead"))) 82 | #else 83 | #define LIBUSB_DEPRECATED_FOR(f) 84 | #endif /* __GNUC__ */ 85 | 86 | /** \def LIBUSB_CALL 87 | * \ingroup misc 88 | * libusb's Windows calling convention. 89 | * 90 | * Under Windows, the selection of available compilers and configurations 91 | * means that, unlike other platforms, there is not one true calling 92 | * convention (calling convention: the manner in which parameters are 93 | * passed to functions in the generated assembly code). 94 | * 95 | * Matching the Windows API itself, libusb uses the WINAPI convention (which 96 | * translates to the stdcall convention) and guarantees that the 97 | * library is compiled in this way. The public header file also includes 98 | * appropriate annotations so that your own software will use the right 99 | * convention, even if another convention is being used by default within 100 | * your codebase. 101 | * 102 | * The one consideration that you must apply in your software is to mark 103 | * all functions which you use as libusb callbacks with this LIBUSB_CALL 104 | * annotation, so that they too get compiled for the correct calling 105 | * convention. 106 | * 107 | * On non-Windows operating systems, this macro is defined as nothing. This 108 | * means that you can apply it to your code without worrying about 109 | * cross-platform compatibility. 110 | */ 111 | /* LIBUSB_CALL must be defined on both definition and declaration of libusb 112 | * functions. You'd think that declaration would be enough, but cygwin will 113 | * complain about conflicting types unless both are marked this way. 114 | * The placement of this macro is important too; it must appear after the 115 | * return type, before the function name. See internal documentation for 116 | * API_EXPORTED. 117 | */ 118 | #if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) 119 | #define LIBUSB_CALL WINAPI 120 | #else 121 | #define LIBUSB_CALL 122 | #endif 123 | 124 | /** \def LIBUSB_API_VERSION 125 | * \ingroup misc 126 | * libusb's API version. 127 | * 128 | * Since version 1.0.13, to help with feature detection, libusb defines 129 | * a LIBUSB_API_VERSION macro that gets increased every time there is a 130 | * significant change to the API, such as the introduction of a new call, 131 | * the definition of a new macro/enum member, or any other element that 132 | * libusb applications may want to detect at compilation time. 133 | * 134 | * The macro is typically used in an application as follows: 135 | * \code 136 | * #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01001234) 137 | * // Use one of the newer features from the libusb API 138 | * #endif 139 | * \endcode 140 | * 141 | * Internally, LIBUSB_API_VERSION is defined as follows: 142 | * (libusb major << 24) | (libusb minor << 16) | (16 bit incremental) 143 | */ 144 | #define LIBUSB_API_VERSION 0x01000104 145 | 146 | /* The following is kept for compatibility, but will be deprecated in the future */ 147 | #define LIBUSBX_API_VERSION LIBUSB_API_VERSION 148 | 149 | #ifdef __cplusplus 150 | extern "C" { 151 | #endif 152 | 153 | /** 154 | * \ingroup misc 155 | * Convert a 16-bit value from host-endian to little-endian format. On 156 | * little endian systems, this function does nothing. On big endian systems, 157 | * the bytes are swapped. 158 | * \param x the host-endian value to convert 159 | * \returns the value in little-endian byte order 160 | */ 161 | static inline uint16_t libusb_cpu_to_le16(const uint16_t x) 162 | { 163 | union { 164 | uint8_t b8[2]; 165 | uint16_t b16; 166 | } _tmp; 167 | _tmp.b8[1] = (uint8_t) (x >> 8); 168 | _tmp.b8[0] = (uint8_t) (x & 0xff); 169 | return _tmp.b16; 170 | } 171 | 172 | /** \def libusb_le16_to_cpu 173 | * \ingroup misc 174 | * Convert a 16-bit value from little-endian to host-endian format. On 175 | * little endian systems, this function does nothing. On big endian systems, 176 | * the bytes are swapped. 177 | * \param x the little-endian value to convert 178 | * \returns the value in host-endian byte order 179 | */ 180 | #define libusb_le16_to_cpu libusb_cpu_to_le16 181 | 182 | /* standard USB stuff */ 183 | 184 | /** \ingroup desc 185 | * Device and/or Interface Class codes */ 186 | enum libusb_class_code { 187 | /** In the context of a \ref libusb_device_descriptor "device descriptor", 188 | * this bDeviceClass value indicates that each interface specifies its 189 | * own class information and all interfaces operate independently. 190 | */ 191 | LIBUSB_CLASS_PER_INTERFACE = 0, 192 | 193 | /** Audio class */ 194 | LIBUSB_CLASS_AUDIO = 1, 195 | 196 | /** Communications class */ 197 | LIBUSB_CLASS_COMM = 2, 198 | 199 | /** Human Interface Device class */ 200 | LIBUSB_CLASS_HID = 3, 201 | 202 | /** Physical */ 203 | LIBUSB_CLASS_PHYSICAL = 5, 204 | 205 | /** Printer class */ 206 | LIBUSB_CLASS_PRINTER = 7, 207 | 208 | /** Image class */ 209 | LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */ 210 | LIBUSB_CLASS_IMAGE = 6, 211 | 212 | /** Mass storage class */ 213 | LIBUSB_CLASS_MASS_STORAGE = 8, 214 | 215 | /** Hub class */ 216 | LIBUSB_CLASS_HUB = 9, 217 | 218 | /** Data class */ 219 | LIBUSB_CLASS_DATA = 10, 220 | 221 | /** Smart Card */ 222 | LIBUSB_CLASS_SMART_CARD = 0x0b, 223 | 224 | /** Content Security */ 225 | LIBUSB_CLASS_CONTENT_SECURITY = 0x0d, 226 | 227 | /** Video */ 228 | LIBUSB_CLASS_VIDEO = 0x0e, 229 | 230 | /** Personal Healthcare */ 231 | LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f, 232 | 233 | /** Diagnostic Device */ 234 | LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc, 235 | 236 | /** Wireless class */ 237 | LIBUSB_CLASS_WIRELESS = 0xe0, 238 | 239 | /** Application class */ 240 | LIBUSB_CLASS_APPLICATION = 0xfe, 241 | 242 | /** Class is vendor-specific */ 243 | LIBUSB_CLASS_VENDOR_SPEC = 0xff 244 | }; 245 | 246 | /** \ingroup desc 247 | * Descriptor types as defined by the USB specification. */ 248 | enum libusb_descriptor_type { 249 | /** Device descriptor. See libusb_device_descriptor. */ 250 | LIBUSB_DT_DEVICE = 0x01, 251 | 252 | /** Configuration descriptor. See libusb_config_descriptor. */ 253 | LIBUSB_DT_CONFIG = 0x02, 254 | 255 | /** String descriptor */ 256 | LIBUSB_DT_STRING = 0x03, 257 | 258 | /** Interface descriptor. See libusb_interface_descriptor. */ 259 | LIBUSB_DT_INTERFACE = 0x04, 260 | 261 | /** Endpoint descriptor. See libusb_endpoint_descriptor. */ 262 | LIBUSB_DT_ENDPOINT = 0x05, 263 | 264 | /** BOS descriptor */ 265 | LIBUSB_DT_BOS = 0x0f, 266 | 267 | /** Device Capability descriptor */ 268 | LIBUSB_DT_DEVICE_CAPABILITY = 0x10, 269 | 270 | /** HID descriptor */ 271 | LIBUSB_DT_HID = 0x21, 272 | 273 | /** HID report descriptor */ 274 | LIBUSB_DT_REPORT = 0x22, 275 | 276 | /** Physical descriptor */ 277 | LIBUSB_DT_PHYSICAL = 0x23, 278 | 279 | /** Hub descriptor */ 280 | LIBUSB_DT_HUB = 0x29, 281 | 282 | /** SuperSpeed Hub descriptor */ 283 | LIBUSB_DT_SUPERSPEED_HUB = 0x2a, 284 | 285 | /** SuperSpeed Endpoint Companion descriptor */ 286 | LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30 287 | }; 288 | 289 | /* Descriptor sizes per descriptor type */ 290 | #define LIBUSB_DT_DEVICE_SIZE 18 291 | #define LIBUSB_DT_CONFIG_SIZE 9 292 | #define LIBUSB_DT_INTERFACE_SIZE 9 293 | #define LIBUSB_DT_ENDPOINT_SIZE 7 294 | #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ 295 | #define LIBUSB_DT_HUB_NONVAR_SIZE 7 296 | #define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE 6 297 | #define LIBUSB_DT_BOS_SIZE 5 298 | #define LIBUSB_DT_DEVICE_CAPABILITY_SIZE 3 299 | 300 | /* BOS descriptor sizes */ 301 | #define LIBUSB_BT_USB_2_0_EXTENSION_SIZE 7 302 | #define LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE 10 303 | #define LIBUSB_BT_CONTAINER_ID_SIZE 20 304 | 305 | /* We unwrap the BOS => define its max size */ 306 | #define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) +\ 307 | (LIBUSB_BT_USB_2_0_EXTENSION_SIZE) +\ 308 | (LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) +\ 309 | (LIBUSB_BT_CONTAINER_ID_SIZE)) 310 | 311 | #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ 312 | #define LIBUSB_ENDPOINT_DIR_MASK 0x80 313 | 314 | /** \ingroup desc 315 | * Endpoint direction. Values for bit 7 of the 316 | * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme. 317 | */ 318 | enum libusb_endpoint_direction { 319 | /** In: device-to-host */ 320 | LIBUSB_ENDPOINT_IN = 0x80, 321 | 322 | /** Out: host-to-device */ 323 | LIBUSB_ENDPOINT_OUT = 0x00 324 | }; 325 | 326 | #define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */ 327 | 328 | /** \ingroup desc 329 | * Endpoint transfer type. Values for bits 0:1 of the 330 | * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field. 331 | */ 332 | enum libusb_transfer_type { 333 | /** Control endpoint */ 334 | LIBUSB_TRANSFER_TYPE_CONTROL = 0, 335 | 336 | /** Isochronous endpoint */ 337 | LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1, 338 | 339 | /** Bulk endpoint */ 340 | LIBUSB_TRANSFER_TYPE_BULK = 2, 341 | 342 | /** Interrupt endpoint */ 343 | LIBUSB_TRANSFER_TYPE_INTERRUPT = 3, 344 | 345 | /** Stream endpoint */ 346 | LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4, 347 | }; 348 | 349 | /** \ingroup misc 350 | * Standard requests, as defined in table 9-5 of the USB 3.0 specifications */ 351 | enum libusb_standard_request { 352 | /** Request status of the specific recipient */ 353 | LIBUSB_REQUEST_GET_STATUS = 0x00, 354 | 355 | /** Clear or disable a specific feature */ 356 | LIBUSB_REQUEST_CLEAR_FEATURE = 0x01, 357 | 358 | /* 0x02 is reserved */ 359 | 360 | /** Set or enable a specific feature */ 361 | LIBUSB_REQUEST_SET_FEATURE = 0x03, 362 | 363 | /* 0x04 is reserved */ 364 | 365 | /** Set device address for all future accesses */ 366 | LIBUSB_REQUEST_SET_ADDRESS = 0x05, 367 | 368 | /** Get the specified descriptor */ 369 | LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06, 370 | 371 | /** Used to update existing descriptors or add new descriptors */ 372 | LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07, 373 | 374 | /** Get the current device configuration value */ 375 | LIBUSB_REQUEST_GET_CONFIGURATION = 0x08, 376 | 377 | /** Set device configuration */ 378 | LIBUSB_REQUEST_SET_CONFIGURATION = 0x09, 379 | 380 | /** Return the selected alternate setting for the specified interface */ 381 | LIBUSB_REQUEST_GET_INTERFACE = 0x0A, 382 | 383 | /** Select an alternate interface for the specified interface */ 384 | LIBUSB_REQUEST_SET_INTERFACE = 0x0B, 385 | 386 | /** Set then report an endpoint's synchronization frame */ 387 | LIBUSB_REQUEST_SYNCH_FRAME = 0x0C, 388 | 389 | /** Sets both the U1 and U2 Exit Latency */ 390 | LIBUSB_REQUEST_SET_SEL = 0x30, 391 | 392 | /** Delay from the time a host transmits a packet to the time it is 393 | * received by the device. */ 394 | LIBUSB_SET_ISOCH_DELAY = 0x31, 395 | }; 396 | 397 | /** \ingroup misc 398 | * Request type bits of the 399 | * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control 400 | * transfers. */ 401 | enum libusb_request_type { 402 | /** Standard */ 403 | LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5), 404 | 405 | /** Class */ 406 | LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5), 407 | 408 | /** Vendor */ 409 | LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5), 410 | 411 | /** Reserved */ 412 | LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5) 413 | }; 414 | 415 | /** \ingroup misc 416 | * Recipient bits of the 417 | * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control 418 | * transfers. Values 4 through 31 are reserved. */ 419 | enum libusb_request_recipient { 420 | /** Device */ 421 | LIBUSB_RECIPIENT_DEVICE = 0x00, 422 | 423 | /** Interface */ 424 | LIBUSB_RECIPIENT_INTERFACE = 0x01, 425 | 426 | /** Endpoint */ 427 | LIBUSB_RECIPIENT_ENDPOINT = 0x02, 428 | 429 | /** Other */ 430 | LIBUSB_RECIPIENT_OTHER = 0x03, 431 | }; 432 | 433 | #define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C 434 | 435 | /** \ingroup desc 436 | * Synchronization type for isochronous endpoints. Values for bits 2:3 of the 437 | * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in 438 | * libusb_endpoint_descriptor. 439 | */ 440 | enum libusb_iso_sync_type { 441 | /** No synchronization */ 442 | LIBUSB_ISO_SYNC_TYPE_NONE = 0, 443 | 444 | /** Asynchronous */ 445 | LIBUSB_ISO_SYNC_TYPE_ASYNC = 1, 446 | 447 | /** Adaptive */ 448 | LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2, 449 | 450 | /** Synchronous */ 451 | LIBUSB_ISO_SYNC_TYPE_SYNC = 3 452 | }; 453 | 454 | #define LIBUSB_ISO_USAGE_TYPE_MASK 0x30 455 | 456 | /** \ingroup desc 457 | * Usage type for isochronous endpoints. Values for bits 4:5 of the 458 | * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in 459 | * libusb_endpoint_descriptor. 460 | */ 461 | enum libusb_iso_usage_type { 462 | /** Data endpoint */ 463 | LIBUSB_ISO_USAGE_TYPE_DATA = 0, 464 | 465 | /** Feedback endpoint */ 466 | LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1, 467 | 468 | /** Implicit feedback Data endpoint */ 469 | LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2, 470 | }; 471 | 472 | /** \ingroup desc 473 | * A structure representing the standard USB device descriptor. This 474 | * descriptor is documented in section 9.6.1 of the USB 3.0 specification. 475 | * All multiple-byte fields are represented in host-endian format. 476 | */ 477 | struct libusb_device_descriptor { 478 | /** Size of this descriptor (in bytes) */ 479 | uint8_t bLength; 480 | 481 | /** Descriptor type. Will have value 482 | * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this 483 | * context. */ 484 | uint8_t bDescriptorType; 485 | 486 | /** USB specification release number in binary-coded decimal. A value of 487 | * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */ 488 | uint16_t bcdUSB; 489 | 490 | /** USB-IF class code for the device. See \ref libusb_class_code. */ 491 | uint8_t bDeviceClass; 492 | 493 | /** USB-IF subclass code for the device, qualified by the bDeviceClass 494 | * value */ 495 | uint8_t bDeviceSubClass; 496 | 497 | /** USB-IF protocol code for the device, qualified by the bDeviceClass and 498 | * bDeviceSubClass values */ 499 | uint8_t bDeviceProtocol; 500 | 501 | /** Maximum packet size for endpoint 0 */ 502 | uint8_t bMaxPacketSize0; 503 | 504 | /** USB-IF vendor ID */ 505 | uint16_t idVendor; 506 | 507 | /** USB-IF product ID */ 508 | uint16_t idProduct; 509 | 510 | /** Device release number in binary-coded decimal */ 511 | uint16_t bcdDevice; 512 | 513 | /** Index of string descriptor describing manufacturer */ 514 | uint8_t iManufacturer; 515 | 516 | /** Index of string descriptor describing product */ 517 | uint8_t iProduct; 518 | 519 | /** Index of string descriptor containing device serial number */ 520 | uint8_t iSerialNumber; 521 | 522 | /** Number of possible configurations */ 523 | uint8_t bNumConfigurations; 524 | }; 525 | 526 | /** \ingroup desc 527 | * A structure representing the standard USB endpoint descriptor. This 528 | * descriptor is documented in section 9.6.6 of the USB 3.0 specification. 529 | * All multiple-byte fields are represented in host-endian format. 530 | */ 531 | struct libusb_endpoint_descriptor { 532 | /** Size of this descriptor (in bytes) */ 533 | uint8_t bLength; 534 | 535 | /** Descriptor type. Will have value 536 | * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in 537 | * this context. */ 538 | uint8_t bDescriptorType; 539 | 540 | /** The address of the endpoint described by this descriptor. Bits 0:3 are 541 | * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction, 542 | * see \ref libusb_endpoint_direction. 543 | */ 544 | uint8_t bEndpointAddress; 545 | 546 | /** Attributes which apply to the endpoint when it is configured using 547 | * the bConfigurationValue. Bits 0:1 determine the transfer type and 548 | * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for 549 | * isochronous endpoints and correspond to \ref libusb_iso_sync_type. 550 | * Bits 4:5 are also only used for isochronous endpoints and correspond to 551 | * \ref libusb_iso_usage_type. Bits 6:7 are reserved. 552 | */ 553 | uint8_t bmAttributes; 554 | 555 | /** Maximum packet size this endpoint is capable of sending/receiving. */ 556 | uint16_t wMaxPacketSize; 557 | 558 | /** Interval for polling endpoint for data transfers. */ 559 | uint8_t bInterval; 560 | 561 | /** For audio devices only: the rate at which synchronization feedback 562 | * is provided. */ 563 | uint8_t bRefresh; 564 | 565 | /** For audio devices only: the address if the synch endpoint */ 566 | uint8_t bSynchAddress; 567 | 568 | /** Extra descriptors. If libusb encounters unknown endpoint descriptors, 569 | * it will store them here, should you wish to parse them. */ 570 | const unsigned char *extra; 571 | 572 | /** Length of the extra descriptors, in bytes. */ 573 | int extra_length; 574 | }; 575 | 576 | /** \ingroup desc 577 | * A structure representing the standard USB interface descriptor. This 578 | * descriptor is documented in section 9.6.5 of the USB 3.0 specification. 579 | * All multiple-byte fields are represented in host-endian format. 580 | */ 581 | struct libusb_interface_descriptor { 582 | /** Size of this descriptor (in bytes) */ 583 | uint8_t bLength; 584 | 585 | /** Descriptor type. Will have value 586 | * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE 587 | * in this context. */ 588 | uint8_t bDescriptorType; 589 | 590 | /** Number of this interface */ 591 | uint8_t bInterfaceNumber; 592 | 593 | /** Value used to select this alternate setting for this interface */ 594 | uint8_t bAlternateSetting; 595 | 596 | /** Number of endpoints used by this interface (excluding the control 597 | * endpoint). */ 598 | uint8_t bNumEndpoints; 599 | 600 | /** USB-IF class code for this interface. See \ref libusb_class_code. */ 601 | uint8_t bInterfaceClass; 602 | 603 | /** USB-IF subclass code for this interface, qualified by the 604 | * bInterfaceClass value */ 605 | uint8_t bInterfaceSubClass; 606 | 607 | /** USB-IF protocol code for this interface, qualified by the 608 | * bInterfaceClass and bInterfaceSubClass values */ 609 | uint8_t bInterfaceProtocol; 610 | 611 | /** Index of string descriptor describing this interface */ 612 | uint8_t iInterface; 613 | 614 | /** Array of endpoint descriptors. This length of this array is determined 615 | * by the bNumEndpoints field. */ 616 | const struct libusb_endpoint_descriptor *endpoint; 617 | 618 | /** Extra descriptors. If libusb encounters unknown interface descriptors, 619 | * it will store them here, should you wish to parse them. */ 620 | const unsigned char *extra; 621 | 622 | /** Length of the extra descriptors, in bytes. */ 623 | int extra_length; 624 | }; 625 | 626 | /** \ingroup desc 627 | * A collection of alternate settings for a particular USB interface. 628 | */ 629 | struct libusb_interface { 630 | /** Array of interface descriptors. The length of this array is determined 631 | * by the num_altsetting field. */ 632 | const struct libusb_interface_descriptor *altsetting; 633 | 634 | /** The number of alternate settings that belong to this interface */ 635 | int num_altsetting; 636 | }; 637 | 638 | /** \ingroup desc 639 | * A structure representing the standard USB configuration descriptor. This 640 | * descriptor is documented in section 9.6.3 of the USB 3.0 specification. 641 | * All multiple-byte fields are represented in host-endian format. 642 | */ 643 | struct libusb_config_descriptor { 644 | /** Size of this descriptor (in bytes) */ 645 | uint8_t bLength; 646 | 647 | /** Descriptor type. Will have value 648 | * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG 649 | * in this context. */ 650 | uint8_t bDescriptorType; 651 | 652 | /** Total length of data returned for this configuration */ 653 | uint16_t wTotalLength; 654 | 655 | /** Number of interfaces supported by this configuration */ 656 | uint8_t bNumInterfaces; 657 | 658 | /** Identifier value for this configuration */ 659 | uint8_t bConfigurationValue; 660 | 661 | /** Index of string descriptor describing this configuration */ 662 | uint8_t iConfiguration; 663 | 664 | /** Configuration characteristics */ 665 | uint8_t bmAttributes; 666 | 667 | /** Maximum power consumption of the USB device from this bus in this 668 | * configuration when the device is fully operation. Expressed in units 669 | * of 2 mA when the device is operating in high-speed mode and in units 670 | * of 8 mA when the device is operating in super-speed mode. */ 671 | uint8_t MaxPower; 672 | 673 | /** Array of interfaces supported by this configuration. The length of 674 | * this array is determined by the bNumInterfaces field. */ 675 | const struct libusb_interface *interface; 676 | 677 | /** Extra descriptors. If libusb encounters unknown configuration 678 | * descriptors, it will store them here, should you wish to parse them. */ 679 | const unsigned char *extra; 680 | 681 | /** Length of the extra descriptors, in bytes. */ 682 | int extra_length; 683 | }; 684 | 685 | /** \ingroup desc 686 | * A structure representing the superspeed endpoint companion 687 | * descriptor. This descriptor is documented in section 9.6.7 of 688 | * the USB 3.0 specification. All multiple-byte fields are represented in 689 | * host-endian format. 690 | */ 691 | struct libusb_ss_endpoint_companion_descriptor { 692 | 693 | /** Size of this descriptor (in bytes) */ 694 | uint8_t bLength; 695 | 696 | /** Descriptor type. Will have value 697 | * \ref libusb_descriptor_type::LIBUSB_DT_SS_ENDPOINT_COMPANION in 698 | * this context. */ 699 | uint8_t bDescriptorType; 700 | 701 | 702 | /** The maximum number of packets the endpoint can send or 703 | * recieve as part of a burst. */ 704 | uint8_t bMaxBurst; 705 | 706 | /** In bulk EP: bits 4:0 represents the maximum number of 707 | * streams the EP supports. In isochronous EP: bits 1:0 708 | * represents the Mult - a zero based value that determines 709 | * the maximum number of packets within a service interval */ 710 | uint8_t bmAttributes; 711 | 712 | /** The total number of bytes this EP will transfer every 713 | * service interval. valid only for periodic EPs. */ 714 | uint16_t wBytesPerInterval; 715 | }; 716 | 717 | /** \ingroup desc 718 | * A generic representation of a BOS Device Capability descriptor. It is 719 | * advised to check bDevCapabilityType and call the matching 720 | * libusb_get_*_descriptor function to get a structure fully matching the type. 721 | */ 722 | struct libusb_bos_dev_capability_descriptor { 723 | /** Size of this descriptor (in bytes) */ 724 | uint8_t bLength; 725 | /** Descriptor type. Will have value 726 | * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY 727 | * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ 728 | uint8_t bDescriptorType; 729 | /** Device Capability type */ 730 | uint8_t bDevCapabilityType; 731 | /** Device Capability data (bLength - 3 bytes) */ 732 | uint8_t dev_capability_data 733 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) 734 | [] /* valid C99 code */ 735 | #else 736 | [0] /* non-standard, but usually working code */ 737 | #endif 738 | ; 739 | }; 740 | 741 | /** \ingroup desc 742 | * A structure representing the Binary Device Object Store (BOS) descriptor. 743 | * This descriptor is documented in section 9.6.2 of the USB 3.0 specification. 744 | * All multiple-byte fields are represented in host-endian format. 745 | */ 746 | struct libusb_bos_descriptor { 747 | /** Size of this descriptor (in bytes) */ 748 | uint8_t bLength; 749 | 750 | /** Descriptor type. Will have value 751 | * \ref libusb_descriptor_type::LIBUSB_DT_BOS LIBUSB_DT_BOS 752 | * in this context. */ 753 | uint8_t bDescriptorType; 754 | 755 | /** Length of this descriptor and all of its sub descriptors */ 756 | uint16_t wTotalLength; 757 | 758 | /** The number of separate device capability descriptors in 759 | * the BOS */ 760 | uint8_t bNumDeviceCaps; 761 | 762 | /** bNumDeviceCap Device Capability Descriptors */ 763 | struct libusb_bos_dev_capability_descriptor *dev_capability 764 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) 765 | [] /* valid C99 code */ 766 | #else 767 | [0] /* non-standard, but usually working code */ 768 | #endif 769 | ; 770 | }; 771 | 772 | /** \ingroup desc 773 | * A structure representing the USB 2.0 Extension descriptor 774 | * This descriptor is documented in section 9.6.2.1 of the USB 3.0 specification. 775 | * All multiple-byte fields are represented in host-endian format. 776 | */ 777 | struct libusb_usb_2_0_extension_descriptor { 778 | /** Size of this descriptor (in bytes) */ 779 | uint8_t bLength; 780 | 781 | /** Descriptor type. Will have value 782 | * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY 783 | * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ 784 | uint8_t bDescriptorType; 785 | 786 | /** Capability type. Will have value 787 | * \ref libusb_capability_type::LIBUSB_BT_USB_2_0_EXTENSION 788 | * LIBUSB_BT_USB_2_0_EXTENSION in this context. */ 789 | uint8_t bDevCapabilityType; 790 | 791 | /** Bitmap encoding of supported device level features. 792 | * A value of one in a bit location indicates a feature is 793 | * supported; a value of zero indicates it is not supported. 794 | * See \ref libusb_usb_2_0_extension_attributes. */ 795 | uint32_t bmAttributes; 796 | }; 797 | 798 | /** \ingroup desc 799 | * A structure representing the SuperSpeed USB Device Capability descriptor 800 | * This descriptor is documented in section 9.6.2.2 of the USB 3.0 specification. 801 | * All multiple-byte fields are represented in host-endian format. 802 | */ 803 | struct libusb_ss_usb_device_capability_descriptor { 804 | /** Size of this descriptor (in bytes) */ 805 | uint8_t bLength; 806 | 807 | /** Descriptor type. Will have value 808 | * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY 809 | * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ 810 | uint8_t bDescriptorType; 811 | 812 | /** Capability type. Will have value 813 | * \ref libusb_capability_type::LIBUSB_BT_SS_USB_DEVICE_CAPABILITY 814 | * LIBUSB_BT_SS_USB_DEVICE_CAPABILITY in this context. */ 815 | uint8_t bDevCapabilityType; 816 | 817 | /** Bitmap encoding of supported device level features. 818 | * A value of one in a bit location indicates a feature is 819 | * supported; a value of zero indicates it is not supported. 820 | * See \ref libusb_ss_usb_device_capability_attributes. */ 821 | uint8_t bmAttributes; 822 | 823 | /** Bitmap encoding of the speed supported by this device when 824 | * operating in SuperSpeed mode. See \ref libusb_supported_speed. */ 825 | uint16_t wSpeedSupported; 826 | 827 | /** The lowest speed at which all the functionality supported 828 | * by the device is available to the user. For example if the 829 | * device supports all its functionality when connected at 830 | * full speed and above then it sets this value to 1. */ 831 | uint8_t bFunctionalitySupport; 832 | 833 | /** U1 Device Exit Latency. */ 834 | uint8_t bU1DevExitLat; 835 | 836 | /** U2 Device Exit Latency. */ 837 | uint16_t bU2DevExitLat; 838 | }; 839 | 840 | /** \ingroup desc 841 | * A structure representing the Container ID descriptor. 842 | * This descriptor is documented in section 9.6.2.3 of the USB 3.0 specification. 843 | * All multiple-byte fields, except UUIDs, are represented in host-endian format. 844 | */ 845 | struct libusb_container_id_descriptor { 846 | /** Size of this descriptor (in bytes) */ 847 | uint8_t bLength; 848 | 849 | /** Descriptor type. Will have value 850 | * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY 851 | * LIBUSB_DT_DEVICE_CAPABILITY in this context. */ 852 | uint8_t bDescriptorType; 853 | 854 | /** Capability type. Will have value 855 | * \ref libusb_capability_type::LIBUSB_BT_CONTAINER_ID 856 | * LIBUSB_BT_CONTAINER_ID in this context. */ 857 | uint8_t bDevCapabilityType; 858 | 859 | /** Reserved field */ 860 | uint8_t bReserved; 861 | 862 | /** 128 bit UUID */ 863 | uint8_t ContainerID[16]; 864 | }; 865 | 866 | /** \ingroup asyncio 867 | * Setup packet for control transfers. */ 868 | struct libusb_control_setup { 869 | /** Request type. Bits 0:4 determine recipient, see 870 | * \ref libusb_request_recipient. Bits 5:6 determine type, see 871 | * \ref libusb_request_type. Bit 7 determines data transfer direction, see 872 | * \ref libusb_endpoint_direction. 873 | */ 874 | uint8_t bmRequestType; 875 | 876 | /** Request. If the type bits of bmRequestType are equal to 877 | * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD 878 | * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to 879 | * \ref libusb_standard_request. For other cases, use of this field is 880 | * application-specific. */ 881 | uint8_t bRequest; 882 | 883 | /** Value. Varies according to request */ 884 | uint16_t wValue; 885 | 886 | /** Index. Varies according to request, typically used to pass an index 887 | * or offset */ 888 | uint16_t wIndex; 889 | 890 | /** Number of bytes to transfer */ 891 | uint16_t wLength; 892 | }; 893 | 894 | #define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup)) 895 | 896 | /* libusb */ 897 | 898 | struct libusb_context; 899 | struct libusb_device; 900 | struct libusb_device_handle; 901 | 902 | /** \ingroup lib 903 | * Structure providing the version of the libusb runtime 904 | */ 905 | struct libusb_version { 906 | /** Library major version. */ 907 | const uint16_t major; 908 | 909 | /** Library minor version. */ 910 | const uint16_t minor; 911 | 912 | /** Library micro version. */ 913 | const uint16_t micro; 914 | 915 | /** Library nano version. */ 916 | const uint16_t nano; 917 | 918 | /** Library release candidate suffix string, e.g. "-rc4". */ 919 | const char *rc; 920 | 921 | /** For ABI compatibility only. */ 922 | const char* describe; 923 | }; 924 | 925 | /** \ingroup lib 926 | * Structure representing a libusb session. The concept of individual libusb 927 | * sessions allows for your program to use two libraries (or dynamically 928 | * load two modules) which both independently use libusb. This will prevent 929 | * interference between the individual libusb users - for example 930 | * libusb_set_debug() will not affect the other user of the library, and 931 | * libusb_exit() will not destroy resources that the other user is still 932 | * using. 933 | * 934 | * Sessions are created by libusb_init() and destroyed through libusb_exit(). 935 | * If your application is guaranteed to only ever include a single libusb 936 | * user (i.e. you), you do not have to worry about contexts: pass NULL in 937 | * every function call where a context is required. The default context 938 | * will be used. 939 | * 940 | * For more information, see \ref contexts. 941 | */ 942 | typedef struct libusb_context libusb_context; 943 | 944 | /** \ingroup dev 945 | * Structure representing a USB device detected on the system. This is an 946 | * opaque type for which you are only ever provided with a pointer, usually 947 | * originating from libusb_get_device_list(). 948 | * 949 | * Certain operations can be performed on a device, but in order to do any 950 | * I/O you will have to first obtain a device handle using libusb_open(). 951 | * 952 | * Devices are reference counted with libusb_ref_device() and 953 | * libusb_unref_device(), and are freed when the reference count reaches 0. 954 | * New devices presented by libusb_get_device_list() have a reference count of 955 | * 1, and libusb_free_device_list() can optionally decrease the reference count 956 | * on all devices in the list. libusb_open() adds another reference which is 957 | * later destroyed by libusb_close(). 958 | */ 959 | typedef struct libusb_device libusb_device; 960 | 961 | 962 | /** \ingroup dev 963 | * Structure representing a handle on a USB device. This is an opaque type for 964 | * which you are only ever provided with a pointer, usually originating from 965 | * libusb_open(). 966 | * 967 | * A device handle is used to perform I/O and other operations. When finished 968 | * with a device handle, you should call libusb_close(). 969 | */ 970 | typedef struct libusb_device_handle libusb_device_handle; 971 | 972 | /** \ingroup dev 973 | * Speed codes. Indicates the speed at which the device is operating. 974 | */ 975 | enum libusb_speed { 976 | /** The OS doesn't report or know the device speed. */ 977 | LIBUSB_SPEED_UNKNOWN = 0, 978 | 979 | /** The device is operating at low speed (1.5MBit/s). */ 980 | LIBUSB_SPEED_LOW = 1, 981 | 982 | /** The device is operating at full speed (12MBit/s). */ 983 | LIBUSB_SPEED_FULL = 2, 984 | 985 | /** The device is operating at high speed (480MBit/s). */ 986 | LIBUSB_SPEED_HIGH = 3, 987 | 988 | /** The device is operating at super speed (5000MBit/s). */ 989 | LIBUSB_SPEED_SUPER = 4, 990 | }; 991 | 992 | /** \ingroup dev 993 | * Supported speeds (wSpeedSupported) bitfield. Indicates what 994 | * speeds the device supports. 995 | */ 996 | enum libusb_supported_speed { 997 | /** Low speed operation supported (1.5MBit/s). */ 998 | LIBUSB_LOW_SPEED_OPERATION = 1, 999 | 1000 | /** Full speed operation supported (12MBit/s). */ 1001 | LIBUSB_FULL_SPEED_OPERATION = 2, 1002 | 1003 | /** High speed operation supported (480MBit/s). */ 1004 | LIBUSB_HIGH_SPEED_OPERATION = 4, 1005 | 1006 | /** Superspeed operation supported (5000MBit/s). */ 1007 | LIBUSB_SUPER_SPEED_OPERATION = 8, 1008 | }; 1009 | 1010 | /** \ingroup dev 1011 | * Masks for the bits of the 1012 | * \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field 1013 | * of the USB 2.0 Extension descriptor. 1014 | */ 1015 | enum libusb_usb_2_0_extension_attributes { 1016 | /** Supports Link Power Management (LPM) */ 1017 | LIBUSB_BM_LPM_SUPPORT = 2, 1018 | }; 1019 | 1020 | /** \ingroup dev 1021 | * Masks for the bits of the 1022 | * \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field 1023 | * field of the SuperSpeed USB Device Capability descriptor. 1024 | */ 1025 | enum libusb_ss_usb_device_capability_attributes { 1026 | /** Supports Latency Tolerance Messages (LTM) */ 1027 | LIBUSB_BM_LTM_SUPPORT = 2, 1028 | }; 1029 | 1030 | /** \ingroup dev 1031 | * USB capability types 1032 | */ 1033 | enum libusb_bos_type { 1034 | /** Wireless USB device capability */ 1035 | LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1, 1036 | 1037 | /** USB 2.0 extensions */ 1038 | LIBUSB_BT_USB_2_0_EXTENSION = 2, 1039 | 1040 | /** SuperSpeed USB device capability */ 1041 | LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3, 1042 | 1043 | /** Container ID type */ 1044 | LIBUSB_BT_CONTAINER_ID = 4, 1045 | }; 1046 | 1047 | /** \ingroup misc 1048 | * Error codes. Most libusb functions return 0 on success or one of these 1049 | * codes on failure. 1050 | * You can call libusb_error_name() to retrieve a string representation of an 1051 | * error code or libusb_strerror() to get an end-user suitable description of 1052 | * an error code. 1053 | */ 1054 | enum libusb_error { 1055 | /** Success (no error) */ 1056 | LIBUSB_SUCCESS = 0, 1057 | 1058 | /** Input/output error */ 1059 | LIBUSB_ERROR_IO = -1, 1060 | 1061 | /** Invalid parameter */ 1062 | LIBUSB_ERROR_INVALID_PARAM = -2, 1063 | 1064 | /** Access denied (insufficient permissions) */ 1065 | LIBUSB_ERROR_ACCESS = -3, 1066 | 1067 | /** No such device (it may have been disconnected) */ 1068 | LIBUSB_ERROR_NO_DEVICE = -4, 1069 | 1070 | /** Entity not found */ 1071 | LIBUSB_ERROR_NOT_FOUND = -5, 1072 | 1073 | /** Resource busy */ 1074 | LIBUSB_ERROR_BUSY = -6, 1075 | 1076 | /** Operation timed out */ 1077 | LIBUSB_ERROR_TIMEOUT = -7, 1078 | 1079 | /** Overflow */ 1080 | LIBUSB_ERROR_OVERFLOW = -8, 1081 | 1082 | /** Pipe error */ 1083 | LIBUSB_ERROR_PIPE = -9, 1084 | 1085 | /** System call interrupted (perhaps due to signal) */ 1086 | LIBUSB_ERROR_INTERRUPTED = -10, 1087 | 1088 | /** Insufficient memory */ 1089 | LIBUSB_ERROR_NO_MEM = -11, 1090 | 1091 | /** Operation not supported or unimplemented on this platform */ 1092 | LIBUSB_ERROR_NOT_SUPPORTED = -12, 1093 | 1094 | /* NB: Remember to update LIBUSB_ERROR_COUNT below as well as the 1095 | message strings in strerror.c when adding new error codes here. */ 1096 | 1097 | /** Other error */ 1098 | LIBUSB_ERROR_OTHER = -99, 1099 | }; 1100 | 1101 | /* Total number of error codes in enum libusb_error */ 1102 | #define LIBUSB_ERROR_COUNT 14 1103 | 1104 | /** \ingroup asyncio 1105 | * Transfer status codes */ 1106 | enum libusb_transfer_status { 1107 | /** Transfer completed without error. Note that this does not indicate 1108 | * that the entire amount of requested data was transferred. */ 1109 | LIBUSB_TRANSFER_COMPLETED, 1110 | 1111 | /** Transfer failed */ 1112 | LIBUSB_TRANSFER_ERROR, 1113 | 1114 | /** Transfer timed out */ 1115 | LIBUSB_TRANSFER_TIMED_OUT, 1116 | 1117 | /** Transfer was cancelled */ 1118 | LIBUSB_TRANSFER_CANCELLED, 1119 | 1120 | /** For bulk/interrupt endpoints: halt condition detected (endpoint 1121 | * stalled). For control endpoints: control request not supported. */ 1122 | LIBUSB_TRANSFER_STALL, 1123 | 1124 | /** Device was disconnected */ 1125 | LIBUSB_TRANSFER_NO_DEVICE, 1126 | 1127 | /** Device sent more data than requested */ 1128 | LIBUSB_TRANSFER_OVERFLOW, 1129 | 1130 | /* NB! Remember to update libusb_error_name() 1131 | when adding new status codes here. */ 1132 | }; 1133 | 1134 | /** \ingroup asyncio 1135 | * libusb_transfer.flags values */ 1136 | enum libusb_transfer_flags { 1137 | /** Report short frames as errors */ 1138 | LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0, 1139 | 1140 | /** Automatically free() transfer buffer during libusb_free_transfer() */ 1141 | LIBUSB_TRANSFER_FREE_BUFFER = 1<<1, 1142 | 1143 | /** Automatically call libusb_free_transfer() after callback returns. 1144 | * If this flag is set, it is illegal to call libusb_free_transfer() 1145 | * from your transfer callback, as this will result in a double-free 1146 | * when this flag is acted upon. */ 1147 | LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2, 1148 | 1149 | /** Terminate transfers that are a multiple of the endpoint's 1150 | * wMaxPacketSize with an extra zero length packet. This is useful 1151 | * when a device protocol mandates that each logical request is 1152 | * terminated by an incomplete packet (i.e. the logical requests are 1153 | * not separated by other means). 1154 | * 1155 | * This flag only affects host-to-device transfers to bulk and interrupt 1156 | * endpoints. In other situations, it is ignored. 1157 | * 1158 | * This flag only affects transfers with a length that is a multiple of 1159 | * the endpoint's wMaxPacketSize. On transfers of other lengths, this 1160 | * flag has no effect. Therefore, if you are working with a device that 1161 | * needs a ZLP whenever the end of the logical request falls on a packet 1162 | * boundary, then it is sensible to set this flag on every 1163 | * transfer (you do not have to worry about only setting it on transfers 1164 | * that end on the boundary). 1165 | * 1166 | * This flag is currently only supported on Linux. 1167 | * On other systems, libusb_submit_transfer() will return 1168 | * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set. 1169 | * 1170 | * Available since libusb-1.0.9. 1171 | */ 1172 | LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3, 1173 | }; 1174 | 1175 | /** \ingroup asyncio 1176 | * Isochronous packet descriptor. */ 1177 | struct libusb_iso_packet_descriptor { 1178 | /** Length of data to request in this packet */ 1179 | unsigned int length; 1180 | 1181 | /** Amount of data that was actually transferred */ 1182 | unsigned int actual_length; 1183 | 1184 | /** Status code for this packet */ 1185 | enum libusb_transfer_status status; 1186 | }; 1187 | 1188 | struct libusb_transfer; 1189 | 1190 | /** \ingroup asyncio 1191 | * Asynchronous transfer callback function type. When submitting asynchronous 1192 | * transfers, you pass a pointer to a callback function of this type via the 1193 | * \ref libusb_transfer::callback "callback" member of the libusb_transfer 1194 | * structure. libusb will call this function later, when the transfer has 1195 | * completed or failed. See \ref asyncio for more information. 1196 | * \param transfer The libusb_transfer struct the callback function is being 1197 | * notified about. 1198 | */ 1199 | typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer); 1200 | 1201 | /** \ingroup asyncio 1202 | * The generic USB transfer structure. The user populates this structure and 1203 | * then submits it in order to request a transfer. After the transfer has 1204 | * completed, the library populates the transfer with the results and passes 1205 | * it back to the user. 1206 | */ 1207 | struct libusb_transfer { 1208 | /** Handle of the device that this transfer will be submitted to */ 1209 | libusb_device_handle *dev_handle; 1210 | 1211 | /** A bitwise OR combination of \ref libusb_transfer_flags. */ 1212 | uint8_t flags; 1213 | 1214 | /** Address of the endpoint where this transfer will be sent. */ 1215 | unsigned char endpoint; 1216 | 1217 | /** Type of the endpoint from \ref libusb_transfer_type */ 1218 | unsigned char type; 1219 | 1220 | /** Timeout for this transfer in millseconds. A value of 0 indicates no 1221 | * timeout. */ 1222 | unsigned int timeout; 1223 | 1224 | /** The status of the transfer. Read-only, and only for use within 1225 | * transfer callback function. 1226 | * 1227 | * If this is an isochronous transfer, this field may read COMPLETED even 1228 | * if there were errors in the frames. Use the 1229 | * \ref libusb_iso_packet_descriptor::status "status" field in each packet 1230 | * to determine if errors occurred. */ 1231 | enum libusb_transfer_status status; 1232 | 1233 | /** Length of the data buffer */ 1234 | int length; 1235 | 1236 | /** Actual length of data that was transferred. Read-only, and only for 1237 | * use within transfer callback function. Not valid for isochronous 1238 | * endpoint transfers. */ 1239 | int actual_length; 1240 | 1241 | /** Callback function. This will be invoked when the transfer completes, 1242 | * fails, or is cancelled. */ 1243 | libusb_transfer_cb_fn callback; 1244 | 1245 | /** User context data to pass to the callback function. */ 1246 | void *user_data; 1247 | 1248 | /** Data buffer */ 1249 | unsigned char *buffer; 1250 | 1251 | /** Number of isochronous packets. Only used for I/O with isochronous 1252 | * endpoints. */ 1253 | int num_iso_packets; 1254 | 1255 | /** Isochronous packet descriptors, for isochronous transfers only. */ 1256 | struct libusb_iso_packet_descriptor iso_packet_desc 1257 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) 1258 | [] /* valid C99 code */ 1259 | #else 1260 | [0] /* non-standard, but usually working code */ 1261 | #endif 1262 | ; 1263 | }; 1264 | 1265 | /** \ingroup misc 1266 | * Capabilities supported by an instance of libusb on the current running 1267 | * platform. Test if the loaded library supports a given capability by calling 1268 | * \ref libusb_has_capability(). 1269 | */ 1270 | enum libusb_capability { 1271 | /** The libusb_has_capability() API is available. */ 1272 | LIBUSB_CAP_HAS_CAPABILITY = 0x0000, 1273 | /** Hotplug support is available on this platform. */ 1274 | LIBUSB_CAP_HAS_HOTPLUG = 0x0001, 1275 | /** The library can access HID devices without requiring user intervention. 1276 | * Note that before being able to actually access an HID device, you may 1277 | * still have to call additional libusb functions such as 1278 | * \ref libusb_detach_kernel_driver(). */ 1279 | LIBUSB_CAP_HAS_HID_ACCESS = 0x0100, 1280 | /** The library supports detaching of the default USB driver, using 1281 | * \ref libusb_detach_kernel_driver(), if one is set by the OS kernel */ 1282 | LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101 1283 | }; 1284 | 1285 | /** \ingroup lib 1286 | * Log message levels. 1287 | * - LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library (default) 1288 | * - LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr 1289 | * - LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr 1290 | * - LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to stdout, warning 1291 | * and error messages are printed to stderr 1292 | * - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stdout, 1293 | * warnings and errors to stderr 1294 | */ 1295 | enum libusb_log_level { 1296 | LIBUSB_LOG_LEVEL_NONE = 0, 1297 | LIBUSB_LOG_LEVEL_ERROR, 1298 | LIBUSB_LOG_LEVEL_WARNING, 1299 | LIBUSB_LOG_LEVEL_INFO, 1300 | LIBUSB_LOG_LEVEL_DEBUG, 1301 | }; 1302 | 1303 | int LIBUSB_CALL libusb_init(libusb_context **ctx); 1304 | void LIBUSB_CALL libusb_exit(libusb_context *ctx); 1305 | void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level); 1306 | const struct libusb_version * LIBUSB_CALL libusb_get_version(void); 1307 | int LIBUSB_CALL libusb_has_capability(uint32_t capability); 1308 | const char * LIBUSB_CALL libusb_error_name(int errcode); 1309 | int LIBUSB_CALL libusb_setlocale(const char *locale); 1310 | const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode); 1311 | 1312 | ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx, 1313 | libusb_device ***list); 1314 | void LIBUSB_CALL libusb_free_device_list(libusb_device **list, 1315 | int unref_devices); 1316 | libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev); 1317 | void LIBUSB_CALL libusb_unref_device(libusb_device *dev); 1318 | 1319 | int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev, 1320 | int *config); 1321 | int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev, 1322 | struct libusb_device_descriptor *desc); 1323 | int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev, 1324 | struct libusb_config_descriptor **config); 1325 | int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev, 1326 | uint8_t config_index, struct libusb_config_descriptor **config); 1327 | int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev, 1328 | uint8_t bConfigurationValue, struct libusb_config_descriptor **config); 1329 | void LIBUSB_CALL libusb_free_config_descriptor( 1330 | struct libusb_config_descriptor *config); 1331 | int LIBUSB_CALL libusb_get_ss_endpoint_companion_descriptor( 1332 | struct libusb_context *ctx, 1333 | const struct libusb_endpoint_descriptor *endpoint, 1334 | struct libusb_ss_endpoint_companion_descriptor **ep_comp); 1335 | void LIBUSB_CALL libusb_free_ss_endpoint_companion_descriptor( 1336 | struct libusb_ss_endpoint_companion_descriptor *ep_comp); 1337 | int LIBUSB_CALL libusb_get_bos_descriptor(libusb_device_handle *handle, 1338 | struct libusb_bos_descriptor **bos); 1339 | void LIBUSB_CALL libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos); 1340 | int LIBUSB_CALL libusb_get_usb_2_0_extension_descriptor( 1341 | struct libusb_context *ctx, 1342 | struct libusb_bos_dev_capability_descriptor *dev_cap, 1343 | struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension); 1344 | void LIBUSB_CALL libusb_free_usb_2_0_extension_descriptor( 1345 | struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension); 1346 | int LIBUSB_CALL libusb_get_ss_usb_device_capability_descriptor( 1347 | struct libusb_context *ctx, 1348 | struct libusb_bos_dev_capability_descriptor *dev_cap, 1349 | struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_cap); 1350 | void LIBUSB_CALL libusb_free_ss_usb_device_capability_descriptor( 1351 | struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap); 1352 | int LIBUSB_CALL libusb_get_container_id_descriptor(struct libusb_context *ctx, 1353 | struct libusb_bos_dev_capability_descriptor *dev_cap, 1354 | struct libusb_container_id_descriptor **container_id); 1355 | void LIBUSB_CALL libusb_free_container_id_descriptor( 1356 | struct libusb_container_id_descriptor *container_id); 1357 | uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev); 1358 | uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev); 1359 | int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t* port_numbers, int port_numbers_len); 1360 | LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers) 1361 | int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length); 1362 | libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev); 1363 | uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev); 1364 | int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev); 1365 | int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev, 1366 | unsigned char endpoint); 1367 | int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev, 1368 | unsigned char endpoint); 1369 | 1370 | int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle); 1371 | void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle); 1372 | libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle); 1373 | 1374 | int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev, 1375 | int configuration); 1376 | int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev, 1377 | int interface_number); 1378 | int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev, 1379 | int interface_number); 1380 | 1381 | libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid( 1382 | libusb_context *ctx, uint16_t vendor_id, uint16_t product_id); 1383 | 1384 | int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev, 1385 | int interface_number, int alternate_setting); 1386 | int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev, 1387 | unsigned char endpoint); 1388 | int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev); 1389 | 1390 | int LIBUSB_CALL libusb_alloc_streams(libusb_device_handle *dev, 1391 | uint32_t num_streams, unsigned char *endpoints, int num_endpoints); 1392 | int LIBUSB_CALL libusb_free_streams(libusb_device_handle *dev, 1393 | unsigned char *endpoints, int num_endpoints); 1394 | 1395 | int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev, 1396 | int interface_number); 1397 | int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev, 1398 | int interface_number); 1399 | int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev, 1400 | int interface_number); 1401 | int LIBUSB_CALL libusb_set_auto_detach_kernel_driver( 1402 | libusb_device_handle *dev, int enable); 1403 | 1404 | /* async I/O */ 1405 | 1406 | /** \ingroup asyncio 1407 | * Get the data section of a control transfer. This convenience function is here 1408 | * to remind you that the data does not start until 8 bytes into the actual 1409 | * buffer, as the setup packet comes first. 1410 | * 1411 | * Calling this function only makes sense from a transfer callback function, 1412 | * or situations where you have already allocated a suitably sized buffer at 1413 | * transfer->buffer. 1414 | * 1415 | * \param transfer a transfer 1416 | * \returns pointer to the first byte of the data section 1417 | */ 1418 | static inline unsigned char *libusb_control_transfer_get_data( 1419 | struct libusb_transfer *transfer) 1420 | { 1421 | return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE; 1422 | } 1423 | 1424 | /** \ingroup asyncio 1425 | * Get the control setup packet of a control transfer. This convenience 1426 | * function is here to remind you that the control setup occupies the first 1427 | * 8 bytes of the transfer data buffer. 1428 | * 1429 | * Calling this function only makes sense from a transfer callback function, 1430 | * or situations where you have already allocated a suitably sized buffer at 1431 | * transfer->buffer. 1432 | * 1433 | * \param transfer a transfer 1434 | * \returns a casted pointer to the start of the transfer data buffer 1435 | */ 1436 | static inline struct libusb_control_setup *libusb_control_transfer_get_setup( 1437 | struct libusb_transfer *transfer) 1438 | { 1439 | return (struct libusb_control_setup *)(void *) transfer->buffer; 1440 | } 1441 | 1442 | /** \ingroup asyncio 1443 | * Helper function to populate the setup packet (first 8 bytes of the data 1444 | * buffer) for a control transfer. The wIndex, wValue and wLength values should 1445 | * be given in host-endian byte order. 1446 | * 1447 | * \param buffer buffer to output the setup packet into 1448 | * This pointer must be aligned to at least 2 bytes boundary. 1449 | * \param bmRequestType see the 1450 | * \ref libusb_control_setup::bmRequestType "bmRequestType" field of 1451 | * \ref libusb_control_setup 1452 | * \param bRequest see the 1453 | * \ref libusb_control_setup::bRequest "bRequest" field of 1454 | * \ref libusb_control_setup 1455 | * \param wValue see the 1456 | * \ref libusb_control_setup::wValue "wValue" field of 1457 | * \ref libusb_control_setup 1458 | * \param wIndex see the 1459 | * \ref libusb_control_setup::wIndex "wIndex" field of 1460 | * \ref libusb_control_setup 1461 | * \param wLength see the 1462 | * \ref libusb_control_setup::wLength "wLength" field of 1463 | * \ref libusb_control_setup 1464 | */ 1465 | static inline void libusb_fill_control_setup(unsigned char *buffer, 1466 | uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, 1467 | uint16_t wLength) 1468 | { 1469 | struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer; 1470 | setup->bmRequestType = bmRequestType; 1471 | setup->bRequest = bRequest; 1472 | setup->wValue = libusb_cpu_to_le16(wValue); 1473 | setup->wIndex = libusb_cpu_to_le16(wIndex); 1474 | setup->wLength = libusb_cpu_to_le16(wLength); 1475 | } 1476 | 1477 | struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets); 1478 | int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer); 1479 | int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer); 1480 | void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer); 1481 | void LIBUSB_CALL libusb_transfer_set_stream_id( 1482 | struct libusb_transfer *transfer, uint32_t stream_id); 1483 | uint32_t LIBUSB_CALL libusb_transfer_get_stream_id( 1484 | struct libusb_transfer *transfer); 1485 | 1486 | /** \ingroup asyncio 1487 | * Helper function to populate the required \ref libusb_transfer fields 1488 | * for a control transfer. 1489 | * 1490 | * If you pass a transfer buffer to this function, the first 8 bytes will 1491 | * be interpreted as a control setup packet, and the wLength field will be 1492 | * used to automatically populate the \ref libusb_transfer::length "length" 1493 | * field of the transfer. Therefore the recommended approach is: 1494 | * -# Allocate a suitably sized data buffer (including space for control setup) 1495 | * -# Call libusb_fill_control_setup() 1496 | * -# If this is a host-to-device transfer with a data stage, put the data 1497 | * in place after the setup packet 1498 | * -# Call this function 1499 | * -# Call libusb_submit_transfer() 1500 | * 1501 | * It is also legal to pass a NULL buffer to this function, in which case this 1502 | * function will not attempt to populate the length field. Remember that you 1503 | * must then populate the buffer and length fields later. 1504 | * 1505 | * \param transfer the transfer to populate 1506 | * \param dev_handle handle of the device that will handle the transfer 1507 | * \param buffer data buffer. If provided, this function will interpret the 1508 | * first 8 bytes as a setup packet and infer the transfer length from that. 1509 | * This pointer must be aligned to at least 2 bytes boundary. 1510 | * \param callback callback function to be invoked on transfer completion 1511 | * \param user_data user data to pass to callback function 1512 | * \param timeout timeout for the transfer in milliseconds 1513 | */ 1514 | static inline void libusb_fill_control_transfer( 1515 | struct libusb_transfer *transfer, libusb_device_handle *dev_handle, 1516 | unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data, 1517 | unsigned int timeout) 1518 | { 1519 | struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer; 1520 | transfer->dev_handle = dev_handle; 1521 | transfer->endpoint = 0; 1522 | transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL; 1523 | transfer->timeout = timeout; 1524 | transfer->buffer = buffer; 1525 | if (setup) 1526 | transfer->length = (int) (LIBUSB_CONTROL_SETUP_SIZE 1527 | + libusb_le16_to_cpu(setup->wLength)); 1528 | transfer->user_data = user_data; 1529 | transfer->callback = callback; 1530 | } 1531 | 1532 | /** \ingroup asyncio 1533 | * Helper function to populate the required \ref libusb_transfer fields 1534 | * for a bulk transfer. 1535 | * 1536 | * \param transfer the transfer to populate 1537 | * \param dev_handle handle of the device that will handle the transfer 1538 | * \param endpoint address of the endpoint where this transfer will be sent 1539 | * \param buffer data buffer 1540 | * \param length length of data buffer 1541 | * \param callback callback function to be invoked on transfer completion 1542 | * \param user_data user data to pass to callback function 1543 | * \param timeout timeout for the transfer in milliseconds 1544 | */ 1545 | static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer, 1546 | libusb_device_handle *dev_handle, unsigned char endpoint, 1547 | unsigned char *buffer, int length, libusb_transfer_cb_fn callback, 1548 | void *user_data, unsigned int timeout) 1549 | { 1550 | transfer->dev_handle = dev_handle; 1551 | transfer->endpoint = endpoint; 1552 | transfer->type = LIBUSB_TRANSFER_TYPE_BULK; 1553 | transfer->timeout = timeout; 1554 | transfer->buffer = buffer; 1555 | transfer->length = length; 1556 | transfer->user_data = user_data; 1557 | transfer->callback = callback; 1558 | } 1559 | 1560 | /** \ingroup asyncio 1561 | * Helper function to populate the required \ref libusb_transfer fields 1562 | * for a bulk transfer using bulk streams. 1563 | * 1564 | * Since version 1.0.19, \ref LIBUSB_API_VERSION >= 0x01000103 1565 | * 1566 | * \param transfer the transfer to populate 1567 | * \param dev_handle handle of the device that will handle the transfer 1568 | * \param endpoint address of the endpoint where this transfer will be sent 1569 | * \param stream_id bulk stream id for this transfer 1570 | * \param buffer data buffer 1571 | * \param length length of data buffer 1572 | * \param callback callback function to be invoked on transfer completion 1573 | * \param user_data user data to pass to callback function 1574 | * \param timeout timeout for the transfer in milliseconds 1575 | */ 1576 | static inline void libusb_fill_bulk_stream_transfer( 1577 | struct libusb_transfer *transfer, libusb_device_handle *dev_handle, 1578 | unsigned char endpoint, uint32_t stream_id, 1579 | unsigned char *buffer, int length, libusb_transfer_cb_fn callback, 1580 | void *user_data, unsigned int timeout) 1581 | { 1582 | libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer, 1583 | length, callback, user_data, timeout); 1584 | transfer->type = LIBUSB_TRANSFER_TYPE_BULK_STREAM; 1585 | libusb_transfer_set_stream_id(transfer, stream_id); 1586 | } 1587 | 1588 | /** \ingroup asyncio 1589 | * Helper function to populate the required \ref libusb_transfer fields 1590 | * for an interrupt transfer. 1591 | * 1592 | * \param transfer the transfer to populate 1593 | * \param dev_handle handle of the device that will handle the transfer 1594 | * \param endpoint address of the endpoint where this transfer will be sent 1595 | * \param buffer data buffer 1596 | * \param length length of data buffer 1597 | * \param callback callback function to be invoked on transfer completion 1598 | * \param user_data user data to pass to callback function 1599 | * \param timeout timeout for the transfer in milliseconds 1600 | */ 1601 | static inline void libusb_fill_interrupt_transfer( 1602 | struct libusb_transfer *transfer, libusb_device_handle *dev_handle, 1603 | unsigned char endpoint, unsigned char *buffer, int length, 1604 | libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout) 1605 | { 1606 | transfer->dev_handle = dev_handle; 1607 | transfer->endpoint = endpoint; 1608 | transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT; 1609 | transfer->timeout = timeout; 1610 | transfer->buffer = buffer; 1611 | transfer->length = length; 1612 | transfer->user_data = user_data; 1613 | transfer->callback = callback; 1614 | } 1615 | 1616 | /** \ingroup asyncio 1617 | * Helper function to populate the required \ref libusb_transfer fields 1618 | * for an isochronous transfer. 1619 | * 1620 | * \param transfer the transfer to populate 1621 | * \param dev_handle handle of the device that will handle the transfer 1622 | * \param endpoint address of the endpoint where this transfer will be sent 1623 | * \param buffer data buffer 1624 | * \param length length of data buffer 1625 | * \param num_iso_packets the number of isochronous packets 1626 | * \param callback callback function to be invoked on transfer completion 1627 | * \param user_data user data to pass to callback function 1628 | * \param timeout timeout for the transfer in milliseconds 1629 | */ 1630 | static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer, 1631 | libusb_device_handle *dev_handle, unsigned char endpoint, 1632 | unsigned char *buffer, int length, int num_iso_packets, 1633 | libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout) 1634 | { 1635 | transfer->dev_handle = dev_handle; 1636 | transfer->endpoint = endpoint; 1637 | transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS; 1638 | transfer->timeout = timeout; 1639 | transfer->buffer = buffer; 1640 | transfer->length = length; 1641 | transfer->num_iso_packets = num_iso_packets; 1642 | transfer->user_data = user_data; 1643 | transfer->callback = callback; 1644 | } 1645 | 1646 | /** \ingroup asyncio 1647 | * Convenience function to set the length of all packets in an isochronous 1648 | * transfer, based on the num_iso_packets field in the transfer structure. 1649 | * 1650 | * \param transfer a transfer 1651 | * \param length the length to set in each isochronous packet descriptor 1652 | * \see libusb_get_max_packet_size() 1653 | */ 1654 | static inline void libusb_set_iso_packet_lengths( 1655 | struct libusb_transfer *transfer, unsigned int length) 1656 | { 1657 | int i; 1658 | for (i = 0; i < transfer->num_iso_packets; i++) 1659 | transfer->iso_packet_desc[i].length = length; 1660 | } 1661 | 1662 | /** \ingroup asyncio 1663 | * Convenience function to locate the position of an isochronous packet 1664 | * within the buffer of an isochronous transfer. 1665 | * 1666 | * This is a thorough function which loops through all preceding packets, 1667 | * accumulating their lengths to find the position of the specified packet. 1668 | * Typically you will assign equal lengths to each packet in the transfer, 1669 | * and hence the above method is sub-optimal. You may wish to use 1670 | * libusb_get_iso_packet_buffer_simple() instead. 1671 | * 1672 | * \param transfer a transfer 1673 | * \param packet the packet to return the address of 1674 | * \returns the base address of the packet buffer inside the transfer buffer, 1675 | * or NULL if the packet does not exist. 1676 | * \see libusb_get_iso_packet_buffer_simple() 1677 | */ 1678 | static inline unsigned char *libusb_get_iso_packet_buffer( 1679 | struct libusb_transfer *transfer, unsigned int packet) 1680 | { 1681 | int i; 1682 | size_t offset = 0; 1683 | int _packet; 1684 | 1685 | /* oops..slight bug in the API. packet is an unsigned int, but we use 1686 | * signed integers almost everywhere else. range-check and convert to 1687 | * signed to avoid compiler warnings. FIXME for libusb-2. */ 1688 | if (packet > INT_MAX) 1689 | return NULL; 1690 | _packet = (int) packet; 1691 | 1692 | if (_packet >= transfer->num_iso_packets) 1693 | return NULL; 1694 | 1695 | for (i = 0; i < _packet; i++) 1696 | offset += transfer->iso_packet_desc[i].length; 1697 | 1698 | return transfer->buffer + offset; 1699 | } 1700 | 1701 | /** \ingroup asyncio 1702 | * Convenience function to locate the position of an isochronous packet 1703 | * within the buffer of an isochronous transfer, for transfers where each 1704 | * packet is of identical size. 1705 | * 1706 | * This function relies on the assumption that every packet within the transfer 1707 | * is of identical size to the first packet. Calculating the location of 1708 | * the packet buffer is then just a simple calculation: 1709 | * buffer + (packet_size * packet) 1710 | * 1711 | * Do not use this function on transfers other than those that have identical 1712 | * packet lengths for each packet. 1713 | * 1714 | * \param transfer a transfer 1715 | * \param packet the packet to return the address of 1716 | * \returns the base address of the packet buffer inside the transfer buffer, 1717 | * or NULL if the packet does not exist. 1718 | * \see libusb_get_iso_packet_buffer() 1719 | */ 1720 | static inline unsigned char *libusb_get_iso_packet_buffer_simple( 1721 | struct libusb_transfer *transfer, unsigned int packet) 1722 | { 1723 | int _packet; 1724 | 1725 | /* oops..slight bug in the API. packet is an unsigned int, but we use 1726 | * signed integers almost everywhere else. range-check and convert to 1727 | * signed to avoid compiler warnings. FIXME for libusb-2. */ 1728 | if (packet > INT_MAX) 1729 | return NULL; 1730 | _packet = (int) packet; 1731 | 1732 | if (_packet >= transfer->num_iso_packets) 1733 | return NULL; 1734 | 1735 | return transfer->buffer + ((int) transfer->iso_packet_desc[0].length * _packet); 1736 | } 1737 | 1738 | /* sync I/O */ 1739 | 1740 | int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle, 1741 | uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, 1742 | unsigned char *data, uint16_t wLength, unsigned int timeout); 1743 | 1744 | int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle, 1745 | unsigned char endpoint, unsigned char *data, int length, 1746 | int *actual_length, unsigned int timeout); 1747 | 1748 | int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle, 1749 | unsigned char endpoint, unsigned char *data, int length, 1750 | int *actual_length, unsigned int timeout); 1751 | 1752 | /** \ingroup desc 1753 | * Retrieve a descriptor from the default control pipe. 1754 | * This is a convenience function which formulates the appropriate control 1755 | * message to retrieve the descriptor. 1756 | * 1757 | * \param dev a device handle 1758 | * \param desc_type the descriptor type, see \ref libusb_descriptor_type 1759 | * \param desc_index the index of the descriptor to retrieve 1760 | * \param data output buffer for descriptor 1761 | * \param length size of data buffer 1762 | * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure 1763 | */ 1764 | static inline int libusb_get_descriptor(libusb_device_handle *dev, 1765 | uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length) 1766 | { 1767 | return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN, 1768 | LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t) ((desc_type << 8) | desc_index), 1769 | 0, data, (uint16_t) length, 1000); 1770 | } 1771 | 1772 | /** \ingroup desc 1773 | * Retrieve a descriptor from a device. 1774 | * This is a convenience function which formulates the appropriate control 1775 | * message to retrieve the descriptor. The string returned is Unicode, as 1776 | * detailed in the USB specifications. 1777 | * 1778 | * \param dev a device handle 1779 | * \param desc_index the index of the descriptor to retrieve 1780 | * \param langid the language ID for the string descriptor 1781 | * \param data output buffer for descriptor 1782 | * \param length size of data buffer 1783 | * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure 1784 | * \see libusb_get_string_descriptor_ascii() 1785 | */ 1786 | static inline int libusb_get_string_descriptor(libusb_device_handle *dev, 1787 | uint8_t desc_index, uint16_t langid, unsigned char *data, int length) 1788 | { 1789 | return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN, 1790 | LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index), 1791 | langid, data, (uint16_t) length, 1000); 1792 | } 1793 | 1794 | int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev, 1795 | uint8_t desc_index, unsigned char *data, int length); 1796 | 1797 | /* polling and timeouts */ 1798 | 1799 | int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx); 1800 | void LIBUSB_CALL libusb_lock_events(libusb_context *ctx); 1801 | void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx); 1802 | int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx); 1803 | int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx); 1804 | void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx); 1805 | void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx); 1806 | int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv); 1807 | 1808 | int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx, 1809 | struct timeval *tv); 1810 | int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx, 1811 | struct timeval *tv, int *completed); 1812 | int LIBUSB_CALL libusb_handle_events(libusb_context *ctx); 1813 | int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed); 1814 | int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx, 1815 | struct timeval *tv); 1816 | int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx); 1817 | int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx, 1818 | struct timeval *tv); 1819 | 1820 | /** \ingroup poll 1821 | * File descriptor for polling 1822 | */ 1823 | struct libusb_pollfd { 1824 | /** Numeric file descriptor */ 1825 | int fd; 1826 | 1827 | /** Event flags to poll for from . POLLIN indicates that you 1828 | * should monitor this file descriptor for becoming ready to read from, 1829 | * and POLLOUT indicates that you should monitor this file descriptor for 1830 | * nonblocking write readiness. */ 1831 | short events; 1832 | }; 1833 | 1834 | /** \ingroup poll 1835 | * Callback function, invoked when a new file descriptor should be added 1836 | * to the set of file descriptors monitored for events. 1837 | * \param fd the new file descriptor 1838 | * \param events events to monitor for, see \ref libusb_pollfd for a 1839 | * description 1840 | * \param user_data User data pointer specified in 1841 | * libusb_set_pollfd_notifiers() call 1842 | * \see libusb_set_pollfd_notifiers() 1843 | */ 1844 | typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events, 1845 | void *user_data); 1846 | 1847 | /** \ingroup poll 1848 | * Callback function, invoked when a file descriptor should be removed from 1849 | * the set of file descriptors being monitored for events. After returning 1850 | * from this callback, do not use that file descriptor again. 1851 | * \param fd the file descriptor to stop monitoring 1852 | * \param user_data User data pointer specified in 1853 | * libusb_set_pollfd_notifiers() call 1854 | * \see libusb_set_pollfd_notifiers() 1855 | */ 1856 | typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data); 1857 | 1858 | const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds( 1859 | libusb_context *ctx); 1860 | void LIBUSB_CALL libusb_free_pollfds(const struct libusb_pollfd **pollfds); 1861 | void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx, 1862 | libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, 1863 | void *user_data); 1864 | 1865 | /** \ingroup hotplug 1866 | * Callback handle. 1867 | * 1868 | * Callbacks handles are generated by libusb_hotplug_register_callback() 1869 | * and can be used to deregister callbacks. Callback handles are unique 1870 | * per libusb_context and it is safe to call libusb_hotplug_deregister_callback() 1871 | * on an already deregisted callback. 1872 | * 1873 | * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1874 | * 1875 | * For more information, see \ref hotplug. 1876 | */ 1877 | typedef int libusb_hotplug_callback_handle; 1878 | 1879 | /** \ingroup hotplug 1880 | * 1881 | * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1882 | * 1883 | * Flags for hotplug events */ 1884 | typedef enum { 1885 | /** Default value when not using any flags. */ 1886 | LIBUSB_HOTPLUG_NO_FLAGS = 0, 1887 | 1888 | /** Arm the callback and fire it for all matching currently attached devices. */ 1889 | LIBUSB_HOTPLUG_ENUMERATE = 1<<0, 1890 | } libusb_hotplug_flag; 1891 | 1892 | /** \ingroup hotplug 1893 | * 1894 | * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1895 | * 1896 | * Hotplug events */ 1897 | typedef enum { 1898 | /** A device has been plugged in and is ready to use */ 1899 | LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01, 1900 | 1901 | /** A device has left and is no longer available. 1902 | * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device. 1903 | * It is safe to call libusb_get_device_descriptor on a device that has left */ 1904 | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02, 1905 | } libusb_hotplug_event; 1906 | 1907 | /** \ingroup hotplug 1908 | * Wildcard matching for hotplug events */ 1909 | #define LIBUSB_HOTPLUG_MATCH_ANY -1 1910 | 1911 | /** \ingroup hotplug 1912 | * Hotplug callback function type. When requesting hotplug event notifications, 1913 | * you pass a pointer to a callback function of this type. 1914 | * 1915 | * This callback may be called by an internal event thread and as such it is 1916 | * recommended the callback do minimal processing before returning. 1917 | * 1918 | * libusb will call this function later, when a matching event had happened on 1919 | * a matching device. See \ref hotplug for more information. 1920 | * 1921 | * It is safe to call either libusb_hotplug_register_callback() or 1922 | * libusb_hotplug_deregister_callback() from within a callback function. 1923 | * 1924 | * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1925 | * 1926 | * \param ctx context of this notification 1927 | * \param device libusb_device this event occurred on 1928 | * \param event event that occurred 1929 | * \param user_data user data provided when this callback was registered 1930 | * \returns bool whether this callback is finished processing events. 1931 | * returning 1 will cause this callback to be deregistered 1932 | */ 1933 | typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx, 1934 | libusb_device *device, 1935 | libusb_hotplug_event event, 1936 | void *user_data); 1937 | 1938 | /** \ingroup hotplug 1939 | * Register a hotplug callback function 1940 | * 1941 | * Register a callback with the libusb_context. The callback will fire 1942 | * when a matching event occurs on a matching device. The callback is 1943 | * armed until either it is deregistered with libusb_hotplug_deregister_callback() 1944 | * or the supplied callback returns 1 to indicate it is finished processing events. 1945 | * 1946 | * If the \ref LIBUSB_HOTPLUG_ENUMERATE is passed the callback will be 1947 | * called with a \ref LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED for all devices 1948 | * already plugged into the machine. Note that libusb modifies its internal 1949 | * device list from a separate thread, while calling hotplug callbacks from 1950 | * libusb_handle_events(), so it is possible for a device to already be present 1951 | * on, or removed from, its internal device list, while the hotplug callbacks 1952 | * still need to be dispatched. This means that when using \ref 1953 | * LIBUSB_HOTPLUG_ENUMERATE, your callback may be called twice for the arrival 1954 | * of the same device, once from libusb_hotplug_register_callback() and once 1955 | * from libusb_handle_events(); and/or your callback may be called for the 1956 | * removal of a device for which an arrived call was never made. 1957 | * 1958 | * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1959 | * 1960 | * \param[in] ctx context to register this callback with 1961 | * \param[in] events bitwise or of events that will trigger this callback. See \ref 1962 | * libusb_hotplug_event 1963 | * \param[in] flags hotplug callback flags. See \ref libusb_hotplug_flag 1964 | * \param[in] vendor_id the vendor id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY 1965 | * \param[in] product_id the product id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY 1966 | * \param[in] dev_class the device class to match or \ref LIBUSB_HOTPLUG_MATCH_ANY 1967 | * \param[in] cb_fn the function to be invoked on a matching event/device 1968 | * \param[in] user_data user data to pass to the callback function 1969 | * \param[out] handle pointer to store the handle of the allocated callback (can be NULL) 1970 | * \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure 1971 | */ 1972 | int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx, 1973 | libusb_hotplug_event events, 1974 | libusb_hotplug_flag flags, 1975 | int vendor_id, int product_id, 1976 | int dev_class, 1977 | libusb_hotplug_callback_fn cb_fn, 1978 | void *user_data, 1979 | libusb_hotplug_callback_handle *handle); 1980 | 1981 | /** \ingroup hotplug 1982 | * Deregisters a hotplug callback. 1983 | * 1984 | * Deregister a callback from a libusb_context. This function is safe to call from within 1985 | * a hotplug callback. 1986 | * 1987 | * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1988 | * 1989 | * \param[in] ctx context this callback is registered with 1990 | * \param[in] handle the handle of the callback to deregister 1991 | */ 1992 | void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx, 1993 | libusb_hotplug_callback_handle handle); 1994 | 1995 | #ifdef __cplusplus 1996 | } 1997 | #endif 1998 | 1999 | #endif 2000 | --------------------------------------------------------------------------------