MCPcopy Create free account
hub / github.com/SmingHub/Sming / SIGNAL

Function SIGNAL

Sming/Libraries/I2Cdev/I2Cdev.cpp:1161–1331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1159 }
1160
1161 SIGNAL(TWI_vect) {
1162 switch (TW_STATUS) {
1163 // All Master
1164 case TW_START: // sent start condition
1165 case TW_REP_START: // sent repeated start condition
1166 // copy device address and r/w bit to output register and ack
1167 TWDR = twi_slarw;
1168 twi_reply(1);
1169 break;
1170
1171 // Master Transmitter
1172 case TW_MT_SLA_ACK: // slave receiver acked address
1173 case TW_MT_DATA_ACK: // slave receiver acked data
1174 // if there is data to send, send it, otherwise stop
1175 if (twi_masterBufferIndex < twi_masterBufferLength) {
1176 // copy data to output register and ack
1177 TWDR = twi_masterBuffer[twi_masterBufferIndex++];
1178 twi_reply(1);
1179 } else {
1180 twi_stop();
1181 }
1182 break;
1183
1184 case TW_MT_SLA_NACK: // address sent, nack received
1185 twi_error = TW_MT_SLA_NACK;
1186 twi_stop();
1187 break;
1188
1189 case TW_MT_DATA_NACK: // data sent, nack received
1190 twi_error = TW_MT_DATA_NACK;
1191 twi_stop();
1192 break;
1193
1194 case TW_MT_ARB_LOST: // lost bus arbitration
1195 twi_error = TW_MT_ARB_LOST;
1196 twi_releaseBus();
1197 break;
1198
1199 // Master Receiver
1200 case TW_MR_DATA_ACK: // data received, ack sent
1201 // put byte into buffer
1202 twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
1203
1204 case TW_MR_SLA_ACK: // address sent, ack received
1205 // ack if more bytes are expected, otherwise nack
1206 if (twi_masterBufferIndex < twi_masterBufferLength) {
1207 twi_reply(1);
1208 } else {
1209 twi_reply(0);
1210 }
1211 break;
1212
1213 case TW_MR_DATA_NACK: // data received, nack sent
1214 // put final byte into buffer
1215 twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
1216
1217 case TW_MR_SLA_NACK: // address sent, nack received
1218 twi_stop();

Callers

nothing calls this directly

Calls 3

twi_replyFunction · 0.85
twi_releaseBusFunction · 0.85
twi_stopFunction · 0.70

Tested by

no test coverage detected