📄 userot.c
字号:
// Include all the header files you want to include here
// ***********************************************************************
// NOTE: User defined header file: Please add/ modify for your application
// ***********************************************************************
//#include <stdio.h>
// ***************************************
// NOTE: OTLib header file: Do Not Modify
// ***************************************
// OTLib specific header files
#include "SynaOT.h"
// ==========================================================================
// * OTLib Host Processor Specific (Hardware Abstract Layer (HAL) functions *
// ==========================================================================
// Prototype defintions
// *************************************************************************************
// The User has to write the following HAL functions:
//
// 1) void OT_HAL_delay_10th_usec(OT_U16 tenth_microsec);
// // Delay in units of 1/10th of microseconds (100 nano seconds)
//
// 2) void OT_HAL_SDA_IN_MODE(void);
// // Set SDA (I2C Data) Line to Input Mode
//
// 3) void OT_HAL_SCL_IN_MODE(void);
// // Set SCL (I2C Clock) Line to Input Mode
//
// 4) void OT_HAL_SDA_OUT_MODE(void);
// // Set SDA (I2C Data) Line to Output Mode
//
// 5) void OT_HAL_SCL_OUT_MODE(void);
// // Set SCL (I2C Clock) Line to Output Mode
//
// 6) void OT_HAL_I2C_SDA_LO(void);
// // Set SDA (I2C Data) Line to Low (logic "0")
//
// 7) void OT_HAL_I2C_SCL_LO(void);
// // Set SCL (I2C Clock) Line to Low (logic "0")
//
// 8) OT_U8 OT_HAL_BitRead_I2C_SDA(void);
// // Read the state of SDA (I2C Data) Line
//
// 9) OT_U8 OT_HAL_BitRead_I2C_SCL(void);
// // Read the state of SCL (I2C Clock) Line
//
// 10) OT_U8 OT_HAL_BitRead_ATTN(void);
// // Read the state of the Attention (ATTN) line
//
// NOTE: Do not change the function names. Just add to the body of the HAL functions
// **************************************************************************************
// Delay in units of 1/10th of microseconds (100 nano seconds)
void OT_HAL_delay_10th_usec(OT_U16 tenth_microsec)
{
// ***********************************************************************
// NOTE: HAL function: User adds/ writes to the body of this function
// ***********************************************************************
}
// Set SDA (I2C Data) Line to Input Mode
void OT_HAL_SDA_IN_MODE(void)
{
// ***********************************************************************
// NOTE: HAL function: User adds/ writes to the body of this function
// ***********************************************************************
}
// Set SCL (I2C Clock) Line to Input Mode
void OT_HAL_SCL_IN_MODE(void)
{
// ***********************************************************************
// NOTE: HAL function: User adds/ writes to the body of this function
// ***********************************************************************
}
// Set SDA (I2C Data) Line to Output Mode
void OT_HAL_SDA_OUT_MODE(void)
{
// ***********************************************************************
// NOTE: HAL function: User adds/ writes to the body of this function
// ***********************************************************************
}
// Set SCL (I2C Clock) Line to Output Mode
void OT_HAL_SCL_OUT_MODE(void)
{
// ***********************************************************************
// NOTE: HAL function: User adds/ writes to the body of this function
// ***********************************************************************
}
// Set SDA (I2C Data) Line to Low (logic "0")
void OT_HAL_I2C_SDA_LO(void)
{
// ***********************************************************************
// NOTE: HAL function: User adds/ writes to the body of this function
// ***********************************************************************
}
// Set SCL (I2C Clock) Line to Low (logic "0")
void OT_HAL_I2C_SCL_LO(void)
{
// ***********************************************************************
// NOTE: HAL function: User adds/ writes to the body of this function
// ***********************************************************************
}
// Read the state of SDA (I2C Data) Line
OT_U8 OT_HAL_BitRead_I2C_SDA(void)
{
// ***********************************************************************
// NOTE: HAL function: User adds/ writes to the body of this function
// ***********************************************************************
}
// Read the state of SCL (I2C Clock) Line
OT_U8 OT_HAL_BitRead_I2C_SCL(void)
{
// ***********************************************************************
// NOTE: HAL function: User adds/ writes to the body of this function
// ***********************************************************************
}
// Read the state of the Attention (ATTN) line
OT_U8 OT_HAL_BitRead_ATTN(void)
{
// ***********************************************************************
// NOTE: HAL function: User adds/ writes to the body of this function
// ***********************************************************************
}
// Application Example Prototype defintions
void Buttons_Process_Example(void);
//
// Function Name: main
// Functionality : This is the main entry function.
//
OT_U8 pOneTouchDataRegs[OT_NUM_DATA_REG_BYTES]; // OneTouch Data Registers
OT_U8 Interrupt_Flag = OT_FALSE;
void main(void)
{
OT_U8 Result;
// ********************************************************
// ADD code HERE to initialize host and attention lines *
// ********************************************************
// Initialise the Host Processor
// Initialize the Attention Line as input
// *************************************************************
// The USER writes code to initialize host and attention lines *
// *************************************************************
// Initialize I2C data and Clock line
OT_Init_BitBang_I2C(); // Do not remove this.
// Initialize OneTouch Device by writing to the Config Registers
// If the initialization fails, either retry to initialize for a specific number
// of times or display error in initialization
if( OT_Init()==OT_FAILURE )
{
// put your initializataion code here
}
// main loop -- Your application main loop goes here
while(1)
{
if(Interrupt_Flag == OT_TRUE) // If Interrupt Flag is set
{
Interrupt_Flag = OT_FALSE;
// Read the OT Data Registers
if(OT_ReadDataReg(pOneTouchDataRegs) == OT_SUCCESS)
{
// Invoke the Button function, if no error
Buttons_Process_Example();
} // end of OT_ReadDataReg() - if
}
} // end of while(1)
} // end of main()
// Interrupt Service Routine
// Interrupt from the Attention Line
void AttnIntHandler(void)
{
Interrupt_Flag = OT_TRUE;
}
// wait for attention line to be Asserted with timeout
// If this function is not implemented then the
// default function with no timing control is used
OT_U8 OT_Poll_Attn_Line_TimeOut(void)
{
OT_U32 bCounter=0;
// wait until attention line is asserted or timer timeout
do{
bCounter++;
}
while( ( (OT_HAL_BitRead_ATTN() ==1) & (bCounter < OT_TIMEOUT)) );
if(OT_HAL_BitRead_ATTN()== 0)
return OT_SUCCESS;
return OT_FAILURE;
}
// Button Function to do button processing
void Buttons_Process_Example(void)
{
// Write your application specific button processing here
// Uncomment this to use with Category 1A board.
// Example Button function where it toggles the LED on Category-1A board when a
// button is pressed
// Button mapping is as follows:
// pOneTouchDataRegs[0] = Buttons [15:8]
// pOneTouchDataRegs[1] = Buttons [7:0]
// For Category 1A sensor module
// Top left = Button-15
// Top right = Button-12
// Bottom left = Button-7
// Bottom right = Button-4
static OT_U8 pButtonBuffer[4]={0x00, 0x0E, 0x1F, 0x1F};
if(pOneTouchDataRegs[0+OT_BUTTON_OFFSET] &0x80)
pButtonBuffer[3] ^= 0x02;
if(pOneTouchDataRegs[0+OT_BUTTON_OFFSET] &0x10)
pButtonBuffer[3] ^= 0x04;
if(pOneTouchDataRegs[1+OT_BUTTON_OFFSET] &0x80)
pButtonBuffer[3] ^= 0x08;
if(pOneTouchDataRegs[1+OT_BUTTON_OFFSET] &0x10)
pButtonBuffer[3] ^= 0x10;
OT_WriteI2C(OT_ADDR, pButtonBuffer, 4);
OT_Set_ReadAddress();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -