     ;; this bus will always use the selected slave address for commands
     (i2c/select-slave bus slave-address)
 
-    ;; set int mirror and active-high
-    ;; The 4 bit causes the interrupt pins to be internally connected so
-    ;; that either interrupt causes both to be on.
-    ;; The active-high causes an interrupt to have high polarity when active.
-    ;; The IOCON register is shared between :a and :b so it only needs to be
-    ;; set for one bank.
-    (smbus/write-byte bus (get-in registers [:a :iocon]) 0x42)
+    ;; setup the chip with settings defined above in the iocon-settings object
+    ;; in particular, the interrupt pins should be mirrored and driven high
+    ;; when there's an interrupt.
+    (smbus/write-byte bus
+                      (get-in registers [:a :iocon])
+                      (Integer/parseInt (apply str iocon-settings) 2))
 
     ;; enable int on all pins
     ;; (smbus/write-byte bus (get-in mcp23017/register [:a :gpinten]) 0x04)

       :olat 0x15
       }
   })

(defn get-register
  "return the byte contents of a register"

;; All things specific to the mcp23017 chip. If you have to read the datasheet
;; or access the chip, it goes in this file. All else, no!
;; Datasheet: https://www.microchip.com/wwwproducts/en/MCP23017
;; The Microchip MCP23017 has 16-bit I/O port functionality via
;; two 8-bit ports (PORTA and PORTB). This should not be confused
;; with addressing modes BANK=0 or BANK=1.

(ns hsec.source.mcp23017
  (:require [dvlopt.linux.i2c       :as i2c]
            [dvlopt.linux.i2c.smbus :as smbus]))

(def registers
  {  ;; BANK=0 addressing (registers paired)
   :a  { ;; 'a' register, first 8 IO bits
        :iodir 0x00
        :ipol 0x02
        :gpinten 0x04
