| 29 | interface.dmaDeinit(MPR121_I2CADDR_DEFAULT); |
| 30 | } |
| 31 | void MPR121::processData(uint8_t addr, bool running, bool timeout, bool abort_detected, bool stop_detected) |
| 32 | { |
| 33 | cancel_alarm(restart_alarm_id); |
| 34 | if (timeout || abort_detected) |
| 35 | { |
| 36 | failCount++; |
| 37 | if (failCount > 10) |
| 38 | { |
| 39 | status = MPR121_INIT_SOFTRESET; |
| 40 | } |
| 41 | restart_alarm_id = add_alarm_in_ms(500, restart_handler, this, true); |
| 42 | return; |
| 43 | } |
| 44 | if (stop_detected) |
| 45 | { |
| 46 | failCount = 0; |
| 47 | switch (status) |
| 48 | { |
| 49 | case MPR121_INIT_SOFTRESET: |
| 50 | status = MPR121_INIT_ECR_CLEAR; |
| 51 | bufferTx[0] = MPR121_SOFTRESET; |
| 52 | bufferTx[1] = 0x63; |
| 53 | interface.dmaWriteRead(MPR121_I2CADDR_DEFAULT, bufferTx, 2, nullptr, 0); |
| 54 | return; |
| 55 | case MPR121_INIT_ECR_CLEAR: |
| 56 | status = MPR121_INIT_CONFIG2_READ; |
| 57 | bufferTx[0] = MPR121_CONFIG2; |
| 58 | interface.dmaWriteRead(MPR121_I2CADDR_DEFAULT, bufferTx, 1, bufferRx, 1); |
| 59 | return; |
| 60 | case MPR121_INIT_CONFIG2_READ: |
| 61 | if (bufferRx[0] != 0x24) |
| 62 | { |
| 63 | status = MPR121_INIT_SOFTRESET; |
| 64 | restart_alarm_id = add_alarm_in_ms(500, restart_handler, this, true); |
| 65 | } |
| 66 | initTouchpad = 0; |
| 67 | status = MPR121_INIT_TOUCHTH_N; |
| 68 | bufferTx[0] = MPR121_TOUCHTH_0; |
| 69 | bufferTx[1] = MPR121_TOUCH_THRESHOLD_DEFAULT; |
| 70 | interface.dmaWriteRead(MPR121_I2CADDR_DEFAULT, bufferTx, 1, bufferRx, 1); |
| 71 | return; |
| 72 | case MPR121_INIT_TOUCHTH_N: |
| 73 | status = MPR121_INIT_RELEASETH_N; |
| 74 | bufferTx[0] = MPR121_RELEASETH_0 + 2 * initTouchpad; |
| 75 | bufferTx[1] = MPR121_RELEASE_THRESHOLD_DEFAULT; |
| 76 | initTouchpad++; |
| 77 | if (initTouchpad == touchpadCount) |
| 78 | { |
| 79 | status = MPR121_INIT_MHDR; |
| 80 | bufferTx[0] = MPR121_MHDR; |
| 81 | bufferTx[1] = 0x01; |
| 82 | interface.dmaWriteRead(MPR121_I2CADDR_DEFAULT, bufferTx, 2, nullptr, 0); |
| 83 | return; |
| 84 | } |
| 85 | interface.dmaWriteRead(MPR121_I2CADDR_DEFAULT, bufferTx, 1, bufferRx, 1); |
| 86 | return; |
| 87 | case MPR121_INIT_RELEASETH_N: |
| 88 | status = MPR121_INIT_TOUCHTH_N; |
no test coverage detected