Check-in [0e5172d98f]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: user: pine tags: trunk ADDED soft/JK20/build.xml ADDED soft/JK20/src/Config.java ADDED soft/JK20/src/DPrint.java ADDED soft/JK20/src/JK20.java EDITED soft/firmware/src/u2s.c
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0e5172d98f354f5911297bec644a0f608b5fcb80
User & Date: pine 2016-05-10 12:28:16
Context
2016-05-14
00:59
user: pine tags: trunk EDITED .fossil-settings/binary-glob EDITED .fossil-settings/ignore-glob EDITED soft/JK20/build.xml ADDED soft/JK20/jni/Makefile ADDED soft/JK20/jni/foreach.sh ADDED soft/JK20/jni/rda/Makefile ADDED soft/JK20/jni/rda/RDA.c ADDED soft/JK20/jni/rda/RDA.java EDITED soft/JK20/src/Config.java ADDED soft/JK20/src/ConfigSaver.java ADDED soft/JK20/src/ControlMessage.java EDITED soft/JK20/src/JK20.java ADDED soft/JK20/src/Version.java ADDED soft/JK20/src/res/img/gbulboff.png ADDED soft/JK20/src/res/img/gbulbon.png ADDED soft/JK20/src/res/img/rbulboff.png ADDED soft/JK20/src/res/img/rbulbon.png ADDED soft/JK20/src/view/LevelView.java ADDED soft/JK20/src/view/StationListView.java ADDED soft/JK20/src/view/View.java EDITED soft/firmware/Makefile DELETED soft/firmware/lib/sys/stimer.d DELETED soft/firmware/lib/sys/uart.d DELETED soft/firmware/src/fusb/fusb.d DELETED soft/firmware/src/fusb/fusb_proto.d DELETED soft/firmware/src/fusb/fusb_reg.d DELETED soft/firmware/src/led.d DELETED soft/firmware/src/main.d DELETED soft/firmware/src/u2s.d EDITED soft/firmware/src/u2s_shared.h DELETED soft/firmware/src/util.d DELETED soft/libk20/Makefile DELETED soft/libk20/k20tool.c check-in: 8d3a66aa88 user: pine tags: trunk
2016-05-10
12:28
user: pine tags: trunk ADDED soft/JK20/build.xml ADDED soft/JK20/src/Config.java ADDED soft/JK20/src/DPrint.java ADDED soft/JK20/src/JK20.java EDITED soft/firmware/src/u2s.c check-in: 0e5172d98f user: pine tags: trunk
2016-05-08
07:50
user: pine tags: trunk EDITED .fossil-settings/ignore-glob EDITED doc/geda/k20-fm.sch ADDED soft/firmware/Makefile ADDED soft/firmware/incrcnt.tcl ADDED soft/firmware/lib/sys/debug.h ADDED soft/firmware/lib/sys/stimer.c ADDED soft/firmware/lib/sys/stimer.d ADDED soft/firmware/lib/sys/stimer.h ADDED soft/firmware/lib/sys/sys.h ADDED soft/firmware/lib/sys/types.h ADDED soft/firmware/lib/sys/uart.c ADDED soft/firmware/lib/sys/uart.d ADDED soft/firmware/lib/sys/uart.h ADDED soft/firmware/src/fusb/fusb.c ADDED soft/firmware/src/fusb/fusb.d ADDED soft/firmware/src/fusb/fusb.h ADDED soft/firmware/src/fusb/fusb_proto.c ADDED soft/firmware/src/fusb/fusb_proto.d ADDED soft/firmware/src/fusb/fusb_proto.h ADDED soft/firmware/src/fusb/fusb_reg.c ADDED soft/firmware/src/fusb/fusb_reg.d ADDED soft/firmware/src/fusb/fusb_reg.h ADDED soft/firmware/src/led.c ADDED soft/firmware/src/led.d ADDED soft/firmware/src/led.h ADDED soft/firmware/src/main.c ADDED soft/firmware/src/main.d ADDED soft/firmware/src/main_.c ADDED soft/firmware/src/u2s.c ADDED soft/firmware/src/u2s.d ADDED soft/firmware/src/u2s.h ADDED soft/firmware/src/u2s_shared.h ADDED soft/firmware/src/util.c ADDED soft/firmware/src/util.d ADDED soft/firmware/src/util.h ADDED soft/firmware/src/version.h ADDED soft/libk20/Makefile ADDED soft/libk20/k20tool ADDED soft/libk20/k20tool.c check-in: cd62352ec5 user: pine tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added soft/JK20/build.xml.

























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<project name="JK20" basedir="." default="jar">
    <!-- -->
    <property name="main-class" value="org.jk20.JK20"/>
    <!-- -->
    <property name="build.sysclasspath" value="last"/>
    <property environment="env" />
    <!-- -->
    <property name="src.dir"     value="src"/>
    <condition property="build.dir" value="${env.BUILD_DIR}/StAXTest/build" else="build">
        <isset property="env.BUILD_DIR"/>
    </condition>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="jar.dir"     value="${build.dir}/jar"/>
    <!-- -->
    <target name="dirs">
        <mkdir dir="${classes.dir}"/>
    </target>
    <!-- -->
    <available file="jni" type="dir" property="jni.present"/>
    <target name="jni" if="jni.present" depends="dirs">
        <mkdir dir="${build.dir}/jni"/>
        <exec dir="jni" executable="make" failonerror="true">
            <arg value="all"/>
            <env key="BUILD_DIR" value="${build.dir}"/>
            <env key="CLASSES_DIR" value="${classes.dir}"/>
        </exec>
    </target>
    <!-- -->
    <target name="compile" depends="dirs,jni">
        <condition property="javac.debug" value="true" else="false">
            <isset property="env.DEBUG"/>
        </condition>
        <echo message="DEBUG: ${javac.debug}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="${javac.debug}" debuglevel="lines,vars,source">
                <compilerarg value="-Xlint:unchecked"/>
                <compilerarg value="-Xlint:deprecation"/>
        </javac>
    </target>
    <!-- -->
    <target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
            <fileset dir="${src.dir}" includes="res/img/**/*.png"/>
            <fileset dir="${src.dir}" includes="res/img/**/*.jpg"/>
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
    </target>
    <target name="dist" depends="jar">
        <!-- TODO -->
    </target>
    <!-- -->
    <target name="doc">
        <mkdir dir="${build.dir}/doc"/>
        <javadoc destdir="${build.dir}/doc" classpath="${src.dir}"
            Encoding="UTF-8" Locale="en_US">
            <fileset dir="${src.dir}">
                <include name="**/*.java"/>
            </fileset>
        </javadoc>
    </target>
    <!-- -->
    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>
    <!-- -->
    <target name="clean-build" depends="clean, jar"/>
    <!-- -->
    <target name="run" depends="jar">
        <java jar="${jar.dir}/${ant.project.name}.jar" fork="true">
            <jvmarg value="-Djava.library.path=${build.dir}/jni/fft"/>
        </java>
    </target>
