Skip to content

Commit b76f27e

Browse files
authored
Merge pull request #2 from d33mobile/chore/lint-tooling
clang-format + shellcheck tooling via a ./ci entrypoint
2 parents 14d6a43 + 62cab50 commit b76f27e

23 files changed

Lines changed: 375 additions & 324 deletions

.clang-format

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Config tuned to the existing hand-written style:
2+
# 4-space indent, spaces only, K&R braces, 100-col.
3+
# The Align* + SortIncludes:false options preserve the author's manual
4+
# column alignment (aligned #defines, struct members, tables) as much as
5+
# clang-format allows. Residual churn is alignment inside call-args and
6+
# brace-init tables, which clang-format cannot preserve.
7+
BasedOnStyle: LLVM
8+
IndentWidth: 4
9+
TabWidth: 4
10+
UseTab: Never
11+
ColumnLimit: 100
12+
SortIncludes: false
13+
AlignConsecutiveMacros: AcrossComments
14+
AlignConsecutiveDeclarations: true
15+
AlignConsecutiveAssignments: true
16+
AllowShortFunctionsOnASingleLine: None

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
# Pin clang-format to match the version used locally. shellcheck is
13+
# preinstalled on GitHub-hosted ubuntu runners.
14+
- run: pipx install clang-format==19.1.7
15+
- run: ./ci --action=check

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fi
2525
mkdir -p build
2626
cd build
2727
cmake -DPICO_BOARD=pico_w ..
28-
make -j$(nproc)
28+
make -j"$(nproc)"
2929
cd ..
3030

3131
cp build/hslock.uf2 hslock.uf2

ci

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
# Project CI entrypoint. Default: fix formatting locally.
3+
# Use --action=check (dry-run, non-zero on diff) in a git hook / CI.
4+
set -euo pipefail
5+
cd "$(dirname "$0")"
6+
7+
check=lint action=fix
8+
for a in "$@"; do case $a in
9+
--check=*) check=${a#*=} ;;
10+
--action=*) action=${a#*=} ;;
11+
*) echo "usage: ./ci [--check=lint] [--action=fix|check]" >&2; exit 2 ;;
12+
esac; done
13+
14+
srcs() { git ls-files '*.c' '*.h' ':!:libs/**' ':!:version.h'; }
15+
shells() { git ls-files ':!:libs/**' | while read -r f; do
16+
if head -1 -- "$f" | grep -q '^#!.*sh'; then printf '%s\n' "$f"; fi
17+
done; }
18+
19+
case $check.$action in
20+
lint.fix) srcs | xargs -r clang-format -i
21+
shells | xargs -r shellcheck ;; # no autofix; reports only
22+
lint.check) srcs | xargs -r clang-format --dry-run --Werror
23+
shells | xargs -r shellcheck ;;
24+
*) echo "unknown --check=$check --action=$action" >&2; exit 2 ;;
25+
esac

hardware/buzzer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
#define BUZZER_PIN 17
55

6-
#define BUZZER_SHORT_BEEP_DELAY 100
6+
#define BUZZER_SHORT_BEEP_DELAY 100
77
#define BUZZER_MEDIUM_BEEP_DELAY 500
8-
#define BUZZER_LONG_BEEP_DELAY 2000
8+
#define BUZZER_LONG_BEEP_DELAY 2000
99

1010
void buzzer_init();
1111
void buzzer_on();

