Computing Assignment / LED

Dependencies:   mbed

Fork of LED2 by Charlie Bailey

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ADXL362.h Source File

ADXL362.h

00001 #ifndef _ADXL362_H_
00002 #define _ADXL362_H_
00003 
00004 #include "mbed.h"
00005 
00006 // ACC Registers
00007 #define ID0 0x00
00008 #define STATUS 0x0b
00009 #define FIFO_EL 0x0c
00010 #define FIFO_EH 0x0d
00011 #define RESET 0x1f
00012 #define FIFO_CTL 0x28
00013 #define FIFO_SAM 0x29
00014 #define INTMAP1 0x2a
00015 #define INTMAP2 0x2b
00016 #define FILTER_CTL 0x2c
00017 #define POWER_CTL 0x2d
00018 #define WR_SPI 0x0a
00019 #define RD_SPI 0x0b
00020 #define RD_FIFO 0x0d
00021 #define DOWN 0
00022 #define UP 1
00023 #define SAMPLE_SET 128
00024 
00025 /*      Class ADXL362: configure and connect to ADXL362 3-axis accelerometer.
00026  *      Richard McWilliam
00027  *
00028  *      Example:
00029  *
00030  *      #include "mbed.h"
00031  *      #include "ADXL362.h"
00032  *
00033  *      ADXL362 adxl362(p11, p12, p13, p10);  // Accelerometer (mosi, miso, sclk, cs)
00034  *
00035  *      int main()
00036  *      {
00037  *      // local variables
00038  *      int8_t x8 = 0;
00039  *      int8_t y8 = 0;
00040  *      int8_t z8 = 0;  
00041  *      uint8_t reg;
00042  *
00043  *      // set up SPI interface
00044  *      adxl362.init_spi();
00045  *      // Set up accelerometer
00046  *      adxl362.init_adxl362();
00047  *
00048  *      // Check settings
00049  *      reg = adxl362.ACC_ReadReg(FILTER_CTL);
00050  *      printf("FILTER_CTL = 0x%X\r\n", reg);
00051  *
00052  *      adxl362.ACC_GetXYZ8(&x8, &y8, &z8); // Fetch sample from ADXL362
00053  *      wait(0.1); // Wait is required in this mode
00054  *          
00055  *      }
00056 */
00057 class ADXL362 {
00058     
00059     public:
00060         // Set up object for communcation with ADXL362. Pins are mosi, miso, sclk, cs
00061         ADXL362(PinName mosi, PinName miso, PinName sclk, PinName cbs);
00062         //~ADXL362() {};
00063         
00064         // Initialise the SPI interface for ADXL362
00065         void init_spi();
00066         
00067         // Initialise ADXL362 in basic capture mode, 8 bit pcakets.
00068         void init_adxl362();
00069         
00070         // Fetch a single set of x,y,z packets indicating acceleration
00071         void ACC_GetXYZ8(int8_t* x, int8_t* y, int8_t* z);
00072         
00073         // Read specified register of ADXL362
00074         uint8_t ACC_ReadReg( uint8_t reg );
00075         
00076         // Write to register of ADXL362
00077         void ACC_WriteReg( uint8_t reg, uint8_t cmd );
00078     
00079     private:
00080         SPI SPI_m;
00081         DigitalOut CBS_m;       
00082 
00083 };
00084 
00085 #endif