Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Actions #77

Merged
merged 27 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/build-esp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build ESP Examples

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
schedule:
# Build on Mondays at 9am PST every week
- cron: '0 17 * * 1'

jobs:
build-esp:
runs-on: ubuntu-24.04
container: espressif/idf:latest
strategy:
fail-fast: false
matrix:
example: [esp32-led-blink-sdk, esp32-led-strip-sdk]
swift: [swift-DEVELOPMENT-SNAPSHOT-2024-12-04-a]

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install apt dependencies
run: apt-get -qq update && apt-get -qq -y install pkg-config

- name: Install ${{ matrix.swift }}
run: |
wget -q https://download.swift.org/development/ubuntu2404/${{ matrix.swift }}/${{ matrix.swift }}-ubuntu24.04.tar.gz
tar xzf ${{ matrix.swift }}-ubuntu24.04.tar.gz
export PATH="$PATH:`pwd`/${{ matrix.swift }}-ubuntu24.04/usr/bin/"
echo "PATH=$PATH" >> $GITHUB_ENV
swiftc --version

- name: Build ${{ matrix.example }}
run: |
cd $IDF_PATH
. ./export.sh
cd -
cd ${{ matrix.example }}
idf.py set-target esp32c6
idf.py build
65 changes: 65 additions & 0 deletions .github/workflows/build-pico-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build Pico SDK Examples

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
schedule:
# Build on Mondays at 9am PST every week
- cron: '0 17 * * 1'

jobs:
build-pico-sdk:
runs-on: ubuntu-22.04
container: swiftlang/swift:nightly-main-jammy
strategy:
fail-fast: false
matrix:
example:
- name: pico-blink-sdk
board: pico
- name: pico-w-blink-sdk
board: pico_w

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install apt dependencies
run: apt-get -qq update && apt-get -qq -y install curl ninja-build python3

- name: Install CMake 3.30.2
run: |
ARCH=`uname -m`
curl -sL https://github.com/Kitware/CMake/releases/download/v3.30.2/cmake-3.30.2-linux-$ARCH.tar.gz -O
tar xzf cmake-3.30.2-linux-$ARCH.tar.gz
export PATH="`pwd`/cmake-3.30.2-linux-$ARCH/bin:$PATH"
echo "PATH=$PATH" >> $GITHUB_ENV
cmake --version

- name: Clone Pico SDK
run: |
git clone https://github.com/raspberrypi/pico-sdk.git
cd pico-sdk
git submodule update --init --recursive
cd ..

- name: Download GNU ARM toolchain
run: |
ARCH=`uname -m`
curl -sL https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-$ARCH-arm-none-eabi.tar.xz -O
tar xf arm-gnu-toolchain-13.3.rel1-$ARCH-arm-none-eabi.tar.xz

- name: Set Pico environment variables
run: |
ARCH=`uname -m`
echo "PICO_BOARD=${{ matrix.example.board }}" >> $GITHUB_ENV
echo "PICO_SDK_PATH=`pwd`/pico-sdk" >> $GITHUB_ENV
echo "PICO_TOOLCHAIN_PATH=`pwd`/arm-gnu-toolchain-13.3.rel1-$ARCH-arm-none-eabi" >> $GITHUB_ENV

- name: Build ${{ matrix.example.name }}
run: |
cd ${{ matrix.example.name }}
cmake -B build -G Ninja .
cmake --build build
47 changes: 47 additions & 0 deletions .github/workflows/build-zephyr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build Zephyr Examples

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
schedule:
# Build on Mondays at 9am PST every week
- cron: '0 17 * * 1'

jobs:
build-zephyr:
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
example: [nrfx-blink-sdk]
swift: [swift-DEVELOPMENT-SNAPSHOT-2024-12-04-a]

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Setup Zephyr project
uses: zephyrproject-rtos/action-zephyr-setup@v1
with:
app-path: ${{ matrix.example }}
toolchains: arm-zephyr-eabi

- name: Install ${{ matrix.swift }}
run: |
wget -q https://download.swift.org/development/ubuntu2404/${{ matrix.swift }}/${{ matrix.swift }}-ubuntu24.04.tar.gz
tar xzf ${{ matrix.swift }}-ubuntu24.04.tar.gz
export PATH="$PATH:`pwd`/${{ matrix.swift }}-ubuntu24.04/usr/bin/"
echo "PATH=$PATH" >> $GITHUB_ENV
swiftc --version

- name: Build ${{ matrix.example }}
working-directory: ${{ matrix.example }}
run: west build -b nrf52840dk/nrf52840
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
container: swift:6.0-jammy

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install apt dependencies
run: apt-get -qq update && apt-get -qq -y install curl

- name: Compare against swift-mmio swift-format config
run: |
curl -sL https://raw.githubusercontent.com/apple/swift-mmio/refs/heads/main/SupportingFiles/Tools/swift-format/.swift-format -o .swift-format-mmio
diff .swift-format .swift-format-mmio

