🎄⛄❄️🎁 It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! 🎄⛄❄️🎁
0

Retrogame Configuration on Compute Module GPIO Bank 2
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

Retrogame Configuration on Compute Module GPIO Bank 2

by Celtut on Wed Nov 06, 2019 1:56 pm

Hi there,

I am using Raspberry Pi Compute Module 3 for my setup and nearly all the pins are already occupied in GPIO bank 1 and bank 2 (cannot move these pins). I need to use GPIO 40, 41, 42 and 43 as keyboard inputs using retrogame but GPIO pins between 32 and 45 cannot be configured. Retrogame does not recognise these pins as keyboard inputs.

Can you suggest me how to edit the source code retrogame.c to allow all GPIO pins to be configured as keyboard inputs? (Currently, pins until GPIO 31 can be configured.)

Looking forward to hearing your responses.

Thanks in advance.

Celtut
 
Posts: 5
Joined: Wed Nov 06, 2019 12:38 pm

Re: Retrogame Configuration on Compute Module GPIO Bank 2

by pburgess on Fri Nov 08, 2019 2:26 pm

The retrogame code is not easily modified beyond 32 GPIO inputs. Would require an inordinate amount of rewriting and testing, and TBH we really really want that project to just die in favor of using simple Python-based code. It’s a product of another era when Pi’s were much more speed- and RAM-constrained and is horrible to maintain.

If you require GPIO inputs above #31 I might recommend:
  • Use an MCP23017 I2C port expander, which retrogame does support.
  • Write something purpose-built in Python, which will be a ton simpler than trying to comprehend the horrible retrogame source. A couple of .py files alongside retrogame show how to generate keypresses, though these are both designed for port expanders and would require some reworking for raw GPIO. What I don’t know is whether Python GPIO libraries such as GPIO Zero or Blinka are faced with the same pin number issue, and I don’t have a Compute Module to test with.
  • Seems like the Linux gpio_keys device tree overlay is the lowest-level way of doing this sort of thing but I have zero experience with it. But if it works, would require no coding, just a lot of configurating.

pburgess
 
Posts: 4041
Joined: Sun Oct 26, 2008 2:29 am

Re: Retrogame Configuration on Compute Module GPIO Bank 2

by Celtut on Fri Nov 08, 2019 8:35 pm

Many thanks for your answer.

I just realised that the software for Joy Bonnet recognises GPIO 40, 41, 42 and 43. However, it works extremely slow and inconsistent, as my PCB design does not have a joystick, thus not have a ADS1015. So there is nothing connected to I2C pins. I think this might cause delay and consistence problem in button presses (each button press is registered after 2 - 3 seconds, than the software reacts as if they were pressed more than once).

Due to the DPI display I am using for my project, I need to disable I2C. When I2C is disabled, the software for Joy Bonnet does not work at all, none of the GPIO buttons are recognised.

Is there a method of eliminating I2C part of the software? Joy Bonnet software without the I2C seems like the solution to my problem.

I would highly appreciate your suggestions and help on this issue.

Celtut
 
Posts: 5
Joined: Wed Nov 06, 2019 12:38 pm

Re: Retrogame Configuration on Compute Module GPIO Bank 2

by pburgess on Fri Nov 08, 2019 8:54 pm

Oh hey, look at that, I didn’t realize the joyBonnet.py code was that close…it’s using an I2C ADC, not a port expander, and all the buttons are normal GPIOs. Great…

The 'while True' loop at the end of the code can simply be reduced to:
Code: Select all | TOGGLE FULL SIZE
while True:
  time.sleep(1.0)


I think it’s then possible to delete everything between:
Code: Select all | TOGGLE FULL SIZE
###################################### ADS1015 microdriver #################################

and:
Code: Select all | TOGGLE FULL SIZE
######################## main program


Then modify the BUTTONS[] array and KEYS[] dict at the top with the GPIO-to-key connections you want. Everything is then callback-operated, hence the seemingly do-nothing main loop. Should be super efficient then.

pburgess
 
Posts: 4041
Joined: Sun Oct 26, 2008 2:29 am

Re: Retrogame Configuration on Compute Module GPIO Bank 2

by Celtut on Fri Nov 08, 2019 9:33 pm

Great! Everything works perfect.

Thank you so much for the help!

Celtut
 
Posts: 5
Joined: Wed Nov 06, 2019 12:38 pm

Re: Retrogame Configuration on Compute Module GPIO Bank 2

by Celtut on Fri Nov 08, 2019 9:38 pm

Another problem:

When switching back to DPI display (disabling I2C), none of the buttons are recognised. Is there a method of overcoming this? Disabling I2C seems to prevent Joy Bonnet software to work completely.

Celtut
 
Posts: 5
Joined: Wed Nov 06, 2019 12:38 pm

Re: Retrogame Configuration on Compute Module GPIO Bank 2

by pburgess on Fri Nov 08, 2019 10:29 pm

Try deleting these chunks:
Code: Select all | TOGGLE FULL SIZE
try:
     from smbus import SMBus
except ImportError:
    exit("This library requires the smbus module\nInstall with: sudo pip install smbus")

and:
Code: Select all | TOGGLE FULL SIZE
bus     = SMBus(1)

pburgess
 
Posts: 4041
Joined: Sun Oct 26, 2008 2:29 am

Re: Retrogame Configuration on Compute Module GPIO Bank 2

by Celtut on Sat Nov 09, 2019 8:47 am

Yes! That solved the issue.

Many thanks for your great help!

Celtut
 
Posts: 5
Joined: Wed Nov 06, 2019 12:38 pm

Please be positive and constructive with your questions and comments.