Created
June 7, 2016 05:25
-
-
Save colemancda/b3d9cd90c5c4eef293159a4d1c8d0a55 to your computer and use it in GitHub Desktop.
SunXi Extensions for SwiftyGPIO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SunXi.swift | |
// | |
// | |
// Created by Alsey Coleman Miller on 6/7/16. | |
// Copyright © 2016 ColemanCDA. All rights reserved. | |
// | |
public struct SunXiGPIO: CustomStringConvertible, Equatable { | |
// MARK: - Properties | |
public var letter: Letter | |
public var pin: UInt | |
// MARK: - Initialization | |
public init(letter: Letter, pin: UInt) { | |
self.letter = letter | |
self.pin = pin | |
} | |
// MARK: - Computed Properties | |
public var description: String { | |
return pinName | |
} | |
public var pinName: String { | |
return "P" + "\(letter)" + "\(pin)" | |
} | |
public var gpioPin: Int { | |
return (letter.rawValue * 32) + Int(pin) | |
} | |
} | |
// MARK: - Equatable | |
public func == (lhs: SunXiGPIO, rhs: SunXiGPIO) -> Bool { | |
return lhs.letter == rhs.letter && lhs.pin == rhs.pin | |
} | |
// MARK: - Supporting Types | |
public extension SunXiGPIO { | |
public enum Letter: Int { | |
case A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z | |
} | |
} | |
// MARK: - Extensions | |
public extension GPIO { | |
convenience init(sunXi: SunXiGPIO) { | |
self.init(name: sunXi.pinName, id: sunXi.gpioPin) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment