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
@@ -97,8 +98,7 @@ intCallback_Type *i2cIntCbfArra[I2C_ID_MAX][I2C_INT_ALL] = { { NULL } };
*
*******************************************************************************/
#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;
@@ -166,8 +166,7 @@ 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 */
@@ -183,8 +182,7 @@ 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 */
@@ -200,8 +198,7 @@ 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;
@@ -221,8 +218,7 @@ 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;
@@ -255,8 +251,7 @@ 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));
@@ -274,8 +269,7 @@ 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;
@@ -323,8 +317,7 @@ 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;
@@ -359,8 +352,7 @@ 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;
@@ -397,8 +389,7 @@ 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 */
@@ -430,8 +421,7 @@ 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;
@@ -457,8 +447,7 @@ 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;
@@ -477,8 +466,7 @@ 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;
@@ -498,8 +486,7 @@ 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;
@@ -572,8 +559,7 @@ 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;
@@ -650,8 +653,7 @@ 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;
@@ -792,8 +794,7 @@ void I2C_IntMask(I2C_ID_Type i2cNo, I2C_INT_Type intType, BL_Mask_Type intMask)
*
*******************************************************************************/
#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));
@@ -811,10 +812,7 @@ void I2C_Int_Callback_Install(I2C_ID_Type i2cNo, I2C_INT_Type intType, intCallba
*
*******************************************************************************/
#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);
}