Subversion Repositories Code-Repo

Rev

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

Rev 274 Rev 276
Line 112... Line 112...
112
    dummy = RSWRST;
112
    dummy = RSWRST;
113
    // Prevent any unwanted code execution until reset occurs
113
    // Prevent any unwanted code execution until reset occurs
114
    while(1);
114
    while(1);
115
}
115
}
116
 
116
 
-
 
117
void Test_Callback(uint8_t controller, CTRL_BTN_STATUS value) {
-
 
118
    LED1_LAT = 0;
-
 
119
    LED2_LAT = 0;
-
 
120
    LED3_LAT = 0;
-
 
121
    LED4_LAT = 0;
-
 
122
    if (value.BTN_R_N)
-
 
123
        LED1_LAT = 1;
-
 
124
    if (value.BTN_R_E)
-
 
125
        LED2_LAT = 1;
-
 
126
    if (value.BTN_R_S)
-
 
127
        LED3_LAT = 1;
-
 
128
    if (value.BTN_R_W)
-
 
129
        LED4_LAT = 1;
-
 
130
}
-
 
131
 
117
void main() {
132
void main() {
118
    // WARNING!! THIS BOARD WILL RESET EVERY 1048.576s DUE TO THE WDT!!
133
    // WARNING!! THIS BOARD WILL RESET EVERY 1048.576s DUE TO THE WDT!!
119
 
134
 
120
    /* -------------------- BEGIN INITIALIZATION --------------------- */
135
    /* -------------------- BEGIN INITIALIZATION --------------------- */
121
    
136
    
Line 129... Line 144...
129
    // Set all analog I/O pins to digital
144
    // Set all analog I/O pins to digital
130
    AD1PCFGSET = 0xFFFF;
145
    AD1PCFGSET = 0xFFFF;
131
 
146
 
132
    // Enable the watchdog timer with windowed mode disabled
147
    // Enable the watchdog timer with windowed mode disabled
133
    // WDT prescaler set to 1048576 (1048.576s) (see config bits)
148
    // WDT prescaler set to 1048576 (1048.576s) (see config bits)
-
 
149
//    WDTCON = 0x00008000;
134
    WDTCON = 0x00008000;
150
    WDTCON = 0x00000000;
135
 
151
 
136
    // Configure onboard LEDs
152
    // Configure onboard LEDs
137
    LED1_TRIS = 0;
153
    LED1_TRIS = 0;
138
    LED2_TRIS = 0;
154
    LED2_TRIS = 0;
139
    LED3_TRIS = 0;
155
    LED3_TRIS = 0;
Line 155... Line 171...
155
    // Initialize the SPI1 module
171
    // Initialize the SPI1 module
156
    SPI1_DATA spi_1_data;
172
    SPI1_DATA spi_1_data;
157
    SPI1_Init(&spi_1_data, NULL);
173
    SPI1_Init(&spi_1_data, NULL);
158
 
174
 
159
    // Initialize the SPI4 module
175
    // Initialize the SPI4 module
160
    SPI4_DATA spi_4_data;
176
//    SPI4_DATA spi_4_data;
161
    SPI4_Init(&spi_4_data);
177
//    SPI4_Init(&spi_4_data);
162
 
178
 
163
    // Initialize the I2C1 module
179
    // Initialize the I2C1 module
164
    I2C1_DATA i2c_1_data;
180
    I2C1_DATA i2c_1_data;
165
    I2C1_Init(&i2c_1_data, I2C1_400KHZ, 0x20);
181
    I2C1_Init(&i2c_1_data, I2C1_200KHZ, 0x20);
166
 
182
 
167
//    // Initialize the UART1 module
183
//    // Initialize the UART1 module
168
//    UART1_DATA uart_data;
184
//    UART1_DATA uart_data;
169
//    UART1_Init(&uart_data, &Cube_Data_In);
185
//    UART1_Init(&uart_data, &Cube_Data_In);
170
 
186
 
Line 174... Line 190...
174
    // Initialize the cube variables
190
    // Initialize the cube variables
175
    CUBE_DATA cube_data;
191
    CUBE_DATA cube_data;
176
    Cube_Init(&cube_data, 0x40);
192
    Cube_Init(&cube_data, 0x40);
177
 
193
 
178
    // Start the cube update layer interrupt
194
    // Start the cube update layer interrupt
179
    // 2083 = 60Hz, 500 = 250Hz, 250 = 500Hz
195
    // 2084 = 60Hz, 500 = 250Hz, 250 = 500Hz
180
    TIMER5_DATA timer_5_data;
196
    TIMER5_DATA timer_5_data;
181
    TIMER5_Init(&timer_5_data, &Cube_Timer_Interrupt, 500);
197
    TIMER5_Init(&timer_5_data, &Cube_Timer_Interrupt, 500);
182
 
198
 
183
    // Start the controller polling and overlay rotation interrupt
199
    // Initialize timer for controller polling and overlay rotation interrupt
184
    TIMER4_DATA timer_4_data;
200
    TIMER4_DATA timer_4_data;
185
    TIMER4_Init(&timer_4_data, NULL, NULL, 0);
201
    TIMER4_Init(&timer_4_data, NULL, NULL, 0);
186
 
202
 
187
    // Process button inputs
203
    // Process button inputs
188
    BTN_DATA btn_data;
204
    BTN_DATA btn_data;
189
    BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, NULL);
205
    BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, NULL);
