]>
Commit | Line | Data |
---|---|---|
0f2d3242 SM |
1 | /* |
2 | * This file is part of the sigrok-firmware-fx2lafw project. | |
3 | * | |
4 | * Copyright (C) 2009 Ubixum, Inc. | |
5 | * Copyright (C) 2015 Jochen Hoenicke | |
6 | * Copyright (C) 2024 Steve Markgraf | |
7 | * | |
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. | |
12 | * | |
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. | |
17 | * | |
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/>. | |
20 | */ | |
21 | ||
22 | #include <fx2macros.h> | |
23 | #include <fx2ints.h> | |
24 | #include <autovector.h> | |
25 | #include <delay.h> | |
26 | #include <setupdat.h> | |
27 | ||
28 | #define SET_ANALOG_MODE() | |
29 | ||
30 | #define SET_COUPLING(x) set_coupling_pso2020(x) | |
31 | ||
32 | #define SET_CALIBRATION_PULSE(x) | |
33 | ||
34 | #define TOGGLE_CALIBRATION_PIN() | |
35 | ||
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) | |
40 | ||
41 | #define MUX_S0 (1 << 2) | |
42 | #define MUX_S1 (1 << 1) | |
43 | ||
44 | #define TIMER2_VAL 500 | |
45 | ||
46 | /* CTLx pin index (IFCLK, ADC clock input). */ | |
47 | #define CTL_BIT 0 | |
48 | ||
49 | #define OUT0 ((1 << CTL_BIT) << 4) /* OEx = 1, CTLx = 0 */ | |
50 | ||
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 }, | |
64 | }; | |
65 | ||
66 | /** | |
67 | * Control analog mux and relays to switch voltage ranges | |
68 | */ | |
69 | static BOOL set_voltage(BYTE channel, BYTE val) | |
70 | { | |
71 | BYTE bits = 0; | |
72 | BYTE mask = MUX_S0 | MUX_S1; | |
73 | ||
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 */ | |
78 | if (channel > 0) | |
79 | return TRUE; | |
80 | ||
81 | switch (val) { | |
82 | case 1: | |
83 | /* 10 and 20V */ | |
84 | bits = MUX_S1; | |
85 | break; | |
86 | case 2: | |
87 | /* 5V */ | |
88 | bits = MUX_S0; | |
89 | break; | |
90 | case 5: | |
91 | /* 2V */ | |
92 | break; | |
93 | case 10: | |
94 | /* 1V */ | |
95 | bits = MUX_S0 | MUX_S1; | |
96 | break; | |
97 | case 11: | |
98 | /* 500 mV */ | |
99 | bits = MUX_S1; | |
100 | break; | |
101 | case 12: | |
102 | /* 200mV */ | |
103 | bits = MUX_S0; | |
104 | break; | |
105 | case 13: | |
106 | /* 100mV */ | |
107 | break; | |
108 | case 14: | |
109 | /* 20 and 50mV in original software */ | |
110 | bits = MUX_S0 | MUX_S1; | |
111 | break; | |
112 | default: | |
113 | return FALSE; | |
114 | } | |
115 | ||
116 | /* Switch relay for high voltage range */ | |
117 | if (val <= 10) | |
118 | PA7 = 1; | |
119 | else | |
120 | PA7 = 0; | |
121 | ||
122 | IOC = (IOC & ~mask) | (bits & mask); | |
123 | ||
124 | return TRUE; | |
125 | } | |
126 | ||
127 | /** | |
128 | * Switch between AC and DC coupling | |
129 | */ | |
130 | static void set_coupling_pso2020(BYTE coupling_cfg) | |
131 | { | |
132 | if (coupling_cfg & 0x01) | |
133 | PC4 = 0; | |
134 | else | |
135 | PC4 = 1; | |
136 | } | |
137 | ||
138 | #include <scope.inc> |