Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rauhul committed Dec 12, 2024
1 parent 7f52bd1 commit e0158cb
Show file tree
Hide file tree
Showing 20 changed files with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
//
//===----------------------------------------------------------------------===//

func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (LED Blink)")
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (LED Blink)")
}
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, Embedded Swift! (LED Blink)")

let led = LED()
Expand Down
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, Embedded Swift! (LED Blink)")

let led = LED()
Expand Down
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, Embedded Swift! (LED Blink)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (Smart Light)")
}
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, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
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, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
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, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
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, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
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, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
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, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
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, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
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, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@

@Steps {
@Step {
We start the application by declaring an **`app_main`** function with a print statement to show the application has started.

`app_main` serves the same purpose as a `main` function in a traditional user-land application and acts as the primary entry point for our firmware application.
We start the application by declaring an **`main`** function with a print statement to show the application has started.

@Code(name: "Main.swift", file: "walkthrough-example-led-blink-01.swift", previousFile: "walkthrough-example-led-blink-00.swift")
}

@Step {
We use the **`@_cdecl("app_main")`** attribute to generate a wrapper C symbol which is expected by ESP IDF.

> Important: Underscored attributes, like `@_cdecl`, are unstable features of the Swift compiler and may change behavior or break between compiler versions.

@Code(name: "Main.swift", file: "walkthrough-example-led-blink-02.swift", previousFile: "walkthrough-example-led-blink-01.swift")
Expand Down
2 changes: 1 addition & 1 deletion empty-template/main/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift!")
}
2 changes: 1 addition & 1 deletion led-blink/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, Embedded Swift! (LED Blink)")

let led = LED()
Expand Down
10 changes: 0 additions & 10 deletions smart-light/Matter/Clusters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ protocol MatterConcreteCluster: MatterCluster {
struct ClusterID<Cluster: MatterCluster>: RawRepresentable {
var rawValue: UInt32

init(rawValue: UInt32) { self.rawValue = rawValue }

static var identify: ClusterID<Identify> { .init(rawValue: 0x0000_0003) }
static var onOff: ClusterID<OnOff> { .init(rawValue: 0x0000_0006) }
static var levelControl: ClusterID<LevelControl> {
Expand Down Expand Up @@ -65,8 +63,6 @@ struct Identify: MatterConcreteCluster {
static var clusterTypeId: ClusterID<Self> { .identify }
struct AttributeID<Attribute: MatterAttribute>: MatterAttributeID {
var rawValue: UInt32

init(rawValue: UInt32) { self.rawValue = rawValue }
}

var cluster: UnsafeMutablePointer<esp_matter.cluster_t>
Expand All @@ -87,8 +83,6 @@ struct OnOff: MatterConcreteCluster {
struct AttributeID<Attribute: MatterAttribute>: MatterAttributeID {
var rawValue: UInt32

init(rawValue: UInt32) { self.rawValue = rawValue }

static var state: AttributeID<OnOffState> { .init(rawValue: 0x0000_0000) }
}

Expand All @@ -112,8 +106,6 @@ struct LevelControl: MatterConcreteCluster {
struct AttributeID<Attribute: MatterAttribute>: MatterAttributeID {
var rawValue: UInt32

init(rawValue: UInt32) { self.rawValue = rawValue }

static var currentLevel: AttributeID<CurrentLevel> {
.init(rawValue: 0x0000_0000)
}
Expand All @@ -139,8 +131,6 @@ struct ColorControl: MatterConcreteCluster {
struct AttributeID<Attribute: MatterAttribute>: MatterAttributeID {
var rawValue: UInt32

init(rawValue: UInt32) { self.rawValue = rawValue }

static var currentHue: AttributeID<CurrentHue> {
.init(rawValue: 0x0000_0000)
}
Expand Down
8 changes: 4 additions & 4 deletions smart-light/Matter/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ struct RootNode: MatterNode {
MatterAttributeEvent, Endpoint, Cluster, UInt32,
UnsafeMutablePointer<esp_matter_attr_val_t>?
) -> Void
typealias identifyCallback = (
typealias IdentifyCallback = (
esp_matter.identification.callback_type_t, UInt16, UInt8, UInt8
) -> Void

final class Context {
var attribute: AttributeCallback
var identify: identifyCallback
var identify: IdentifyCallback

init(
attribute: @escaping AttributeCallback,
identify: @escaping identifyCallback
identify: @escaping IdentifyCallback
) {
self.attribute = attribute
self.identify = identify
Expand All @@ -57,7 +57,7 @@ struct RootNode: MatterNode {
let context: Context

init?(
attribute: @escaping AttributeCallback, identify: @escaping identifyCallback
attribute: @escaping AttributeCallback, identify: @escaping IdentifyCallback
) {
var nodeConfig = esp_matter.node.config_t()
esp_matter.attribute.set_callback_shim {
Expand Down
2 changes: 1 addition & 1 deletion smart-light/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, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down

0 comments on commit e0158cb

Please sign in to comment.