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

Added definition for an upcoming Pimoroni motor driver board #6314

Merged
merged 4 commits into from
Apr 26, 2022

Conversation

ZodiusInfuser
Copy link

Let me know if you spot any issues. Hoping to launch at the end of the week.

Also I included a NEOPIXEL alias as this was highlighted as missing on Servo 2040 (#6307)

I did also consider including constant tuples for the motor and encoder pairs, as I recently discovered they could be done in MicroPython, but this seemed a bit experimental to include in these CircuitPython definitions.

const mp_rom_obj_tuple_t motor2040_encoderA_pins = {
    {&mp_type_tuple}, 2, { MP_ROM_INT(1), MP_ROM_INT(0) },
};

STATIC const mp_rom_map_elem_t motor2040_globals_table[] = {
    { MP_ROM_QSTR(MP_QSTR_MOTOR_A), MP_ROM_PTR(&motor2040_motorA_pins) },
}

@dhalbert
Copy link
Collaborator

I did also consider including constant tuples for the motor and encoder pairs

You could do that, as you did here: #6208 (comment). The main issue is to make sure that if a static object has pointers to heap objects, that those pointers are included in garbage collection.

@ZodiusInfuser
Copy link
Author

Thanks. I'm a bit pushed for time at the moment, so if I do add those tuples it's unlikely to be for this PR

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine! I had a query/suggestion.

Comment on lines +62 to +70
{ MP_ROM_QSTR(MP_QSTR_CURRENT_SENSE_A_ADDR), MP_ROM_INT(0b000) },
{ MP_ROM_QSTR(MP_QSTR_CURRENT_SENSE_B_ADDR), MP_ROM_INT(0b001) },
{ MP_ROM_QSTR(MP_QSTR_CURRENT_SENSE_C_ADDR), MP_ROM_INT(0b010) },
{ MP_ROM_QSTR(MP_QSTR_CURRENT_SENSE_D_ADDR), MP_ROM_INT(0b011) },
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_SENSE_ADDR), MP_ROM_INT(0b100) },
{ MP_ROM_QSTR(MP_QSTR_FAULT_SENSE_ADDR), MP_ROM_INT(0b101) },
{ MP_ROM_QSTR(MP_QSTR_SENSOR_1_ADDR), MP_ROM_INT(0b110) },
{ MP_ROM_QSTR(MP_QSTR_SENSOR_2_ADDR), MP_ROM_INT(0b111) },
{ MP_ROM_QSTR(MP_QSTR_NUM_SENSORS), MP_ROM_INT(2) },
Copy link
Collaborator

@dhalbert dhalbert Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is going to be a library you (almost) always use with this board, you might consider putting constants like these and NUM_MOTORS in the library rather than casting them in stone.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. There's no specific library for this board at the moment, I was just going to use the existing motor,encoder,neopixel etc libraries, as my time is stretched pretty thin with supporting C++ and Micropython. Something to consider for the future though.

@jepler
Copy link
Member

jepler commented Apr 26, 2022

For your reference, another case of putting a tuple of things in the board module, in this case a sequence of pins defining parallel bus:

STATIC const mp_rom_obj_tuple_t camera_data_tuple = {
    {&mp_type_tuple},
    8,
    {
        MP_ROM_PTR(&pin_GPIO13),
        MP_ROM_PTR(&pin_GPIO15),
        MP_ROM_PTR(&pin_GPIO16),
        MP_ROM_PTR(&pin_GPIO14),
        MP_ROM_PTR(&pin_GPIO12),
        MP_ROM_PTR(&pin_GPIO10),
        MP_ROM_PTR(&pin_GPIO9),
        MP_ROM_PTR(&pin_GPIO7),
    }
};
...
    { MP_ROM_QSTR(MP_QSTR_CAMERA_DATA), MP_ROM_PTR(&camera_data_tuple) },
...

@dhalbert dhalbert merged commit bf2fd53 into adafruit:main Apr 26, 2022
@ZodiusInfuser
Copy link
Author

Thanks for that @jepler. Which file is that in, for reference?

@jepler
Copy link
Member

jepler commented Apr 26, 2022

oops meant to leave the reference in the comment:

STATIC const mp_rom_obj_tuple_t camera_data_tuple = {

jepler pushed a commit to jepler/circuitpython that referenced this pull request Nov 15, 2022
Follow up from a similar fix in 426785a

Fixes issue adafruit#6314.

Signed-off-by: Damien George <damien@micropython.org>
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

Successfully merging this pull request may close these issues.

3 participants