Skip to content

Commit 524fd59

Browse files
committed
check: device setUSBParameters
1 parent 4b1036b commit 524fd59

File tree

5 files changed

+69
-23
lines changed

5 files changed

+69
-23
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ list(APPEND SRC "src/api/FTDI_Device_setDataCharacteristics.c")
3131
list(APPEND SRC "src/api/FTDI_Device_setFlowControl.c")
3232
list(APPEND SRC "src/api/FTDI_Device_setLatencyTimer.c")
3333
list(APPEND SRC "src/api/FTDI_Device_setTimeouts.c")
34+
list(APPEND SRC "src/api/FTDI_Device_setUSBParameters.c")
3435
list(APPEND SRC "src/api/FTDI_Device_simpleFunctions.c")
3536
list(APPEND SRC "src/api/FTDI_Device_write.c")
3637
list(APPEND SRC "src/api/FTDI_Device_writeEE.c")

inc/api/FTDI_Device.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ napi_value device_setDataCharacteristics(napi_env env, napi_callback_info info);
3434
napi_value device_setFlowControl(napi_env env, napi_callback_info info);
3535
napi_value device_setLatencyTimer(napi_env env, napi_callback_info info);
3636
napi_value device_setTimeouts(napi_env env, napi_callback_info info);
37+
napi_value device_setUSBParameters(napi_env env, napi_callback_info info);
3738
napi_value device_setDtr(napi_env env, napi_callback_info info);
3839
napi_value device_setRts(napi_env env, napi_callback_info info);
3940
napi_value device_setBreakOn(napi_env env, napi_callback_info info);

main.d.ts

