Trackball based on the NXP LPC11U24 and the ADNS-9500

Dependencies:   ADNS9500 USBDevice mbed 25LCxxx_SPI

main.h

Committer:
xxann5
Date:
2013-01-14
Revision:
7:d6ee49a89009
Parent:
6:4cb2c9a3abcd
Child:
8:5674f5ab61cd

File content as of revision 7:d6ee49a89009:

/* Copyright (c) 2012-2013 Chris Majoros(chris@majoros.us), MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "mbed.h"
#include "USBHID.h"
#include "USBMouse.h"

#include <math.h>
#include <stdint.h>


#define PINDETECT_PIN_ASSTERED  0    //setAssertValue
#define PINDETECT_SAMPLE_PERIOD 100 //setSampleFrequency
#define PINDETECT_ASSERT_COUNT  10    //setSamplesTillAssert
#define PINDETECT_HOLD_COUNT    500

#include "PinDetect.h"

#define ADNS9500_SROM_91

#define DEBUG

#include "adns9500.hpp"
#include "Ser25lcxxx.h"

enum cli_actions {
    SET   = 0x01,
    GET   = 0x02,
    CLEAR = 0x03,
    INIT  = 0x04,
};

enum settings {    
    CPI_DEFAULT     = 0x00,
    CPI_MAX         = 0x01,
    CPI_MIN         = 0x02,
    CPI_STEP        = 0x03,
    CPI_Z_DEFAULT   = 0x04,
    CPI_HR_DEFAULT  = 0x05,
    
    VID             = 0x06,
    PID             = 0x07,

    LED_SHOW        = 0x08,
    SETTINGS_OFFSET = 0x00
};

enum ands_meta {
    ADNS_CRC         = 0x0,
    ADNS_ID          = 0x1,
    ADNS_FW_LEN      = 0x2,
    ADNS_FW_OFFSET   = 0xF000,
    ADNS_META_OFFSET = 0xEFF0
};

#define UINT16(ub, lb)             (uint16_t)(((ub & 0xff) << 8) | (lb & 0xff))
#define INT16(ub, lb)              (int16_t)(((ub & 0xff) << 8) | (lb & 0xff))
  
//This report will contain data to be sent
HID_REPORT send_rep;
HID_REPORT recv_rep;

PinDetect btn_l(P1_25);
PinDetect btn_m(P1_19);
PinDetect btn_r(P0_20);
PinDetect btn_z(P0_2);
PinDetect btn_hr(P1_26);

DigitalIn btn_program(P0_4);

adns9500::ADNS9500 *sensor;
USBMouse *mouse;

bool motion_triggered = false;
bool z_axis_active    = false;
bool high_rez_active  = false;

uint16_t s[9] = {
    1080,    // CPI_DEFAULT
    5040,    // CPI_MAX
    0,       // CPI_MIN
    90,      // CPI_STEP
    90,      // CPI_Z_DEFAULT
    180,     // CPI_HR_DEFULT
    0x192f,  // VID
    0x0000,  // PID
    0,       // LED_SHOW
};

uint16_t a[3];

void track();
void program();

void motionCallback( void );

void btn_hr_press( void );
void btn_hr_release( void );

void btn_z_press( void );
void btn_z_release( void );

void btn_l_press(void);
void btn_l_release( void );

void btn_m_press( void );
void btn_m_release( void );

void btn_r_press( void );
void btn_r_release( void );

void set_setting( Ser25LCxxx *eeprom, uint16_t attrib, uint16_t val );
uint16_t get_setting( Ser25LCxxx *eeprom, uint16_t attrib);
void clear_setting( Ser25LCxxx *eeprom, uint16_t attrib);

void set_adns_firmware( Ser25LCxxx *eeprom, uint16_t offset, uint16_t len, uint8_t* val );
uint8_t* get_adns_firmware( Ser25LCxxx *eeprom, uint16_t offset, uint16_t len );

void set_adns_meta( Ser25LCxxx *eeprom, uint16_t attrib, uint16_t val );
uint16_t get_adns_meta( Ser25LCxxx *eeprom, uint16_t attrib );