2 * This file is part of the sigrok-firmware-fx2lafw project.
4 * Copyright (C) 2009 Ubixum, Inc.
5 * Copyright (C) 2015 Jochen Hoenicke
6 * Copyright (C) 2024 Steve Markgraf
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include <fx2macros.h>
24 #include <autovector.h>
28 #define SET_ANALOG_MODE()
30 #define SET_COUPLING(x) set_coupling_pso2020(x)
32 #define SET_CALIBRATION_PULSE(x)
34 #define TOGGLE_CALIBRATION_PIN()
36 #define LED_CLEAR() do { PA6 = 1; IOE |= (1 << 2); IOE &= ~(1 << 1); } while (0)
37 #define LED_GREEN() do { PA6 = 0; IOE |= (1 << 2); } while (0)
38 #define LED_RED() do { PA6 = 1; IOE &= ~(1 << 2); } while (0)
39 #define LED_WHITE() do { IOE |= (1 << 1); } while (0)
41 #define MUX_S0 (1 << 2)
42 #define MUX_S1 (1 << 1)
44 #define TIMER2_VAL 500
46 /* CTLx pin index (IFCLK, ADC clock input). */
49 #define OUT0 ((1 << CTL_BIT) << 4) /* OEx = 1, CTLx = 0 */
51 static const struct samplerate_info samplerates[] = {
52 { 48, 0x80, 0, 3, 0, 0x00, 0xea },
53 { 30, 0x80, 0, 3, 0, 0x00, 0xaa },
54 { 24, 1, 0, 2, 1, OUT0, 0xca },
55 { 16, 1, 1, 2, 0, OUT0, 0xca },
56 { 12, 2, 1, 2, 0, OUT0, 0xca },
57 { 8, 3, 2, 2, 0, OUT0, 0xca },
58 { 4, 6, 5, 2, 0, OUT0, 0xca },
59 { 2, 12, 11, 2, 0, OUT0, 0xca },
60 { 1, 24, 23, 2, 0, OUT0, 0xca },
61 { 50, 48, 47, 2, 0, OUT0, 0xca },
62 { 20, 120, 119, 2, 0, OUT0, 0xca },
63 { 10, 240, 239, 2, 0, OUT0, 0xca },
67 * Control analog mux and relays to switch voltage ranges
69 static BOOL set_voltage(BYTE channel, BYTE val)
72 BYTE mask = MUX_S0 | MUX_S1;
74 /* ADC channel B is only used for interleaved sampling
75 * to get 96 MHz sampling rate, so it shares the
76 * analog input circuitry with channel A
77 * Instead of returning an error, silently ignore it */
95 bits = MUX_S0 | MUX_S1;
109 /* 20 and 50mV in original software */
110 bits = MUX_S0 | MUX_S1;
116 /* Switch relay for high voltage range */
122 IOC = (IOC & ~mask) | (bits & mask);
128 * Switch between AC and DC coupling
130 static void set_coupling_pso2020(BYTE coupling_cfg)
132 if (coupling_cfg & 0x01)