Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running macropad_keyscan.py, possible missing pin definitions in pins.c? #2

Open
stealthcopter opened this issue Oct 19, 2024 · 4 comments

Comments

@stealthcopter
Copy link

First off thanks for writing this code, I cant wait to get it all working and do some proper tinkering!

It's been a bit of a journey but I've managed to get circuit python building the firmware and installed on my RGB macropad. I've successfully run the macropad_backlight.py script and can control the LEDs nicely. However, when I try and run the macropad_keyscan.py I run into an error:

AttributeError: 'module' object has no attribute 'GP6'

I think this means that the pins have not been defined for the board in the firmware that I've installed? I may be wrong as this is all pretty new to me, so apologies if so! I checked the definition in the pins.c class and they dont seem to be defined:
https://github.com/FrameworkComputer/circuitpython/blob/fwk_keyboard/ports/raspberrypi/boards/framework_inputmodule/pins.c

Any guidance is much appreciated! Cheers

@stealthcopter
Copy link
Author

One peculiarity, while I remember it, just in case it's relevant is that it seems to have compiled and is running Circuit Python 9.0.0 but it would only work if I used the adafruit libraries for version 8, is that to be expected?

Adafruit CircuitPython 9.0.0-alpha.0-53-g029c7a0caa on 2024-10-19; Framework Laptop 16 Keyboard (CircuitPython) with rp2040
Board ID:framework_inputmodule
UID:DC634802CB433C2C

@stealthcopter
Copy link
Author

I managed to "reverse engineer" the missing pins, for anyone else who might find this comment pins.c should be:

#include "shared-bindings/board/__init__.h"

STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
    CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS

    // SLEEP#
    { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) },   // From original pins.c file (known)

    // INTB (ADC input pin from matrix.c)
    { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, // From matrix.c (defined as ADC_CH2_PIN)

    // SDB
    { MP_ROM_QSTR(MP_QSTR_GP29), MP_ROM_PTR(&pin_GPIO29) }, // From original pins.c file (known)

    // PWM for backlight control
    { MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO25) }, // From info.json and config.h (backlight control)

    // Capslock
    { MP_ROM_QSTR(MP_QSTR_GP24), MP_ROM_PTR(&pin_GPIO24) }, // From original pins.c file (known)

    // LED Controller I2C
    { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO26) },  // From original pins.c file (I2C SDA)
    { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO27) },  // From original pins.c file (I2C SCL)
    { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },  // From original pins.c file (I2C)

    // Add GP6 and GP7
    { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) },   // From your CircuitPython script and matrix.c (unused row pins)
    { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) },   // From your CircuitPython script and matrix.c (unused row pins)

    // KSO Pins (Key Scan Output) - from matrix.c (KSO0 to KSO15 are defined in matrix.c)
    { MP_ROM_QSTR(MP_QSTR_KSO0), MP_ROM_PTR(&pin_GPIO8) },  // From matrix.c (KSO0)
    { MP_ROM_QSTR(MP_QSTR_KSO1), MP_ROM_PTR(&pin_GPIO9) },  // From matrix.c (KSO1)
    { MP_ROM_QSTR(MP_QSTR_KSO2), MP_ROM_PTR(&pin_GPIO10) }, // From matrix.c (KSO2)
    { MP_ROM_QSTR(MP_QSTR_KSO3), MP_ROM_PTR(&pin_GPIO11) }, // From matrix.c (KSO3)
    { MP_ROM_QSTR(MP_QSTR_KSO4), MP_ROM_PTR(&pin_GPIO12) }, // From matrix.c (KSO4)
    { MP_ROM_QSTR(MP_QSTR_KSO5), MP_ROM_PTR(&pin_GPIO13) }, // From matrix.c (KSO5)
    { MP_ROM_QSTR(MP_QSTR_KSO6), MP_ROM_PTR(&pin_GPIO14) }, // From matrix.c (KSO6)
    { MP_ROM_QSTR(MP_QSTR_KSO7), MP_ROM_PTR(&pin_GPIO15) }, // From matrix.c (KSO7)

    // Additional KSO pins (from matrix.c)
    { MP_ROM_QSTR(MP_QSTR_KSO8), MP_ROM_PTR(&pin_GPIO21) }, // From matrix.c (KSO8)
    { MP_ROM_QSTR(MP_QSTR_KSO9), MP_ROM_PTR(&pin_GPIO20) }, // From matrix.c (KSO9)
    { MP_ROM_QSTR(MP_QSTR_KSO10), MP_ROM_PTR(&pin_GPIO19) }, // From matrix.c (KSO10)
    { MP_ROM_QSTR(MP_QSTR_KSO11), MP_ROM_PTR(&pin_GPIO18) }, // From matrix.c (KSO11)
    { MP_ROM_QSTR(MP_QSTR_KSO12), MP_ROM_PTR(&pin_GPIO17) }, // From matrix.c (KSO12)
    { MP_ROM_QSTR(MP_QSTR_KSO13), MP_ROM_PTR(&pin_GPIO16) }, // From matrix.c (KSO13)
    { MP_ROM_QSTR(MP_QSTR_KSO14), MP_ROM_PTR(&pin_GPIO23) }, // From matrix.c (KSO14)
    { MP_ROM_QSTR(MP_QSTR_KSO15), MP_ROM_PTR(&pin_GPIO22) }, // From matrix.c (KSO15)

    // MUX pins (Multiplexer control) - defined in framework.h and matrix.c
    { MP_ROM_QSTR(MP_QSTR_MUX_ENABLE), MP_ROM_PTR(&pin_GPIO4) }, // From framework.h and matrix.c (MUX_ENABLE = GP4)
    { MP_ROM_QSTR(MP_QSTR_MUX_A), MP_ROM_PTR(&pin_GPIO1) },      // From matrix.c (MUX_A = GP1)
    { MP_ROM_QSTR(MP_QSTR_MUX_B), MP_ROM_PTR(&pin_GPIO2) },      // From matrix.c (MUX_B = GP2)
    { MP_ROM_QSTR(MP_QSTR_MUX_C), MP_ROM_PTR(&pin_GPIO3) },      // From matrix.c (MUX_C = GP3)

    { MP_ROM_QSTR(MP_QSTR_BOOT_DONE), MP_ROM_PTR(&pin_GPIO5) }, // From framework.h (BOOT_DONE_GPIO GP5)

    // FIXME: Double-check other hardware mappings or schematic
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

I've also written a python per-key LED layered macro pad based off this code now! https://github.com/stealthcopter/framework-macropad-python

@tannewt
Copy link

tannewt commented Oct 23, 2024

One peculiarity, while I remember it, just in case it's relevant is that it seems to have compiled and is running Circuit Python 9.0.0 but it would only work if I used the adafruit libraries for version 8, is that to be expected?

9.0.0-alpha.0 is before we updated the MicroPython core to 9.0.0 finals version. So, it is expected to match CP 8. I'd recommend using a newer version of CircuitPython.

It would be great if you could get this finished: adafruit/circuitpython#8233

@stealthcopter
Copy link
Author

ah thanks @tannewt that makes sense, I'll have a go at moving the changes over to a newer build and giving it a test to see how it runs. I've suggested my changes over in the PR, and would love for it to be merged in, however, I'm really not sure what else needs modification before it would be suitable for merging in? If it's just those pin definitions then LGTM 😄 otherwise I'm happy to test and do some basic reverse engineering to figure stuff out but it's not my area of expertise.

@JohnAZoidberg any input here would be appreciated 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants