Added a GPIO to power on/off for external I2C sensor(s) (with LEDs)

Dependencies:   UniGraphic mbed vt100

18-Jun-2018 外部センサの電源オン・オフ機能は下位互換の為に無効になっていました。 この版で再度有効にしました。

Committer:
Rhyme
Date:
Fri Apr 13 04:19:23 2018 +0000
Revision:
0:846e2321c637
power to color sensor on/off test OK. Currently the function is disabled.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:846e2321c637 1 /**
Rhyme 0:846e2321c637 2 * Copyright 2015 Afero, Inc.
Rhyme 0:846e2321c637 3 *
Rhyme 0:846e2321c637 4 * Licensed under the Apache License, Version 2.0 (the "License");
Rhyme 0:846e2321c637 5 * you may not use this file except in compliance with the License.
Rhyme 0:846e2321c637 6 * You may obtain a copy of the License at
Rhyme 0:846e2321c637 7 *
Rhyme 0:846e2321c637 8 * http://www.apache.org/licenses/LICENSE-2.0
Rhyme 0:846e2321c637 9 *
Rhyme 0:846e2321c637 10 * Unless required by applicable law or agreed to in writing, software
Rhyme 0:846e2321c637 11 * distributed under the License is distributed on an "AS IS" BASIS,
Rhyme 0:846e2321c637 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Rhyme 0:846e2321c637 13 * See the License for the specific language governing permissions and
Rhyme 0:846e2321c637 14 * limitations under the License.
Rhyme 0:846e2321c637 15 */
Rhyme 0:846e2321c637 16
Rhyme 0:846e2321c637 17 #ifndef AFLIB_H__
Rhyme 0:846e2321c637 18 #define AFLIB_H__
Rhyme 0:846e2321c637 19
Rhyme 0:846e2321c637 20 #include "mbed.h"
Rhyme 0:846e2321c637 21 #include "iafLib.h"
Rhyme 0:846e2321c637 22 #include "SPI.h"
Rhyme 0:846e2321c637 23 #include "Command.h"
Rhyme 0:846e2321c637 24 #include "StatusCommand.h"
Rhyme 0:846e2321c637 25 #include "afSPI.h"
Rhyme 0:846e2321c637 26 // #include "WatchDogWrapper.hpp"
Rhyme 0:846e2321c637 27
Rhyme 0:846e2321c637 28 #define STATE_IDLE 0
Rhyme 0:846e2321c637 29 #define STATE_STATUS_SYNC 1
Rhyme 0:846e2321c637 30 #define STATE_STATUS_ACK 3
Rhyme 0:846e2321c637 31 #define STATE_SEND_BYTES 4
Rhyme 0:846e2321c637 32 #define STATE_RECV_BYTES 5
Rhyme 0:846e2321c637 33 #define STATE_CMD_COMPLETE 6
Rhyme 0:846e2321c637 34
Rhyme 0:846e2321c637 35 #define SPI_FRAME_LEN 16
Rhyme 0:846e2321c637 36
Rhyme 0:846e2321c637 37 #define REQUEST_QUEUE_SIZE 10
Rhyme 0:846e2321c637 38
Rhyme 0:846e2321c637 39 typedef struct {
Rhyme 0:846e2321c637 40 uint8_t messageType;
Rhyme 0:846e2321c637 41 uint16_t attrId;
Rhyme 0:846e2321c637 42 uint8_t requestId;
Rhyme 0:846e2321c637 43 uint16_t valueLen;
Rhyme 0:846e2321c637 44 uint8_t *p_value;
Rhyme 0:846e2321c637 45 } request_t;
Rhyme 0:846e2321c637 46
Rhyme 0:846e2321c637 47 class afLib : public iafLib {
Rhyme 0:846e2321c637 48 public:
Rhyme 0:846e2321c637 49 afLib(PinName mcuInterrupt, isr isrWrapper,
Rhyme 0:846e2321c637 50 onAttributeSet attrSet, onAttributeSetComplete attrSetComplete, afSPI *theSPI);
Rhyme 0:846e2321c637 51 //wsugi 20161128
Rhyme 0:846e2321c637 52 ~afLib();
Rhyme 0:846e2321c637 53 //wsugi 20161128
Rhyme 0:846e2321c637 54
Rhyme 0:846e2321c637 55 // motoo tanaka 20171116
Rhyme 0:846e2321c637 56 virtual int getRequestId(void) ;
Rhyme 0:846e2321c637 57 // motoo tanaka 20171116
Rhyme 0:846e2321c637 58 // motoo tanaka 20171229
Rhyme 0:846e2321c637 59 virtual void disable_irq(void) { fco.disable_irq() ; }
Rhyme 0:846e2321c637 60 virtual void enable_irq(void) { fco.enable_irq() ; }
Rhyme 0:846e2321c637 61
Rhyme 0:846e2321c637 62 virtual void loop(void);
Rhyme 0:846e2321c637 63
Rhyme 0:846e2321c637 64 virtual int getAttribute(const uint16_t attrId);
Rhyme 0:846e2321c637 65
Rhyme 0:846e2321c637 66 virtual int setAttributeBool(const uint16_t attrId, const bool value);
Rhyme 0:846e2321c637 67
Rhyme 0:846e2321c637 68 virtual int setAttribute8(const uint16_t attrId, const int8_t value);
Rhyme 0:846e2321c637 69
Rhyme 0:846e2321c637 70 virtual int setAttribute16(const uint16_t attrId, const int16_t value);
Rhyme 0:846e2321c637 71
Rhyme 0:846e2321c637 72 virtual int setAttribute32(const uint16_t attrId, const int32_t value);
Rhyme 0:846e2321c637 73
Rhyme 0:846e2321c637 74 virtual int setAttribute64(const uint16_t attrId, const int64_t value);
Rhyme 0:846e2321c637 75
Rhyme 0:846e2321c637 76 virtual int setAttribute(const uint16_t attrId, const string &value);
Rhyme 0:846e2321c637 77
Rhyme 0:846e2321c637 78 virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const char *value);
Rhyme 0:846e2321c637 79
Rhyme 0:846e2321c637 80 virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const uint8_t *value);
Rhyme 0:846e2321c637 81
Rhyme 0:846e2321c637 82 virtual int setAttributeComplete(uint8_t requestId, const uint16_t attrId, const uint16_t valueLen, const uint8_t *value);
Rhyme 0:846e2321c637 83
Rhyme 0:846e2321c637 84 virtual bool isIdle();
Rhyme 0:846e2321c637 85
Rhyme 0:846e2321c637 86 virtual void mcuISR();
Rhyme 0:846e2321c637 87
Rhyme 0:846e2321c637 88 private:
Rhyme 0:846e2321c637 89 Timeout deathWish;
Rhyme 0:846e2321c637 90 Timer *checkLastSync;
Rhyme 0:846e2321c637 91 static void kick_the_bucket();
Rhyme 0:846e2321c637 92 afSPI *_theSPI;
Rhyme 0:846e2321c637 93
Rhyme 0:846e2321c637 94 //SPISettings _spiSettings;
Rhyme 0:846e2321c637 95 volatile int _interrupts_pending;
Rhyme 0:846e2321c637 96 int _state;
Rhyme 0:846e2321c637 97 uint16_t _bytesToSend;
Rhyme 0:846e2321c637 98 uint16_t _bytesToRecv;
Rhyme 0:846e2321c637 99 uint8_t _requestId;
Rhyme 0:846e2321c637 100 uint16_t _outstandingSetGetAttrId;
Rhyme 0:846e2321c637 101
Rhyme 0:846e2321c637 102 // Application Callbacks.
Rhyme 0:846e2321c637 103 onAttributeSet _onAttrSet;
Rhyme 0:846e2321c637 104 onAttributeSetComplete _onAttrSetComplete;
Rhyme 0:846e2321c637 105
Rhyme 0:846e2321c637 106 Command *_writeCmd;
Rhyme 0:846e2321c637 107 uint16_t _writeBufferLen;
Rhyme 0:846e2321c637 108 uint8_t *_writeBuffer;
Rhyme 0:846e2321c637 109
Rhyme 0:846e2321c637 110 Command *_readCmd;
Rhyme 0:846e2321c637 111 uint16_t _readBufferLen;
Rhyme 0:846e2321c637 112 uint8_t *_readBuffer;
Rhyme 0:846e2321c637 113
Rhyme 0:846e2321c637 114 int _writeCmdOffset;
Rhyme 0:846e2321c637 115 int _readCmdOffset;
Rhyme 0:846e2321c637 116
Rhyme 0:846e2321c637 117 StatusCommand *_txStatus;
Rhyme 0:846e2321c637 118 StatusCommand *_rxStatus;
Rhyme 0:846e2321c637 119
Rhyme 0:846e2321c637 120 request_t _request;
Rhyme 0:846e2321c637 121 request_t _requestQueue[REQUEST_QUEUE_SIZE];
Rhyme 0:846e2321c637 122
Rhyme 0:846e2321c637 123 #ifdef ATTRIBUTE_CLI
Rhyme 0:846e2321c637 124 int parseCommand(const char *cmd);
Rhyme 0:846e2321c637 125 #endif
Rhyme 0:846e2321c637 126
Rhyme 0:846e2321c637 127 void sendCommand(void);
Rhyme 0:846e2321c637 128
Rhyme 0:846e2321c637 129 void runStateMachine(void);
Rhyme 0:846e2321c637 130
Rhyme 0:846e2321c637 131 void printState(int state);
Rhyme 0:846e2321c637 132
Rhyme 0:846e2321c637 133 //void beginSPI();
Rhyme 0:846e2321c637 134
Rhyme 0:846e2321c637 135 //void endSPI();
Rhyme 0:846e2321c637 136
Rhyme 0:846e2321c637 137 int exchangeStatus(StatusCommand *tx, StatusCommand *rx);
Rhyme 0:846e2321c637 138
Rhyme 0:846e2321c637 139 bool inSync(StatusCommand *tx, StatusCommand *rx);
Rhyme 0:846e2321c637 140
Rhyme 0:846e2321c637 141 int writeStatus(StatusCommand *c);
Rhyme 0:846e2321c637 142
Rhyme 0:846e2321c637 143 void sendBytes();
Rhyme 0:846e2321c637 144
Rhyme 0:846e2321c637 145 void recvBytes();
Rhyme 0:846e2321c637 146
Rhyme 0:846e2321c637 147 void dumpBytes(char *label, int len, uint8_t *bytes);
Rhyme 0:846e2321c637 148
Rhyme 0:846e2321c637 149 void updateIntsPending(int amount);
Rhyme 0:846e2321c637 150
Rhyme 0:846e2321c637 151 void queueInit(void);
Rhyme 0:846e2321c637 152
Rhyme 0:846e2321c637 153 int queuePut(uint8_t messageType, uint8_t requestId, const uint16_t attributeId, uint16_t valueLen, const uint8_t *value);
Rhyme 0:846e2321c637 154
Rhyme 0:846e2321c637 155 int queueGet(uint8_t *messageType, uint8_t *requestId, uint16_t *attributeId, uint16_t *valueLen, uint8_t **value);
Rhyme 0:846e2321c637 156
Rhyme 0:846e2321c637 157 int doGetAttribute(uint8_t requestId, uint16_t attrId);
Rhyme 0:846e2321c637 158
Rhyme 0:846e2321c637 159 int doSetAttribute(uint8_t requestId, uint16_t attrId, uint16_t valueLen, uint8_t *value);
Rhyme 0:846e2321c637 160
Rhyme 0:846e2321c637 161 int doUpdateAttribute(uint8_t requestId, uint16_t attrId, uint8_t status, uint16_t valueLen, uint8_t *value);
Rhyme 0:846e2321c637 162
Rhyme 0:846e2321c637 163 void onStateIdle(void);
Rhyme 0:846e2321c637 164 void onStateSync(void);
Rhyme 0:846e2321c637 165 void onStateAck(void);
Rhyme 0:846e2321c637 166 void onStateSendBytes(void);
Rhyme 0:846e2321c637 167 void onStateRecvBytes(void);
Rhyme 0:846e2321c637 168 void onStateCmdComplete(void);
Rhyme 0:846e2321c637 169 void printTransaction(uint8_t *rbytes, int len);
Rhyme 0:846e2321c637 170 InterruptIn fco;
Rhyme 0:846e2321c637 171 };
Rhyme 0:846e2321c637 172
Rhyme 0:846e2321c637 173 #endif // AFLIB_H__