Shop OBEX P1 Docs P2 Docs Learn Events
Writing Drivers — Parallax Forums

Writing Drivers

NWCCTVNWCCTV Posts: 3,629
edited 2013-01-21 21:50 in General Discussion
Where would be a good place to start if I want to learn how to write drivers for various hardware devices and what piece of hardware would be an easy item to start with?

Comments

  • kwinnkwinn Posts: 8,697
    edited 2013-01-21 17:25
    Drivers for the Propeller, Windows, or some other CPU?

    If it's for the propeller I would suggest starting with some simple hardware like the '595 chip.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-01-21 17:34
    I was just pondering drivers in general. I think the propeller would be a good start. What is the 595 chip and where would I start?
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2013-01-21 18:23
    Wow, what a coincidence!!!

    I have been writing a driver for the 74HC595, 74HC4094, and 74HC4021 shift registers.
    The 595 and 4094 are serial in to 8 bit parallel out, and the 4021 is 8 bit parallel in to serial out.

    I'm adding a pair of instructions to Mike Greens FemtoBasic. These code snippets are written in spin:
    204: ' SROUT [<expr>] = <expr>
                     ' SROUT [<Pin#>] = <Value>
                   a := getAddress(dot)
                   outa[a..a+3] := %0000
                   dira[a..a+3] := %1110
                   b := specialExpr
                   repeat 32
                      outa[a+2] := b & 1             ' Send   a    Bit  To The Registers
                      b <-= 1                        ' Rotate Left Bits In The Variable
                      outa[a]~~                      ' Shift  Left Bits In The Registers
                      outa[a]~
                   outa[a+1]~~                       ' Strobe The Output Registers
                   outa[a+1]~
    
    205: ' SRIN [ <expr> ]
             t := getAddress(dot)
             outa[t..t+3] := %0000
             dira[t..t+3] := %1110
             i := 0
                outa[t+1]~~      ' Strobe The Registers
                outa[t+1]~
                repeat 32
                   i += ina[t+3] ' Put    a     Bit  In The Variable
                   i <-= 1       ' Rotate Left  Bits In The Variable
                   outa[t]~~     ' Shift  Left  Bits In The Registers
                   outa[t]~ 
                i += ina[t+3]    ' Put Last Bit      In The Variable
             return i
    
    This simple example expects the there are 4 chips strung in series for a total of 32 bits;
    Any combination of output or input devices can be used.
    This consumes 4 Prop pins which must be in sequence.
    1 = Shift Clock
    1+1 = Register Clock
    1+2 = Serial Bits Out
    1+3 = Serial Bits In

    Ok these examples are specific to FemtoBasic but the concept is sound.

    Enhancements:
    Allow from 1 to 4 or more chips on a set of 4 Prop pins.

    I am looking for a code snippet that will be the equivalent of a "ROL", Rotate Left, spin instruction that can rotate 2 to 31 bits instead of the standard 32 bits.

    Duane J
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-01-21 20:31
    OK, You lost me at Wow!!!!
  • frank freedmanfrank freedman Posts: 1,983
    edited 2013-01-21 20:57
    Pick something in the OBEX that is not too complex and pick it apart, check out some stuff JonnyMac has posted both for methods and style.
  • kwinnkwinn Posts: 8,697
    edited 2013-01-21 21:50
    NWCCTV wrote: »
    OK, You lost me at Wow!!!!

    It really is a simple chip to start with. Only needs 3 signals to start with (plus power and ground of course), SER, SCK, and RCK. Download the data sheet and buy a '595 locally along with 8 hi efficiency leds and 8 180 to 220 ohm resistors. Connect the leds and resistors to the output pins of the '595, its SER, SCK, AND RCK pins to 2 free pins on the micro, ground the /G pin, put a pullup on the SRCLR pin and you are off to the races. I can post a block diagram if you want.
Sign In or Register to comment.