an old afLib which supports both SPI and UART
afTransport.h@1:112741fe45d1, 2018-04-23 (annotated)
- 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?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Rhyme | 0:6f371c791202 | 1 | /** |
| Rhyme | 0:6f371c791202 | 2 | * Copyright 2016 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 | #ifndef AFLIB_AFTRANSPORT_H |
| Rhyme | 0:6f371c791202 | 17 | #define AFLIB_AFTRANSPORT_H |
| Rhyme | 0:6f371c791202 | 18 | |
| Rhyme | 0:6f371c791202 | 19 | #include "StatusCommand.h" |
| Rhyme | 0:6f371c791202 | 20 | |
| Rhyme | 0:6f371c791202 | 21 | class afTransport { |
| Rhyme | 0:6f371c791202 | 22 | public: |
| Rhyme | 0:6f371c791202 | 23 | /* |
| Rhyme | 0:6f371c791202 | 24 | * checkForInterrupt |
| Rhyme | 0:6f371c791202 | 25 | * |
| Rhyme | 0:6f371c791202 | 26 | * For interfaces that don't use the interrupt pin to signal they want the state machine to run (like UART). |
| Rhyme | 0:6f371c791202 | 27 | */ |
| Rhyme | 0:6f371c791202 | 28 | virtual void checkForInterrupt(volatile int *interrupts_pending, bool idle) = 0; |
| Rhyme | 0:6f371c791202 | 29 | |
| Rhyme | 0:6f371c791202 | 30 | /* |
| Rhyme | 0:6f371c791202 | 31 | * exchangeStatus |
| Rhyme | 0:6f371c791202 | 32 | * |
| Rhyme | 0:6f371c791202 | 33 | * Write a status message to the interface and read one back. |
| Rhyme | 0:6f371c791202 | 34 | */ |
| Rhyme | 0:6f371c791202 | 35 | virtual int exchangeStatus(StatusCommand *tx, StatusCommand *rx) = 0; |
| Rhyme | 0:6f371c791202 | 36 | |
| Rhyme | 0:6f371c791202 | 37 | /* |
| Rhyme | 0:6f371c791202 | 38 | * writeStatus |
| Rhyme | 0:6f371c791202 | 39 | * |
| Rhyme | 0:6f371c791202 | 40 | * Write the specified status message to the interface. |
| Rhyme | 0:6f371c791202 | 41 | */ |
| Rhyme | 0:6f371c791202 | 42 | virtual int writeStatus(StatusCommand *c) = 0; |
| Rhyme | 0:6f371c791202 | 43 | |
| Rhyme | 0:6f371c791202 | 44 | /* |
| Rhyme | 0:6f371c791202 | 45 | * sendBytes |
| Rhyme | 0:6f371c791202 | 46 | * |
| Rhyme | 0:6f371c791202 | 47 | * Write the specified bytes to the interface. |
| Rhyme | 0:6f371c791202 | 48 | */ |
| Rhyme | 0:6f371c791202 | 49 | virtual void sendBytes(char *bytes, int len) = 0; |
| Rhyme | 0:6f371c791202 | 50 | |
| Rhyme | 0:6f371c791202 | 51 | /* |
| Rhyme | 0:6f371c791202 | 52 | * recvBytes |
| Rhyme | 0:6f371c791202 | 53 | * |
| Rhyme | 0:6f371c791202 | 54 | * Read the specified bytes from the interface. |
| Rhyme | 0:6f371c791202 | 55 | */ |
| Rhyme | 0:6f371c791202 | 56 | virtual void recvBytes(char *bytes, int len) = 0; |
| Rhyme | 0:6f371c791202 | 57 | |
| Rhyme | 0:6f371c791202 | 58 | /* |
| Rhyme | 0:6f371c791202 | 59 | * sendBytesOffset |
| Rhyme | 0:6f371c791202 | 60 | * |
| Rhyme | 0:6f371c791202 | 61 | * Write bytes using an interface specific packet size. |
| Rhyme | 0:6f371c791202 | 62 | * It may take multiple calls to this method to write all of the bytes. |
| Rhyme | 0:6f371c791202 | 63 | * |
| Rhyme | 0:6f371c791202 | 64 | * @param bytes buffer of bytes to be written. |
| Rhyme | 0:6f371c791202 | 65 | * @param bytesToSend Pointer to count of total number of bytes to be written. |
| Rhyme | 0:6f371c791202 | 66 | * This value is decremented after each packet is written and will be 0 when all bytes have been sent. |
| Rhyme | 0:6f371c791202 | 67 | * @param offset Pointer to offset into bytes buffer. |
| Rhyme | 0:6f371c791202 | 68 | * This value is incremented after each packet is written and will equal bytesToSend when all bytes have been sent. |
| Rhyme | 0:6f371c791202 | 69 | */ |
| Rhyme | 0:6f371c791202 | 70 | virtual void sendBytesOffset(char *bytes, uint16_t *bytesToSend, uint16_t *offset) = 0; |
| Rhyme | 0:6f371c791202 | 71 | |
| Rhyme | 0:6f371c791202 | 72 | /* |
| Rhyme | 0:6f371c791202 | 73 | * recvBytesOffset |
| Rhyme | 0:6f371c791202 | 74 | * |
| Rhyme | 0:6f371c791202 | 75 | * Read bytes using an interface specific packet size. |
| Rhyme | 0:6f371c791202 | 76 | * It may take multiple calls to this method to read all of the bytes. |
| Rhyme | 0:6f371c791202 | 77 | * |
| Rhyme | 0:6f371c791202 | 78 | * @param bytes Pointer to buffer of bytes to read into. |
| Rhyme | 0:6f371c791202 | 79 | * This buffer is allocated for all bytesToRecv before the first packet is read. |
| Rhyme | 0:6f371c791202 | 80 | * NOTE: IT IS THE CALLER'S RESPONSIBILITY TO FREE THIS BUFFER. |
| Rhyme | 0:6f371c791202 | 81 | * @param bytesToRecv Pointer to count of total number of bytes to be read. |
| Rhyme | 0:6f371c791202 | 82 | * This value is decremented after each packet is read and will be 0 when all bytes have been read. |
| Rhyme | 0:6f371c791202 | 83 | * @param offset Pointer to offset into bytes buffer. |
| Rhyme | 0:6f371c791202 | 84 | * This value is incremented after each packet is read and will equal bytesToRecv when all bytes have been read. |
| Rhyme | 0:6f371c791202 | 85 | */ |
| Rhyme | 0:6f371c791202 | 86 | virtual void recvBytesOffset(char **bytes, uint16_t *bytesLen, uint16_t *bytesToRecv, uint16_t *offset) = 0; |
| Rhyme | 0:6f371c791202 | 87 | }; |
| Rhyme | 0:6f371c791202 | 88 | |
| Rhyme | 0:6f371c791202 | 89 | #endif |
| Rhyme | 0:6f371c791202 | 90 | |
| Rhyme | 0:6f371c791202 | 91 |