Library for MAXREFDES131 OneWire GridEYE sensor interface

Dependents:   MAXREFDES131_Qt_Demo MAXREFDES130_131_Demo

Committer:
j3
Date:
Sat Apr 30 01:27:34 2016 +0000
Revision:
1:9e457e35e2e3
Child:
2:b10e7a2961ab
Added API code from Panasonic to OWGridEye Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 1:9e457e35e2e3 1 /**********************************************************************
j3 1:9e457e35e2e3 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 1:9e457e35e2e3 3 *
j3 1:9e457e35e2e3 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 1:9e457e35e2e3 5 * copy of this software and associated documentation files (the "Software"),
j3 1:9e457e35e2e3 6 * to deal in the Software without restriction, including without limitation
j3 1:9e457e35e2e3 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 1:9e457e35e2e3 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 1:9e457e35e2e3 9 * Software is furnished to do so, subject to the following conditions:
j3 1:9e457e35e2e3 10 *
j3 1:9e457e35e2e3 11 * The above copyright notice and this permission notice shall be included
j3 1:9e457e35e2e3 12 * in all copies or substantial portions of the Software.
j3 1:9e457e35e2e3 13 *
j3 1:9e457e35e2e3 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 1:9e457e35e2e3 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 1:9e457e35e2e3 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 1:9e457e35e2e3 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 1:9e457e35e2e3 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 1:9e457e35e2e3 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 1:9e457e35e2e3 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 1:9e457e35e2e3 21 *
j3 1:9e457e35e2e3 22 * Except as contained in this notice, the name of Maxim Integrated
j3 1:9e457e35e2e3 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 1:9e457e35e2e3 24 * Products, Inc. Branding Policy.
j3 1:9e457e35e2e3 25 *
j3 1:9e457e35e2e3 26 * The mere transfer of this software does not imply any licenses
j3 1:9e457e35e2e3 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 1:9e457e35e2e3 28 * trademarks, maskwork rights, or any other form of intellectual
j3 1:9e457e35e2e3 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 1:9e457e35e2e3 30 * ownership rights.
j3 1:9e457e35e2e3 31 **********************************************************************/
j3 1:9e457e35e2e3 32
j3 1:9e457e35e2e3 33
j3 1:9e457e35e2e3 34 #include "OWGridEye.h"
j3 1:9e457e35e2e3 35 #include "grideye_api_lv1.h"
j3 1:9e457e35e2e3 36 #include "grideye_api_lv2.h"
j3 1:9e457e35e2e3 37 #include "grideye_api_lv3.h"
j3 1:9e457e35e2e3 38
j3 1:9e457e35e2e3 39
j3 1:9e457e35e2e3 40 //*********************************************************************
j3 1:9e457e35e2e3 41 OWGridEye::OWGridEye(OneWireMaster & owm, RomId & ds2413Rom)
j3 1:9e457e35e2e3 42 : _owm(owm), _sw_rom(ds2413Rom)
j3 1:9e457e35e2e3 43 {
j3 1:9e457e35e2e3 44 }
j3 1:9e457e35e2e3 45
j3 1:9e457e35e2e3 46
j3 1:9e457e35e2e3 47 //*********************************************************************
j3 1:9e457e35e2e3 48 OWGridEye::CmdResult OWGridEye::disconnectGridEye(void)
j3 1:9e457e35e2e3 49 {
j3 1:9e457e35e2e3 50 OWGridEye::CmdResult result = OWGridEye::OpFailure;
j3 1:9e457e35e2e3 51 Ds2413 ow_switch(_owm);
j3 1:9e457e35e2e3 52 uint8_t pio_state;
j3 1:9e457e35e2e3 53
j3 1:9e457e35e2e3 54 Ds2413::CmdResult sw_result = ow_switch.pio_access_read_chB(_sw_rom, pio_state);
j3 1:9e457e35e2e3 55 if(sw_result == Ds2413::Success)
j3 1:9e457e35e2e3 56 {
j3 1:9e457e35e2e3 57 //if high take low, falling edge puts bridge and sensor to sleep
j3 1:9e457e35e2e3 58 if(pio_state)
j3 1:9e457e35e2e3 59 {
j3 1:9e457e35e2e3 60 sw_result = ow_switch.pio_access_write_chB(_sw_rom, 0);
j3 1:9e457e35e2e3 61 if(sw_result == Ds2413::Success)
j3 1:9e457e35e2e3 62 {
j3 1:9e457e35e2e3 63 result = OWGridEye::Success;
j3 1:9e457e35e2e3 64 }
j3 1:9e457e35e2e3 65 }
j3 1:9e457e35e2e3 66 else
j3 1:9e457e35e2e3 67 {
j3 1:9e457e35e2e3 68 //if low, take high, then low to get falling edge
j3 1:9e457e35e2e3 69 sw_result = ow_switch.pio_access_write_chB(_sw_rom, 1);
j3 1:9e457e35e2e3 70 if(sw_result == Ds2413::Success)
j3 1:9e457e35e2e3 71 {
j3 1:9e457e35e2e3 72 sw_result = ow_switch.pio_access_write_chB(_sw_rom, 0);
j3 1:9e457e35e2e3 73 if(sw_result == Ds2413::Success)
j3 1:9e457e35e2e3 74 {
j3 1:9e457e35e2e3 75 result = OWGridEye::Success;
j3 1:9e457e35e2e3 76 }
j3 1:9e457e35e2e3 77 }
j3 1:9e457e35e2e3 78 }
j3 1:9e457e35e2e3 79 }
j3 1:9e457e35e2e3 80
j3 1:9e457e35e2e3 81 return result;
j3 1:9e457e35e2e3 82 }
j3 1:9e457e35e2e3 83
j3 1:9e457e35e2e3 84
j3 1:9e457e35e2e3 85 //*********************************************************************
j3 1:9e457e35e2e3 86 OWGridEye::CmdResult OWGridEye::connectGridEye(void)
j3 1:9e457e35e2e3 87 {
j3 1:9e457e35e2e3 88 OWGridEye::CmdResult result = OWGridEye::OpFailure;
j3 1:9e457e35e2e3 89
j3 1:9e457e35e2e3 90 Ds2413 ow_switch(_owm);
j3 1:9e457e35e2e3 91
j3 1:9e457e35e2e3 92 Ds2413::CmdResult sw_result = ow_switch.pio_access_write_chB(_sw_rom, 1);
j3 1:9e457e35e2e3 93 if(sw_result == Ds2413::Success)
j3 1:9e457e35e2e3 94 {
j3 1:9e457e35e2e3 95 result = OWGridEye::Success;
j3 1:9e457e35e2e3 96 }
j3 1:9e457e35e2e3 97
j3 1:9e457e35e2e3 98 return result;
j3 1:9e457e35e2e3 99 }
j3 1:9e457e35e2e3 100
j3 1:9e457e35e2e3 101
j3 1:9e457e35e2e3 102 //*********************************************************************
j3 1:9e457e35e2e3 103 OWGridEye::CmdResult OWGridEye::connectOWbus(void)
j3 1:9e457e35e2e3 104 {
j3 1:9e457e35e2e3 105 OWGridEye::CmdResult result = OWGridEye::OpFailure;
j3 1:9e457e35e2e3 106
j3 1:9e457e35e2e3 107 Ds2413 ow_switch(_owm);
j3 1:9e457e35e2e3 108
j3 1:9e457e35e2e3 109 Ds2413::CmdResult sw_result = ow_switch.pio_access_write_chA(_sw_rom, 0);
j3 1:9e457e35e2e3 110 if(sw_result == Ds2413::Success)
j3 1:9e457e35e2e3 111 {
j3 1:9e457e35e2e3 112 result = OWGridEye::Success;
j3 1:9e457e35e2e3 113 }
j3 1:9e457e35e2e3 114
j3 1:9e457e35e2e3 115 return result;
j3 1:9e457e35e2e3 116 }
j3 1:9e457e35e2e3 117
j3 1:9e457e35e2e3 118
j3 1:9e457e35e2e3 119 //*********************************************************************
j3 1:9e457e35e2e3 120 OWGridEye::CmdResult OWGridEye::disconnectOWbus(void)
j3 1:9e457e35e2e3 121 {
j3 1:9e457e35e2e3 122 OWGridEye::CmdResult result = OWGridEye::OpFailure;
j3 1:9e457e35e2e3 123
j3 1:9e457e35e2e3 124 Ds2413 ow_switch(_owm);
j3 1:9e457e35e2e3 125
j3 1:9e457e35e2e3 126 Ds2413::CmdResult sw_result = ow_switch.pio_access_write_chA(_sw_rom, 1);
j3 1:9e457e35e2e3 127 if(sw_result == Ds2413::Success)
j3 1:9e457e35e2e3 128 {
j3 1:9e457e35e2e3 129 result = OWGridEye::Success;
j3 1:9e457e35e2e3 130 }
j3 1:9e457e35e2e3 131
j3 1:9e457e35e2e3 132 return result;
j3 1:9e457e35e2e3 133 }
j3 1:9e457e35e2e3 134
j3 1:9e457e35e2e3 135
j3 1:9e457e35e2e3 136 //*********************************************************************
j3 1:9e457e35e2e3 137 OWGridEye::CmdResult OWGridEye::gridEyeAccess(bool readWrite, GridEyeRegister regAdrs, uint8_t numBytes, uint8_t * dataBuf)
j3 1:9e457e35e2e3 138 {
j3 1:9e457e35e2e3 139 OneWireMaster::CmdResult ow_result = OneWireMaster::OperationFailure;
j3 1:9e457e35e2e3 140 Ds28e17::CmdResult i2c_cmd_result;
j3 1:9e457e35e2e3 141 OWGridEye::CmdResult gridEye_result = OWGridEye::OpFailure;
j3 1:9e457e35e2e3 142
j3 1:9e457e35e2e3 143 Ds28e17 i2c_bridge(_owm);
j3 1:9e457e35e2e3 144
j3 1:9e457e35e2e3 145 OneWireMaster::SearchState search_state;
j3 1:9e457e35e2e3 146 search_state.romId.setFamilyCode(OWGridEye::DS28E17_FAMILY_CODE);
j3 1:9e457e35e2e3 147
j3 1:9e457e35e2e3 148 _owm.OWTargetSetup(search_state);
j3 1:9e457e35e2e3 149 ow_result = _owm.OWNext(search_state);
j3 1:9e457e35e2e3 150 if(ow_result == OneWireMaster::Success)
j3 1:9e457e35e2e3 151 {
j3 1:9e457e35e2e3 152 i2c_bridge.set_rom_id(search_state.romId);
j3 1:9e457e35e2e3 153 uint8_t read_pointer = regAdrs;
j3 1:9e457e35e2e3 154 uint8_t status, wr_status;
j3 1:9e457e35e2e3 155
j3 1:9e457e35e2e3 156 if(readWrite)
j3 1:9e457e35e2e3 157 {
j3 1:9e457e35e2e3 158 i2c_cmd_result = i2c_bridge.I2C_WriteReadDataWithStop((OWGridEye::I2C_ADRS << 1),
j3 1:9e457e35e2e3 159 1, &read_pointer, numBytes,
j3 1:9e457e35e2e3 160 status, wr_status, dataBuf);
j3 1:9e457e35e2e3 161 }
j3 1:9e457e35e2e3 162 else
j3 1:9e457e35e2e3 163 {
j3 1:9e457e35e2e3 164 i2c_cmd_result = i2c_bridge.I2C_WriteDataWithStop((OWGridEye::I2C_ADRS << 1),
j3 1:9e457e35e2e3 165 numBytes, dataBuf, status,
j3 1:9e457e35e2e3 166 wr_status);
j3 1:9e457e35e2e3 167 }
j3 1:9e457e35e2e3 168
j3 1:9e457e35e2e3 169 if(i2c_cmd_result == Ds28e17::Success)
j3 1:9e457e35e2e3 170 {
j3 1:9e457e35e2e3 171 gridEye_result = OWGridEye::Success;
j3 1:9e457e35e2e3 172 }
j3 1:9e457e35e2e3 173 }
j3 1:9e457e35e2e3 174
j3 1:9e457e35e2e3 175 return gridEye_result;
j3 1:9e457e35e2e3 176 }
j3 1:9e457e35e2e3 177
j3 1:9e457e35e2e3 178
j3 1:9e457e35e2e3 179 //*********************************************************************
j3 1:9e457e35e2e3 180 OWGridEye::CmdResult OWGridEye::gridEyeGetThermistor(int16_t & thermTemp)
j3 1:9e457e35e2e3 181 {
j3 1:9e457e35e2e3 182 OWGridEye::CmdResult ge_result;
j3 1:9e457e35e2e3 183 uint8_t data[2];
j3 1:9e457e35e2e3 184
j3 1:9e457e35e2e3 185 ge_result = this->gridEyeAccess(1, OWGridEye::THERMISTOR_LOW, 2, data);
j3 1:9e457e35e2e3 186 if(ge_result == OWGridEye::Success)
j3 1:9e457e35e2e3 187 {
j3 1:9e457e35e2e3 188 thermTemp = shAMG_PUB_TMP_ConvThermistor(data);
j3 1:9e457e35e2e3 189 }
j3 1:9e457e35e2e3 190
j3 1:9e457e35e2e3 191 return ge_result;
j3 1:9e457e35e2e3 192 }
j3 1:9e457e35e2e3 193
j3 1:9e457e35e2e3 194
j3 1:9e457e35e2e3 195 //*********************************************************************
j3 1:9e457e35e2e3 196 OWGridEye::CmdResult OWGridEye::gridEyeGetPixelTemperature(uint8_t pixelAdrs, int16_t & pixelTemp)
j3 1:9e457e35e2e3 197 {
j3 1:9e457e35e2e3 198 OWGridEye::CmdResult ge_result;
j3 1:9e457e35e2e3 199 uint8_t data[2];
j3 1:9e457e35e2e3 200
j3 1:9e457e35e2e3 201 ge_result = this->gridEyeAccess(1, (GridEyeRegister) pixelAdrs, 2, data);
j3 1:9e457e35e2e3 202 if(ge_result == OWGridEye::Success)
j3 1:9e457e35e2e3 203 {
j3 1:9e457e35e2e3 204 pixelTemp = shAMG_PUB_TMP_ConvTemperature(data);
j3 1:9e457e35e2e3 205 }
j3 1:9e457e35e2e3 206
j3 1:9e457e35e2e3 207 return ge_result;
j3 1:9e457e35e2e3 208 }
j3 1:9e457e35e2e3 209
j3 1:9e457e35e2e3 210
j3 1:9e457e35e2e3 211 //*********************************************************************
j3 1:9e457e35e2e3 212 OWGridEye::CmdResult OWGridEye::gridEyeGetFrameTemperature(int16_t * frameTemp)
j3 1:9e457e35e2e3 213 {
j3 1:9e457e35e2e3 214 OWGridEye::CmdResult ge_result;
j3 1:9e457e35e2e3 215 uint8_t data[128];
j3 1:9e457e35e2e3 216
j3 1:9e457e35e2e3 217 ge_result = this->gridEyeAccess(1,(GridEyeRegister) OWGridEye::PIXEL_BASE_ADRS, 128, data);
j3 1:9e457e35e2e3 218 if(ge_result == OWGridEye::Success)
j3 1:9e457e35e2e3 219 {
j3 1:9e457e35e2e3 220 vAMG_PUB_TMP_ConvTemperature64(data, frameTemp);
j3 1:9e457e35e2e3 221 }
j3 1:9e457e35e2e3 222
j3 1:9e457e35e2e3 223 return ge_result;
j3 1:9e457e35e2e3 224 }
j3 1:9e457e35e2e3 225
j3 1:9e457e35e2e3 226
j3 1:9e457e35e2e3 227 //*********************************************************************
j3 1:9e457e35e2e3 228 int16_t OWGridEye::gridEyeConvFtoS(float data)
j3 1:9e457e35e2e3 229 {
j3 1:9e457e35e2e3 230 int16_t convData = 0;
j3 1:9e457e35e2e3 231
j3 1:9e457e35e2e3 232 return convData;
j3 1:9e457e35e2e3 233 }
j3 1:9e457e35e2e3 234
j3 1:9e457e35e2e3 235
j3 1:9e457e35e2e3 236 //*********************************************************************
j3 1:9e457e35e2e3 237 float OWGridEye::gridEyeConvStoF(int16_t data)
j3 1:9e457e35e2e3 238 {
j3 1:9e457e35e2e3 239 float convData = fAMG_PUB_CMN_ConvStoF(data);
j3 1:9e457e35e2e3 240 return convData;
j3 1:9e457e35e2e3 241 }