Subversion Repositories freemyipod

Rev

Rev 902 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
770 user890104 1
//
2
//
898 user890104 3
//    Copyright 2013 user890104
770 user890104 4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
#include "global.h"
24
 
25
#include "usb.h"
26
#include "cache.h"
27
#include "emcore.h"
28
#include "fuse.h"
29
#include "util.h"
30
 
898 user890104 31
int main() {
32
    int32_t res, res2;
33
    uint8_t reattach = 0;
770 user890104 34
 
898 user890104 35
    /* emcore_get_version */
36
    struct emcore_dev_info dev_info;
784 user890104 37
 
898 user890104 38
    /* emcore_get_malloc_pool_bounds */
39
    struct emcore_malloc_pool_bounds bounds;
784 user890104 40
 
898 user890104 41
    /* emcore_readmem */
42
    /*
43
    void *buf;
44
    uint16_t buf_size;
45
    uint32_t read_addr;
46
    */
784 user890104 47
 
898 user890104 48
    /* emcore_readi2c */
49
    /* uint8_t i2cdata; */
770 user890104 50
 
898 user890104 51
    /* emcore_dir_open */
52
    //uint32_t dir_handle;
770 user890104 53
 
898 user890104 54
    /* emcore_dir_close_all */
55
    //uint32_t count;
56
 
770 user890104 57
    res = usb_init();
58
 
898 user890104 59
    if (res == LIBUSB_SUCCESS) {
770 user890104 60
        res = usb_find(EMCORE_USB_VID, EMCORE_USB_PID, &reattach);
61
    }
62
 
898 user890104 63
    if (res == LIBUSB_SUCCESS) {
770 user890104 64
        res = emcorefs_init();
65
    }
66
 
898 user890104 67
    do {
902 user890104 68
        if (res != EMCORE_SUCCESS) {
69
            break;
70
        }
71
 
898 user890104 72
        res = emcore_get_version(&dev_info);
770 user890104 73
 
898 user890104 74
        if (res != EMCORE_SUCCESS) {
75
            break;
76
        }
770 user890104 77
 
898 user890104 78
        printf("Connected to %c%c%c%c running %s v%d.%d.%d r%d\n",
79
            dev_info.hw_type & 0xFF, (dev_info.hw_type >> 8) & 0xFF, (dev_info.hw_type >> 16) & 0xFF, dev_info.hw_type >> 24,
80
            (dev_info.sw_type == 2 ? "emCORE" : "UNKNOWN"),
81
            dev_info.major, dev_info.minor, dev_info.patch, dev_info.svn_revision
82
        );
83
 
84
        res = emcore_get_malloc_pool_bounds(&bounds);
770 user890104 85
 
898 user890104 86
        if (res != EMCORE_SUCCESS) {
87
            break;
88
        }
89
 
90
        printf("Malloc pool bounds: 0x%08x - 0x%08x\n", bounds.lower, bounds.upper);
91
/*
92
        read_addr = 0x09000000;
93
        buf_size = 0x1000;
94
        buf = malloc(buf_size);
95
 
96
        printf("Reading 0x%08x bytes from 0x%08x\n", buf_size, read_addr);
97
 
98
        res = emcore_read(buf, read_addr, buf_size);
99
 
100
        if (res != EMCORE_SUCCESS) {
101
            free(buf);
102
            break;
103
        }
104
 
105
#ifdef DEBUG
106
        //dump_packet(buf, buf_size);
107
 
770 user890104 108
#endif
898 user890104 109
 
110
        printf("Writing 0x%08x bytes to 0x%08x\n", buf_size, read_addr);
111
 
112
        res = emcore_write(buf, read_addr, buf_size);
113
 
114
        if (res != EMCORE_SUCCESS) {
115
            free(buf);
116
            break;
117
        }
118
 
119
        free(buf);
120
*/
121
        /*
122
        printf("Reading 1 byte from I2C\n");
123
 
124
        res = emcore_readi2c(&i2cdata, 0, 0xe6, 0x29, 1);
125
 
126
        if (res != EMCORE_SUCCESS) {
127
            break;
128
        }
129
 
130
#ifdef DEBUG
131
        dump_packet(&i2cdata, 1);
132
 
133
#endif
134
        */
135
        /* nano2g - turns on/off the backlight */
136
        /*
137
        i2cdata = 1;
138
 
139
        printf("Writing 1 byte to I2C\n");
140
 
141
        res = emcore_writei2c(&i2cdata, 0, 0xe6, 0x29, 1);
142
 
143
        if (res != EMCORE_SUCCESS) {
144
            break;
145
        }
146
 
147
        sleep(1);
148
 
149
        i2cdata = 0;
150
 
151
        printf("Writing 1 byte to I2C\n");
152
 
153
        res = emcore_writei2c(&i2cdata, 0, 0xe6, 0x29, 1);
154
 
155
        if (res != EMCORE_SUCCESS) {
156
            break;
157
        }
158
        */
159
        /*
160
        // short filenames without malloc()
161
        res = emcore_file_open(&dir_handle, "/README", 0);
162
 
163
        if (res != EMCORE_SUCCESS) {
164
            break;
165
        }
166
 
167
        printf("Opened file handle: 0x%08x\n", dir_handle);
168
 
169
        res = emcore_file_close(dir_handle);
170
 
171
        if (res != EMCORE_SUCCESS) {
172
            break;
173
        }
174
 
175
        printf("Closed file handle: 0x%08x\n", dir_handle);
176
 
177
        // long filenames with malloc()
178
        res = emcore_file_open(&dir_handle, "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.png", 0);
179
 
180
        if (res != EMCORE_SUCCESS) {
181
            break;
182
        }
183
 
184
        printf("Opened file handle: 0x%08x\n", dir_handle);
185
 
186
        res = emcore_file_close(dir_handle);
187
 
188
        if (res != EMCORE_SUCCESS) {
189
            break;
190
        }
191
 
192
        printf("Closed file handle: 0x%08x\n", dir_handle);
193
        */
194
        /*
195
        res = emcore_dir_open(&dir_handle, "/");
196
 
197
        if (res != EMCORE_SUCCESS) {
198
            break;
199
        }
200
 
201
        printf("Opened dir handle: 0x%08x\n", dir_handle);
202
 
203
        res = emcore_ls(dir_handle);
204
 
205
        if (res != EMCORE_SUCCESS) {
206
            break;
207
        }
208
 
209
        printf("Listed dir handle: 0x%08x\n", dir_handle);
210
 
211
        res = emcore_dir_close(dir_handle);
212
 
213
        if (res != EMCORE_SUCCESS) {
214
            break;
215
        }
216
 
217
        printf("Closed dir handle 0x%08x\n", dir_handle);
218
 
219
        res = emcore_dir_close_all(&count);
220
 
221
        if (res != EMCORE_SUCCESS) {
222
            break;
223
        }
224
 
225
        printf("Closed %d dir handles\n", count);
226
        */
227
 
228
        /* powers off the device - graceful
229
        res = emcore_poweroff(1);
230
 
231
        if (res != EMCORE_SUCCESS) {
232
            break;
233
        }
234
 
235
        printf("Device powered off successfully!\n");
236
        */
770 user890104 237
    }
898 user890104 238
    while (0);
770 user890104 239
 
898 user890104 240
    if (res != EMCORE_SUCCESS) {
770 user890104 241
        print_error(res);
242
    }
243
 
244
    res2 = usb_destroy(reattach);
245
 
898 user890104 246
    if (res2 != LIBUSB_SUCCESS) {
770 user890104 247
        print_error(res2);
248
    }
249
 
898 user890104 250
    if (res < 0) {
770 user890104 251
        res = -res;
252
    }
253
 
254
    return res;
255
}