I2C wake part workaround

This commit is contained in:
Ben V. Brown
2022-04-19 17:47:38 +10:00
parent 68a540be17
commit 5853261ddf
3 changed files with 639 additions and 643 deletions

View File

@@ -43,7 +43,7 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_b
i2cCfg.subAddrSize = 1; // one byte address
err = I2C_MasterReceiveBlocking(I2C0_ID, &i2cCfg);
MSG((char *)"I2C Mem_Read %02X - %d - %d\r\n", DevAddress >> 1, err, number_of_byte);
// MSG((char *)"I2C Mem_Read %02X - %d - %d\r\n", DevAddress >> 1, err, number_of_byte);
bool res = err == SUCCESS;
if (!res) {
I2C_Unstick();
@@ -66,7 +66,7 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_bu
i2cCfg.subAddrSize = 1; // one byte address
err = I2C_MasterSendBlocking(I2C0_ID, &i2cCfg);
MSG((char *)"I2C Mem_Write %02X - %d\r\n", DevAddress >> 1, err);
// MSG((char *)"I2C Mem_Write %02X - %d\r\n", DevAddress >> 1, err);
bool res = err == SUCCESS;
if (!res) {
I2C_Unstick();
@@ -107,7 +107,6 @@ bool FRToSI2C::writeRegistersBulk(const uint8_t address, const I2C_REG *register
bool FRToSI2C::wakePart(uint16_t DevAddress) {
// wakepart is a special case where only the device address is sent
return false; // TODO
if (!lock()) {
return false;
@@ -129,6 +128,6 @@ bool FRToSI2C::wakePart(uint16_t DevAddress) {
I2C_Unstick();
}
unlock();
MSG((char *)"I2C probe done \r\n");
// MSG((char *)"I2C probe done \r\n");
return res;
}

View File

@@ -35,6 +35,7 @@
*/
#include "bl702_i2c.h"
#include "bflb_platform.h"
#include "bl702_glb.h"
/** @addtogroup BL702_Peripheral_Driver
@@ -68,7 +69,7 @@
/** @defgroup I2C_Private_Variables
* @{
*/
intCallback_Type *i2cIntCbfArra[I2C_ID_MAX][I2C_INT_ALL] = { { NULL } };
intCallback_Type *i2cIntCbfArra[I2C_ID_MAX][I2C_INT_ALL] = {{NULL}};
/*@} end of group I2C_Private_Variables */
@@ -95,10 +96,9 @@ intCallback_Type *i2cIntCbfArra[I2C_ID_MAX][I2C_INT_ALL] = { { NULL } };
*
* @return None
*
*******************************************************************************/
*******************************************************************************/
#ifndef BFLB_USE_HAL_DRIVER
static void I2C_IntHandler(I2C_ID_Type i2cNo)
{
static void I2C_IntHandler(I2C_ID_Type i2cNo) {
uint32_t tmpVal;
uint32_t I2Cx = I2C_BASE;
@@ -165,9 +165,8 @@ static void I2C_IntHandler(I2C_ID_Type i2cNo)
*
* @return None
*
*******************************************************************************/
void I2C_SendWord(I2C_ID_Type i2cNo, uint32_t data)
{
*******************************************************************************/
void I2C_SendWord(I2C_ID_Type i2cNo, uint32_t data) {
uint32_t I2Cx = I2C_BASE;
/* Check the parameters */
@@ -182,9 +181,8 @@ void I2C_SendWord(I2C_ID_Type i2cNo, uint32_t data)
*
* @return word data
*
*******************************************************************************/
uint32_t I2C_RecieveWord(I2C_ID_Type i2cNo)
{
*******************************************************************************/
uint32_t I2C_RecieveWord(I2C_ID_Type i2cNo) {
uint32_t I2Cx = I2C_BASE;
/* Check the parameters */
@@ -199,9 +197,8 @@ uint32_t I2C_RecieveWord(I2C_ID_Type i2cNo)
*
* @return None
*
*******************************************************************************/
void I2C_Enable(I2C_ID_Type i2cNo)
{
*******************************************************************************/
void I2C_Enable(I2C_ID_Type i2cNo) {
uint32_t tmpVal;
uint32_t I2Cx = I2C_BASE;
@@ -220,9 +217,8 @@ void I2C_Enable(I2C_ID_Type i2cNo)
*
* @return None
*
*******************************************************************************/
void I2C_Disable(I2C_ID_Type i2cNo)
{
*******************************************************************************/
void I2C_Disable(I2C_ID_Type i2cNo) {
uint32_t tmpVal;
uint32_t I2Cx = I2C_BASE;
@@ -254,9 +250,8 @@ void I2C_Disable(I2C_ID_Type i2cNo)
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
BL_Err_Type I2C_Reset(I2C_ID_Type i2cNo)
{
*******************************************************************************/
BL_Err_Type I2C_Reset(I2C_ID_Type i2cNo) {
/* Check the parameters */
CHECK_PARAM(IS_I2C_ID_TYPE(i2cNo));
@@ -273,9 +268,8 @@ BL_Err_Type I2C_Reset(I2C_ID_Type i2cNo)
*
* @return None
*
*******************************************************************************/
void I2C_Init(I2C_ID_Type i2cNo, I2C_Direction_Type direct, I2C_Transfer_Cfg *cfg)
{
*******************************************************************************/
void I2C_Init(I2C_ID_Type i2cNo, I2C_Direction_Type direct, I2C_Transfer_Cfg *cfg) {
uint32_t tmpVal;
uint32_t I2Cx = I2C_BASE;
@@ -322,9 +316,8 @@ void I2C_Init(I2C_ID_Type i2cNo, I2C_Direction_Type direct, I2C_Transfer_Cfg *cf
*
* @return SUCCESS
*
*******************************************************************************/
BL_Err_Type I2C_SetDeglitchCount(I2C_ID_Type i2cNo, uint8_t cnt)
{
*******************************************************************************/
BL_Err_Type I2C_SetDeglitchCount(I2C_ID_Type i2cNo, uint8_t cnt) {
uint32_t tmpVal;
uint32_t I2Cx = I2C_BASE;
@@ -358,16 +351,15 @@ BL_Err_Type I2C_SetDeglitchCount(I2C_ID_Type i2cNo, uint8_t cnt)
*
* @return None
*
*******************************************************************************/
void I2C_SetPrd(I2C_ID_Type i2cNo, uint8_t phase)
{
*******************************************************************************/
void I2C_SetPrd(I2C_ID_Type i2cNo, uint8_t phase) {
uint32_t tmpVal;
uint32_t I2Cx = I2C_BASE;
/* Check the parameters */
CHECK_PARAM(IS_I2C_ID_TYPE(i2cNo));
//phase_cycles = (32000000 / phase / 4) - 1;
// phase_cycles = (32000000 / phase / 4) - 1;
tmpVal = BL_RD_REG(I2Cx, I2C_PRD_START);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, I2C_CR_I2C_PRD_S_PH_0, phase);
tmpVal = BL_SET_REG_BITS_VAL(tmpVal, I2C_CR_I2C_PRD_S_PH_1, phase);
@@ -396,9 +388,8 @@ void I2C_SetPrd(I2C_ID_Type i2cNo, uint8_t phase)
*
* @return None
*
*******************************************************************************/
void I2C_ClockSet(I2C_ID_Type i2cNo, uint32_t clk)
{
*******************************************************************************/
void I2C_ClockSet(I2C_ID_Type i2cNo, uint32_t clk) {
uint8_t bclkDiv = 0;
/* Check the parameters */
@@ -429,9 +420,8 @@ void I2C_ClockSet(I2C_ID_Type i2cNo, uint32_t clk)
*
* @return None
*
*******************************************************************************/
void I2C_SetSclSync(I2C_ID_Type i2cNo, uint8_t enable)
{
*******************************************************************************/
void I2C_SetSclSync(I2C_ID_Type i2cNo, uint8_t enable) {
uint32_t tmpVal;
uint32_t I2Cx = I2C_BASE;
@@ -456,9 +446,8 @@ void I2C_SetSclSync(I2C_ID_Type i2cNo, uint8_t enable)
*
* @return RESET or SET
*
*******************************************************************************/
BL_Sts_Type I2C_IsBusy(I2C_ID_Type i2cNo)
{
*******************************************************************************/
BL_Sts_Type I2C_IsBusy(I2C_ID_Type i2cNo) {
uint32_t tmpVal;
uint32_t I2Cx = I2C_BASE;
@@ -476,9 +465,8 @@ BL_Sts_Type I2C_IsBusy(I2C_ID_Type i2cNo)
*
* @return RESET or SET
*
*******************************************************************************/
BL_Sts_Type I2C_TransferEndStatus(I2C_ID_Type i2cNo)
{
*******************************************************************************/
BL_Sts_Type I2C_TransferEndStatus(I2C_ID_Type i2cNo) {
uint32_t tmpVal;
uint32_t I2Cx = I2C_BASE;
@@ -497,9 +485,8 @@ BL_Sts_Type I2C_TransferEndStatus(I2C_ID_Type i2cNo)
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
BL_Err_Type I2C_MasterSendBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg)
{
*******************************************************************************/
BL_Err_Type I2C_MasterSendBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg) {
uint8_t i;
uint32_t timeOut = 0;
uint32_t temp = 0;
@@ -571,9 +558,8 @@ BL_Err_Type I2C_MasterSendBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg)
*
* @return SUCCESS or ERROR
*
*******************************************************************************/
BL_Err_Type I2C_MasterReceiveBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg)
{
*******************************************************************************/
BL_Err_Type I2C_MasterReceiveBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg) {
uint8_t i = 0;
uint32_t timeOut = 0;
uint32_t temp = 0;
@@ -585,7 +571,24 @@ BL_Err_Type I2C_MasterReceiveBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg)
I2C_Disable(i2cNo);
I2C_Init(i2cNo, I2C_READ, cfg);
I2C_Enable(i2cNo);
timeOut = I2C_FIFO_STATUS_TIMEOUT;
while (BL_RD_REG(I2C_BASE, I2C_BUS_BUSY)) {
timeOut--;
if (timeOut == 0) {
I2C_Disable(i2cNo);
MSG((char *)"I2C BSY\r\n");
return TIMEOUT;
}
}
temp = BL_RD_REG(I2C_BASE, I2C_INT_STS); // TODO this sucks as a workaround
if (BL_IS_REG_BIT_SET(temp, I2C_NAK_INT)) {
temp = BL_RD_REG(I2C_BASE, I2C_BUS_BUSY);
MSG((char *)"I2C NACK\r\n");
I2C_Disable(i2cNo);
return TIMEOUT;
}
/* Read I2C data */
while (cfg->dataSize - i >= 4) {
timeOut = I2C_FIFO_STATUS_TIMEOUT;
@@ -649,9 +652,8 @@ BL_Err_Type I2C_MasterReceiveBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg)
*
* @return None
*
*******************************************************************************/
void I2C_IntMask(I2C_ID_Type i2cNo, I2C_INT_Type intType, BL_Mask_Type intMask)
{
*******************************************************************************/
void I2C_IntMask(I2C_ID_Type i2cNo, I2C_INT_Type intType, BL_Mask_Type intMask) {
uint32_t tmpVal;
uint32_t I2Cx = I2C_BASE;
@@ -790,10 +792,9 @@ void I2C_IntMask(I2C_ID_Type i2cNo, I2C_INT_Type intType, BL_Mask_Type intMask)
*
* @return None
*
*******************************************************************************/
*******************************************************************************/
#ifndef BFLB_USE_HAL_DRIVER
void I2C_Int_Callback_Install(I2C_ID_Type i2cNo, I2C_INT_Type intType, intCallback_Type *cbFun)
{
void I2C_Int_Callback_Install(I2C_ID_Type i2cNo, I2C_INT_Type intType, intCallback_Type *cbFun) {
/* Check the parameters */
CHECK_PARAM(IS_I2C_ID_TYPE(i2cNo));
CHECK_PARAM(IS_I2C_INT_TYPE(intType));
@@ -809,12 +810,9 @@ void I2C_Int_Callback_Install(I2C_ID_Type i2cNo, I2C_INT_Type intType, intCallba
*
* @return None
*
*******************************************************************************/
*******************************************************************************/
#ifndef BFLB_USE_HAL_DRIVER
void I2C_IRQHandler(void)
{
I2C_IntHandler(I2C0_ID);
}
void I2C_IRQHandler(void) { I2C_IntHandler(I2C0_ID); }
#endif
/*@} end of group I2C_Public_Functions */

View File

@@ -896,7 +896,6 @@ void startGUITask(void const *argument) {
for (;;) {
ButtonState buttons = getButtonState();
MSG((char *)"Buttons %d\r\n", int(buttons));
if (buttons != BUTTON_NONE) {
OLED::setDisplayState(OLED::DisplayState::ON);
}