public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Problem reading buttons on AT91sam7s-ek
@ 2007-10-01 12:27 Rasmus Stougaard
  2007-10-01 14:28 ` Andrew Lunn
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus Stougaard @ 2007-10-01 12:27 UTC (permalink / raw)
  To: ecos-discuss

Hi

I am trying to read the state of the buttons on a AT91sam7s-ek
evaluation kit from atmel.

I figure that something like:

    cyg_uint32 value;
    HAL_ARM_AT91_GPIO_CFG_DIRECTION(AT91_GPIO_PA20, AT91_PIN_IN);
    HAL_ARM_AT91_GPIO_CFG_PULLUP(AT91_GPIO_PA20, AT91_PIN_PULLUP_ENABLE);
    HAL_ARM_AT91_GPIO_GET(AT91_GPIO_PA20, value);
    trace(" AT91_GPIO_PA20 %d\n", value);

Should configure the pin for input and print the current state of the
of the pin.

However, the state returned in value is always zero, so I must be
doing something wrong.

Any hints much apreciated.

Regards
Rasmus Stougaard

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] Problem reading buttons on AT91sam7s-ek
  2007-10-01 12:27 [ECOS] Problem reading buttons on AT91sam7s-ek Rasmus Stougaard
@ 2007-10-01 14:28 ` Andrew Lunn
  2007-10-02 11:40   ` Rasmus Stougaard
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Lunn @ 2007-10-01 14:28 UTC (permalink / raw)
  To: Rasmus Stougaard; +Cc: ecos-discuss

On Mon, Oct 01, 2007 at 02:27:32PM +0200, Rasmus Stougaard wrote:
> Hi
> 
> I am trying to read the state of the buttons on a AT91sam7s-ek
> evaluation kit from atmel.
> 
> I figure that something like:
> 
>     cyg_uint32 value;
>     HAL_ARM_AT91_GPIO_CFG_DIRECTION(AT91_GPIO_PA20, AT91_PIN_IN);
>     HAL_ARM_AT91_GPIO_CFG_PULLUP(AT91_GPIO_PA20, AT91_PIN_PULLUP_ENABLE);
>     HAL_ARM_AT91_GPIO_GET(AT91_GPIO_PA20, value);
>     trace(" AT91_GPIO_PA20 %d\n", value);
> 
> Should configure the pin for input and print the current state of the
> of the pin.

In general that looks O.K. Have you tried the other 3 switches?

One idea i have. Is the clock to the GPIO device enabled? Check bit
AT91_PMC_PCER_PIOA in AT91_PMC_PCER. Without a clock you can do
output. But to do input you need the clock enabled.

  Andrew
 

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] Problem reading buttons on AT91sam7s-ek
  2007-10-01 14:28 ` Andrew Lunn
@ 2007-10-02 11:40   ` Rasmus Stougaard
  2007-10-02 11:47     ` Andrew Lunn
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus Stougaard @ 2007-10-02 11:40 UTC (permalink / raw)
  To: Rasmus Stougaard, ecos-discuss

On 10/1/07, Andrew Lunn <andrew@lunn.ch> wrote:
> On Mon, Oct 01, 2007 at 02:27:32PM +0200, Rasmus Stougaard wrote:
> > Hi
> >
> > I am trying to read the state of the buttons on a AT91sam7s-ek
> > evaluation kit from atmel.
> >
> > I figure that something like:
> >
> >     cyg_uint32 value;
> >     HAL_ARM_AT91_GPIO_CFG_DIRECTION(AT91_GPIO_PA20, AT91_PIN_IN);
> >     HAL_ARM_AT91_GPIO_CFG_PULLUP(AT91_GPIO_PA20, AT91_PIN_PULLUP_ENABLE);
> >     HAL_ARM_AT91_GPIO_GET(AT91_GPIO_PA20, value);
> >     trace(" AT91_GPIO_PA20 %d\n", value);
> >
> > Should configure the pin for input and print the current state of the
> > of the pin.
>
> In general that looks O.K. Have you tried the other 3 switches?
>
> One idea i have. Is the clock to the GPIO device enabled? Check bit
> AT91_PMC_PCER_PIOA in AT91_PMC_PCER. Without a clock you can do
> output. But to do input you need the clock enabled.
>
>   Andrew
>
>

Hi Andrew

Thanks a lot, that solved it :-)

Here is my code for later reference (probably to myself)

int get_pin_state(int gpio_pin)
{
  int value;
  // Enable the clock to the GPIO (enable input sampling)
  HAL_WRITE_UINT32(AT91_PMC + AT91_PMC_PCER, AT91_PMC_PCER_PIOA);

  HAL_ARM_AT91_GPIO_CFG_DIRECTION(gpio_pin, AT91_PIN_IN);
  HAL_ARM_AT91_GPIO_GET(gpio_pin, value);

  return value;
}

