=================================================================== RCS file: /cvs/funnyos/arch/sam7s64/dev/gpioled.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- funnyos/arch/sam7s64/dev/gpioled.c 2007/11/24 19:04:42 1.4 +++ funnyos/arch/sam7s64/dev/gpioled.c 2007/12/16 23:10:08 1.5 @@ -1,18 +1,23 @@ /* - * $Id: gpioled.c,v 1.4 2007/11/24 19:04:42 nbrk Exp $ + * $Id: gpioled.c,v 1.5 2007/12/16 23:10:08 nbrk Exp $ */ #include #include #include +#include +#include +#include /* * GPIO LED found on my SAM7-P64 development board. */ int gpioled_attach(struct device *, uint32_t, uint8_t); +int gpioled_devctl(struct device *self, uint32_t ctlcmd, void *ctldata); + struct driver gpioled_dr = { - 1, + sizeof(struct gpioled_dd), gpioled_attach, NULL, NULL @@ -22,19 +27,42 @@ int gpioled_attach(struct device *self, uint32_t loc, uint8_t flags) { + struct gpioled_dd *ddp = self->dv_devdata; /* grab parent's gpio_controller */ - struct gpio_controller *gcp = self->dv_parent->dv_aux; - struct gpio_pin pin; + ddp->gld_gcp = self->dv_parent->dv_aux; - pin.gp_pinno = loc; /* PA17 or PA18 please */ - pin.gp_pio = 1; /* PIO mode */ - pin.gp_flags = GPIO_PIN_OUTPUT; - pin.gp_value = 0; /* LED on */ + ddp->gld_pin.gp_pinno = loc; /* PA17 or PA18 please */ + ddp->gld_pin.gp_pio = 1; /* PIO mode */ + ddp->gld_pin.gp_flags = GPIO_PIN_OUTPUT; + ddp->gld_pin.gp_value = 0; /* LED on */ - printf("p64 onboard LED (pin %d)\n", pin.gp_pinno); + printf("p64 onboard LED (pio pin %d)\n", ddp->gld_pin.gp_pinno); /* talk to gpio controller */ - gcp->gc_pinset(gcp->gc_selfdd, pin); + ddp->gld_gcp->gc_pinset(ddp->gld_gcp->gc_selfdd, ddp->gld_pin); + + devctl_register(self, gpioled_devctl); + return(0); +} + + +int +gpioled_devctl(struct device *self, uint32_t ctlcmd, void *ctldata) +{ + struct gpioled_dd *ddp; + + ddp = self->dv_devdata; + + switch(ctlcmd) { + case(DCGPIOLED_TOGGLE): + /* toggle LED */ + ddp->gld_pin.gp_value = ~ddp->gld_pin.gp_value & 0x01; + + /* update us using our gpio controller */ + ddp->gld_gcp->gc_pinset(ddp->gld_gcp->gc_selfdd, ddp->gld_pin); + default: + break; + } return(0); }