+35-21
Original file line numberDiff line numberDiff line change
@@ -153,27 +153,6 @@ declare class FTDI_Device {
153153
*/
154154
setFlowControl(flow_control: number, xon: number, xoff: number): void;
155155

156-
/** Sets the latency timer value (supported devices only)
157-
* @param timer Latency timer value, in milliseconds. Valid range is 2 to 255.
158-
*/
159-
setLatencyTimer(timer: number): void;
160-
161-
/** Enables different chip modes (puts the device in a mode other than the default UART or FIFO mode).
162-
* @param mask Bit mode mask
163-
* Sets up which bits are inputs and which are outputs.
164-
* A bit value of 0 sets the corresponding pin to an input, a bit value of 1 sets the corresponding pin to an output.
165-
* In the case of CBUS Bit Bang, the upper nibble of this value controls which pins are inputs and outputs, while the lower nibble controls which of the outputs are high and low.
166-
* @param bit_mode Mode value. Can be one of the following:
167-
* For FT232H devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_MPSSE, FT_BIT_MODE_SYNC_BITBANG, FT_BIT_MODE_CBUS_BITBANG, FT_BIT_MODE_MCU_HOST, FT_BIT_MODE_FAST_SERIAL, FT_BIT_MODE_SYNC_FIFO.
168-
* For FT2232H devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_MPSSE, FT_BIT_MODE_SYNC_BITBANG, FT_BIT_MODE_MCU_HOST, FT_BIT_MODE_FAST_SERIAL, FT_BIT_MODE_SYNC_FIFO.
169-
* For FT4232H devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_MPSSE, FT_BIT_MODE_SYNC_BITBANG.
170-
* For FT232R devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_SYNC_BITBANG, FT_BIT_MODE_CBUS_BITBANG.
171-
* For FT245R devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_SYNC_BITBANG.
172-
* For FT2232 devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_MPSSE, FT_BIT_MODE_SYNC_BITBANG, FT_BIT_MODE_MCU_HOST, FT_BIT_MODE_FAST_SERIAL.
173-
* For FT232B and FT245B devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG.
174-
*/
175-
setBitMode(mask: number, bit_mode: number): void;
176-
177156
/** Sets the Data Terminal Ready (DTR) control signal */
178157
setDtr(): void;
179158

@@ -209,6 +188,41 @@ declare class FTDI_Device {
209188

210189
/** Erases the device EEPROM */
211190
eraseEE(): Promise<void>;
191+
192+
/** Sets the latency timer value (supported devices only)
193+
* @param timer Latency timer value, in milliseconds. Valid range is 2 to 255.
194+
*/
195+
setLatencyTimer(timer: number): void;
196+
197+
/** Enables different chip modes (puts the device in a mode other than the default UART or FIFO mode).
198+
* @param mask Bit mode mask
199+
* Sets up which bits are inputs and which are outputs.
200+
* A bit value of 0 sets the corresponding pin to an input, a bit value of 1 sets the corresponding pin to an output.
201+
* In the case of CBUS Bit Bang, the upper nibble of this value controls which pins are inputs and outputs, while the lower nibble controls which of the outputs are high and low.
202+
* @param bit_mode Mode value. Can be one of the following:
203+
* For FT232H devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_MPSSE, FT_BIT_MODE_SYNC_BITBANG, FT_BIT_MODE_CBUS_BITBANG, FT_BIT_MODE_MCU_HOST, FT_BIT_MODE_FAST_SERIAL, FT_BIT_MODE_SYNC_FIFO.
204+
* For FT2232H devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_MPSSE, FT_BIT_MODE_SYNC_BITBANG, FT_BIT_MODE_MCU_HOST, FT_BIT_MODE_FAST_SERIAL, FT_BIT_MODE_SYNC_FIFO.
205+
* For FT4232H devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_MPSSE, FT_BIT_MODE_SYNC_BITBANG.
206+
* For FT232R devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_SYNC_BITBANG, FT_BIT_MODE_CBUS_BITBANG.
207+
* For FT245R devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_SYNC_BITBANG.
208+
* For FT2232 devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG, FT_BIT_MODE_MPSSE, FT_BIT_MODE_SYNC_BITBANG, FT_BIT_MODE_MCU_HOST, FT_BIT_MODE_FAST_SERIAL.
209+
* For FT232B and FT245B devices, valid values are FT_BIT_MODE_RESET, FT_BIT_MODE_ASYNC_BITBANG.
210+
*/
211+
setBitMode(mask: number, bit_mode: number): void;
212+
213+
/** Sets the USB request transfer size
214+
*
215+
* This function can be used to change the transfer sizes from the default transfer size of 4096 bytes to
216+
* better suit the application requirements. Transfer sizes must be set to a multiple of 64 bytes between 64
217+
* bytes and 64k bytes.
218+
* When FT_SetUSBParameters is called, the change comes into effect immediately and any data that was
219+
* held in the driver at the time of the change is lost.
220+
* Note that, at present, only `in_transfer_size` is supported by the FTDI vendor driver.
221+
*
222+
* @param in_transfer_size Transfer size in bits for USB IN request
223+
* @param out_transfer_size Transfer size in bits for USB OUT request (unsupported yet)
224+
*/
225+
setUSBParameters(in_transfer_size: number, out_transfer_size: number): void;
212226
}
213227

214228
/** Get the list of FTDI devices connected to the system */

src/api/FTDI_Device.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ void device_initialize_class(napi_env env, napi_value* result) {
7070
{ "setDataCharacteristics", NULL, device_setDataCharacteristics, NULL, NULL, NULL, napi_enumerable, NULL },
7171
{ "setTimeouts", NULL, device_setTimeouts, NULL, NULL, NULL, napi_enumerable, NULL },
7272
{ "setFlowControl", NULL, device_setFlowControl, NULL, NULL, NULL, napi_enumerable, NULL },
73-
{ "setLatencyTimer", NULL, device_setLatencyTimer, NULL, NULL, NULL, napi_enumerable, NULL },
74-
{ "setBitMode", NULL, device_setBitMode, NULL, NULL, NULL, napi_enumerable, NULL },
7573
{ "setDtr", NULL, device_setDtr, NULL, NULL, NULL, napi_enumerable, NULL },
7674
{ "clrDtr", NULL, device_clrDtr, NULL, NULL, NULL, napi_enumerable, NULL },
7775
{ "setRts", NULL, device_setRts, NULL, NULL, NULL, napi_enumerable, NULL },
@@ -82,6 +80,9 @@ void device_initialize_class(napi_env env, napi_value* result) {
8280
{ "readEE", NULL, device_readEE, NULL, NULL, NULL, napi_enumerable, NULL },
8381
{ "writeEE", NULL, device_writeEE, NULL, NULL, NULL, napi_enumerable, NULL },
8482
{ "eraseEE", NULL, device_eraseEE, NULL, NULL, NULL, napi_enumerable, NULL },
83+
{ "setLatencyTimer", NULL, device_setLatencyTimer, NULL, NULL, NULL, napi_enumerable, NULL },
84+
{ "setBitMode", NULL, device_setBitMode, NULL, NULL, NULL, napi_enumerable, NULL },
85+
{ "setUSBParameters", NULL, device_setUSBParameters, NULL, NULL, NULL, napi_enumerable, NULL },
8586
};
8687
size_t nb_props = sizeof(props) / sizeof(napi_property_descriptor);
8788

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "api/FTDI_Device.h"
2+
#include "ftd2xx.h"
3+
#include "utils.h"
4+
5+
napi_value device_setUSBParameters(napi_env env, napi_callback_info info) {
6+
// Get JavaScript `this` corresponding to this instance of the class and `argc`/`argv` passed to the function
7+
#define NB_ARGS 2 // number of expected arguments
8+
size_t argc = NB_ARGS; // size of the argv buffer
9+
napi_value this_arg, argv[NB_ARGS];
10+
utils_check(napi_get_cb_info(env, info, &argc, argv, &this_arg, NULL));
11+
if(utils_check(argc < NB_ARGS, "Missing argument", "missarg")) return NULL;
12+
13+
// Get the class instance data containing FTDI device handle
14+
device_instance_data_t* instance_data;
15+
utils_check(napi_unwrap(env, this_arg, (void**)(&instance_data)));
16+
17+
// Check the device is open if its handle is still there
18+
if(utils_check(instance_data->ftHandle == NULL, "Dead device object", "deadobj")) return NULL;
19+
20+
// Check arguments, and convert JavaScript values to C values
21+
uint32_t in_transfer_size, out_transfer_size;
22+
if(utils_check(napi_get_value_uint32(env, argv[0], &in_transfer_size), "Transfer size for USB IN request must be a number", "wrongarg")) return NULL;
23+
if(utils_check(napi_get_value_uint32(env, argv[1], &out_transfer_size), "Transfer size for USB OUT request must be a number", "wrongarg")) return NULL;
24+
25+
// Update FTDI device
26+
utils_check(FT_SetUSBParameters(instance_data->ftHandle, (ULONG)in_transfer_size, (ULONG)out_transfer_size));
27+
28+
return NULL;
29+
}

0 commit comments

Comments
 (0)