Skip to content

A lightweight Embedded Swift library that provides a clean, Swift-native interface for working with the UART driver

License

Notifications You must be signed in to change notification settings

lawrencebensaid/SwiftUART

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUART

SwiftUART is a lightweight Embedded Swift library that provides a clean, Swiftly interface for the platform's UART driver (currently only ESP-IDF). It supports configurable pins, flow control, parity, and async reads with task-based callbacks. Designed for ESP32, it integrates seamlessly with Swift-based embedded projects. STM32 support is on the horizon, aiming to provide cross-platform UART access using a consistent Swift API.

Any pull-requests from the community are more than welcome.

Support

Status Notes
ESP-IDF ✅ Supported Tested with ESP32-C6 / IDF v5.4.1
STM32 🚧 Planned On the roadmap

Installation (ESP-IDF)

1. Download library: Place this library where you like in your project. For example /main/lib/SwiftUART.

mkdir main/lib
cd main/lib
git clone git@github.com:lawrencebensaid/SwiftUART.git

2. Add compile source: In your project main/CMakeLists.txt, add lib/SwiftUART/src/*.swift to your Swift target_sources() like so:

target_sources(
    PRIVATE
    Main.swift  <- (Your own project files)
    ...
    lib/SwiftUART/src/*.swift   <- (SwiftUART)
)

3. Add IDF component: In your idf_component.yml, add SwiftUART to your dependencies like so:

dependencies:
  SwiftUART:
    path: lib/SwiftUART

Done!

Usage

Example 1: Writing

// Install driver

let uart = UART(.num1, txPin: 1, rxPin: 2, baudRate: .s115200)


// Flush & write

uart.flush()

uart.write("AT")


// Reading syncronously

if let res = uart.read() {
    print("Response \(res)")
}


// Reading asyncronously

uart.read(timeout: 1000) { res in
    print("Response \(res)")
}

License

SwiftUART is licensed under the Business Source License 1.1.

  • ✅ Free for personal, academic, and open-source use.
  • 💼 Commercial use requires a commercial license.
    Fair-use terms are available — contact lawrencebensaid@icloud.com.

🕒 On 1 January 2035, this project will be re-licensed under the MIT License.

About

A lightweight Embedded Swift library that provides a clean, Swift-native interface for working with the UART driver

Topics

Resources

License

Stars

Watchers

Forks

Languages