Check-in [20cda04cde]
Not logged in

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

Overview
Comment: user: pine tags: trunk EDITED soft/JK20/jni/rda/RDA.c EDITED soft/JK20/jni/rda/RDA.java EDITED soft/JK20/src/JK20.java EDITED soft/JK20/src/view/StationListView.java EDITED soft/firmware/lib/sys/uart.c EDITED soft/firmware/src/main.c DELETED soft/firmware/src/main_.c EDITED soft/firmware/src/u2s.c
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:20cda04cdeecebc79286aff6f629ed5216534597
User & Date: pine 2016-05-21 03:29:41
Context
2016-05-22
02:24
user: pine tags: trunk EDITED soft/JK20/jni/rda/RDA.c EDITED soft/JK20/jni/rda/RDA.java EDITED soft/JK20/src/Config.java EDITED soft/JK20/src/ConfigSaver.java EDITED soft/JK20/src/ControlMessage.java EDITED soft/JK20/src/JK20.java EDITED soft/JK20/src/view/StationListView.java EDITED soft/JK20/src/view/View.java Leaf check-in: 2b79db1dc3 user: pine tags: trunk
2016-05-21
03:29
user: pine tags: trunk EDITED soft/JK20/jni/rda/RDA.c EDITED soft/JK20/jni/rda/RDA.java EDITED soft/JK20/src/JK20.java EDITED soft/JK20/src/view/StationListView.java EDITED soft/firmware/lib/sys/uart.c EDITED soft/firmware/src/main.c DELETED soft/firmware/src/main_.c EDITED soft/firmware/src/u2s.c check-in: 20cda04cde user: pine tags: trunk
2016-05-15
13:02
user: pine tags: trunk EDITED soft/JK20/jni/rda/RDA.c EDITED soft/JK20/src/JK20.java ADDED soft/JK20/src/res/img/logo.png EDITED soft/JK20/src/view/StationListView.java EDITED soft/JK20/src/view/View.java EDITED soft/firmware/src/u2s.c check-in: 7dadf72775 user: pine tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to soft/JK20/jni/rda/RDA.c.

394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
    int n;

    ret = libusb_bulk_transfer(handle,
            LIBUSB_ENDPOINT_IN | org_jk20_jni_rda_RDA_DEVICE_TRANSFER_ENDPOINT,
        buf, len, &n, timeout);
    if (ret)         
    {
        fprintf(stderr, "transfer (IN) error %d\r\n", ret);
        return -1;
    }
