Subversion Repositories freemyipod

Rev

Rev 814 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 814 Rev 877
Line 68... Line 68...
68
    IICDS(bus) = device & ~1;
68
    IICDS(bus) = device & ~1;
69
    while (IIC10(bus));
69
    while (IIC10(bus));
70
    IICSTAT(bus) = 0xF0;
70
    IICSTAT(bus) = 0xF0;
71
    while (IIC10(bus));
71
    while (IIC10(bus));
72
    IICCON(bus) = 0xB7;
72
    IICCON(bus) = 0xB7;
-
 
73
    while (IIC10(bus));
73
    while ((IICCON(bus) & 0x10) == 0) yield();
74
    while ((IICCON(bus) & 0x10) == 0) yield();
74
    if (address >= 0)
75
    if (address >= 0)
75
    {
76
    {
76
        /* write address */
77
        /* write address */
77
        while (IIC10(bus));
78
        while (IIC10(bus));
78
        IICDS(bus) = address;
79
        IICDS(bus) = address;
79
        while (IIC10(bus));
80
        while (IIC10(bus));
80
        IICCON(bus) = 0xB7;
81
        IICCON(bus) = 0xB7;
-
 
82
        while (IIC10(bus));
81
        while ((IICCON(bus) & 0x10) == 0) yield();
83
        while ((IICCON(bus) & 0x10) == 0) yield();
82
    }
84
    }
83
    /* write data */
85
    /* write data */
84
    while (length--)
86
    while (length--)
85
    {
87
    {
86
        while (IIC10(bus));
88
        while (IIC10(bus));
87
        IICDS(bus) = *data++;
89
        IICDS(bus) = *data++;
88
        while (IIC10(bus));
90
        while (IIC10(bus));
89
        IICCON(bus) = 0xB7;
91
        IICCON(bus) = 0xB7;
-
 
92
        while (IIC10(bus));
90
        while ((IICCON(bus) & 0x10) == 0) yield();
93
        while ((IICCON(bus) & 0x10) == 0) yield();
91
    }
94
    }
92
    /* STOP */
95
    /* STOP */
93
    while (IIC10(bus));
96
    while (IIC10(bus));
94
    IICSTAT(bus) = 0xD0;
97
    IICSTAT(bus) = 0xD0;
Line 110... Line 113...
110
        IICDS(bus) = device & ~1;
113
        IICDS(bus) = device & ~1;
111
        while (IIC10(bus));
114
        while (IIC10(bus));
112
        IICSTAT(bus) = 0xF0;
115
        IICSTAT(bus) = 0xF0;
113
        while (IIC10(bus));
116
        while (IIC10(bus));
114
        IICCON(bus) = 0xB7;
117
        IICCON(bus) = 0xB7;
-
 
118
        while (IIC10(bus));
115
        while ((IICCON(bus) & 0x10) == 0) yield();
119
        while ((IICCON(bus) & 0x10) == 0) yield();
116
        /* write address */
120
        /* write address */
117
        while (IIC10(bus));
121
        while (IIC10(bus));
118
        IICDS(bus) = address;
122
        IICDS(bus) = address;
119
        while (IIC10(bus));
123
        while (IIC10(bus));
120
        IICCON(bus) = 0xB7;
124
        IICCON(bus) = 0xB7;
-
 
125
        while (IIC10(bus));
121
        while ((IICCON(bus) & 0x10) == 0) yield();
126
        while ((IICCON(bus) & 0x10) == 0) yield();
122
    }
127
    }
123
    /* (repeated) START */
128
    /* (repeated) START */
124
    while (IIC10(bus));
129
    while (IIC10(bus));
125
    IICDS(bus) = device | 1;
130
    IICDS(bus) = device | 1;
126
    while (IIC10(bus));
131
    while (IIC10(bus));
127
    IICSTAT(bus) = 0xB0;
132
    IICSTAT(bus) = 0xB0;
128
    while (IIC10(bus));
133
    while (IIC10(bus));
129
    IICCON(bus) = 0xB7;
134
    IICCON(bus) = 0xB7;
-
 
135
    while (IIC10(bus));
130
    while ((IICCON(bus) & 0x10) == 0) yield();
136
    while ((IICCON(bus) & 0x10) == 0) yield();
131
    while (length--)
137
    while (length--)
132
    {
138
    {
133
        while (IIC10(bus));
139
        while (IIC10(bus));
134
        IICCON(bus) = (length == 0) ? 0x37 : 0xB7; /* NACK or ACK */
140
        IICCON(bus) = (length == 0) ? 0x37 : 0xB7; /* NACK or ACK */
-
 
141
        while (IIC10(bus));
135
        while ((IICCON(bus) & 0x10) == 0) yield();
142
        while ((IICCON(bus) & 0x10) == 0) yield();
136
        *data++ = IICDS(bus);
143
        *data++ = IICDS(bus);
137
    }
144
    }
138
    /* STOP */
145
    /* STOP */
139
    while (IIC10(bus));
146
    while (IIC10(bus));
140
    IICSTAT(bus) = 0x90;
147
    IICSTAT(bus) = 0x90;
141
    while (IIC10(bus));
148
    while (IIC10(bus));
142
    IICCON(bus) = 0xB7;
149
    IICCON(bus) = 0xB7;
-
 
150
    while (IIC10(bus));
143
    while ((IICSTAT(bus) & (1 << 5)) != 0) yield();
151
    while ((IICSTAT(bus) & (1 << 5)) != 0) yield();
144
	i2c_off(bus);
152
	i2c_off(bus);
145
    mutex_unlock(&i2cmutex);
153
    mutex_unlock(&i2cmutex);
146
}
154
}
147
 
155