cyanobyte: 0.1.0
info:
  title: TCS3472
  description: Color Light-to-Digital Converter with IR Filter
  package: com.cyanobyte
  contact:
    name: Nick Felker
    url: https://ams.com/documents/20143/36005/TCS3472_DS000390_2-00.pdf
    email: felker@google.com
  copyright:
    name: Google Inc.
    date: '2019'
  license:
    name: Apache-2.0
  version: 0.1.0

i2c:
  addressType: 7-bit
  address: 0x29
  addressMask: 0xFF

registers:
  # TCS3472 has a Command Register that all commands need to go through:
  #
  # | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  # | 1 | Incre | Address Field     |
  #
  # Hence, the Clear register actually needs to be addressed as:
  #
  # 0b1000,0000 OR 0b0010,0000 OR 0x14 = 180 = 0xB0
  enable:
    address: 0x80
    length: 8
    title: Enable
    description: Enable specific components of the peripheral
  clear:
    address: 0xB4
    length: 16
    readWrite: 'R'
    title: Clear channel
    description: This is the ambient amount of detected light.
  red:
    address: 0xB6
    length: 16
    readWrite: 'R'
    title: Red channel
    description: Red light as an int. Divide by ambient light to get scaled number.
    # Implementation note: float(light.get_red()) / light.get_clear() * 255 -> Red color value
  green:
    address: 0xB8
    length: 16
    readWrite: 'R'
    title: Green channel
    description: Green light as an int. Divide by ambient light to get scaled number.
  blue:
    address: 0xBA
    length: 16
    readWrite: 'R'
    title: Blue channel
    description: Blue light as an int. Divide by ambient light to get scaled number.

fields:
  init:
    title: Setup the device configuration
    description: Enable RGBC and Power
    register: '#/registers/enable'
    readWrite: 'R/W'
    bitStart: 7 # The whole register
    bitEnd: 0
    type: 'enum'
    enum:
      Power:
        title: Power
        value: 1
      RGBC:
        title: Color
        value: 0b10

functions:
  _lifecycle:
    title: Code to run when device class is constructed
    description: Enables features on device
    register: '#/registers/enable'
    computed:
      Begin:
        variables:
          enables: int8
        logic:
          # Enable register = ENABLE_RGBC | ENABLE_POWER
          - enables:
            - sum:
              - 1
              - 0b10
          - send: enables