#ifdef DEBUG_THIS
    {
        int i;

        printf(" IN: ");







|







394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
    int n;

    ret = libusb_bulk_transfer(handle,
            LIBUSB_ENDPOINT_IN | org_jk20_jni_rda_RDA_DEVICE_TRANSFER_ENDPOINT,
        buf, len, &n, timeout);
    if (ret)         
    {
//        fprintf(stderr, "transfer (IN) error %d\r\n", ret);
        return -1;
    }
#ifdef DEBUG_THIS
    {
        int i;

        printf(" IN: ");

Changes to soft/JK20/jni/rda/RDA.java.

258
259
260
261
262
263
264



265
266
267
268
269
270
271
...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
...
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
    }
    /**
     * Take state of device (read data from device).
     */
    public void take() throws Exception {
        read();




        rREADCHAN = (char)((regs[0x0A] >>> 0 ) & 0b1111111111);
        rST       = (char)((regs[0x0A] >>> 10) & 0b1         );
        rBLK_E    = (char)((regs[0x0A] >>> 11) & 0b1         );
        rRDSS     = (char)((regs[0x0A] >>> 12) & 0b1         );
        rSF       = (char)((regs[0x0A] >>> 13) & 0b1         );
        rSTC      = (char)((regs[0x0A] >>> 14) & 0b1         );
        rRDSR     = (char)((regs[0x0A] >>> 15) & 0b1         );
................................................................................
        rFM_TRUE  = (char)((regs[0x0B] >>> 8 ) & 0b1         );
        rRSSI     = (char)((regs[0x0B] >>> 9 ) & 0b1111111   );

        rRDSA = regs[0x0C];
        rRDSB = regs[0x0D];
        rRDSC = regs[0x0E];
        rRDSD = regs[0x0F];

        throw new Exception("TODO read from device");
    }
    /**
     * Enable power.
     */
    public void powerEnable() {
        wENABLE = 1;
    }
................................................................................
     */
    public void softMuteDisable() {
        wSOFTMUTE_EN = 0;
    }
    /**
     * Set volume level. Value should be between <b>RDA.wcVOLUME_MIN</b> and <b>RDA.wcVOLUME_MAX</b>.
     */
    public void setVolume(char value) {
        if (value < wcVOLUME_MIN)
            value = wcVOLUME_MIN;
        if (value > wcVOLUME_MAX)
            value = wcVOLUME_MAX;
        wVOLUME = value;
    }
    /**
     * Set seekSNR Threshold value. Value should be between <b>RDA.wcSEEKTH_MIN</b> and <b>RDA.wcSEEKTH_MAX</b>.
     */
    public void setSeekSNRThreshold(char value) {
        if (value < wcSEEKTH_MIN)
            value = wcSEEKTH_MIN;







>
>
>







 







<
<







 







|




|







258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
...
280
281
282
283
284
285
286


287
288
289
290
291
292
293
...
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
    }
    /**
     * Take state of device (read data from device).
     */
    public void take() throws Exception {
        read();

        for (int i = READ_REG_START; i <  READ_REG_START + REG_NUMBER; i++)
            System.out.format("REG %02X %04X%n", i, (int)regs[i]);

        rREADCHAN = (char)((regs[0x0A] >>> 0 ) & 0b1111111111);
        rST       = (char)((regs[0x0A] >>> 10) & 0b1         );
        rBLK_E    = (char)((regs[0x0A] >>> 11) & 0b1         );
        rRDSS     = (char)((regs[0x0A] >>> 12) & 0b1         );
        rSF       = (char)((regs[0x0A] >>> 13) & 0b1         );
        rSTC      = (char)((regs[0x0A] >>> 14) & 0b1         );
        rRDSR     = (char)((regs[0x0A] >>> 15) & 0b1         );
................................................................................
        rFM_TRUE  = (char)((regs[0x0B] >>> 8 ) & 0b1         );
        rRSSI     = (char)((regs[0x0B] >>> 9 ) & 0b1111111   );

        rRDSA = regs[0x0C];
        rRDSB = regs[0x0D];
        rRDSC = regs[0x0E];
        rRDSD = regs[0x0F];


    }
    /**
     * Enable power.
     */
    public void powerEnable() {
        wENABLE = 1;
    }
................................................................................
     */
    public void softMuteDisable() {
        wSOFTMUTE_EN = 0;
    }
    /**
     * Set volume level. Value should be between <b>RDA.wcVOLUME_MIN</b> and <b>RDA.wcVOLUME_MAX</b>.
     */
    public void setVolume(int value) {
        if (value < wcVOLUME_MIN)
            value = wcVOLUME_MIN;
        if (value > wcVOLUME_MAX)
            value = wcVOLUME_MAX;
        wVOLUME = (char)value;
    }
    /**
     * Set seekSNR Threshold value. Value should be between <b>RDA.wcSEEKTH_MIN</b> and <b>RDA.wcSEEKTH_MAX</b>.
     */
    public void setSeekSNRThreshold(char value) {
        if (value < wcSEEKTH_MIN)
            value = wcSEEKTH_MIN;

Changes to soft/JK20/src/JK20.java.

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
..
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
        jk20 = this;
        jk20Thread = Thread.currentThread();

        messageQueue = new ArrayBlockingQueue<ControlMessage>(MESSAGE_QUEUE_CAPACITY);

        config = new Config().load();
        configSaver = new ConfigSaver(config).start();
        SwingUtilities.invokeLater(() -> {
            view = new View().make();
        });

        rda = new RDA();
        try {
            rda.init();
//            rda.setChannel(88.5);
        } catch (Exception e) {
            System.out.println("RDA init error: " + e);
            terminate();
            return;
        }


































        boolean first = true;
        while (!needTerminate()) {
            if (first) {
                first = false;
            } else {
                rda.close();
................................................................................
            try {
                rda.apply();
            } catch (Exception e) {
                System.out.println("RDA apply error: " + e);
                continue;
            }

            messageQueue.clear();
            while (!needTerminate()) {
                ControlMessage message;
                try {
                    message = messageQueue.take();









                } catch (InterruptedException e) {
                    System.out.println(getClass().getSimpleName() + " interrupted, " + e);
                    terminate = true;
                    break;
                }
                processMessage(message);
            }















            /* show "---.- MHz" if connection to device was lost */
            view.setFrequencyIndicator(0);
        }
        terminate();
    }
    /**
     *
     */
    private boolean needTerminate() {







|
|
|




<





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
<
<

|
>
>
>
>
>
>
>
>
>
|
|



<


>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|







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
...
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
        jk20 = this;
        jk20Thread = Thread.currentThread();

        messageQueue = new ArrayBlockingQueue<ControlMessage>(MESSAGE_QUEUE_CAPACITY);

        config = new Config().load();
        configSaver = new ConfigSaver(config).start();
//        SwingUtilities.invokeLater(() -> {
//            view = new View().make();
//        });

        rda = new RDA();
        try {
            rda.init();

        } catch (Exception e) {
            System.out.println("RDA init error: " + e);
            terminate();
            return;
        }

        rda.powerEnable();
        rda.audioHighZDisable();
        try {
//            rda.selectBand(RDA.wcBAND_65_76_MHZ); 
            rda.selectBand(RDA.wcBAND_76_108_MHZ);
            

//            rda.setChannel(67.22);
            rda.setChannel(88.5);
//            rda.setChannel(105.4);
//            rda.setChannel(102.5);
//            rda.setChannel(106.6);
        } catch (Exception e) {
            System.out.println("RDA invalid argument: " + e);
        }
        rda.muteDisable();
        rda.softMuteDisable();
        rda.setVolume(RDA.wcVOLUME_MAX * 1 / 5);

        rda.tuneEnable();
//        rda.setSeekUp();
//        rda.seekEnable();
//        rda.setSeekModeWrap();
//        rda.setSeekModeStop();

//        /* apply current settings */
//        try {
//            rda.apply();
//            System.out.format("freq %f%n", rda.getChannel());
//        } catch (Exception e) {
//            System.out.println("RDA apply error: " + e);
//        }

        boolean first = true;
        while (!needTerminate()) {
            if (first) {
                first = false;
            } else {
                rda.close();
................................................................................
            try {
                rda.apply();
            } catch (Exception e) {
                System.out.println("RDA apply error: " + e);
                continue;
            }

            while (true) {


                try {
                    rda.take();
                    System.out.format("freq %f%n", rda.getChannel());
                } catch (Exception e) {
                    System.out.println("RDA take error: " + e);
                    break;
                }


                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e2) {
                    System.out.println(getClass().getSimpleName() + " interrupted, " + e2);
                    terminate = true;
                    break;
                }

            }


//            messageQueue.clear();
//            while (!needTerminate()) {
//                ControlMessage message;
//                try {
//                    message = messageQueue.take();
//                } catch (InterruptedException e) {
//                    System.out.println(getClass().getSimpleName() + " interrupted, " + e);
//                    terminate = true;
//                    break;
//                }
//                processMessage(message);
//            }
//
//            /* show "---.- MHz" if connection to device was lost */
//            view.setFrequencyIndicator(0);
        }
        terminate();
    }
    /**
     *
     */
    private boolean needTerminate() {

Changes to soft/JK20/src/view/StationListView.java.

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
        });

        SwingUtilities.invokeLater(() -> {
            table.getColumnModel().getColumn(0).setMaxWidth(table.getWidth() * 4 / 5);
            table.getColumnModel().getColumn(1).setMaxWidth(table.getWidth() * 1 / 5);
        });

        /* XXX */
        SwingUtilities.invokeLater(() -> {
            selectCurrent();
        });
    }
    /**
     *
     */
    public void selectCurrent() {
        synchronized (config) {
            for (Config.Station station: config.stationList) {







|
|
|
|







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
        });

        SwingUtilities.invokeLater(() -> {
            table.getColumnModel().getColumn(0).setMaxWidth(table.getWidth() * 4 / 5);
            table.getColumnModel().getColumn(1).setMaxWidth(table.getWidth() * 1 / 5);
        });

//        /* XXX */
//        SwingUtilities.invokeLater(() -> {
//            selectCurrent();
//        });
    }
    /**
     *
     */
    public void selectCurrent() {
        synchronized (config) {
            for (Config.Station station: config.stationList) {

Changes to soft/firmware/lib/sys/uart.c.

29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
    SPBRG = (UART_DIVIDER & 0xff);
    SPBRGH = (UART_DIVIDER >> 8) & 0xff;

    RCSTAbits.SPEN = 1;     /* enable serial port */
    RCSTAbits.CREN = 1;     /* continues receive enable */
    TXSTAbits.TXEN = 1;     /* transmit enable */


    PIE1bits.RCIE = 1;

    rxbuf.c = 0;
    txbuf.c = 0;
    txbuf.p = 0;
}

/*







>
|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    SPBRG = (UART_DIVIDER & 0xff);
    SPBRGH = (UART_DIVIDER >> 8) & 0xff;

    RCSTAbits.SPEN = 1;     /* enable serial port */
    RCSTAbits.CREN = 1;     /* continues receive enable */
    TXSTAbits.TXEN = 1;     /* transmit enable */

/* XXX rx interrupt disabled */
//    PIE1bits.RCIE = 1;

    rxbuf.c = 0;
    txbuf.c = 0;
    txbuf.p = 0;
}

/*

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

11
12
13
14
15
16
17

18

19
20
21
22
23
24
25
..
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma config USBDIV = OFF
#pragma config IESO   = OFF
#pragma config FOSC   = HS
#pragma config PLLEN  = ON
#pragma config FCMEN  = OFF
#pragma config PCLKEN = ON
#pragma config BOREN  = SBORDIS

#pragma config BORV   = 30

#pragma config PWRTEN = ON
#pragma config WDTPS  = 8192       /* XXX TODO */
#pragma config WDTEN  = OFF        /* XXX TODO */
#pragma config MCLRE  = ON
#pragma config HFOFST = OFF
#pragma config DEBUG  = OFF
#pragma config STVREN = ON
................................................................................
}

