-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
70 additions
and
87 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Denko | ||
module SPI | ||
module BusCommon | ||
include Behaviors::BusController | ||
include Behaviors::Reader | ||
extend Forwardable | ||
|
||
# Add peripheral to self and the board. It gets callbacks directly from the board. | ||
def add_component(component) | ||
# Ignore components with no select pin. Mostly for APA102. | ||
return unless component.pin | ||
|
||
pins = components.map { |c| c.pin } | ||
if pins.include? component.pin | ||
raise ArgumentError, "duplicate select pin for #{component}" | ||
end | ||
|
||
components << component | ||
board.add_component(component) | ||
end | ||
|
||
# Remove peripheral from self and the board. | ||
def remove_component(component) | ||
components.delete(component) | ||
board.remove_component(component) | ||
end | ||
|
||
# Forward pin control methods to the board, for select pin setup. | ||
def_delegator :board, :convert_pin | ||
def_delegator :board, :set_pin_mode | ||
|
||
# If a component calls #stop, that's just a call to Board#spi_stop giving its select pin. | ||
def_delegator :board, :spi_stop, :stop | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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