Bluetooth UART support for the Adafruit BluefruitLE SPI, for the University of York Engineering Stage 1 project
utility/sdep.h@3:bdfd15be7b82, 2021-03-12 (annotated)
- Committer:
- ajp109
- Date:
- Fri Mar 12 14:35:25 2021 +0000
- Revision:
- 3:bdfd15be7b82
- Parent:
- 0:a80552d32b80
Remove readme
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ajp109 | 0:a80552d32b80 | 1 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 2 | /*! |
ajp109 | 0:a80552d32b80 | 3 | @file sdep.h |
ajp109 | 0:a80552d32b80 | 4 | @author hathach |
ajp109 | 0:a80552d32b80 | 5 | |
ajp109 | 0:a80552d32b80 | 6 | @section LICENSE |
ajp109 | 0:a80552d32b80 | 7 | |
ajp109 | 0:a80552d32b80 | 8 | Software License Agreement (BSD License) |
ajp109 | 0:a80552d32b80 | 9 | |
ajp109 | 0:a80552d32b80 | 10 | Copyright (c) 2013, K. Townsend (microBuilder.eu) |
ajp109 | 0:a80552d32b80 | 11 | Copyright (c) 2014, Adafruit Industries (adafruit.com) |
ajp109 | 0:a80552d32b80 | 12 | |
ajp109 | 0:a80552d32b80 | 13 | All rights reserved. |
ajp109 | 0:a80552d32b80 | 14 | |
ajp109 | 0:a80552d32b80 | 15 | Redistribution and use in source and binary forms, with or without |
ajp109 | 0:a80552d32b80 | 16 | modification, are permitted provided that the following conditions are met: |
ajp109 | 0:a80552d32b80 | 17 | 1. Redistributions of source code must retain the above copyright |
ajp109 | 0:a80552d32b80 | 18 | notice, this list of conditions and the following disclaimer. |
ajp109 | 0:a80552d32b80 | 19 | 2. Redistributions in binary form must reproduce the above copyright |
ajp109 | 0:a80552d32b80 | 20 | notice, this list of conditions and the following disclaimer in the |
ajp109 | 0:a80552d32b80 | 21 | documentation and/or other materials provided with the distribution. |
ajp109 | 0:a80552d32b80 | 22 | 3. Neither the name of the copyright holders nor the |
ajp109 | 0:a80552d32b80 | 23 | names of its contributors may be used to endorse or promote products |
ajp109 | 0:a80552d32b80 | 24 | derived from this software without specific prior written permission. |
ajp109 | 0:a80552d32b80 | 25 | |
ajp109 | 0:a80552d32b80 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
ajp109 | 0:a80552d32b80 | 27 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
ajp109 | 0:a80552d32b80 | 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
ajp109 | 0:a80552d32b80 | 29 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY |
ajp109 | 0:a80552d32b80 | 30 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
ajp109 | 0:a80552d32b80 | 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
ajp109 | 0:a80552d32b80 | 32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
ajp109 | 0:a80552d32b80 | 33 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
ajp109 | 0:a80552d32b80 | 34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
ajp109 | 0:a80552d32b80 | 35 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ajp109 | 0:a80552d32b80 | 36 | */ |
ajp109 | 0:a80552d32b80 | 37 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 38 | #ifndef _SDEP_H_ |
ajp109 | 0:a80552d32b80 | 39 | #define _SDEP_H_ |
ajp109 | 0:a80552d32b80 | 40 | |
ajp109 | 0:a80552d32b80 | 41 | #include "common_header.h" |
ajp109 | 0:a80552d32b80 | 42 | |
ajp109 | 0:a80552d32b80 | 43 | #define SDEP_MAX_PACKETSIZE 16 // Maximum payload per packet |
ajp109 | 0:a80552d32b80 | 44 | |
ajp109 | 0:a80552d32b80 | 45 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 46 | /*! |
ajp109 | 0:a80552d32b80 | 47 | This enumeration is used to make sure that each command has a unique |
ajp109 | 0:a80552d32b80 | 48 | ID, and is used to create the command lookup table enum further down |
ajp109 | 0:a80552d32b80 | 49 | */ |
ajp109 | 0:a80552d32b80 | 50 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 51 | typedef enum { |
ajp109 | 0:a80552d32b80 | 52 | SDEP_CMDTYPE_INITIALIZE = 0xBEEF, /**< Controls the on board LED(s) */ |
ajp109 | 0:a80552d32b80 | 53 | SDEP_CMDTYPE_AT_WRAPPER = 0x0A00, |
ajp109 | 0:a80552d32b80 | 54 | SDEP_CMDTYPE_BLE_UARTTX = 0x0A01, |
ajp109 | 0:a80552d32b80 | 55 | SDEP_CMDTYPE_BLE_UARTRX = 0x0A02, |
ajp109 | 0:a80552d32b80 | 56 | } sdepCmdType_t; |
ajp109 | 0:a80552d32b80 | 57 | |
ajp109 | 0:a80552d32b80 | 58 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 59 | /*! |
ajp109 | 0:a80552d32b80 | 60 | The first byte of every transfer defines the message type |
ajp109 | 0:a80552d32b80 | 61 | */ |
ajp109 | 0:a80552d32b80 | 62 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 63 | typedef enum { |
ajp109 | 0:a80552d32b80 | 64 | SDEP_MSGTYPE_COMMAND = 0x10, |
ajp109 | 0:a80552d32b80 | 65 | SDEP_MSGTYPE_RESPONSE = 0x20, |
ajp109 | 0:a80552d32b80 | 66 | SDEP_MSGTYPE_ALERT = 0x40, |
ajp109 | 0:a80552d32b80 | 67 | SDEP_MSGTYPE_ERROR = 0x80 |
ajp109 | 0:a80552d32b80 | 68 | } sdepMsgType_t; |
ajp109 | 0:a80552d32b80 | 69 | |
ajp109 | 0:a80552d32b80 | 70 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 71 | /*! |
ajp109 | 0:a80552d32b80 | 72 | 4-byte header for SDEP messages |
ajp109 | 0:a80552d32b80 | 73 | */ |
ajp109 | 0:a80552d32b80 | 74 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 75 | typedef struct ATTR_PACKED { |
ajp109 | 0:a80552d32b80 | 76 | uint8_t msg_type; // 8-bit message type indicator (sdepMsgType_t) |
ajp109 | 0:a80552d32b80 | 77 | |
ajp109 | 0:a80552d32b80 | 78 | union { |
ajp109 | 0:a80552d32b80 | 79 | uint16_t cmd_id; // 16-bit command ID |
ajp109 | 0:a80552d32b80 | 80 | struct { |
ajp109 | 0:a80552d32b80 | 81 | uint8_t cmd_id_low; |
ajp109 | 0:a80552d32b80 | 82 | uint8_t cmd_id_high; |
ajp109 | 0:a80552d32b80 | 83 | }; |
ajp109 | 0:a80552d32b80 | 84 | }; |
ajp109 | 0:a80552d32b80 | 85 | |
ajp109 | 0:a80552d32b80 | 86 | struct ATTR_PACKED { |
ajp109 | 0:a80552d32b80 | 87 | uint8_t length : 7; // Payload length (for this packet) |
ajp109 | 0:a80552d32b80 | 88 | uint8_t more_data : 1; // 'more' bit for multiple packet transfers |
ajp109 | 0:a80552d32b80 | 89 | }; |
ajp109 | 0:a80552d32b80 | 90 | } sdepMsgHeader_t; |
ajp109 | 0:a80552d32b80 | 91 | |
ajp109 | 0:a80552d32b80 | 92 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 93 | /*! |
ajp109 | 0:a80552d32b80 | 94 | SDEP command message |
ajp109 | 0:a80552d32b80 | 95 | */ |
ajp109 | 0:a80552d32b80 | 96 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 97 | typedef struct ATTR_PACKED { |
ajp109 | 0:a80552d32b80 | 98 | sdepMsgHeader_t header; |
ajp109 | 0:a80552d32b80 | 99 | uint8_t payload[SDEP_MAX_PACKETSIZE]; |
ajp109 | 0:a80552d32b80 | 100 | } sdepMsgCommand_t; |
ajp109 | 0:a80552d32b80 | 101 | |
ajp109 | 0:a80552d32b80 | 102 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 103 | /*! |
ajp109 | 0:a80552d32b80 | 104 | Response message struct (same as sdepMsgCommand_t) |
ajp109 | 0:a80552d32b80 | 105 | */ |
ajp109 | 0:a80552d32b80 | 106 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 107 | typedef sdepMsgCommand_t sdepMsgResponse_t; |
ajp109 | 0:a80552d32b80 | 108 | |
ajp109 | 0:a80552d32b80 | 109 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 110 | /*! |
ajp109 | 0:a80552d32b80 | 111 | Alert message struct |
ajp109 | 0:a80552d32b80 | 112 | */ |
ajp109 | 0:a80552d32b80 | 113 | /******************************************************************************/ |
ajp109 | 0:a80552d32b80 | 114 | typedef sdepMsgCommand_t sdepMsgAlert_t; |
ajp109 | 0:a80552d32b80 | 115 | |
ajp109 | 0:a80552d32b80 | 116 | #endif |