Extended MaximInterface

Dependents:   mbed_DS28EC20_GPIO

Committer:
IanBenzMaxim
Date:
Thu Jan 11 13:50:39 2018 -0600
Revision:
3:f818ea5172ed
Parent:
0:f77ad7f72d04
Child:
6:a8c83a2e6fa4
Updated to version 1.1.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 0:f77ad7f72d04 1 /*******************************************************************************
IanBenzMaxim 0:f77ad7f72d04 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 0:f77ad7f72d04 3 *
IanBenzMaxim 0:f77ad7f72d04 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 0:f77ad7f72d04 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 0:f77ad7f72d04 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 0:f77ad7f72d04 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 0:f77ad7f72d04 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 0:f77ad7f72d04 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 0:f77ad7f72d04 10 *
IanBenzMaxim 0:f77ad7f72d04 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 0:f77ad7f72d04 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 0:f77ad7f72d04 13 *
IanBenzMaxim 0:f77ad7f72d04 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 0:f77ad7f72d04 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 0:f77ad7f72d04 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 0:f77ad7f72d04 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 0:f77ad7f72d04 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 0:f77ad7f72d04 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 0:f77ad7f72d04 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 0:f77ad7f72d04 21 *
IanBenzMaxim 0:f77ad7f72d04 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 24 * Products, Inc. Branding Policy.
IanBenzMaxim 0:f77ad7f72d04 25 *
IanBenzMaxim 0:f77ad7f72d04 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 0:f77ad7f72d04 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 0:f77ad7f72d04 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 0:f77ad7f72d04 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 0:f77ad7f72d04 30 * ownership rights.
IanBenzMaxim 0:f77ad7f72d04 31 *******************************************************************************/
IanBenzMaxim 0:f77ad7f72d04 32
IanBenzMaxim 0:f77ad7f72d04 33 #include "DS9400.hpp"
IanBenzMaxim 0:f77ad7f72d04 34
IanBenzMaxim 0:f77ad7f72d04 35 namespace MaximInterface {
IanBenzMaxim 0:f77ad7f72d04 36
IanBenzMaxim 3:f818ea5172ed 37 error_code DS9400::waitAwake() {
IanBenzMaxim 3:f818ea5172ed 38 error_code result;
IanBenzMaxim 3:f818ea5172ed 39 uint_least8_t data;
IanBenzMaxim 3:f818ea5172ed 40 do {
IanBenzMaxim 3:f818ea5172ed 41 result = uart->readByte(data);
IanBenzMaxim 3:f818ea5172ed 42 } while (!result && data != 0xA5);
IanBenzMaxim 3:f818ea5172ed 43 return result;
IanBenzMaxim 3:f818ea5172ed 44 }
IanBenzMaxim 3:f818ea5172ed 45
IanBenzMaxim 0:f77ad7f72d04 46 error_code DS9400::start() { return uart->writeByte('S'); }
IanBenzMaxim 0:f77ad7f72d04 47
IanBenzMaxim 0:f77ad7f72d04 48 error_code DS9400::start(uint_least8_t address) {
IanBenzMaxim 0:f77ad7f72d04 49 error_code result = start();
IanBenzMaxim 0:f77ad7f72d04 50 if (!result) {
IanBenzMaxim 0:f77ad7f72d04 51 result = writeByte(address);
IanBenzMaxim 0:f77ad7f72d04 52 }
IanBenzMaxim 0:f77ad7f72d04 53 return result;
IanBenzMaxim 0:f77ad7f72d04 54 }
IanBenzMaxim 0:f77ad7f72d04 55
IanBenzMaxim 0:f77ad7f72d04 56 error_code DS9400::stop() { return uart->writeByte('P'); }
IanBenzMaxim 0:f77ad7f72d04 57
IanBenzMaxim 0:f77ad7f72d04 58 error_code DS9400::writeByte(uint_least8_t data) {
IanBenzMaxim 0:f77ad7f72d04 59 const uint_least8_t packet[] = {'Q', data};
IanBenzMaxim 0:f77ad7f72d04 60 error_code result = uart->clearReadBuffer();
IanBenzMaxim 0:f77ad7f72d04 61 if (!result) {
IanBenzMaxim 0:f77ad7f72d04 62 result = uart->writeBlock(packet, sizeof(packet) / sizeof(packet[0]));
IanBenzMaxim 0:f77ad7f72d04 63 if (!result) {
IanBenzMaxim 0:f77ad7f72d04 64 result = uart->readByte(data);
IanBenzMaxim 0:f77ad7f72d04 65 if (!result && data != 0) {
IanBenzMaxim 0:f77ad7f72d04 66 result = make_error_code(I2CMaster::NackError);
IanBenzMaxim 0:f77ad7f72d04 67 }
IanBenzMaxim 0:f77ad7f72d04 68 }
IanBenzMaxim 0:f77ad7f72d04 69 }
IanBenzMaxim 0:f77ad7f72d04 70 return result;
IanBenzMaxim 0:f77ad7f72d04 71 }
IanBenzMaxim 0:f77ad7f72d04 72
IanBenzMaxim 0:f77ad7f72d04 73 error_code DS9400::readByte(AckStatus status, uint_least8_t & data) {
IanBenzMaxim 0:f77ad7f72d04 74 error_code result = uart->clearReadBuffer();
IanBenzMaxim 0:f77ad7f72d04 75 if (!result) {
IanBenzMaxim 0:f77ad7f72d04 76 result = uart->writeByte(status == Ack ? 'R' : 'N');
IanBenzMaxim 0:f77ad7f72d04 77 if (!result) {
IanBenzMaxim 0:f77ad7f72d04 78 result = uart->readByte(data);
IanBenzMaxim 0:f77ad7f72d04 79 }
IanBenzMaxim 0:f77ad7f72d04 80 }
IanBenzMaxim 0:f77ad7f72d04 81 return result;
IanBenzMaxim 0:f77ad7f72d04 82 }
IanBenzMaxim 0:f77ad7f72d04 83
IanBenzMaxim 3:f818ea5172ed 84 error_code DS9400::configure(uint_least8_t config) {
IanBenzMaxim 3:f818ea5172ed 85 const uint_least8_t packet[] = {'C', config};
IanBenzMaxim 3:f818ea5172ed 86 return uart->writeBlock(packet, sizeof(packet) / sizeof(packet[0]));
IanBenzMaxim 3:f818ea5172ed 87 }
IanBenzMaxim 3:f818ea5172ed 88
IanBenzMaxim 0:f77ad7f72d04 89 } // namespace MaximInterface