2 * This file is part of the sigrok-firmware-fx2lafw project.
4 * Copyright (C) 2009 Ubixum, Inc.
5 * Copyright (C) 2015 Jochen Hoenicke
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include <fx2macros.h>
23 #include <autovector.h>
27 #define SET_ANALOG_MODE()
29 #define SET_COUPLING(x)
31 #define SET_CALIBRATION_PULSE(x)
33 /* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */
34 #define TOGGLE_CALIBRATION_PIN() PA7 = !PA7
36 #define LED_CLEAR() PC0 = 1; PC1 = 1;
37 #define LED_GREEN() PC0 = 1; PC1 = 0;
38 #define LED_RED() PC0 = 0; PC1 = 1;
40 #define TIMER2_VAL 500
42 /* CTLx pin index (IFCLK, ADC clock input). */
45 #define OUT0 ((1 << CTL_BIT) << 4) /* OEx = 1, CTLx = 0 */
47 static const struct samplerate_info samplerates[] = {
48 { 48, 0x80, 0, 3, 0, 0x00, 0xea },
49 { 30, 0x80, 0, 3, 0, 0x00, 0xaa },
50 { 24, 1, 0, 2, 1, OUT0, 0xca },
51 { 16, 1, 1, 2, 0, OUT0, 0xca },
52 { 12, 2, 1, 2, 0, OUT0, 0xca },
53 { 8, 3, 2, 2, 0, OUT0, 0xca },
54 { 4, 6, 5, 2, 0, OUT0, 0xca },
55 { 2, 12, 11, 2, 0, OUT0, 0xca },
56 { 1, 24, 23, 2, 0, OUT0, 0xca },
57 { 50, 48, 47, 2, 0, OUT0, 0xca },
58 { 20, 120, 119, 2, 0, OUT0, 0xca },
59 { 10, 240, 239, 2, 0, OUT0, 0xca },
63 * This sets three bits for each channel, one channel at a time.
64 * For channel 0 we want to set bits 5, 6 & 7
65 * For channel 1 we want to set bits 2, 3 & 4
67 * We convert the input values that are strange due to original
68 * firmware code into the value of the three bits as follows:
76 * The third bit is always zero since there are only four outputs connected
77 * in the serial selector chip.
79 * The multiplication of the converted value by 0x24 sets the relevant bits in
80 * both channels and then we mask it out to only affect the channel currently
83 static BOOL set_voltage(BYTE channel, BYTE val)
104 mask = (channel) ? 0xe0 : 0x1c;
105 IOC = (IOC & ~mask) | (bits & mask);