Initial Release of Library for PAT9125 OTS on L476RG Platform

Dependencies:   mbed

Committer:
pixus_mbed
Date:
Fri Oct 20 10:58:39 2017 +0000
Revision:
15:089f1d28d152
Parent:
9:53b4b362cbb8
Child:
16:7bea34dc0356
1. Separate LCD and UART mode.; 2. Configure BTN with default pull-up.; 3. NULL handle.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pixus_mbed 0:411244c71423 1 /* mbed Microcontroller Library
pixus_mbed 0:411244c71423 2 * Copyright (c) 2006-2013 ARM Limited
pixus_mbed 0:411244c71423 3 *
pixus_mbed 0:411244c71423 4 * Licensed under the Apache License, Version 2.0 (the "License");
pixus_mbed 0:411244c71423 5 * you may not use this file except in compliance with the License.
pixus_mbed 0:411244c71423 6 * You may obtain a copy of the License at
pixus_mbed 0:411244c71423 7 *
pixus_mbed 0:411244c71423 8 * http://www.apache.org/licenses/LICENSE-2.0
pixus_mbed 0:411244c71423 9 *
pixus_mbed 0:411244c71423 10 * Unless required by applicable law or agreed to in writing, software
pixus_mbed 0:411244c71423 11 * distributed under the License is distributed on an "AS IS" BASIS,
pixus_mbed 0:411244c71423 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
pixus_mbed 0:411244c71423 13 * See the License for the specific language governing permissions and
pixus_mbed 0:411244c71423 14 * limitations under the License.
pixus_mbed 0:411244c71423 15 */
pixus_mbed 0:411244c71423 16
pixus_mbed 0:411244c71423 17 #include "mbed.h"
pixus_mbed 0:411244c71423 18 #include "pixart_lcm.h"
pixus_mbed 0:411244c71423 19 #include "pat9125_i2c.h"
pixus_mbed 0:411244c71423 20 #include "pat9125_mbed.h"
pixus_mbed 0:411244c71423 21
pixus_mbed 15:089f1d28d152 22 #define LCM_MODE
pixus_mbed 15:089f1d28d152 23
pixus_mbed 0:411244c71423 24 pat9125_mbed_state_s g_pat9125_mbed_state ;
pixus_mbed 0:411244c71423 25 pat9125_mbed *gp_pat9125_mbed ;
pixus_mbed 15:089f1d28d152 26 pixart_lcm *gp_pixart_lcm = NULL;
pixus_mbed 15:089f1d28d152 27 Serial *serial = NULL ;
pixus_mbed 0:411244c71423 28
pixus_mbed 15:089f1d28d152 29 #ifdef LCM_MODE
pixus_mbed 15:089f1d28d152 30 SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK);
pixus_mbed 15:089f1d28d152 31 #else
pixus_mbed 15:089f1d28d152 32 Serial pc(USBTX, USBRX);
pixus_mbed 15:089f1d28d152 33 #endif
pixus_mbed 0:411244c71423 34
pixus_mbed 9:53b4b362cbb8 35 #define I2C_SDA_PIN I2C_SDA
pixus_mbed 9:53b4b362cbb8 36 #define I2C_SCL_PIN I2C_SCL
pixus_mbed 15:089f1d28d152 37 //DigitalIn sdaDummy(I2C_SDA_PIN, PullUp);
pixus_mbed 15:089f1d28d152 38 //DigitalIn sclDummy(I2C_SCL_PIN, PullUp);
pixus_mbed 0:411244c71423 39 pat9125_i2c *gp_pat9125_i2c;//(I2C_SDA0, I2C_SCL0);
pixus_mbed 15:089f1d28d152 40
pixus_mbed 0:411244c71423 41
pixus_mbed 9:53b4b362cbb8 42 DigitalOut PIN_LCM_CSB(PB_6);
pixus_mbed 9:53b4b362cbb8 43 DigitalOut PIN_LCM_RSTB(PA_9);
pixus_mbed 9:53b4b362cbb8 44 DigitalOut PIN_LCM_RS(PC_7);
pixus_mbed 0:411244c71423 45
pixus_mbed 9:53b4b362cbb8 46 InterruptIn PIN_SEN_MOTION(PB_3);
pixus_mbed 9:53b4b362cbb8 47 DigitalIn motionDummy(PB_3, PullUp);
pixus_mbed 15:089f1d28d152 48
pixus_mbed 9:53b4b362cbb8 49 DigitalIn PIN_BTN_L(PA_0);
pixus_mbed 15:089f1d28d152 50 DigitalIn BTN_L_Dummy(PA_0, PullUp);
pixus_mbed 9:53b4b362cbb8 51 DigitalIn PIN_BTN_R(PA_1);
pixus_mbed 15:089f1d28d152 52 DigitalIn BTN_R_Dummy(PA_1, PullUp);
pixus_mbed 0:411244c71423 53
pixus_mbed 9:53b4b362cbb8 54 DigitalOut PIN_GLED(PA_10);
pixus_mbed 9:53b4b362cbb8 55 DigitalOut PIN_RLED(PB_4);
pixus_mbed 0:411244c71423 56 #define I2C_ADDRESS 0x73
pixus_mbed 0:411244c71423 57
pixus_mbed 0:411244c71423 58 //-----------------------------------------------------------------------
pixus_mbed 0:411244c71423 59 int main(void)
pixus_mbed 0:411244c71423 60 {
pixus_mbed 15:089f1d28d152 61 int i = 0;
pixus_mbed 0:411244c71423 62 char addr = 0;
pixus_mbed 0:411244c71423 63 char data ;
pixus_mbed 0:411244c71423 64
pixus_mbed 15:089f1d28d152 65 #ifdef LCM_MODE
pixus_mbed 0:411244c71423 66 // +++++++ LCM Initialization +++++++ //
pixus_mbed 0:411244c71423 67 // Chip must be deselected
pixus_mbed 0:411244c71423 68 PIN_LCM_CSB = 1 ;
pixus_mbed 0:411244c71423 69
pixus_mbed 0:411244c71423 70 // Setup the spi for 8 bit data, high steady state clock,
pixus_mbed 0:411244c71423 71 // second edge capture, with a 1MHz clock rate
pixus_mbed 0:411244c71423 72 spi.format(8,3);
pixus_mbed 0:411244c71423 73 spi.frequency(1000000);
pixus_mbed 0:411244c71423 74 gp_pixart_lcm = new pixart_lcm(&spi, &PIN_LCM_CSB, &PIN_LCM_RSTB, &PIN_LCM_RS) ;
pixus_mbed 0:411244c71423 75 // ------- LCM Initialization ------- //
pixus_mbed 15:089f1d28d152 76 #else
pixus_mbed 15:089f1d28d152 77 serial = &pc ;
pixus_mbed 15:089f1d28d152 78 //pc.set_flow_control(SerialBase::Disabled) ;
pixus_mbed 15:089f1d28d152 79 pc.baud(115200);
pixus_mbed 15:089f1d28d152 80 pc.printf("---------- Pixart PAT9125 Demo\n");
pixus_mbed 15:089f1d28d152 81 #endif
pixus_mbed 0:411244c71423 82 // +++++++ PAT9125 Initialization +++++++ //
pixus_mbed 1:73967d37f487 83 gp_pat9125_i2c = new pat9125_i2c(I2C_SDA_PIN, I2C_SCL_PIN);
pixus_mbed 0:411244c71423 84 gp_pat9125_i2c->frequency(400000);
pixus_mbed 0:411244c71423 85 g_pat9125_mbed_state.p_i2c = gp_pat9125_i2c;
pixus_mbed 15:089f1d28d152 86 g_pat9125_mbed_state.p_pc = serial;
pixus_mbed 0:411244c71423 87 g_pat9125_mbed_state.pBTN_L = &PIN_BTN_L ;
pixus_mbed 0:411244c71423 88 g_pat9125_mbed_state.pBTN_R = &PIN_BTN_R ;
pixus_mbed 0:411244c71423 89 g_pat9125_mbed_state.pINT = &PIN_SEN_MOTION;
pixus_mbed 0:411244c71423 90 g_pat9125_mbed_state.pRLED = &PIN_RLED;
pixus_mbed 0:411244c71423 91 g_pat9125_mbed_state.pGLED = &PIN_GLED;
pixus_mbed 0:411244c71423 92 g_pat9125_mbed_state.pLCM = gp_pixart_lcm;
pixus_mbed 0:411244c71423 93 g_pat9125_mbed_state.slave_id = (I2C_ADDRESS << 1);
pixus_mbed 0:411244c71423 94 g_pat9125_mbed_state.sen_status = 0;
pixus_mbed 0:411244c71423 95
pixus_mbed 15:089f1d28d152 96 gp_pat9125_mbed = new pat9125_mbed(&g_pat9125_mbed_state) ;
pixus_mbed 15:089f1d28d152 97 #ifdef LCM_MODE
pixus_mbed 0:411244c71423 98 gp_pixart_lcm->LCM_DisplayString_Boot(g_pat9125_mbed_state.sen_status);
pixus_mbed 15:089f1d28d152 99 #else
pixus_mbed 0:411244c71423 100 if(g_pat9125_mbed_state.sen_status == true)
pixus_mbed 0:411244c71423 101 {
pixus_mbed 0:411244c71423 102 pc.printf("Initial Sensor ... Done\n");
pixus_mbed 0:411244c71423 103 }
pixus_mbed 0:411244c71423 104 else
pixus_mbed 0:411244c71423 105 {
pixus_mbed 0:411244c71423 106 pc.printf("Initial Sensor ... Fail\n");
pixus_mbed 0:411244c71423 107 }
pixus_mbed 15:089f1d28d152 108 #endif
pixus_mbed 0:411244c71423 109 while(true)
pixus_mbed 0:411244c71423 110 {
pixus_mbed 0:411244c71423 111 gp_pat9125_mbed->task();
pixus_mbed 0:411244c71423 112 }
pixus_mbed 15:089f1d28d152 113
pixus_mbed 0:411244c71423 114 }