PixArt Imaging / Mbed 2 deprecated PAT9125_OTS_nRF51

Dependencies:   mbed pat9125_mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "mbed.h"
00018 #include "pixart_lcm.h"
00019 #include "pat9125_i2c.h"
00020 #include "pat9125_mbed.h"
00021 
00022 pat9125_mbed_state_s g_pat9125_mbed_state ;
00023 pat9125_mbed *gp_pat9125_mbed ;
00024 pixart_lcm *gp_pixart_lcm ;
00025 
00026 
00027 Serial  pc(USBTX, USBRX);
00028 #define I2C_SDA_PIN I2C_SDA0
00029 #define I2C_SCL_PIN I2C_SCL0
00030 //DigitalIn sdaDummy(I2C_SDA0, PullUp);
00031 //DigitalIn sclDummy(I2C_SCL0, PullUp);
00032 pat9125_i2c *gp_pat9125_i2c;//(I2C_SDA0, I2C_SCL0);
00033 SPI spi(SPI_PSELMOSI0, NC, SPI_PSELSCK0);
00034 
00035 DigitalOut PIN_LCM_CSB(SPI_PSELSS0);
00036 DigitalOut PIN_LCM_RSTB(p20);
00037 DigitalOut PIN_LCM_RS(p23);
00038 
00039 InterruptIn PIN_SEN_MOTION(p15);
00040 DigitalIn motionDummy(p15, PullUp);
00041 DigitalIn PIN_BTN_L(p1);
00042 DigitalIn PIN_BTN_R(p2);
00043 
00044 DigitalOut PIN_GLED(p14);
00045 DigitalOut PIN_RLED(p17);
00046 #define I2C_ADDRESS    0x73
00047 
00048 //-----------------------------------------------------------------------
00049 int main(void)
00050 {
00051     char addr = 0;
00052     char data ;
00053     pc.set_flow_control(SerialBase::Disabled) ;
00054     pc.baud(115200);
00055     pc.printf("---------- Pixart PAT9125 Demo\n");  
00056 
00057     // +++++++ LCM Initialization +++++++ //
00058     // Chip must be deselected
00059     PIN_LCM_CSB = 1 ;
00060 
00061     // Setup the spi for 8 bit data, high steady state clock,
00062     // second edge capture, with a 1MHz clock rate
00063     spi.format(8,3);
00064     spi.frequency(1000000);
00065     gp_pixart_lcm = new pixart_lcm(&spi, &PIN_LCM_CSB, &PIN_LCM_RSTB, &PIN_LCM_RS) ;
00066     // ------- LCM Initialization ------- //
00067     
00068     // +++++++ PAT9125 Initialization +++++++ //
00069     gp_pat9125_i2c = new pat9125_i2c(I2C_SDA_PIN, I2C_SCL_PIN);
00070     gp_pat9125_i2c->frequency(400000); 
00071     g_pat9125_mbed_state.p_i2c = gp_pat9125_i2c;
00072     g_pat9125_mbed_state.p_pc = &pc;
00073     g_pat9125_mbed_state.pBTN_L = &PIN_BTN_L ;
00074     g_pat9125_mbed_state.pBTN_R = &PIN_BTN_R ;
00075     g_pat9125_mbed_state.pINT = &PIN_SEN_MOTION;
00076     g_pat9125_mbed_state.pRLED = &PIN_RLED;
00077     g_pat9125_mbed_state.pGLED = &PIN_GLED;
00078     g_pat9125_mbed_state.pLCM = gp_pixart_lcm;    
00079     g_pat9125_mbed_state.slave_id = (I2C_ADDRESS << 1);
00080     g_pat9125_mbed_state.sen_status = 0;
00081     
00082     gp_pat9125_mbed = new pat9125_mbed(&g_pat9125_mbed_state) ;        
00083     gp_pixart_lcm->LCM_DisplayString_Boot(g_pat9125_mbed_state.sen_status);
00084     
00085     if(g_pat9125_mbed_state.sen_status == true) 
00086     {
00087         pc.printf("Initial Sensor ... Done\n");
00088     }
00089     else    
00090     {
00091         pc.printf("Initial Sensor ... Fail\n");
00092     }
00093     while(true)
00094     {
00095       gp_pat9125_mbed->task();
00096     }
00097 }