Layering drivers
Posted: Mon Jan 11, 2016 5:36 pm
Hello.
I'm new to ChibiOS, but not to programming in general, or even real-time µC programming which is where I cut my teeth.
Now, I'd like to develop a driver for the (now defunct) Apple Desktop Bus, I'm developing a hardware dongle for the older Wacom Intuos tablets. As a stand-alone application, I think I can probably manage it using the (E)ICU and PWM drivers , but I'd quite like to pull the ADB side out into a separate driver that I can use in other applications.
The problem is that, from within (for example) an ICU callback, I only have access to the ICU driver object. For example, I might write something like this:
But this means I have variables `state`, `bit`, `data` and `byte_count` as file-local variables, rather than being able to wrap them into an ADB Codec driver object, which is where they should more reasonably live (they are ADB Codec state).
I think what I'm after is the ability to pass some sort of arbitrary "context" object into callbacks instead of the "driver" object that's being passed in now. That way my callbacks could get an ADBCodecDriver object, which contains the relevant ICUDriver object.
Does that make sense?
Simon
I'm new to ChibiOS, but not to programming in general, or even real-time µC programming which is where I cut my teeth.
Now, I'd like to develop a driver for the (now defunct) Apple Desktop Bus, I'm developing a hardware dongle for the older Wacom Intuos tablets. As a stand-alone application, I think I can probably manage it using the (E)ICU and PWM drivers , but I'd quite like to pull the ADB side out into a separate driver that I can use in other applications.
The problem is that, from within (for example) an ICU callback, I only have access to the ICU driver object. For example, I might write something like this:
Code: Select all
void falling_edge_cb (ICUDriver * icu) {
switch (state) {
case WAIT_START:
state = IN_START;
break;
case IN_START:
state = IN_DATA;
bit = 7;
break;
case MAYBE_STOP:
bit = 7;
byte_count++;
state = IN_DATA;
/* deliberately fall through */
case IN_DATA:
data = (data << 1);
if (low_time < threshold_time) data |= 1;
if (bit == 0) {
state = MAYBE_STOP;
} else {
bit--;
}
break;
default:
/* error */
state = ERROR;
break;
}
}But this means I have variables `state`, `bit`, `data` and `byte_count` as file-local variables, rather than being able to wrap them into an ADB Codec driver object, which is where they should more reasonably live (they are ADB Codec state).
I think what I'm after is the ability to pass some sort of arbitrary "context" object into callbacks instead of the "driver" object that's being passed in now. That way my callbacks could get an ADBCodecDriver object, which contains the relevant ICUDriver object.
Does that make sense?
Simon