190
 
206
 
191
    // Initialize controllers
207
    // Initialize controllers
192
    CONTROLLER_DATA ctrl_data;
208
    CONTROLLER_DATA ctrl_data;
193
    Controller_Init(&ctrl_data);
209
    Controller_Init(&ctrl_data, NULL);
194
 
210
 
195
    // Initialize the Ethernet module
211
    // Initialize the Ethernet module
196
    if (op_state == BOARD_MODE_ETHERNET) {
212
    if (op_state == BOARD_MODE_ETHERNET) {
197
        LED1_LAT = 1;
213
        LED1_LAT = 1;
198
        ETH_DATA eth_data;
214
        ETH_DATA eth_data;
Line 201... Line 217...
201
    
217
    
202
    SNAKE_DATA snake_data;
218
    SNAKE_DATA snake_data;
203
    TRON_DATA tron_data;
219
    TRON_DATA tron_data;
204
 
220
 
205
    PWM2_Start();
221
    PWM2_Start();
206
    TIMER5_Start();
-
 
207
    
222
    
208
    /* -------------------- END OF INITIALIZATION -------------------- */
223
    /* -------------------- END OF INITIALIZATION -------------------- */
209
    /* ------------------------ BEGIN DISPLAY ------------------------ */
224
    /* ------------------------ BEGIN DISPLAY ------------------------ */
210
 
225
 
211
    // Figure out what to do at this point (depending on current state)
226
    // Figure out what to do at this point (depending on current state)
212
    switch (op_state) {
227
    switch (op_state) {
213
        case BOARD_MODE_IDLE:
228
        case BOARD_MODE_IDLE:
-
 
229
            TIMER5_Start(); // Use the default refresh rate (250Hz)
214
            Idle_Animation_Sequence();
230
            Idle_Animation_Sequence();
215
            break;
231
            break;
216
        case BOARD_MODE_SNAKE:;
232
        case BOARD_MODE_SNAKE:
-
 
233
            // Change refresh rate to ~60Hz
-
 
234
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2000);
-
 
235
            TIMER5_Start();
-
 
236
            // Poll the controllers at 1kHz
217
            Controller_Init(&ctrl_data);
237
            Controller_Init(NULL, &Snake_Update_Direction);
218
            TIMER4_Init(NULL, &Controller_Update, NULL, 0);
238
            TIMER4_Init(NULL, &Controller_Update, NULL, 0);
219
            TIMER4_Start();
239
            // Initialize and start the game
220
            Snake_Init(&snake_data);
240
            Snake_Init(&snake_data);
221
            Snake_Main();
241
            Snake_Main();
222
            break;
242
            break;
223
        case BOARD_MODE_TRON:
243
        case BOARD_MODE_TRON:
-
 
244
            // Change refresh rate to ~60Hz
-
 
245
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2000);
-
 
246
            TIMER5_Start();
-
 
247
            // Poll the controllers at 1kHz
224
            Controller_Init(&ctrl_data);
248
            Controller_Init(&ctrl_data, NULL);
225
            TIMER4_Init(NULL, &Controller_Update, NULL, 0);
249
            TIMER4_Init(NULL, &Controller_Update, NULL, 0);
226
            TIMER4_Start();
250
            // Initialize and start the game
227
            Tron_Init(&tron_data);
251
            Tron_Init(&tron_data);
-
 
252
            TIMER4_Start();
228
            Tron_Main();
253
            Tron_Main();
229
            break;
254
            break;
230
        case BOARD_MODE_ETHERNET:
255
        case BOARD_MODE_ETHERNET:
231
            TIMER4_Stop();
256
            TIMER4_Stop();
-
 
257
            TIMER5_Start();
232
            LED2_LAT = 1;
258
            LED2_LAT = 1;
233
            while(1);
259
            while(1);
234
            break;
260
            break;
235
    }
261
    }
