dupontgu / retro-ipod-spotify-client

The software that powers the sPot: a 4th generation "Click Wheel" iPod with a full Spotify client.
Apache License 2.0
892 stars 90 forks source link

(Request) Help Porting Clickwheel Code to PocketBeagle #35

Open ntfrueh opened 3 years ago

ntfrueh commented 3 years ago

Hey everyone,

I was holding off on posting here for a while, but I've banged my head against the wall for so long that I need a bit of guidance.

Like Guy, I had been working on a similar project since last summer, but decided to try to switch over to the PocketBeagle instead of a Raspberry Pi (mainly due to it's alleged support for very low power sleep modes).

Getting things like Wi-Fi/Bluetooth/SPI displays working on this was a battle and a half, but I managed to work through them. One thing I'm still stuck on, however, is the clickwheel code.

From what I can tell, he's got a few callback functions triggered to run whenever either the clock or data line changes, then does a bit of bit-banging. What I'm struggling with is the switch to the IOBB library to get similar behavior up and running on a PocketBeagle.

// Nate added these for PocketBeagle to make hack-y callback functions
int CURRENTCLOCKSTATE = 0;
int CURRENTDATASTATE = 0;
int PASTCLOCKSTATE = 0;
int PASTDATASTATE = 0;

iolib_init();

iolib_setdir(1, 28, DigitalIn);  // Set clock pin GPIO13 (P1,28) as input
iolib_setdir(1, 26, DigitalIn);  // Set data pin GPIO12 (P1,26) as input

// Back to Guy's code
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) { 
    perror("socket creation failed"); 
    exit(EXIT_FAILURE); 
} 

memset(&servaddr, 0, sizeof(servaddr)); 

servaddr.sin_family = AF_INET; 
servaddr.sin_port = htons(PORT); 
servaddr.sin_addr.s_addr = INADDR_ANY;

// I also removed the pulses/haptic code, as I wasn't planning on integrating that

while(running) {

    CURRENTCLOCKSTATE = (is_low(1, 28)) ? 0 : 1;
    CURRENTDATASTATE = (is_low(1, 26)) ? 0 : 1;

    //printf("Did clock state change?");
    if(CURRENTCLOCKSTATE != PASTCLOCKSTATE) {
        printf("Clock state changed!\n");
        onClockEdge(28, CURRENTCLOCKSTATE);  // Runs his original functions
        PASTCLOCKSTATE = CURRENTCLOCKSTATE;
    }

    //printf("Did data state change?");
    if(CURRENTDATASTATE != PASTDATASTATE) {
        printf("Data state changed!\n");
        onDataEdge(26, CURRENTDATASTATE);  // Runs his original functions
        PASTDATASTATE = CURRENTDATASTATE;
    }
}

The idea is that I'm creating my own callback functions if the current data/clock pin state changes compared to the previous one. However, it perpetually reads the state of those pins as 0, which makes me think I'm just not polling correctly.

I'm not a programmer by trade (especially not this low level of programming), and unfortunately I've exhausted my list of resources for i2c reading/bit-banging.

tomaculum commented 3 years ago

I do not know anything about the IOBB library or the PocketBeagle but I think you did not "translate" those two lines of code:

https://github.com/dupontgu/retro-ipod-spotify-client/blob/dff6b1d9abb40a61fc67074ab1bb50ee0adf10ba/clickwheel/click.c#L194

https://github.com/dupontgu/retro-ipod-spotify-client/blob/dff6b1d9abb40a61fc67074ab1bb50ee0adf10ba/clickwheel/click.c#L195