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() do { PA7 = 1; } while (0)
29 #define SET_COUPLING(x) set_coupling_isds205(x)
31 #define SET_CALIBRATION_PULSE(x)
33 #define TOGGLE_CALIBRATION_PIN() do { PA0 = !PA0; } while (0)
35 #define LED_CLEAR() NOP
39 #define TIMER2_VAL 500
41 /* CTLx pin index (IFCLK, ADC clock input). */
44 #define OUT0 ((1 << CTL_BIT) << 4) /* OEx = 1, CTLx = 0 */
50 volatile BYTE vol_state = 0 ; /* ISDS205C uses 74HC595 to expand ports, here we save his actual state. */
52 static void drive_74hc595(BYTE bits)
56 for(i = 0; i < 8; i++)
67 static const struct samplerate_info samplerates[] = {
68 { 48, 0x80, 0, 3, 0, 0x00, 0xea },
69 { 30, 0x80, 0, 3, 0, 0x00, 0xaa },
70 { 24, 1, 0, 2, 1, OUT0, 0xca },
71 { 16, 1, 1, 2, 0, OUT0, 0xca },
72 { 12, 2, 1, 2, 0, OUT0, 0xca },
73 { 8, 3, 2, 2, 0, OUT0, 0xca },
74 { 4, 6, 5, 2, 0, OUT0, 0xca },
75 { 2, 12, 11, 2, 0, OUT0, 0xca },
76 { 1, 24, 23, 2, 0, OUT0, 0xca },
77 { 50, 48, 47, 2, 0, OUT0, 0xca },
78 { 20, 120, 119, 2, 0, OUT0, 0xca },
79 { 10, 240, 239, 2, 0, OUT0, 0xca },
83 * This sets three bits for each channel, one channel at a time.
84 * For channel 0 we want to set bits 0, 1 & 6
85 * For channel 1 we want to set bits 2, 3 & 4
87 * We directly set the relevant bits for both channels and then
88 * we mask them out to only affect the channel currently requested.
90 static BOOL set_voltage(BYTE channel, BYTE val)
117 mask = (channel) ? 0b00011100 : 0b01000011;
118 vol_state = (vol_state & ~mask) | (bits & mask);
120 drive_74hc595(vol_state);
126 * Bits 5 & 7 of the byte controls the coupling per channel.
128 * Setting bit 7 enables AC coupling relay on CH0.
129 * Setting bit 5 enables AC coupling relay on CH1.
131 static void set_coupling_isds205(BYTE coupling_cfg)
133 if (coupling_cfg & 0x01)
138 if (coupling_cfg & 0x10)
143 drive_74hc595(vol_state);