Skip to content

Commit f382b41

Browse files
authored
Merge pull request #11 from pyroesp/fix_switched_pins
Fixed switched data and cmd
2 parents ad80474 + 944ed7a commit f382b41

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

pic16f18325/main.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
/* Controller ID */
6969
#define ID_DIG_CTRL 0x5A41 // digital
70+
#define ID_ANP_CTRL 0x5A73 // analog/pad
7071
#define ID_ANS_CTRL 0x5A53 // analog/stick
7172
#define ID_GUNCON_CTRL 0x5A63 // light gun
7273

@@ -129,6 +130,7 @@ void clear_buff(uint8_t *p, uint8_t s);
129130
void __delay_s(uint8_t s);
130131

131132
#ifdef DEBUG
133+
void UART_init(void);
132134
void UART_sendByte(uint8_t c);
133135
void UART_print(uint8_t *str);
134136
void UART_printHex(uint8_t b);
@@ -139,14 +141,18 @@ void UART_printHex(uint8_t b);
139141
void __interrupt() _spi_int(void) {
140142
// SPI1 interrupt
141143
if (PIR1bits.SSP1IF){
142-
cmd.buff[cmd_cnt] = SSP1BUF;
143-
cmd_cnt++;
144+
if (data_cnt < PS1_CTRL_BUFF_SIZE){
145+
data.buff[data_cnt] = SSP1BUF;
146+
data_cnt++;
147+
}
144148
PIR1bits.SSP1IF = 0; // clear SPI1 flag
145149
}
146150
// SPI2 interrupt
147151
if (PIR2bits.SSP2IF){
148-
data.buff[data_cnt] = SSP2BUF;
149-
data_cnt++;
152+
if (cmd_cnt < PS1_CTRL_BUFF_SIZE){
153+
cmd.buff[cmd_cnt] = SSP2BUF;
154+
cmd_cnt++;
155+
}
150156
PIR2bits.SSP2IF = 0; // clear SPI2 flag
151157
}
152158
}
@@ -200,6 +206,7 @@ void main(void){
200206
// DEBUG
201207
#ifdef DEBUG
202208
UART_init();
209+
UART_print((uint8_t*)"PlayStation 1 mod:\n\r");
203210
#endif
204211

205212
// SETUP variables and arrays
@@ -260,6 +267,7 @@ void main(void){
260267
break;
261268
case ID_DIG_CTRL:
262269
case ID_ANS_CTRL:
270+
case ID_ANP_CTRL:
263271
key_combo = KEY_COMBO_CTRL;
264272
break;
265273
default:
@@ -320,17 +328,18 @@ void __delay_s(uint8_t s){
320328
__delay_ms(1000);
321329
}
322330

331+
#ifdef DEBUG
323332
/**********************************************************/
324333
/* UART Debug Functions */
325334

326-
/*Initialize UART with TX on output RC3 */
335+
/* Initialize UART with TX on output RC3 */
327336
void UART_init(void){
328337
// SETUP UART
329338
ANSELCbits.ANSC3 = 0; // TX set to digital I/O
330339
LATCbits.LATC3 = 0; // set output 0
331340
TRISCbits.TRISC3 = 0; // TX set to output
332341
RC3PPSbits.RC3PPS = 0x14; // TX = RC3
333-
342+
334343
SP1BRGL = 51; // 9615 baud
335344
SP1BRGH = 0; // 9615 baud
336345
// BRGH = 1 ; SPBRG = 16 -> 117.64k baud
@@ -368,4 +377,5 @@ void UART_printHex(uint8_t b){
368377
UART_print((uint8_t*)"0x");
369378
UART_sendByte(high_nibble >= 10 ? (high_nibble - 10 + 'A') : high_nibble + '0');
370379
UART_sendByte(low_nibble >= 10 ? (low_nibble - 10 + 'A') : low_nibble + '0');
371-
}
380+
}
381+
#endif

0 commit comments

Comments
 (0)