-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
432 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## ----------------------------------------------------------- ## | ||
## Don't touch the next line unless you know what you're doing.## | ||
## ----------------------------------------------------------- ## | ||
|
||
# Name of the module | ||
LOCAL_NAME := demo/i2c | ||
|
||
# List of submodules which contain code we need to include in the final lib | ||
LOCAL_API_DEPENDS := \ | ||
|
||
LOCAL_ADD_INCLUDE := include\ | ||
include/std_inc \ | ||
include/api_inc \ | ||
|
||
|
||
# Set this to any non-null string to signal a module which | ||
# generates a binary (must contain a "main" entry point). | ||
# If left null, only a library will be generated. | ||
IS_ENTRY_POINT := no | ||
|
||
## ------------------------------------ ## | ||
## Add your custom flags here ## | ||
## ------------------------------------ ## | ||
MYCFLAGS += | ||
|
||
## ------------------------------------- ## | ||
## List all your sources here ## | ||
## ------------------------------------- ## | ||
C_SRC := ${notdir ${wildcard src/*.c}} | ||
|
||
## ------------------------------------- ## | ||
## Do Not touch below this line ## | ||
## ------------------------------------- ## | ||
include ${SOFT_WORKDIR}/platform/compilation/cust_rules.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
#include "stdbool.h" | ||
#include "stdint.h" | ||
#include "stdio.h" | ||
#include "string.h" | ||
|
||
#include "api_os.h" | ||
#include "api_debug.h" | ||
#include "api_event.h" | ||
#include "api_hal_i2c.h" | ||
|
||
|
||
|
||
|
||
#define MAIN_TASK_STACK_SIZE (2048 * 2) | ||
#define MAIN_TASK_PRIORITY 0 | ||
#define MAIN_TASK_NAME "Main Test Task" | ||
|
||
#define SECOND_TASK_STACK_SIZE (2048 * 2) | ||
#define SECOND_TASK_PRIORITY 1 | ||
#define SECOND_TASK_NAME "Second Test Task" | ||
|
||
static HANDLE mainTaskHandle = NULL; | ||
static HANDLE secondTaskHandle = NULL; | ||
#define I2C_ACC I2C2 | ||
|
||
|
||
void EventDispatch(API_Event_t* pEvent) | ||
{ | ||
switch(pEvent->id) | ||
{ | ||
case API_EVENT_ID_NO_SIMCARD: | ||
Trace(10,"!!NO SIM CARD%d!!!!",pEvent->param1); | ||
break; | ||
|
||
case API_EVENT_ID_SYSTEM_READY: | ||
Trace(1,"system initialize complete"); | ||
break; | ||
|
||
case API_EVENT_ID_NETWORK_REGISTERED_HOME: | ||
case API_EVENT_ID_NETWORK_REGISTERED_ROAMING: | ||
Trace(2,"network register success"); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
void SecondTask(void *pData) | ||
{ | ||
uint8_t accId; | ||
I2C_Config_t config; | ||
|
||
config.freq = I2C_FREQ_100K; | ||
I2C_Init(I2C_ACC, config); | ||
|
||
while(1) | ||
{ | ||
I2C_ReadByte(I2C_ACC, 0x19, 0x0f, &accId); | ||
Trace(1,"accelerator id shold be 0x33, read:0X%02x",accId); | ||
OS_Sleep(3000); | ||
} | ||
} | ||
|
||
void MainTask(void *pData) | ||
{ | ||
API_Event_t* event=NULL; | ||
|
||
secondTaskHandle = OS_CreateTask(SecondTask, | ||
NULL, NULL, SECOND_TASK_STACK_SIZE, SECOND_TASK_PRIORITY, 0, 0, SECOND_TASK_NAME); | ||
|
||
while(1) | ||
{ | ||
if(OS_WaitEvent(mainTaskHandle, (void**)&event, OS_TIME_OUT_WAIT_FOREVER)) | ||
{ | ||
EventDispatch(event); | ||
OS_Free(event->pParam1); | ||
OS_Free(event->pParam2); | ||
OS_Free(event); | ||
} | ||
} | ||
} | ||
|
||
void i2c_Main(void) | ||
{ | ||
mainTaskHandle = OS_CreateTask(MainTask, | ||
NULL, NULL, MAIN_TASK_STACK_SIZE, MAIN_TASK_PRIORITY, 0, 0, MAIN_TASK_NAME); | ||
OS_SetUserMainHandle(&mainTaskHandle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#ifndef __API_HAL_I2C_H__ | ||
#define __API_HAL_I2C_H__ | ||
|
||
#include <sdk_init.h> | ||
|
||
|
||
/// \brief bool I2C_Init(I2C_ID_t i2c, I2C_Config_t config); | ||
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus | ||
/// \param I2C_Bps_t Bpsx, the speed of I2C | ||
/// \return BOOL | ||
/// TRUE: init success | ||
/// FALSE: init failed | ||
/// \note when I2C1 is used, the i2c1 pin must be pulled up | ||
#define I2C_Init CSDK_FUNC(I2C_Init) | ||
|
||
|
||
/// \brief I2C_Error_t I2C_ReadByte(I2C_ID_t i2c, uint32_t slaveAddr, uint32_t memAddr, uint8_t* data); | ||
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus | ||
/// \param uint32_t slaveAddr, Address of the slave from which we read a byte | ||
/// \param uint32_t memAddr, memAddr Address in the memory map where to get the byte. | ||
/// \param uint8_t* pData, pData pointer to save one byte data | ||
/// \return I2C_Error_t | ||
#define I2C_ReadByte CSDK_FUNC(I2C_ReadByte) | ||
|
||
|
||
/// \brief I2C_Error_t I2C_WriteByte(I2C_ID_t i2c, uint32_t slaveAddr, uint32_t memAddr, uint8_t data); | ||
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus | ||
/// \param uint32_t slaveAdd, Address of the slave to which we write a byte | ||
/// \param uint8_t* pData, one byte data that you want to write | ||
/// \return I2C_Error_t | ||
#define I2C_WriteByte CSDK_FUNC(I2C_WriteByte) | ||
|
||
|
||
/// \brief I2C_Error_t I2C_ReadBytes(I2C_ID_t i2c, uint32_t slaveAddr, uint32_t memAddr, uint8_t* pData, uint32_t length); | ||
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus | ||
/// \param uint32_t slaveAddr, Address of the slave from which we read data | ||
/// \param uint32_t memAddr, memAddr Address in the memory map where to get data. | ||
/// \param uint8_t* pData, buffer pointer to read the data | ||
/// \param uint32_t length, length of the data that you want to read | ||
/// \return I2C_Error_t | ||
#define I2C_ReadBytes CSDK_FUNC(I2C_ReadBytes) | ||
|
||
|
||
/// \brief I2C_Error_t I2C_WriteBytes(I2C_ID_t i2c, uint32_t slaveAddr, uint32_t memAddr, CONST uint8_t* pData, uint32_t length); | ||
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus | ||
/// \param uint32_t slaveAdd, Address of the slave to which we write a byte | ||
/// \param uint8_t* pData, the pointer of buffer that you want to write | ||
/// \param uint32_t length, length of the data that you want to write | ||
/// \return I2C_Error_t | ||
#define I2C_WriteBytes CSDK_FUNC(I2C_WriteBytes) | ||
|
||
|
||
/// \brief I2C_Error_t I2C_ReadRawByte(I2C_ID_t i2c, uint32_t CmdMask); | ||
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus | ||
/// \param uint32_t CmdMask, can be I2C_MASTER_ACK|I2C_MASTER_RD|I2C_MASTER_STO|I2C_MASTER_WR|I2C_MASTER_STA | ||
/// \return I2C_Error_t | ||
/// \note This function completes the 2 phase read cycle as defined in the SCCB | ||
/// spec. The actual commands for the I2C module must be: Stop, Read, and | ||
/// NACK. (The SCCB requires a NACK at the end of the read byte) | ||
#define I2C_ReadRawByte CSDK_FUNC(I2C_ReadRawByte) | ||
|
||
|
||
/// \brief I2C_Error_t I2C_WriteRawByte(I2C_ID_t i2c, uint8_t SendByte, uint32_t CmdMask); | ||
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus | ||
/// \param uint8_t SendByte, one byte what you want to send | ||
/// \param uint32_t CmdMask, this is the command associated with this byte. It must | ||
/// be sent at the same time so the two actions (write to the data fifo and | ||
/// issue the command) are done together, can be I2C_MASTER_ACK|I2C_MASTER_RD| | ||
/// I2C_MASTER_STO|I2C_MASTER_WR|I2C_MASTER_STA | ||
/// \return I2C_Error_t | ||
/// \note This function sends a single byte on the I2C interface | ||
/// It is not designed for use in the real I2C protocol, but allows access | ||
/// for non-standard usages such as SCCB for the Omnivision Camera control | ||
#define I2C_WriteRawByte CSDK_FUNC(I2C_WriteRawByte) | ||
|
||
|
||
/// \brief bool I2C_Close(I2C_ID_t i2c); | ||
/// \param I2C_Bus_ID_t i2c, ID of the I2C bus | ||
/// \return BOOL | ||
/// TRUE: close success | ||
/// FALSE: close failed | ||
#define I2C_Close CSDK_FUNC(I2C_Close) | ||
|
||
|
||
#endif |
Oops, something went wrong.