/*
 *
 */
void init()
{
    u2s_init();
    led_init();
    stimer_init();
    uart_init();
    fusb_init();

    INTCONbits.GIEH = 1;
    INTCONbits.PEIE = 1;
}








>
|
>







 







|
|
|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma config USBDIV = OFF
#pragma config IESO   = OFF
#pragma config FOSC   = HS
#pragma config PLLEN  = ON
#pragma config FCMEN  = OFF
#pragma config PCLKEN = ON
#pragma config BOREN  = SBORDIS
//#pragma config BOREN  = OFF
//#pragma config BORV   = 30
#pragma config BORV   = 19
#pragma config PWRTEN = ON
#pragma config WDTPS  = 8192       /* XXX TODO */
#pragma config WDTEN  = OFF        /* XXX TODO */
#pragma config MCLRE  = ON
#pragma config HFOFST = OFF
#pragma config DEBUG  = OFF
#pragma config STVREN = ON
................................................................................
}

/*
 *
 */
void init()
{
    stimer_init();
    u2s_init();
    led_init();
    uart_init();
    fusb_init();

    INTCONbits.GIEH = 1;
    INTCONbits.PEIE = 1;
}

Deleted soft/firmware/src/main_.c.

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
/*
 * sdcc
 */
#include <pic16/pic18fregs.h>
#include <types.h>
#include <stimer.h>
#include "version.h"
#include "led.h"
#include "uart.h"
#include "debug.h"
#include "usb.h"

