Initial commit of motor driver firmware

Dependencies:   mbed-src

Fork of mbed_AS5047P_driver by Duncan Haldane

enc.h

Committer:
dhaldane
Date:
2016-09-28
Revision:
1:d68c51a0a706
Parent:
0:00c56a9c6dee

File content as of revision 1:d68c51a0a706:

#include "mbed.h"
#define u8 unsigned char
#define u16 unsigned int
#define ubyte unsigned char
#define ushort unsigned short int
#define bit unsigned char
typedef struct {
    unsigned int pos; // raw reading from sensor 14 bits
    long oticks;  // revolution counter
    unsigned int calibPos;  // 0 to 2pi, converted to 16 bits
    unsigned int offset; // initial reading on setup - relative zero position
} EncObj; 

class enc
{
public:
    //Connect over i2c
    enc(PinName mosi, PinName miso, PinName sck, PinName cs);
    //Destroy instance
    ~enc();
    unsigned int  ams_read();
    void update_pos();
    void set_offset(ushort zpos);
    unsigned int cal_state(); //Calibrated stat
    static ushort par(ushort value);
    ushort write_spi(ushort reg, u8 rw);
    ushort read_spi(ushort reg);
    EncObj enc_pos;
    
private:
    SPI m_spi;
    DigitalOut csl;

};