GPIO Programming:

SNES Controller

Computing Machinery II Tutorial:

Week of April fo.Ols!!

Review

  • We're now all experts in reading and writing C programs to control GPIO pins (gpio.h) and sending information to our host computer terminal (uart.h).

Assignment 4

Today:

 

  • Identify SNES Pins

 

  • Analyse 07_SNESController Code

    • Decode outputs
    • get_SNES()
      • Comprehend controller mechanism and associated communication protocol in code

SNES Pins:

Our hardware-software interface

Program output:

  • We know that puthex(NUMBER); prints any number in it's hexademical representation
  • There are 12 buttons to represent as numbers...
  • Knowing nothing about how the controller works you might think that each button should be assigned a consecutive number starting from 1. Is this what's going on?

Program output:

  • The controller is built to have it's state sampled and the controller designers chose to represent this pressed/not-pressed state of all buttons with a single 16 bit number.
    • This way we can recognise combinations of buttons as distinct from a sequence of button presses, regardless of how close in time they might be.
    • This also reduces controller CPU communication costs
  • If   L   is 0x400 and  A  is 0x100, what is the hexidecimal representation of this button press combination?
  • What button combination makes this hexadecimal number?
\cdots 00 ~ \overbrace{0001} ~ \overbrace{0101} ~ \overbrace{0011}
0x00000153

Can every button press combination be represented by a unique hexidecimal number?

Important parts of code

  • includes
    • "systimer.h" for microsecond_delay()
  • while loop
    • get_SNES() returns that 16 bit number from the controller
  • get_SNES() function definition describes the serial communication protocol
    1. pulse Latch pin
    2. wait
    3. trigger clock pin falling edge
    4. read data pin
    5. wait
    6. trigger clock pin rising edge
    7. goto step 2 (15 times)

Two Easy Extensions For You:

  1. Print button combinations as useful strings instead of Hex
  2. Catch special button combos with additional print out
  3. Poll controller state ~ 60 times per second.

Pi_5

By pathomas

Pi_5

  • 595