Skip to content

Commit a8ebc73

Browse files
fix cross-platofrm compatibility issues and build up CI
1 parent fe526f0 commit a8ebc73

8 files changed

Lines changed: 40 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,28 @@ jobs:
6161

6262
- name: Test
6363
run: ctest --test-dir build --output-on-failure
64+
65+
build-arm64:
66+
name: Build (ARM64)
67+
runs-on: ubuntu-22.04
68+
container:
69+
image: ubuntu:22.04
70+
# request ARM64 emulation — GitHub runners will use qemu for multiarch containers
71+
options: --platform linux/arm64
72+
73+
steps:
74+
- uses: actions/checkout@v4
75+
76+
- name: Install dependencies
77+
run: |
78+
apt-get update
79+
apt-get install -y cmake ninja-build gcc g++ libc6-dev
80+
81+
- name: Configure
82+
run: cmake -S . -B build -G Ninja -DBUILD_TESTING=ON
83+
84+
- name: Build
85+
run: cmake --build build
86+
87+
- name: Test
88+
run: ctest --test-dir build --output-on-failure

examples/c/i2c_scanner/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <stdio.h>
77
#include <stdint.h>
8+
#include <sys/types.h>
89
#include "linux_wire.h"
910

1011
int main(void)

examples/c/i2c_scanner_strict/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <stdio.h>
77
#include <stdint.h>
8+
#include <sys/types.h>
89
#include "linux_wire.h"
910

1011
int main(void)

examples/c/master_multiplier/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
#include <stdio.h>
77
#include <stdint.h>
8-
#include <unistd.h>
8+
#include <sys/types.h>
9+
#include <time.h>
910
#include "linux_wire.h"
1011

1112
static const uint16_t DEVICE_ADDR = 0x40;
@@ -31,7 +32,9 @@ int main(void)
3132
return 1;
3233
}
3334

34-
usleep(1000); /* small delay to let peripheral respond */
35+
/* sleep ~1ms */
36+
struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000 * 1000 };
37+
nanosleep(&ts, NULL);
3538

3639
uint8_t result = 0;
3740
ssize_t r = lw_ioctl_read(&bus, DEVICE_ADDR, NULL, 0, &result, 1, 0);

examples/c/master_reader/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <stdio.h>
77
#include <stdint.h>
8+
#include <sys/types.h>
89
#include "linux_wire.h"
910

1011
static const uint16_t DEVICE_ADDR = 0x40;

examples/c/master_writer/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <stdio.h>
77
#include <stdint.h>
8+
#include <sys/types.h>
89
#include "linux_wire.h"
910

1011
static const uint16_t DEVICE_ADDR = 0x40;

examples/cpp/master_multiplier/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <cstdio>
2-
#include <unistd.h> // for usleep
2+
#include <time.h>
33
#include "Wire.h"
44

55
/*
@@ -32,8 +32,9 @@ int main()
3232
return 1;
3333
}
3434

35-
// Wait briefly to allow the Nano to process the value
36-
usleep(1000); // 1 ms is enough for AVR callbacks
35+
// Wait briefly to allow the Nano to process the value (~1ms)
36+
struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000 * 1000 };
37+
nanosleep(&ts, NULL);
3738

3839
// Request 1 byte back
3940
uint8_t count = Wire.requestFrom(DEVICE_ADDR, (uint8_t)1);

src/Wire.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "Wire.h"
2+
#include <sys/types.h>
3+
#include <unistd.h>
24

35
#include <cerrno>
46
#include <cstring>

0 commit comments

Comments
 (0)