Skip to content

Commit

Permalink
Change HW4 to use WS ADAPTER V2
Browse files Browse the repository at this point in the history
  • Loading branch information
splash5 committed Feb 26, 2022
1 parent 3116321 commit 9732c4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Cart_Reader/WS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
#include "options.h"
#ifdef enable_WS

#ifdef ws_adapter_v2
#define WS_CLK_BIT 5 // USE PE5 as CLK
#else
#define WS_CLK_BIT 3 // USE PE3 as CLK
#endif

/******************************************
Menu
*****************************************/
Expand Down Expand Up @@ -61,8 +67,8 @@ void setup_WS()
PORTH |= ((1 << 0) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6));

// CLK outputs LOW
DDRE |= (1 << 3);
PORTE &= ~(1 << 3);
DDRE |= (1 << WS_CLK_BIT);
PORTE &= ~(1 << WS_CLK_BIT);

// IO? as input with internal pull-up enabled
DDRE &= ~(1 << 4);
Expand Down Expand Up @@ -1214,10 +1220,10 @@ void generateEepromInstruction_WS(uint8_t *instruction, uint8_t opcode, uint16_t
boolean unlockMMC2003_WS()
{
// initialize all control pin state
// RST(PH0) and CLK(PE3) to LOW
// RST(PH0) and CLK(PE3or5) to LOW
// CART(PH3) MMC(PH4) WE(PH5) OE(PH6) to HIGH
PORTH &= ~(1 << 0);
PORTE &= ~(1 << 3);
PORTE &= ~(1 << WS_CLK_BIT);
PORTH |= ((1 << 3) | (1 << 4) | (1 << 5) | (1 << 6));

// switch RST(PH0) to HIGH
Expand Down Expand Up @@ -1256,7 +1262,7 @@ boolean unlockMMC2003_WS()
return false;
}

// doing a L->H on CLK(PE3) pin
// doing a L->H on CLK pin
void pulseCLK_WS(uint8_t count)
{
register uint8_t tic;
Expand All @@ -1267,20 +1273,20 @@ void pulseCLK_WS(uint8_t count)
"cpi %[count], 0\n\t"
"breq L3_%=\n\t"
"dec %[count]\n\t"
"cbi %[porte], 3\n\t"
"cbi %[porte], %[ws_clk_bit]\n\t"
"ldi %[tic], 6\n\t"
"L1_%=:\n\t"
"dec %[tic]\n\t"
"brne L1_%=\n\t"
"sbi %[porte], 3\n\t"
"sbi %[porte], %[ws_clk_bit]\n\t"
"ldi %[tic], 5\n\t"
"L2_%=:\n\t"
"dec %[tic]\n\t"
"brne L2_%=\n\t"
"rjmp L0_%=\n\t"
"L3_%=:\n\t"
: [tic] "=a" (tic)
: [count] "a" (count), [porte] "I" (_SFR_IO_ADDR(PORTE))
: [count] "a" (count), [porte] "I" (_SFR_IO_ADDR(PORTE)), [ws_clk_bit] "I" (WS_CLK_BIT)
);
}

Expand Down
1 change: 1 addition & 0 deletions Cart_Reader/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define enable_rotary
#define clockgen_installed
#define fastcrc
#define ws_adapter_v2
#endif

#if (defined(HW2) || defined(HW3))
Expand Down

0 comments on commit 9732c4a

Please sign in to comment.