Added a GPIO to power on/off for external I2C sensor(s) (with LEDs)
Dependencies: UniGraphic mbed vt100
afLib.h
00001 /** 00002 * Copyright 2015 Afero, Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef AFLIB_H__ 00018 #define AFLIB_H__ 00019 00020 #include "mbed.h" 00021 #include "iafLib.h" 00022 #include "SPI.h" 00023 #include "Command.h" 00024 #include "StatusCommand.h" 00025 #include "afSPI.h" 00026 // #include "WatchDogWrapper.hpp" 00027 00028 #define STATE_IDLE 0 00029 #define STATE_STATUS_SYNC 1 00030 #define STATE_STATUS_ACK 3 00031 #define STATE_SEND_BYTES 4 00032 #define STATE_RECV_BYTES 5 00033 #define STATE_CMD_COMPLETE 6 00034 00035 #define SPI_FRAME_LEN 16 00036 00037 #define REQUEST_QUEUE_SIZE 10 00038 00039 typedef struct { 00040 uint8_t messageType; 00041 uint16_t attrId; 00042 uint8_t requestId; 00043 uint16_t valueLen; 00044 uint8_t *p_value; 00045 } request_t; 00046 00047 class afLib : public iafLib { 00048 public: 00049 afLib(PinName mcuInterrupt, isr isrWrapper, 00050 onAttributeSet attrSet, onAttributeSetComplete attrSetComplete, afSPI *theSPI); 00051 //wsugi 20161128 00052 ~afLib(); 00053 //wsugi 20161128 00054 00055 // motoo tanaka 20171116 00056 virtual int getRequestId(void) ; 00057 // motoo tanaka 20171116 00058 // motoo tanaka 20171229 00059 virtual void disable_irq(void) { fco.disable_irq() ; } 00060 virtual void enable_irq(void) { fco.enable_irq() ; } 00061 00062 virtual void loop(void); 00063 00064 virtual int getAttribute(const uint16_t attrId); 00065 00066 virtual int setAttributeBool(const uint16_t attrId, const bool value); 00067 00068 virtual int setAttribute8(const uint16_t attrId, const int8_t value); 00069 00070 virtual int setAttribute16(const uint16_t attrId, const int16_t value); 00071 00072 virtual int setAttribute32(const uint16_t attrId, const int32_t value); 00073 00074 virtual int setAttribute64(const uint16_t attrId, const int64_t value); 00075 00076 virtual int setAttribute(const uint16_t attrId, const string &value); 00077 00078 virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const char *value); 00079 00080 virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const uint8_t *value); 00081 00082 virtual int setAttributeComplete(uint8_t requestId, const uint16_t attrId, const uint16_t valueLen, const uint8_t *value); 00083 00084 virtual bool isIdle(); 00085 00086 virtual void mcuISR(); 00087 00088 private: 00089 Timeout deathWish; 00090 Timer *checkLastSync; 00091 static void kick_the_bucket(); 00092 afSPI *_theSPI; 00093 00094 //SPISettings _spiSettings; 00095 volatile int _interrupts_pending; 00096 int _state; 00097 uint16_t _bytesToSend; 00098 uint16_t _bytesToRecv; 00099 uint8_t _requestId; 00100 uint16_t _outstandingSetGetAttrId; 00101 00102 // Application Callbacks. 00103 onAttributeSet _onAttrSet; 00104 onAttributeSetComplete _onAttrSetComplete; 00105 00106 Command *_writeCmd; 00107 uint16_t _writeBufferLen; 00108 uint8_t *_writeBuffer; 00109 00110 Command *_readCmd; 00111 uint16_t _readBufferLen; 00112 uint8_t *_readBuffer; 00113 00114 int _writeCmdOffset; 00115 int _readCmdOffset; 00116 00117 StatusCommand *_txStatus; 00118 StatusCommand *_rxStatus; 00119 00120 request_t _request; 00121 request_t _requestQueue[REQUEST_QUEUE_SIZE]; 00122 00123 #ifdef ATTRIBUTE_CLI 00124 int parseCommand(const char *cmd); 00125 #endif 00126 00127 void sendCommand(void); 00128 00129 void runStateMachine(void); 00130 00131 void printState(int state); 00132 00133 //void beginSPI(); 00134 00135 //void endSPI(); 00136 00137 int exchangeStatus(StatusCommand *tx, StatusCommand *rx); 00138 00139 bool inSync(StatusCommand *tx, StatusCommand *rx); 00140 00141 int writeStatus(StatusCommand *c); 00142 00143 void sendBytes(); 00144 00145 void recvBytes(); 00146 00147 void dumpBytes(char *label, int len, uint8_t *bytes); 00148 00149 void updateIntsPending(int amount); 00150 00151 void queueInit(void); 00152 00153 int queuePut(uint8_t messageType, uint8_t requestId, const uint16_t attributeId, uint16_t valueLen, const uint8_t *value); 00154 00155 int queueGet(uint8_t *messageType, uint8_t *requestId, uint16_t *attributeId, uint16_t *valueLen, uint8_t **value); 00156 00157 int doGetAttribute(uint8_t requestId, uint16_t attrId); 00158 00159 int doSetAttribute(uint8_t requestId, uint16_t attrId, uint16_t valueLen, uint8_t *value); 00160 00161 int doUpdateAttribute(uint8_t requestId, uint16_t attrId, uint8_t status, uint16_t valueLen, uint8_t *value); 00162 00163 void onStateIdle(void); 00164 void onStateSync(void); 00165 void onStateAck(void); 00166 void onStateSendBytes(void); 00167 void onStateRecvBytes(void); 00168 void onStateCmdComplete(void); 00169 void printTransaction(uint8_t *rbytes, int len); 00170 InterruptIn fco; 00171 }; 00172 00173 #endif // AFLIB_H__
Generated on Wed Jul 13 2022 12:25:10 by 1.7.2