</project>

Added soft/JK20/src/Config.java.



































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/**
 *
 */
package org.jk20;
/* */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.TreeMap;
import java.util.Map;
//import java.util.LinkedTreeMap;
import java.util.Iterator;
import java.util.Locale;
/* */
import java.awt.Color;
/* */
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.Attribute;

/**
 *
 */
public class Config {
    public TreeMap<Double, String> stationList;
    public Double currentStation;
    public Color bgColor;
    public Color fgColor;

    private static final String CONFIG_DIR = ".jk20";
    private File configPath; 
    /**
     *
     */
    public Config() {
        stationList = new TreeMap<>();
        currentStation = new Double(88.5);
        bgColor = Color.BLACK;
        fgColor = Color.WHITE;
    }
    /**
     *
     */
    public Config load() {
        Map<String, String> env = System.getenv();

        String homeEnv = env.get("HOME");
        if (homeEnv == null) {
            System.err.println("(E) Failed to get HOME environment variable");
            return this;
        }

        File homePath = new File(homeEnv);
        File cdirPath = new File(homePath, CONFIG_DIR);
        configPath    = new File(cdirPath, "config.xml");

        if (cdirPath.exists()) {
            if (!cdirPath.isDirectory()) {
                System.err.println("(E) Config directory is regular file (" + cdirPath.toString() + ")");
                return this;
            }
        } else {
            if (!cdirPath.mkdir()) {
                System.err.println("(E) Failed to create config directory (" + cdirPath.toString() + ")");
                return this;
            }
        }
        /* */
        if (configPath.exists()) {
            if (!configPath.isFile()) {
                System.err.println("(E) Config file not regular file (" + configPath.toString() + ")");
                return this;
            }
        }

        try {
            XMLInputFactory factory = XMLInputFactory.newInstance();
            XMLEventReader reader = factory.createXMLEventReader(configPath.toString(), new FileInputStream(configPath.toString()));
            readXML(reader, null);
        } catch (Exception e) {
            System.err.println("(E) Failed to read XML (" + configPath.toString() + "), " + e);
            return this;
        }

        return this;
    }
    /**
     *
     */
    private void readXML(XMLEventReader reader, String parent) throws XMLStreamException {
        while(reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            if (event.isStartElement()) {
                StartElement element = event.asStartElement();
                String elementName = element.getName().toString();
                String name = (parent == null) ? elementName : parent + "." + elementName;
                processXMLElement(name, element);
                readXML(reader, name);
            }
            if (event.isEndElement()) {
                break;
            }
        }
    }
    /**
     *
     */
    private class SimpleAttr {
        public String name;
        public String value;
    }
    /**
     *
     */
    private class SimpleAttrIterator implements Iterable<SimpleAttr> {
        private Iterator<Attribute> attrs;

