I'm fiddling with micropython and creating a driver for the PCA9557. You can have up to 8 of these devices on a single I2C bus. I have looked at servo and accel as examples to roll my own.
So far I can see my device appear in the dir(pyb), however I'm not done yet with passing and getting the right parameters.
Is there somebody who has a skeleton or at least some more explanation on the mechanism with the MP_DEFINE_CONST_FUN_OBJ... variations?
Is it possible to have the names like "inputreg" (0), "outputreg" (1), "polarity"(2) and "config"(3) as parameter and as such known to the dictionary of micropython?
Basically what I try to do
Code: Select all
device = pyb.PCA9557(1..8)
device.init()
device.read(register=0..3)
device.write(register=0..3, value=0..255)
device.deinit()
Code: Select all
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&pyb_pca9557_read_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&pyb_pca9557_write_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_pca9557_init_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&pyb_pca9557_deinit_obj },
Code: Select all
STATIC mp_obj_t pyb_pca9557_write(mp_obj_t reg, mp_obj_t val) {
...
} MP_DEFINE_CONST_FUN_OBJ_2(pyb_pca9557_write_obj, pyb_pca9557_write);
Code: Select all
STATIC mp_obj_t pyb_pca9557_read(mp_obj_t value) {
...
} MP_DEFINE_CONST_FUN_OBJ_1(pyb_pca9557_read_obj, pyb_pca9557_read);
Any pointers...
R