From d534cb69ade872bdf6acd6a9447573807c568977 Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Sun, 19 Jan 2020 16:34:54 +0100 Subject: fix compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit warning: absolute value function ‘fabsf’ given an argument of type ‘double’ but has parameter of type ‘float’ which may cause truncation of value warning: ‘__builtin_strncpy’ specified bound 64 equals destination size --- src/libosmo-fl2k.c | 6 +++--- src/rds_mod.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libosmo-fl2k.c b/src/libosmo-fl2k.c index afc4d4f..7e1a008 100644 --- a/src/libosmo-fl2k.c +++ b/src/libosmo-fl2k.c @@ -250,9 +250,9 @@ int fl2k_set_sample_rate(fl2k_dev_t *dev, uint32_t target_freq) error = sample_clock - (double)target_freq; /* Keep closest match */ - if (fabsf(error) < last_error) { + if (fabs(error) < last_error) { result_reg = reg; - last_error = fabsf(error); + last_error = fabs(error); } } } @@ -262,7 +262,7 @@ int fl2k_set_sample_rate(fl2k_dev_t *dev, uint32_t target_freq) error = sample_clock - (double)target_freq; dev->rate = sample_clock; - if (fabsf(error) > 1) + if (fabs(error) > 1) fprintf(stderr, "Requested sample rate %d not possible, using" " %f, error is %f\n", target_freq, sample_clock, error); diff --git a/src/rds_mod.c b/src/rds_mod.c index 8e31b0d..687aa65 100644 --- a/src/rds_mod.c +++ b/src/rds_mod.c @@ -38,8 +38,8 @@ extern double waveform_biphase[576]; struct { uint16_t pi; int ta; - char ps[PS_LENGTH]; - char rt[RT_LENGTH]; + char ps[PS_LENGTH+1]; + char rt[RT_LENGTH+1]; } rds_params = { 0 }; /* The RDS error-detection code generator polynomial is -- cgit v1.2.3 From 4b72aab349ac55073208864036188ccc70e88b0a Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Sun, 19 Jan 2020 16:36:37 +0100 Subject: set CMake policy CMP0075 if it exists Otherwise newer versions of CMake are throwing a warning. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fb110f..84bc55d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,11 @@ project(libosmo-fl2k C) include(GNUInstallDirs) +# CMP0075 Include file check macros honor CMAKE_REQUIRED_LIBRARIES +if(POLICY CMP0075) + cmake_policy(SET CMP0075 NEW) +endif() + #select the release build type by default to get optimization flags if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") -- cgit v1.2.3 From a9f3771eb6ad4f9afb98d346dc6c54a1812d6e73 Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Sun, 19 Jan 2020 16:45:20 +0100 Subject: lib: use interface 0 altsetting 1 instead of interface 1 This makes osmo-fl2k work again with Linux 5.5.0-rc6 or later, as the FL2000 shares the endpoints for interface 0 and 1, which is forbidden by the USB spec and the Kernel will not ignore this anymore. See: https://marc.info/?l=linux-usb&m=157944230213296&w=2 --- src/libosmo-fl2k.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libosmo-fl2k.c b/src/libosmo-fl2k.c index 7e1a008..7478893 100644 --- a/src/libosmo-fl2k.c +++ b/src/libosmo-fl2k.c @@ -2,7 +2,7 @@ * osmo-fl2k, turns FL2000-based USB 3.0 to VGA adapters into * low cost DACs * - * Copyright (C) 2016-2018 by Steve Markgraf + * Copyright (C) 2016-2020 by Steve Markgraf * * SPDX-License-Identifier: GPL-2.0+ * @@ -444,10 +444,10 @@ int fl2k_open(fl2k_dev_t **out_dev, uint32_t index) fprintf(stderr, "usb_claim_interface 0 error %d\n", r); goto err; } - r = libusb_claim_interface(dev->devh, 1); + r = libusb_set_interface_alt_setting(dev->devh, 0, 1); if (r < 0) { - fprintf(stderr, "usb_claim_interface 1 error %d\n", r); + fprintf(stderr, "Error enabling IF 0 altsetting 1: %d\n", r); goto err; } -- cgit v1.2.3 From f05c961455f2c9aabce71ec3d9592199b07c47da Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Sun, 26 Jan 2020 20:52:24 +0100 Subject: lib: fall back to iface 1 in case iface 0 altsetting 1 fails Some people on the mailing list reported that with older kernels setting interface 0 altsetting 1 does not work, fall back to the old behavior in this case for now, while still investigating the root cause of this problem. --- src/libosmo-fl2k.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libosmo-fl2k.c b/src/libosmo-fl2k.c index 7478893..9ebe130 100644 --- a/src/libosmo-fl2k.c +++ b/src/libosmo-fl2k.c @@ -447,8 +447,13 @@ int fl2k_open(fl2k_dev_t **out_dev, uint32_t index) r = libusb_set_interface_alt_setting(dev->devh, 0, 1); if (r < 0) { - fprintf(stderr, "Error enabling IF 0 altsetting 1: %d\n", r); - goto err; + fprintf(stderr, "Failed to switch interface 0 to " + "altsetting 1, trying to use interface 1\n"); + + r = libusb_claim_interface(dev->devh, 1); + if (r < 0) { + fprintf(stderr, "Could not claim interface 1: %d\n", r); + } } r = fl2k_init_device(dev); -- cgit v1.2.3 From b82303f44fc8388817306235a673e0bfa671dd3f Mon Sep 17 00:00:00 2001 From: Sergey Alirzaev Date: Sat, 16 May 2020 03:28:28 +0300 Subject: lib: implement enabling RGB332 mode I've decided to provide a separate pointer for a raw buffer in case the library user comes up with a non-RGB332 use case that avoids byte rearrangement (and copying should be replaced with pulling from the user's pointer in this case) --- include/osmo-fl2k.h | 9 +++++++++ src/libosmo-fl2k.c | 26 +++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/osmo-fl2k.h b/include/osmo-fl2k.h index 02ad4ad..7aafc24 100644 --- a/include/osmo-fl2k.h +++ b/include/osmo-fl2k.h @@ -54,6 +54,7 @@ typedef struct fl2k_data_info { char *r_buf; /* pointer to red buffer */ char *g_buf; /* pointer to green buffer */ char *b_buf; /* pointer to blue buffer */ + char *raw_buf; /* pointer to pre-arranged buffer */ } fl2k_data_info_t; typedef struct fl2k_dev fl2k_dev_t; @@ -89,6 +90,14 @@ FL2K_API int fl2k_close(fl2k_dev_t *dev); */ FL2K_API int fl2k_set_sample_rate(fl2k_dev_t *dev, uint32_t target_freq); +/*! + * Set RGB332 sample format + * + * \param dev the device handle given by fl2k_open() + * \return 0 on success + */ +FL2K_API int fl2k_set_rgb332(fl2k_dev_t *dev); + /*! * Get actual sample rate the device is configured to. * diff --git a/src/libosmo-fl2k.c b/src/libosmo-fl2k.c index 9ebe130..2ac371e 100644 --- a/src/libosmo-fl2k.c +++ b/src/libosmo-fl2k.c @@ -204,6 +204,13 @@ int fl2k_deinit_device(fl2k_dev_t *dev) return r; } +int fl2k_set_rgb332(fl2k_dev_t *dev) +{ + uint32_t reg; + fl2k_read_reg(dev, 0x8004, ®); + return fl2k_write_reg(dev, 0x8004, reg | (1 << 25)); +} + static double fl2k_reg_to_freq(uint32_t reg) { double sample_clock, offset, offs_div; @@ -910,15 +917,20 @@ static void *fl2k_sample_worker(void *arg) xfer_info = (fl2k_xfer_info_t *)xfer->user_data; out_buf = (char *)xfer->buffer; - /* Re-arrange and copy bytes in buffer for DACs */ - fl2k_convert_r(out_buf, data_info.r_buf, dev->xfer_buf_len, - data_info.sampletype_signed ? 128 : 0); + if (data_info.raw_buf) { + /* Shove a pre-arranged buffer into the DACs */ + memcpy(out_buf, data_info.raw_buf, dev->xfer_buf_len); + } else { + /* Re-arrange and copy bytes in buffer for DACs */ + fl2k_convert_r(out_buf, data_info.r_buf, dev->xfer_buf_len, + data_info.sampletype_signed ? 128 : 0); - fl2k_convert_g(out_buf, data_info.g_buf, dev->xfer_buf_len, - data_info.sampletype_signed ? 128 : 0); + fl2k_convert_g(out_buf, data_info.g_buf, dev->xfer_buf_len, + data_info.sampletype_signed ? 128 : 0); - fl2k_convert_b(out_buf, data_info.b_buf, dev->xfer_buf_len, - data_info.sampletype_signed ? 128 : 0); + fl2k_convert_b(out_buf, data_info.b_buf, dev->xfer_buf_len, + data_info.sampletype_signed ? 128 : 0); + } xfer_info->seq = buf_cnt++; xfer_info->state = BUF_FILLED; -- cgit v1.2.3 From 3f44f8fc224c6b0b45a824109619f993e0b87552 Mon Sep 17 00:00:00 2001 From: Sergey Alirzaev Date: Sat, 16 May 2020 03:28:29 +0300 Subject: lib: added utility macros for rgb332 mode --- include/osmo-fl2k.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/osmo-fl2k.h b/include/osmo-fl2k.h index 7aafc24..f88ecdf 100644 --- a/include/osmo-fl2k.h +++ b/include/osmo-fl2k.h @@ -70,6 +70,13 @@ typedef struct fl2k_dev fl2k_dev_t; #define FL2K_BUF_LEN (1280 * 1024) #define FL2K_XFER_LEN (FL2K_BUF_LEN * 3) +/** Utility macros for 8 bit per sample mode */ +#define RGB332_TO_R(x) (((x) & 3) << 6) +#define RGB332_TO_G(x) (((x) & 7) << 3) +#define RGB332_TO_B(x) (((x) & 7) << 0) +#define RGB332_TO_RGB(r, g, b) (TO_R(r) | TO_G(g) | TO_B(b)) + + FL2K_API uint32_t fl2k_get_device_count(void); FL2K_API const char* fl2k_get_device_name(uint32_t index); -- cgit v1.2.3 From 58de0a5bccb6648ee3372643517ea51b3ab5b523 Mon Sep 17 00:00:00 2001 From: Sergey Alirzaev Date: Fri, 22 May 2020 20:02:07 +0300 Subject: lib: fixed rgb332 macros --- include/osmo-fl2k.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/osmo-fl2k.h b/include/osmo-fl2k.h index f88ecdf..17c7e1f 100644 --- a/include/osmo-fl2k.h +++ b/include/osmo-fl2k.h @@ -74,7 +74,7 @@ typedef struct fl2k_dev fl2k_dev_t; #define RGB332_TO_R(x) (((x) & 3) << 6) #define RGB332_TO_G(x) (((x) & 7) << 3) #define RGB332_TO_B(x) (((x) & 7) << 0) -#define RGB332_TO_RGB(r, g, b) (TO_R(r) | TO_G(g) | TO_B(b)) +#define RGB332_TO_RGB(r, g, b) (RGB332_TO_R(r) | RGB332_TO_G(g) | RGB332_TO_B(b)) FL2K_API uint32_t fl2k_get_device_count(void); -- cgit v1.2.3 From 44b6e3b9290991a27337b48106a5fe09c9d2df4e Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Tue, 26 May 2020 22:02:09 +0200 Subject: lib: reuse hint message when zero-copy buffer alloc fails --- src/libosmo-fl2k.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libosmo-fl2k.c b/src/libosmo-fl2k.c index 2ac371e..8d15581 100644 --- a/src/libosmo-fl2k.c +++ b/src/libosmo-fl2k.c @@ -585,6 +585,10 @@ static int fl2k_alloc_submit_transfers(fl2k_dev_t *dev) { unsigned int i; int r = 0; + const char *incr_usbfs = "Please increase your allowed usbfs buffer" + " size with the following command:\n" + "echo 0 > /sys/module/usbcore/parameters/" + "usbfs_memory_mb\n"; if (!dev) return FL2K_ERROR_INVALID_PARAM; @@ -625,8 +629,9 @@ static int fl2k_alloc_submit_transfers(fl2k_dev_t *dev) } } else { fprintf(stderr, "Failed to allocate zero-copy " - "buffer for transfer %d\nFalling " - "back to buffers in userspace\n", i); + "buffer for transfer %d\n%sFalling " + "back to buffers in userspace\n", + i, incr_usbfs); dev->use_zerocopy = 0; break; } @@ -680,12 +685,8 @@ static int fl2k_alloc_submit_transfers(fl2k_dev_t *dev) dev->xfer_info[i].state = BUF_SUBMITTED; if (r < 0) { - fprintf(stderr, "Failed to submit transfer %i\n" - "Please increase your allowed " - "usbfs buffer size with the " - "following command:\n" - "echo 0 > /sys/module/usbcore" - "/parameters/usbfs_memory_mb\n", i); + fprintf(stderr, "Failed to submit transfer %i\n%s", + i, incr_usbfs); break; } } -- cgit v1.2.3 From b11fc430f3d033f345f22340e62857cb544e1a2a Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Tue, 26 May 2020 23:10:37 +0200 Subject: lib: fix hang on exit As the sample worker thread might still be waiting for a buffer, we need to wake it up first before trying to join. --- src/libosmo-fl2k.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libosmo-fl2k.c b/src/libosmo-fl2k.c index 8d15581..9b42bcd 100644 --- a/src/libosmo-fl2k.c +++ b/src/libosmo-fl2k.c @@ -794,6 +794,9 @@ static void *fl2k_usb_worker(void *arg) } } + /* wake up sample worker */ + pthread_cond_signal(&dev->buf_cond); + /* wait for sample worker thread to finish before freeing buffers */ pthread_join(dev->sample_worker_thread, NULL); _fl2k_free_async_buffers(dev); -- cgit v1.2.3 From 197f421c98f929d4266a09bc9d667b7869e09c27 Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Tue, 2 Jun 2020 00:50:53 +0200 Subject: lib: revert implementing RGB233 mode We will soon have support for a palette mode, which can replicate the RGB233 mode if required, or any custom arrangement of bits per color. Furthermore, the RGB233 mode did not work correctly in this state, as we did not implement swapping of the 32 bit words. This reverts the following commits: 58de0a5bccb6648ee3372643517ea51b3ab5b523 3f44f8fc224c6b0b45a824109619f993e0b87552 b82303f44fc8388817306235a673e0bfa671dd3f --- include/osmo-fl2k.h | 16 ---------------- src/libosmo-fl2k.c | 26 +++++++------------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/include/osmo-fl2k.h b/include/osmo-fl2k.h index 17c7e1f..02ad4ad 100644 --- a/include/osmo-fl2k.h +++ b/include/osmo-fl2k.h @@ -54,7 +54,6 @@ typedef struct fl2k_data_info { char *r_buf; /* pointer to red buffer */ char *g_buf; /* pointer to green buffer */ char *b_buf; /* pointer to blue buffer */ - char *raw_buf; /* pointer to pre-arranged buffer */ } fl2k_data_info_t; typedef struct fl2k_dev fl2k_dev_t; @@ -70,13 +69,6 @@ typedef struct fl2k_dev fl2k_dev_t; #define FL2K_BUF_LEN (1280 * 1024) #define FL2K_XFER_LEN (FL2K_BUF_LEN * 3) -/** Utility macros for 8 bit per sample mode */ -#define RGB332_TO_R(x) (((x) & 3) << 6) -#define RGB332_TO_G(x) (((x) & 7) << 3) -#define RGB332_TO_B(x) (((x) & 7) << 0) -#define RGB332_TO_RGB(r, g, b) (RGB332_TO_R(r) | RGB332_TO_G(g) | RGB332_TO_B(b)) - - FL2K_API uint32_t fl2k_get_device_count(void); FL2K_API const char* fl2k_get_device_name(uint32_t index); @@ -97,14 +89,6 @@ FL2K_API int fl2k_close(fl2k_dev_t *dev); */ FL2K_API int fl2k_set_sample_rate(fl2k_dev_t *dev, uint32_t target_freq); -/*! - * Set RGB332 sample format - * - * \param dev the device handle given by fl2k_open() - * \return 0 on success - */ -FL2K_API int fl2k_set_rgb332(fl2k_dev_t *dev); - /*! * Get actual sample rate the device is configured to. * diff --git a/src/libosmo-fl2k.c b/src/libosmo-fl2k.c index 9b42bcd..99dcd33 100644 --- a/src/libosmo-fl2k.c +++ b/src/libosmo-fl2k.c @@ -204,13 +204,6 @@ int fl2k_deinit_device(fl2k_dev_t *dev) return r; } -int fl2k_set_rgb332(fl2k_dev_t *dev) -{ - uint32_t reg; - fl2k_read_reg(dev, 0x8004, ®); - return fl2k_write_reg(dev, 0x8004, reg | (1 << 25)); -} - static double fl2k_reg_to_freq(uint32_t reg) { double sample_clock, offset, offs_div; @@ -921,20 +914,15 @@ static void *fl2k_sample_worker(void *arg) xfer_info = (fl2k_xfer_info_t *)xfer->user_data; out_buf = (char *)xfer->buffer; - if (data_info.raw_buf) { - /* Shove a pre-arranged buffer into the DACs */ - memcpy(out_buf, data_info.raw_buf, dev->xfer_buf_len); - } else { - /* Re-arrange and copy bytes in buffer for DACs */ - fl2k_convert_r(out_buf, data_info.r_buf, dev->xfer_buf_len, - data_info.sampletype_signed ? 128 : 0); + /* Re-arrange and copy bytes in buffer for DACs */ + fl2k_convert_r(out_buf, data_info.r_buf, dev->xfer_buf_len, + data_info.sampletype_signed ? 128 : 0); - fl2k_convert_g(out_buf, data_info.g_buf, dev->xfer_buf_len, - data_info.sampletype_signed ? 128 : 0); + fl2k_convert_g(out_buf, data_info.g_buf, dev->xfer_buf_len, + data_info.sampletype_signed ? 128 : 0); - fl2k_convert_b(out_buf, data_info.b_buf, dev->xfer_buf_len, - data_info.sampletype_signed ? 128 : 0); - } + fl2k_convert_b(out_buf, data_info.b_buf, dev->xfer_buf_len, + data_info.sampletype_signed ? 128 : 0); xfer_info->seq = buf_cnt++; xfer_info->state = BUF_FILLED; -- cgit v1.2.3