        public SimpleAttrIterator(StartElement element) {
            @SuppressWarnings("unchecked")
            Iterator<Attribute> iterator = element.getAttributes();
            attrs = iterator;
        }
        public Iterator<SimpleAttr> iterator() {
            return new Iterator<SimpleAttr>() {
                @Override
                public boolean hasNext() {
                    return attrs.hasNext();
                }
                @Override
                public SimpleAttr next() {
                    Attribute attr = attrs.next();
                    SimpleAttr sAttr = new SimpleAttr();

                    sAttr.name  = attr.getName().toString();
                    sAttr.value = attr.getValue();

                    return sAttr;
                }
                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    }
    /**
     *
     */
    private void processXMLElement(String elementName, StartElement element) throws XMLStreamException {
        if (elementName.equals("config.stations.station")) {
            String stationName = null;
            Double stationValue = null;

            for (SimpleAttr attr: new SimpleAttrIterator(element)) {
                if (attr.name.equals("name")) {
                    stationName = attr.value;
                }
                if (attr.name.equals("value")) {
                    try {
                        stationValue = Double.parseDouble(attr.value);
                    } catch (Exception e) {
                        throw new XMLStreamException("Invalid value of stations's frequency attribute: " + e, element.getLocation());
                    }
                }
            }

            if (stationName == null)
                throw new XMLStreamException("Station has no \"name\" attribute", element.getLocation());
            if (stationValue == null)
                throw new XMLStreamException("Station has no \"value\" attribute", element.getLocation());
            stationList.put(stationValue, stationName);
        } else if (elementName.equals("config.stations.current")) {
            Double stationValue = null;
            for (SimpleAttr attr: new SimpleAttrIterator(element)) {
                if (attr.name.equals("value")) {
                    try {
                        stationValue = Double.parseDouble(attr.value);
                    } catch (Exception e) {
                        throw new XMLStreamException("Invalid value of stations's frequency attribute: " + e, element.getLocation());
                    }
                }
            }
            if (stationValue == null)
                throw new XMLStreamException("current has no \"value\" attribute", element.getLocation());
            currentStation = stationValue;
        } else if (
                elementName.equals("config.colors.bgcolor") ||
                elementName.equals("config.colors.fgcolor"))
        {
            Integer value = null;

            for (SimpleAttr attr: new SimpleAttrIterator(element)) {
                if (attr.name.equals("value")) {
                    try {
                        value = Integer.decode(attr.value);
                    } catch (Exception e) {
                        throw new XMLStreamException("Invalid value of color: " + e, element.getLocation());
                    }
                }
            }
            if (value == null)
                throw new XMLStreamException("color has no \"value\" attribute", element.getLocation());
            if (elementName.equals("config.colors.bgcolor")) {
                bgColor = new Color(value);
            } else if (elementName.equals("config.colors.fgcolor")) {
                fgColor = new Color(value);
            }
        }
    }
    /**
     *
     */
    public void save() {
        try {
            writeXML();
        } catch (Exception e) {
            System.err.println("(E) Failed to write XML (" + configPath.toString() + "), " + e);
        }
    }
    /**
     *
     */
    private String repeatString(String s, int n) {
        if (n == 0)
            return "";
        if (n == 1)
            return s;

        StringBuilder result = new StringBuilder(s.length() * n);
        while (--n >= 0) {
            result.append(s);
        }
        return result.toString();
    }
    /**
     *
     */
    private void writeXML() throws XMLStreamException, IOException {
        final String INDENT = "    ";
        int indent = 0;

        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        XMLStreamWriter xtw = xof.createXMLStreamWriter(new FileOutputStream(configPath), "UTF-8");

        xtw.writeStartDocument("utf-8","1.0");

        xtw.writeCharacters("\n");
        xtw.writeStartElement("config");
        xtw.writeCharacters("\n");
        /* colors */
        if (true) {
            xtw.writeCharacters(repeatString(INDENT, ++indent)); xtw.writeStartElement("colors");
            xtw.writeCharacters("\n");

            xtw.writeCharacters(repeatString(INDENT, ++indent)); xtw.writeEmptyElement("bgcolor");
            xtw.writeAttribute("value", String.format("#%06x", bgColor.getRGB() & 0x00ffffff));
            xtw.writeCharacters("\n");
            indent--;

            xtw.writeCharacters(repeatString(INDENT, ++indent)); xtw.writeEmptyElement("fgcolor");
            xtw.writeAttribute("value", String.format("#%06x", fgColor.getRGB() & 0x00ffffff));
            xtw.writeCharacters("\n");
            indent--;

            xtw.writeCharacters(repeatString(INDENT, indent--)); xtw.writeEndElement();
            xtw.writeCharacters("\n");
        }
        /* stations */
        if (true) {
            xtw.writeCharacters(repeatString(INDENT, ++indent)); xtw.writeStartElement("stations");
            xtw.writeCharacters("\n");

            indent++;

            xtw.writeCharacters(repeatString(INDENT, indent));
            xtw.writeEmptyElement("current");
            xtw.writeAttribute("value", String.format(Locale.US, "%.2f", currentStation));
            xtw.writeCharacters("\n");

            for (Double key: stationList.keySet()) {
                xtw.writeCharacters(repeatString(INDENT, indent));
                xtw.writeEmptyElement("station");
                xtw.writeAttribute("value", String.format(Locale.US, "%.2f", key));
                xtw.writeAttribute("name", String.format("%s", stationList.get(key)));
                xtw.writeCharacters("\n");
            }
            indent--;

            xtw.writeCharacters(repeatString(INDENT, indent--)); xtw.writeEndElement();
            xtw.writeCharacters("\n");
        }
        xtw.writeEndElement();
        xtw.writeCharacters("\n");

        xtw.flush();
        xtw.close();
    }
}

Added soft/JK20/src/DPrint.java.































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 *
 */
package org.jk20;


/*
 *
 */
public class DPrint {
    /**
     * Levels of debug
     * 0 - no  debug messages
     * 6 - all debug messages
     */
    private static int level = 6;
    public enum Level {
        NONE      (0),
        EXCEPTION (1),
        VERBOSE4  (2),
        VERBOSE3  (3),
        VERBOSE2  (4),
        VERBOSE1  (5),
        VERBOSE0  (6),
        NOMSG     (255);