hardware/clock.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
uint32_t clock_get_unix_time(void) {
44
datetime_t dt;
5-
if (!rtc_get_datetime(&dt)) return 0;
5+
if (!rtc_get_datetime(&dt))
6+
return 0;
67

78
struct tm t = {
89
.tm_year = dt.year - 1900,
@@ -17,12 +18,12 @@ uint32_t clock_get_unix_time(void) {
1718
}
1819

1920
void clock_set_from_unix_time(uint32_t unix_time) {
20-
time_t t = (time_t)unix_time;
21+
time_t t = (time_t)unix_time;
2122
struct tm *utc = gmtime(&t);
2223

2324
datetime_t dt = {
2425
.year = utc->tm_year + 1900,
25-
.month = utc->tm_mon + 1,
26+
.month = utc->tm_mon + 1,
2627
.day = utc->tm_mday,
2728
.dotw = utc->tm_wday,
2829
.hour = utc->tm_hour,

hardware/keypad.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
#include "pico/stdlib.h"
33
#include "pico/time.h"
44

5+
// clang-format off
6+
// Kept as a 4x4 grid mirroring the physical keypad layout.
57
static const char KEY_MAP[KEYPAD_ROWS][KEYPAD_COLS] = {
68
{'1', '2', '3', 'A'},
79
{'4', '5', '6', 'B'},
810
{'7', '8', '9', 'C'},
911
{'*', '0', '#', 'D'}
1012
};
13+
// clang-format on
1114

1215
void keypad_init(void) {
1316
// Rows: outputs, default HIGH
@@ -48,16 +51,16 @@ static char scan_raw(void) {
4851
}
4952

5053
char keypad_get_key(void) {
51-
static char last_raw = 0;
52-
static char last_stable = 0;
53-
static absolute_time_t stable_at = {0};
54+
static char last_raw = 0;
55+
static char last_stable = 0;
56+
static absolute_time_t stable_at = {0};
5457

5558
char raw = scan_raw();
5659

5760
if (raw != last_raw) {
5861
// Reading changed - restart debounce timer
59-
last_raw = raw;
60-
stable_at = make_timeout_time_ms(KEYPAD_DEBOUNCE_MS);
62+
last_raw = raw;
63+
stable_at = make_timeout_time_ms(KEYPAD_DEBOUNCE_MS);
6164
return 0;
6265
}
6366

hardware/light.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <stdio.h>
55

6-
76
void light_init() {
87
gpio_init(LIGHT_PIN);
98
gpio_set_dir(LIGHT_PIN, GPIO_OUT);

lwipopts.h

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,91 @@
11
#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H
22
#define _LWIPOPTS_EXAMPLE_COMMONH_H
33

4-
54
// Common settings used in most of the pico_w examples
65
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
76

87
// allow override in some examples
98
#ifndef NO_SYS
10-
#define NO_SYS 1
9+
#define NO_SYS 1
1110
#endif
1211
// allow override in some examples
1312
#ifndef LWIP_SOCKET
14-
#define LWIP_SOCKET 0
13+
#define LWIP_SOCKET 0
1514
#endif
1615
#if PICO_CYW43_ARCH_POLL
17-
#define MEM_LIBC_MALLOC 1
16+
#define MEM_LIBC_MALLOC 1
1817
#else
1918
// MEM_LIBC_MALLOC is incompatible with non polling versions
20-
#define MEM_LIBC_MALLOC 0
19+
#define MEM_LIBC_MALLOC 0
2120
#endif
22-
#define MEM_ALIGNMENT 4
21+
#define MEM_ALIGNMENT 4
2322
#ifndef MEM_SIZE
24-
#define MEM_SIZE 4000
23+
#define MEM_SIZE 4000
2524
#endif
26-
#define MEMP_NUM_TCP_SEG 32
27-
#define MEMP_NUM_ARP_QUEUE 10
28-
#define PBUF_POOL_SIZE 24
29-
#define LWIP_ARP 1
30-
#define LWIP_ETHERNET 1
31-
#define LWIP_ICMP 1
32-
#define LWIP_RAW 1
33-
#define TCP_WND (8 * TCP_MSS)
34-
#define TCP_MSS 1460
35-
#define TCP_SND_BUF (8 * TCP_MSS)
36-
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
37-
#define LWIP_NETIF_STATUS_CALLBACK 1
38-
#define LWIP_NETIF_LINK_CALLBACK 1
39-
#define LWIP_NETIF_HOSTNAME 1
40-
#define LWIP_NETCONN 0
41-
#define MEM_STATS 0
42-
#define SYS_STATS 0
43-
#define MEMP_STATS 0
44-
#define LINK_STATS 0
25+
#define MEMP_NUM_TCP_SEG 32
26+
#define MEMP_NUM_ARP_QUEUE 10
27+
#define PBUF_POOL_SIZE 24
28+
#define LWIP_ARP 1
29+
#define LWIP_ETHERNET 1
30+
#define LWIP_ICMP 1
31+
#define LWIP_RAW 1
32+
#define TCP_WND (8 * TCP_MSS)
33+
#define TCP_MSS 1460
34+
#define TCP_SND_BUF (8 * TCP_MSS)
35+
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
36+
#define LWIP_NETIF_STATUS_CALLBACK 1
37+
#define LWIP_NETIF_LINK_CALLBACK 1
38+
#define LWIP_NETIF_HOSTNAME 1
39+
#define LWIP_NETCONN 0
40+
#define MEM_STATS 0
41+
#define SYS_STATS 0
42+
#define MEMP_STATS 0
43+
#define LINK_STATS 0
4544
// #define ETH_PAD_SIZE 2
46-
#define LWIP_CHKSUM_ALGORITHM 3
47-
#define LWIP_DHCP 1
48-
#define LWIP_IPV4 1
49-
#define LWIP_TCP 1
50-
#define LWIP_UDP 1
51-
#define LWIP_DNS 1
52-
#define LWIP_TCP_KEEPALIVE 1
53-
#define LWIP_NETIF_TX_SINGLE_PBUF 1
54-
#define DHCP_DOES_ARP_CHECK 0
55-
#define LWIP_DHCP_DOES_ACD_CHECK 0
45+
#define LWIP_CHKSUM_ALGORITHM 3
46+
#define LWIP_DHCP 1
47+
#define LWIP_IPV4 1
48+
#define LWIP_TCP 1
49+
#define LWIP_UDP 1
50+
#define LWIP_DNS 1
51+
#define LWIP_TCP_KEEPALIVE 1
52+
#define LWIP_NETIF_TX_SINGLE_PBUF 1
53+
#define DHCP_DOES_ARP_CHECK 0
54+
#define LWIP_DHCP_DOES_ACD_CHECK 0
5655

5756
#ifndef NDEBUG
58-
#define LWIP_DEBUG 1
59-
#define LWIP_STATS 1
60-
#define LWIP_STATS_DISPLAY 1
57+
#define LWIP_DEBUG 1
58+
#define LWIP_STATS 1
59+
#define LWIP_STATS_DISPLAY 1
6160
#endif
6261

63-
#define ETHARP_DEBUG LWIP_DBG_OFF
64-
#define NETIF_DEBUG LWIP_DBG_OFF
65-
#define PBUF_DEBUG LWIP_DBG_OFF
66-
#define API_LIB_DEBUG LWIP_DBG_OFF
67-
#define API_MSG_DEBUG LWIP_DBG_OFF
68-
#define SOCKETS_DEBUG LWIP_DBG_OFF
69-
#define ICMP_DEBUG LWIP_DBG_OFF
70-
#define INET_DEBUG LWIP_DBG_OFF
71-
#define IP_DEBUG LWIP_DBG_OFF
72-
#define IP_REASS_DEBUG LWIP_DBG_OFF
73-
#define RAW_DEBUG LWIP_DBG_OFF
74-
#define MEM_DEBUG LWIP_DBG_OFF
75-
#define MEMP_DEBUG LWIP_DBG_OFF
76-
#define SYS_DEBUG LWIP_DBG_OFF
77-
#define TCP_DEBUG LWIP_DBG_OFF
78-
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
79-
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
80-
#define TCP_RTO_DEBUG LWIP_DBG_OFF
81-
#define TCP_CWND_DEBUG LWIP_DBG_OFF
82-
#define TCP_WND_DEBUG LWIP_DBG_OFF
83-
#define TCP_FR_DEBUG LWIP_DBG_OFF
84-
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
85-
#define TCP_RST_DEBUG LWIP_DBG_OFF
86-
#define UDP_DEBUG LWIP_DBG_OFF
87-
#define TCPIP_DEBUG LWIP_DBG_OFF
88-
#define PPP_DEBUG LWIP_DBG_OFF
89-
#define SLIP_DEBUG LWIP_DBG_OFF
90-
#define DHCP_DEBUG LWIP_DBG_OFF
62+
#define ETHARP_DEBUG LWIP_DBG_OFF
63+
#define NETIF_DEBUG LWIP_DBG_OFF
64+
#define PBUF_DEBUG LWIP_DBG_OFF
65+
#define API_LIB_DEBUG LWIP_DBG_OFF
66+
#define API_MSG_DEBUG LWIP_DBG_OFF
67+
#define SOCKETS_DEBUG LWIP_DBG_OFF
68+
#define ICMP_DEBUG LWIP_DBG_OFF
69+
#define INET_DEBUG LWIP_DBG_OFF
70+
#define IP_DEBUG LWIP_DBG_OFF
71+
#define IP_REASS_DEBUG LWIP_DBG_OFF
72+
#define RAW_DEBUG LWIP_DBG_OFF
73+
#define MEM_DEBUG LWIP_DBG_OFF
74+
#define MEMP_DEBUG LWIP_DBG_OFF
75+
#define SYS_DEBUG LWIP_DBG_OFF
76+
#define TCP_DEBUG LWIP_DBG_OFF
77+
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
78+
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
79+
#define TCP_RTO_DEBUG LWIP_DBG_OFF
80+
#define TCP_CWND_DEBUG LWIP_DBG_OFF
81+
#define TCP_WND_DEBUG LWIP_DBG_OFF
82+
#define TCP_FR_DEBUG LWIP_DBG_OFF
83+
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
84+
#define TCP_RST_DEBUG LWIP_DBG_OFF
85+
#define UDP_DEBUG LWIP_DBG_OFF
86+
#define TCPIP_DEBUG LWIP_DBG_OFF
87+
#define PPP_DEBUG LWIP_DBG_OFF
88+
#define SLIP_DEBUG LWIP_DBG_OFF
89+
#define DHCP_DEBUG LWIP_DBG_OFF
9190

9291
#endif /* __LWIPOPTS_H__ */

main.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
static void main1(void) {
2020
// allow pausing core 1 while writing to flash
2121
multicore_lockout_victim_init();
22-
multicore_fifo_push_blocking(1); // signal core 0: ready
22+
multicore_fifo_push_blocking(1); // signal core 0: ready
2323

2424
keypad_init();
25-
25+
2626
while (true) {
2727
char key = keypad_get_key();
2828
if (key) {
@@ -54,8 +54,7 @@ static void boot_network(void) {
5454
// Block until first NTP sync succeeds - beep + retry on failure
5555
printf("[main] waiting for NTP sync...\r\n");
5656
while (!ntp_sync()) {
57-
printf("[main] NTP sync failed, retrying in %ds...\r\n",
58-
NTP_RETRY_INTERVAL_S);
57+
printf("[main] NTP sync failed, retrying in %ds...\r\n", NTP_RETRY_INTERVAL_S);
5958
buzzer_beep_short();
6059
sleep_ms(NTP_RETRY_INTERVAL_S * 1000);
6160
}
@@ -65,27 +64,27 @@ static void boot_network(void) {
6564

6665
int main(void) {
6766
stdio_init_all();
68-
67+
6968
buzzer_init();
7069
latch_init();
7170
light_init();
7271

7372
buzzer_beep_short();
74-
73+
7574
// Core 1 must be running and ready before any flash writes
7675
multicore_launch_core1(main1);
77-
multicore_fifo_pop_blocking(); // wait for core 1 ready signal
76+
multicore_fifo_pop_blocking(); // wait for core 1 ready signal
7877

7978
storage_init();
8079

8180
boot_network();
82-
81+
8382
// Startup beep - signals boot completed
8483
buzzer_beep_short();
8584
buzzer_beep_short();
86-
85+
8786
console_init();
88-
87+
8988
while (true) {
9089
console_task();
9190
ntp_task();

0 commit comments

Comments
 (0)