Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
build:
uses: madmachineio/actions/.github/workflows/build.yml@main
with:
runners: '["ubuntu-24.04", "macos-13"]'
runners: '["ubuntu-24.04", "macos-15"]'
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ let package = Package(
// use specific library would speed up the compile procedure
.product(name: "IS31FL3731", package: "MadDrivers")
]),
.testTarget(
name: "FrameTests",
dependencies: ["Frame"]),
]
)
1 change: 0 additions & 1 deletion Examples/IS31FL3731/Frame/Sources/Frame/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import SwiftIO
import MadBoard
import IS31FL3731
import MadDisplay

let i2c = I2C(Id.I2C0)
let led = IS31FL3731(i2c)
Expand Down
47 changes: 0 additions & 47 deletions Examples/IS31FL3731/Frame/Tests/FrameTests/FrameTests.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let package = Package(
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
.package(url: "https://github.com/madmachineio/CFreeType.git", from: "2.13.2"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand All @@ -18,10 +19,8 @@ let package = Package(
"SwiftIO",
"MadBoards",
// use specific library would speed up the compile procedure
.product(name: "IS31FL3731", package: "MadDrivers")
.product(name: "IS31FL3731", package: "MadDrivers"),
"CFreeType",
]),
.testTarget(
name: "ScrollingTextTests",
dependencies: ["ScrollingText"]),
]
)
Binary file not shown.
35 changes: 27 additions & 8 deletions Examples/IS31FL3731/ScrollingText/Sources/ScrollingText/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@
import SwiftIO
import MadBoard
import IS31FL3731
import MadDisplay
import MadGraphics

let i2c = I2C(Id.I2C0)
let led = IS31FL3731(i2c)
let display = MadDisplay(screen: led)
let group = Group()
let screen = IS31FL3731(i2c)

let text = Label(y: 4, text: "Hello", font: ASCII8())
group.append(text)
var screenBuffer = [UInt8](repeating: 0, count: screen.width * screen.height)
var frameBuffer = [UInt32](repeating: 0, count: screen.width * screen.height)

let robotoFont = Font(path: "/lfs/Resources/Fonts/RobotoMono-VariableFont_wght.ttf" , pointSize: 12)

let rootLayer = Layer(width: screen.width, height: screen.height, backgroundColor: Pixel.black)
rootLayer.render(into: &frameBuffer, output: &screenBuffer, transform: Pixel.toGray) { dirty, data in
screen.writeBitmap(x: dirty.x, y: dirty.y, width: dirty.width, height: dirty.height, data: data)
}

let text = TextLayer(at: Point(x: 0, y: 0), string: "Hello", font: robotoFont, foregroundColor: Pixel.white)
rootLayer.append(text)

// It is decided by the width of your text.
let xmin = -24
Expand All @@ -20,10 +28,21 @@ let xmax = 16
while true {
// The text will scroll from right to left.
for x in (xmin...xmax).reversed() {
text.setX(x)
display.update(group)
text.position = Point(x: x, y: 0)
rootLayer.render(into: &frameBuffer, output: &screenBuffer, transform: Pixel.toGray) { dirty, data in
screen.writeBitmap(x: dirty.x, y: dirty.y, width: dirty.width, height: dirty.height, data: data)
}
sleep(ms: 100)
}
}


extension Pixel {
static func toGray(_ pixel: UInt32) -> UInt8 {
let r = (pixel >> 16) & 0xFF
let g = (pixel >> 8) & 0xFF
let b = pixel & 0xFF
// Use the luminosity method to convert RGB to grayscale.
return UInt8(0.299 * Float(r) + 0.587 * Float(g) + 0.114 * Float(b))
}
}

This file was deleted.

4 changes: 2 additions & 2 deletions Examples/ST7789/DrawPixels/Sources/DrawPixels/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftIO
import MadBoard
import ST7789

let spi = SPI(Id.SPI0, speed: 50_000_000)
let spi = SPI(Id.SPI0, speed: 30_000_000)
let cs = DigitalOut(Id.D9)
let dc = DigitalOut(Id.D10)
let rst = DigitalOut(Id.D14)
Expand All @@ -25,4 +25,4 @@ for x in 60..<180 {

while true {
sleep(ms: 1000)
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "DrawUsingMadDisplay",
name: "DrawUsingMadGraphics",
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
.package(url: "https://github.com/madmachineio/MadDisplay.git", branch: "main"),
.package(url: "https://github.com/madmachineio/CFreeType.git", from: "2.13.2"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.executableTarget(
name: "DrawUsingMadDisplay",
name: "DrawUsingMadGraphics",
dependencies: [
"SwiftIO",
"MadBoards",
"MadDisplay",
// use specific library would speed up the compile procedure
.product(name: "ST7789", package: "MadDrivers")
.product(name: "ST7789", package: "MadDrivers"),
"CFreeType",
]),
.testTarget(
name: "DrawUsingMadDisplayTests",
dependencies: ["DrawUsingMadDisplay"]),
]
)
17 changes: 17 additions & 0 deletions Examples/ST7789/DrawUsingMadGraphics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# DrawUsingMadGraphics

Use another library `MadGraphics` to draw graphics on the LCD. You'll fill the screen with yellow, draw an orange square in the middle and display the text "Hello world!".

## Library reference

* [SwiftIO](https://github.com/madmachineio/SwiftIO)
* [MadBoard](https://github.com/madmachineio/MadBoards)
* [ST7789](https://github.com/madmachineio/MadDrivers/tree/main/Sources/ST7789/ST7789.swift)
* [MadGraphics](https://madmachineio.github.io/MadGraphicsDocs/documentation/madgraphics/)


## How to use

1. Download the MadDrivers folder.
2. Open and run one of the examples in Visual Studio Code. If you are not familiar with the operation, you could refer to [this tutorial](https://docs.madmachine.io/overview/advanced/run-example).

Binary file not shown.
Binary file not shown.
Loading
Loading