summaryrefslogtreecommitdiffstats
path: root/core/serial_ftdi.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2017-06-27 11:59:11 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2017-06-27 13:58:15 -0700
commitd01b7bf89167ff8ab40c4b663398816da678084a (patch)
tree33b5b554b6ec8ed42febc46ba4a560b06ba52107 /core/serial_ftdi.c
parente79bede0aa5b3bd169a29dbb907002d6ac717c6e (diff)
downloadsubsurface-d01b7bf89167ff8ab40c4b663398816da678084a.tar.gz
Switch over to SSRF_CUSTOM_IO v2
I hate changing the IO interfaces this often, but when I converted the custom serial interface to the more generic custom IO interface, I intentionally left the legacy serial operations alone, because I didn't want to change something I didn't care about. But it turns out that leaving them with the old calling convention caused extra problems when converting the bluetooth serial code to have the BLE GATT packet fall-back, which requires mixing two kinds of operations. Also, the packet_open() routine was passed a copy of the 'dc_context_t', which makes it possible to update the 'dc_custom_io_t' field on the fly at open time. That makes a lot of chaining operations much simpler, since now you can chain the 'custom_io_t' at open time and then libdivecomputer will automatically call the new routines instead of the old ones. That dc_context_t availability gets rid of all the if (device && device->ops) return device->ops->serial_xyz(..); hackery inside the rfcomm routines - now we can just at open time do a simple dc_context_set_custom_io(context, &ble_serial_ops); to switch things over to the BLE version of the serial code instead. Finally, SSRF_CUSTOM_IO v2 added an opaque "dc_user_device_t" pointer argument to the custom_io descriptor, which gets filled in as the custom_io is registered with the download context. Note that unlike most opaque pointers, this one is opaque to *libdivecomputer*, and the type is supposed to be supplied by the user. We define the "dc_user_device_t" as our old "struct device_data_t", making it "struct user_device_t" instead. That means that the IO routines now get passed the device info showing what device they are supposed to download for. That, in turn, means that now our BLE GATT open code can take the device type it opens for into account if it wants to. And it will want to, since the rules for Shearwater are different from the rules for Suunto, for example. NOTE! Because of the interface change with libdivecomputer, this will need a flag-day again where libdivecomputer and subsurface are updated together. It may not be the last time, either. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'core/serial_ftdi.c')
-rw-r--r--core/serial_ftdi.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/core/serial_ftdi.c b/core/serial_ftdi.c
index 0c9e6c428..ade104a1c 100644
--- a/core/serial_ftdi.c
+++ b/core/serial_ftdi.c
@@ -71,9 +71,9 @@ typedef struct ftdi_serial_t {
unsigned int nbits;
} ftdi_serial_t;
-static dc_status_t serial_ftdi_get_received (void **userdata, size_t *value)
+static dc_status_t serial_ftdi_get_received (dc_custom_io_t *io, size_t *value)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;
@@ -145,7 +145,7 @@ static int serial_ftdi_open_device (struct ftdi_context *ftdi_ctx)
//
// Open the serial port.
// Initialise ftdi_context and use it to open the device
-static dc_status_t serial_ftdi_open (void **userdata, const char* name)
+static dc_status_t serial_ftdi_open (dc_custom_io_t *io, dc_context_t *context, const char* name)
{
INFO(0, "serial_ftdi_open called");
// Allocate memory.
@@ -203,7 +203,7 @@ static dc_status_t serial_ftdi_open (void **userdata, const char* name)
device->ftdi_ctx = ftdi_ctx;
- *userdata = device;
+ io->userdata = device;
return DC_STATUS_SUCCESS;
}
@@ -211,9 +211,9 @@ static dc_status_t serial_ftdi_open (void **userdata, const char* name)
//
// Close the serial port.
//
-static dc_status_t serial_ftdi_close (void **userdata)
+static dc_status_t serial_ftdi_close (dc_custom_io_t *io)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_SUCCESS;
@@ -233,7 +233,7 @@ static dc_status_t serial_ftdi_close (void **userdata)
// Free memory.
free (device);
- *userdata = NULL;
+ io->userdata = NULL;
return DC_STATUS_SUCCESS;
}
@@ -241,9 +241,9 @@ static dc_status_t serial_ftdi_close (void **userdata)
//
// Configure the serial port (baudrate, databits, parity, stopbits and flowcontrol).
//
-static dc_status_t serial_ftdi_configure (void **userdata, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol)
+static dc_status_t serial_ftdi_configure (dc_custom_io_t *io, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;
@@ -341,9 +341,9 @@ static dc_status_t serial_ftdi_configure (void **userdata, unsigned int baudrate
//
// Configure the serial port (timeouts).
//
-static dc_status_t serial_ftdi_set_timeout (void **userdata, long timeout)
+static dc_status_t serial_ftdi_set_timeout (dc_custom_io_t *io, long timeout)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;
@@ -355,9 +355,9 @@ static dc_status_t serial_ftdi_set_timeout (void **userdata, long timeout)
return DC_STATUS_SUCCESS;
}
-static dc_status_t serial_ftdi_set_halfduplex (void **userdata, unsigned int value)
+static dc_status_t serial_ftdi_set_halfduplex (dc_custom_io_t *io, unsigned int value)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;
@@ -370,9 +370,9 @@ static dc_status_t serial_ftdi_set_halfduplex (void **userdata, unsigned int val
return DC_STATUS_SUCCESS;
}
-static dc_status_t serial_ftdi_read (void **userdata, void *data, size_t size, size_t *actual)
+static dc_status_t serial_ftdi_read (dc_custom_io_t *io, void *data, size_t size, size_t *actual)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;
@@ -421,9 +421,9 @@ static dc_status_t serial_ftdi_read (void **userdata, void *data, size_t size, s
return DC_STATUS_SUCCESS;
}
-static dc_status_t serial_ftdi_write (void **userdata, const void *data, size_t size, size_t *actual)
+static dc_status_t serial_ftdi_write (dc_custom_io_t *io, const void *data, size_t size, size_t *actual)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;
@@ -488,9 +488,9 @@ static dc_status_t serial_ftdi_write (void **userdata, const void *data, size_t
return DC_STATUS_SUCCESS;
}
-static dc_status_t serial_ftdi_flush (void **userdata, dc_direction_t queue)
+static dc_status_t serial_ftdi_flush (dc_custom_io_t *io, dc_direction_t queue)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;
@@ -525,9 +525,9 @@ static dc_status_t serial_ftdi_flush (void **userdata, dc_direction_t queue)
return DC_STATUS_SUCCESS;
}
-static dc_status_t serial_ftdi_send_break (void **userdata)
+static dc_status_t serial_ftdi_send_break (dc_custom_io_t *io)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;
@@ -542,9 +542,9 @@ static dc_status_t serial_ftdi_send_break (void **userdata)
return DC_STATUS_UNSUPPORTED;
}
-static dc_status_t serial_ftdi_set_break (void **userdata, int level)
+static dc_status_t serial_ftdi_set_break (dc_custom_io_t *io, int level)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;
@@ -556,9 +556,9 @@ static dc_status_t serial_ftdi_set_break (void **userdata, int level)
return DC_STATUS_UNSUPPORTED;
}
-static dc_status_t serial_ftdi_set_dtr (void **userdata, int level)
+static dc_status_t serial_ftdi_set_dtr (dc_custom_io_t *io, int level)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;
@@ -573,9 +573,9 @@ static dc_status_t serial_ftdi_set_dtr (void **userdata, int level)
return DC_STATUS_SUCCESS;
}
-static dc_status_t serial_ftdi_set_rts (void **userdata, int level)
+static dc_status_t serial_ftdi_set_rts (dc_custom_io_t *io, int level)
{
- ftdi_serial_t *device = (ftdi_serial_t*) *userdata;
+ ftdi_serial_t *device = (ftdi_serial_t*) io->userdata;
if (device == NULL)
return DC_STATUS_INVALIDARGS;