#define CONF1L_UNDEF 0x38
#define CONF1H_UNDEF 0xff
#define CONF2L_UNDEF 0x1f
#define CONF2H_UNDEF 0x1f
#define CONF3H_UNDEF 0x88
#define CONF4L_UNDEF 0xcd

static __code char __at(__CONFIG1L) conf1L = 
    CONF1L_UNDEF & _USBDIV_OFF_1L & _CPUDIV_NOCLKDIV_1L;

static __code char __at(__CONFIG1H) conf1H = 
    CONF1H_UNDEF & _FOSC_HS_1H & _PLLEN_ON_1H & _PCLKEN_ON_1H & _FCMEN_OFF_1H & _IESO_OFF_1H;

static __code char __at(__CONFIG2L) conf2L = 
    CONF2L_UNDEF & _BOREN_OFF_2L;

static __code char __at(__CONFIG2H) conf2H = 
    CONF2H_UNDEF & _WDTEN_OFF_2H; /* TODO postscaller */

static __code char __at(__CONFIG3H) conf3H = 
    CONF3H_UNDEF & _MCLRE_ON_3H & _HFOFST_ON_3H;

static __code char __at(__CONFIG4L) conf4L = 
    CONF4L_UNDEF & _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_OFF_4L & _XINST_OFF_4L;



