Skip to content

Commit 40c0e30

Browse files
committed
ARMmbed#114 Add busy error code to I2C transactions when the response hasn't been attended
Uprev I2C protocl version
1 parent 9d09263 commit 40c0e30

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

source/board/microbitv2/i2c_commands.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ static void i2c_write_flash_callback(uint8_t* pData, uint8_t size);
7373
static void i2c_read_flash_callback(uint8_t* pData, uint8_t size);
7474

7575
static void i2c_slave_callback(I2C_Type *base, i2c_slave_transfer_t *xfer, void *userData) {
76+
i2cCommand_t i2cResponse = {0};
77+
7678
switch (xfer->event)
7779
{
7880
/* Address match event */
@@ -101,6 +103,13 @@ static void i2c_slave_callback(I2C_Type *base, i2c_slave_transfer_t *xfer, void
101103
xfer->data = g_slave_RX_buff;
102104
xfer->dataSize = I2C_DATA_LENGTH;
103105
g_SlaveRxFlag = true;
106+
107+
// Clear transmit Buffer in IRQ. It will be filled when the task attends the I2C event
108+
i2c_clearBuffer();
109+
// Add busy error code
110+
i2cResponse.cmdId = gErrorResponse_c;
111+
i2cResponse.cmdData.errorRspCmd.errorCode = gErrorBusy_c;
112+
i2c_fillBuffer((uint8_t*) &i2cResponse, 0, sizeof(i2cResponse));
104113
break;
105114

106115
/* Transfer done */
@@ -276,7 +285,7 @@ static void i2c_write_comms_callback(uint8_t* pData, uint8_t size) {
276285
memcpy(&i2cResponse.cmdData.readRspCmd.data, &board_id_hex, sizeof(board_id_hex));
277286
break;
278287
case gI2CProtocolVersion_c: {
279-
uint16_t i2c_version = 1;
288+
uint16_t i2c_version = 2;
280289
i2cResponse.cmdData.readRspCmd.dataSize = sizeof(i2c_version);
281290
memcpy(&i2cResponse.cmdData.readRspCmd.data, &i2c_version, sizeof(i2c_version));
282291
}

source/board/microbitv2/i2c_commands.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ typedef enum errorCode_tag {
7777
gErrorWrongPropertySize_c = 0x35,
7878
gErrorReadDisallowed_c = 0x36,
7979
gErrorWriteDisallowed_c = 0x37,
80-
gErrorWriteFail_c = 0x38
80+
gErrorWriteFail_c = 0x38,
81+
gErrorBusy_c = 0x39
8182
} errorCode_t;
8283

8384
typedef __PACKED_STRUCT readReqCmd_tag {

0 commit comments

Comments
 (0)