Cheers
Rasmus

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] Problem reading buttons on AT91sam7s-ek
  2007-10-02 11:40   ` Rasmus Stougaard
@ 2007-10-02 11:47     ` Andrew Lunn
  2007-10-02 13:04       ` Rasmus Stougaard
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Lunn @ 2007-10-02 11:47 UTC (permalink / raw)
  To: Rasmus Stougaard; +Cc: ecos-discuss

> int get_pin_state(int gpio_pin)
> {
>   int value;
>   // Enable the clock to the GPIO (enable input sampling)
>   HAL_WRITE_UINT32(AT91_PMC + AT91_PMC_PCER, AT91_PMC_PCER_PIOA);

You only need to enable the clock once. You could move this outside of
the read function.

Maybe i should add a macro to var_io.h to enable/disable the clock?

      Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] Problem reading buttons on AT91sam7s-ek
  2007-10-02 11:47     ` Andrew Lunn
@ 2007-10-02 13:04       ` Rasmus Stougaard
  2007-10-02 13:40         ` Andrew Lunn
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus Stougaard @ 2007-10-02 13:04 UTC (permalink / raw)
  To: Rasmus Stougaard, ecos-discuss

> >   // Enable the clock to the GPIO (enable input sampling)
> >   HAL_WRITE_UINT32(AT91_PMC + AT91_PMC_PCER, AT91_PMC_PCER_PIOA);
>
> You only need to enable the clock once. You could move this outside of
> the read function.

Ok thanks again, will do that. I also plan to convert my example to a
macro, to save the overhead of making the function call.

>
> Maybe i should add a macro to var_io.h to enable/disable the clock?

That might be a good idea, or add a comment to
HAL_ARM_AT91_GPIO_CFG_DIRECTION
and
HAL_ARM_AT91_GPIO_GET
stating that the clock must be enabled to receive inputs. At least it
was not obvios to me, and others might benefit too :-)

By the way can you point me to an example/documentation of how to use
HAL_ARM_AT91_GPIO_CFG_INTERRUPT

I want to setup the buttons to generate interupts for handling user input.
I have found some domentation of how to set up ISR and DSR using
cyg_interrupt_create().

However, I can figure out how to map a GPIO pin to trigger the interrupt vector?

Cheers
Rasmus

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] Problem reading buttons on AT91sam7s-ek
  2007-10-02 13:04       ` Rasmus Stougaard
@ 2007-10-02 13:40         ` Andrew Lunn
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2007-10-02 13:40 UTC (permalink / raw)
  To: Rasmus Stougaard; +Cc: ecos-discuss

On Tue, Oct 02, 2007 at 03:04:16PM +0200, Rasmus Stougaard wrote:
> > >   // Enable the clock to the GPIO (enable input sampling)
> > >   HAL_WRITE_UINT32(AT91_PMC + AT91_PMC_PCER, AT91_PMC_PCER_PIOA);
> >
> > You only need to enable the clock once. You could move this outside of
> > the read function.
> 
> Ok thanks again, will do that. I also plan to convert my example to a
> macro, to save the overhead of making the function call.
> 
> >
> > Maybe i should add a macro to var_io.h to enable/disable the clock?
> 
> That might be a good idea, or add a comment to
> HAL_ARM_AT91_GPIO_CFG_DIRECTION
> and
> HAL_ARM_AT91_GPIO_GET
> stating that the clock must be enabled to receive inputs. At least it
> was not obvios to me, and others might benefit too :-)

It is in the data sheet, but i guess not everybody reads that.
 
> By the way can you point me to an example/documentation of how to use
> HAL_ARM_AT91_GPIO_CFG_INTERRUPT
> 
> I want to setup the buttons to generate interupts for handling user input.
> I have found some domentation of how to set up ISR and DSR using
> cyg_interrupt_create().

I don't think there is any code which actually uses it. It also might
not of been tested. 

You should get an interrupt on CYGNUM_HAL_INTERRUPT_PIOA. Again the
clock needs to be enabled. If i remember correctly the GPIO interrupts
are edge triggered, so you should get an interrupt for button press
and button release. To find out which has happened you need to read
first the interrupt status register, for which there is no macro at
the moment, to find out which GPIO line caused the interrupt. Then
read the GPIO pin to get its current state. You probably also need to
add debounce logic in software.

    Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-10-02 13:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-01 12:27 [ECOS] Problem reading buttons on AT91sam7s-ek Rasmus Stougaard
2007-10-01 14:28 ` Andrew Lunn
2007-10-02 11:40   ` Rasmus Stougaard
2007-10-02 11:47     ` Andrew Lunn
2007-10-02 13:04       ` Rasmus Stougaard
2007-10-02 13:40         ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).