Page 1 of 3
Ext driver example
Posted: Mon Jun 04, 2012 11:27 am
by Tectu
Hello Folks,
Could someone provide a very bare example, how to use the EXT driver? I didn't had any problems at all with other drivers like SPI, PAL, ADC etc, when I read the documentation. But I really don't have any clue how to use the EXT driver to use external interrupts, for example for a touchpad.
Thanks
~ Tectu
Re: Ext driver example
Posted: Mon Jun 04, 2012 11:50 am
by Giovanni
Hi,
There are examples under ./testhal.
Giovanni
Re: Ext driver example
Posted: Mon Jun 04, 2012 11:53 am
by Tectu
ooh! Thats pretty useful.
Thanks for the tip, sir!
Re: Ext driver example
Posted: Mon Jun 04, 2012 12:14 pm
by Tectu
I've one more question:
How about arguments etc? Is it possible to pass a pointer to a big buffer to the callback function? I'd need a buffer of 2048 bytes size there. I guess it's not that good when I write unsigned char buffer[2048]; into the callback function.
How to make this work the right way?
~ Tectu
Re: Ext driver example
Posted: Mon Jun 04, 2012 12:43 pm
by Giovanni
Hi,
In general large buffers should never be automatic variables. If you make it static you don't need to pass a pointer, you already know where it is.
Giovanni
Re: Ext driver example
Posted: Mon Jun 04, 2012 3:54 pm
by Tectu
Can I go with another question?
I use the EXT driver to fire an interrupt when my touchpad controller puts PEN_IRQ low. This works great. I can toggle an LED by pressing the touchpad

Now, of course, I want to use the ISR to read out the X and Y coordinates. Now: When I make:
Code: Select all
static void touchIRQ(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
lcdDrawPixel(tpReadY(), tpReadY(), Green);
}
I can compile, and load the .elf. When I run, nothing works

It just hangs there and not even anything from the main gets executed. When I comment the lcdDrawPixel line out, it works. I could figure out that the problem is the calling of tpReadX() and tpReadY() causes this error.
This is my tpReadX():
Code: Select all
static uint16_t tpReadRealX(void) {
uint32_t results = 0;
uint16_t i, x;
for(i=0; i<CONVERSIONS; i++) {
readX();
results += readX();
}
// get from 0 to 2048 to 0 to LCD "length"
x = (((lcdGetHeight()-1) * (results/CONVERSIONS)) / 2048);
return x;
}
uint16_t tpReadX(void) {
// calibrate
return cal.xm * tpReadRealX() + cal.xn;
}
I also tried:
Code: Select all
static void touchIRQ(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
lcdDrawPixel(tpReadY(), tpReadY(), Green);
}
void foo(void) {
uint16_t x, y;
x = tpReadX();
y = tpReadY();
}
This gave the same result.
Any ideas?
Re: Ext driver example
Posted: Mon Jun 04, 2012 4:24 pm
by Giovanni
Are you OK with using complex graphic primitives from ISRs?
BTW, moving to the support forum in order to reduce noise in the development forum.
Giovanni
Re: Ext driver example
Posted: Mon Jun 04, 2012 5:06 pm
by Tectu
Thanks for the moving, I'll post similar question to there from now on (if i am allowed to ask more

)
What would be the propper way to do that then? I never worked with an RTOS. I come from the AVR side.
I guess I can use external interrupts from the PEN_IRQ signal from the touchpad controller somehow to read out the actual coordinates?
~ Tectu
Re: Ext driver example
Posted: Mon Jun 04, 2012 6:06 pm
by Giovanni
You are welcome to ask questions

If you need to perform an "heavy" operation in response of an external event (the callback) usually you wake up a thread to do the work out of ISR context.
There is an article in the documentation about various ways to wakeup a thread:
http://www.chibios.org/dokuwiki/doku.ph ... tos:wakeupthe right one depends on what you want to achieve. Additionally you may use a mailbox if you need to send messages from the ISR to the thread.
Giovanni
Re: Ext driver example
Posted: Mon Jun 04, 2012 6:36 pm
by Tectu
Giovanni wrote:You are welcome to ask questions

That's nice to hear. I always try to not ask too stupid questions

Thanks for the link. This looks like what I need. I did the following:
Code: Select all
static Thread *tpThread = NULL;
void mythread(void *p) {
while (TRUE) {
palTogglePad(GPIOD, GPIOD_LED2);
chEvtWaitAny((eventmask_t)1);
}
}
static void touchIRQ(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
chSysLockFromIsr();
chEvtSignalFlagsI(tpThread, (eventmask_t)1);
chSysUnlockFromIsr()
}
When I compile, load and run, the same behaviour appears again: Nothing works, It hangs as before I even get to the change to calibrate the screen. I get into _unhandled_exception.
Any ideas?
I don't think that it is some issue with my touchpad code, because it works great without the IRQ stuff.
~ Tectu