Crystal Bus
A simple library used to create an IO bus and attach connectors to read and write data on the bus.
Installation
- Add
cry-busto yourshard.yml:
dependencies:
cry-bus:
github: D-Shwagginz/cry-bus
- Run
shards install
Usage
For a guide check out the docs
Make sure to check out the examples!
Quick example of using Crybus to connect two registers to be written to and read from on a bus:
require "cry-bus"
class Register < Crybus::Circuit
@data : UInt8 = 0
def output(address : UInt32) : UInt8
return @data
end
def input(address : UInt32, data : UInt8)
@data = data
end
def initialize(bus : Crybus::Bus, address : UInt32)
bus.connect(@connector)
@connector.segments << Crybus::Connector::Segment.new(address, ->output(UInt32), ->input(UInt32, UInt8))
end
end
bus = Crybus::Bus.new
Register.new(bus, 0)
Register.new(bus, 1)
You can now bus.read(address) and bus.write(address, data) to registers at 0x00 and 0x01!
Contributing
- Fork it (https://github.com/your-github-user/cry-bus/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- D. Shwagginz - creator and maintainer