an old afLib which supports both SPI and UART

Committer:
Rhyme
Date:
Mon Apr 23 06:15:05 2018 +0000
Revision:
1:112741fe45d1
Parent:
0:6f371c791202
afLib1.3 first mbed version with working UART

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:6f371c791202 1 /**
Rhyme 0:6f371c791202 2 * Copyright 2015 Afero, Inc.
Rhyme 0:6f371c791202 3 *
Rhyme 0:6f371c791202 4 * Licensed under the Apache License, Version 2.0 (the "License");
Rhyme 0:6f371c791202 5 * you may not use this file except in compliance with the License.
Rhyme 0:6f371c791202 6 * You may obtain a copy of the License at
Rhyme 0:6f371c791202 7 *
Rhyme 0:6f371c791202 8 * http://www.apache.org/licenses/LICENSE-2.0
Rhyme 0:6f371c791202 9 *
Rhyme 0:6f371c791202 10 * Unless required by applicable law or agreed to in writing, software
Rhyme 0:6f371c791202 11 * distributed under the License is distributed on an "AS IS" BASIS,
Rhyme 0:6f371c791202 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Rhyme 0:6f371c791202 13 * See the License for the specific language governing permissions and
Rhyme 0:6f371c791202 14 * limitations under the License.
Rhyme 0:6f371c791202 15 */
Rhyme 0:6f371c791202 16
Rhyme 0:6f371c791202 17 /**
Rhyme 0:6f371c791202 18 * afLib public interface
Rhyme 0:6f371c791202 19 *
Rhyme 0:6f371c791202 20 * This file defines everything your application should need for commuinicating with the Afero ASR-1 radio module.
Rhyme 0:6f371c791202 21 * Is there is anything missing from this file, please post a request on the developer forum and we will see what
Rhyme 0:6f371c791202 22 * we can do.
Rhyme 0:6f371c791202 23 */
Rhyme 0:6f371c791202 24 #ifndef AFLIB_IAFLIB_H
Rhyme 0:6f371c791202 25 #define AFLIB_IAFLIB_H
Rhyme 0:6f371c791202 26
Rhyme 0:6f371c791202 27 #include "mbed.h"
Rhyme 0:6f371c791202 28 #define Stream Serial
Rhyme 0:6f371c791202 29 #include "afErrors.h"
Rhyme 0:6f371c791202 30 #include "afSPI.h"
Rhyme 0:6f371c791202 31 #include "afUART.h"
Rhyme 0:6f371c791202 32 #include "afTransport.h"
Rhyme 0:6f371c791202 33
Rhyme 0:6f371c791202 34 #define afMINIMUM_TIME_BETWEEN_REQUESTS 1000
Rhyme 0:6f371c791202 35
Rhyme 0:6f371c791202 36 #define MAX_ATTRIBUTE_SIZE 255
Rhyme 0:6f371c791202 37
Rhyme 0:6f371c791202 38 typedef void (*isr)();
Rhyme 0:6f371c791202 39 typedef bool (*AttrSetHandler)(const uint8_t requestId, const uint16_t attributeId, const uint16_t valueLen, const uint8_t *value);
Rhyme 0:6f371c791202 40 typedef void (*AttrNotifyHandler)(const uint8_t requestId, const uint16_t attributeId, const uint16_t valueLen, const uint8_t *value);
Rhyme 0:6f371c791202 41
Rhyme 0:6f371c791202 42 class iafLib {
Rhyme 0:6f371c791202 43 public:
Rhyme 0:6f371c791202 44 /**
Rhyme 0:6f371c791202 45 * create
Rhyme 0:6f371c791202 46 *
Rhyme 0:6f371c791202 47 * Create an instance of the afLib object. The afLib is a singleton. Calling this method multiple
Rhyme 0:6f371c791202 48 * times will return the same instance.
Rhyme 0:6f371c791202 49 *
Rhyme 0:6f371c791202 50 * @param attrSet Callback for notification of attribute set requests
Rhyme 0:6f371c791202 51 * @param attrNotify Callback for notification of attribute set request completions
Rhyme 0:6f371c791202 52 * @param theLog An instance of a Stream object that will be used for debug prints
Rhyme 0:6f371c791202 53 * @param theTransport An instance of an afTransport object to be used for communications with the ASR-1
Rhyme 0:6f371c791202 54 * @param attrNotify Callback for notification of attribute set request completions
Rhyme 0:6f371c791202 55 * @return iafLib * Instance of iafLib
Rhyme 0:6f371c791202 56 */
Rhyme 0:6f371c791202 57 static iafLib * create(AttrSetHandler attrSet, AttrNotifyHandler attrNotify, Stream *theLog, afTransport *theTransport);
Rhyme 0:6f371c791202 58
Rhyme 0:6f371c791202 59 static iafLib * create(PinName mcuInterrupt, isr isrWrapper, AttrSetHandler attrSet, AttrNotifyHandler attrNotify, Stream *theLog, afTransport *theTransport);
Rhyme 0:6f371c791202 60
Rhyme 0:6f371c791202 61 /**
Rhyme 0:6f371c791202 62 * loop
Rhyme 0:6f371c791202 63 *
Rhyme 0:6f371c791202 64 * Called by the loop() method in your sketch to give afLib some CPU time
Rhyme 0:6f371c791202 65 */
Rhyme 0:6f371c791202 66 virtual void loop(void) = 0;
Rhyme 0:6f371c791202 67
Rhyme 0:6f371c791202 68 /**
Rhyme 0:6f371c791202 69 * getAttribute
Rhyme 0:6f371c791202 70 *
Rhyme 0:6f371c791202 71 * Request the value of an attribute be returned from the ASR-1.
Rhyme 0:6f371c791202 72 * Value will be returned in the attrNotify callback.
Rhyme 0:6f371c791202 73 */
Rhyme 0:6f371c791202 74 virtual int getAttribute(const uint16_t attrId) = 0;
Rhyme 0:6f371c791202 75
Rhyme 0:6f371c791202 76 /**
Rhyme 0:6f371c791202 77 * setAttribute
Rhyme 0:6f371c791202 78 *
Rhyme 0:6f371c791202 79 * Request setting an attribute.
Rhyme 0:6f371c791202 80 * For MCU attributes, the attribute value will be updated.
Rhyme 0:6f371c791202 81 * For IO attributes, the attribute value will be updated, and then onAttrSetComplete will be called.
Rhyme 0:6f371c791202 82 */
Rhyme 0:6f371c791202 83 virtual int setAttributeBool(const uint16_t attrId, const bool value) = 0;
Rhyme 0:6f371c791202 84
Rhyme 0:6f371c791202 85 virtual int setAttribute8(const uint16_t attrId, const int8_t value) = 0;
Rhyme 0:6f371c791202 86
Rhyme 0:6f371c791202 87 virtual int setAttribute16(const uint16_t attrId, const int16_t value) = 0;
Rhyme 0:6f371c791202 88
Rhyme 0:6f371c791202 89 virtual int setAttribute32(const uint16_t attrId, const int32_t value) = 0;
Rhyme 0:6f371c791202 90
Rhyme 0:6f371c791202 91 virtual int setAttribute64(const uint16_t attrId, const int64_t value) = 0;
Rhyme 0:6f371c791202 92
Rhyme 0:6f371c791202 93 virtual int setAttributeStr(const uint16_t attrId, const char *value) = 0;
Rhyme 0:6f371c791202 94
Rhyme 0:6f371c791202 95 virtual int setAttributeCStr(const uint16_t attrId, const uint16_t valueLen, const char *value) = 0;
Rhyme 0:6f371c791202 96
Rhyme 0:6f371c791202 97 virtual int setAttributeBytes(const uint16_t attrId, const uint16_t valueLen, const uint8_t *value) = 0;
Rhyme 0:6f371c791202 98
Rhyme 0:6f371c791202 99 /**
Rhyme 0:6f371c791202 100 * isIdle
Rhyme 0:6f371c791202 101 *
Rhyme 0:6f371c791202 102 * Call to find out of the ASR-1 is currently handling a request.
Rhyme 0:6f371c791202 103 *
Rhyme 0:6f371c791202 104 * @return true if an operation is in progress
Rhyme 0:6f371c791202 105 */
Rhyme 0:6f371c791202 106 virtual bool isIdle() = 0;
Rhyme 0:6f371c791202 107
Rhyme 0:6f371c791202 108 /**
Rhyme 0:6f371c791202 109 * mcuISR
Rhyme 0:6f371c791202 110 *
Rhyme 0:6f371c791202 111 * Called by your sketch to pass the interrupt along to afLib.
Rhyme 0:6f371c791202 112 */
Rhyme 0:6f371c791202 113 virtual void mcuISR() = 0;
Rhyme 0:6f371c791202 114 };
Rhyme 0:6f371c791202 115 #endif //AFLIB_IAFLIB_H