236
 
262
 
Line 248... Line 274...
248
//    Animation_Pseudo_Random_Colors(200);
274
//    Animation_Pseudo_Random_Colors(200);
249
//    Animation_Pseudo_Random_Colors(200);
275
//    Animation_Pseudo_Random_Colors(200);
250
//    Animation_Pseudo_Random_Colors(200);
276
//    Animation_Pseudo_Random_Colors(200);
251
//    Animation_Pseudo_Random_Colors(200);
277
//    Animation_Pseudo_Random_Colors(200);
252
//    Animation_Pseudo_Random_Colors(200);
278
//    Animation_Pseudo_Random_Colors(200);
-
 
279
    
-
 
280
    uint8_t connected, i;
-
 
281
    connected = Controller_Get_Connected();
-
 
282
    for (i = 0; i < connected; i++) {
-
 
283
        Controller_Set_Idle(i);
-
 
284
    }
253
 
285
 
254
    // Start the scrolling text
286
    // Start the scrolling text
255
    TIMER4_Stop();
287
    TIMER4_Stop();
256
    TIMER4_Init(NULL, NULL, &Cube_Text_Interrupt, 100);
288
    TIMER4_Init(NULL, NULL, &Cube_Text_Interrupt, 100);
257
//    TIMER4_Start();
289
//    TIMER4_Start();
Line 284... Line 316...
284
        Animation_Wave2(100);
316
        Animation_Wave2(100);
285
//        Animation_Solid_Colors(300);
317
//        Animation_Solid_Colors(300);
286
//        Animation_Layer_Alternate(300);
318
//        Animation_Layer_Alternate(300);
287
//        Animation_Pixel_Alternate(200);
319
//        Animation_Pixel_Alternate(200);
288
//        Animation_Full_Color_Sweep(1000);
320
//        Animation_Full_Color_Sweep(1000);
289
        Animation_Row_Column_Sweep(40);
321
//        Animation_Row_Column_Sweep(40);
290
        Animation_Row_Column_Sweep(40);
322
        Animation_Row_Column_Sweep(40);
291
        Animation_Cube_In_Cube(300);
323
        Animation_Cube_In_Cube(300);
292
        Animation_Cube_In_Cube(300);
324
        Animation_Cube_In_Cube(300);
293
        Animation_Cube_In_Cube(300);
325
        Animation_Cube_In_Cube(300);
294
        Animation_Double_Rotation(30);
326
        Animation_Double_Rotation(30);