        private final int value;
        Level(int value) {
            this.value = value;
        }
        public int getValue() {
            return value;
        }
    }
    /**
     *
     */
    public static void hex(byte[] data) {
        int i = 0;
        for (byte b: data) {
            if ((i % 8) == 0)
            {
                System.out.format(" ");
                if ((i % 16) == 0)
                {
                    System.out.format("%n");
                    if ((i % 256) == 0)
                    {
                        System.out.format("------: ");
                        for (int k = 0; k < 16; k++)
                            System.out.format("%02X%s", k, k == 7 ? "  " : "-");
                        System.out.format("--%n");
                    }
                    System.out.format("%06X: ", i);
                }
            }

            System.out.format("%02X ", b);
            i++;
        }
        System.out.println();
    }
    /**
     *
     */
    public static void format(Level plevel, String format, Object... args)
    {
        if (DPrint.level == 0)
            return;  
        if (plevel.getValue() <= DPrint.level)
            System.out.format(format, (Object[])args);
    }
    /**
     * Print formatted message, if level is zero output nothing
     */
    public static void format(String format, Object... args)
    {
        if (DPrint.level == 0)
            return;  
        System.out.format(format, (Object[])args);
    }

    /**
     *
     */
    public static void stackTrace() {
        int level = 0;
        System.out.println("--- trace begin --- ");
        for (StackTraceElement st: Thread.currentThread().getStackTrace())
        {
            if (level > 1)
                System.out.println(st);
            else
                level++;
        }
        System.out.println("--- trace end --- ");

        System.out.println("Press Enter");
        try {
            System.in.read();
        } catch (Exception e) {};
    }
    /**
     * Used to mark some dirty code
     */
    @Deprecated
    public static void warning(String msg) {
        System.out.println("Warning:  " + msg);
    }
};

Added soft/JK20/src/JK20.java.





















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
 *
 */
package org.jk20;

/**
 *
 */
public class JK20 {
    private static Config config;

