]>
Commit | Line | Data |
---|---|---|
a7cf2e1b | 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 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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/>. | |
19 | */ | |
20 | ||
21 | #include <fx2macros.h> | |
22 | #include <fx2ints.h> | |
23 | #include <autovector.h> | |
24 | #include <delay.h> | |
25 | #include <setupdat.h> | |
26 | ||
27 | #define SET_ANALOG_MODE() do { PA7 = 1; } while (0) | |
28 | ||
29 | #define SET_COUPLING(x) set_coupling_isds205(x) | |
30 | ||
31 | #define SET_CALIBRATION_PULSE(x) | |
32 | ||
33 | #define TOGGLE_CALIBRATION_PIN() do { PA0 = !PA0; } while (0) | |
34 | ||
35 | #define LED_CLEAR() NOP | |
36 | #define LED_GREEN() | |
37 | #define LED_RED() | |
38 | ||
39 | #define TIMER2_VAL 500 | |
40 | ||
41 | /* CTLx pin index (IFCLK, ADC clock input). */ | |
42 | #define CTL_BIT 0 | |
43 | ||
44 | #define OUT0 ((1 << CTL_BIT) << 4) /* OEx = 1, CTLx = 0 */ | |
45 | ||
46 | #define SRCLK PA6 | |
47 | #define SRIN PA4 | |
48 | #define STOCLK PA5 | |
49 | ||
50 | volatile BYTE vol_state = 0 ; /* ISDS205C uses 74HC595 to expand ports, here we save his actual state. */ | |
51 | ||
52 | static void drive_74hc595(BYTE bits) | |
53 | { | |
54 | BYTE i; | |
55 | ||
56 | for(i = 0; i < 8; i++) | |
57 | { | |
58 | SRCLK = 0; | |
59 | SRIN = bits >> 7; | |
60 | SRCLK = 1; | |
61 | bits = bits << 1; | |
62 | } | |
63 | STOCLK = 1; | |
64 | STOCLK = 0; | |
65 | } | |
66 | ||
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 }, | |
80 | }; | |
81 | ||
82 | /* | |
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 | |
86 | * | |
87 | * We directly set the relevant bits for both channels and then | |
88 | * we mask them out to only affect the channel currently requested. | |
89 | */ | |
90 | static BOOL set_voltage(BYTE channel, BYTE val) | |
91 | { | |
92 | BYTE bits, mask; | |
93 | ||
94 | switch (val) { | |
95 | case 1: | |
96 | bits = 0b00001001; | |
97 | break; | |
98 | case 2: | |
99 | bits = 0b00000110; | |
100 | break; | |
101 | case 5: | |
102 | bits = 0b00000000; | |
103 | break; | |
104 | case 10: | |
105 | bits = 0b01010110; | |
106 | break; | |
107 | case 11: | |
108 | bits = 0b01010000; | |
109 | break; | |
110 | case 12: | |
111 | bits = 0b01011111; | |
112 | break; | |
113 | default: | |
114 | return FALSE; | |
115 | } | |
116 | ||
117 | mask = (channel) ? 0b00011100 : 0b01000011; | |
118 | vol_state = (vol_state & ~mask) | (bits & mask); | |
119 | ||
120 | drive_74hc595(vol_state); | |
121 | ||
122 | return TRUE; | |
123 | } | |
124 | ||
125 | /** | |
126 | * Bits 5 & 7 of the byte controls the coupling per channel. | |
127 | * | |
128 | * Setting bit 7 enables AC coupling relay on CH0. | |
129 | * Setting bit 5 enables AC coupling relay on CH1. | |
130 | */ | |
131 | static void set_coupling_isds205(BYTE coupling_cfg) | |
132 | { | |
133 | if (coupling_cfg & 0x01) | |
134 | vol_state &= ~0x80; | |
135 | else | |
136 | vol_state |= 0x80; | |
137 | ||
138 | if (coupling_cfg & 0x10) | |
139 | vol_state &= ~0x20; | |
140 | else | |
141 | vol_state |= 0x20; | |
142 | ||
143 | drive_74hc595(vol_state); | |
144 | } | |
145 | ||
146 | #include <scope.inc> |