/* * $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 = { sizeof(struct gpioled_dd), gpioled_attach, NULL, NULL }; int gpioled_attach(struct device *self, uint32_t loc, uint8_t flags) { struct gpioled_dd *ddp = self->dv_devdata; /* grab parent's gpio_controller */ ddp->gld_gcp = self->dv_parent->dv_aux; 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 (pio pin %d)\n", ddp->gld_pin.gp_pinno); /* talk to gpio controller */ 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); }