libhackrf: gain control

This commit is contained in:
Hoernchen
2013-05-26 22:43:50 +02:00
parent 2200e4c109
commit d18159cf62
2 changed files with 92 additions and 1 deletions

View File

@ -48,7 +48,10 @@ typedef enum {
HACKRF_VENDOR_REQUEST_VERSION_STRING_READ = 15, HACKRF_VENDOR_REQUEST_VERSION_STRING_READ = 15,
HACKRF_VENDOR_REQUEST_SET_FREQ = 16, HACKRF_VENDOR_REQUEST_SET_FREQ = 16,
HACKRF_VENDOR_REQUEST_AMP_ENABLE = 17, HACKRF_VENDOR_REQUEST_AMP_ENABLE = 17,
HACKRF_VENDOR_REQUEST_BOARD_PARTID_SERIALNO_READ = 18 HACKRF_VENDOR_REQUEST_BOARD_PARTID_SERIALNO_READ = 18,
HACKRF_VENDOR_REQUEST_SET_LNA_GAIN = 19,
HACKRF_VENDOR_REQUEST_SET_VGA_GAIN = 20,
HACKRF_VENDOR_REQUEST_SET_TXVGA_GAIN = 21,
} hackrf_vendor_request; } hackrf_vendor_request;
typedef enum { typedef enum {
@ -789,6 +792,90 @@ int ADDCALL hackrf_board_partid_serialno_read(hackrf_device* device, read_partid
} }
} }
int ADDCALL hackrf_set_lna_gain(hackrf_device* device, uint32_t value)
{
int result;
if( value > 40 )
{
return HACKRF_ERROR_INVALID_PARAM;
}
result = libusb_control_transfer(
device->usb_device,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
HACKRF_VENDOR_REQUEST_SET_LNA_GAIN,
0,
value,
NULL,
0,
0
);
if( result != 0 )
{
return HACKRF_ERROR_INVALID_PARAM;
} else {
return HACKRF_SUCCESS;
}
}
int ADDCALL hackrf_set_vga_gain(hackrf_device* device, uint32_t value)
{
int result;
if( value > 62 )
{
return HACKRF_ERROR_INVALID_PARAM;
}
result = libusb_control_transfer(
device->usb_device,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
HACKRF_VENDOR_REQUEST_SET_VGA_GAIN,
0,
value,
NULL,
0,
0
);
if( result != 0 )
{
return HACKRF_ERROR_INVALID_PARAM;
} else {
return HACKRF_SUCCESS;
}
}
int ADDCALL hackrf_set_txvga_gain(hackrf_device* device, uint32_t value, uint32_t plus16db)
{
int result;
if( value > 47 )
{
return HACKRF_ERROR_INVALID_PARAM;
}
result = libusb_control_transfer(
device->usb_device,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
HACKRF_VENDOR_REQUEST_SET_TXVGA_GAIN,
plus16db,
value,
NULL,
0,
0
);
if( result != 0 )
{
return HACKRF_ERROR_INVALID_PARAM;
} else {
return HACKRF_SUCCESS;
}
}
static void* transfer_threadproc(void* arg) static void* transfer_threadproc(void* arg)
{ {
hackrf_device* device = (hackrf_device*)arg; hackrf_device* device = (hackrf_device*)arg;

View File

@ -134,6 +134,10 @@ extern ADDAPI int ADDCALL hackrf_set_amp_enable(hackrf_device* device, const uin
extern ADDAPI int ADDCALL hackrf_board_partid_serialno_read(hackrf_device* device, read_partid_serialno_t* read_partid_serialno); extern ADDAPI int ADDCALL hackrf_board_partid_serialno_read(hackrf_device* device, read_partid_serialno_t* read_partid_serialno);
extern ADDAPI int ADDCALL hackrf_set_lna_gain(hackrf_device* device, uint32_t value);
extern ADDAPI int ADDCALL hackrf_set_vga_gain(hackrf_device* device, uint32_t value);
extern ADDAPI int ADDCALL hackrf_set_txvga_gain(hackrf_device* device, uint32_t value, uint32_t plus16db);
extern ADDAPI const char* ADDCALL hackrf_error_name(enum hackrf_error errcode); extern ADDAPI const char* ADDCALL hackrf_error_name(enum hackrf_error errcode);
extern ADDAPI const char* ADDCALL hackrf_board_id_name(enum hackrf_board_id board_id); extern ADDAPI const char* ADDCALL hackrf_board_id_name(enum hackrf_board_id board_id);