Subversion Repositories freemyipod

Rev

Details | 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 {
68
        res = emcore_get_version(&dev_info);
770 user890104 69
 
898 user890104 70
        if (res != EMCORE_SUCCESS) {
71
            break;
72
        }
770 user890104 73
 
898 user890104 74
        printf("Connected to %c%c%c%c running %s v%d.%d.%d r%d\n",
75
            dev_info.hw_type & 0xFF, (dev_info.hw_type >> 8) & 0xFF, (dev_info.hw_type >> 16) & 0xFF, dev_info.hw_type >> 24,
76
            (dev_info.sw_type == 2 ? "emCORE" : "UNKNOWN"),
77
            dev_info.major, dev_info.minor, dev_info.patch, dev_info.svn_revision
78
        );
79
 
80
        res = emcore_get_malloc_pool_bounds(&bounds);
770 user890104 81
 
898 user890104 82
        if (res != EMCORE_SUCCESS) {
83
            break;
84
        }
85
 
86
        printf("Malloc pool bounds: 0x%08x - 0x%08x\n", bounds.lower, bounds.upper);
87
/*
88
        read_addr = 0x09000000;
89
        buf_size = 0x1000;
90
        buf = malloc(buf_size);
91
 
92
        printf("Reading 0x%08x bytes from 0x%08x\n", buf_size, read_addr);
93
 
94
        res = emcore_read(buf, read_addr, buf_size);
95
 
96
        if (res != EMCORE_SUCCESS) {
97
            free(buf);
98
            break;
99
        }
100
 
101
#ifdef DEBUG
102
        //dump_packet(buf, buf_size);
103
 
770 user890104 104
#endif
898 user890104 105
 
106
        printf("Writing 0x%08x bytes to 0x%08x\n", buf_size, read_addr);
107
 
108
        res = emcore_write(buf, read_addr, buf_size);
109
 
110
        if (res != EMCORE_SUCCESS) {
111
            free(buf);
112
            break;
113
        }
114
 
115
        free(buf);
116
*/
117
        /*
118
        printf("Reading 1 byte from I2C\n");
119
 
120
        res = emcore_readi2c(&i2cdata, 0, 0xe6, 0x29, 1);
121
 
122
        if (res != EMCORE_SUCCESS) {
123
            break;
124
        }
125
 
126
#ifdef DEBUG
127
        dump_packet(&i2cdata, 1);
128
 
129
#endif
130
        */
131
        /* nano2g - turns on/off the backlight */
132
        /*
133
        i2cdata = 1;
134
 
135
        printf("Writing 1 byte to I2C\n");
136
 
137
        res = emcore_writei2c(&i2cdata, 0, 0xe6, 0x29, 1);
138
 
139
        if (res != EMCORE_SUCCESS) {
140
            break;
141
        }
142
 
143
        sleep(1);
144
 
145
        i2cdata = 0;
146
 
147
        printf("Writing 1 byte to I2C\n");
148
 
149
        res = emcore_writei2c(&i2cdata, 0, 0xe6, 0x29, 1);
150
 
151
        if (res != EMCORE_SUCCESS) {
152
            break;
153
        }
154
        */
155
        /*
156
        // short filenames without malloc()
157
        res = emcore_file_open(&dir_handle, "/README", 0);
158
 
159
        if (res != EMCORE_SUCCESS) {
160
            break;
161
        }
162
 
163
        printf("Opened file handle: 0x%08x\n", dir_handle);
164
 
165
        res = emcore_file_close(dir_handle);
166
 
167
        if (res != EMCORE_SUCCESS) {
168
            break;
169
        }
170
 
171
        printf("Closed file handle: 0x%08x\n", dir_handle);
172
 
173
        // long filenames with malloc()
174
        res = emcore_file_open(&dir_handle, "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.png", 0);
175
 
176
        if (res != EMCORE_SUCCESS) {
177
            break;
178
        }
179
 
180
        printf("Opened file handle: 0x%08x\n", dir_handle);
181
 
182
        res = emcore_file_close(dir_handle);
183
 
184
        if (res != EMCORE_SUCCESS) {
185
            break;
186
        }
187
 
188
        printf("Closed file handle: 0x%08x\n", dir_handle);
189
        */
190
        /*
191
        res = emcore_dir_open(&dir_handle, "/");
192
 
193
        if (res != EMCORE_SUCCESS) {
194
            break;
195
        }
196
 
197
        printf("Opened dir handle: 0x%08x\n", dir_handle);
198
 
199
        res = emcore_ls(dir_handle);
200
 
201
        if (res != EMCORE_SUCCESS) {
202
            break;
203
        }
204
 
205
        printf("Listed dir handle: 0x%08x\n", dir_handle);
206
 
207
        res = emcore_dir_close(dir_handle);
208
 
209
        if (res != EMCORE_SUCCESS) {
210
            break;
211
        }
212
 
213
        printf("Closed dir handle 0x%08x\n", dir_handle);
214
 
215
        res = emcore_dir_close_all(&count);
216
 
217
        if (res != EMCORE_SUCCESS) {
218
            break;
219
        }
220
 
221
        printf("Closed %d dir handles\n", count);
222
        */
223
 
224
        /* powers off the device - graceful
225
        res = emcore_poweroff(1);
226
 
227
        if (res != EMCORE_SUCCESS) {
228
            break;
229
        }
230
 
231
        printf("Device powered off successfully!\n");
232
        */
770 user890104 233
    }
898 user890104 234
    while (0);
770 user890104 235
 
898 user890104 236
    if (res != EMCORE_SUCCESS) {
770 user890104 237
        print_error(res);
238
    }
239
 
240
    res2 = usb_destroy(reattach);
241
 
898 user890104 242
    if (res2 != LIBUSB_SUCCESS) {
770 user890104 243
        print_error(res2);
244
    }
245
 
898 user890104 246
    if (res < 0) {
770 user890104 247
        res = -res;
248
    }
249
 
250
    return res;
251
}