# Copyright (C) 2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cyanobyte: 0.1.0
info:
  contact:
    name: Nick Felker, Chris Frederickson
    url: https://github.com/google/cyanobyte
    email: felker@google.com
  package: com.cyanobyte
  title: MCP4725
  description: Microchip 4725 Digital-to-Analog Converter
  copyright:
    name: Google Inc.
    date: '2019'
  license:
    name: Apache-2.0
  version: 0.1.0

i2c:
  addressType: 7-bit
  address: 0x62
  addressMask: 0x60
  endian: little

registers:
  VOut:
    address: 0x40
    length: 12
    title: Output voltage
    description: |
      VOut = (Vcc * value) / 4096
      The output is a range between 0 and Vcc with
      steps of Vcc/4096.
      In a 3.3v system, each step is 800 microvolts.
  EEPROM:
    address: 0x60
    length: 12
    title: EEPROM
    description: |
      If EEPROM is set, the saved voltage output will
      be loaded from power-on.

fields:
  digitalOut:
    title: Digital (binary) output
    description: |
      Only allows you to send fully on or off
    register: '#/registers/EEPROM'
    readWrite: 'R/W'
    bitStart: 12
    bitEnd: 0
    type: 'enum'
    enum:
      VCC:
        title: Vcc (full power)
        value: 0b111111111111
      GND:
        title: Ground
        value: 0b000000000000
functions:
  setVOut:
    title: Set output voltage
    description: set vout
    type: number
    register: '#/registers/EEPROM'
    bitStart: 12
    bitEnd: 0
    computed:
      asVoltage:
        input:
          vcc: float32
          output: float32
        logic:
          - output: = output / vcc * 4096
          - send: output
  getVOut:
    title: Get output voltage
    description: get vout
    type: number
    register: '#/registers/EEPROM'
    bitStart: 12
    bitEnd: 0
    computed:
      asVoltage:
        input:
          vcc: float32
          value: float32 # automatically pulls value
        variables:
          voltage: float32
        logic:
          - voltage: = value / 4096 * vcc
        return: voltage
