Skip to content

Commit f73a592

Browse files
committed
Add ST7796 Examples
Signed-off-by: Andy Liu <[email protected]>
1 parent d401fea commit f73a592

File tree

13 files changed

+204
-2
lines changed

13 files changed

+204
-2
lines changed

Examples/ST7789/DrawPixels/Sources/DrawPixels/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SwiftIO
33
import MadBoard
44
import ST7789
55

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

2626
while true {
2727
sleep(ms: 1000)
28-
}
28+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This is a MadMachine project file in TOML format
2+
# This file holds those parameters that could not be managed by SwiftPM
3+
# Edit this file would change the behavior of the building/downloading procedure
4+
# Those project files in the dependent libraries would be IGNORED
5+
6+
# Specify the board name below
7+
# There are "SwiftIOBoard" and "SwiftIOMicro" now
8+
board = "SwiftIOMicro"
9+
10+
# Specifiy the target triple below
11+
# There are "thumbv7em-unknown-none-eabi" and "thumbv7em-unknown-none-eabihf" now
12+
# If your code use significant floating-point calculation,
13+
# plz set it to "thumbv7em-unknown-none-eabihf"
14+
triple = "thumbv7em-unknown-none-eabi"
15+
16+
# Reserved for future use
17+
version = 1
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
import PackageDescription
4+
let package = Package(
5+
name: "DrawPixels",
6+
dependencies: [
7+
// Dependencies declare other packages that this package depends on.
8+
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
9+
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
10+
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
11+
],
12+
targets: [
13+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
14+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
15+
.executableTarget(
16+
name: "DrawPixels",
17+
dependencies: [
18+
"SwiftIO",
19+
"MadBoards",
20+
// use specific library would speed up the compile procedure
21+
.product(name: "ST7796", package: "MadDrivers")
22+
]),
23+
]
24+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# DrawPixels
2+
3+
Fill the LCD with white and draw a red square on the middle.
4+
5+
## Library reference
6+
7+
* [SwiftIO](https://github.com/madmachineio/SwiftIO)
8+
* [MadBoard](https://github.com/madmachineio/MadBoards)
9+
* [ST7789](https://github.com/madmachineio/MadDrivers/tree/main/Sources/ST7789/ST7789.swift)
10+
11+
12+
## How to use
13+
14+
1. Download the MadDrivers folder.
15+
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).
16+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Draw a red square on a white background on the screen.
2+
import SwiftIO
3+
import MadBoard
4+
import ST7796
5+
6+
let spi = SPI(Id.SPI0, speed: 30_000_000)
7+
let cs = DigitalOut(Id.D1)
8+
let dc = DigitalOut(Id.D5)
9+
let rst = DigitalOut(Id.D0)
10+
let bl = DigitalOut(Id.D2)
11+
12+
let screen = ST7796(spi: spi, cs: cs, dc: dc, rst: rst, bl: bl)
13+
14+
let white: UInt16 = 0xFFFF
15+
let red: UInt16 = 0xF800
16+
17+
screen.clearScreen(white)
18+
sleep(ms: 1000)
19+
20+
for y in 100..<150 {
21+
for x in 100..<200 {
22+
screen.writePixel(x: x, y: y, color: red)
23+
}
24+
}
25+
26+
while true {
27+
sleep(ms: 1000)
28+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This is a MadMachine project file in TOML format
2+
# This file holds those parameters that could not be managed by SwiftPM
3+
# Edit this file would change the behavior of the building/downloading procedure
4+
# Those project files in the dependent libraries would be IGNORED
5+
6+
# Specify the board name below
7+
# There are "SwiftIOBoard" and "SwiftIOMicro" now
8+
board = "SwiftIOMicro"
9+
10+
# Specifiy the target triple below
11+
# There are "thumbv7em-unknown-none-eabi" and "thumbv7em-unknown-none-eabihf" now
12+
# If your code use significant floating-point calculation,
13+
# plz set it to "thumbv7em-unknown-none-eabihf"
14+
triple = "thumbv7em-unknown-none-eabi"
15+
16+
# Reserved for future use
17+
version = 1
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
import PackageDescription
4+
let package = Package(
5+
name: "DrawUsingMadGraphics",
6+
dependencies: [
7+
// Dependencies declare other packages that this package depends on.
8+
.package(url: "https://github.com/madmachineio/SwiftIO.git", branch: "main"),
9+
.package(url: "https://github.com/madmachineio/MadBoards.git", branch: "main"),
10+
.package(url: "https://github.com/madmachineio/MadDrivers.git", branch: "main"),
11+
.package(url: "https://github.com/madmachineio/CFreeType.git", from: "2.13.2"),
12+
],
13+
targets: [
14+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
15+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
16+
.executableTarget(
17+
name: "DrawUsingMadGraphics",
18+
dependencies: [
19+
"SwiftIO",
20+
"MadBoards",
21+
// use specific library would speed up the compile procedure
22+
.product(name: "ST7796", package: "MadDrivers"),
23+
"CFreeType",
24+
]),
25+
]
26+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# DrawUsingMadGraphics
2+
3+
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!".
4+
5+
## Library reference
6+
7+
* [SwiftIO](https://github.com/madmachineio/SwiftIO)
8+
* [MadBoard](https://github.com/madmachineio/MadBoards)
9+
* [ST7789](https://github.com/madmachineio/MadDrivers/tree/main/Sources/ST7789/ST7789.swift)
10+
* [MadGraphics](https://madmachineio.github.io/MadGraphicsDocs/documentation/madgraphics/)
11+
12+
13+
## How to use
14+
15+
1. Download the MadDrivers folder.
16+
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).
17+

0 commit comments

Comments
 (0)