pwm period is now 200us instead of the default 20ms veml6040 config is now AF_BIT | TRIG_BIT

Dependencies:   mbed MMA8451Q USBDevice WakeUp vt100

Fork of afero_node_suntory_2017_06_15 by Orefatoi

Committer:
Rhyme
Date:
Wed Oct 18 00:31:13 2017 +0000
Revision:
23:e4d2316383a1
Parent:
21:d03c7bbb9f37
pwm period is now 200us from default 20ms; veml6040->setCOLORCOnf is now AF_BIT | TRIG_BIT from 0x00;

Who changed what in which revision?

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