/*
 *
 */
void hisr() __interrupt 1
{
//    stimer_isr();
    uart_isr();
    usb_isr();
}


/*
 *
 */
void main(void)
{
    uart_init();

    debug_str("\r\n-= u2s, v."VERSION_STRING", "__DATE__" "__TIME__" =-\r\n");
//    led_init();
//    stimer_init();
    INTCONbits.GIEH = 1;
    INTCONbits.PEIE = 1;

    while(1)
    {
//        led_process();
        usb_process();
    }
}

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












































































































































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

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
...
233
234
235
236
237
238
239

240
241
242
243
244
245
246
...
252
253
254
255
256
257
258

259
260
261
262
263
264
265
#include "util.h"
#include "u2s.h"
#include "fusb/fusb.h"
#include "fusb/fusb_reg.h"
#include "led.h"
#include "u2s_shared.h"

#define DEBUG_THIS

#ifdef DEBUG_THIS
    #define DEBUG_THIS_STR(s)    debug_str(s)
    #define DEBUG_THIS_CHAR(c)   debug_char(c)
    #define DEBUG_THIS_HEX(h, l) debug_hex(h, l)
#else
    #define DEBUG_THIS_STR(s)
................................................................................
    {
        if (stimer_delta(to) >= SSP_TIMEOUT)
        {
            DEBUG_THIS_STR("(E) SNT\n");
            return 0;
        }
    }

    return 1;
}

/*
 *
 * RETURN
 *     0 on success, nonzero on error
................................................................................

    DEBUG_THIS_STR("rda write:");
#ifdef DEBUG_THIS
    util_printarray(data, sizeof(union rda_write_data_t));
#endif

#define RDA_ADDRESS    0x10


    /* START */
    if (!_i2c_start())
        goto error;

    /* Write address. */
    if (!_i2c_write((RDA_ADDRESS << 1) | 0))







|







 







>







 







>







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#include "util.h"
#include "u2s.h"
#include "fusb/fusb.h"
#include "fusb/fusb_reg.h"
#include "led.h"
#include "u2s_shared.h"

//#define DEBUG_THIS

#ifdef DEBUG_THIS
    #define DEBUG_THIS_STR(s)    debug_str(s)
    #define DEBUG_THIS_CHAR(c)   debug_char(c)
    #define DEBUG_THIS_HEX(h, l) debug_hex(h, l)
#else
    #define DEBUG_THIS_STR(s)
................................................................................
    {
        if (stimer_delta(to) >= SSP_TIMEOUT)
        {
            DEBUG_THIS_STR("(E) SNT\n");
            return 0;
        }
    }
    PIR1bits.SSPIF = 0;
    return 1;
}

/*
 *
 * RETURN
 *     0 on success, nonzero on error
................................................................................

    DEBUG_THIS_STR("rda write:");
#ifdef DEBUG_THIS
    util_printarray(data, sizeof(union rda_write_data_t));
#endif

#define RDA_ADDRESS    0x10
//#define RDA_ADDRESS    0x11

    /* START */
    if (!_i2c_start())
        goto error;

    /* Write address. */
    if (!_i2c_write((RDA_ADDRESS << 1) | 0))