[BACK]Return to p64lcd.c CVS log [TXT][DIR] Up to [local] / funnyos / arch / sam7s64 / dev

Annotation of funnyos/arch/sam7s64/dev/p64lcd.c, Revision 1.1

1.1     ! nbrk        1: /*
        !             2:  * $Id$
        !             3:  */
        !             4: #include <sys/types.h>
        !             5: #include <sys/device.h>
        !             6: #include <sys/gpio.h>
        !             7: #include <dev/lcd/44780var.h>
        !             8:
        !             9: #include <arch/sam7s64/dev/at91sam7.h>
        !            10:
        !            11: /*
        !            12:  * 44780-based LCD connected to my p64 board.
        !            13:  * Wiring for chip logic:
        !            14:  *     RS  -> PA10
        !            15:  *     R/W -> PA9
        !            16:  *     E -> PA8
        !            17:  *     D{0..7} -> PA{7,6,5,4,3,2,1,0}
        !            18:  *
        !            19:  * We will fake-up as a 10-bit bus for our child (real 44780 driver).
        !            20:  * This 10-bit bus is: MSB <RS><R/W><D7>..<D0> LSB
        !            21:  * Please note that p64lcd_read() returns 8-bit D0..D7.
        !            22:  */
        !            23: int            p64lcd_attach(struct device *self, uint32_t loc, uint8_t flags);
        !            24: void   p64lcd_write(void *pldd, uint16_t data);
        !            25: uint8_t p64lcd_read(void *pldd);
        !            26: uint8_t        p64lcd_readbf(void *pldd);
        !            27: void   p64lcd_strobe(void *pldd);
        !            28:
        !            29: /* our devdata */
        !            30: struct p64lcd_dd {
        !            31:        struct gpio_controller  *pl_gcp;
        !            32:
        !            33:        struct h44780_busops            pl_bus;                 /* our 10-bit control bus for driver */
        !            34: };
        !            35:
        !            36: struct driver p64lcd_dr = {
        !            37:        sizeof(struct p64lcd_dd),
        !            38:        p64lcd_attach,
        !            39:        NULL,
        !            40:        NULL
        !            41: };
        !            42:
        !            43:
        !            44: int
        !            45: p64lcd_attach(struct device *self, uint32_t loc, uint8_t flags)
        !            46: {
        !            47:        struct p64lcd_dd *ddp = self->dv_devdata;
        !            48:        struct gpio_pin pin;
        !            49:        uint8_t i;
        !            50:        int j;
        !            51:
        !            52:        /* grab parent's gpio_controller */
        !            53:        ddp->pl_gcp = self->dv_parent->dv_aux;
        !            54:
        !            55:        /* configure pins */
        !            56:        pin.gp_pio = 1;
        !            57:        pin.gp_flags = GPIO_PIN_OUTPUT; /* XXX what about read? */
        !            58:        pin.gp_value = 0;
        !            59:        for(i = 0; i < 11; i++) {
        !            60:                pin.gp_pinno = i;
        !            61:                ddp->pl_gcp->gc_pinset(ddp->pl_gcp->gc_selfdd, pin);
        !            62:        }
        !            63:
        !            64:        /* XXX enable synchronous data output on our data lines */
        !            65:        *AT91C_PIOA_OWER = 0xff;
        !            66: //     *AT91C_PIOA_ODSR = 0xaa;
        !            67: //     *AT91C_PIOA_ODSR = ~0xaa;
        !            68:
        !            69:        printf("p64 10-bit bus for LCD, dedicated E strobe\n");
        !            70:
        !            71:        /* link 44780_ops */
        !            72:        ddp->pl_bus.write = p64lcd_write;
        !            73:        ddp->pl_bus.read = p64lcd_read;
        !            74:        ddp->pl_bus.readbf = p64lcd_readbf;
        !            75:        ddp->pl_bus.strobe = p64lcd_strobe;
        !            76:        ddp->pl_bus.selfdd = ddp;
        !            77:
        !            78:        /* export */
        !            79:        self->dv_aux = &ddp->pl_bus;
        !            80:
        !            81:        return(0);
        !            82: }
        !            83:
        !            84: void
        !            85: p64lcd_write(void *pldd, uint16_t data)
        !            86: {
        !            87:        uint32_t setmask = 0;
        !            88:        uint8_t i, rs, rw = rs = 0;
        !            89:        /*
        !            90:         * Decode and place given 10-bit data on the wires.
        !            91:         * We will use raw PIOA registers instead of gpio_controller abstraction
        !            92:         * so we can hit all pins in one shoot.
        !            93:         */
        !            94:        /*
        !            95:         * Caller gives us: <RS><RW><D7><D6><D5><D4><D3><D2><D1><D0> (LSB)
        !            96:         */
        !            97:        /* strip unneeded bits */
        !            98:        data = data & 0x3ff;
        !            99:
        !           100:        /* XXX bring all our lines to high */
        !           101:        //*AT91C_PIOA_CODR = 0x3ff;
        !           102:
        !           103:        /* check if caller requested to assert RS */
        !           104:        if (data & 0x200)
        !           105:                rs = 1;
        !           106: //             setmask |= 1 << 10; /* 'RS' is PA10 */
        !           107: //             *AT91C_PIOA_CODR = 1 << 10;
        !           108: //     else *AT91C_PIOA_SODR = 1 << 10;
        !           109:
        !           110:        /* check if caller requested to assert R/W */
        !           111:        if (data & 0x100)
        !           112:                rw = 1;
        !           113: //             setmask |= 1 << 9; /* 'RW' is PA9 */
        !           114: //             *AT91C_PIOA_CODR = 1 << 9;
        !           115: //     else *AT91C_PIOA_SODR = 1 << 9;
        !           116:
        !           117:        /*
        !           118:         * Deal with LSB of data which contains D0..D7 value.
        !           119:         * Since D0..D7 is wired to PA7..PA0 we need to reverse bits.
        !           120:         */
        !           121:
        !           122:        for(i = 0; i < 7; i++)
        !           123:                if (data & (1 << i))
        !           124:                        setmask |= 1 << (7 - i);
        !           125: //     setmask = data & 0xff;
        !           126:
        !           127:        printf("p64lcd_write: rs=%d rw=%d setmask=0x%x\n", rs, rw, setmask);
        !           128:
        !           129: //     *AT91C_PIOA_SODR = setmask;
        !           130: //     *AT91C_PIOA_CODR = (uint8_t)(~setmask);
        !           131:        if (rs)
        !           132:                *AT91C_PIOA_SODR = 1 << 10;
        !           133:        else
        !           134:                *AT91C_PIOA_CODR = 1 << 10;
        !           135:
        !           136:        if (rw)
        !           137:                *AT91C_PIOA_SODR = 1 << 9;
        !           138:        else
        !           139:                *AT91C_PIOA_CODR = 1 << 9;
        !           140:
        !           141:        /* E high */
        !           142:        *AT91C_PIOA_SODR = 1 << 8;
        !           143:
        !           144:        *AT91C_PIOA_ODSR = setmask;
        !           145:
        !           146:        /* E low */
        !           147:        *AT91C_PIOA_CODR = 1 << 8;
        !           148:
        !           149:        //*AT91C_PIOA_ODSR = ~setmask;
        !           150: }
        !           151:
        !           152:
        !           153: uint8_t
        !           154: p64lcd_read(void *pldd)
        !           155: {
        !           156:        /* TODO */
        !           157:
        !           158:
        !           159:        return(1);
        !           160: }
        !           161:
        !           162:
        !           163: uint8_t
        !           164: p64lcd_readbf(void *pldd)
        !           165: {
        !           166:        /* TODO */
        !           167:
        !           168:        return(1);
        !           169: }
        !           170:
        !           171:
        !           172: void
        !           173: p64lcd_strobe(void *pldd)
        !           174: {
        !           175:        volatile int i;
        !           176:        *AT91C_PIOA_SODR = 1 << 8;
        !           177:        /* XXX delay? */
        !           178:        for(i = 0; i < 10; i++)
        !           179:                ;
        !           180:        *AT91C_PIOA_CODR = 1 << 8;
        !           181: }
        !           182:

CVSweb