- name: Lint
run: swift-format lint --recursive --strict .
69 changes: 69 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentation" : {
"spaces" : 2
},
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 80,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : false,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : true,
"NeverUseForceTry" : true,
"NeverUseImplicitlyUnwrappedOptionals" : true,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : false,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"TypeNamesShouldBeCapitalized" : true,
"UseEarlyExits" : true,
"UseLetInEveryBoundCaseVariable" : true,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : true,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : true
},
"spacesBeforeEndOfLineComments": 2,
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 2,
"version" : 1
}
2 changes: 1 addition & 1 deletion esp32-led-blink-sdk/main/Led.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Led {
fatalError("cannot reset led")
}
}
func setLed(value:Bool) {
func setLed(value: Bool) {
let level: UInt32 = value ? 1 : 0
gpio_set_level(ledPin, level)
}
Expand Down
22 changes: 11 additions & 11 deletions esp32-led-blink-sdk/main/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
//
//===----------------------------------------------------------------------===//

//The code will blink an LED on GPIO8. To change the pin, modify Led(gpioPin: 8)
// The code will blink an LED on GPIO8. To change the pin, modify Led(gpioPin: 8)
@_cdecl("app_main")
func app_main() {
print("Hello from Swift on ESP32-C6!")
func main() {
print("Hello from Swift on ESP32-C6!")

var ledValue: Bool = false
let blinkDelayMs: UInt32 = 500
let led = Led(gpioPin: 8)
var ledValue: Bool = false
let blinkDelayMs: UInt32 = 500
let led = Led(gpioPin: 8)

while true {
led.setLed(value: ledValue)
ledValue.toggle() // Toggle the boolean value
vTaskDelay(blinkDelayMs / (1000 / UInt32(configTICK_RATE_HZ)))
}
while true {
led.setLed(value: ledValue)
ledValue.toggle() // Toggle the boolean value
vTaskDelay(blinkDelayMs / (1000 / UInt32(configTICK_RATE_HZ)))
}
}
22 changes: 13 additions & 9 deletions esp32-led-strip-sdk/main/LedStrip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// A simple "overlay" to provide nicer APIs in Swift
struct LedStrip {
private let handle: led_strip_handle_t

init(gpioPin: Int, maxLeds: Int) {
var handle = led_strip_handle_t(bitPattern: 0)
var stripConfig = led_strip_config_t(
Expand All @@ -26,24 +27,27 @@ struct LedStrip {
spi_bus: SPI2_HOST,
flags: .init(with_dma: 1)
)
guard led_strip_new_spi_device(&stripConfig, &spiConfig, &handle) == ESP_OK else {
fatalError("cannot configure spi device")
}
self.handle = handle!
guard led_strip_new_spi_device(&stripConfig, &spiConfig, &handle) == ESP_OK,
let handle = handle
else { fatalError("cannot configure spi device") }
self.handle = handle
}

struct Color {
var r, g, b: UInt8
struct Color {
static var white = Color(r: 255, g: 255, b: 255)
static var lightWhite = Color(r: 16, g: 16, b: 16)
static var lightRandom: Color {
Color(r: .random(in: 0...16), g: .random(in: 0...16), b: .random(in: 0...16))
static var lightRandom: Color {
Color(
r: .random(in: 0...16), g: .random(in: 0...16), b: .random(in: 0...16))
}
static var off = Color(r: 0, g: 0, b: 0)

var r, g, b: UInt8
}

func setPixel(index: Int, color: Color) {
led_strip_set_pixel(handle, UInt32(index), UInt32(color.r), UInt32(color.g), UInt32(color.b))
led_strip_set_pixel(
handle, UInt32(index), UInt32(color.r), UInt32(color.g), UInt32(color.b))
}

func refresh() { led_strip_refresh(handle) }
Expand Down
6 changes: 3 additions & 3 deletions esp32-led-strip-sdk/main/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("Hello from Swift on ESP32-C6!")

let n = 8
Expand All @@ -22,11 +22,11 @@ func app_main() {
colors.removeLast()
colors.insert(.lightRandom, at: 0)

for index in 0 ..< n {
for index in 0..<n {
ledStrip.setPixel(index: index, color: colors[index])
}
ledStrip.refresh()

let blinkDelayMs: UInt32 = 500
vTaskDelay(blinkDelayMs / (1000 / UInt32(configTICK_RATE_HZ)))
}
Expand Down
3 changes: 2 additions & 1 deletion nrfx-blink-sdk/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ struct Main {
static func main() {
// Note: & in Swift is not the "address of" operator, but on a global variable declared in C
// it will give the correct address of the global.
gpio_pin_configure_dt(&led0, GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH | GPIO_OUTPUT_INIT_LOGICAL)
gpio_pin_configure_dt(
&led0, GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH | GPIO_OUTPUT_INIT_LOGICAL)
while true {
gpio_pin_toggle_dt(&led0)
k_msleep(100)
Expand Down
13 changes: 13 additions & 0 deletions nrfx-blink-sdk/west.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
manifest:
remotes:
- name: zephyrproject-rtos
url-base: https://github.com/zephyrproject-rtos

projects:
- name: zephyr
remote: zephyrproject-rtos
revision: main
import:
name-allowlist:
- cmsis # required by the ARM port
- hal_nordic # required by the custom_plank board (Nordic based)
2 changes: 1 addition & 1 deletion pico-blink-sdk/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Main {
static func main() {
let led = UInt32(PICO_DEFAULT_LED_PIN)
gpio_init(led)
gpio_set_dir(led, /*out*/true)
gpio_set_dir(led, /*out*/ true)
while true {
gpio_put(led, true)
sleep_ms(250)
Expand Down
Loading
Loading