driver

Dependencies:   mbed

Committer:
dhaldane
Date:
Sat Mar 05 00:09:45 2016 +0000
Revision:
0:00c56a9c6dee
Driver codes;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dhaldane 0:00c56a9c6dee 1 #include "mbed.h"
dhaldane 0:00c56a9c6dee 2 #define u8 unsigned char
dhaldane 0:00c56a9c6dee 3 #define u16 unsigned int
dhaldane 0:00c56a9c6dee 4 #define ubyte unsigned char
dhaldane 0:00c56a9c6dee 5 #define ushort unsigned short int
dhaldane 0:00c56a9c6dee 6 #define bit unsigned char
dhaldane 0:00c56a9c6dee 7 typedef struct {
dhaldane 0:00c56a9c6dee 8 unsigned int pos; // raw reading from sensor 14 bits
dhaldane 0:00c56a9c6dee 9 long oticks; // revolution counter
dhaldane 0:00c56a9c6dee 10 unsigned int calibPos; // 0 to 2pi, converted to 16 bits
dhaldane 0:00c56a9c6dee 11 unsigned int offset; // initial reading on setup - relative zero position
dhaldane 0:00c56a9c6dee 12 } EncObj;
dhaldane 0:00c56a9c6dee 13
dhaldane 0:00c56a9c6dee 14 class enc
dhaldane 0:00c56a9c6dee 15 {
dhaldane 0:00c56a9c6dee 16 public:
dhaldane 0:00c56a9c6dee 17 //Connect over i2c
dhaldane 0:00c56a9c6dee 18 enc(PinName mosi, PinName miso, PinName sck, PinName cs);
dhaldane 0:00c56a9c6dee 19 //Destroy instance
dhaldane 0:00c56a9c6dee 20 ~enc();
dhaldane 0:00c56a9c6dee 21 unsigned int ams_read();
dhaldane 0:00c56a9c6dee 22 void update_pos();
dhaldane 0:00c56a9c6dee 23 void set_offset();
dhaldane 0:00c56a9c6dee 24 unsigned int cal_state(); //Calibrated stat
dhaldane 0:00c56a9c6dee 25 static ushort par(ushort value);
dhaldane 0:00c56a9c6dee 26 ushort write_spi(ushort reg, u8 rw);
dhaldane 0:00c56a9c6dee 27 ushort read_spi(ushort reg);
dhaldane 0:00c56a9c6dee 28 EncObj enc_pos;
dhaldane 0:00c56a9c6dee 29
dhaldane 0:00c56a9c6dee 30 private:
dhaldane 0:00c56a9c6dee 31 SPI m_spi;
dhaldane 0:00c56a9c6dee 32 DigitalOut csl;
dhaldane 0:00c56a9c6dee 33
dhaldane 0:00c56a9c6dee 34 };
dhaldane 0:00c56a9c6dee 35
dhaldane 0:00c56a9c6dee 36
dhaldane 0:00c56a9c6dee 37
dhaldane 0:00c56a9c6dee 38
dhaldane 0:00c56a9c6dee 39