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
afLib/afLib.h@0:20bce0dcc921, 2016-12-20 (annotated)
- Committer:
- wataloh
- Date:
- Tue Dec 20 01:51:02 2016 +0000
- Revision:
- 0:20bce0dcc921
- Child:
- 5:9d5c7ee80f3b
kl25z teensy merged
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:20bce0dcc921 | 26 | |
wataloh | 0:20bce0dcc921 | 27 | #include "debugIO.h" |
wataloh | 0:20bce0dcc921 | 28 | |
wataloh | 0:20bce0dcc921 | 29 | #define STATE_IDLE 0 |
wataloh | 0:20bce0dcc921 | 30 | #define STATE_STATUS_SYNC 1 |
wataloh | 0:20bce0dcc921 | 31 | #define STATE_STATUS_ACK 3 |
wataloh | 0:20bce0dcc921 | 32 | #define STATE_SEND_BYTES 4 |
wataloh | 0:20bce0dcc921 | 33 | #define STATE_RECV_BYTES 5 |
wataloh | 0:20bce0dcc921 | 34 | #define STATE_CMD_COMPLETE 6 |
wataloh | 0:20bce0dcc921 | 35 | |
wataloh | 0:20bce0dcc921 | 36 | #define SPI_FRAME_LEN 16 |
wataloh | 0:20bce0dcc921 | 37 | |
wataloh | 0:20bce0dcc921 | 38 | #define REQUEST_QUEUE_SIZE 10 |
wataloh | 0:20bce0dcc921 | 39 | |
wataloh | 0:20bce0dcc921 | 40 | typedef struct { |
wataloh | 0:20bce0dcc921 | 41 | uint8_t messageType; |
wataloh | 0:20bce0dcc921 | 42 | uint16_t attrId; |
wataloh | 0:20bce0dcc921 | 43 | uint8_t requestId; |
wataloh | 0:20bce0dcc921 | 44 | uint16_t valueLen; |
wataloh | 0:20bce0dcc921 | 45 | uint8_t *p_value; |
wataloh | 0:20bce0dcc921 | 46 | } request_t; |
wataloh | 0:20bce0dcc921 | 47 | |
wataloh | 0:20bce0dcc921 | 48 | class afLib : public iafLib { |
wataloh | 0:20bce0dcc921 | 49 | public: |
wataloh | 0:20bce0dcc921 | 50 | afLib(PinName mcuInterrupt, isr isrWrapper, |
wataloh | 0:20bce0dcc921 | 51 | onAttributeSet attrSet, onAttributeSetComplete attrSetComplete, afSPI *theSPI); |
wataloh | 0:20bce0dcc921 | 52 | //wsugi 20161128 |
wataloh | 0:20bce0dcc921 | 53 | ~afLib(); |
wataloh | 0:20bce0dcc921 | 54 | //wsugi 20161128 |
wataloh | 0:20bce0dcc921 | 55 | virtual void loop(void); |
wataloh | 0:20bce0dcc921 | 56 | |
wataloh | 0:20bce0dcc921 | 57 | virtual int getAttribute(const uint16_t attrId); |
wataloh | 0:20bce0dcc921 | 58 | |
wataloh | 0:20bce0dcc921 | 59 | virtual int setAttributeBool(const uint16_t attrId, const bool value); |
wataloh | 0:20bce0dcc921 | 60 | |
wataloh | 0:20bce0dcc921 | 61 | virtual int setAttribute8(const uint16_t attrId, const int8_t value); |
wataloh | 0:20bce0dcc921 | 62 | |
wataloh | 0:20bce0dcc921 | 63 | virtual int setAttribute16(const uint16_t attrId, const int16_t value); |
wataloh | 0:20bce0dcc921 | 64 | |
wataloh | 0:20bce0dcc921 | 65 | virtual int setAttribute32(const uint16_t attrId, const int32_t value); |
wataloh | 0:20bce0dcc921 | 66 | |
wataloh | 0:20bce0dcc921 | 67 | virtual int setAttribute64(const uint16_t attrId, const int64_t value); |
wataloh | 0:20bce0dcc921 | 68 | |
wataloh | 0:20bce0dcc921 | 69 | virtual int setAttribute(const uint16_t attrId, const string &value); |
wataloh | 0:20bce0dcc921 | 70 | |
wataloh | 0:20bce0dcc921 | 71 | virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const char *value); |
wataloh | 0:20bce0dcc921 | 72 | |
wataloh | 0:20bce0dcc921 | 73 | virtual int setAttribute(const uint16_t attrId, const uint16_t valueLen, const uint8_t *value); |
wataloh | 0:20bce0dcc921 | 74 | |
wataloh | 0:20bce0dcc921 | 75 | virtual int setAttributeComplete(uint8_t requestId, const uint16_t attrId, const uint16_t valueLen, const uint8_t *value); |
wataloh | 0:20bce0dcc921 | 76 | |
wataloh | 0:20bce0dcc921 | 77 | virtual bool isIdle(); |
wataloh | 0:20bce0dcc921 | 78 | |
wataloh | 0:20bce0dcc921 | 79 | virtual void mcuISR(); |
wataloh | 0:20bce0dcc921 | 80 | |
wataloh | 0:20bce0dcc921 | 81 | private: |
wataloh | 0:20bce0dcc921 | 82 | |
wataloh | 0:20bce0dcc921 | 83 | afSPI *_theSPI; |
wataloh | 0:20bce0dcc921 | 84 | |
wataloh | 0:20bce0dcc921 | 85 | //SPISettings _spiSettings; |
wataloh | 0:20bce0dcc921 | 86 | volatile int _interrupts_pending; |
wataloh | 0:20bce0dcc921 | 87 | int _state; |
wataloh | 0:20bce0dcc921 | 88 | uint16_t _bytesToSend; |
wataloh | 0:20bce0dcc921 | 89 | uint16_t _bytesToRecv; |
wataloh | 0:20bce0dcc921 | 90 | uint8_t _requestId; |
wataloh | 0:20bce0dcc921 | 91 | uint16_t _outstandingSetGetAttrId; |
wataloh | 0:20bce0dcc921 | 92 | |
wataloh | 0:20bce0dcc921 | 93 | // Application Callbacks. |
wataloh | 0:20bce0dcc921 | 94 | onAttributeSet _onAttrSet; |
wataloh | 0:20bce0dcc921 | 95 | onAttributeSetComplete _onAttrSetComplete; |
wataloh | 0:20bce0dcc921 | 96 | |
wataloh | 0:20bce0dcc921 | 97 | Command *_writeCmd; |
wataloh | 0:20bce0dcc921 | 98 | uint16_t _writeBufferLen; |
wataloh | 0:20bce0dcc921 | 99 | uint8_t *_writeBuffer; |
wataloh | 0:20bce0dcc921 | 100 | |
wataloh | 0:20bce0dcc921 | 101 | Command *_readCmd; |
wataloh | 0:20bce0dcc921 | 102 | uint16_t _readBufferLen; |
wataloh | 0:20bce0dcc921 | 103 | uint8_t *_readBuffer; |
wataloh | 0:20bce0dcc921 | 104 | |
wataloh | 0:20bce0dcc921 | 105 | int _writeCmdOffset; |
wataloh | 0:20bce0dcc921 | 106 | int _readCmdOffset; |
wataloh | 0:20bce0dcc921 | 107 | |
wataloh | 0:20bce0dcc921 | 108 | StatusCommand *_txStatus; |
wataloh | 0:20bce0dcc921 | 109 | StatusCommand *_rxStatus; |
wataloh | 0:20bce0dcc921 | 110 | |
wataloh | 0:20bce0dcc921 | 111 | request_t _request; |
wataloh | 0:20bce0dcc921 | 112 | request_t _requestQueue[REQUEST_QUEUE_SIZE]; |
wataloh | 0:20bce0dcc921 | 113 | |
wataloh | 0:20bce0dcc921 | 114 | #ifdef ATTRIBUTE_CLI |
wataloh | 0:20bce0dcc921 | 115 | int parseCommand(const char *cmd); |
wataloh | 0:20bce0dcc921 | 116 | #endif |
wataloh | 0:20bce0dcc921 | 117 | |
wataloh | 0:20bce0dcc921 | 118 | void sendCommand(void); |
wataloh | 0:20bce0dcc921 | 119 | |
wataloh | 0:20bce0dcc921 | 120 | void runStateMachine(void); |
wataloh | 0:20bce0dcc921 | 121 | |
wataloh | 0:20bce0dcc921 | 122 | void printState(int state); |
wataloh | 0:20bce0dcc921 | 123 | |
wataloh | 0:20bce0dcc921 | 124 | //void beginSPI(); |
wataloh | 0:20bce0dcc921 | 125 | |
wataloh | 0:20bce0dcc921 | 126 | //void endSPI(); |
wataloh | 0:20bce0dcc921 | 127 | |
wataloh | 0:20bce0dcc921 | 128 | int exchangeStatus(StatusCommand *tx, StatusCommand *rx); |
wataloh | 0:20bce0dcc921 | 129 | |
wataloh | 0:20bce0dcc921 | 130 | bool inSync(StatusCommand *tx, StatusCommand *rx); |
wataloh | 0:20bce0dcc921 | 131 | |
wataloh | 0:20bce0dcc921 | 132 | int writeStatus(StatusCommand *c); |
wataloh | 0:20bce0dcc921 | 133 | |
wataloh | 0:20bce0dcc921 | 134 | void sendBytes(); |
wataloh | 0:20bce0dcc921 | 135 | |
wataloh | 0:20bce0dcc921 | 136 | void recvBytes(); |
wataloh | 0:20bce0dcc921 | 137 | |
wataloh | 0:20bce0dcc921 | 138 | void dumpBytes(char *label, int len, uint8_t *bytes); |
wataloh | 0:20bce0dcc921 | 139 | |
wataloh | 0:20bce0dcc921 | 140 | void updateIntsPending(int amount); |
wataloh | 0:20bce0dcc921 | 141 | |
wataloh | 0:20bce0dcc921 | 142 | void queueInit(void); |
wataloh | 0:20bce0dcc921 | 143 | |
wataloh | 0:20bce0dcc921 | 144 | int queuePut(uint8_t messageType, uint8_t requestId, const uint16_t attributeId, uint16_t valueLen, const uint8_t *value); |
wataloh | 0:20bce0dcc921 | 145 | |
wataloh | 0:20bce0dcc921 | 146 | int queueGet(uint8_t *messageType, uint8_t *requestId, uint16_t *attributeId, uint16_t *valueLen, uint8_t **value); |
wataloh | 0:20bce0dcc921 | 147 | |
wataloh | 0:20bce0dcc921 | 148 | int doGetAttribute(uint8_t requestId, uint16_t attrId); |
wataloh | 0:20bce0dcc921 | 149 | |
wataloh | 0:20bce0dcc921 | 150 | int doSetAttribute(uint8_t requestId, uint16_t attrId, uint16_t valueLen, uint8_t *value); |
wataloh | 0:20bce0dcc921 | 151 | |
wataloh | 0:20bce0dcc921 | 152 | int doUpdateAttribute(uint8_t requestId, uint16_t attrId, uint8_t status, uint16_t valueLen, uint8_t *value); |
wataloh | 0:20bce0dcc921 | 153 | |
wataloh | 0:20bce0dcc921 | 154 | void onStateIdle(void); |
wataloh | 0:20bce0dcc921 | 155 | void onStateSync(void); |
wataloh | 0:20bce0dcc921 | 156 | void onStateAck(void); |
wataloh | 0:20bce0dcc921 | 157 | void onStateSendBytes(void); |
wataloh | 0:20bce0dcc921 | 158 | void onStateRecvBytes(void); |
wataloh | 0:20bce0dcc921 | 159 | void onStateCmdComplete(void); |
wataloh | 0:20bce0dcc921 | 160 | void printTransaction(uint8_t *rbytes, int len); |
wataloh | 0:20bce0dcc921 | 161 | InterruptIn fco; |
wataloh | 0:20bce0dcc921 | 162 | }; |
wataloh | 0:20bce0dcc921 | 163 | |
wataloh | 0:20bce0dcc921 | 164 | #endif // AFLIB_H__ |