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

Slg46826 c type import #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dry-75
Copy link

@dry-75 dry-75 commented Feb 28, 2024

Adds C header with bits & bytes defined as per SLG46826 layout which can be used in C code but we also want to import it and use as is into Python.

Adds class SLG46826Reg with minimal use/test case.
Adds SLG header parser helper, for extracting fields & using them, dynamically.

This code does not affect any of the current greenpak library code.

Denis Ryndine added 3 commits February 28, 2024 14:19
 - Add slg46826_reg*.h from MoTeC I2C_SLG fork: this defines reg memory as blob of 256 bytes
   or details it at registers & bits level.
 - Add test.c: runtime check of bitorder in the fields.
 - Imports provided slg46826_register_t.h and allows register/field access from Python.
…bers during runtime.

 - Map slg_register_t members into runtime, as a list/array if variable names.
 - Extract bitfield width also.
@dry-75
Copy link
Author

dry-75 commented Feb 28, 2024

@zapta

We building some test scripts (console so far) where we would like to use this. We think it should benefit the greenpak library in general
Please review.

 - Lists what's needed to run Python scripts in this folder.
@zapta
Copy link
Owner

zapta commented Feb 28, 2024

Can you create an issue that explain what this feature is supposed to do?

A few question

  1. I see C codes, will this require users to have a C compiler or is it just an off line computation thing as part of the developement of this feature?

  2. If I got it correctly, you parse the bits/regs specification which is currently in .h format. How about making the parser emitting some nicely structured definition of the registers, e.g. in json? This definition can then be used in many ways, including generation of python code to access/manipulate specific registers.

  {
   register {
       name = "reg1",
       offset = 16
       num_bits = 4
       comment = "bla bla"
  }
     register {
       name = "reg2",
       offset = 20
       num_bits = 1
       comment = "bla bla"
  }

@dry-75
Copy link
Author

dry-75 commented Feb 28, 2024

  1. In sum: the C header is imported, and the C type is the directly usable -i.e., its fields/variables inside - from Python as in SLG46826Reg class. No compiler required if only that class is used.

If one wants to got a bit over, as with the parsing example provided, one may need to have C GCC compiler, as per line in that script, but it could be optional if pre-processed header used. Idea was to provide it as options to be available.

For us, we just want some test scripts which would use the C type shared with C code base, and we want to use it in the Python with greenpak lib to do some external testing which would involve interacting with the Gp devices. Displaying live values is an example.

I'm cleaning up some script which would use those modules in this PR, but they all Linux & SMBus layer based, unsure how much you would be able to try them.

  1. Yes you may do it, but is outside of scope at the moment for this work. If you or anyone would like to do something as you describe, it would be great. We just have no need or didn't think of it, at this day.

As you saw, the parsing already enables us from python get all the fields/regs from file into list, initialize runtime SLG class instance with raw bytes, and then access those fields vales using the list of names extracted.

At the moment we would like to use just that, to build simple test scripts. And take further as needed.

@zapta
Copy link
Owner

zapta commented Feb 28, 2024 via email

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