    /**
     *
     */
    private void start(String[] args) {
        config = new Config().load();
//        config.save();
    }
    /**
     *
     */
    public static void main(String[] args) {
        new JK20().start(args);
    }
}

Changes to soft/firmware/src/u2s.c.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
..
77
78
79
80
81
82
83





84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
static uint8 u2s_buf[U2S_BUF_SIZE];

static void u2s_error(uint8 error);

static uint8 _rda_write(uint8* data);
static uint8 _rda_read(uint8* data);

//static void u2s_spi_setup(struct u2s_spi_setup_options *options);
//static void u2s_spi_exec(
//        struct u2s_spi_exec_options *options,
//        uint8 *txbuf, uint8 *rxbuf, int len);
//static void u2s_spi_exec2(
//        struct u2s_spi_exec_options *options, uint8 cs_gap,
//        uint8 *txbuf, uint8 *rxbuf, int len);
//static void u2s_io_dir(union u2s_io_map_t *dir, union u2s_io_map_t *mask);
//static void u2s_io_control(union u2s_io_map_t *control, union u2s_io_map_t *mask);
//static uint8 u2s_io_read();
//static void u2s_swd_raw(uint8 *iodir, uint8 *txbuf, uint8 *rxbuf, uint8 nbits);
//static void u2s_swd_exec(struct cmd_swd_exec_req_t *req, struct cmd_swd_exec_resp_t *resp);

//#define  IO0_TRIS    TRISCbits.TRISC0
//#define  IO1_TRIS    TRISCbits.TRISC1
//#define  IO2_TRIS    TRISCbits.TRISC5
//#define  IO3_TRIS    TRISCbits.TRISC4
//#define  KEY_TRIS    TRISCbits.TRISC2
//#define MOSI_TRIS    TRISCbits.TRISC7
//#define MISO_TRIS    TRISBbits.TRISB4
//#define  SCK_TRIS    TRISBbits.TRISB6
//
//#define  IO0_LAT    LATCbits.LATC0
//#define  IO1_LAT    LATCbits.LATC1
//#define  IO2_LAT    LATCbits.LATC5
//#define  IO3_LAT    LATCbits.LATC4
//#define  KEY_LAT    LATCbits.LATC2
//#define MOSI_LAT    LATCbits.LATC7
//#define MISO_LAT    LATBbits.LATB4
//#define  SCK_LAT    LATBbits.LATB6
//
//#define  IO0_PORT    PORTCbits.RC0
//#define  IO1_PORT    PORTCbits.RC1
//#define  IO2_PORT    PORTCbits.RC5
//#define  IO3_PORT    PORTCbits.RC4
//#define  KEY_PORT    PORTCbits.RC2
//#define MOSI_PORT    PORTCbits.RC7
//#define MISO_PORT    PORTBbits.RB4
//#define  SCK_PORT    PORTBbits.RB6

/*
 * send data to host
 */
#define u2s_send(buf, len) fusb_send_wrap(buf, len)


/*
................................................................................
 * initialize IO, etc
 */
void u2s_init()
{
    ANSEL  = 0;
    ANSELH = 0;






//    IO0_TRIS  = 1;
//    IO1_TRIS  = 1;
//    IO2_TRIS  = 1;
//    IO3_TRIS  = 1;
//    KEY_TRIS  = 0;
//    MOSI_TRIS = 1;
//    MISO_TRIS = 1;
//    SCK_TRIS  = 1;
//
//    IO0_LAT  = 0;
//    IO1_LAT  = 0;
//    IO2_LAT  = 0;
//    IO3_LAT  = 0;
//    KEY_LAT  = 1; /* NOTE */
//    MOSI_LAT = 0;
//    MISO_LAT = 0;
//    SCK_LAT  = 0;
}

/*
 * receive data from host
 */
void u2s_receive(uint8 *buf, uint8 len)
{







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>








<
<
<
<
<
<
<
<
<







23
24
25
26
27
28
29








































30
31
32
33
34
35
36
..
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56









57
58
59
60
61
62
63
static uint8 u2s_buf[U2S_BUF_SIZE];

static void u2s_error(uint8 error);

static uint8 _rda_write(uint8* data);
static uint8 _rda_read(uint8* data);









































/*
 * send data to host
 */
#define u2s_send(buf, len) fusb_send_wrap(buf, len)


/*
................................................................................
 * initialize IO, etc
 */
void u2s_init()
{
    ANSEL  = 0;
    ANSELH = 0;

    /* setup i2c */
    {


    }
//    IO0_TRIS  = 1;
//    IO1_TRIS  = 1;
//    IO2_TRIS  = 1;
//    IO3_TRIS  = 1;
//    KEY_TRIS  = 0;
//    MOSI_TRIS = 1;
//    MISO_TRIS = 1;
//    SCK_TRIS  = 1;









}

/*
 * receive data from host
 */
void u2s_receive(uint8 *buf, uint8 len)
{