]>
Commit | Line | Data |
---|---|---|
3608c106 UH |
1 | /** |
2 | * Copyright (C) 2009 Ubixum, Inc. | |
3 | * | |
4 | * This library is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU Lesser General Public | |
6 | * License as published by the Free Software Foundation; either | |
7 | * version 2.1 of the License, or (at your option) any later version. | |
8 | * | |
9 | * This library is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * Lesser General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU Lesser General Public | |
15 | * License along with this library; if not, write to the Free Software | |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | **/ | |
18 | ||
19 | #include <stdio.h> | |
20 | ||
21 | #include <fx2regs.h> | |
22 | #include <fx2macros.h> | |
23 | ||
24 | #include <serial.h> | |
25 | #include <delay.h> | |
26 | #include <i2c.h> | |
27 | #include <lights.h> | |
28 | ||
29 | #define LG_PROM 0x51 // large prom ( is 16 bit addr mode) | |
30 | ||
31 | #define READ_SIZE 100 | |
32 | ||
33 | xdata BYTE buf[READ_SIZE]; | |
34 | ||
35 | #define IIC_SIZE 8 | |
36 | extern xdata BYTE fx2_c0[]; | |
37 | ||
38 | /* | |
39 | Modified eeprom_write that always uses two byte buffer. | |
40 | So can write to LG_PROM w/ out recompiling lib. | |
41 | (The library dynamically detects the prom based on the startup state. | |
42 | On the dev board, you can switch the prom with EEPROM select while | |
43 | the firmware is running.) | |
44 | */ | |
45 | void eeprom_write_local(BYTE prom_addr, WORD addr, WORD length, BYTE* buf) { | |
46 | BYTE addr_len=0; | |
47 | // 1st bytes of buffer are address and next byte is value | |
48 | BYTE data_buffer[3]; | |
49 | BYTE cur_byte=0; | |
50 | ||
51 | while ( cur_byte<length ) { | |
52 | addr_len=0; | |
53 | printf ( "%d %04x:%02x\n", cur_byte, addr, buf[cur_byte]); | |
54 | data_buffer[addr_len++] = MSB(addr); | |
55 | data_buffer[addr_len++] = LSB(addr); | |
56 | data_buffer[addr_len++] = buf[cur_byte++]; | |
57 | i2c_write ( prom_addr, addr_len, data_buffer, 0, NULL ); | |
58 | ++addr; // next byte goes to next address | |
59 | } | |
60 | ||
61 | } | |
62 | ||
63 | void main() { | |
64 | ||
65 | BOOL on=FALSE; | |
66 | unsigned int size=0; | |
67 | ||
68 | SETCPUFREQ(CLK_48M); | |
69 | sio0_init(57600); | |
70 | ||
71 | ||
72 | eeprom_write_local(LG_PROM, 0, IIC_SIZE, fx2_c0); | |
73 | ||
74 | ||
75 | while (1) { | |
76 | delay(1000); | |
77 | if (on) {d5on();} else {d5off();} | |
78 | on = !on; | |
79 | } | |
80 | ||
81 | ||
82 | } |