User Tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
code:sub2r-lib [2019/04/03 02:31] – [Windows] Igor Yefmovcode:sub2r-lib [2022/09/10 20:39] (current) – [Basic "vendor request" call] Igor Yefmov
Line 1: Line 1:
 ====== Windows ====== ====== Windows ======
  
-You can download the library from [[http://download.sub2r.com/SUB2r-lib-2019-04-03.zip|this location]]. What you get in this package is:+You can download the library from [[http://sub2r-download.com/SUB2r-lib-2022-08-22.zip|this location]]. What you get in this package is:
   - A header file ''FX3.h'' - the only include you need besides the standard headers   - A header file ''FX3.h'' - the only include you need besides the standard headers
   - Both ''Release'' and ''Debug'' libraries with full symbol files (''.pdb'') and support for edit and continue (''.idb'' - currently only for ''Debug'' mode). These include the libraries from Cypress that this package depends on.   - Both ''Release'' and ''Debug'' libraries with full symbol files (''.pdb'') and support for edit and continue (''.idb'' - currently only for ''Debug'' mode). These include the libraries from Cypress that this package depends on.
-  - A sample code that demonstrates some basics on how to use the library: ''sample1.cpp''+  - Sample code that demonstrates some basics on how to use the library: ''sample1.cpp'' 
 +  - Sample code that showcases the use of ''sysinfo'': ''sample2.cpp'' 
 +  - Sample code for controlling FPS: ''sample3.cpp''
  
-The library is built using MSVC 2017 version ''15.9.10'' with Windows SDK ''10.0.17763.0'' for use with ''UNICODE'' and ''multi-threaded'' CRT in ''64-bit'' mode only. The library requires a C++17 toolchain to be built.+The library is built using MSVC 2022 version ''17.3.1'' with Windows SDK ''10.0.19041.0'' for use with ''UNICODE'' and ''multi-threaded'' CRT in ''64-bit'' and ''32-bit'' mode. The library requires a C++20 toolchain to be built.
  
-===== byte_span ===== +===== Basic "vendor request" call =====
-Beginning with version ''2018-09-05'' the code relies on [[https://github.com/Microsoft/GSL|Guidelines Support Library]] (GSL). Part of that change is to use ''gsl::span<std::byte>'' to represent raw byte buffers.+
  
-Quite often a need arises to represent "simpledata types (like ''uint32_t'') as a byte buffer when using hardware API. To reduce the potential for stupid bugs and make code more readable it is recommended to use the provided <code c++>template<class T> gsl::span<std::byte> byte_span(T& _x) noexcept;</code> function when such a buffer's address is needed. +SUB2r API calls are implemented as USB "vendor requestcommands, where ''USB_SETUP_PACKET::bmRequest::Type'' is set to ''2'', following the USB specification.
- +
-All the library's methods were updated to conform to this calling convention.+
  
 Sample usage: Sample usage:
Line 19: Line 18:
 using S2R::FX3; using S2R::FX3;
 FX3 fx3; // by default opens device #0 FX3 fx3; // by default opens device #0
-if(fx3){ +if(fx3.isValid()){ 
-    uint32_t vi{};+    array<std::byte, 4> vi{};
     const auto rc{m_fx3.vrCmd(Fx3Cmd::fx3_version // vendor request command     const auto rc{m_fx3.vrCmd(Fx3Cmd::fx3_version // vendor request command
-                              , VrCmdOpType::read // read from device +                            , VrCmdOpType::read   // read from device 
-                              , 0                 // "value" +                            , 0                   // "value" 
-                              , 0                 // "index" +                            , 0                   // "index" 
-                              byte_span(vi))};  // buffer to read into+                            , vi)};               // buffer to read into
     return vi;                                    // 32 bits of the "version info" (4 bytes)     return vi;                                    // 32 bits of the "version info" (4 bytes)
 } }
Line 360: Line 359:
 | <code c++>m_rollingbar</code> | enable/disable a rolling bar, only valid when ''m_mode == color_bar'' | | <code c++>m_rollingbar</code> | enable/disable a rolling bar, only valid when ''m_mode == color_bar'' |
 | <code c++>m_enabled</code> | enable/disable the test pattern mode | | <code c++>m_enabled</code> | enable/disable the test pattern mode |
- 
- 
-==== UFix_8_8 ==== 
-{{ :code:class-ufix_8_8.png?nolink|Class diagram - UFix_8_8}} 
- 
-A helper class for working with a 2-byte floating number format used to specify fractional parameters for the FX3. More details are available in  [[code:numberformats#ufix_88|UFIX 8.8 documentation]]. 
- 
-^ Method ^ Signature ^ Functionality ^ 
-| ''constructor'' | <code c++>constexpr 
-  UFix_8_8( 
-      uint8_t _i 
-    , uint8_t _f = 0 
-    ) noexcept</code> | construct a number from provided integer (''_i'') and fractional (''_f'') parts, for example: <code c++>auto uf88{1, 128}; // uf88 is now 1.5</code>No validation is performed to make sure the ''_f'' is in range [''0''..''255''] | 
-| ''constructor'' | <code c++>constexpr 
-  UFix_8_8(double _d) 
-    noexcept;</code> | construct from a floating-point number, i.e.: <code c++>auto uf88{1.2};</code> | 
-| ''constructor'' | <code c++>UFix_8_8( 
-    gsl::span<const std::byte> _buf 
-    ) noexcept;</code> | use this constructor when you read a 2-byte ''UFix_8_8'' value from FX3 | 
-| ''operator double'' | <code c++>constexpr 
-  operator double() const 
-    noexcept;</code> | a type conversion into a floating-point number | 
-| ''operator uint16_t'' | <code c++>constexpr 
-  operator uint16_t() const 
-    noexcept;</code> | make 2 bytes that are ready to be written to FX3, for example:<code c++>// omitting all the error checks!!! 
-uint8_t valI{1}, valF{128}; 
-auto val{S2R::UFix_8_8(valI, valF)}; 
-S2R::I2C dev; 
-// a port to set the image adjustment auto- 
-// functions' update interval 
-constexpr uint8_t port{0xDF}; 
-dev.vrCmd(port, S2R::FX3::write, val, 0); 
-</code> | 
  
  
Line 411: Line 377:
     using namespace S2R;     using namespace S2R;
  
-    cout << "SUB2r-lib sample #1: basic functionality" << endl << endl;+    cout << "SUB2r-lib sample #1: basic functionality\n\n";
  
-    I2C dev; +    const auto numDevs{ImgSensor::deviceCount()}
-    const auto numDevs = dev.deviceCount(); +    cout << "Cypress devices attached to this system: " << static_cast<int>(numDevs) << "\n\n"; 
-    cout << "Cypress devices attached to this system: " << static_cast<int>(numDevs) << endl << endl+    ImgSensor dev(false)
-    for(uint8_t i = 0; i < numDevs; ++i){ +    for(uint8_t i{}; i < numDevs; ++i){ 
-        auto GAIN_R = IImgSensor::Value::gain_r;+        auto GAIN_R{IImgSensorChip::Value::gain_r};
         cout << "Opening device #" << static_cast<int>(i) << "... ";         cout << "Opening device #" << static_cast<int>(i) << "... ";
         if(dev.open(i)){         if(dev.open(i)){
-            wcout << L"success.\nDevice name is: " << dev[FX3::PropWString::friendly_name].c_str() << endl+            wcout << L"success.\nDevice name is: " << dev[FX3::PropWString::friendly_name].c_str() << "\n"
-            cout << "Sensor chipset: " << dev->chipsetName() << endl+            cout << "Sensor chipset: " << dev->chipsetName() << "\n"
-            cout << "FX3 version info: " << string(dev.fx3Version()) << endl+            cout << "FX3 version info: " << string(dev.fx3Version()) << "\n"
-            cout << "FPGA version info: " << string(dev.fpgaVersion()) << endl+            cout << "FPGA version info: " << string(dev.fpgaVersion()) << "\n"
-            auto & ov = *dev.sensor();  // make a shortcut to the sensor chip +            
-            if(dev){    // or dev.isValid() works, too +                auto & ov{dev.sensor()}  // shortcut to the sensor chip 
-                cout << "current red channel gain is: " << dev->val(GAIN_R) << endl+                cout << "current red channel gain is: " << dev->val(GAIN_R) << "\n"
-                auto gainR ov[GAIN_R];+                auto gainR{ov[GAIN_R]};
                 gainR = gainR + 1;  // increment the red gain by one and update the sensor with the new value                 gainR = gainR + 1;  // increment the red gain by one and update the sensor with the new value
-                cout << "after increasing red channel gain by 1 it is now: " << gainR << endl;+                cout << "after increasing red channel gain by 1 it is now: " << gainR << "\n";
                 ov[GAIN_R] -= 1;                 ov[GAIN_R] -= 1;
-                cout << "and back to the previous value of: " << gainR << endl;+                cout << "and back to the previous value of: " << gainR << "\n";
                 ov[GAIN_R] *= 1.0;                 ov[GAIN_R] *= 1.0;
             }             }
Line 437: Line 403:
             dev.close();    // or the destructor (or even the next call to open()) will take care of that             dev.close();    // or the destructor (or even the next call to open()) will take care of that
             if(dev){             if(dev){
-                cout << "something has gone terribly wrong - the device was supposed to be closed by now!" << endl;+                cout << "something has gone terribly wrong - the device was supposed to be closed by now!\n";
             }else{             }else{
-                cout << "the device is now closed and cannot be accessed without re-opening it" << endl+                cout << "the device is now closed and cannot be accessed without re-opening it\n"; 
-                cout << "For example the red channel gain is now: " << ov[GAIN_R] << endl+                cout << "For example the red channel gain is now: " << dev.sensor()[GAIN_R] << "\n"
-                cout << "But some info is still available, like the sensor chipset: " << dev->chipsetName() << endl+                cout << "But some info is still available, like the sensor chipset: " << dev->chipsetName() << "\n"
-                cout << "Or the information about the limit of red channel gain: " << dev->getLimit(GAIN_R) << endl;+                cout << "Or the information about the limit of red channel gain: " << dev->getLimit(GAIN_R) << "\n";
             }             }
         }else{         }else{
-            cout << "failed." << endl;+            cout << "failed.\n";
             if(dev.isValid()){             if(dev.isValid()){
-                wcout << L"But the FX3 part is still functional, so we can get info like the device's name: " << dev[FX3::PropWString::friendly_name].c_str() << endl;+                wcout << L"But the FX3 part is still functional, so we can get info like the device's name: " << dev[FX3::PropWString::friendly_name].c_str() << "\n";
             }             }
         }         }
-        cout << endl;+        cout << "\n";
     }     }
     return 0;     return 0;
Line 469: Line 435:
 FIXME FIXME
  
 +====== Previous versions ======
  
 +  * [[SUB2r-lib-2020-10-08]]
 +  * [[SUB2r-lib-2019-04-29]]

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information