|
44 | 44 | (2.695e9, 3.24e9, 0x34), |
45 | 45 | (3.24e9, 3.72e9, 0x3c)] |
46 | 46 |
|
| 47 | +# LPF code to bandwidth in MHz |
| 48 | +LPF_CODE_TO_BW = { |
| 49 | +0x0 : 14, |
| 50 | +0x1 : 10, |
| 51 | +0x2 : 7, |
| 52 | +0x3 : 6, |
| 53 | +0x4 : 5, |
| 54 | +0x5 : 4.375, |
| 55 | +0x6 : 3.5, |
| 56 | +0x7 : 3, |
| 57 | +0x8 : 2.75, |
| 58 | +0x9 : 2.5, |
| 59 | +0xa : 1.92, |
| 60 | +0xb : 1.5, |
| 61 | +0xc : 1.375, |
| 62 | +0xd : 1.25, |
| 63 | +0xe : 0.875, |
| 64 | +0xf : 0.75, |
| 65 | +} |
| 66 | + |
| 67 | +# LPF bandwidth in MHz to LPF code |
| 68 | +# Just reverse LPF_CODE_TO_BW for simplicity |
| 69 | +LPF_BW_TO_CODE = {v:k for k, v in LPF_CODE_TO_BW.iteritems()} |
| 70 | + |
| 71 | + |
47 | 72 | # A list of reserved registers which read as junk |
48 | 73 | RESV_REGS = (0x0C, 0x0D, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x69, 0x6A, 0x6B, 0x6C, 0x6D) |
49 | 74 |
|
@@ -283,6 +308,60 @@ def lms_get_rx_vga2gain(lms_dev): |
283 | 308 | gain = gain if gain <= 20 else 20 |
284 | 309 | return gain * 3 |
285 | 310 |
|
| 311 | +def lms_set_tx_lpf_raw(lms_dev, val): |
| 312 | + """ Set Tx LPF bandwidth raw value. |
| 313 | + val is in [0 .. 15] range |
| 314 | + Returns the old gain value on success, None on error""" |
| 315 | + if not (0 <= val <= 15): return None |
| 316 | + old_bits = lms_dev.reg_write_bits(0x34, (0x0f << 2), (int(val) << 2)) |
| 317 | + return (old_bits >> 2) & 0x0f |
| 318 | + |
| 319 | +def lms_set_tx_lpf(lms_dev, val): |
| 320 | + """ Set Tx LPF bandwidth in MHz. |
| 321 | + val is in [0 .. 14] MHz range |
| 322 | + Returns the old gain value on success, None on error""" |
| 323 | + return lms_set_rx_lpf_raw(lms_dev, LPF_BW_TO_CODE[val]) |
| 324 | + |
| 325 | +def lms_get_tx_lpf_raw(lms_dev): |
| 326 | + """ Get Tx LPF bandwidth raw value. |
| 327 | + return value is in [0 .. 15] range |
| 328 | + Returns the gain value on success, None on error""" |
| 329 | + value = lms_dev.reg_get_bits(0x34, (0x0f << 2), 2) |
| 330 | + return value |
| 331 | + |
| 332 | +def lms_get_tx_lpf(lms_dev): |
| 333 | + """ Get Tx LPF bandwidth in MHz. |
| 334 | + return value is in [0.75 .. 14] MHz range |
| 335 | + Returns the gain value on success, None on error""" |
| 336 | + return LPF_CODE_TO_BW[lms_get_rx_lpf_raw(lms_dev)] |
| 337 | + |
| 338 | +def lms_set_rx_lpf_raw(lms_dev, val): |
| 339 | + """ Set Rx LPF bandwidth raw value. |
| 340 | + val is in [0 .. 15] range |
| 341 | + Returns the old gain value on success, None on error""" |
| 342 | + if not (0 <= val <= 15): return None |
| 343 | + old_bits = lms_dev.reg_write_bits(0x54, (0x0f << 2), (int(val) << 2)) |
| 344 | + return (old_bits >> 2) & 0x0f |
| 345 | + |
| 346 | +def lms_set_rx_lpf(lms_dev, val): |
| 347 | + """ Set Rx LPF bandwidth in MHz. |
| 348 | + val is in [0 .. 14] MHz range |
| 349 | + Returns the old gain value on success, None on error""" |
| 350 | + return lms_set_rx_lpf_raw(lms_dev, LPF_BW_TO_CODE[val]) |
| 351 | + |
| 352 | +def lms_get_rx_lpf_raw(lms_dev): |
| 353 | + """ Get Rx Rx LPF bandwidth raw value. |
| 354 | + return value is in [0 .. 15] range |
| 355 | + Returns the gain value on success, None on error""" |
| 356 | + value = lms_dev.reg_get_bits(0x54, (0x0f << 2), 2) |
| 357 | + return value |
| 358 | + |
| 359 | +def lms_get_rx_lpf(lms_dev): |
| 360 | + """ Get Rx Rx LPF bandwidth in MHz. |
| 361 | + return value is in [0.75 .. 14] MHz range |
| 362 | + Returns the gain value on success, None on error""" |
| 363 | + return LPF_CODE_TO_BW[lms_get_rx_lpf_raw(lms_dev)] |
| 364 | + |
286 | 365 | def lms_set_vga1dc_i_int(lms_dev, dc_shift_int): |
287 | 366 | """ Set VGA1 DC offset, I channel |
288 | 367 | dc_shift_int is an integer representation of the DC shift [0 .. 255] |
|
0 commit comments