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

Add BUS based IO (busio) support #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jetpax
Copy link

@jetpax jetpax commented Jan 31, 2025

This is a small addition to the existing pin macros that allows an application using libopeninv to drive bus based I/O, which may be on SPI,LIN,CAN,I2C etc., using the existing digio API eg

DigIo::lin_nslp.Toggle();

In order for this to be enabled, first create a busio.h/cpp file in your libopeninv project and include the drivers for the BUS device of interest.

A minimal example of a busio.h/cpp implementation that exposes the MCP2515 GPIO to digio is available here

Then, adding pins is done in digio_prj.h in the usual way, eg

   DIG_IO_ENTRY(gp_12Vin,  GPIOE, GPIO7,  PinMode::INPUT_FLT)   \
    BUS_IO_ENTRY(can2_term, BusType::MCP2515, 0x00, BusPinMode::OUTPUT) \

(Note that the bus type relates to the physical device that provides the interface; its just an enum that allows the code to dispatch pin commands to the right handler.)

Adding support for other devices or busses is by expanding the relevant enums

{
    MCP2515,
    TIC12400,
    DRV8912,
    UJA1023
};

// Bus IO pin modes 
enum class BusPinMode : uint8_t
{
    HI_Z,
    OUTPUT
};// pin modes 

and adding the corresponding Configure() and set()/get() handlers.

The implementation has no effect on existing I/O, but obviously this is not as fast as direct GPIO as it is over a bus.
Nonetheless, on SPI an MCP2515 output pin can be toggled in ~10us.

@jsphuebner
Copy link
Owner

Can you add the busio.* files as well?

@jetpax
Copy link
Author

jetpax commented Feb 1, 2025

I can add busio files, but then your build will be broken because they are the ones that then pull in the drivers.
IMO these files belong in the project that uses libopeninv rather than libopeninv itself, hence the include guard.
(I tried attaching them to this PR, but github bizarrely does not allow .cpp,.h files to be attached!?)

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.

2 participants