   ([type]
    (create-board type {}))
   ([type config]
-   (impl/instantiate type config)))
+   (Board. (atom {}) (impl/instantiate type config))))
 
 ;; What follows then are a suite of simple tools for dealing with the boards.
 

  [f pin & args]
  (apply f (:board pin) (:pin-n pin) args))



;; The usage pattern involves first setting the edge detection mode of the pin, then tapping into a central
;; channel and using that tap to convey messages of state changes throughout the app.


(defn set-edge-chan!
  "Set the edge channel for the specified pin. If there is an existing channel for the pin, it will be
  closed."
  ([board pin-n ch]
   (sw/set-edge-chan! board pin-n ch))
  ([pin ch]
   (board-apply sw/set-edge-chan! pin ch)))

(defn get-edge-chan
  "Get the current edge channel for the specified pin."
  ([board pin-n]
   (sw/get-edge-chan board pin-n))
  ([pin]
   (board-apply sw/get-edge-chan pin)))

(defmulti set-edge!
  "Set the edge direction of a pin. Accepts `:falling`, `:rising`, `:both` and `:none` edges.
  Args should either be `[pin edge & [ch-or-buffer]]` or `[board pin-n edge & [ch-or-buffer]]`.
  Edge events will be placed on the specified channel or one that is created with the given buffer.
  If ch-or-buffer is not specified, an unbeffered chan is returned.
  The channel can be changed with `set-edge-chan!` and retrieved with `get-edge-chan`."
  board-dispatch)

(defmethod set-edge! true
  [board pin-n edge & [ch-or-buffer]]
  (let [current-ch (get-edge-chan board pin-n)
        ch (cond
             (chan? ch-or-buffer) ch
             ch-or-buffer         (chan ch-or-buffer)
             current-ch           current-ch
             :else                (chan))]
    (sw/set-edge-chan! board pin-n ch)
    (pcp/set-edge! board pin-n edge ch)))

(defmethod set-edge! false
  [pin edge & [ch-or-buffer]]
  (board-apply set-edge! pin edge ch-or-buffer))


;; ### Some helper functions for navigating through boards and pins.

;; Nothing to see here...

;(defn- board?
  ;[obj]
  ;(satisfies? p/PBoard obj))
(defn- board?
  [obj]
  (= (type obj) Board))

(defn- board-dispatch
  [x & args] (board? x))
