]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_master/main.cpp
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[qmk_firmware.git] / tmk_core / tool / mbed / mbed-sdk / libraries / tests / mbed / i2c_master / main.cpp
1 #include "mbed.h"
2 #include "test_env.h"
3
4 #define SIZE (10)
5 #define ADDR (0x90)
6
7 #if defined(TARGET_KL25Z)
8 I2C i2c(PTE0, PTE1);
9 #elif defined(TARGET_nRF51822)
10 I2C i2c(p22,p20);
11 #elif defined(TARGET_FF_ARDUINO) || defined(TARGET_MAXWSNENV)
12 I2C i2c(I2C_SDA, I2C_SCL);
13 #else
14 I2C i2c(p28, p27);
15 #endif
16
17 int main() {
18     bool success = true;
19     char buf[] = {3, 2, 1, 4, 5, 6, 7, 8, 9, 10};
20     char res[SIZE];
21
22     i2c.write(ADDR, buf, SIZE);
23     i2c.read(ADDR, res, SIZE);
24
25     // here should be buf[all]++
26     i2c.write(ADDR, res, SIZE);
27     i2c.read(ADDR, res, SIZE);
28
29     // here should be buf[all]+=2
30     i2c.write(ADDR, res, SIZE);
31     i2c.write(ADDR, res, SIZE);
32
33     // here should be buf[all]+=3
34     i2c.read(ADDR, res, SIZE);
35     i2c.read(ADDR, res, SIZE);
36
37     for(int i = 0; i < SIZE; i++) {
38         if (res[i] != (buf[i] + 3)) {
39             success = false;
40             break;
41         }
42     }
43
44     notify_completion(success);
45 }